<commit_before>
DV.Schema.helpers = {

    HOST_EXTRACTOR : (/https?:\/\/([^\/]+)\//),
    annotationClassName: '.DV-annotation',

    // Bind all events for the docviewer
    // live/delegate are the preferred methods of event attachment
    bindEvents: function(context){
      var boundZoom = this.events.compile('zoom');
      var doc = context.models.document;
      var value = _.indexOf(doc.ZOOM_RANGES, doc.zoomLevel) * 24.7;
      this.application.slider = $j('#DV-zoomBox').slider({ step: 24.7, value: value, change: function(el,d){
        boundZoom(context.models.document.ZOOM_RANGES[parseInt(d.value / 24.7, 10)]);
      }});

      // next/previous
      var compiled        = this.application.compiled;
      compiled.next       = this.events.compile('next');
      compiled.previous   = this.events.compile('previous');


      var states = context.states;
      $j('#DV-navControls').delegate('span#DV-next','click', compiled.next);
      $j('#DV-navControls').delegate('span#DV-previous','click', compiled.previous);

      $j('#DV-annotationView').delegate('.DV-trigger','click',function(e){
        e.preventDefault();
        states.ViewAnnotation();
      });
      $j('#DV-documentView').delegate('.DV-trigger','click',function(e){
        DV.history.save('document/p'+context.models.document.currentPage());
        states.ViewDocument();
      });
      $j('#DV-textView').delegate('.DV-trigger','click',function(e){

        DV.history.save('text/p'+context.models.document.currentPage());
        states.ViewText();
      });
      $j('.DV-pagination').delegate('span.DV-gotoPage','click', $j.proxy(this.gotoPage, this));

      $j('form#DV-searchDocument').submit(this.events.compile('search'));
      $j('#DV-searchBar').delegate('#DV-closeSearch','click',function(e){
        e.preventDefault();
        DV.history.save('text/p'+context.models.document.currentPage());
        states.ViewText();
      });

      $j('#DV-searchResults').delegate('span.DV-resultPrevious','click', $j.proxy(this.highlightPreviousMatch, this));

      $j('#DV-searchResults').delegate('span.DV-resultNext','click', $j.proxy(this.highlightNextMatch, this));


      var boundToggle           = $j.proxy(this.annotationBridgeToggle, this);
      var boundDrawConnector    = $j.proxy(this.annotationBridgeDrawConnector,this);
      var boundRemoveConnector  = $j.proxy(this.annotationBridgeRemoveConnector,this);
      var collection            = this.elements.collection;

      collection.delegate('span.DV-annotationTab','click', boundToggle);
      collection.delegate('span.DV-annotationTab','mouseover', boundDrawConnector);
      collection.delegate('span.DV-annotationTab','mouseout', boundRemoveConnector);

      collection.delegate('span.DV-annotationRegion','mouseover', boundDrawConnector);
      collection.delegate('span.DV-annotationRegion','mouseout', boundRemoveConnector);
      collection.delegate('span.DV-annotationRegion','click', $j.proxy(this.annotationBridgeShow, this));

      collection.delegate('span.DV-annotationNext','click', $j.proxy(this.annotationBridgeNext, this));
      collection.delegate('span.DV-annotationPrevious','click', $j.proxy(this.annotationBridgePrevious, this));
      collection.delegate('.DV-showEdit','click', $j.proxy(this.showAnnotationEdit, this));
      collection.delegate('.DV-cancelEdit','click', $j.proxy(this.cancelAnnotationEdit, this));
      collection.delegate('.DV-saveAnnotation','click', $j.proxy(this.saveAnnotation, this));
      collection.delegate('.DV-deleteAnnotation','click', $j.proxy(this.deleteAnnotation, this));

      $j('#DV-descriptionToggle').live('click',function(e){
        e.preventDefault();
        e.stopPropagation();

        $j('#DV-descriptionText').slideToggle(300,function(){
          $j('#DV-descriptionToggle').toggleClass('DV-showDescription');
        });
      });

      var cleanUp = $j.proxy(this.application.pageSet.cleanUp, this);


      this.elements.window.live('mousedown',
        function(e){
          var el = $j(e.target);
          if (el.parents().is('.DV-annotation') || el.is('.DV-annotation')) return true;
          if(context.elements.window.hasClass('DV-coverVisible')){
            if((el.width() - parseInt(e.clientX,10)) >= 15){
              cleanUp();
            }
          }
        }
      );

      if(jQuery.browser.msie == true){
        this.elements.browserDocument.bind('focus',$j.proxy(this.focusWindow,this));
        this.elements.browserDocument.bind('focusout',$j.proxy(this.focusOut,this));
      }else{
        this.elements.browserWindow.bind('focus',$j.proxy(this.focusWindow,this));
        this.elements.browserWindow.bind('blur',$j.proxy(this.blurWindow,this));
      }

      // When the document is scrolled, even in the background, resume polling.
      this.elements.window.bind('scroll', $j.proxy(this.focusWindow, this));

      this.elements.coverPages.live('mousedown', cleanUp);

      this.application.acceptInput = this.elements.currentPage.acceptInput({ changeCallBack: $j.proxy(this.acceptInputCallBack,this) });

    },
    startCheckTimer: function(){
      var _t = this.application;
      var _check = function(){
        _t.events.check();
      };
      this.application.checkTimer = setInterval(_check,100);
    },
    stopCheckTimer: function(){
      clearTimeout(this.application.checkTimer);
    },
    blurWindow: function(){
      if(this.application.isFocus === true){
        this.application.isFocus = false;
        // pause draw timer
        this.stopCheckTimer();
      }else{
        return;
      }
    },
    focusOut: function(){
      if(this.application.activeElement != document.activeElement){
        this.application.activeElement = document.activeElement;
        this.application.isFocus = true;
      }else{
        // pause draw timer
        this.application.isFocus = false;
        DV.controller.helpers.stopCheckTimer();
        return;
      }
    },
    focusWindow: function(){
      if(this.application.isFocus === true){
        return;
      }else{
        this.application.isFocus = true;
        // restart draw timer
        this.startCheckTimer();
      }
    },
    setDocHeight:   function(height,diff) {
      this.elements.window[0].scrollTop += diff;
      this.elements.bar.css('height', height);
    },
    getWindowDimensions: function(){

      var offset = (DV.options.embedded == true) ? 0 : parseInt($j(document.body).css('padding-top'), 10);

      var d = {
        height: (window.innerHeight ? window.innerHeight : this.elements.browserWindow.height()) - offset,
        width: this.elements.browserWindow.width()
      };
      return d;
    },

    // Is the given URL on a remote domain?
    isCrossDomain : function(url) {
      var urlDomain = url.match(this.HOST_EXTRACTOR)[1];
      return urlDomain != window.location.host;
    },
    resetScrollState: function(){
      this.elements.window.scrollTop(0);
    },<commit_msg>safer detection of cross-domain URLs, for filesystem resource loading, when downloaded.<commit_after>
DV.Schema.helpers = {

    HOST_EXTRACTOR : (/https?:\/\/([^\/]+)\//),
    annotationClassName: '.DV-annotation',

    // Bind all events for the docviewer
    // live/delegate are the preferred methods of event attachment
    bindEvents: function(context){
      var boundZoom = this.events.compile('zoom');
      var doc = context.models.document;
      var value = _.indexOf(doc.ZOOM_RANGES, doc.zoomLevel) * 24.7;
      this.application.slider = $j('#DV-zoomBox').slider({ step: 24.7, value: value, change: function(el,d){
        boundZoom(context.models.document.ZOOM_RANGES[parseInt(d.value / 24.7, 10)]);
      }});

      // next/previous
      var compiled        = this.application.compiled;
      compiled.next       = this.events.compile('next');
      compiled.previous   = this.events.compile('previous');


      var states = context.states;
      $j('#DV-navControls').delegate('span#DV-next','click', compiled.next);
      $j('#DV-navControls').delegate('span#DV-previous','click', compiled.previous);

      $j('#DV-annotationView').delegate('.DV-trigger','click',function(e){
        e.preventDefault();
        states.ViewAnnotation();
      });
      $j('#DV-documentView').delegate('.DV-trigger','click',function(e){
        DV.history.save('document/p'+context.models.document.currentPage());
        states.ViewDocument();
      });
      $j('#DV-textView').delegate('.DV-trigger','click',function(e){

        DV.history.save('text/p'+context.models.document.currentPage());
        states.ViewText();
      });
      $j('.DV-pagination').delegate('span.DV-gotoPage','click', $j.proxy(this.gotoPage, this));

      $j('form#DV-searchDocument').submit(this.events.compile('search'));
      $j('#DV-searchBar').delegate('#DV-closeSearch','click',function(e){
        e.preventDefault();
        DV.history.save('text/p'+context.models.document.currentPage());
        states.ViewText();
      });

      $j('#DV-searchResults').delegate('span.DV-resultPrevious','click', $j.proxy(this.highlightPreviousMatch, this));

      $j('#DV-searchResults').delegate('span.DV-resultNext','click', $j.proxy(this.highlightNextMatch, this));


      var boundToggle           = $j.proxy(this.annotationBridgeToggle, this);
      var boundDrawConnector    = $j.proxy(this.annotationBridgeDrawConnector,this);
      var boundRemoveConnector  = $j.proxy(this.annotationBridgeRemoveConnector,this);
      var collection            = this.elements.collection;

      collection.delegate('span.DV-annotationTab','click', boundToggle);
      collection.delegate('span.DV-annotationTab','mouseover', boundDrawConnector);
      collection.delegate('span.DV-annotationTab','mouseout', boundRemoveConnector);

      collection.delegate('span.DV-annotationRegion','mouseover', boundDrawConnector);
      collection.delegate('span.DV-annotationRegion','mouseout', boundRemoveConnector);
      collection.delegate('span.DV-annotationRegion','click', $j.proxy(this.annotationBridgeShow, this));

      collection.delegate('span.DV-annotationNext','click', $j.proxy(this.annotationBridgeNext, this));
      collection.delegate('span.DV-annotationPrevious','click', $j.proxy(this.annotationBridgePrevious, this));
      collection.delegate('.DV-showEdit','click', $j.proxy(this.showAnnotationEdit, this));
      collection.delegate('.DV-cancelEdit','click', $j.proxy(this.cancelAnnotationEdit, this));
      collection.delegate('.DV-saveAnnotation','click', $j.proxy(this.saveAnnotation, this));
      collection.delegate('.DV-deleteAnnotation','click', $j.proxy(this.deleteAnnotation, this));

      $j('#DV-descriptionToggle').live('click',function(e){
        e.preventDefault();
        e.stopPropagation();

        $j('#DV-descriptionText').slideToggle(300,function(){
          $j('#DV-descriptionToggle').toggleClass('DV-showDescription');
        });
      });

      var cleanUp = $j.proxy(this.application.pageSet.cleanUp, this);


      this.elements.window.live('mousedown',
        function(e){
          var el = $j(e.target);
          if (el.parents().is('.DV-annotation') || el.is('.DV-annotation')) return true;
          if(context.elements.window.hasClass('DV-coverVisible')){
            if((el.width() - parseInt(e.clientX,10)) >= 15){
              cleanUp();
            }
          }
        }
      );

      if(jQuery.browser.msie == true){
        this.elements.browserDocument.bind('focus',$j.proxy(this.focusWindow,this));
        this.elements.browserDocument.bind('focusout',$j.proxy(this.focusOut,this));
      }else{
        this.elements.browserWindow.bind('focus',$j.proxy(this.focusWindow,this));
        this.elements.browserWindow.bind('blur',$j.proxy(this.blurWindow,this));
      }

      // When the document is scrolled, even in the background, resume polling.
      this.elements.window.bind('scroll', $j.proxy(this.focusWindow, this));

      this.elements.coverPages.live('mousedown', cleanUp);

      this.application.acceptInput = this.elements.currentPage.acceptInput({ changeCallBack: $j.proxy(this.acceptInputCallBack,this) });

    },
    startCheckTimer: function(){
      var _t = this.application;
      var _check = function(){
        _t.events.check();
      };
      this.application.checkTimer = setInterval(_check,100);
    },
    stopCheckTimer: function(){
      clearTimeout(this.application.checkTimer);
    },
    blurWindow: function(){
      if(this.application.isFocus === true){
        this.application.isFocus = false;
        // pause draw timer
        this.stopCheckTimer();
      }else{
        return;
      }
    },
    focusOut: function(){
      if(this.application.activeElement != document.activeElement){
        this.application.activeElement = document.activeElement;
        this.application.isFocus = true;
      }else{
        // pause draw timer
        this.application.isFocus = false;
        DV.controller.helpers.stopCheckTimer();
        return;
      }
    },
    focusWindow: function(){
      if(this.application.isFocus === true){
        return;
      }else{
        this.application.isFocus = true;
        // restart draw timer
        this.startCheckTimer();
      }
    },
    setDocHeight:   function(height,diff) {
      this.elements.window[0].scrollTop += diff;
      this.elements.bar.css('height', height);
    },
    getWindowDimensions: function(){

      var offset = (DV.options.embedded == true) ? 0 : parseInt($j(document.body).css('padding-top'), 10);

      var d = {
        height: (window.innerHeight ? window.innerHeight : this.elements.browserWindow.height()) - offset,
        width: this.elements.browserWindow.width()
      };
      return d;
    },

    // Is the given URL on a remote domain?
    isCrossDomain : function(url) {
      var match = url.match(this.HOST_EXTRACTOR);
      return match && (match[1] != window.location.host);
    },
    resetScrollState: function(){
      this.elements.window.scrollTop(0);
    },
{'fraction_non_alphanumeric': 0.16330314483348785, 'fraction_numerical': 0.0038508165157241673, 'mean_word_length': 3.1577230951675066, 'pattern_counts': {'":': 0, '<': 3, '<?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': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4879138', 'n_tokens_mistral': 4147, 'n_tokens_neox': 3953, 'n_words': 563}