<commit_before>/* jslint browser:true */

let React = require("react"),
  { FrameFactory } = require("./views/frame.js"),
  { setGitRevision, staticLink } = require("./linker"),
  { AbstractShot } = require("../shared/shot"),
  { requestProfile } = require("./events");

// This represents the model we are rendering:
let model;

// This represents the current user's profile.
let profile;

exports.setModel = function (data) {
  let firstSet = ! model;
  model = data;
  model.shot = new AbstractShot(data.backend, data.id, data.shot);
  model.shot.contentUrl = `//${data.contentOrigin}/content/${model.shot.id}`;
  model.shot.urlIfDeleted = data.urlIfDeleted;
  model.shot.expireTime = new Date(data.expireTime);
  model.shot.deleted = data.deleted;

  if (firstSet) {
    let toolbar = document.getElementById("toolbar");
    let fullPageButton = document.getElementById("full-page-button");
    let fullPageButtonScrollable = document.getElementById("full-page-button-scrollable");
    let frameElement = document.getElementById("frame");
    let offset = (fullPageButtonScrollable.clientHeight / 2);
    window.onscroll = function (e) {
      if (e.pageY > 40) {
        toolbar.style.visibility = "visible";
        let frameOffset = frameElement.getBoundingClientRect().top + window.scrollY;
        let toolbarHeight = toolbar.clientHeight;
        let visibleHeight = window.innerHeight - toolbarHeight;
        let frameTop = frameOffset - toolbarHeight;
        if (e.pageY >= frameTop - visibleHeight - offset) {
          fullPageButton.style.visibility = "hidden";
          fullPageButtonScrollable.style.visibility = "visible";
        } else {
          fullPageButton.style.visibility = "visible";
          fullPageButtonScrollable.style.visibility = "hidden";
        }
      } else {
        toolbar.style.visibility = "hidden";
      }
    };

    document.addEventListener("helper-ready", function onHelperReady(e) {
      document.removeEventListener("helper-ready", onHelperReady, false);
      requestProfile();
    }, false);
    document.addEventListener("refresh-profile", refreshProfile, false);
    window.addEventListener("hashchange", refreshHash, false);
    refreshHash();
  }
  render();
};

function render() {
  setGitRevision(model.gitRevision);
  let attrs = { staticLink };
  for (let attr in model) {
    attrs[attr] = model[attr];
  }
  for (let attr in profile) {
    attrs[attr] = profile[attr];
  }
  attrs.renderBodyOnly = true;
  let frame = FrameFactory(attrs);

  React.render(
    frame,
    document.getElementById("react-body-container"));
}

function refreshProfile(e) {
  profile = JSON.parse(e.detail);
  render();
}

function refreshHash() {
  let clipId = null;
  let match = (/clip=([^&]+)/).exec(location.hash);
  if (match) {
    clipId = decodeURIComponent(match[1]);
  }
  if ((model.activeClipId || null) === clipId) {
    // No change
    return;
  }
  model.activeClipId = clipId;
  sendShowElement(clipId);
  render();
}

function sendShowElement(clipId) {
  let frame = document.getElementById("frame");
  if (! frame) {
    throw new Error("Could not find #frame");
  }
  let postMessage;
  if (clipId) {
    let clip = model.shot.getClip(clipId);
    if (! clip) {
      throw new Error("Could not find clip with id " + clipId);
    }
    postMessage = {
      type: "displayClip",
      clip: clip.asJson()
    };
  } else {
    postMessage = {
      type: "removeDisplayClip"
    };
  }

  try {
    window.sendToChild(postMessage);
  } catch (e) {
    console.error("Error sending postMessage:", e);
    console.error("Message:", postMessage);
    throw e;
  }
}

if (typeof window != "undefined") {
  window.clientglue = exports;
}
<commit_msg>Remove vestigal code<commit_after>/* jslint browser:true */

