diff --git a/jquery.flexdatalist.js b/jquery.flexdatalist.js index 8926cc6..be23585 100644 --- a/jquery.flexdatalist.js +++ b/jquery.flexdatalist.js @@ -187,7 +187,7 @@ jQuery.fn.flexdatalist = function (_option, _value) { window.onresize = function (event) { _this.position(); }; - + // Run garbage collector this.cache.gc(); @@ -308,7 +308,7 @@ jQuery.fn.flexdatalist = function (_option, _value) { inputWidth: function (event) { var options = _this.options.get(); if (options.multiple) { - var keyword = $alias.val(), + var keyword = $alias.val(), fontSize = parseInt($alias.css('fontSize').replace('px', '')), minWidth = 40, maxWidth = $this.innerWidth(), @@ -337,7 +337,7 @@ jQuery.fn.flexdatalist = function (_option, _value) { var val = _this.fvalue.get(), keyword = $alias.val(), options = _this.options.get(); - + if (!options.multiple && options.selectionRequired && keyword.length <= options.minLength) { _this.fvalue.clear(); } @@ -373,7 +373,7 @@ jQuery.fn.flexdatalist = function (_option, _value) { if ($this.attr('autofocus')) { $alias.focus(); } - + $this.data('aliascontainer', ($multiple ? $multiple : $alias)).addClass('flexdatalist flexdatalist-set').css({ 'position': 'absolute', 'top': -14000, @@ -424,7 +424,7 @@ jQuery.fn.flexdatalist = function (_option, _value) { .addClass('flexdatalist-multiple-value') .append($alias) .appendTo($multiple); - + return $multiple; }, /** @@ -686,7 +686,7 @@ jQuery.fn.flexdatalist = function (_option, _value) { args = [{value: data.value, text: data.text, action: action}, options]; $this.trigger('before:flexdatalist.toggle', args); - + if (action === 'enable') { var value = $li.data('value'); current.splice(index, 0, value); @@ -1410,10 +1410,10 @@ jQuery.fn.flexdatalist = function (_option, _value) { var $li = $('
  • ').data('item', item).addClass('item'), options = _this.options.get(), visibleProperties = options.visibleProperties; - + for (var index = 0; index < visibleProperties.length; index++) { var visibleProperty = visibleProperties[index]; - + if (visibleProperty.indexOf('{') > -1) { var str = _this.fvalue.placeholders.replace(item, visibleProperty), parsed = _this.fvalue.placeholders.parse(visibleProperty); @@ -1438,7 +1438,7 @@ jQuery.fn.flexdatalist = function (_option, _value) { .html(propertyText + ' '); } } - + $item.appendTo($li); } return $li; diff --git a/jquery.flexdatalist.min.js b/jquery.flexdatalist.min.js index 4d6ee59..f78c641 100644 --- a/jquery.flexdatalist.min.js +++ b/jquery.flexdatalist.min.js @@ -1,2 +1,2 @@ -/** jQuery.Flexdatalist 2.2.2.2 */ -jQuery.fn.flexdatalist=function(e,t){"use strict";var i=function(e,t){e.each(function(){var e=$(this),i=e.data(),a=i.flexdatalist,r=i.aliascontainer;r&&(e.removeClass("flexdatalist-set").attr({style:null,tabindex:null}).val(a&&a.originalValue&&!t?a.originalValue:"").removeData("flexdatalist").removeData("aliascontainer").off(),r.remove())})};if("string"==typeof e&&"reset"!==e){if("undefined"!=typeof this[0].fvalue){var a=this[0];if("destroy"===e)i(this,t);else if("value"===e){if("undefined"==typeof t)return a.fvalue.get();a.fvalue.set(t)}else if("add"===e){if("undefined"==typeof t)return a.debug("Missing value to add!");a.fvalue.add(t)}else if("toggle"===e){if("undefined"==typeof t)return a.debug("Missing value to toggle!");a.fvalue.toggle(t)}else if("remove"===e){if("undefined"==typeof t)return a.debug("Missing value to remove!");a.fvalue.remove(t)}else if("disabled"===e){if("undefined"==typeof t)return a.fdisabled();a.fdisabled(t)}else if("string"==typeof e){if("undefined"==typeof t)return a.options.get(e);a.options.set(e,t)}return this}e={_option:t}}this.length>0&&"undefined"!=typeof this[0].fvalue&&i(this);var r=$.extend({url:null,data:[],params:{},relatives:null,chainedRelatives:!1,cache:!0,cacheLifetime:60,minLength:2,groupBy:!1,selectionRequired:!1,focusFirstResult:!1,textProperty:null,valueProperty:null,visibleProperties:[],iconProperty:"thumb",searchIn:["label"],searchContain:!1,searchEqual:!1,searchByWord:!1,searchDisabled:!1,searchDelay:300,normalizeString:null,multiple:null,disabled:null,maxShownResults:100,removeOnBackspace:!0,noResultsText:'No results found for "{keyword}"',toggleSelected:!1,allowDuplicateValues:!1,redoSearchOnFocus:!0,requestType:"get",requestContentType:"x-www-form-urlencoded",resultsProperty:"results",keywordParamName:"keyword",limitOfValues:0,valuesSeparator:",",debug:!0},e);return this.each(function(e){var t=$(this),i=this,a=null,n=[],s="flex"+e,l=null,o=null;this.init=function(){var e=this.options.init();this.set.up(),l.on("focusin",function(e){i.action.redoSearchFocus(e),i.action.showAllResults(e),o&&o.addClass("focus")}).on("input keydown",function(e){9===i.keyNum(e)&&i.results.remove(),i.action.keypressValue(e,188),i.action.backSpaceKeyRemove(e)}).on("input keyup",function(e){i.action.keypressValue(e,13),i.action.keypressSearch(e),i.action.copyValue(e),i.action.backSpaceKeyRemove(e),i.action.showAllResults(e),i.action.clearValue(e),i.action.removeResults(e),i.action.inputWidth(e)}).on("focusout",function(e){o&&o.removeClass("focus"),i.action.clearText(e),i.action.clearValue(e)}),window.onresize=function(){i.position()},this.cache.gc(),e.selectionRequired&&i.fvalue.clear(!0,!0),this.fvalue._load(e.originalValue,function(){i.fdisabled(e.disabled),t.trigger("init:flexdatalist",[e])},!0)},this.action={keypressValue:function(e,t){var a=i.keyNum(e),r=l[0].value,n=i.options.get();if(r.length>0&&a===t&&!n.selectionRequired&&n.multiple){var r=l[0].value;e.preventDefault(),i.fvalue.extract(r),i.results.remove()}},keypressSearch:function(e){var t=i.keyNum(e),r=l.val(),n=r.length,s=i.options.get();clearTimeout(a),(!t||13!==t&&(37>t||t>40))&&(a=setTimeout(function(){(0===s.minLength&&n>0||s.minLength>0&&n>=s.minLength)&&i.data.load(function(e){i.search.get(r,e,function(e){i.results.show(e)})})},s.searchDelay))},redoSearchFocus:function(e){var t=i.fvalue.get(),a=i.options.get(),r=l.val();a.redoSearchOnFocus&&(r.length>0&&a.multiple||r.length>0&&0===t.length)&&this.keypressSearch(e)},copyValue:function(e){if(13!==i.keyNum(e)){var t=l.val(),a=i.fvalue.get(!0),r=i.options.get();r.multiple||r.selectionRequired||t.length===a.length||i.fvalue.extract(t)}},backSpaceKeyRemove:function(e){var t=i.options.get();if(t.removeOnBackspace&&t.multiple){var a=l.val(),r=l.data("_remove");8===i.keyNum(e)&&(0===a.length?r?(i.fvalue.remove(r),l.data("_remove",null)):(console.log("remove!"),l.data("_remove",l.parents("li:eq(0)").prev())):l.data("_remove",null))}},showAllResults:function(){var e=l.val();e=$.trim(e),""===e&&0===i.options.get("minLength")&&i.data.load(function(e){i.results.show(e)})},inputWidth:function(){var e=i.options.get();if(e.multiple){var a=l.val(),r=parseInt(l.css("fontSize").replace("px","")),n=40,s=t.innerWidth(),o=(a.length+1)*r;o>=n&&s>=o&&(l[0].style.width=o+"px")}},clearText:function(){var e=i.fvalue.get(),t=i.options.get();!t.multiple&&t.selectionRequired&&0===e.length&&(l[0].value="")},clearValue:function(){var e=(i.fvalue.get(),l.val()),t=i.options.get();!t.multiple&&t.selectionRequired&&e.length<=t.minLength&&i.fvalue.clear()},removeResults:function(){var e=(i.fvalue.get(),l.val()),t=i.options.get();t.minLength>0&&e.length').attr({"class":t.attr("class"),name:t.attr("name")?"flexdatalist-"+t.attr("name"):null,id:e,placeholder:t.attr("placeholder")}).addClass("flexdatalist-alias "+e).removeClass("flexdatalist").attr("autocomplete","off");return i},multipleInput:function(e){return o=$('