materialize-sass 0.97.8 → 1.0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.gitattributes +1 -0
- data/.gitignore +1 -0
- data/README.md +34 -32
- data/Rakefile +38 -21
- data/assets/javascripts/materialize/anime.min.js +417 -0
- data/assets/javascripts/materialize/autocomplete.js +504 -0
- data/assets/javascripts/materialize/buttons.js +409 -0
- data/assets/javascripts/materialize/cards.js +34 -0
- data/assets/javascripts/materialize/carousel.js +797 -0
- data/assets/javascripts/materialize/cash.js +990 -0
- data/assets/javascripts/materialize/characterCounter.js +180 -0
- data/assets/javascripts/materialize/chips.js +564 -0
- data/assets/javascripts/materialize/collapsible.js +337 -0
- data/assets/javascripts/materialize/component.js +57 -0
- data/assets/javascripts/materialize/datepicker.js +935 -0
- data/assets/javascripts/materialize/dropdown.js +659 -0
- data/assets/javascripts/materialize/extras/nouislider.js +2147 -0
- data/assets/javascripts/materialize/extras/nouislider.min.js +1 -0
- data/assets/javascripts/materialize/forms.js +244 -0
- data/assets/javascripts/materialize/global.js +408 -0
- data/assets/javascripts/materialize/materialbox.js +513 -0
- data/assets/javascripts/materialize/modal.js +449 -0
- data/assets/javascripts/materialize/parallax.js +173 -0
- data/assets/javascripts/materialize/pushpin.js +179 -0
- data/assets/javascripts/materialize/range.js +310 -0
- data/assets/javascripts/materialize/scrollspy.js +328 -0
- data/assets/javascripts/materialize/select.js +497 -0
- data/assets/javascripts/materialize/sidenav.js +655 -0
- data/assets/javascripts/materialize/slider.js +424 -0
- data/assets/javascripts/materialize/tabs.js +476 -0
- data/assets/javascripts/materialize/tapTarget.js +364 -0
- data/assets/javascripts/materialize/timepicker.js +647 -0
- data/assets/javascripts/materialize/toasts.js +355 -0
- data/assets/javascripts/materialize/tooltip.js +351 -0
- data/{app/assets → assets}/javascripts/materialize/waves.js +42 -47
- data/{app/assets → assets}/javascripts/materialize-sprockets.js +12 -13
- data/assets/javascripts/materialize.js +12374 -0
- data/assets/stylesheets/materialize/components/_badges.scss +55 -0
- data/{app/assets → assets}/stylesheets/materialize/components/_buttons.scss +99 -58
- data/{app/assets → assets}/stylesheets/materialize/components/_cards.scss +14 -6
- data/{app/assets → assets}/stylesheets/materialize/components/_carousel.scss +12 -7
- data/{app/assets → assets}/stylesheets/materialize/components/_chips.scss +13 -6
- data/{app/assets → assets}/stylesheets/materialize/components/_collapsible.scss +16 -15
- data/assets/stylesheets/materialize/components/_color-classes.scss +32 -0
- data/{app/assets/stylesheets/materialize/components/_color.scss → assets/stylesheets/materialize/components/_color-variables.scss} +2 -44
- data/assets/stylesheets/materialize/components/_datepicker.scss +191 -0
- data/{app/assets → assets}/stylesheets/materialize/components/_dropdown.scss +35 -15
- data/{app/assets → assets}/stylesheets/materialize/components/_global.scss +96 -125
- data/{app/assets → assets}/stylesheets/materialize/components/_grid.scss +45 -36
- data/{app/assets → assets}/stylesheets/materialize/components/_icons-material-design.scss +0 -0
- data/{app/assets → assets}/stylesheets/materialize/components/_materialbox.scss +13 -12
- data/{app/assets → assets}/stylesheets/materialize/components/_modal.scss +7 -3
- data/{app/assets → assets}/stylesheets/materialize/components/_navbar.scss +29 -11
- data/assets/stylesheets/materialize/components/_normalize.scss +447 -0
- data/{app/assets → assets}/stylesheets/materialize/components/_preloader.scss +2 -2
- data/assets/stylesheets/materialize/components/_pulse.scss +34 -0
- data/{app/assets/stylesheets/materialize/components/_sideNav.scss → assets/stylesheets/materialize/components/_sidenav.scss} +47 -47
- data/{app/assets → assets}/stylesheets/materialize/components/_slider.scss +0 -0
- data/{app/assets → assets}/stylesheets/materialize/components/_table_of_contents.scss +5 -5
- data/{app/assets → assets}/stylesheets/materialize/components/_tabs.scss +10 -10
- data/assets/stylesheets/materialize/components/_tapTarget.scss +103 -0
- data/assets/stylesheets/materialize/components/_timepicker.scss +183 -0
- data/{app/assets → assets}/stylesheets/materialize/components/_toast.scss +7 -14
- data/{app/assets → assets}/stylesheets/materialize/components/_tooltip.scss +3 -3
- data/assets/stylesheets/materialize/components/_transitions.scss +13 -0
- data/{app/assets → assets}/stylesheets/materialize/components/_typography.scss +8 -9
- data/{app/assets → assets}/stylesheets/materialize/components/_variables.scss +65 -29
- data/assets/stylesheets/materialize/components/_waves.scss +114 -0
- data/{app/assets → assets}/stylesheets/materialize/components/forms/_checkboxes.scss +26 -46
- data/{app/assets → assets}/stylesheets/materialize/components/forms/_file-input.scss +6 -0
- data/{app/assets → assets}/stylesheets/materialize/components/forms/_forms.scss +0 -0
- data/{app/assets → assets}/stylesheets/materialize/components/forms/_input-fields.scss +131 -63
- data/assets/stylesheets/materialize/components/forms/_radio-buttons.scss +115 -0
- data/{app/assets → assets}/stylesheets/materialize/components/forms/_range.scss +35 -33
- data/{app/assets → assets}/stylesheets/materialize/components/forms/_select.scss +88 -19
- data/{app/assets → assets}/stylesheets/materialize/components/forms/_switches.scss +32 -21
- data/assets/stylesheets/materialize/extras/nouislider.css +406 -0
- data/{app/assets → assets}/stylesheets/materialize.scss +10 -9
- data/lib/materialize-sass/engine.rb +9 -7
- data/lib/materialize-sass/helpers.rb +38 -0
- data/lib/materialize-sass/version.rb +1 -1
- data/lib/materialize-sass.rb +13 -28
- data/materialize-sass.gemspec +5 -5
- metadata +97 -119
- data/app/assets/fonts/roboto/Roboto-Bold.eot +0 -0
- data/app/assets/fonts/roboto/Roboto-Bold.ttf +0 -0
- data/app/assets/fonts/roboto/Roboto-Bold.woff +0 -0
- data/app/assets/fonts/roboto/Roboto-Bold.woff2 +0 -0
- data/app/assets/fonts/roboto/Roboto-Light.eot +0 -0
- data/app/assets/fonts/roboto/Roboto-Light.ttf +0 -0
- data/app/assets/fonts/roboto/Roboto-Light.woff +0 -0
- data/app/assets/fonts/roboto/Roboto-Light.woff2 +0 -0
- data/app/assets/fonts/roboto/Roboto-Medium.eot +0 -0
- data/app/assets/fonts/roboto/Roboto-Medium.ttf +0 -0
- data/app/assets/fonts/roboto/Roboto-Medium.woff +0 -0
- data/app/assets/fonts/roboto/Roboto-Medium.woff2 +0 -0
- data/app/assets/fonts/roboto/Roboto-Regular.eot +0 -0
- data/app/assets/fonts/roboto/Roboto-Regular.ttf +0 -0
- data/app/assets/fonts/roboto/Roboto-Regular.woff +0 -0
- data/app/assets/fonts/roboto/Roboto-Regular.woff2 +0 -0
- data/app/assets/fonts/roboto/Roboto-Thin.eot +0 -0
- data/app/assets/fonts/roboto/Roboto-Thin.ttf +0 -0
- data/app/assets/fonts/roboto/Roboto-Thin.woff +0 -0
- data/app/assets/fonts/roboto/Roboto-Thin.woff2 +0 -0
- data/app/assets/javascripts/materialize/animation.js +0 -9
- data/app/assets/javascripts/materialize/buttons.js +0 -267
- data/app/assets/javascripts/materialize/cards.js +0 -26
- data/app/assets/javascripts/materialize/carousel.js +0 -454
- data/app/assets/javascripts/materialize/character_counter.js +0 -72
- data/app/assets/javascripts/materialize/chips.js +0 -289
- data/app/assets/javascripts/materialize/collapsible.js +0 -160
- data/app/assets/javascripts/materialize/date_picker/picker.date.js +0 -1430
- data/app/assets/javascripts/materialize/date_picker/picker.js +0 -1123
- data/app/assets/javascripts/materialize/dropdown.js +0 -265
- data/app/assets/javascripts/materialize/extras/nouislider.js +0 -1666
- data/app/assets/javascripts/materialize/extras/nouislider.min.js +0 -1
- data/app/assets/javascripts/materialize/forms.js +0 -682
- data/app/assets/javascripts/materialize/global.js +0 -98
- data/app/assets/javascripts/materialize/hammer.min.js +0 -1
- data/app/assets/javascripts/materialize/init.js +0 -174
- data/app/assets/javascripts/materialize/initial.js +0 -11
- data/app/assets/javascripts/materialize/jquery.easing.1.3.js +0 -205
- data/app/assets/javascripts/materialize/jquery.hammer.js +0 -33
- data/app/assets/javascripts/materialize/jquery.timeago.min.js +0 -1
- data/app/assets/javascripts/materialize/materialbox.js +0 -269
- data/app/assets/javascripts/materialize/modal.js +0 -184
- data/app/assets/javascripts/materialize/parallax.js +0 -58
- data/app/assets/javascripts/materialize/prism.js +0 -8
- data/app/assets/javascripts/materialize/pushpin.js +0 -71
- data/app/assets/javascripts/materialize/scrollFire.js +0 -48
- data/app/assets/javascripts/materialize/scrollspy.js +0 -284
- data/app/assets/javascripts/materialize/sideNav.js +0 -370
- data/app/assets/javascripts/materialize/slider.js +0 -321
- data/app/assets/javascripts/materialize/tabs.js +0 -164
- data/app/assets/javascripts/materialize/toasts.js +0 -137
- data/app/assets/javascripts/materialize/tooltip.js +0 -236
- data/app/assets/javascripts/materialize/transitions.js +0 -169
- data/app/assets/javascripts/materialize/velocity.min.js +0 -5
- data/app/assets/javascripts/materialize.js +0 -5
- data/app/assets/stylesheets/materialize/components/_mixins.scss +0 -5
- data/app/assets/stylesheets/materialize/components/_normalize.scss +0 -424
- data/app/assets/stylesheets/materialize/components/_prefixer.scss +0 -384
- data/app/assets/stylesheets/materialize/components/_roboto.scss +0 -49
- data/app/assets/stylesheets/materialize/components/_waves.scss +0 -177
- data/app/assets/stylesheets/materialize/components/date_picker/_default.date.scss +0 -435
- data/app/assets/stylesheets/materialize/components/date_picker/_default.scss +0 -201
- data/app/assets/stylesheets/materialize/components/date_picker/_default.time.scss +0 -125
- data/app/assets/stylesheets/materialize/components/forms/_radio-buttons.scss +0 -117
- data/app/assets/stylesheets/materialize/extras/nouislider.css +0 -259
@@ -1,289 +0,0 @@
|
|
1
|
-
(function ($) {
|
2
|
-
var chipsHandleEvents = false;
|
3
|
-
var materialChipsDefaults = {
|
4
|
-
data: [],
|
5
|
-
placeholder: '',
|
6
|
-
secondaryPlaceholder: '',
|
7
|
-
};
|
8
|
-
|
9
|
-
$(document).on('turbolinks:load', function() {
|
10
|
-
// Handle removal of static chips.
|
11
|
-
$(document).on('click', '.chip .close', function(e){
|
12
|
-
var $chips = $(this).closest('.chips');
|
13
|
-
if ($chips.attr('data-initialized')) {
|
14
|
-
return;
|
15
|
-
}
|
16
|
-
$(this).closest('.chip').remove();
|
17
|
-
});
|
18
|
-
});
|
19
|
-
|
20
|
-
$.fn.material_chip = function (options) {
|
21
|
-
var self = this;
|
22
|
-
this.$el = $(this);
|
23
|
-
this.$document = $(document);
|
24
|
-
this.SELS = {
|
25
|
-
CHIPS: '.chips',
|
26
|
-
CHIP: '.chip',
|
27
|
-
INPUT: 'input',
|
28
|
-
DELETE: '.material-icons',
|
29
|
-
SELECTED_CHIP: '.selected',
|
30
|
-
};
|
31
|
-
|
32
|
-
if ('data' === options) {
|
33
|
-
return this.$el.data('chips');
|
34
|
-
}
|
35
|
-
|
36
|
-
var curr_options = $.extend({}, materialChipsDefaults, options);
|
37
|
-
|
38
|
-
|
39
|
-
// Initialize
|
40
|
-
this.init = function() {
|
41
|
-
var i = 0;
|
42
|
-
var chips;
|
43
|
-
self.$el.each(function(){
|
44
|
-
var $chips = $(this);
|
45
|
-
var chipId = Materialize.guid();
|
46
|
-
|
47
|
-
if (!curr_options.data || !(curr_options.data instanceof Array)) {
|
48
|
-
curr_options.data = [];
|
49
|
-
}
|
50
|
-
$chips.data('chips', curr_options.data);
|
51
|
-
$chips.attr('data-index', i);
|
52
|
-
$chips.attr('data-initialized', true);
|
53
|
-
|
54
|
-
if (!$chips.hasClass(self.SELS.CHIPS)) {
|
55
|
-
$chips.addClass('chips');
|
56
|
-
}
|
57
|
-
|
58
|
-
self.chips($chips, chipId);
|
59
|
-
i++;
|
60
|
-
});
|
61
|
-
};
|
62
|
-
|
63
|
-
this.handleEvents = function(){
|
64
|
-
var SELS = self.SELS;
|
65
|
-
|
66
|
-
self.$document.off('click.chips-focus', SELS.CHIPS).on('click.chips-focus', SELS.CHIPS, function(e){
|
67
|
-
$(e.target).find(SELS.INPUT).focus();
|
68
|
-
});
|
69
|
-
|
70
|
-
self.$document.off('click.chips-select', SELS.CHIP).on('click.chips-select', SELS.CHIP, function(e){
|
71
|
-
$(SELS.CHIP).removeClass('selected');
|
72
|
-
$(this).toggleClass('selected');
|
73
|
-
});
|
74
|
-
|
75
|
-
self.$document.off('keydown.chips').on('keydown.chips', function(e){
|
76
|
-
if ($(e.target).is('input, textarea')) {
|
77
|
-
return;
|
78
|
-
}
|
79
|
-
|
80
|
-
// delete
|
81
|
-
var $chip = self.$document.find(SELS.CHIP + SELS.SELECTED_CHIP);
|
82
|
-
var $chips = $chip.closest(SELS.CHIPS);
|
83
|
-
var length = $chip.siblings(SELS.CHIP).length;
|
84
|
-
var index;
|
85
|
-
|
86
|
-
if (!$chip.length) {
|
87
|
-
return;
|
88
|
-
}
|
89
|
-
|
90
|
-
if (e.which === 8 || e.which === 46) {
|
91
|
-
e.preventDefault();
|
92
|
-
|
93
|
-
index = $chip.index();
|
94
|
-
self.deleteChip(index, $chips);
|
95
|
-
|
96
|
-
var selectIndex = null;
|
97
|
-
if ((index + 1) < length) {
|
98
|
-
selectIndex = index;
|
99
|
-
} else if (index === length || (index + 1) === length) {
|
100
|
-
selectIndex = length - 1;
|
101
|
-
}
|
102
|
-
|
103
|
-
if (selectIndex < 0) selectIndex = null;
|
104
|
-
|
105
|
-
if (null !== selectIndex) {
|
106
|
-
self.selectChip(selectIndex, $chips);
|
107
|
-
}
|
108
|
-
if (!length) $chips.find('input').focus();
|
109
|
-
|
110
|
-
// left
|
111
|
-
} else if (e.which === 37) {
|
112
|
-
index = $chip.index() - 1;
|
113
|
-
if (index < 0) {
|
114
|
-
return;
|
115
|
-
}
|
116
|
-
$(SELS.CHIP).removeClass('selected');
|
117
|
-
self.selectChip(index, $chips);
|
118
|
-
|
119
|
-
// right
|
120
|
-
} else if (e.which === 39) {
|
121
|
-
index = $chip.index() + 1;
|
122
|
-
$(SELS.CHIP).removeClass('selected');
|
123
|
-
if (index > length) {
|
124
|
-
$chips.find('input').focus();
|
125
|
-
return;
|
126
|
-
}
|
127
|
-
self.selectChip(index, $chips);
|
128
|
-
}
|
129
|
-
});
|
130
|
-
|
131
|
-
self.$document.off('focusin.chips', SELS.CHIPS + ' ' + SELS.INPUT).on('focusin.chips', SELS.CHIPS + ' ' + SELS.INPUT, function(e){
|
132
|
-
var $currChips = $(e.target).closest(SELS.CHIPS);
|
133
|
-
$currChips.addClass('focus');
|
134
|
-
$currChips.siblings('label, .prefix').addClass('active');
|
135
|
-
$(SELS.CHIP).removeClass('selected');
|
136
|
-
});
|
137
|
-
|
138
|
-
self.$document.off('focusout.chips', SELS.CHIPS + ' ' + SELS.INPUT).on('focusout.chips', SELS.CHIPS + ' ' + SELS.INPUT, function(e){
|
139
|
-
var $currChips = $(e.target).closest(SELS.CHIPS);
|
140
|
-
$currChips.removeClass('focus');
|
141
|
-
|
142
|
-
// Remove active if empty
|
143
|
-
if (!$currChips.data('chips').length) {
|
144
|
-
$currChips.siblings('label').removeClass('active');
|
145
|
-
}
|
146
|
-
$currChips.siblings('.prefix').removeClass('active');
|
147
|
-
});
|
148
|
-
|
149
|
-
self.$document.off('keydown.chips-add', SELS.CHIPS + ' ' + SELS.INPUT).on('keydown.chips-add', SELS.CHIPS + ' ' + SELS.INPUT, function(e){
|
150
|
-
var $target = $(e.target);
|
151
|
-
var $chips = $target.closest(SELS.CHIPS);
|
152
|
-
var chipsLength = $chips.children(SELS.CHIP).length;
|
153
|
-
|
154
|
-
// enter
|
155
|
-
if (13 === e.which) {
|
156
|
-
e.preventDefault();
|
157
|
-
self.addChip({tag: $target.val()}, $chips);
|
158
|
-
$target.val('');
|
159
|
-
return;
|
160
|
-
}
|
161
|
-
|
162
|
-
// delete or left
|
163
|
-
if ((8 === e.keyCode || 37 === e.keyCode) && '' === $target.val() && chipsLength) {
|
164
|
-
self.selectChip(chipsLength - 1, $chips);
|
165
|
-
$target.blur();
|
166
|
-
return;
|
167
|
-
}
|
168
|
-
});
|
169
|
-
|
170
|
-
// Click on delete icon in chip.
|
171
|
-
self.$document.off('click.chips-delete', SELS.CHIPS + ' ' + SELS.DELETE).on('click.chips-delete', SELS.CHIPS + ' ' + SELS.DELETE, function(e) {
|
172
|
-
var $target = $(e.target);
|
173
|
-
var $chips = $target.closest(SELS.CHIPS);
|
174
|
-
var $chip = $target.closest(SELS.CHIP);
|
175
|
-
e.stopPropagation();
|
176
|
-
self.deleteChip($chip.index(), $chips);
|
177
|
-
$chips.find('input').focus();
|
178
|
-
});
|
179
|
-
};
|
180
|
-
|
181
|
-
this.chips = function($chips, chipId) {
|
182
|
-
var html = '';
|
183
|
-
$chips.data('chips').forEach(function(elem){
|
184
|
-
html += self.renderChip(elem);
|
185
|
-
});
|
186
|
-
html += '<input id="' + chipId +'" class="input" placeholder="">';
|
187
|
-
$chips.html(html);
|
188
|
-
self.setPlaceholder($chips);
|
189
|
-
|
190
|
-
// Set for attribute for label
|
191
|
-
var label = $chips.next('label');
|
192
|
-
if (label.length) {
|
193
|
-
label.attr('for', chipId);
|
194
|
-
|
195
|
-
if ($chips.data('chips').length) {
|
196
|
-
label.addClass('active');
|
197
|
-
}
|
198
|
-
}
|
199
|
-
};
|
200
|
-
|
201
|
-
this.renderChip = function(elem) {
|
202
|
-
if (!elem.tag) return;
|
203
|
-
|
204
|
-
var html = '<div class="chip">' + elem.tag;
|
205
|
-
if (elem.image) {
|
206
|
-
html += ' <img src="' + elem.image + '"> ';
|
207
|
-
}
|
208
|
-
html += '<i class="material-icons close">close</i>';
|
209
|
-
html += '</div>';
|
210
|
-
return html;
|
211
|
-
};
|
212
|
-
|
213
|
-
this.setPlaceholder = function($chips) {
|
214
|
-
if ($chips.data('chips').length && curr_options.placeholder) {
|
215
|
-
$chips.find('input').prop('placeholder', curr_options.placeholder);
|
216
|
-
|
217
|
-
} else if (!$chips.data('chips').length && curr_options.secondaryPlaceholder) {
|
218
|
-
$chips.find('input').prop('placeholder', curr_options.secondaryPlaceholder);
|
219
|
-
}
|
220
|
-
};
|
221
|
-
|
222
|
-
this.isValid = function($chips, elem) {
|
223
|
-
var chips = $chips.data('chips');
|
224
|
-
var exists = false;
|
225
|
-
for (var i=0; i < chips.length; i++) {
|
226
|
-
if (chips[i].tag === elem.tag) {
|
227
|
-
exists = true;
|
228
|
-
return;
|
229
|
-
}
|
230
|
-
}
|
231
|
-
return '' !== elem.tag && !exists;
|
232
|
-
};
|
233
|
-
|
234
|
-
this.addChip = function(elem, $chips) {
|
235
|
-
if (!self.isValid($chips, elem)) {
|
236
|
-
return;
|
237
|
-
}
|
238
|
-
var chipHtml = self.renderChip(elem);
|
239
|
-
var newData = [];
|
240
|
-
var oldData = $chips.data('chips');
|
241
|
-
for (var i = 0; i < oldData.length; i++) {
|
242
|
-
newData.push(oldData[i]);
|
243
|
-
}
|
244
|
-
newData.push(elem);
|
245
|
-
|
246
|
-
$chips.data('chips', newData);
|
247
|
-
$(chipHtml).insertBefore($chips.find('input'));
|
248
|
-
$chips.trigger('chip.add', elem);
|
249
|
-
self.setPlaceholder($chips);
|
250
|
-
};
|
251
|
-
|
252
|
-
this.deleteChip = function(chipIndex, $chips) {
|
253
|
-
var chip = $chips.data('chips')[chipIndex];
|
254
|
-
$chips.find('.chip').eq(chipIndex).remove();
|
255
|
-
|
256
|
-
var newData = [];
|
257
|
-
var oldData = $chips.data('chips');
|
258
|
-
for (var i = 0; i < oldData.length; i++) {
|
259
|
-
if (i !== chipIndex) {
|
260
|
-
newData.push(oldData[i]);
|
261
|
-
}
|
262
|
-
}
|
263
|
-
|
264
|
-
$chips.data('chips', newData);
|
265
|
-
$chips.trigger('chip.delete', chip);
|
266
|
-
self.setPlaceholder($chips);
|
267
|
-
};
|
268
|
-
|
269
|
-
this.selectChip = function(chipIndex, $chips) {
|
270
|
-
var $chip = $chips.find('.chip').eq(chipIndex);
|
271
|
-
if ($chip && false === $chip.hasClass('selected')) {
|
272
|
-
$chip.addClass('selected');
|
273
|
-
$chips.trigger('chip.select', $chips.data('chips')[chipIndex]);
|
274
|
-
}
|
275
|
-
};
|
276
|
-
|
277
|
-
this.getChipsElement = function(index, $chips) {
|
278
|
-
return $chips.eq(index);
|
279
|
-
};
|
280
|
-
|
281
|
-
// init
|
282
|
-
this.init();
|
283
|
-
|
284
|
-
if (!chipsHandleEvents) {
|
285
|
-
this.handleEvents();
|
286
|
-
chipsHandleEvents = true;
|
287
|
-
}
|
288
|
-
};
|
289
|
-
}( jQuery ));
|
@@ -1,160 +0,0 @@
|
|
1
|
-
(function ($) {
|
2
|
-
$.fn.collapsible = function(options) {
|
3
|
-
var defaults = {
|
4
|
-
accordion: undefined,
|
5
|
-
onOpen: undefined,
|
6
|
-
onClose: undefined
|
7
|
-
};
|
8
|
-
|
9
|
-
options = $.extend(defaults, options);
|
10
|
-
|
11
|
-
|
12
|
-
return this.each(function() {
|
13
|
-
|
14
|
-
var $this = $(this);
|
15
|
-
|
16
|
-
var $panel_headers = $(this).find('> li > .collapsible-header');
|
17
|
-
|
18
|
-
var collapsible_type = $this.data("collapsible");
|
19
|
-
|
20
|
-
// Turn off any existing event handlers
|
21
|
-
$this.off('click.collapse', '> li > .collapsible-header');
|
22
|
-
$panel_headers.off('click.collapse');
|
23
|
-
|
24
|
-
|
25
|
-
/****************
|
26
|
-
Helper Functions
|
27
|
-
****************/
|
28
|
-
|
29
|
-
// Accordion Open
|
30
|
-
function accordionOpen(object) {
|
31
|
-
$panel_headers = $this.find('> li > .collapsible-header');
|
32
|
-
if (object.hasClass('active')) {
|
33
|
-
object.parent().addClass('active');
|
34
|
-
}
|
35
|
-
else {
|
36
|
-
object.parent().removeClass('active');
|
37
|
-
}
|
38
|
-
if (object.parent().hasClass('active')){
|
39
|
-
object.siblings('.collapsible-body').stop(true,false).slideDown({ duration: 350, easing: "easeOutQuart", queue: false, complete: function() {$(this).css('height', '');}});
|
40
|
-
}
|
41
|
-
else{
|
42
|
-
object.siblings('.collapsible-body').stop(true,false).slideUp({ duration: 350, easing: "easeOutQuart", queue: false, complete: function() {$(this).css('height', '');}});
|
43
|
-
}
|
44
|
-
|
45
|
-
$panel_headers.not(object).removeClass('active').parent().removeClass('active');
|
46
|
-
|
47
|
-
// Close previously open accordion elements.
|
48
|
-
$panel_headers.not(object).parent().children('.collapsible-body').stop(true,false).each(function() {
|
49
|
-
if ($(this).is(':visible')) {
|
50
|
-
$(this).slideUp({
|
51
|
-
duration: 350,
|
52
|
-
easing: "easeOutQuart",
|
53
|
-
queue: false,
|
54
|
-
complete:
|
55
|
-
function() {
|
56
|
-
$(this).css('height', '');
|
57
|
-
execCallbacks($(this).siblings('.collapsible-header'));
|
58
|
-
}
|
59
|
-
});
|
60
|
-
}
|
61
|
-
});
|
62
|
-
}
|
63
|
-
|
64
|
-
// Expandable Open
|
65
|
-
function expandableOpen(object) {
|
66
|
-
if (object.hasClass('active')) {
|
67
|
-
object.parent().addClass('active');
|
68
|
-
}
|
69
|
-
else {
|
70
|
-
object.parent().removeClass('active');
|
71
|
-
}
|
72
|
-
if (object.parent().hasClass('active')){
|
73
|
-
object.siblings('.collapsible-body').stop(true,false).slideDown({ duration: 350, easing: "easeOutQuart", queue: false, complete: function() {$(this).css('height', '');}});
|
74
|
-
}
|
75
|
-
else {
|
76
|
-
object.siblings('.collapsible-body').stop(true,false).slideUp({ duration: 350, easing: "easeOutQuart", queue: false, complete: function() {$(this).css('height', '');}});
|
77
|
-
}
|
78
|
-
}
|
79
|
-
|
80
|
-
// Open collapsible. object: .collapsible-header
|
81
|
-
function collapsibleOpen(object) {
|
82
|
-
if (options.accordion || collapsible_type === "accordion" || collapsible_type === undefined) { // Handle Accordion
|
83
|
-
accordionOpen(object);
|
84
|
-
} else { // Handle Expandables
|
85
|
-
expandableOpen(object);
|
86
|
-
}
|
87
|
-
|
88
|
-
execCallbacks(object);
|
89
|
-
}
|
90
|
-
|
91
|
-
// Handle callbacks
|
92
|
-
function execCallbacks(object) {
|
93
|
-
if (object.hasClass('active')) {
|
94
|
-
if (typeof(options.onOpen) === "function") {
|
95
|
-
options.onOpen.call(this, object.parent());
|
96
|
-
}
|
97
|
-
} else {
|
98
|
-
if (typeof(options.onClose) === "function") {
|
99
|
-
options.onClose.call(this, object.parent());
|
100
|
-
}
|
101
|
-
}
|
102
|
-
}
|
103
|
-
|
104
|
-
/**
|
105
|
-
* Check if object is children of panel header
|
106
|
-
* @param {Object} object Jquery object
|
107
|
-
* @return {Boolean} true if it is children
|
108
|
-
*/
|
109
|
-
function isChildrenOfPanelHeader(object) {
|
110
|
-
|
111
|
-
var panelHeader = getPanelHeader(object);
|
112
|
-
|
113
|
-
return panelHeader.length > 0;
|
114
|
-
}
|
115
|
-
|
116
|
-
/**
|
117
|
-
* Get panel header from a children element
|
118
|
-
* @param {Object} object Jquery object
|
119
|
-
* @return {Object} panel header object
|
120
|
-
*/
|
121
|
-
function getPanelHeader(object) {
|
122
|
-
|
123
|
-
return object.closest('li > .collapsible-header');
|
124
|
-
}
|
125
|
-
|
126
|
-
/***** End Helper Functions *****/
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
// Add click handler to only direct collapsible header children
|
131
|
-
$this.on('click.collapse', '> li > .collapsible-header', function(e) {
|
132
|
-
var element = $(e.target);
|
133
|
-
|
134
|
-
if (isChildrenOfPanelHeader(element)) {
|
135
|
-
element = getPanelHeader(element);
|
136
|
-
}
|
137
|
-
|
138
|
-
element.toggleClass('active');
|
139
|
-
|
140
|
-
collapsibleOpen(element);
|
141
|
-
});
|
142
|
-
|
143
|
-
|
144
|
-
// Open first active
|
145
|
-
if (options.accordion || collapsible_type === "accordion" || collapsible_type === undefined) { // Handle Accordion
|
146
|
-
collapsibleOpen($panel_headers.filter('.active').first());
|
147
|
-
|
148
|
-
} else { // Handle Expandables
|
149
|
-
$panel_headers.filter('.active').each(function() {
|
150
|
-
collapsibleOpen($(this));
|
151
|
-
});
|
152
|
-
}
|
153
|
-
|
154
|
-
});
|
155
|
-
};
|
156
|
-
|
157
|
-
$(document).on('turbolinks:load', function(){
|
158
|
-
$('.collapsible').collapsible();
|
159
|
-
});
|
160
|
-
}( jQuery ));
|