diff options
author | lou <louiscuny@gmail.com> | 2013-03-23 16:42:55 +0100 |
---|---|---|
committer | lou <louiscuny@gmail.com> | 2013-04-19 11:57:53 +0200 |
commit | 9cb9572d6d232e33fc157433ac35f28841705613 (patch) | |
tree | 1da86ab36db5790f89c1206110ba3b20f8a0d91f /js/jquery.multi-select.js | |
parent | db7c79eeb957eec8d1b2272fe5d88400167d945d (diff) | |
download | multi-select-9cb9572d6d232e33fc157433ac35f28841705613.zip multi-select-9cb9572d6d232e33fc157433ac35f28841705613.tar.gz multi-select-9cb9572d6d232e33fc157433ac35f28841705613.tar.bz2 |
simplify sanitize regexp and pre-compiled it
Diffstat (limited to 'js/jquery.multi-select.js')
-rw-r--r-- | js/jquery.multi-select.js | 13 |
1 files changed, 6 insertions, 7 deletions
diff --git a/js/jquery.multi-select.js b/js/jquery.multi-select.js index f23df0d..95e924a 100644 --- a/js/jquery.multi-select.js +++ b/js/jquery.multi-select.js @@ -26,6 +26,7 @@ this.$selectableUl = $('<ul class="ms-list"></ul>'); this.$selectionUl = $('<ul class="ms-list"></ul>'); this.scrollTo = 0; + this.sanitizeRegexp = new RegExp("\\W+", 'gi'); } MultiSelect.prototype = { @@ -39,8 +40,6 @@ ms.css({ position: 'absolute', left: '-9999px' }); ms.attr('id', ms.attr('id') ? ms.attr('id') : 'ms-'+Math.ceil(Math.random()*1000)); - - var optgroupLabel = null, optgroupId = null, optgroupCpt = 0, @@ -105,7 +104,7 @@ selectedLi = selectableLi.clone(); var value = $(this).val(), - msId = that.sanitize(value); + msId = that.sanitize(value, that.sanitizeRegexp); selectableLi .data('ms-value', value) @@ -305,7 +304,7 @@ value = [value] var that = this, ms = this.$element, - msIds = $.map(value, function(val, index){ return(that.sanitize(val)) }), + msIds = $.map(value, function(val, index){ return(that.sanitize(val, that.sanitizeRegexp)) }), selectables = this.$selectableUl.find('#' + msIds.join('-selectable, #')+'-selectable').filter(':not(.'+that.options.disabledClass+')'), selections = this.$selectionUl.find('#' + msIds.join('-selection, #') + '-selection'), options = ms.find('option').filter(function(index){ return($.inArray(this.value, value) > -1) }); @@ -348,7 +347,7 @@ value = [value] var that = this, ms = this.$element, - msIds = $.map(value, function(val, index){ return(that.sanitize(val)) }), + msIds = $.map(value, function(val, index){ return(that.sanitize(val, that.sanitizeRegexp)) }), selectables = this.$selectableUl.find('#' + msIds.join('-selectable, #')+'-selectable'), selections = this.$selectionUl.find('#' + msIds.join('-selection, #')+'-selection').filter('.ms-selected'), options = ms.find('option').filter(function(index){ return($.inArray(this.value, value) > -1) }); @@ -430,8 +429,8 @@ ); }, - sanitize: function(value){ - return(value.replace(/[^A-Za-z0-9]*/gi, '_')); + sanitize: function(value, reg){ + return(value.replace(reg, '_')); } } |