selectivity-rails 0.1.7 → 0.1.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f9962649945a0f217355e4e18ea370d25b1aec02
|
4
|
+
data.tar.gz: 7e58ef158675932c42c21c7683d0030fabd2bdae
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d5bd4d195d05ddee4d51a35234ae4e7db8d4da1980573dac036a3fcb426ff33bd2605f3941da9d072f3111872a6caccbccb09e7de0ebf561dd0fc56b2e60c885
|
7
|
+
data.tar.gz: 3e0a5c418e0efbda4a8815e4d7e7c7cc3a7b7fabd32e3b0df2e1d99e35220b754cc85d02d556c7e57e2e42e72a03ef0b9d7d2da6719d35ddfedf726323a678bb
|
data/lib/selectivity/rspec.rb
CHANGED
@@ -37,11 +37,17 @@ module Selectivity
|
|
37
37
|
private
|
38
38
|
|
39
39
|
def find_selectivity_input(from, options)
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
40
|
+
label = first(:xpath, ".//label[contains(., '#{from}')]", options)
|
41
|
+
if label.present?
|
42
|
+
find(:div, "##{label[:for]}", options)
|
43
|
+
else
|
44
|
+
target = first(:xpath, ".//div[contains(., '#{from}')]", options) || first(:div, from, options)
|
45
|
+
if target[:class].include?('selectivity-input')
|
46
|
+
target
|
47
|
+
else
|
48
|
+
target.first('.selectivity-input')
|
49
|
+
end
|
50
|
+
end
|
45
51
|
end
|
46
52
|
|
47
53
|
def _selectivity_multiselect?(input)
|
@@ -1,3 +1,10 @@
|
|
1
|
+
/**
|
2
|
+
* @license
|
3
|
+
* Selectivity.js 2.1.0 <https://arendjr.github.io/selectivity/>
|
4
|
+
* Copyright (c) 2014-2016 Arend van Beelen jr.
|
5
|
+
* (c) 2016 Speakap BV
|
6
|
+
* Available under MIT license <https://github.com/arendjr/selectivity/blob/master/LICENSE>
|
7
|
+
*/
|
1
8
|
!function(e){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=e();else if("function"==typeof define&&define.amd)define([],e);else{var f;"undefined"!=typeof window?f=window:"undefined"!=typeof global?f=global:"undefined"!=typeof self&&(f=self),f.selectivity=e()}}(function(){var define,module,exports;return (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(_dereq_,module,exports){
|
2
9
|
_dereq_(5);_dereq_(6);_dereq_(7);_dereq_(9);_dereq_(10);_dereq_(11);_dereq_(12);_dereq_(13);_dereq_(14);_dereq_(15);_dereq_(16);_dereq_(17);_dereq_(18);_dereq_(19);module.exports=_dereq_(8);
|
3
10
|
},{"10":10,"11":11,"12":12,"13":13,"14":14,"15":15,"16":16,"17":17,"18":18,"19":19,"5":5,"6":6,"7":7,"8":8,"9":9}],2:[function(_dereq_,module,exports){
|
@@ -105,7 +112,8 @@ var now = Date.now;
|
|
105
112
|
* Creates a function that delays invoking `func` until after `wait` milliseconds
|
106
113
|
* have elapsed since the last time it was invoked.
|
107
114
|
*
|
108
|
-
* See [David Corbacho's article]
|
115
|
+
* See [David Corbacho's article]
|
116
|
+
* (http://drupalmotion.com/article/debounce-and-throttle-visual-explanation)
|
109
117
|
* for details over the differences between `_.debounce` and `_.throttle`.
|
110
118
|
*
|
111
119
|
* @static
|
@@ -252,8 +260,6 @@ Selectivity.OptionListeners.unshift(function(selectivity, options) {
|
|
252
260
|
Selectivity.Locale.needMoreCharacters(minimumInputLength - term.length)
|
253
261
|
);
|
254
262
|
} else {
|
255
|
-
selectivity.dropdown.showLoading();
|
256
|
-
|
257
263
|
var url = (ajax.url instanceof Function ? ajax.url(queryOptions) : ajax.url);
|
258
264
|
if (params) {
|
259
265
|
url += (url.indexOf('?') > -1 ? '&' : '?') + $.param(params(term, offset));
|
@@ -560,6 +566,8 @@ function Selectivity(options) {
|
|
560
566
|
this.data(options.data || null, { triggerChange: false });
|
561
567
|
}
|
562
568
|
|
569
|
+
this.$el.on('mouseover', this._mouseover.bind(this));
|
570
|
+
this.$el.on('mouseleave', this._mouseout.bind(this));
|
563
571
|
this.$el.on('selectivity-close', this._closed.bind(this));
|
564
572
|
|
565
573
|
EventDelegator.call(this);
|
@@ -600,6 +608,9 @@ $.extend(Selectivity.prototype, EventDelegator.prototype, {
|
|
600
608
|
* selected.
|
601
609
|
* @param options Optional options object. May contain the following property:
|
602
610
|
* triggerChange - Set to false to suppress the "change" event being triggered.
|
611
|
+
* Note this will also cause the UI to not update automatically;
|
612
|
+
* so you may want to call rerenderSelection() manually when
|
613
|
+
* using this option.
|
603
614
|
*
|
604
615
|
* @return If newData is omitted, this method returns the current data.
|
605
616
|
*/
|
@@ -656,8 +667,6 @@ $.extend(Selectivity.prototype, EventDelegator.prototype, {
|
|
656
667
|
|
657
668
|
if (this.$searchInput) {
|
658
669
|
this.$searchInput.focus();
|
659
|
-
} else if (this.dropdown) {
|
660
|
-
this.dropdown.focus();
|
661
670
|
}
|
662
671
|
},
|
663
672
|
|
@@ -687,8 +696,12 @@ $.extend(Selectivity.prototype, EventDelegator.prototype, {
|
|
687
696
|
* action of searching when something is typed.
|
688
697
|
*
|
689
698
|
* @param $input jQuery container for the input element.
|
699
|
+
* @param options Optional options object. May contain the following property:
|
700
|
+
* noSearch - If true, no event handlers are setup to initiate searching when
|
701
|
+
* the user types in the input field. This is useful if you want to
|
702
|
+
* use the input only to handle keyboard support.
|
690
703
|
*/
|
691
|
-
initSearchInput: function($input) {
|
704
|
+
initSearchInput: function($input, options) {
|
692
705
|
|
693
706
|
this.$searchInput = $input;
|
694
707
|
|
@@ -696,11 +709,13 @@ $.extend(Selectivity.prototype, EventDelegator.prototype, {
|
|
696
709
|
listener(this, $input);
|
697
710
|
}.bind(this));
|
698
711
|
|
699
|
-
|
700
|
-
|
701
|
-
|
702
|
-
|
703
|
-
|
712
|
+
if (!options || !options.noSearch) {
|
713
|
+
$input.on('keyup', function(event) {
|
714
|
+
if (!event.isDefaultPrevented()) {
|
715
|
+
this.search();
|
716
|
+
}
|
717
|
+
}.bind(this));
|
718
|
+
}
|
704
719
|
},
|
705
720
|
|
706
721
|
/**
|
@@ -734,6 +749,8 @@ $.extend(Selectivity.prototype, EventDelegator.prototype, {
|
|
734
749
|
this.search('');
|
735
750
|
}
|
736
751
|
}
|
752
|
+
|
753
|
+
this.$el.children().toggleClass('open', true);
|
737
754
|
}
|
738
755
|
},
|
739
756
|
|
@@ -976,11 +993,14 @@ $.extend(Selectivity.prototype, EventDelegator.prototype, {
|
|
976
993
|
* case it will assume the text is equal to the ID. This is useful if you're working with tags,
|
977
994
|
* or selecting e-mail addresses for instance, but may not always be what you want.
|
978
995
|
*
|
979
|
-
* @param newValue Optional new value to set. For a MultipleSelectivity instance the value must
|
980
|
-
* an array of IDs, for a SingleSelectivity instance the value must be a
|
981
|
-
* (a string or a number) or null to indicate no item is selected.
|
996
|
+
* @param newValue Optional new value to set. For a MultipleSelectivity instance the value must
|
997
|
+
* be an array of IDs, for a SingleSelectivity instance the value must be a
|
998
|
+
* single ID (a string or a number) or null to indicate no item is selected.
|
982
999
|
* @param options Optional options object. May contain the following property:
|
983
1000
|
* triggerChange - Set to false to suppress the "change" event being triggered.
|
1001
|
+
* Note this will also cause the UI to not update automatically;
|
1002
|
+
* so you may want to call rerenderSelection() manually when
|
1003
|
+
* using this option.
|
984
1004
|
*
|
985
1005
|
* @return If newValue is omitted, this method returns the current value.
|
986
1006
|
*/
|
@@ -1021,6 +1041,8 @@ $.extend(Selectivity.prototype, EventDelegator.prototype, {
|
|
1021
1041
|
_closed: function() {
|
1022
1042
|
|
1023
1043
|
this.dropdown = null;
|
1044
|
+
|
1045
|
+
this.$el.children().toggleClass('open', false);
|
1024
1046
|
},
|
1025
1047
|
|
1026
1048
|
/**
|
@@ -1064,6 +1086,22 @@ $.extend(Selectivity.prototype, EventDelegator.prototype, {
|
|
1064
1086
|
return '' + id;
|
1065
1087
|
}
|
1066
1088
|
}
|
1089
|
+
},
|
1090
|
+
|
1091
|
+
/**
|
1092
|
+
* @private
|
1093
|
+
*/
|
1094
|
+
_mouseout: function() {
|
1095
|
+
|
1096
|
+
this.$el.children().toggleClass('hover', false);
|
1097
|
+
},
|
1098
|
+
|
1099
|
+
/**
|
1100
|
+
* @private
|
1101
|
+
*/
|
1102
|
+
_mouseover: function() {
|
1103
|
+
|
1104
|
+
this.$el.children().toggleClass('hover', true);
|
1067
1105
|
}
|
1068
1106
|
|
1069
1107
|
});
|
@@ -2209,13 +2247,6 @@ function SelectivityDropdown(options) {
|
|
2209
2247
|
*/
|
2210
2248
|
this.$results = this.$('.selectivity-results-container');
|
2211
2249
|
|
2212
|
-
/**
|
2213
|
-
* jQuery container for the search input.
|
2214
|
-
*
|
2215
|
-
* May be null as long as there is no visible search input. It is set by initSearchInput().
|
2216
|
-
*/
|
2217
|
-
this.$searchInput = null;
|
2218
|
-
|
2219
2250
|
/**
|
2220
2251
|
* Boolean indicating whether more results are available than currently displayed in the
|
2221
2252
|
* dropdown.
|
@@ -2332,16 +2363,6 @@ $.extend(SelectivityDropdown.prototype, EventDelegator.prototype, {
|
|
2332
2363
|
'mouseenter .selectivity-result-item': '_resultHovered'
|
2333
2364
|
},
|
2334
2365
|
|
2335
|
-
/**
|
2336
|
-
* Applies focus to the input.
|
2337
|
-
*/
|
2338
|
-
focus: function() {
|
2339
|
-
|
2340
|
-
if (this.$searchInput) {
|
2341
|
-
this.$searchInput.focus();
|
2342
|
-
}
|
2343
|
-
},
|
2344
|
-
|
2345
2366
|
/**
|
2346
2367
|
* Highlights a result item.
|
2347
2368
|
*
|
@@ -2378,29 +2399,6 @@ $.extend(SelectivityDropdown.prototype, EventDelegator.prototype, {
|
|
2378
2399
|
this.loadMoreHighlighted = true;
|
2379
2400
|
},
|
2380
2401
|
|
2381
|
-
/**
|
2382
|
-
* Initializes the search input element.
|
2383
|
-
*
|
2384
|
-
* Sets the $searchInput property, invokes all search input listeners and attaches the default
|
2385
|
-
* action of searching when something is typed.
|
2386
|
-
*
|
2387
|
-
* @param $input jQuery container for the input element.
|
2388
|
-
*/
|
2389
|
-
initSearchInput: function($input) {
|
2390
|
-
|
2391
|
-
this.$searchInput = $input;
|
2392
|
-
|
2393
|
-
this.selectivity.searchInputListeners.forEach(function(listener) {
|
2394
|
-
listener(this, $input);
|
2395
|
-
}.bind(this));
|
2396
|
-
|
2397
|
-
$input.on('keyup', function(event) {
|
2398
|
-
if (!event.isDefaultPrevented()) {
|
2399
|
-
this.search();
|
2400
|
-
}
|
2401
|
-
}.bind(this));
|
2402
|
-
},
|
2403
|
-
|
2404
2402
|
/**
|
2405
2403
|
* Loads a follow-up page with results after a search.
|
2406
2404
|
*
|
@@ -2420,9 +2418,7 @@ $.extend(SelectivityDropdown.prototype, EventDelegator.prototype, {
|
|
2420
2418
|
throw new Error('callback must be passed a response object');
|
2421
2419
|
}
|
2422
2420
|
}.bind(this),
|
2423
|
-
error:
|
2424
|
-
this._showResults([], { add: true });
|
2425
|
-
}.bind(this),
|
2421
|
+
error: this._showResults.bind(this, [], { add: true }),
|
2426
2422
|
offset: this.results.length,
|
2427
2423
|
selectivity: this.selectivity,
|
2428
2424
|
term: this.term
|
@@ -2478,35 +2474,30 @@ $.extend(SelectivityDropdown.prototype, EventDelegator.prototype, {
|
|
2478
2474
|
* search will be performed among those items. Otherwise, the query function specified in the
|
2479
2475
|
* options will be used to perform the search. If neither is defined, nothing happens.
|
2480
2476
|
*
|
2481
|
-
* @param term
|
2482
|
-
* is used as term.
|
2477
|
+
* @param term Term to search for.
|
2483
2478
|
*/
|
2484
2479
|
search: function(term) {
|
2485
2480
|
|
2486
2481
|
var self = this;
|
2487
|
-
function setResults(results, resultOptions) {
|
2488
|
-
self._showResults(results, $.extend({ term: term }, resultOptions));
|
2489
|
-
}
|
2490
2482
|
|
2491
|
-
|
2492
|
-
|
2493
|
-
}
|
2483
|
+
term = term || '';
|
2484
|
+
self.term = term;
|
2494
2485
|
|
2495
2486
|
if (self.options.items) {
|
2496
2487
|
term = Selectivity.transformText(term);
|
2497
2488
|
var matcher = self.selectivity.matcher;
|
2498
|
-
|
2489
|
+
self._showResults(self.options.items.map(function(item) {
|
2499
2490
|
return matcher(item, term);
|
2500
2491
|
}).filter(function(item) {
|
2501
2492
|
return !!item;
|
2502
|
-
}));
|
2493
|
+
}), { term: term });
|
2503
2494
|
} else if (self.options.query) {
|
2504
2495
|
self.options.query({
|
2505
2496
|
callback: function(response) {
|
2506
2497
|
if (response && response.results) {
|
2507
|
-
|
2498
|
+
self._showResults(
|
2508
2499
|
Selectivity.processItems(response.results),
|
2509
|
-
{ hasMore: !!response.more }
|
2500
|
+
{ hasMore: !!response.more, term: term }
|
2510
2501
|
);
|
2511
2502
|
} else {
|
2512
2503
|
throw new Error('callback must be passed a response object');
|
@@ -2518,8 +2509,6 @@ $.extend(SelectivityDropdown.prototype, EventDelegator.prototype, {
|
|
2518
2509
|
term: term
|
2519
2510
|
});
|
2520
2511
|
}
|
2521
|
-
|
2522
|
-
self.term = term;
|
2523
2512
|
},
|
2524
2513
|
|
2525
2514
|
/**
|
@@ -2542,7 +2531,7 @@ $.extend(SelectivityDropdown.prototype, EventDelegator.prototype, {
|
|
2542
2531
|
selectItem: function(id) {
|
2543
2532
|
|
2544
2533
|
var item = Selectivity.findNestedById(this.results, id);
|
2545
|
-
if (item) {
|
2534
|
+
if (item && !item.disabled) {
|
2546
2535
|
var options = { id: id, item: item };
|
2547
2536
|
if (this.selectivity.triggerEvent('selectivity-selecting', options)) {
|
2548
2537
|
this.selectivity.triggerEvent('selectivity-selected', options);
|
@@ -2740,7 +2729,7 @@ $.extend(SelectivityDropdown.prototype, EventDelegator.prototype, {
|
|
2740
2729
|
event.screenY === undefined || event.screenY !== this._lastMousePosition.y) {
|
2741
2730
|
var id = this.selectivity._getItemId(event);
|
2742
2731
|
var item = Selectivity.findNestedById(this.results, id);
|
2743
|
-
if (item) {
|
2732
|
+
if (item && !item.disabled) {
|
2744
2733
|
this.highlight(item);
|
2745
2734
|
}
|
2746
2735
|
|
@@ -2766,7 +2755,7 @@ $.extend(SelectivityDropdown.prototype, EventDelegator.prototype, {
|
|
2766
2755
|
*/
|
2767
2756
|
_showResults: function(results, options) {
|
2768
2757
|
|
2769
|
-
this.showResults(this.selectivity.filterResults(results), options
|
2758
|
+
this.showResults(this.selectivity.filterResults(results), options);
|
2770
2759
|
},
|
2771
2760
|
|
2772
2761
|
/**
|
@@ -3214,7 +3203,7 @@ function MultipleSelectivity(options) {
|
|
3214
3203
|
|
3215
3204
|
this.initSearchInput(this.$('.selectivity-multiple-input:not(.selectivity-width-detector)'));
|
3216
3205
|
|
3217
|
-
this.
|
3206
|
+
this.rerenderSelection();
|
3218
3207
|
|
3219
3208
|
if (!options.positionDropdown) {
|
3220
3209
|
// dropdowns for multiple-value inputs should open below the select box,
|
@@ -3292,7 +3281,7 @@ var callSuper = Selectivity.inherits(MultipleSelectivity, {
|
|
3292
3281
|
* Follows the same format as Backbone: http://backbonejs.org/#View-delegateEvents
|
3293
3282
|
*/
|
3294
3283
|
events: {
|
3295
|
-
'change': '
|
3284
|
+
'change': 'rerenderSelection',
|
3296
3285
|
'change .selectivity-multiple-input': function() { return false; },
|
3297
3286
|
'click': '_clicked',
|
3298
3287
|
'click .selectivity-multiple-selected-item': '_itemClicked',
|
@@ -3371,6 +3360,49 @@ var callSuper = Selectivity.inherits(MultipleSelectivity, {
|
|
3371
3360
|
}
|
3372
3361
|
},
|
3373
3362
|
|
3363
|
+
/**
|
3364
|
+
* Re-renders the selection.
|
3365
|
+
*
|
3366
|
+
* Normally the UI is automatically updated whenever the selection changes, but you may want to
|
3367
|
+
* call this method explicitly if you've updated the selection with the triggerChange option set
|
3368
|
+
* to false.
|
3369
|
+
*/
|
3370
|
+
rerenderSelection: function(event) {
|
3371
|
+
|
3372
|
+
event = event || {};
|
3373
|
+
|
3374
|
+
if (event.added) {
|
3375
|
+
this._renderSelectedItem(event.added);
|
3376
|
+
|
3377
|
+
this._scrollToBottom();
|
3378
|
+
} else if (event.removed) {
|
3379
|
+
var quotedId = Selectivity.quoteCssAttr(event.removed.id);
|
3380
|
+
this.$('.selectivity-multiple-selected-item[data-item-id=' + quotedId + ']').remove();
|
3381
|
+
} else {
|
3382
|
+
this.$('.selectivity-multiple-selected-item').remove();
|
3383
|
+
|
3384
|
+
this._data.forEach(this._renderSelectedItem, this);
|
3385
|
+
|
3386
|
+
this._updateInputWidth();
|
3387
|
+
}
|
3388
|
+
|
3389
|
+
if (event.added || event.removed) {
|
3390
|
+
if (this.dropdown) {
|
3391
|
+
this.dropdown.showResults(this.filterResults(this.dropdown.results), {
|
3392
|
+
hasMore: this.dropdown.hasMore
|
3393
|
+
});
|
3394
|
+
}
|
3395
|
+
|
3396
|
+
if (this.hasKeyboard) {
|
3397
|
+
this.focus();
|
3398
|
+
}
|
3399
|
+
}
|
3400
|
+
|
3401
|
+
this.positionDropdown();
|
3402
|
+
|
3403
|
+
this._updatePlaceholder();
|
3404
|
+
},
|
3405
|
+
|
3374
3406
|
/**
|
3375
3407
|
* @inherit
|
3376
3408
|
*/
|
@@ -3381,10 +3413,8 @@ var callSuper = Selectivity.inherits(MultipleSelectivity, {
|
|
3381
3413
|
if (this.options.tokenizer) {
|
3382
3414
|
term = this.options.tokenizer(term, this._data, this.add.bind(this), this.options);
|
3383
3415
|
|
3384
|
-
if ($.type(term) === 'string') {
|
3416
|
+
if ($.type(term) === 'string' && term !== this.$searchInput.val()) {
|
3385
3417
|
this.$searchInput.val(term);
|
3386
|
-
} else {
|
3387
|
-
term = '';
|
3388
3418
|
}
|
3389
3419
|
}
|
3390
3420
|
|
@@ -3441,7 +3471,13 @@ var callSuper = Selectivity.inherits(MultipleSelectivity, {
|
|
3441
3471
|
options.allowedTypes = options.allowedTypes || {};
|
3442
3472
|
options.allowedTypes[backspaceHighlightsBeforeDelete] = 'boolean';
|
3443
3473
|
|
3474
|
+
var wasEnabled = this.enabled;
|
3475
|
+
|
3444
3476
|
callSuper(this, 'setOptions', options);
|
3477
|
+
|
3478
|
+
if (wasEnabled !== this.enabled) {
|
3479
|
+
this.$el.html(this.template('multipleSelectInput', { enabled: this.enabled }));
|
3480
|
+
}
|
3445
3481
|
},
|
3446
3482
|
|
3447
3483
|
/**
|
@@ -3646,45 +3682,6 @@ var callSuper = Selectivity.inherits(MultipleSelectivity, {
|
|
3646
3682
|
.on('click', this._itemRemoveClicked.bind(this));
|
3647
3683
|
},
|
3648
3684
|
|
3649
|
-
/**
|
3650
|
-
* @private
|
3651
|
-
*/
|
3652
|
-
_rerenderSelection: function(event) {
|
3653
|
-
|
3654
|
-
event = event || {};
|
3655
|
-
|
3656
|
-
if (event.added) {
|
3657
|
-
this._renderSelectedItem(event.added);
|
3658
|
-
|
3659
|
-
this._scrollToBottom();
|
3660
|
-
} else if (event.removed) {
|
3661
|
-
var quotedId = Selectivity.quoteCssAttr(event.removed.id);
|
3662
|
-
this.$('.selectivity-multiple-selected-item[data-item-id=' + quotedId + ']').remove();
|
3663
|
-
} else {
|
3664
|
-
this.$('.selectivity-multiple-selected-item').remove();
|
3665
|
-
|
3666
|
-
this._data.forEach(this._renderSelectedItem, this);
|
3667
|
-
|
3668
|
-
this._updateInputWidth();
|
3669
|
-
}
|
3670
|
-
|
3671
|
-
if (event.added || event.removed) {
|
3672
|
-
if (this.dropdown) {
|
3673
|
-
this.dropdown.showResults(this.filterResults(this.dropdown.results), {
|
3674
|
-
hasMore: this.dropdown.hasMore
|
3675
|
-
});
|
3676
|
-
}
|
3677
|
-
|
3678
|
-
if (this.hasKeyboard) {
|
3679
|
-
this.focus();
|
3680
|
-
}
|
3681
|
-
}
|
3682
|
-
|
3683
|
-
this.positionDropdown();
|
3684
|
-
|
3685
|
-
this._updatePlaceholder();
|
3686
|
-
},
|
3687
|
-
|
3688
3685
|
/**
|
3689
3686
|
* @private
|
3690
3687
|
*/
|
@@ -3759,7 +3756,7 @@ function SingleSelectivity(options) {
|
|
3759
3756
|
this.$el.html(this.template('singleSelectInput', this.options))
|
3760
3757
|
.trigger('selectivity-init', 'single');
|
3761
3758
|
|
3762
|
-
this.
|
3759
|
+
this.rerenderSelection();
|
3763
3760
|
|
3764
3761
|
if (!options.positionDropdown) {
|
3765
3762
|
// dropdowns for single-value inputs should open below the select box,
|
@@ -3786,7 +3783,7 @@ function SingleSelectivity(options) {
|
|
3786
3783
|
}
|
3787
3784
|
|
3788
3785
|
if (options.showSearchInputInDropdown === false) {
|
3789
|
-
this.initSearchInput(this.$('.selectivity-single-select-input'));
|
3786
|
+
this.initSearchInput(this.$('.selectivity-single-select-input'), { noSearch: true });
|
3790
3787
|
}
|
3791
3788
|
}
|
3792
3789
|
|
@@ -3801,7 +3798,7 @@ var callSuper = Selectivity.inherits(SingleSelectivity, {
|
|
3801
3798
|
* Follows the same format as Backbone: http://backbonejs.org/#View-delegateEvents
|
3802
3799
|
*/
|
3803
3800
|
events: {
|
3804
|
-
'change': '
|
3801
|
+
'change': 'rerenderSelection',
|
3805
3802
|
'click': '_clicked',
|
3806
3803
|
'focus .selectivity-single-select-input': '_focused',
|
3807
3804
|
'selectivity-selected': '_resultSelected'
|
@@ -3878,6 +3875,32 @@ var callSuper = Selectivity.inherits(SingleSelectivity, {
|
|
3878
3875
|
this._opening = false;
|
3879
3876
|
},
|
3880
3877
|
|
3878
|
+
/**
|
3879
|
+
* Re-renders the selection.
|
3880
|
+
*
|
3881
|
+
* Normally the UI is automatically updated whenever the selection changes, but you may want to
|
3882
|
+
* call this method explicitly if you've updated the selection with the triggerChange option set
|
3883
|
+
* to false.
|
3884
|
+
*/
|
3885
|
+
rerenderSelection: function() {
|
3886
|
+
|
3887
|
+
var $container = this.$('.selectivity-single-result-container');
|
3888
|
+
if (this._data) {
|
3889
|
+
$container.html(
|
3890
|
+
this.template('singleSelectedItem', $.extend({
|
3891
|
+
removable: this.options.allowClear && !this.options.readOnly
|
3892
|
+
}, this._data))
|
3893
|
+
);
|
3894
|
+
|
3895
|
+
$container.find('.selectivity-single-selected-item-remove')
|
3896
|
+
.on('click', this._itemRemoveClicked.bind(this));
|
3897
|
+
} else {
|
3898
|
+
$container.html(
|
3899
|
+
this.template('singleSelectPlaceholder', { placeholder: this.options.placeholder })
|
3900
|
+
);
|
3901
|
+
}
|
3902
|
+
},
|
3903
|
+
|
3881
3904
|
/**
|
3882
3905
|
* @inherit
|
3883
3906
|
*
|
@@ -3965,28 +3988,6 @@ var callSuper = Selectivity.inherits(SingleSelectivity, {
|
|
3965
3988
|
return false;
|
3966
3989
|
},
|
3967
3990
|
|
3968
|
-
/**
|
3969
|
-
* @private
|
3970
|
-
*/
|
3971
|
-
_rerenderSelection: function() {
|
3972
|
-
|
3973
|
-
var $container = this.$('.selectivity-single-result-container');
|
3974
|
-
if (this._data) {
|
3975
|
-
$container.html(
|
3976
|
-
this.template('singleSelectedItem', $.extend({
|
3977
|
-
removable: this.options.allowClear && !this.options.readOnly
|
3978
|
-
}, this._data))
|
3979
|
-
);
|
3980
|
-
|
3981
|
-
$container.find('.selectivity-single-selected-item-remove')
|
3982
|
-
.on('click', this._itemRemoveClicked.bind(this));
|
3983
|
-
} else {
|
3984
|
-
$container.html(
|
3985
|
-
this.template('singleSelectPlaceholder', { placeholder: this.options.placeholder })
|
3986
|
-
);
|
3987
|
-
}
|
3988
|
-
},
|
3989
|
-
|
3990
3991
|
/**
|
3991
3992
|
* @private
|
3992
3993
|
*/
|
@@ -4079,6 +4080,18 @@ var callSuper = Selectivity.inherits(SelectivitySubmenu, SelectivityDropdown, {
|
|
4079
4080
|
}
|
4080
4081
|
},
|
4081
4082
|
|
4083
|
+
/**
|
4084
|
+
* @inherit
|
4085
|
+
*/
|
4086
|
+
search: function(term) {
|
4087
|
+
|
4088
|
+
if (this.submenu) {
|
4089
|
+
this.submenu.search(term);
|
4090
|
+
} else {
|
4091
|
+
callSuper(this, 'search', term);
|
4092
|
+
}
|
4093
|
+
},
|
4094
|
+
|
4082
4095
|
/**
|
4083
4096
|
* @inherit
|
4084
4097
|
*/
|
@@ -4097,7 +4110,7 @@ var callSuper = Selectivity.inherits(SelectivitySubmenu, SelectivityDropdown, {
|
|
4097
4110
|
selectItem: function(id) {
|
4098
4111
|
|
4099
4112
|
var item = Selectivity.findNestedById(this.results, id);
|
4100
|
-
if (item && !item.submenu) {
|
4113
|
+
if (item && !item.disabled && !item.submenu) {
|
4101
4114
|
var options = { id: id, item: item };
|
4102
4115
|
if (this.selectivity.triggerEvent('selectivity-selecting', options)) {
|
4103
4116
|
this.selectivity.triggerEvent('selectivity-selected', options);
|
@@ -4403,11 +4416,13 @@ Selectivity.Templates = {
|
|
4403
4416
|
* @param options Options object containing the following properties:
|
4404
4417
|
* id - Identifier for the item.
|
4405
4418
|
* text - Text label which the user sees.
|
4419
|
+
* disabled - Truthy if the item should be disabled.
|
4406
4420
|
* submenu - Truthy if the result item has a menu with subresults.
|
4407
4421
|
*/
|
4408
4422
|
resultItem: function(options) {
|
4409
4423
|
return (
|
4410
|
-
'<div class="selectivity-result-item
|
4424
|
+
'<div class="selectivity-result-item' + (options.disabled ? ' disabled' : '') + '"' +
|
4425
|
+
' data-item-id="' + escape(options.id) + '">' +
|
4411
4426
|
escape(options.text) +
|
4412
4427
|
(options.submenu ? '<i class="selectivity-submenu-icon fa fa-chevron-right"></i>'
|
4413
4428
|
: '') +
|
@@ -4494,10 +4509,14 @@ Selectivity.Templates = {
|
|
4494
4509
|
* mode - Mode in which select exists, single or multiple.
|
4495
4510
|
*/
|
4496
4511
|
selectCompliance: function(options) {
|
4497
|
-
|
4498
|
-
|
4512
|
+
var mode = options.mode;
|
4513
|
+
var name = options.name;
|
4514
|
+
if (mode === 'multiple' && name.slice(-2) !== '[]') {
|
4515
|
+
name += '[]';
|
4499
4516
|
}
|
4500
|
-
return (
|
4517
|
+
return (
|
4518
|
+
'<select name="' + name + '"' + (mode === 'multiple' ? ' multiple' : '') + '></select>'
|
4519
|
+
);
|
4501
4520
|
},
|
4502
4521
|
|
4503
4522
|
/**
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: selectivity-rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.8
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Konrad Jurkowski
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2016-01-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|