less-rails-semantic_ui 2.0.7.0 → 2.1.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/assets/fonts/semantic_ui/themes/github/assets/fonts/octicons-local.ttf +0 -0
- data/assets/fonts/semantic_ui/themes/github/assets/fonts/octicons.svg +200 -0
- data/assets/fonts/semantic_ui/themes/github/assets/fonts/octicons.ttf +0 -0
- data/assets/fonts/semantic_ui/themes/github/assets/fonts/octicons.woff +0 -0
- data/assets/javascripts/semantic_ui/definitions/behaviors/api.js +26 -8
- data/assets/javascripts/semantic_ui/definitions/behaviors/form.js +281 -74
- data/assets/javascripts/semantic_ui/definitions/globals/site.js +2 -2
- data/assets/javascripts/semantic_ui/definitions/modules/accordion.js +17 -13
- data/assets/javascripts/semantic_ui/definitions/modules/checkbox.js +124 -48
- data/assets/javascripts/semantic_ui/definitions/modules/dropdown.js +202 -112
- data/assets/javascripts/semantic_ui/definitions/modules/embed.js +1 -4
- data/assets/javascripts/semantic_ui/definitions/modules/modal.js +13 -13
- data/assets/javascripts/semantic_ui/definitions/modules/nag.js +11 -1
- data/assets/javascripts/semantic_ui/definitions/modules/popup.js +23 -10
- data/assets/javascripts/semantic_ui/definitions/modules/search.js +84 -55
- data/assets/javascripts/semantic_ui/definitions/modules/sticky.js +34 -32
- data/assets/javascripts/semantic_ui/definitions/modules/tab.js +10 -9
- data/assets/javascripts/semantic_ui/definitions/modules/transition.js +5 -5
- data/assets/stylesheets/semantic_ui/definitions/collections/breadcrumb.less +1 -1
- data/assets/stylesheets/semantic_ui/definitions/collections/form.less +90 -25
- data/assets/stylesheets/semantic_ui/definitions/collections/grid.less +146 -23
- data/assets/stylesheets/semantic_ui/definitions/collections/menu.less +138 -64
- data/assets/stylesheets/semantic_ui/definitions/collections/message.less +6 -6
- data/assets/stylesheets/semantic_ui/definitions/collections/table.less +19 -0
- data/assets/stylesheets/semantic_ui/definitions/elements/button.less +109 -31
- data/assets/stylesheets/semantic_ui/definitions/elements/container.less +25 -1
- data/assets/stylesheets/semantic_ui/definitions/elements/divider.less +4 -3
- data/assets/stylesheets/semantic_ui/definitions/elements/header.less +0 -2
- data/assets/stylesheets/semantic_ui/definitions/elements/icon.less +22 -3
- data/assets/stylesheets/semantic_ui/definitions/elements/input.less +59 -28
- data/assets/stylesheets/semantic_ui/definitions/elements/label.less +353 -235
- data/assets/stylesheets/semantic_ui/definitions/elements/list.less +16 -1
- data/assets/stylesheets/semantic_ui/definitions/elements/reveal.less +4 -11
- data/assets/stylesheets/semantic_ui/definitions/elements/segment.less +2 -1
- data/assets/stylesheets/semantic_ui/definitions/elements/step.less +9 -5
- data/assets/stylesheets/semantic_ui/definitions/globals/site.less +3 -0
- data/assets/stylesheets/semantic_ui/definitions/modules/dropdown.less +19 -1
- data/assets/stylesheets/semantic_ui/definitions/views/item.less +2 -2
- data/assets/stylesheets/semantic_ui/theme.less +10 -4
- data/assets/stylesheets/semantic_ui/themes/amazon/globals/site.variables +43 -0
- data/assets/stylesheets/semantic_ui/themes/bookish/elements/header.variables +5 -5
- data/assets/stylesheets/semantic_ui/themes/chubby/elements/header.variables +5 -5
- data/assets/stylesheets/semantic_ui/themes/default/collections/breadcrumb.variables +1 -1
- data/assets/stylesheets/semantic_ui/themes/default/collections/form.variables +15 -5
- data/assets/stylesheets/semantic_ui/themes/default/collections/grid.variables +5 -0
- data/assets/stylesheets/semantic_ui/themes/default/collections/menu.variables +29 -14
- data/assets/stylesheets/semantic_ui/themes/default/elements/button.variables +14 -4
- data/assets/stylesheets/semantic_ui/themes/default/elements/container.variables +14 -1
- data/assets/stylesheets/semantic_ui/themes/default/elements/icon.overrides +0 -12
- data/assets/stylesheets/semantic_ui/themes/default/elements/input.variables +5 -6
- data/assets/stylesheets/semantic_ui/themes/default/elements/label.variables +30 -6
- data/assets/stylesheets/semantic_ui/themes/default/globals/site.variables +11 -2
- data/assets/stylesheets/semantic_ui/themes/default/modules/checkbox.variables +4 -4
- data/assets/stylesheets/semantic_ui/themes/default/modules/dropdown.variables +13 -7
- data/assets/stylesheets/semantic_ui/themes/default/modules/popup.variables +1 -1
- data/assets/stylesheets/semantic_ui/themes/github/collections/breadcrumb.variables +11 -0
- data/assets/stylesheets/semantic_ui/themes/github/collections/grid.variables +2 -0
- data/assets/stylesheets/semantic_ui/themes/github/collections/table.variables +8 -0
- data/assets/stylesheets/semantic_ui/themes/github/elements/header.variables +9 -0
- data/assets/stylesheets/semantic_ui/themes/github/elements/icon.overrides +208 -0
- data/assets/stylesheets/semantic_ui/themes/github/elements/icon.variables +13 -0
- data/assets/stylesheets/semantic_ui/themes/github/elements/image.variables +5 -0
- data/assets/stylesheets/semantic_ui/themes/github/elements/input.overrides +32 -0
- data/assets/stylesheets/semantic_ui/themes/github/elements/input.variables +16 -0
- data/assets/stylesheets/semantic_ui/themes/github/elements/label.overrides +9 -0
- data/assets/stylesheets/semantic_ui/themes/github/elements/label.variables +4 -0
- data/assets/stylesheets/semantic_ui/themes/github/globals/site.variables +47 -0
- data/assets/stylesheets/semantic_ui/themes/github/modules/dropdown.overrides +53 -0
- data/assets/stylesheets/semantic_ui/themes/github/modules/dropdown.variables +35 -0
- data/assets/stylesheets/semantic_ui/themes/github/modules/popup.variables +12 -0
- data/assets/stylesheets/semantic_ui/themes/material/elements/button.overrides +0 -8
- data/assets/stylesheets/semantic_ui/themes/material/elements/button.variables +4 -2
- data/assets/stylesheets/semantic_ui/themes/twitter/elements/button.variables +1 -2
- data/lib/less/rails/semantic_ui/version.rb +1 -1
- metadata +22 -2
@@ -81,7 +81,7 @@ $.site = $.fn.site = function(parameters) {
|
|
81
81
|
requestAnimationFrame: function() {
|
82
82
|
module.debug('Normalizing requestAnimationFrame');
|
83
83
|
if(window.requestAnimationFrame === undefined) {
|
84
|
-
module.debug('RequestAnimationFrame not available,
|
84
|
+
module.debug('RequestAnimationFrame not available, normalizing event');
|
85
85
|
window.requestAnimationFrame = window.requestAnimationFrame
|
86
86
|
|| window.mozRequestAnimationFrame
|
87
87
|
|| window.webkitRequestAnimationFrame
|
@@ -484,4 +484,4 @@ $.extend($.expr[ ":" ], {
|
|
484
484
|
});
|
485
485
|
|
486
486
|
|
487
|
-
})( jQuery, window , document );
|
487
|
+
})( jQuery, window , document );
|
@@ -63,7 +63,9 @@ $.fn.accordion = function(parameters) {
|
|
63
63
|
initialize: function() {
|
64
64
|
module.debug('Initializing', $module);
|
65
65
|
module.bind.events();
|
66
|
-
|
66
|
+
if(settings.observeChanges) {
|
67
|
+
module.observeChanges();
|
68
|
+
}
|
67
69
|
module.instantiate();
|
68
70
|
},
|
69
71
|
|
@@ -546,22 +548,24 @@ $.fn.accordion.settings = {
|
|
546
548
|
verbose : false,
|
547
549
|
performance : true,
|
548
550
|
|
549
|
-
on : 'click',
|
551
|
+
on : 'click', // event on title that opens accordion
|
552
|
+
|
553
|
+
observeChanges : true, // whether accordion should automatically refresh on DOM insertion
|
550
554
|
|
551
|
-
exclusive : true,
|
552
|
-
collapsible : true,
|
553
|
-
closeNested : false,
|
554
|
-
animateChildren : true,
|
555
|
+
exclusive : true, // whether a single accordion content panel should be open at once
|
556
|
+
collapsible : true, // whether accordion content can be closed
|
557
|
+
closeNested : false, // whether nested content should be closed when a panel is closed
|
558
|
+
animateChildren : true, // whether children opacity should be animated
|
555
559
|
|
556
|
-
duration : 350,
|
557
|
-
easing : 'easeOutQuad',
|
560
|
+
duration : 350, // duration of animation
|
561
|
+
easing : 'easeOutQuad', // easing equation for animation
|
558
562
|
|
559
563
|
|
560
|
-
onOpening : function(){},
|
561
|
-
onOpen : function(){},
|
562
|
-
onClosing : function(){},
|
563
|
-
onClose : function(){},
|
564
|
-
onChange : function(){},
|
564
|
+
onOpening : function(){}, // callback before open animation
|
565
|
+
onOpen : function(){}, // callback after open animation
|
566
|
+
onClosing : function(){}, // callback before closing animation
|
567
|
+
onClose : function(){}, // callback after closing animation
|
568
|
+
onChange : function(){}, // callback after closing or opening animation
|
565
569
|
|
566
570
|
error: {
|
567
571
|
method : 'The method you called is not defined'
|
@@ -43,9 +43,10 @@ $.fn.checkbox = function(parameters) {
|
|
43
43
|
$module = $(this),
|
44
44
|
$label = $(this).children(selector.label),
|
45
45
|
$input = $(this).children(selector.input),
|
46
|
+
input = $input[0],
|
46
47
|
|
48
|
+
initialLoad = false,
|
47
49
|
shortcutPressed = false,
|
48
|
-
|
49
50
|
instance = $module.data(moduleNamespace),
|
50
51
|
|
51
52
|
observer,
|
@@ -95,35 +96,26 @@ $.fn.checkbox = function(parameters) {
|
|
95
96
|
},
|
96
97
|
|
97
98
|
setup: function() {
|
99
|
+
module.set.initialLoad();
|
98
100
|
if( module.is.indeterminate() ) {
|
99
101
|
module.debug('Initial value is indeterminate');
|
100
|
-
module.
|
101
|
-
if(settings.fireOnInit) {
|
102
|
-
settings.onIndeterminate.call($input[0]);
|
103
|
-
settings.onChange.call($input[0]);
|
104
|
-
}
|
102
|
+
module.indeterminate();
|
105
103
|
}
|
106
104
|
else if( module.is.checked() ) {
|
107
105
|
module.debug('Initial value is checked');
|
108
|
-
module.
|
109
|
-
if(settings.fireOnInit) {
|
110
|
-
settings.onChecked.call($input[0]);
|
111
|
-
settings.onChange.call($input[0]);
|
112
|
-
}
|
106
|
+
module.check();
|
113
107
|
}
|
114
108
|
else {
|
115
109
|
module.debug('Initial value is unchecked');
|
116
|
-
module.
|
117
|
-
if(settings.fireOnInit) {
|
118
|
-
settings.onUnchecked.call($input[0]);
|
119
|
-
settings.onChange.call($input[0]);
|
120
|
-
}
|
110
|
+
module.uncheck();
|
121
111
|
}
|
112
|
+
module.remove.initialLoad();
|
122
113
|
},
|
123
114
|
|
124
115
|
refresh: function() {
|
125
116
|
$label = $module.children(selector.label);
|
126
117
|
$input = $module.children(selector.input);
|
118
|
+
input = $input[0];
|
127
119
|
},
|
128
120
|
|
129
121
|
hide: {
|
@@ -174,10 +166,17 @@ $.fn.checkbox = function(parameters) {
|
|
174
166
|
|
175
167
|
event: {
|
176
168
|
click: function(event) {
|
177
|
-
|
169
|
+
var
|
170
|
+
$target = $(event.target)
|
171
|
+
;
|
172
|
+
if( $target.is(selector.input) ) {
|
178
173
|
module.verbose('Using default check action on initialized checkbox');
|
179
174
|
return;
|
180
175
|
}
|
176
|
+
if( $target.is(selector.link) ) {
|
177
|
+
module.debug('Clicking link inside checkbox, skipping toggle');
|
178
|
+
return;
|
179
|
+
}
|
181
180
|
module.toggle();
|
182
181
|
$input.focus();
|
183
182
|
event.preventDefault();
|
@@ -213,47 +212,53 @@ $.fn.checkbox = function(parameters) {
|
|
213
212
|
},
|
214
213
|
|
215
214
|
check: function() {
|
216
|
-
if( !module.
|
217
|
-
module.debug('Checkbox is already checked');
|
215
|
+
if( !module.should.allowCheck() ) {
|
218
216
|
return;
|
219
217
|
}
|
220
218
|
module.debug('Checking checkbox', $input);
|
221
219
|
module.set.checked();
|
222
|
-
|
223
|
-
|
220
|
+
if( !module.should.ignoreCallbacks() ) {
|
221
|
+
settings.onChecked.call(input);
|
222
|
+
settings.onChange.call(input);
|
223
|
+
}
|
224
224
|
},
|
225
225
|
|
226
226
|
uncheck: function() {
|
227
|
-
if( !module.
|
228
|
-
module.debug('Checkbox is already unchecked');
|
227
|
+
if( !module.should.allowUncheck() ) {
|
229
228
|
return;
|
230
229
|
}
|
231
230
|
module.debug('Unchecking checkbox');
|
232
231
|
module.set.unchecked();
|
233
|
-
|
234
|
-
|
232
|
+
if( !module.should.ignoreCallbacks() ) {
|
233
|
+
settings.onUnchecked.call(input);
|
234
|
+
settings.onChange.call(input);
|
235
|
+
}
|
235
236
|
},
|
236
237
|
|
237
238
|
indeterminate: function() {
|
238
|
-
if( module.
|
239
|
+
if( module.should.allowIndeterminate() ) {
|
239
240
|
module.debug('Checkbox is already indeterminate');
|
240
241
|
return;
|
241
242
|
}
|
242
243
|
module.debug('Making checkbox indeterminate');
|
243
244
|
module.set.indeterminate();
|
244
|
-
|
245
|
-
|
245
|
+
if( !module.should.ignoreCallbacks() ) {
|
246
|
+
settings.onIndeterminate.call(input);
|
247
|
+
settings.onChange.call(input);
|
248
|
+
}
|
246
249
|
},
|
247
250
|
|
248
251
|
determinate: function() {
|
249
|
-
if( module.
|
252
|
+
if( module.should.allowDeterminate() ) {
|
250
253
|
module.debug('Checkbox is already determinate');
|
251
254
|
return;
|
252
255
|
}
|
253
256
|
module.debug('Making checkbox determinate');
|
254
257
|
module.set.determinate();
|
255
|
-
|
256
|
-
|
258
|
+
if( !module.should.ignoreCallbacks() ) {
|
259
|
+
settings.onDeterminate.call(input);
|
260
|
+
settings.onChange.call(input);
|
261
|
+
}
|
257
262
|
},
|
258
263
|
|
259
264
|
enable: function() {
|
@@ -263,7 +268,7 @@ $.fn.checkbox = function(parameters) {
|
|
263
268
|
}
|
264
269
|
module.debug('Enabling checkbox');
|
265
270
|
module.set.enabled();
|
266
|
-
settings.onEnable.call(
|
271
|
+
settings.onEnable.call(input);
|
267
272
|
},
|
268
273
|
|
269
274
|
disable: function() {
|
@@ -273,7 +278,7 @@ $.fn.checkbox = function(parameters) {
|
|
273
278
|
}
|
274
279
|
module.debug('Disabling checkbox');
|
275
280
|
module.set.disabled();
|
276
|
-
settings.onDisable.call(
|
281
|
+
settings.onDisable.call(input);
|
277
282
|
},
|
278
283
|
|
279
284
|
get: {
|
@@ -292,6 +297,9 @@ $.fn.checkbox = function(parameters) {
|
|
292
297
|
},
|
293
298
|
|
294
299
|
is: {
|
300
|
+
initialLoad: function() {
|
301
|
+
return initialLoad;
|
302
|
+
},
|
295
303
|
radio: function() {
|
296
304
|
return ($input.hasClass(className.radio) || $input.attr('type') == 'radio');
|
297
305
|
},
|
@@ -315,6 +323,59 @@ $.fn.checkbox = function(parameters) {
|
|
315
323
|
}
|
316
324
|
},
|
317
325
|
|
326
|
+
should: {
|
327
|
+
allowCheck: function() {
|
328
|
+
if(module.is.determinate() && module.is.checked() && !module.should.forceCallbacks() ) {
|
329
|
+
module.debug('Should not allow check, checkbox is already checked');
|
330
|
+
return false;
|
331
|
+
}
|
332
|
+
if(settings.beforeChecked.apply(input) === false) {
|
333
|
+
module.debug('Should not allow check, beforeChecked cancelled');
|
334
|
+
return false;
|
335
|
+
}
|
336
|
+
return true;
|
337
|
+
},
|
338
|
+
allowUncheck: function() {
|
339
|
+
if(module.is.determinate() && module.is.unchecked() && !module.should.forceCallbacks() ) {
|
340
|
+
module.debug('Should not allow uncheck, checkbox is already unchecked');
|
341
|
+
return false;
|
342
|
+
}
|
343
|
+
if(settings.beforeUnchecked.apply(input) === false) {
|
344
|
+
module.debug('Should not allow uncheck, beforeUnchecked cancelled');
|
345
|
+
return false;
|
346
|
+
}
|
347
|
+
return true;
|
348
|
+
},
|
349
|
+
allowIndeterminate: function() {
|
350
|
+
if(module.is.indeterminate() && !module.should.forceCallbacks() ) {
|
351
|
+
module.debug('Should not allow indeterminate, checkbox is already indeterminate');
|
352
|
+
return false;
|
353
|
+
}
|
354
|
+
if(settings.beforeIndeterminate.apply(input) === false) {
|
355
|
+
module.debug('Should not allow indeterminate, beforeIndeterminate cancelled');
|
356
|
+
return false;
|
357
|
+
}
|
358
|
+
return true;
|
359
|
+
},
|
360
|
+
allowDeterminate: function() {
|
361
|
+
if(module.is.determinate() && !module.should.forceCallbacks() ) {
|
362
|
+
module.debug('Should not allow determinate, checkbox is already determinate');
|
363
|
+
return false;
|
364
|
+
}
|
365
|
+
if(settings.beforeDeterminate.apply(input) === false) {
|
366
|
+
module.debug('Should not allow determinate, beforeDeterminate cancelled');
|
367
|
+
return false;
|
368
|
+
}
|
369
|
+
return true;
|
370
|
+
},
|
371
|
+
forceCallbacks: function() {
|
372
|
+
return (module.is.initialLoad() && settings.fireOnInit);
|
373
|
+
},
|
374
|
+
ignoreCallbacks: function() {
|
375
|
+
return (initialLoad && !settings.fireOnInit);
|
376
|
+
}
|
377
|
+
},
|
378
|
+
|
318
379
|
can: {
|
319
380
|
change: function() {
|
320
381
|
return !( $module.hasClass(className.disabled) || $module.hasClass(className.readOnly) || $input.prop('disabled') || $input.prop('readonly') );
|
@@ -328,6 +389,9 @@ $.fn.checkbox = function(parameters) {
|
|
328
389
|
},
|
329
390
|
|
330
391
|
set: {
|
392
|
+
initialLoad: function() {
|
393
|
+
initialLoad = true;
|
394
|
+
},
|
331
395
|
checked: function() {
|
332
396
|
module.verbose('Setting class to checked');
|
333
397
|
$module
|
@@ -341,7 +405,7 @@ $.fn.checkbox = function(parameters) {
|
|
341
405
|
module.debug('Input is already checked, skipping input property change');
|
342
406
|
return;
|
343
407
|
}
|
344
|
-
module.verbose('Setting state to checked',
|
408
|
+
module.verbose('Setting state to checked', input);
|
345
409
|
$input
|
346
410
|
.prop('indeterminate', false)
|
347
411
|
.prop('checked', true)
|
@@ -430,6 +494,12 @@ $.fn.checkbox = function(parameters) {
|
|
430
494
|
}
|
431
495
|
},
|
432
496
|
|
497
|
+
remove: {
|
498
|
+
initialLoad: function() {
|
499
|
+
initialLoad = false;
|
500
|
+
}
|
501
|
+
},
|
502
|
+
|
433
503
|
trigger: {
|
434
504
|
change: function() {
|
435
505
|
module.verbose('Triggering change event from programmatic change');
|
@@ -682,27 +752,32 @@ $.fn.checkbox = function(parameters) {
|
|
682
752
|
|
683
753
|
$.fn.checkbox.settings = {
|
684
754
|
|
685
|
-
name
|
686
|
-
namespace
|
755
|
+
name : 'Checkbox',
|
756
|
+
namespace : 'checkbox',
|
687
757
|
|
688
|
-
debug
|
689
|
-
verbose
|
690
|
-
performance
|
758
|
+
debug : false,
|
759
|
+
verbose : true,
|
760
|
+
performance : true,
|
691
761
|
|
692
762
|
// delegated event context
|
693
|
-
uncheckable
|
694
|
-
fireOnInit
|
763
|
+
uncheckable : 'auto',
|
764
|
+
fireOnInit : false,
|
765
|
+
|
766
|
+
onChange : function(){},
|
695
767
|
|
696
|
-
|
768
|
+
beforeChecked : function(){},
|
769
|
+
beforeUnchecked : function(){},
|
770
|
+
beforeDeterminate : function(){},
|
771
|
+
beforeIndeterminate : function(){},
|
697
772
|
|
698
|
-
onChecked
|
699
|
-
onUnchecked
|
773
|
+
onChecked : function(){},
|
774
|
+
onUnchecked : function(){},
|
700
775
|
|
701
|
-
onDeterminate
|
702
|
-
onIndeterminate
|
776
|
+
onDeterminate : function() {},
|
777
|
+
onIndeterminate : function() {},
|
703
778
|
|
704
|
-
onEnabled
|
705
|
-
onDisabled
|
779
|
+
onEnabled : function(){},
|
780
|
+
onDisabled : function(){},
|
706
781
|
|
707
782
|
className : {
|
708
783
|
checked : 'checked',
|
@@ -721,6 +796,7 @@ $.fn.checkbox.settings = {
|
|
721
796
|
checkbox : '.ui.checkbox',
|
722
797
|
label : 'label, .box',
|
723
798
|
input : 'input[type="checkbox"], input[type="radio"]',
|
799
|
+
link : 'a[href]'
|
724
800
|
}
|
725
801
|
|
726
802
|
};
|
@@ -39,6 +39,7 @@ $.fn.dropdown = function(parameters) {
|
|
39
39
|
|
40
40
|
className = settings.className,
|
41
41
|
message = settings.message,
|
42
|
+
fields = settings.fields,
|
42
43
|
metadata = settings.metadata,
|
43
44
|
namespace = settings.namespace,
|
44
45
|
regExp = settings.regExp,
|
@@ -65,6 +66,7 @@ $.fn.dropdown = function(parameters) {
|
|
65
66
|
|
66
67
|
activated = false,
|
67
68
|
itemActivated = false,
|
69
|
+
internalChange = false,
|
68
70
|
element = this,
|
69
71
|
instance = $module.data(moduleNamespace),
|
70
72
|
|
@@ -93,11 +95,7 @@ $.fn.dropdown = function(parameters) {
|
|
93
95
|
module.restore.selected();
|
94
96
|
|
95
97
|
module.create.id();
|
96
|
-
|
97
|
-
module.bind.touchEvents();
|
98
|
-
}
|
99
|
-
module.bind.mouseEvents();
|
100
|
-
module.bind.keyboardEvents();
|
98
|
+
module.bind.events();
|
101
99
|
|
102
100
|
module.observeChanges();
|
103
101
|
module.instantiate();
|
@@ -183,10 +181,11 @@ $.fn.dropdown = function(parameters) {
|
|
183
181
|
;
|
184
182
|
$.each(values, function(index, value) {
|
185
183
|
if(module.get.item(value) === false) {
|
186
|
-
html = settings.templates.addition(value);
|
184
|
+
html = settings.templates.addition( module.add.variables(message.addResult, value) );
|
187
185
|
$userChoice = $('<div />')
|
188
186
|
.html(html)
|
189
|
-
.data
|
187
|
+
.attr('data-' + metadata.value, value)
|
188
|
+
.attr('data-' + metadata.text, value)
|
190
189
|
.addClass(className.addition)
|
191
190
|
.addClass(className.item)
|
192
191
|
;
|
@@ -211,6 +210,12 @@ $.fn.dropdown = function(parameters) {
|
|
211
210
|
});
|
212
211
|
}
|
213
212
|
},
|
213
|
+
menu: function() {
|
214
|
+
$menu = $('<div />')
|
215
|
+
.addClass(className.menu)
|
216
|
+
.appendTo($module)
|
217
|
+
;
|
218
|
+
}
|
214
219
|
},
|
215
220
|
|
216
221
|
search: function(query) {
|
@@ -268,6 +273,9 @@ $.fn.dropdown = function(parameters) {
|
|
268
273
|
module.setup.select();
|
269
274
|
module.setup.returnedObject();
|
270
275
|
}
|
276
|
+
if( !module.has.menu() ) {
|
277
|
+
module.create.menu();
|
278
|
+
}
|
271
279
|
if( module.is.search() && !module.has.search() ) {
|
272
280
|
module.verbose('Adding search input');
|
273
281
|
$search = $('<input />')
|
@@ -278,12 +286,6 @@ $.fn.dropdown = function(parameters) {
|
|
278
286
|
if(settings.allowTab) {
|
279
287
|
module.set.tabbable();
|
280
288
|
}
|
281
|
-
if($menu.length === 0) {
|
282
|
-
$menu = $('<div />')
|
283
|
-
.addClass(className.menu)
|
284
|
-
.appendTo($module)
|
285
|
-
;
|
286
|
-
}
|
287
289
|
},
|
288
290
|
select: function() {
|
289
291
|
var
|
@@ -297,7 +299,10 @@ $.fn.dropdown = function(parameters) {
|
|
297
299
|
if($input.parent(selector.dropdown).length > 0) {
|
298
300
|
module.debug('UI dropdown already exists. Creating dropdown menu only');
|
299
301
|
$module = $input.closest(selector.dropdown);
|
300
|
-
|
302
|
+
if( !module.has.menu() ) {
|
303
|
+
module.create.menu();
|
304
|
+
}
|
305
|
+
$menu = $module.children(selector.menu);
|
301
306
|
module.setup.menu(selectValues);
|
302
307
|
}
|
303
308
|
else {
|
@@ -316,6 +321,10 @@ $.fn.dropdown = function(parameters) {
|
|
316
321
|
if($input.is('[multiple]')) {
|
317
322
|
module.set.multiple();
|
318
323
|
}
|
324
|
+
if ($input.prop('disabled')) {
|
325
|
+
module.debug('Disabling dropdown')
|
326
|
+
$module.addClass(className.disabled)
|
327
|
+
}
|
319
328
|
$input
|
320
329
|
.removeAttr('class')
|
321
330
|
.detach()
|
@@ -325,7 +334,7 @@ $.fn.dropdown = function(parameters) {
|
|
325
334
|
module.refresh();
|
326
335
|
},
|
327
336
|
menu: function(values) {
|
328
|
-
$menu.html( templates.menu(
|
337
|
+
$menu.html( templates.menu(values, fields));
|
329
338
|
$item = $menu.find(selector.item);
|
330
339
|
},
|
331
340
|
reference: function() {
|
@@ -382,7 +391,6 @@ $.fn.dropdown = function(parameters) {
|
|
382
391
|
;
|
383
392
|
},
|
384
393
|
|
385
|
-
|
386
394
|
toggle: function() {
|
387
395
|
module.verbose('Toggling menu visibility');
|
388
396
|
if( !module.is.active() ) {
|
@@ -400,19 +408,21 @@ $.fn.dropdown = function(parameters) {
|
|
400
408
|
;
|
401
409
|
if( module.can.show() && !module.is.active() ) {
|
402
410
|
module.debug('Showing dropdown');
|
403
|
-
if(module.is.multiple()) {
|
404
|
-
|
405
|
-
|
406
|
-
|
411
|
+
if(module.is.multiple() && !module.has.search() && module.is.allFiltered()) {
|
412
|
+
return true;
|
413
|
+
}
|
414
|
+
if(module.has.message() && !module.has.maxSelections()) {
|
415
|
+
module.remove.message();
|
416
|
+
}
|
417
|
+
if(settings.onShow.call(element) !== false) {
|
418
|
+
module.animate.show(function() {
|
419
|
+
if( module.can.click() ) {
|
420
|
+
module.bind.intent();
|
421
|
+
}
|
422
|
+
module.set.visible();
|
423
|
+
callback.call(element);
|
424
|
+
});
|
407
425
|
}
|
408
|
-
module.animate.show(function() {
|
409
|
-
if( module.can.click() ) {
|
410
|
-
module.bind.intent();
|
411
|
-
}
|
412
|
-
module.set.visible();
|
413
|
-
callback.call(element);
|
414
|
-
});
|
415
|
-
settings.onShow.call(element);
|
416
426
|
}
|
417
427
|
},
|
418
428
|
|
@@ -423,11 +433,12 @@ $.fn.dropdown = function(parameters) {
|
|
423
433
|
;
|
424
434
|
if( module.is.active() ) {
|
425
435
|
module.debug('Hiding dropdown');
|
426
|
-
|
427
|
-
module.
|
428
|
-
|
429
|
-
|
430
|
-
|
436
|
+
if(settings.onHide.call(element) !== false) {
|
437
|
+
module.animate.hide(function() {
|
438
|
+
module.remove.visible();
|
439
|
+
callback.call(element);
|
440
|
+
});
|
441
|
+
}
|
431
442
|
}
|
432
443
|
},
|
433
444
|
|
@@ -456,8 +467,30 @@ $.fn.dropdown = function(parameters) {
|
|
456
467
|
},
|
457
468
|
|
458
469
|
bind: {
|
470
|
+
events: function() {
|
471
|
+
if(hasTouch) {
|
472
|
+
module.bind.touchEvents();
|
473
|
+
}
|
474
|
+
module.bind.keyboardEvents();
|
475
|
+
module.bind.inputEvents();
|
476
|
+
module.bind.mouseEvents();
|
477
|
+
},
|
478
|
+
touchEvents: function() {
|
479
|
+
module.debug('Touch device detected binding additional touch events');
|
480
|
+
if( module.is.searchSelection() ) {
|
481
|
+
// do nothing special yet
|
482
|
+
}
|
483
|
+
else if( module.is.single() ) {
|
484
|
+
$module
|
485
|
+
.on('touchstart' + eventNamespace, module.event.test.toggle)
|
486
|
+
;
|
487
|
+
}
|
488
|
+
$menu
|
489
|
+
.on('touchstart' + eventNamespace, selector.item, module.event.item.mouseenter)
|
490
|
+
;
|
491
|
+
},
|
459
492
|
keyboardEvents: function() {
|
460
|
-
module.
|
493
|
+
module.verbose('Binding keyboard events');
|
461
494
|
$module
|
462
495
|
.on('keydown' + eventNamespace, module.event.keydown)
|
463
496
|
;
|
@@ -472,25 +505,17 @@ $.fn.dropdown = function(parameters) {
|
|
472
505
|
;
|
473
506
|
}
|
474
507
|
},
|
475
|
-
|
476
|
-
module.
|
477
|
-
|
478
|
-
|
479
|
-
}
|
480
|
-
else if( module.is.single() ) {
|
481
|
-
$module
|
482
|
-
.on('touchstart' + eventNamespace, module.event.test.toggle)
|
483
|
-
;
|
484
|
-
}
|
485
|
-
$menu
|
486
|
-
.on('touchstart' + eventNamespace, selector.item, module.event.item.mouseenter)
|
508
|
+
inputEvents: function() {
|
509
|
+
module.verbose('Binding input change events');
|
510
|
+
$module
|
511
|
+
.on('change' + eventNamespace, selector.input, module.event.change)
|
487
512
|
;
|
488
513
|
},
|
489
514
|
mouseEvents: function() {
|
490
|
-
module.
|
515
|
+
module.verbose('Binding mouse events');
|
491
516
|
if(module.is.multiple()) {
|
492
517
|
$module
|
493
|
-
.on('click' + eventNamespace, selector.label,
|
518
|
+
.on('click' + eventNamespace, selector.label, module.event.label.click)
|
494
519
|
.on('click' + eventNamespace, selector.remove, module.event.remove.click)
|
495
520
|
;
|
496
521
|
}
|
@@ -627,7 +652,6 @@ $.fn.dropdown = function(parameters) {
|
|
627
652
|
apiSettings = {
|
628
653
|
errorDuration : false,
|
629
654
|
throttle : settings.throttle,
|
630
|
-
cache : 'local',
|
631
655
|
urlData : {
|
632
656
|
query: query
|
633
657
|
},
|
@@ -668,7 +692,7 @@ $.fn.dropdown = function(parameters) {
|
|
668
692
|
beginsWithRegExp = new RegExp('^' + escapedTerm, 'igm')
|
669
693
|
;
|
670
694
|
// avoid loop if we're matching nothing
|
671
|
-
if(
|
695
|
+
if( !module.has.query() ) {
|
672
696
|
$results = $item;
|
673
697
|
}
|
674
698
|
else {
|
@@ -706,7 +730,6 @@ $.fn.dropdown = function(parameters) {
|
|
706
730
|
})
|
707
731
|
;
|
708
732
|
}
|
709
|
-
|
710
733
|
module.debug('Showing only matched items', searchTerm);
|
711
734
|
module.remove.filteredItem();
|
712
735
|
$item
|
@@ -765,7 +788,7 @@ $.fn.dropdown = function(parameters) {
|
|
765
788
|
: $activeItem,
|
766
789
|
hasSelected = ($selectedItem.size() > 0)
|
767
790
|
;
|
768
|
-
if(hasSelected) {
|
791
|
+
if( hasSelected && module.has.query() ) {
|
769
792
|
module.debug('Forcing partial selection to selected item', $selectedItem);
|
770
793
|
module.event.item.click.call($selectedItem);
|
771
794
|
}
|
@@ -775,6 +798,12 @@ $.fn.dropdown = function(parameters) {
|
|
775
798
|
},
|
776
799
|
|
777
800
|
event: {
|
801
|
+
change: function() {
|
802
|
+
if(!internalChange) {
|
803
|
+
module.debug('Input changed, updating selection');
|
804
|
+
module.set.selected();
|
805
|
+
}
|
806
|
+
},
|
778
807
|
focus: function() {
|
779
808
|
if(settings.showOnFocus && !activated && module.is.hidden() && !pageLostFocus) {
|
780
809
|
module.show();
|
@@ -796,7 +825,7 @@ $.fn.dropdown = function(parameters) {
|
|
796
825
|
module.hide();
|
797
826
|
}
|
798
827
|
},
|
799
|
-
// prevents focus callback from
|
828
|
+
// prevents focus callback from occurring on mousedown
|
800
829
|
mousedown: function() {
|
801
830
|
activated = true;
|
802
831
|
},
|
@@ -827,6 +856,11 @@ $.fn.dropdown = function(parameters) {
|
|
827
856
|
module.hide();
|
828
857
|
}
|
829
858
|
}
|
859
|
+
else if(pageLostFocus) {
|
860
|
+
if(settings.forceSelection) {
|
861
|
+
module.forceSelection();
|
862
|
+
}
|
863
|
+
}
|
830
864
|
}
|
831
865
|
},
|
832
866
|
icon: {
|
@@ -903,7 +937,9 @@ $.fn.dropdown = function(parameters) {
|
|
903
937
|
touch: function(event) {
|
904
938
|
module.determine.eventOnElement(event, function() {
|
905
939
|
if(event.type == 'touchstart') {
|
906
|
-
module.timer = setTimeout(
|
940
|
+
module.timer = setTimeout(function() {
|
941
|
+
module.hide();
|
942
|
+
}, settings.delay.touch);
|
907
943
|
}
|
908
944
|
else if(event.type == 'touchmove') {
|
909
945
|
clearTimeout(module.timer);
|
@@ -953,15 +989,17 @@ $.fn.dropdown = function(parameters) {
|
|
953
989
|
}, settings.delay.hide);
|
954
990
|
}
|
955
991
|
},
|
992
|
+
touchend: function() {
|
993
|
+
},
|
956
994
|
click: function (event) {
|
957
995
|
var
|
958
|
-
$choice
|
959
|
-
$target
|
996
|
+
$choice = $(this),
|
997
|
+
$target = (event)
|
960
998
|
? $(event.target)
|
961
999
|
: $(''),
|
962
|
-
$subMenu
|
963
|
-
text
|
964
|
-
value
|
1000
|
+
$subMenu = $choice.find(selector.menu),
|
1001
|
+
text = module.get.choiceText($choice),
|
1002
|
+
value = module.get.choiceValue($choice, text),
|
965
1003
|
hasSubMenu = ($subMenu.length > 0),
|
966
1004
|
isBubbledEvent = ($subMenu.find($target).length > 0)
|
967
1005
|
;
|
@@ -988,7 +1026,7 @@ $.fn.dropdown = function(parameters) {
|
|
988
1026
|
var
|
989
1027
|
$label = $module.find(selector.label),
|
990
1028
|
$activeLabel = $label.filter('.' + className.active),
|
991
|
-
activeValue = $activeLabel.data(
|
1029
|
+
activeValue = $activeLabel.data(metadata.value),
|
992
1030
|
labelIndex = $label.index($activeLabel),
|
993
1031
|
labelCount = $label.length,
|
994
1032
|
hasActiveLabel = ($activeLabel.length > 0),
|
@@ -1114,6 +1152,7 @@ $.fn.dropdown = function(parameters) {
|
|
1114
1152
|
hasSubMenu = ($subMenu.length> 0),
|
1115
1153
|
hasSelectedItem = ($selectedItem.length > 0),
|
1116
1154
|
selectedIsSelectable = ($selectedItem.not(selector.unselectable).length > 0),
|
1155
|
+
delimiterPressed = (pressedKey == keys.delimiter && settings.allowAdditions && module.is.multiple()),
|
1117
1156
|
$nextItem,
|
1118
1157
|
isSubMenuItem,
|
1119
1158
|
newIndex
|
@@ -1123,7 +1162,7 @@ $.fn.dropdown = function(parameters) {
|
|
1123
1162
|
if( module.is.visible() ) {
|
1124
1163
|
|
1125
1164
|
// enter (select or open sub-menu)
|
1126
|
-
if(pressedKey == keys.enter ||
|
1165
|
+
if(pressedKey == keys.enter || delimiterPressed) {
|
1127
1166
|
if(pressedKey == keys.enter && hasSelectedItem && hasSubMenu && !settings.allowCategorySelection) {
|
1128
1167
|
module.verbose('Pressed enter on unselectable category, opening sub menu');
|
1129
1168
|
pressedKey = keys.rightArrow;
|
@@ -1240,7 +1279,7 @@ $.fn.dropdown = function(parameters) {
|
|
1240
1279
|
}
|
1241
1280
|
else {
|
1242
1281
|
// delimiter key
|
1243
|
-
if(
|
1282
|
+
if(delimiterPressed) {
|
1244
1283
|
event.preventDefault();
|
1245
1284
|
}
|
1246
1285
|
// down arrow (open menu)
|
@@ -1351,7 +1390,8 @@ $.fn.dropdown = function(parameters) {
|
|
1351
1390
|
module.hideAndClear();
|
1352
1391
|
},
|
1353
1392
|
|
1354
|
-
hide: function() {
|
1393
|
+
hide: function(text, value) {
|
1394
|
+
module.set.value(value);
|
1355
1395
|
module.hideAndClear();
|
1356
1396
|
}
|
1357
1397
|
|
@@ -1361,6 +1401,15 @@ $.fn.dropdown = function(parameters) {
|
|
1361
1401
|
id: function() {
|
1362
1402
|
return id;
|
1363
1403
|
},
|
1404
|
+
defaultText: function() {
|
1405
|
+
return $module.data(metadata.defaultText);
|
1406
|
+
},
|
1407
|
+
defaultValue: function() {
|
1408
|
+
return $module.data(metadata.defaultValue);
|
1409
|
+
},
|
1410
|
+
placeholderText: function() {
|
1411
|
+
return $module.data(metadata.placeholderText) || '';
|
1412
|
+
},
|
1364
1413
|
text: function() {
|
1365
1414
|
return $text.text();
|
1366
1415
|
},
|
@@ -1509,8 +1558,8 @@ $.fn.dropdown = function(parameters) {
|
|
1509
1558
|
return ($choice.data(metadata.text) !== undefined)
|
1510
1559
|
? $choice.data(metadata.text)
|
1511
1560
|
: (preserveHTML)
|
1512
|
-
? $choice.html()
|
1513
|
-
: $choice.text()
|
1561
|
+
? $.trim($choice.html())
|
1562
|
+
: $.trim($choice.text())
|
1514
1563
|
;
|
1515
1564
|
}
|
1516
1565
|
},
|
@@ -1520,10 +1569,10 @@ $.fn.dropdown = function(parameters) {
|
|
1520
1569
|
return false;
|
1521
1570
|
}
|
1522
1571
|
return ($choice.data(metadata.value) !== undefined)
|
1523
|
-
? $choice.data(metadata.value)
|
1572
|
+
? String( $choice.data(metadata.value) )
|
1524
1573
|
: (typeof choiceText === 'string')
|
1525
|
-
? choiceText.toLowerCase()
|
1526
|
-
: choiceText
|
1574
|
+
? $.trim(choiceText.toLowerCase())
|
1575
|
+
: String(choiceText)
|
1527
1576
|
;
|
1528
1577
|
},
|
1529
1578
|
inputEvent: function() {
|
@@ -1626,7 +1675,7 @@ $.fn.dropdown = function(parameters) {
|
|
1626
1675
|
;
|
1627
1676
|
shouldSearch = (isMultiple)
|
1628
1677
|
? (value.length > 0)
|
1629
|
-
: (value !== undefined && value !==
|
1678
|
+
: (value !== undefined && value !== null)
|
1630
1679
|
;
|
1631
1680
|
isMultiple = (module.is.multiple() && $.isArray(value));
|
1632
1681
|
strict = (value === '' || value === 0)
|
@@ -1646,7 +1695,7 @@ $.fn.dropdown = function(parameters) {
|
|
1646
1695
|
return;
|
1647
1696
|
}
|
1648
1697
|
if(isMultiple) {
|
1649
|
-
if($.inArray(optionValue
|
1698
|
+
if($.inArray( String(optionValue), value) !== -1 || $.inArray(optionText, value) !== -1) {
|
1650
1699
|
$selectedItem = ($selectedItem)
|
1651
1700
|
? $selectedItem.add($choice)
|
1652
1701
|
: $choice
|
@@ -1661,7 +1710,7 @@ $.fn.dropdown = function(parameters) {
|
|
1661
1710
|
}
|
1662
1711
|
}
|
1663
1712
|
else {
|
1664
|
-
if( optionValue
|
1713
|
+
if( String(optionValue) == String(value) || optionText == value) {
|
1665
1714
|
module.verbose('Found select item by value', optionValue, value);
|
1666
1715
|
$selectedItem = $choice;
|
1667
1716
|
return true;
|
@@ -1711,15 +1760,21 @@ $.fn.dropdown = function(parameters) {
|
|
1711
1760
|
},
|
1712
1761
|
defaultText: function() {
|
1713
1762
|
var
|
1714
|
-
defaultText
|
1763
|
+
defaultText = module.get.defaultText(),
|
1764
|
+
placeholderText = module.get.placeholderText
|
1715
1765
|
;
|
1716
|
-
|
1717
|
-
|
1718
|
-
|
1766
|
+
if(defaultText === placeholderText) {
|
1767
|
+
module.debug('Restoring default placeholder text', defaultText);
|
1768
|
+
module.set.placeholderText(defaultText);
|
1769
|
+
}
|
1770
|
+
else {
|
1771
|
+
module.debug('Restoring default text', defaultText);
|
1772
|
+
module.set.text(defaultText);
|
1773
|
+
}
|
1719
1774
|
},
|
1720
1775
|
defaultValue: function() {
|
1721
1776
|
var
|
1722
|
-
defaultValue =
|
1777
|
+
defaultValue = module.get.defaultValue()
|
1723
1778
|
;
|
1724
1779
|
if(defaultValue !== undefined) {
|
1725
1780
|
module.debug('Restoring default value', defaultValue);
|
@@ -1831,7 +1886,7 @@ $.fn.dropdown = function(parameters) {
|
|
1831
1886
|
var
|
1832
1887
|
text
|
1833
1888
|
;
|
1834
|
-
if($text.hasClass(className.placeholder)) {
|
1889
|
+
if(settings.placeholder !== false && $text.hasClass(className.placeholder)) {
|
1835
1890
|
text = module.get.text();
|
1836
1891
|
module.verbose('Saving placeholder text as', text);
|
1837
1892
|
$module.data(metadata.placeholderText, text);
|
@@ -1865,8 +1920,8 @@ $.fn.dropdown = function(parameters) {
|
|
1865
1920
|
|
1866
1921
|
scrollPage: function(direction, $selectedItem) {
|
1867
1922
|
var
|
1868
|
-
$
|
1869
|
-
$menu = $
|
1923
|
+
$currentItem = $selectedItem || module.get.selectedItem(),
|
1924
|
+
$menu = $currentItem.closest(selector.menu),
|
1870
1925
|
menuHeight = $menu.outerHeight(),
|
1871
1926
|
currentScroll = $menu.scrollTop(),
|
1872
1927
|
itemHeight = $item.eq(0).outerHeight(),
|
@@ -1881,8 +1936,8 @@ $.fn.dropdown = function(parameters) {
|
|
1881
1936
|
elementIndex
|
1882
1937
|
;
|
1883
1938
|
elementIndex = (direction == 'up')
|
1884
|
-
? $selectableItem.index($
|
1885
|
-
: $selectableItem.index($
|
1939
|
+
? $selectableItem.index($currentItem) - itemsPerPage
|
1940
|
+
: $selectableItem.index($currentItem) + itemsPerPage
|
1886
1941
|
;
|
1887
1942
|
isWithinRange = (direction == 'up')
|
1888
1943
|
? (elementIndex >= 0)
|
@@ -1896,7 +1951,7 @@ $.fn.dropdown = function(parameters) {
|
|
1896
1951
|
;
|
1897
1952
|
if($nextSelectedItem.length > 0) {
|
1898
1953
|
module.debug('Scrolling page', direction, $nextSelectedItem);
|
1899
|
-
$
|
1954
|
+
$currentItem
|
1900
1955
|
.removeClass(className.selected)
|
1901
1956
|
;
|
1902
1957
|
$nextSelectedItem
|
@@ -1938,12 +1993,10 @@ $.fn.dropdown = function(parameters) {
|
|
1938
1993
|
$module.addClass(className.loading);
|
1939
1994
|
},
|
1940
1995
|
placeholderText: function(text) {
|
1941
|
-
text = text ||
|
1942
|
-
|
1943
|
-
|
1944
|
-
|
1945
|
-
$text.addClass(className.placeholder);
|
1946
|
-
}
|
1996
|
+
text = text || module.get.placeholderText();
|
1997
|
+
module.debug('Setting placeholder text', text);
|
1998
|
+
module.set.text(text);
|
1999
|
+
$text.addClass(className.placeholder);
|
1947
2000
|
},
|
1948
2001
|
tabbable: function() {
|
1949
2002
|
if( module.has.search() ) {
|
@@ -1972,6 +2025,14 @@ $.fn.dropdown = function(parameters) {
|
|
1972
2025
|
module.verbose('Setting initial load');
|
1973
2026
|
initialLoad = true;
|
1974
2027
|
},
|
2028
|
+
activeItem: function($item) {
|
2029
|
+
if( settings.allowAdditions && $item.filter(selector.addition).length > 0 ) {
|
2030
|
+
$item.addClass(className.filtered);
|
2031
|
+
}
|
2032
|
+
else {
|
2033
|
+
$item.addClass(className.active);
|
2034
|
+
}
|
2035
|
+
},
|
1975
2036
|
scrollPosition: function($item, forceScroll) {
|
1976
2037
|
var
|
1977
2038
|
edgeTolerance = 5,
|
@@ -2026,10 +2087,12 @@ $.fn.dropdown = function(parameters) {
|
|
2026
2087
|
}
|
2027
2088
|
}
|
2028
2089
|
else {
|
2090
|
+
if(text !== module.get.placeholderText()) {
|
2091
|
+
$text.removeClass(className.placeholder);
|
2092
|
+
}
|
2029
2093
|
module.debug('Changing text', text, $text);
|
2030
2094
|
$text
|
2031
2095
|
.removeClass(className.filtered)
|
2032
|
-
.removeClass(className.placeholder)
|
2033
2096
|
;
|
2034
2097
|
if(settings.preserveHTML) {
|
2035
2098
|
$text.html(text);
|
@@ -2095,8 +2158,8 @@ $.fn.dropdown = function(parameters) {
|
|
2095
2158
|
hasInput = ($input.length > 0),
|
2096
2159
|
isAddition = !module.has.value(value),
|
2097
2160
|
currentValue = module.get.values(),
|
2098
|
-
stringValue = (
|
2099
|
-
? value
|
2161
|
+
stringValue = (value !== undefined)
|
2162
|
+
? String(value)
|
2100
2163
|
: value,
|
2101
2164
|
newValue
|
2102
2165
|
;
|
@@ -2113,15 +2176,22 @@ $.fn.dropdown = function(parameters) {
|
|
2113
2176
|
module.add.optionValue(value);
|
2114
2177
|
}
|
2115
2178
|
module.debug('Updating input value', value, currentValue);
|
2179
|
+
internalChange = true;
|
2116
2180
|
$input
|
2117
2181
|
.val(value)
|
2118
|
-
.trigger('change')
|
2119
2182
|
;
|
2183
|
+
if(settings.fireOnInit === false && module.is.initialLoad()) {
|
2184
|
+
module.debug('Input native change event ignored on initial load');
|
2185
|
+
}
|
2186
|
+
else {
|
2187
|
+
$input.trigger('change');
|
2188
|
+
}
|
2189
|
+
internalChange = false;
|
2120
2190
|
}
|
2121
2191
|
else {
|
2122
2192
|
module.verbose('Storing value in metadata', value, $input);
|
2123
2193
|
if(value !== currentValue) {
|
2124
|
-
$module.data(metadata.value,
|
2194
|
+
$module.data(metadata.value, stringValue);
|
2125
2195
|
}
|
2126
2196
|
}
|
2127
2197
|
if(settings.fireOnInit === false && module.is.initialLoad()) {
|
@@ -2188,14 +2258,14 @@ $.fn.dropdown = function(parameters) {
|
|
2188
2258
|
if(settings.useLabels) {
|
2189
2259
|
module.add.value(selectedValue, selectedText, $selected);
|
2190
2260
|
module.add.label(selectedValue, selectedText, shouldAnimate);
|
2191
|
-
$selected
|
2261
|
+
module.set.activeItem($selected);
|
2192
2262
|
module.filterActive();
|
2193
2263
|
module.select.nextAvailable($selectedItem);
|
2194
2264
|
}
|
2195
2265
|
else {
|
2196
2266
|
module.add.value(selectedValue, selectedText, $selected);
|
2197
2267
|
module.set.text(module.add.variables(message.count));
|
2198
|
-
$selected
|
2268
|
+
module.set.activeItem($selected);
|
2199
2269
|
}
|
2200
2270
|
}
|
2201
2271
|
else if(!isFiltered) {
|
@@ -2308,7 +2378,8 @@ $.fn.dropdown = function(parameters) {
|
|
2308
2378
|
userSuggestion: function(value) {
|
2309
2379
|
var
|
2310
2380
|
$addition = $menu.children(selector.addition),
|
2311
|
-
|
2381
|
+
$existingItem = module.get.item(value),
|
2382
|
+
alreadyHasValue = $existingItem && $existingItem.not(selector.addition).length,
|
2312
2383
|
hasUserSuggestion = $addition.length > 0,
|
2313
2384
|
html
|
2314
2385
|
;
|
@@ -2323,10 +2394,11 @@ $.fn.dropdown = function(parameters) {
|
|
2323
2394
|
.removeClass(className.selected)
|
2324
2395
|
;
|
2325
2396
|
if(hasUserSuggestion) {
|
2326
|
-
html = settings.templates.addition(value);
|
2397
|
+
html = settings.templates.addition( module.add.variables(message.addResult, value) );
|
2327
2398
|
$addition
|
2328
2399
|
.html(html)
|
2329
|
-
.data
|
2400
|
+
.attr('data-' + metadata.value, value)
|
2401
|
+
.attr('data-' + metadata.text, value)
|
2330
2402
|
.removeClass(className.filtered)
|
2331
2403
|
.addClass(className.selected)
|
2332
2404
|
;
|
@@ -2341,7 +2413,7 @@ $.fn.dropdown = function(parameters) {
|
|
2341
2413
|
module.verbose('Adding item choice to menu corresponding with user choice addition', $addition);
|
2342
2414
|
}
|
2343
2415
|
},
|
2344
|
-
variables: function(message) {
|
2416
|
+
variables: function(message, term) {
|
2345
2417
|
var
|
2346
2418
|
hasCount = (message.search('{count}') !== -1),
|
2347
2419
|
hasMaxCount = (message.search('{maxCount}') !== -1),
|
@@ -2360,7 +2432,7 @@ $.fn.dropdown = function(parameters) {
|
|
2360
2432
|
message = message.replace('{maxCount}', settings.maxSelections);
|
2361
2433
|
}
|
2362
2434
|
if(hasTerm) {
|
2363
|
-
query = module.get.query();
|
2435
|
+
query = term || module.get.query();
|
2364
2436
|
message = message.replace('{term}', query);
|
2365
2437
|
}
|
2366
2438
|
return message;
|
@@ -2395,7 +2467,7 @@ $.fn.dropdown = function(parameters) {
|
|
2395
2467
|
}
|
2396
2468
|
|
2397
2469
|
if(settings.fireOnInit === false && module.is.initialLoad()) {
|
2398
|
-
module.verbose('
|
2470
|
+
module.verbose('Skipping onadd callback on initial load', settings.onAdd);
|
2399
2471
|
}
|
2400
2472
|
else {
|
2401
2473
|
settings.onAdd.call(element, addedValue, addedText, $selectedItem);
|
@@ -2432,7 +2504,7 @@ $.fn.dropdown = function(parameters) {
|
|
2432
2504
|
if(settings.useLabels && module.has.maxSelections() ) {
|
2433
2505
|
return;
|
2434
2506
|
}
|
2435
|
-
if(settings.useLabels) {
|
2507
|
+
if(settings.useLabels && module.is.multiple()) {
|
2436
2508
|
$item.not('.' + className.active).removeClass(className.filtered);
|
2437
2509
|
}
|
2438
2510
|
else {
|
@@ -2493,7 +2565,12 @@ $.fn.dropdown = function(parameters) {
|
|
2493
2565
|
}
|
2494
2566
|
else {
|
2495
2567
|
module.remove.value(selectedValue, selectedText, $selected);
|
2496
|
-
|
2568
|
+
if(module.get.selectionCount() === 0) {
|
2569
|
+
module.set.placeholderText();
|
2570
|
+
}
|
2571
|
+
else {
|
2572
|
+
module.set.text(module.add.variables(message.count));
|
2573
|
+
}
|
2497
2574
|
}
|
2498
2575
|
}
|
2499
2576
|
else {
|
@@ -2565,16 +2642,19 @@ $.fn.dropdown = function(parameters) {
|
|
2565
2642
|
$labels
|
2566
2643
|
.each(function(){
|
2567
2644
|
var
|
2568
|
-
value = $(this).data(
|
2569
|
-
|
2645
|
+
value = $(this).data(metadata.value),
|
2646
|
+
stringValue = (value !== undefined)
|
2647
|
+
? String(value)
|
2648
|
+
: value,
|
2649
|
+
isUserValue = module.is.userValue(stringValue)
|
2570
2650
|
;
|
2571
2651
|
if(isUserValue) {
|
2572
|
-
module.remove.value(
|
2573
|
-
module.remove.label(
|
2652
|
+
module.remove.value(stringValue);
|
2653
|
+
module.remove.label(stringValue);
|
2574
2654
|
}
|
2575
2655
|
else {
|
2576
2656
|
// selected will also remove label
|
2577
|
-
module.remove.selected(
|
2657
|
+
module.remove.selected(stringValue);
|
2578
2658
|
}
|
2579
2659
|
})
|
2580
2660
|
;
|
@@ -2645,6 +2725,9 @@ $.fn.dropdown = function(parameters) {
|
|
2645
2725
|
allResultsFiltered: function() {
|
2646
2726
|
return ($item.filter(selector.unselectable).length === $item.length);
|
2647
2727
|
},
|
2728
|
+
query: function() {
|
2729
|
+
return (module.get.query() !== '');
|
2730
|
+
},
|
2648
2731
|
value: function(value) {
|
2649
2732
|
var
|
2650
2733
|
values = module.get.values(),
|
@@ -3151,7 +3234,7 @@ $.fn.dropdown.settings = {
|
|
3151
3234
|
|
3152
3235
|
maxSelections : false, // When set to a number limits the number of selections to this count
|
3153
3236
|
useLabels : true, // whether multiple select should filter currently active selections from choices
|
3154
|
-
delimiter : ',', // when multiselect uses normal <input> the values will be
|
3237
|
+
delimiter : ',', // when multiselect uses normal <input> the values will be delimited with this character
|
3155
3238
|
|
3156
3239
|
showOnFocus : true, // show menu on focus
|
3157
3240
|
allowTab : true, // add tabindex to element
|
@@ -3225,6 +3308,13 @@ $.fn.dropdown.settings = {
|
|
3225
3308
|
value : 'value'
|
3226
3309
|
},
|
3227
3310
|
|
3311
|
+
// property names for remote query
|
3312
|
+
fields: {
|
3313
|
+
values : 'values', // grouping for all dropdown values
|
3314
|
+
name : 'name', // displayed dropdown text
|
3315
|
+
value : 'value' // actual dropdown value
|
3316
|
+
},
|
3317
|
+
|
3228
3318
|
selector : {
|
3229
3319
|
addition : '.addition',
|
3230
3320
|
dropdown : '.ui.dropdown',
|
@@ -3295,13 +3385,13 @@ $.fn.dropdown.settings.templates = {
|
|
3295
3385
|
},
|
3296
3386
|
|
3297
3387
|
// generates just menu from select
|
3298
|
-
menu: function(response) {
|
3388
|
+
menu: function(response, fields) {
|
3299
3389
|
var
|
3300
3390
|
values = response.values || {},
|
3301
3391
|
html = ''
|
3302
3392
|
;
|
3303
|
-
$.each(response.values, function(index, option) {
|
3304
|
-
html += '<div class="item" data-value="' + option.value + '">' + option.name + '</div>';
|
3393
|
+
$.each(response[fields.values], function(index, option) {
|
3394
|
+
html += '<div class="item" data-value="' + option[fields.value] + '">' + option[fields.name] + '</div>';
|
3305
3395
|
});
|
3306
3396
|
return html;
|
3307
3397
|
},
|