blob: ac6ffda0e6afa85fba6b6adc61a6fda8a28a58ff (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
|
tuskar.number_picker = (function () {
'use strict';
var module = {};
module.init = function () {
$('input.number-picker').removeClass(
'form-control').wrap(
'<div class="number_picker unselectable form-control">').before(
'<a class="arrow-left" href="#">' +
'<i class="fa fa-chevron-left"></i></a>').after(
'<a class="arrow-right" href="#">' +
'<i class="fa fa-chevron-right"></i></a>').each(
function () {
var $this = $(this);
var $right_arrow = $this.next('a.arrow-right');
var $left_arrow = $this.prev('a.arrow-left');
if ($this.attr('readonly')) {
$this.parent().addClass('readonly');
}
function change(step) {
var value = +$this.val();
var maximum = +$this.attr('max');
var minimum = +$this.attr('min');
value += step;
if (!isNaN(maximum)) { value = Math.min(maximum, value); }
if (!isNaN(minimum)) { value = Math.max(minimum, value); }
$right_arrow.toggleClass('disabled', (value === maximum));
$left_arrow.toggleClass('disabled', (value === minimum));
$this.val(value);
$this.trigger('change');
}
$right_arrow.click(function () {
var step = +($this.attr('step') || 1);
change(step);
});
$left_arrow.click(function () {
var step = -($this.attr('step') || 1);
change(step);
});
change(0);
var step = +($this.attr('step') || 1);
if (step !== 1) {
$this.after('<span class="step">+' + step + '</span>');
}
});
};
horizon.addInitFunction(module.init);
return module;
} ());
|