<commit_before>/*global Butter*/
(function( global, $ ) {
  var plugins = {};

  var EditorHelper = function() {
    throw "Do not use EditorHelper in this manner. Use EditorHelper.init instead.";
  };

  // This fix is to ensure content-editable still updates correctly, and deals with ie9 not reading document.activeElement properly
  function blurActiveEl() {
   if ( document.activeElement && document.activeElement.blur ) {
      document.activeElement.blur();
    }
  }

  function calculateFinalPositions( event, ui, trackEvent, targetContainer, container, options ) {
    var target = targetContainer.getBoundingClientRect(),
        height = container.clientHeight,
        width = container.clientWidth,
        top = ui.position.top,
        left = ui.position.left,
        targetHeight = target.height,
        targetWidth = target.width,
        minHeightPix = targetHeight * ( ( options.minHeight || 0 ) / 100 ),
        minWidthPix = targetWidth * ( ( options.minWidth || 0 ) / 100 );

    top = Math.max( 0, top );
    left = Math.max( 0, left );
    height = Math.max( minHeightPix, height );
    width = Math.max( minWidthPix, width );

    if ( ( container.offsetTop + height ) > targetHeight ) {
      top = targetHeight - height;
    }

    if ( ( container.offsetLeft + width ) > targetWidth ) {
      left = targetWidth - width;
    }

    height = ( height / targetHeight ) * 100;
    width = ( width / targetWidth ) * 100;

    if ( options.end ) {
      options.end();
    }

    // Enforce container size here, instead of relying on the update.
    container.style.width = width + "%";
    container.style.height = height + "%";

    blurActiveEl();

    trackEvent.update({
      height: height,
      width: width,
      top: ( top / targetHeight ) * 100,
      left: ( left / targetWidth ) * 100
    });
  }

  EditorHelper.init = function( butter ) {

    global.EditorHelper.selectable = function( trackEvent, dragContainer ) {

      var highlight = function() {

        var media,
            manifest,
            manifestOptions,
            track = trackEvent.track;

        if ( !track || !track._media ) {
          return;
        }

        if ( !trackEvent.manifest || !trackEvent.manifest.options ) {
          return;
        }

        media = track._media;
        manifestOptions = trackEvent.manifest.options;

        if ( "zindex" in manifestOptions ) {
          var newZIndex = media.maxPluginZIndex - track.order;
          if ( trackEvent.selected ) {
            dragContainer.classList.add( "track-event-selected" );
            dragContainer.style.zIndex = newZIndex + media.maxPluginZIndex;
          } else {
            dragContainer.style.zIndex = newZIndex;
            dragContainer.classList.remove( "track-event-selected" );
          }
        }
      };

      var onSelect = function( e ) {
        if ( !e.shiftKey ) {
          butter.deselectAllTrackEvents();
        }
        trackEvent.selected = true;
      };

      var update = function() {
        dragContainer.removeEventListener( "mousedown", onSelect, false );
        trackEvent.unlisten( "trackeventselected", highlight );
        trackEvent.unlisten( "trackeventdeselected", highlight );
        trackEvent.unlisten( "trackeventupdated", update );
      };

      highlight();

      dragContainer.addEventListener( "mousedown", onSelect, false );
      trackEvent.listen( "trackeventselected", highlight );
      trackEvent.listen( "trackeventdeselected", highlight );
      trackEvent.listen( "trackeventupdated", update );
    };

    /**
     * Member: draggable
     *
     * Makes a container draggable using jQueryUI
     *
     * @param {TrackEvent} trackEvent: The trackEvent to update when position changes
     * @param {DOMElement} dragContainer: the container which to apply draggable to
     * @param {media} The current media's target element in Butter ( parent container )
     * @param {Object} extra options to apply to the draggable call
     *                 Options are:
     *                    {DOMElement} handle: Restrict drag start event to this element
     *                    {Function} start: Function to execute on drag start event
     *                    {Function} end: Fucntion to execute on drag end event
     */
    global.EditorHelper.draggable = function( trackEvent, dragContainer, targetContainer, options ) {
      if ( $( dragContainer ).data( "draggable" ) ) {
        return;
      }

      var iframeCover = targetContainer.querySelector( ".butter-iframe-fix" );

      options = options || {};

      var el = document.createElement( "div" ),
          stopPropagation = false,
          toolTip,
          onBlur,
          onStopPropagation,
          onMouseDown,
          onMouseUp,
          onDblClick;

      require( [ "ui/widget/tooltip" ], function( ToolTip ) {
        toolTip = ToolTip.create({
          element: dragContainer,
          message: options.tooltip || Butter.localized.get( "Double click to edit" ),
          marginTop: "10px"
        });
        toolTip.hidden = false;
      });

      onBlur = function() {
        if ( stopPropagation ) {
          stopPropagation = false;
          return;
        }
        if ( toolTip ) {
          toolTip.hidden = false;
        }
        dragContainer.removeEventListener( "mousedown", onStopPropagation, false );
        el.addEventListener( "dblclick", onDblClick, false );
        document.removeEventListener( "mousedown", onBlur, false );
        el.style.display = "";
        dragContainer.classList.remove( "track-event-editing" );
      };
      onStopPropagation = function() {
        stopPropagation = true;
      };
      onDblClick = function() {
        if ( toolTip ) {
          toolTip.hidden = true;<commit_msg>[bug 911278] Made tooltips optional<commit_after>/*global Butter*/
(function( global, $ ) {
  var plugins = {};

  var EditorHelper = function() {
    throw "Do not use EditorHelper in this manner. Use EditorHelper.init instead.";
  };

  // This fix is to ensure content-editable still updates correctly, and deals with ie9 not reading document.activeElement properly
  function blurActiveEl() {
   if ( document.activeElement && document.activeElement.blur ) {
      document.activeElement.blur();
    }
  }

  function calculateFinalPositions( event, ui, trackEvent, targetContainer, container, options ) {
    var target = targetContainer.getBoundingClientRect(),
        height = container.clientHeight,
        width = container.clientWidth,
        top = ui.position.top,
        left = ui.position.left,
        targetHeight = target.height,
        targetWidth = target.width,
        minHeightPix = targetHeight * ( ( options.minHeight || 0 ) / 100 ),
        minWidthPix = targetWidth * ( ( options.minWidth || 0 ) / 100 );

    top = Math.max( 0, top );
    left = Math.max( 0, left );
    height = Math.max( minHeightPix, height );
    width = Math.max( minWidthPix, width );

    if ( ( container.offsetTop + height ) > targetHeight ) {
      top = targetHeight - height;
    }

    if ( ( container.offsetLeft + width ) > targetWidth ) {
      left = targetWidth - width;
    }

    height = ( height / targetHeight ) * 100;
    width = ( width / targetWidth ) * 100;

    if ( options.end ) {
      options.end();
    }

    // Enforce container size here, instead of relying on the update.
    container.style.width = width + "%";
    container.style.height = height + "%";

    blurActiveEl();

    trackEvent.update({
      height: height,
      width: width,
      top: ( top / targetHeight ) * 100,
      left: ( left / targetWidth ) * 100
    });
  }

  EditorHelper.init = function( butter ) {

    global.EditorHelper.selectable = function( trackEvent, dragContainer ) {

      var highlight = function() {

        var media,
            manifest,
            manifestOptions,
            track = trackEvent.track;

        if ( !track || !track._media ) {
          return;
        }

        if ( !trackEvent.manifest || !trackEvent.manifest.options ) {
          return;
        }

        media = track._media;
        manifestOptions = trackEvent.manifest.options;

        if ( "zindex" in manifestOptions ) {
          var newZIndex = media.maxPluginZIndex - track.order;
          if ( trackEvent.selected ) {
            dragContainer.classList.add( "track-event-selected" );
            dragContainer.style.zIndex = newZIndex + media.maxPluginZIndex;
          } else {
            dragContainer.style.zIndex = newZIndex;
            dragContainer.classList.remove( "track-event-selected" );
          }
        }
      };

      var onSelect = function( e ) {
        if ( !e.shiftKey ) {
          butter.deselectAllTrackEvents();
        }
        trackEvent.selected = true;
      };

      var update = function() {
        dragContainer.removeEventListener( "mousedown", onSelect, false );
        trackEvent.unlisten( "trackeventselected", highlight );
        trackEvent.unlisten( "trackeventdeselected", highlight );
        trackEvent.unlisten( "trackeventupdated", update );
      };

      highlight();

      dragContainer.addEventListener( "mousedown", onSelect, false );
      trackEvent.listen( "trackeventselected", highlight );
      trackEvent.listen( "trackeventdeselected", highlight );
      trackEvent.listen( "trackeventupdated", update );
    };

    /**
     * Member: draggable
     *
     * Makes a container draggable using jQueryUI
     *
     * @param {TrackEvent} trackEvent: The trackEvent to update when position changes
     * @param {DOMElement} dragContainer: the container which to apply draggable to
     * @param {media} The current media's target element in Butter ( parent container )
     * @param {Object} extra options to apply to the draggable call
     *                 Options are:
     *                    {DOMElement} handle: Restrict drag start event to this element
     *                    {Function} start: Function to execute on drag start event
     *                    {Function} end: Fucntion to execute on drag end event
     */
    global.EditorHelper.draggable = function( trackEvent, dragContainer, targetContainer, options ) {
      if ( $( dragContainer ).data( "draggable" ) ) {
        return;
      }

      var iframeCover = targetContainer.querySelector( ".butter-iframe-fix" );

      options = options || {};

      var el = document.createElement( "div" ),
          stopPropagation = false,
          toolTip,
          onBlur,
          onStopPropagation,
          onMouseDown,
          onMouseUp,
          onDblClick;

      if ( !options.disableTooltip ) {
        require( [ "ui/widget/tooltip" ], function( ToolTip ) {
          toolTip = ToolTip.create({
            element: dragContainer,
            message: options.tooltip || Butter.localized.get( "Double click to edit" ),
            marginTop: "10px"
          });
          toolTip.hidden = false;
        });
      }

      onBlur = function() {
        if ( stopPropagation ) {
          stopPropagation = false;
          return;
        }
        if ( toolTip ) {
          toolTip.hidden = false;
        }
        dragContainer.removeEventListener( "mousedown", onStopPropagation, false );
        el.addEventListener( "dblclick", onDblClick, false );
        document.removeEventListener( "mousedown", onBlur, false );
        el.style.display = "";
        dragContainer.classList.remove( "track-event-editing" );
      };
      onStopPropagation = function() {
        stopPropagation = true;
      };
      onDblClick = function() {
        if ( toolTip ) {
          toolTip.hidden = true;
{'fraction_non_alphanumeric': 0.10740899357601713, 'fraction_numerical': 0.004796573875802998, 'mean_word_length': 2.171102661596958, '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': '3741162', 'n_tokens_mistral': 3267, 'n_tokens_neox': 3129, 'n_words': 793}