<commit_before>'use strict';

/* Directives */

/**
 * <inline model='page.text' action='updateDb'/>
 */
zdrojak.directive('inline', function(){
  var KEY_CODE_ENTER = 13;
  return {
    restrict: 'E',
    replace: true,
    scope: {
      action: '=action',
      model: '=model',
      textarea: '@textarea'
    },
    template: 
      '<div>' +
        '<span ng-hide="mode">{{model}}</span>' +
        '<input type="text" ng-show="mode && !textarea" ng-model="model" required>' +
        '<textarea ng-show="mode && textarea" ng-model="model"></textarea>' +
      '</div>',
    link: function(scope, element) {
      var children = element.children();
      var span  = angular.element(children[0]);
      var input = angular.element(children[1]);
      var area  = angular.element(children[2]);
      
      //puvodni obsah
      var oldContent;
      
      //zmenit editaci na text a zavolat akci po editaci
      function send() {
        var newContent = element.text().trim();
        if (newContent !== '') {
          scope.$apply('mode=false');    
        }
        if (newContent !== oldContent) {
          scope.action();  
        }    
      }
      
      function focusInput() {
        input[0].focus();    
      }
      
      function focusArea() {
        area[0].focus();    
      }
      
      function focus() {
        scope.textarea ? focusArea(): focusInput();
      }
      
      function blur() {
        if (!scope.mode) return;
        send();      
      }
      
      function enter(e) {
        if (!scope.mode) return;
        if (e.charCode === KEY_CODE_ENTER) {
          send();       
        }  
      }
      
      //ztrata focusu, ulozit zmenu
      input.bind('blur', blur);
      area.bind('blur', blur);
      
      //uzivatel kliknul na enter, ulozit zmenu
      input.bind('keypress', enter);
      
      //po kliknuti na text zobrazit input pro editaci
      span.bind('click', function(){
        oldContent = element.text().trim();
        scope.$apply('mode=true');
        focus();
      });
    }
  }
});

/**
 * <range change="filter" min="{{params.minPrice}}" max="{{params.maxPrice}}" step="500" model="price">
 */
zdrojak.directive('range', function(){
  return {
    restrict: 'E',
    replace: true,
    scope: {
      max: '@max',
      min: '@min',
      model: '=model',
      change: '=change'
    },
    template: '<input type="range" ng-model="model">',
    link: function(scope, element) {
      element.bind('change', function(){
        //TODO: pridat setTimeout, nevolat behem posunovani
        scope.change();
      });   
    }
  }
});<commit_msg>Nenacitat obsah produktu v kategorii po kazdem kroku pri praci se sliderem<commit_after>'use strict';

/* Directives */

/**
 * <inline model='page.text' action='updateDb'/>
 */
zdrojak.directive('inline', function(){
  var KEY_CODE_ENTER = 13;
  return {
    restrict: 'E',
    replace: true,
    scope: {
      action: '=action',
      model: '=model',
      textarea: '@textarea'
    },
    template: 
      '<div>' +
        '<span ng-hide="mode">{{model}}</span>' +
        '<input type="text" ng-show="mode && !textarea" ng-model="model" required>' +
        '<textarea ng-show="mode && textarea" ng-model="model"></textarea>' +
      '</div>',
    link: function(scope, element) {
      var children = element.children();
      var span  = angular.element(children[0]);
      var input = angular.element(children[1]);
      var area  = angular.element(children[2]);
      
      //puvodni obsah
      var oldContent;
      
      //zmenit editaci na text a zavolat akci po editaci
      function send() {
        var newContent = element.text().trim();
        if (newContent !== '') {
          scope.$apply('mode=false');    
        }
        if (newContent !== oldContent) {
          scope.action();  
        }    
      }
      
      function focusInput() {
        input[0].focus();    
      }
      
      function focusArea() {
        area[0].focus();    
      }
      
      function focus() {
        scope.textarea ? focusArea(): focusInput();
      }
      
      function blur() {
        if (!scope.mode) return;
        send();      
      }
      
      function enter(e) {
        if (!scope.mode) return;
        if (e.charCode === KEY_CODE_ENTER) {
          send();       
        }  
      }
      
      //ztrata focusu, ulozit zmenu
      input.bind('blur', blur);
      area.bind('blur', blur);
      
      //uzivatel kliknul na enter, ulozit zmenu
      input.bind('keypress', enter);
      
      //po kliknuti na text zobrazit input pro editaci
      span.bind('click', function(){
        oldContent = element.text().trim();
        scope.$apply('mode=true');
        focus();
      });
    }
  }
});

/**
 * <range change="filter" min="{{params.minPrice}}" max="{{params.maxPrice}}" step="500" model="price">
 */
zdrojak.directive('range', function(){
  return {
    restrict: 'E',
    replace: true,
    scope: {
      max: '@max',
      min: '@min',
      model: '=model',
      change: '=change'
    },
    template: '<input type="range" ng-model="model">',
    link: function(scope, element) {
      var timer;
      element.bind('change', function(){
        if (timer) clearInterval(timer);
        timer = setTimeout(scope.change, 200);
      });   
    }
  }
});
{'fraction_non_alphanumeric': 0.16654191616766467, 'fraction_numerical': 0.004303892215568862, 'mean_word_length': 1.9563053097345133, 'pattern_counts': {'":': 0, '<': 23, '<?xml version=': 0, '>': 23, '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': '3359350', 'n_tokens_mistral': 1674, 'n_tokens_neox': 1661, 'n_words': 356}