-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapplication.js
129 lines (109 loc) · 3.57 KB
/
application.js
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
// Some general UI pack related JS
// Extend JS String with repeat method
String.prototype.repeat = function (num) {
return new Array(Math.round(num) + 1).join(this);
};
(function ($) {
// Add segments to a slider
$.fn.addSliderSegments = function () {
return this.each(function () {
var $this = $(this),
option = $this.slider('option'),
amount = (option.max - option.min)/option.step,
orientation = option.orientation;
if ( 'vertical' === orientation ) {
var output = '', i;
console.log(amount);
for (i = 1; i <= amount - 1; i++) {
output += '<div class="ui-slider-segment" style="top:' + 100 / amount * i + '%;"></div>';
}
$this.prepend(output);
} else {
var segmentGap = 100 / (amount) + '%';
var segment = '<div class="ui-slider-segment" style="margin-left: ' + segmentGap + ';"></div>';
$this.prepend(segment.repeat(amount - 1));
}
});
};
$(function () {
// Todo list
$('.todo').on('click', 'li', function () {
$(this).toggleClass('todo-done');
});
// Custom Selects
if ($('[data-toggle="select"]').length) {
$('[data-toggle="select"]').select2();
}
// Checkboxes and Radio buttons
$('[data-toggle="checkbox"]').radiocheck();
$('[data-toggle="radio"]').radiocheck();
// Tooltips
$('[data-toggle=tooltip]').tooltip('show');
// jQuery UI Sliders
var $slider = $('#slider');
if ($slider.length > 0) {
$slider.slider({
max: 15,
step: 6,
value: 3,
orientation: 'horizontal',
range: 'min'
}).addSliderSegments();
}
var $verticalSlider = $('#vertical-slider');
if ($verticalSlider.length) {
$verticalSlider.slider({
min: 1,
max: 5,
value: 3,
orientation: 'vertical',
range: 'min'
}).addSliderSegments($verticalSlider.slider('option').max, 'vertical');
}
// Focus state for append/prepend inputs
$('.input-group').on('focus', '.form-control', function () {
$(this).closest('.input-group, .form-group').addClass('focus');
}).on('blur', '.form-control', function () {
$(this).closest('.input-group, .form-group').removeClass('focus');
});
// Make pagination demo work
$('.pagination').on('click', 'a', function () {
$(this).parent().siblings('li').removeClass('active').end().addClass('active');
});
$('.btn-group').on('click', 'a', function () {
$(this).siblings().removeClass('active').end().addClass('active');
});
// Disable link clicks to prevent page scrolling
$(document).on('click', 'a[href="#fakelink"]', function (e) {
e.preventDefault();
});
// Switches
if ($('[data-toggle="switch"]').length) {
$('[data-toggle="switch"]').bootstrapSwitch();
}
// Typeahead
if ($('#typeahead-demo-01').length) {
var states = new Bloodhound({
datumTokenizer: function (d) { return Bloodhound.tokenizers.whitespace(d.word); },
queryTokenizer: Bloodhound.tokenizers.whitespace,
limit: 4,
local: [
{ word: 'Alabama' },
{ word: 'Alaska' },
{ word: 'Arizona' },
{ word: 'Arkansas' },
{ word: 'California' },
{ word: 'Colorado' }
]
});
states.initialize();
$('#typeahead-demo-01').typeahead(null, {
name: 'states',
displayKey: 'word',
source: states.ttAdapter()
});
}
// make code pretty
window.prettyPrint && prettyPrint();
});
})(jQuery);