let React = require("react"),
  { FrameFactory } = require("./views/frame.js"),
  { setGitRevision, staticLink } = require("./linker"),
  { AbstractShot } = require("../shared/shot"),
  { requestProfile } = require("./events");

// This represents the model we are rendering:
let model;

// This represents the current user's profile.
let profile;

exports.setModel = function (data) {
  let firstSet = ! model;
  model = data;
  model.shot = new AbstractShot(data.backend, data.id, data.shot);
  model.shot.contentUrl = `//${data.contentOrigin}/content/${model.shot.id}`;
  model.shot.urlIfDeleted = data.urlIfDeleted;
  model.shot.expireTime = new Date(data.expireTime);
  model.shot.deleted = data.deleted;

  if (firstSet) {
    let toolbar = document.getElementById("toolbar");
    let fullPageButton = document.getElementById("full-page-button");
    let fullPageButtonScrollable = document.getElementById("full-page-button-scrollable");
    let frameElement = document.getElementById("frame");
    let offset = (fullPageButtonScrollable.clientHeight / 2);
    window.onscroll = function (e) {
      if (e.pageY > 40) {
        toolbar.style.visibility = "visible";
        let frameOffset = frameElement.getBoundingClientRect().top + window.scrollY;
        let toolbarHeight = toolbar.clientHeight;
        let visibleHeight = window.innerHeight - toolbarHeight;
        let frameTop = frameOffset - toolbarHeight;
        if (e.pageY >= frameTop - visibleHeight - offset) {
          fullPageButton.style.visibility = "hidden";
          fullPageButtonScrollable.style.visibility = "visible";
        } else {
          fullPageButton.style.visibility = "visible";
          fullPageButtonScrollable.style.visibility = "hidden";
        }
      } else {
        toolbar.style.visibility = "hidden";
      }
    };

    document.addEventListener("helper-ready", function onHelperReady(e) {
      document.removeEventListener("helper-ready", onHelperReady, false);
      requestProfile();
    }, false);
    document.addEventListener("refresh-profile", refreshProfile, false);
    window.addEventListener("hashchange", refreshHash, false);
    refreshHash();
  }
  render();
};

function render() {
  setGitRevision(model.gitRevision);
  let attrs = { staticLink };
  for (let attr in model) {
    attrs[attr] = model[attr];
  }
  for (let attr in profile) {
    attrs[attr] = profile[attr];
  }
  let frame = FrameFactory(attrs);

  React.render(
    frame,
    document.getElementById("react-body-container"));
}

function refreshProfile(e) {
  profile = JSON.parse(e.detail);
  render();
}

function refreshHash() {
  let clipId = null;
  let match = (/clip=([^&]+)/).exec(location.hash);
  if (match) {
    clipId = decodeURIComponent(match[1]);
  }
  if ((model.activeClipId || null) === clipId) {
    // No change
    return;
  }
  model.activeClipId = clipId;
  sendShowElement(clipId);
  render();
}

function sendShowElement(clipId) {
  let frame = document.getElementById("frame");
  if (! frame) {
    throw new Error("Could not find #frame");
  }
  let postMessage;
  if (clipId) {
    let clip = model.shot.getClip(clipId);
    if (! clip) {
      throw new Error("Could not find clip with id " + clipId);
    }
    postMessage = {
      type: "displayClip",
      clip: clip.asJson()
    };
  } else {
    postMessage = {
      type: "removeDisplayClip"
    };
  }

  try {
    window.sendToChild(postMessage);
  } catch (e) {
    console.error("Error sending postMessage:", e);
    console.error("Message:", postMessage);
    throw e;
  }
}

if (typeof window != "undefined") {
  window.clientglue = exports;
}

{'fraction_non_alphanumeric': 0.14044792228818131, 'fraction_numerical': 0.0010793308148947653, 'mean_word_length': 3.2824956672443673, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1518295', 'n_tokens_mistral': 2253, 'n_tokens_neox': 2218, 'n_words': 484}