ru-se.com

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs

number.js (1642B)


      1 wp.customize.controlConstructor['kirki-number'] = wp.customize.Control.extend({
      2 
      3     ready: function () {
      4 
      5         'use strict';
      6 
      7         var control = this,
      8             element = this.container.find('input'),
      9             min = -99999,
     10             max = 99999,
     11             step = 1;
     12 
     13         // Set minimum value.
     14         if ('undefined' !== typeof control.params.choices && 'undefined' !== typeof control.params.choices.min) {
     15             min = control.params.choices.min;
     16         }
     17 
     18         // Set maximum value.
     19         if ('undefined' !== typeof control.params.choices && 'undefined' !== typeof control.params.choices.max) {
     20             max = control.params.choices.max;
     21         }
     22 
     23         // Set step value.
     24         if ('undefined' !== typeof control.params.choices && 'undefined' !== typeof control.params.choices.step) {
     25             step = control.params.choices.step;
     26             if ('any' === control.params.choices.step) {
     27                 step = '0.001';
     28             }
     29         }
     30 
     31         // Init the spinner
     32         jQuery(element).spinner({
     33             min: min,
     34             max: max,
     35             step: step
     36         });
     37 
     38         // On change
     39 
     40         var lastValue = undefined;
     41 
     42         var onChange = _.debounce(function () {
     43             var value = jQuery(element).val();
     44             if (lastValue !== value) {
     45                 lastValue = value;
     46                 control.setting.set(value);
     47             }
     48         }, 600);
     49 
     50 
     51         this.container.on('mousedown keydown', 'input', function () {
     52             lastValue = this.value;
     53         });
     54 
     55 
     56         this.container.on('change click keyup paste', 'input', onChange);
     57 
     58     }
     59 
     60 });