From aec3515ceeb225541d0cc38fa8a9b0f6530f11dc Mon Sep 17 00:00:00 2001 From: Ad Schellevis Date: Wed, 23 Jan 2019 11:44:34 +0100 Subject: [PATCH] Tokenize2, pull in 1.3 from https://github.com/dragonofmercy/Tokenize2 --- src/opnsense/www/js/tokenize2.js | 765 +++++++++++++++++++++++++++++-- 1 file changed, 729 insertions(+), 36 deletions(-) diff --git a/src/opnsense/www/js/tokenize2.js b/src/opnsense/www/js/tokenize2.js index 8c6d6e736..290d73042 100644 --- a/src/opnsense/www/js/tokenize2.js +++ b/src/opnsense/www/js/tokenize2.js @@ -1,6 +1,6 @@ /*! - * Tokenize2 v1.2 (https://github.com/zellerda/Tokenize2) - * Copyright 2016-2017 David Zeller. + * Tokenize2 v1.3 (https://github.com/dragonofmercy/Tokenize2) + * Copyright 2016-2017 DragonOfMercy. * Licensed under the new BSD license */ (function(factory){ @@ -29,7 +29,6 @@ factory(jQuery); } }(function($){ - /** * Tokenize2 constructor. * @@ -67,7 +66,7 @@ MAJ: 16 }; - Tokenize2.VERSION = '1.0'; + Tokenize2.VERSION = '1.3'; Tokenize2.DEBOUNCE = null; Tokenize2.DEFAULTS = { tokensMaxItems: 0, @@ -181,7 +180,9 @@ this.trigger('tokenize:select', [($(e.target)[0] === this.tokensContainer[0])]); }, this)) .focusout($.proxy(function(){ - this.trigger('tokenize:deselect'); + if(this.container.hasClass('focus')){ + this.trigger('tokenize:deselect') + } }, this)); if(this.options.tokensMaxItems === 1){ @@ -189,27 +190,22 @@ } if(this.options.sortable){ - if(typeof $.ui !== 'undefined'){ - this.container.addClass('sortable'); - this.tokensContainer.sortable({ - items: 'li.token', - cursor: 'move', - placeholder: 'token shadow', - forcePlaceholderSize: true, - update: $.proxy(function(){ - this.trigger('tokenize:tokens:reorder'); - }, this), - start: $.proxy(function(){ - this.searchContainer.hide(); - } , this), - stop: $.proxy(function(){ - this.searchContainer.show(); - }, this) - }); - } else { - this.options.sortable = false; - console.error('jQuery UI is not loaded, sortable option has been disabled'); - } + this.container.addClass('sortable'); + this.tokensContainer.tokenize2sortable({ + itemSelector: 'li.token', + cursor: 'move', + placeholder: '

  • ', + placeholderClass: 'token shadow', + onDragStart: $.proxy(function($item, container, _super){ + this.searchContainer.hide(); + _super($item, container); + } , this), + onDrop: $.proxy(function($item, container, _super){ + this.searchContainer.show(); + this.trigger('tokenize:tokens:reorder'); + _super($item, container); + }, this) + }); } this.element @@ -240,9 +236,9 @@ Tokenize2.prototype.reorder = function(){ if(this.options.sortable){ - var previous, current; - $.each(this.tokensContainer.sortable('toArray', {attribute: 'data-value'}), $.proxy(function(k, v){ - current = $('option[value="' + $.escapeSelector(v) + '"]', this.element); + var previous, current, data = this.tokensContainer.tokenize2sortable('serialize').get(0); + $.each(data, $.proxy(function(k, v){ + current = $('option[value="' + v.value + '"]', this.element); if(previous === undefined){ current.prependTo(this.element); } else { @@ -251,7 +247,6 @@ previous = current; }, this)); } - }; /** @@ -299,13 +294,13 @@ } // Check duplicate token - if($('li.token[data-value="' + $.escapeSelector(value) + '"]', this.tokensContainer).length > 0){ + if($('li.token[data-value="' + value + '"]', this.tokensContainer).length > 0){ this.trigger('tokenize:tokens:error:duplicate', [value, text]); return this; } - if($('option[value="' + $.escapeSelector(value) + '"]', this.element).length) { - $('option[value="' + $.escapeSelector(value) + '"]', this.element).attr('selected', 'selected').prop('selected', true); + if($('option[value="' + value + '"]', this.element).length) { + $('option[value="' + value + '"]', this.element).attr('selected', 'selected').prop('selected', true); } else if(force){ this.element.append($('