<commit_before>/* globals require, self, unescape */
/* exported FILENAME */
/** The worker for shoot-panel.html
    This is setup and directly communicated to by main.js
    The shot comes from `lib/shooter.js:ShotContext` (and the `Shot` model)
    The outgoing messages are routed to `ShotContext.panelHandlers)
    */


let err = require("./error-utils.js"),
  React = require("react"),
  {AbstractShot} = require("../lib/shared/shot.js");

// For error messages:
let FILENAME = "shoot-panel.js";
let isAdding = {};
let hasDeleted = {};
let lastData;
let debugDisplayTextSource = false;

const MAX_WIDTH = 375,
  MAX_HEIGHT = 238;

function stripProtocol(url) {
  return url.replace(/^https?:\/\//i, "");
}

function domainOnly(url) {
  return url.replace(/^https?:\/\//i, "").replace(/\/.*$/, "").replace(/^www\./i, "");
}

/** Renders the image of the clip inside the panel */
class ImageClip extends React.Component {
  render() {
    var width = this.props.clip.image.dimensions.x,
      height = this.props.clip.image.dimensions.y;

    if (width > MAX_WIDTH) {
      let factor = MAX_WIDTH / width;
      width = MAX_WIDTH;
      height = height * factor;
    } else if (height > MAX_HEIGHT) {
      let factor =  MAX_HEIGHT / height;
      height = MAX_HEIGHT;
      width = width * factor;
    }

    height = height + 'px';
    width = width + 'px';

    return <img className="snippet-image" src={this.props.clip.image.url} style={{ height: height, width: width }} />;
  }
}

/** Renders a the text of a text clip inside the panel */
class TextClip extends React.Component {
  render() {
    if (debugDisplayTextSource) {
      return <textarea readOnly="1" className="snippet-text" value={this.props.clip.text.html} />;
    }
    let html = {__html: this.props.clip.text.html};
    return <div className="snippet-text" dangerouslySetInnerHTML={html}></div>;
  }
}

/** Renders when no clips have yet been added to the shot */
class LoadingClip extends React.Component {
  render() {
    return <img src="icons/pageshot-camera-empty.svg" />;
  }
}

class ShareButtons extends React.Component {
  render() {
    let size = this.props.large ? "32" : "16";
    return <div className="share-row">
      <a target="_blank" href={ "https://www.facebook.com/sharer/sharer.php?u=" + encodeURIComponent(this.props.shot.viewUrl) }>
        <img src={ `icons/facebook-${size}.png` } />
      </a>
      <a target="_blank" href={"https://twitter.com/home?status=" + encodeURIComponent(this.props.shot.viewUrl) }>
        <img src={ `icons/twitter-${size}.png` } />
      </a>
      <a target="_blank" href={"https://pinterest.com/pin/create/button/?url=" + encodeURIComponent(this.props.shot.viewUrl) + "&media=" + encodeURIComponent(this.props.clipUrl) + "&description=" }>
        <img src={ `icons/pinterest-${size}.png` } />
      </a>
      <a target="_blank" href={ "mailto:?subject=Check%20out%20this%20PageShot%20page&body=" + encodeURIComponent(this.props.shot.viewUrl) }>
        <img src={ `icons/email-${size}.png` } /><commit_msg>Fixes #601 Change the email to contain more detailed information.<commit_after>/* globals require, self, unescape */
/* exported FILENAME */
/** The worker for shoot-panel.html
    This is setup and directly communicated to by main.js
    The shot comes from `lib/shooter.js:ShotContext` (and the `Shot` model)
    The outgoing messages are routed to `ShotContext.panelHandlers)
    */


let err = require("./error-utils.js"),
  React = require("react"),
  {AbstractShot} = require("../lib/shared/shot.js");

// For error messages:
let FILENAME = "shoot-panel.js";
let isAdding = {};
let hasDeleted = {};
let lastData;
let debugDisplayTextSource = false;

const MAX_WIDTH = 375,
  MAX_HEIGHT = 238;

function stripProtocol(url) {
  return url.replace(/^https?:\/\//i, "");
}

function domainOnly(url) {
  return url.replace(/^https?:\/\//i, "").replace(/\/.*$/, "").replace(/^www\./i, "");
}

/** Renders the image of the clip inside the panel */
class ImageClip extends React.Component {
  render() {
    var width = this.props.clip.image.dimensions.x,
      height = this.props.clip.image.dimensions.y;

    if (width > MAX_WIDTH) {
      let factor = MAX_WIDTH / width;
      width = MAX_WIDTH;
      height = height * factor;
    } else if (height > MAX_HEIGHT) {
      let factor =  MAX_HEIGHT / height;
      height = MAX_HEIGHT;
      width = width * factor;
    }

    height = height + 'px';
    width = width + 'px';

    return <img className="snippet-image" src={this.props.clip.image.url} style={{ height: height, width: width }} />;
  }
}

/** Renders a the text of a text clip inside the panel */
class TextClip extends React.Component {
  render() {
    if (debugDisplayTextSource) {
      return <textarea readOnly="1" className="snippet-text" value={this.props.clip.text.html} />;
    }
    let html = {__html: this.props.clip.text.html};
    return <div className="snippet-text" dangerouslySetInnerHTML={html}></div>;
  }
}

/** Renders when no clips have yet been added to the shot */
class LoadingClip extends React.Component {
  render() {
    return <img src="icons/pageshot-camera-empty.svg" />;
  }
}

class ShareButtons extends React.Component {
  render() {
    let size = this.props.large ? "32" : "16";
    return <div className="share-row">
      <a target="_blank" href={ "https://www.facebook.com/sharer/sharer.php?u=" + encodeURIComponent(this.props.shot.viewUrl) }>
        <img src={ `icons/facebook-${size}.png` } />
      </a>
      <a target="_blank" href={"https://twitter.com/home?status=" + encodeURIComponent(this.props.shot.viewUrl) }>
        <img src={ `icons/twitter-${size}.png` } />
      </a>
      <a target="_blank" href={"https://pinterest.com/pin/create/button/?url=" + encodeURIComponent(this.props.shot.viewUrl) + "&media=" + encodeURIComponent(this.props.clipUrl) + "&description=" }>
        <img src={ `icons/pinterest-${size}.png` } />
      </a>
      <a target="_blank" href={ `mailto:?subject=Fwd:%20${encodeURIComponent(this.props.shot.title)}&body=${encodeURIComponent(this.props.shot.title)}%0A%0A${encodeURIComponent(this.props.shot.viewUrl)}%0A%0ASource:%20${encodeURIComponent(this.props.shot.url)}%0A` }>
        <img src={ `icons/email-${size}.png` } />
{'fraction_non_alphanumeric': 0.16991065730695595, 'fraction_numerical': 0.006700701978302489, 'mean_word_length': 3.383916083916084, 'pattern_counts': {'":': 0, '<': 37, '<?xml version=': 0, '>': 41, 'https://': 6, 'lorem ipsum': 0, 'www.': 4, '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': '3482638', 'n_tokens_mistral': 2090, 'n_tokens_neox': 2060, 'n_words': 470}