<commit_before>define( [ "ui/page-element", "ui/logo-spinner", "util/lang", "ui/widget/textbox", "text!layouts/media-view.html" ],
  function( PageElement, LogoSpinner, LangUtils, TextboxWrapper, HTML_TEMPLATE ){

  var DEFAULT_SUBTITLE = "Supports HTML5 video and YouTube",
      MOUSE_OUT_DURATION = 300,
      MAX_URLS = 4;

  return function( media, options ){
    var _media = media,
        _pageElement,
        _onDropped = options.onDropped || function(){},
        _closeSignal = false,
        _logoSpinner;

    var _propertiesElement = LangUtils.domFragment( HTML_TEMPLATE ),
        _container = _propertiesElement.querySelector( "div.container" ),
        _urlContainer = _propertiesElement.querySelector( "div.url" ),
        _urlTextbox = _propertiesElement.querySelector( "input[type='text']" ),
        _subtitle = _propertiesElement.querySelector( ".form-field-notes" ),
        _changeButton = _propertiesElement.querySelector( "button.save" ),
        _addUrlButton = _propertiesElement.querySelector( "button.add-url" ),
        _urlList = _propertiesElement.querySelector( "div.url-group" ),
        _loadingContainer = _propertiesElement.querySelector( ".loading-container" );

    var _containerDims;

    function setDimensions( state ){
      if( state ){
        _closeSignal = false;
        _propertiesElement.style.width = _containerDims.width + "px";
        _propertiesElement.style.height = _containerDims.height + "px";
      }
      else {
        _propertiesElement.style.width = "";
        _propertiesElement.style.height = "";
      }
    }

    function prepareTextbox( textbox ){
      TextboxWrapper( textbox );
    }

    function addUrl() {
      var newContainer = _urlContainer.cloneNode( true );
      newContainer.classList.remove( "fade-in" );
      _urlList.appendChild( newContainer );

      // force the browser to wait a tick before applying this class
      // so fade-in effect occurs
      setTimeout(function(){
        newContainer.classList.add( "fade-in" );
      }, 0);

      _containerDims.width = _container.clientWidth;
      _containerDims.height = _container.clientHeight;
      setDimensions( true );

      newContainer.querySelector( "button.remove" ).addEventListener( "click", function ( e ) {
        removeUrl( newContainer );
      }, false );

      prepareTextbox( newContainer.querySelector( "input[type='text']" ) );

      if ( _urlList.querySelectorAll( "input[type='text']" ).length >= MAX_URLS ) {
        _addUrlButton.style.visibility = "hidden";
      }
    }

    function removeUrl( container ){
      _urlList.removeChild( container );
      _containerDims.width = _container.clientWidth;
      _containerDims.height = _container.clientHeight;
      setDimensions( true );
      if ( _urlList.querySelectorAll( "input[type='text']" ).length < MAX_URLS ) {
        _addUrlButton.style.visibility = "visible";
      }
    }

    _addUrlButton.addEventListener( "click", function( e ) {
      addUrl();
    }, false );

    prepareTextbox( _urlTextbox );

    _propertiesElement.addEventListener( "mouseover", function( e ) {
      e.stopPropagation();
      _propertiesElement.classList.add( "open" );
      // silly hack to stop jittering of width/height
      if ( !_containerDims ) {
        _containerDims = {
          width: _container.clientWidth,
          height: _container.clientHeight
        };
      }
      setDimensions( true );
    }, true );

    _propertiesElement.addEventListener( "mouseout", function( e ) {
      setTimeout(function(){
        if ( _closeSignal ) {
          setDimensions( false );
          _propertiesElement.classList.remove( "open" );
        }
      }, MOUSE_OUT_DURATION );
      _closeSignal = true;
    }, false );

    _logoSpinner = LogoSpinner( _loadingContainer );

    _subtitle.innerHTML = DEFAULT_SUBTITLE;<commit_msg>[t1339] keepOpen flag in media view maintain focus<commit_after>define( [ "ui/page-element", "ui/logo-spinner", "util/lang", "ui/widget/textbox", "text!layouts/media-view.html" ],
  function( PageElement, LogoSpinner, LangUtils, TextboxWrapper, HTML_TEMPLATE ){

  var DEFAULT_SUBTITLE = "Supports HTML5 video and YouTube",
      MOUSE_OUT_DURATION = 300,
      MAX_URLS = 4;

  return function( media, options ){
    var _media = media,
        _pageElement,
        _onDropped = options.onDropped || function(){},
        _closeSignal = false,
        _keepOpen = false,
        _logoSpinner;

    var _propertiesElement = LangUtils.domFragment( HTML_TEMPLATE ),
        _container = _propertiesElement.querySelector( "div.container" ),
        _urlContainer = _propertiesElement.querySelector( "div.url" ),
        _urlTextbox = _propertiesElement.querySelector( "input[type='text']" ),
        _subtitle = _propertiesElement.querySelector( ".form-field-notes" ),
        _changeButton = _propertiesElement.querySelector( "button.save" ),
        _addUrlButton = _propertiesElement.querySelector( "button.add-url" ),
        _urlList = _propertiesElement.querySelector( "div.url-group" ),
        _loadingContainer = _propertiesElement.querySelector( ".loading-container" );

    var _containerDims;

    function closeIfPossible(){
      if ( _closeSignal && !_keepOpen ) {
        setDimensions( false );
        _propertiesElement.classList.remove( "open" );
      }
    }

    function setDimensions( state ){
      if( state ){
        _closeSignal = false;
        _propertiesElement.style.width = _containerDims.width + "px";
        _propertiesElement.style.height = _containerDims.height + "px";
      }
      else {
        _propertiesElement.style.width = "";
        _propertiesElement.style.height = "";
      }
    }

    function prepareTextbox( textbox ){
      TextboxWrapper( textbox );
      textbox.addEventListener( "blur", function( e ) {
        _keepOpen = false;
        closeIfPossible();
      }, false );
      textbox.addEventListener( "focus", function( e ) {
        _keepOpen = true;
      }, false );
    }

    function addUrl() {
      var newContainer = _urlContainer.cloneNode( true );
      newContainer.classList.remove( "fade-in" );
      _urlList.appendChild( newContainer );

      // force the browser to wait a tick before applying this class
      // so fade-in effect occurs
      setTimeout(function(){
        newContainer.classList.add( "fade-in" );
      }, 0);

      _containerDims.width = _container.clientWidth;
      _containerDims.height = _container.clientHeight;
      setDimensions( true );

      newContainer.querySelector( "button.remove" ).addEventListener( "click", function ( e ) {
        removeUrl( newContainer );
      }, false );

      prepareTextbox( newContainer.querySelector( "input[type='text']" ) );

      if ( _urlList.querySelectorAll( "input[type='text']" ).length >= MAX_URLS ) {
        _addUrlButton.style.visibility = "hidden";
      }
    }

    function removeUrl( container ){
      _urlList.removeChild( container );
      _containerDims.width = _container.clientWidth;
      _containerDims.height = _container.clientHeight;
      setDimensions( true );
      if ( _urlList.querySelectorAll( "input[type='text']" ).length < MAX_URLS ) {
        _addUrlButton.style.visibility = "visible";
      }
    }

    _addUrlButton.addEventListener( "click", function( e ) {
      addUrl();
    }, false );

    prepareTextbox( _urlTextbox );

    _propertiesElement.addEventListener( "mouseover", function( e ) {
      e.stopPropagation();
      _propertiesElement.classList.add( "open" );
      // silly hack to stop jittering of width/height
      if ( !_containerDims ) {
        _containerDims = {
          width: _container.clientWidth,
          height: _container.clientHeight
        };
      }
      setDimensions( true );
    }, true );

    _propertiesElement.addEventListener( "mouseout", function( e ) {
      setTimeout(function(){
        closeIfPossible();
      }, MOUSE_OUT_DURATION );
      _closeSignal = true;
    }, false );

    _logoSpinner = LogoSpinner( _loadingContainer );

    _subtitle.innerHTML = DEFAULT_SUBTITLE;
{'fraction_non_alphanumeric': 0.11602619547757322, 'fraction_numerical': 0.0019770171753367106, 'mean_word_length': 2.856121962839447, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '638866', 'n_tokens_mistral': 2332, 'n_tokens_neox': 2304, 'n_words': 451}