diff --git a/bower.json b/bower.json index a3eeecd..73458d4 100644 --- a/bower.json +++ b/bower.json @@ -1,7 +1,7 @@ { "name": "EasyAutocomplete", "description": "EasyAutocomplete is a jQuery autocomplete plugin. Easy to create autocomplete dropdown list for text input fields", - "version": "1.3.5", + "version": "1.3.6", "authors": [ "Łukasz Pawełczak " ], diff --git a/dist/easy-autocomplete.css b/dist/easy-autocomplete.css index 58b3a3b..897eeac 100644 --- a/dist/easy-autocomplete.css +++ b/dist/easy-autocomplete.css @@ -3,7 +3,7 @@ * jQuery plugin for autocompletion * * @author Łukasz Pawełczak (http://github.com/pawelczak) - * @version 1.3.5 + * @version 1.3.6 * Copyright License: */ diff --git a/dist/easy-autocomplete.min.css b/dist/easy-autocomplete.min.css index 3b49ea1..0f74483 100644 --- a/dist/easy-autocomplete.min.css +++ b/dist/easy-autocomplete.min.css @@ -3,7 +3,7 @@ * jQuery plugin for autocompletion * * @author Łukasz Pawełczak (http://github.com/pawelczak) - * @version 1.3.5 + * @version 1.3.6 * Copyright License: */ diff --git a/dist/easy-autocomplete.themes.css b/dist/easy-autocomplete.themes.css index 1e544b1..1995cc2 100644 --- a/dist/easy-autocomplete.themes.css +++ b/dist/easy-autocomplete.themes.css @@ -3,7 +3,7 @@ * jQuery plugin for autocompletion * * @author Łukasz Pawełczak (http://github.com/pawelczak) - * @version 1.3.5 + * @version 1.3.6 * Copyright License: */ diff --git a/dist/easy-autocomplete.themes.min.css b/dist/easy-autocomplete.themes.min.css index bcc690f..99eeab6 100644 --- a/dist/easy-autocomplete.themes.min.css +++ b/dist/easy-autocomplete.themes.min.css @@ -3,7 +3,7 @@ * jQuery plugin for autocompletion * * @author Łukasz Pawełczak (http://github.com/pawelczak) - * @version 1.3.5 + * @version 1.3.6 * Copyright License: */ diff --git a/dist/jquery.easy-autocomplete.js b/dist/jquery.easy-autocomplete.js index 88f2951..911abe3 100644 --- a/dist/jquery.easy-autocomplete.js +++ b/dist/jquery.easy-autocomplete.js @@ -3,12 +3,12 @@ * jQuery plugin for autocompletion * * @author Łukasz Pawełczak (http://github.com/pawelczak) - * @version 1.3.5 + * @version 1.3.6 * Copyright License: */ /* - * EasyAutocomplete - Configuration + * EasyAutocomplete - Configuration */ var EasyAutocomplete = (function(scope){ @@ -88,7 +88,7 @@ var EasyAutocomplete = (function(scope){ onChooseEvent: function() {}, onKeyEnterEvent: function() {}, onMouseOverEvent: function() {}, - onMouseOutEvent: function() {}, + onMouseOutEvent: function() {}, onShowListEvent: function() {}, onHideListEvent: function() {} }, @@ -105,6 +105,8 @@ var EasyAutocomplete = (function(scope){ adjustWidth: true, + noResults: false, + ajaxSettings: {}, preparePostData: function(data, inputPhrase) {return data;}, @@ -120,7 +122,7 @@ var EasyAutocomplete = (function(scope){ }] }; - + var externalObjects = ["ajaxSettings", "template"]; this.get = function(propertyName) { @@ -132,8 +134,8 @@ var EasyAutocomplete = (function(scope){ if (defaults[name] === value) { return true; } - } - + } + return false; }; @@ -163,7 +165,7 @@ var EasyAutocomplete = (function(scope){ mergeOptions(); if (defaults.loggerEnabled === true) { - printPropertiesThatDoesntExist(console, options); + printPropertiesThatDoesntExist(console, options); } addAjaxSettings(); @@ -172,7 +174,7 @@ var EasyAutocomplete = (function(scope){ function prepareDefaults() { if (options.dataType === "xml") { - + if (!options.getValue) { options.getValue = function(element) { @@ -180,11 +182,11 @@ var EasyAutocomplete = (function(scope){ }; } - + if (!options.list) { options.list = {}; - } + } if (!options.list.sort) { options.list.sort = {}; @@ -221,7 +223,7 @@ var EasyAutocomplete = (function(scope){ var categories = []; - for (var i = 0, length = options.categories.length; i < length; i += 1) { + for (var i = 0, length = options.categories.length; i < length; i += 1) { var category = options.categories[i]; @@ -249,7 +251,7 @@ var EasyAutocomplete = (function(scope){ for (var propertyName in source) { if (target[propertyName] !== undefined && target[propertyName] !== null) { - if (typeof target[propertyName] !== "object" || + if (typeof target[propertyName] !== "object" || target[propertyName] instanceof Array) { mergedObject[propertyName] = target[propertyName]; } else { @@ -257,7 +259,7 @@ var EasyAutocomplete = (function(scope){ } } } - + /* If data is an object */ if (target.data !== undefined && target.data !== null && typeof target.data === "object") { mergedObject.data = target.data; @@ -265,11 +267,11 @@ var EasyAutocomplete = (function(scope){ return mergedObject; } - } + } function processAfterMerge() { - + if (defaults.url !== "list-required" && typeof defaults.url !== "function") { var defaultUrl = defaults.url; defaults.url = function() { @@ -294,7 +296,7 @@ var EasyAutocomplete = (function(scope){ } else { defaults.listLocation = function(data) { return data[defaultlistLocation]; - }; + }; } } @@ -316,9 +318,9 @@ var EasyAutocomplete = (function(scope){ if (options.ajaxSettings !== undefined && typeof options.ajaxSettings === "object") { defaults.ajaxSettings = options.ajaxSettings; } else { - defaults.ajaxSettings = {}; + defaults.ajaxSettings = {}; } - + } function isAssigned(name) { @@ -329,19 +331,19 @@ var EasyAutocomplete = (function(scope){ } } function printPropertiesThatDoesntExist(consol, optionsToCheck) { - + checkPropertiesIfExist(defaults, optionsToCheck); function checkPropertiesIfExist(source, target) { for(var property in target) { if (source[property] === undefined) { - consol.log("Property '" + property + "' does not exist in EasyAutocomplete options API."); + consol.log("Property '" + property + "' does not exist in EasyAutocomplete options API."); } if (typeof source[property] === "object" && $.inArray(property, externalObjects) === -1) { checkPropertiesIfExist(source[property], target[property]); } - } + } } } }; @@ -350,7 +352,6 @@ var EasyAutocomplete = (function(scope){ })(EasyAutocomplete || {}); - /* * EasyAutocomplete - Logger */ @@ -882,9 +883,9 @@ var EasyAutocomplete = (function(scope){ */ var EasyAutocomplete = (function(scope) { - + scope.main = function Core($input, options) { - + var module = { name: "EasyAutocomplete", shortcut: "eac" @@ -897,7 +898,7 @@ var EasyAutocomplete = (function(scope) { listBuilderService = new scope.ListBuilderService(config, scope.proccess), checkParam = config.equals, - $field = $input, + $field = $input, $container = "", elementsList = [], selectedElement = -1, @@ -964,19 +965,19 @@ var EasyAutocomplete = (function(scope) { prepareField(); - bindEvents(); + bindEvents(); } function prepareField() { - + if ($field.parent().hasClass(consts.getValue("WRAPPER_CSS_CLASS"))) { removeContainer(); removeWrapper(); - } - + } + createWrapper(); - createContainer(); + createContainer(); $container = $("#" + getContainerId()); if (config.get("placeholder")) { @@ -988,7 +989,7 @@ var EasyAutocomplete = (function(scope) { var $wrapper = $("
"), classes = consts.getValue("WRAPPER_CSS_CLASS"); - + if (config.get("theme") && config.get("theme") !== "") { classes += " eac-" + config.get("theme"); } @@ -1000,7 +1001,7 @@ var EasyAutocomplete = (function(scope) { if (template.getTemplateClass() !== "") { classes += " " + template.getTemplateClass(); } - + $wrapper .addClass(classes); @@ -1008,16 +1009,16 @@ var EasyAutocomplete = (function(scope) { if (config.get("adjustWidth") === true) { - adjustWrapperWidth(); + adjustWrapperWidth(); } - + } function adjustWrapperWidth() { var fieldWidth = $field.outerWidth(); - $field.parent().css("width", fieldWidth); + $field.parent().css("width", fieldWidth); } function removeWrapper() { @@ -1060,7 +1061,7 @@ var EasyAutocomplete = (function(scope) { } config.get("list").onShowListEvent(); - + }) /* List hide animation */ .on("hide.eac", function() { @@ -1096,7 +1097,7 @@ var EasyAutocomplete = (function(scope) { config.get("list").onSelectItemEvent(); }) .on("loadElements.eac", function(event, listBuilders, phrase) { - + var $item = "", $listContainer = $elements_container.find("ul"); @@ -1121,7 +1122,7 @@ var EasyAutocomplete = (function(scope) { for(var i = 0, listDataLength = listData.length; i < listDataLength && counter < listBuilders[builderIndex].maxListSize; i += 1) { $item = $("
  • "); - + (function() { var j = i, @@ -1142,7 +1143,7 @@ var EasyAutocomplete = (function(scope) { .mouseover(function() { selectedElement = itemCounter; - selectElement(itemCounter); + selectElement(itemCounter); config.get("list").onMouseOverEvent(); }) @@ -1158,6 +1159,10 @@ var EasyAutocomplete = (function(scope) { } } + if (config.get("noResults") && counter == 0) { + $listContainer.append("
  • " + config.get("noResults") + "
  • "); + } + $elements_container.append($listContainer); config.get("list").onLoadEvent(); @@ -1175,11 +1180,11 @@ var EasyAutocomplete = (function(scope) { function highlight(string, phrase) { if(config.get("highlightPhrase") && phrase !== "") { - return highlightPhrase(string, phrase); + return highlightPhrase(string, phrase); } else { return string; } - + } function escapeRegExp(str) { @@ -1195,7 +1200,7 @@ var EasyAutocomplete = (function(scope) { } function getContainerId() { - + var elementId = $field.attr("id"); elementId = consts.getValue("CONTAINER_ID") + elementId; @@ -1205,7 +1210,7 @@ var EasyAutocomplete = (function(scope) { function bindEvents() { bindAllEvents(); - + function bindAllEvents() { if (checkParam("autocompleteOff", true)) { @@ -1271,7 +1276,7 @@ var EasyAutocomplete = (function(scope) { selectElement(selectedElement); - } + } break; case 40: @@ -1285,7 +1290,7 @@ var EasyAutocomplete = (function(scope) { $field.val(config.get("getValue")(elementsList[selectedElement])); selectElement(selectedElement); - + } break; @@ -1311,13 +1316,13 @@ var EasyAutocomplete = (function(scope) { } else { hideContainer(); } - + } break; } - + function loadData(inputPhrase) { @@ -1334,13 +1339,13 @@ var EasyAutocomplete = (function(scope) { var listBuilders = listBuilderService.init(data); listBuilders = listBuilderService.updateCategories(listBuilders, data); - + listBuilders = listBuilderService.processData(listBuilders, inputPhrase); loadElements(listBuilders, inputPhrase); if ($field.parent().find("li").length > 0) { - showContainer(); + showContainer(); } else { hideContainer(); } @@ -1364,24 +1369,24 @@ var EasyAutocomplete = (function(scope) { settings.data = config.get("preparePostData")(settings.data, inputPhrase); - $.ajax(settings) + $.ajax(settings) .done(function(data) { var listBuilders = listBuilderService.init(data); listBuilders = listBuilderService.updateCategories(listBuilders, data); - + listBuilders = listBuilderService.convertXml(listBuilders); if (checkInputPhraseMatchResponse(inputPhrase, data)) { listBuilders = listBuilderService.processData(listBuilders, inputPhrase); - loadElements(listBuilders, inputPhrase); - + loadElements(listBuilders, inputPhrase); + } - if (listBuilderService.checkIfDataExists(listBuilders) && $field.parent().find("li").length > 0) { - showContainer(); + if ((listBuilderService.checkIfDataExists(listBuilders) && $field.parent().find("li").length > 0) || config.get("noResults")) { + showContainer(); } else { hideContainer(); } @@ -1397,7 +1402,7 @@ var EasyAutocomplete = (function(scope) { }); } - + function createAjaxSettings() { @@ -1441,7 +1446,7 @@ var EasyAutocomplete = (function(scope) { evt = evt || window.event; var keyCode = evt.keyCode; if (keyCode === 38) { - suppressKeypress = true; + suppressKeypress = true; return false; } }) @@ -1471,18 +1476,18 @@ var EasyAutocomplete = (function(scope) { $field.focus(function() { if ($field.val() !== "" && elementsList.length > 0) { - + selectedElement = -1; - showContainer(); + showContainer(); } - + }); } function bindBlur() { $field.blur(function() { - setTimeout(function() { - + setTimeout(function() { + selectedElement = -1; hideContainer(); }, 250); @@ -1504,7 +1509,7 @@ var EasyAutocomplete = (function(scope) { } function selectElement(index) { - + $container.trigger("selectElement.eac", index); } @@ -1539,13 +1544,13 @@ var EasyAutocomplete = (function(scope) { var fieldId = ""; do { - fieldId = "eac-" + Math.floor(Math.random() * 10000); + fieldId = "eac-" + Math.floor(Math.random() * 10000); } while ($("#" + fieldId).length !== 0); - + elementId = scope.consts.getValue("CONTAINER_ID") + fieldId; $(input).attr("id", fieldId); - + }; scope.setHandle = function(handle, id) { diff --git a/dist/jquery.easy-autocomplete.min.js b/dist/jquery.easy-autocomplete.min.js index 70630c5..ff0a4cd 100644 --- a/dist/jquery.easy-autocomplete.min.js +++ b/dist/jquery.easy-autocomplete.min.js @@ -3,8 +3,8 @@ * jQuery plugin for autocompletion * * @author Łukasz Pawełczak (http://github.com/pawelczak) - * @version 1.3.5 + * @version 1.3.6 * Copyright License: */ -var EasyAutocomplete=function(a){return a.Configuration=function(a){function b(){if("xml"===a.dataType&&(a.getValue||(a.getValue=function(a){return $(a).text()}),a.list||(a.list={}),a.list.sort||(a.list.sort={}),a.list.sort.method=function(b,c){return b=a.getValue(b),c=a.getValue(c),c>b?-1:b>c?1:0},a.list.match||(a.list.match={}),a.list.match.method=function(a,b){return a.search(b)>-1}),void 0!==a.categories&&a.categories instanceof Array){for(var b=[],c=0,d=a.categories.length;d>c;c+=1){var e=a.categories[c];for(var f in h.categories[0])void 0===e[f]&&(e[f]=h.categories[0][f]);b.push(e)}a.categories=b}}function c(){function b(a,c){var d=a||{};for(var e in a)void 0!==c[e]&&null!==c[e]&&("object"!=typeof c[e]||c[e]instanceof Array?d[e]=c[e]:b(a[e],c[e]));return void 0!==c.data&&null!==c.data&&"object"==typeof c.data&&(d.data=c.data),d}h=b(h,a)}function d(){if("list-required"!==h.url&&"function"!=typeof h.url){var b=h.url;h.url=function(){return b}}if(void 0!==h.ajaxSettings.url&&"function"!=typeof h.ajaxSettings.url){var b=h.ajaxSettings.url;h.ajaxSettings.url=function(){return b}}if("string"==typeof h.listLocation){var c=h.listLocation;"XML"===h.dataType.toUpperCase()?h.listLocation=function(a){return $(a).find(c)}:h.listLocation=function(a){return a[c]}}if("string"==typeof h.getValue){var d=h.getValue;h.getValue=function(a){return a[d]}}void 0!==a.categories&&(h.categoriesAssigned=!0)}function e(){void 0!==a.ajaxSettings&&"object"==typeof a.ajaxSettings?h.ajaxSettings=a.ajaxSettings:h.ajaxSettings={}}function f(a){return void 0!==h[a]&&null!==h[a]}function g(a,b){function c(b,d){for(var e in d)void 0===b[e]&&a.log("Property '"+e+"' does not exist in EasyAutocomplete options API."),"object"==typeof b[e]&&-1===$.inArray(e,i)&&c(b[e],d[e])}c(h,b)}var h={data:"list-required",url:"list-required",dataType:"json",listLocation:function(a){return a},xmlElementName:"",getValue:function(a){return a},autocompleteOff:!0,placeholder:!1,ajaxCallback:function(){},matchResponseProperty:!1,list:{sort:{enabled:!1,method:function(a,b){return a=h.getValue(a),b=h.getValue(b),b>a?-1:a>b?1:0}},maxNumberOfElements:6,hideOnEmptyPhrase:!0,match:{enabled:!1,caseSensitive:!1,method:function(a,b){return a.search(b)>-1}},showAnimation:{type:"normal",time:400,callback:function(){}},hideAnimation:{type:"normal",time:400,callback:function(){}},onClickEvent:function(){},onSelectItemEvent:function(){},onLoadEvent:function(){},onChooseEvent:function(){},onKeyEnterEvent:function(){},onMouseOverEvent:function(){},onMouseOutEvent:function(){},onShowListEvent:function(){},onHideListEvent:function(){}},highlightPhrase:!0,theme:"",cssClasses:"",minCharNumber:0,requestDelay:0,adjustWidth:!0,ajaxSettings:{},preparePostData:function(a,b){return a},loggerEnabled:!0,template:"",categoriesAssigned:!1,categories:[{maxNumberOfElements:4}]},i=["ajaxSettings","template"];this.get=function(a){return h[a]},this.equals=function(a,b){return!(!f(a)||h[a]!==b)},this.checkDataUrlProperties=function(){return"list-required"!==h.url||"list-required"!==h.data},this.checkRequiredProperties=function(){for(var a in h)if("required"===h[a])return logger.error("Option "+a+" must be defined"),!1;return!0},this.printPropertiesThatDoesntExist=function(a,b){g(a,b)},b(),c(),h.loggerEnabled===!0&&g(console,a),e(),d()},a}(EasyAutocomplete||{}),EasyAutocomplete=function(a){return a.Logger=function(){this.error=function(a){console.log("ERROR: "+a)},this.warning=function(a){console.log("WARNING: "+a)}},a}(EasyAutocomplete||{}),EasyAutocomplete=function(a){return a.Constans=function(){var a={CONTAINER_CLASS:"easy-autocomplete-container",CONTAINER_ID:"eac-container-",WRAPPER_CSS_CLASS:"easy-autocomplete"};this.getValue=function(b){return a[b]}},a}(EasyAutocomplete||{}),EasyAutocomplete=function(a){return a.ListBuilderService=function(a,b){function c(b,c){function d(){var d,e={};return void 0!==b.xmlElementName&&(e.xmlElementName=b.xmlElementName),void 0!==b.listLocation?d=b.listLocation:void 0!==a.get("listLocation")&&(d=a.get("listLocation")),void 0!==d?"string"==typeof d?e.data=$(c).find(d):"function"==typeof d&&(e.data=d(c)):e.data=c,e}function e(){var a={};return void 0!==b.listLocation?"string"==typeof b.listLocation?a.data=c[b.listLocation]:"function"==typeof b.listLocation&&(a.data=b.listLocation(c)):a.data=c,a}var f={};if(f="XML"===a.get("dataType").toUpperCase()?d():e(),void 0!==b.header&&(f.header=b.header),void 0!==b.maxNumberOfElements&&(f.maxNumberOfElements=b.maxNumberOfElements),void 0!==a.get("list").maxNumberOfElements&&(f.maxListSize=a.get("list").maxNumberOfElements),void 0!==b.getValue)if("string"==typeof b.getValue){var g=b.getValue;f.getValue=function(a){return a[g]}}else"function"==typeof b.getValue&&(f.getValue=b.getValue);else f.getValue=a.get("getValue");return f}function d(b){var c=[];return void 0===b.xmlElementName&&(b.xmlElementName=a.get("xmlElementName")),$(b.data).find(b.xmlElementName).each(function(){c.push(this)}),c}this.init=function(b){var c=[],d={};return d.data=a.get("listLocation")(b),d.getValue=a.get("getValue"),d.maxListSize=a.get("list").maxNumberOfElements,c.push(d),c},this.updateCategories=function(b,d){if(a.get("categoriesAssigned")){b=[];for(var e=0;ee;e+=1)c[e].data=b(a,c[e],d);return c},this.checkIfDataExists=function(a){for(var b=0,c=a.length;c>b;b+=1)if(void 0!==a[b].data&&a[b].data instanceof Array&&a[b].data.length>0)return!0;return!1}},a}(EasyAutocomplete||{}),EasyAutocomplete=function(a){return a.proccess=function(b,c,d){function e(a,c){var d=[],e="";if(b.get("list").match.enabled)for(var g=0,h=a.length;h>g;g+=1)e=b.get("getValue")(a[g]),f(e,c)&&d.push(a[g]);else d=a;return d}function f(a,c){return b.get("list").match.caseSensitive||("string"==typeof a&&(a=a.toLowerCase()),c=c.toLowerCase()),!!b.get("list").match.method(a,c)}function g(a){return void 0!==c.maxNumberOfElements&&a.length>c.maxNumberOfElements&&(a=a.slice(0,c.maxNumberOfElements)),a}function h(a){return b.get("list").sort.enabled&&a.sort(b.get("list").sort.method),a}a.proccess.match=f;var i=c.data,j=d;return i=e(i,j),i=g(i),i=h(i)},a}(EasyAutocomplete||{}),EasyAutocomplete=function(a){return a.Template=function(a){var b={basic:{type:"basic",method:function(a){return a},cssClass:""},description:{type:"description",fields:{description:"description"},method:function(a){return a+" - description"},cssClass:"eac-description"},iconLeft:{type:"iconLeft",fields:{icon:""},method:function(a){return a},cssClass:"eac-icon-left"},iconRight:{type:"iconRight",fields:{iconSrc:""},method:function(a){return a},cssClass:"eac-icon-right"},links:{type:"links",fields:{link:""},method:function(a){return a},cssClass:""},custom:{type:"custom",method:function(){},cssClass:""}},c=function(a){var c,d=a.fields;return"description"===a.type?(c=b.description.method,"string"==typeof d.description?c=function(a,b){return a+" - "+b[d.description]+""}:"function"==typeof d.description&&(c=function(a,b){return a+" - "+d.description(b)+""}),c):"iconRight"===a.type?("string"==typeof d.iconSrc?c=function(a,b){return a+""}:"function"==typeof d.iconSrc&&(c=function(a,b){return a+""}),c):"iconLeft"===a.type?("string"==typeof d.iconSrc?c=function(a,b){return""+a}:"function"==typeof d.iconSrc&&(c=function(a,b){return""+a}),c):"links"===a.type?("string"==typeof d.link?c=function(a,b){return""+a+""}:"function"==typeof d.link&&(c=function(a,b){return""+a+""}),c):"custom"===a.type?a.method:b.basic.method},d=function(a){return a&&a.type&&a.type&&b[a.type]?c(a):b.basic.method},e=function(a){var c=function(){return""};return a&&a.type&&a.type&&b[a.type]?function(){var c=b[a.type].cssClass;return function(){return c}}():c};this.getTemplateClass=e(a),this.build=d(a)},a}(EasyAutocomplete||{}),EasyAutocomplete=function(a){return a.main=function(b,c){function d(){return 0===t.length?void p.error("Input field doesn't exist."):o.checkDataUrlProperties()?o.checkRequiredProperties()?(e(),void g()):void p.error("Will not work without mentioned properties."):void p.error("One of options variables 'data' or 'url' must be defined.")}function e(){function a(){var a=$("
    "),c=n.getValue("WRAPPER_CSS_CLASS");o.get("theme")&&""!==o.get("theme")&&(c+=" eac-"+o.get("theme")),o.get("cssClasses")&&""!==o.get("cssClasses")&&(c+=" "+o.get("cssClasses")),""!==q.getTemplateClass()&&(c+=" "+q.getTemplateClass()),a.addClass(c),t.wrap(a),o.get("adjustWidth")===!0&&b()}function b(){var a=t.outerWidth();t.parent().css("width",a)}function c(){t.unwrap()}function d(){var a=$("
    ").addClass(n.getValue("CONTAINER_CLASS"));a.attr("id",f()).prepend($("
      ")),function(){a.on("show.eac",function(){switch(o.get("list").showAnimation.type){case"slide":var b=o.get("list").showAnimation.time,c=o.get("list").showAnimation.callback;a.find("ul").slideDown(b,c);break;case"fade":var b=o.get("list").showAnimation.time,c=o.get("list").showAnimation.callback;a.find("ul").fadeIn(b),c;break;default:a.find("ul").show()}o.get("list").onShowListEvent()}).on("hide.eac",function(){switch(o.get("list").hideAnimation.type){case"slide":var b=o.get("list").hideAnimation.time,c=o.get("list").hideAnimation.callback;a.find("ul").slideUp(b,c);break;case"fade":var b=o.get("list").hideAnimation.time,c=o.get("list").hideAnimation.callback;a.find("ul").fadeOut(b,c);break;default:a.find("ul").hide()}o.get("list").onHideListEvent()}).on("selectElement.eac",function(){a.find("ul li").removeClass("selected"),a.find("ul li").eq(w).addClass("selected"),o.get("list").onSelectItemEvent()}).on("loadElements.eac",function(b,c,d){var e="",f=a.find("ul");f.empty().detach(),v=[];for(var h=0,i=0,k=c.length;k>i;i+=1){var l=c[i].data;if(0!==l.length){void 0!==c[i].header&&c[i].header.length>0&&f.append("
      "+c[i].header+"
      ");for(var m=0,n=l.length;n>m&&h
      "),function(){var a=m,b=h,f=c[i].getValue(l[a]);e.find(" > div").on("click",function(){t.val(f).trigger("change"),w=b,j(b),o.get("list").onClickEvent(),o.get("list").onChooseEvent()}).mouseover(function(){w=b,j(b),o.get("list").onMouseOverEvent()}).mouseout(function(){o.get("list").onMouseOutEvent()}).html(q.build(g(f,d),l[a]))}(),f.append(e),v.push(l[m]),h+=1}}a.append(f),o.get("list").onLoadEvent()})}(),t.after(a)}function e(){t.next("."+n.getValue("CONTAINER_CLASS")).remove()}function g(a,b){return o.get("highlightPhrase")&&""!==b?i(a,b):a}function h(a){return a.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g,"\\$&")}function i(a,b){var c=h(b);return(a+"").replace(new RegExp("("+c+")","gi"),"$1")}t.parent().hasClass(n.getValue("WRAPPER_CSS_CLASS"))&&(e(),c()),a(),d(),u=$("#"+f()),o.get("placeholder")&&t.attr("placeholder",o.get("placeholder"))}function f(){var a=t.attr("id");return a=n.getValue("CONTAINER_ID")+a}function g(){function a(){s("autocompleteOff",!0)&&n(),b(),c(),d(),e(),f(),g()}function b(){t.focusout(function(){var a,b=t.val();o.get("list").match.caseSensitive||(b=b.toLowerCase());for(var c=0,d=v.length;d>c;c+=1)if(a=o.get("getValue")(v[c]),o.get("list").match.caseSensitive||(a=a.toLowerCase()),a===b)return w=c,void j(w)})}function c(){t.off("keyup").keyup(function(a){function b(a){function b(){var a={},b=o.get("ajaxSettings")||{};for(var c in b)a[c]=b[c];return a}function c(a,b){return o.get("matchResponseProperty")!==!1?"string"==typeof o.get("matchResponseProperty")?b[o.get("matchResponseProperty")]===a:"function"==typeof o.get("matchResponseProperty")?o.get("matchResponseProperty")(b)===a:!0:!0}if(!(a.length0?h():i()}var f=b();void 0!==f.url&&""!==f.url||(f.url=o.get("url")),void 0!==f.dataType&&""!==f.dataType||(f.dataType=o.get("dataType")),void 0!==f.url&&"list-required"!==f.url&&(f.url=f.url(a),f.data=o.get("preparePostData")(f.data,a),$.ajax(f).done(function(b){var d=r.init(b);d=r.updateCategories(d,b),d=r.convertXml(d),c(a,b)&&(d=r.processData(d,a),k(d,a)),r.checkIfDataExists(d)&&t.parent().find("li").length>0?h():i(),o.get("ajaxCallback")()}).fail(function(){p.warning("Fail to load response data")}).always(function(){}))}}switch(a.keyCode){case 27:i(),l();break;case 38:a.preventDefault(),v.length>0&&w>0&&(w-=1,t.val(o.get("getValue")(v[w])),j(w));break;case 40:a.preventDefault(),v.length>0&&w40||8===a.keyCode){var c=t.val();o.get("list").hideOnEmptyPhrase!==!0||8!==a.keyCode||""!==c?o.get("requestDelay")>0?(void 0!==m&&clearTimeout(m),m=setTimeout(function(){b(c)},o.get("requestDelay"))):b(c):i()}}})}function d(){t.on("keydown",function(a){a=a||window.event;var b=a.keyCode;return 38===b?(suppressKeypress=!0,!1):void 0}).keydown(function(a){13===a.keyCode&&w>-1&&(t.val(o.get("getValue")(v[w])),o.get("list").onKeyEnterEvent(),o.get("list").onChooseEvent(),w=-1,i(),a.preventDefault())})}function e(){t.off("keypress")}function f(){t.focus(function(){""!==t.val()&&v.length>0&&(w=-1,h())})}function g(){t.blur(function(){setTimeout(function(){w=-1,i()},250)})}function n(){t.attr("autocomplete","off")}a()}function h(){u.trigger("show.eac")}function i(){u.trigger("hide.eac")}function j(a){u.trigger("selectElement.eac",a)}function k(a,b){u.trigger("loadElements.eac",[a,b])}function l(){t.trigger("blur")}var m,n=new a.Constans,o=new a.Configuration(c),p=new a.Logger,q=new a.Template(c.template),r=new a.ListBuilderService(o,a.proccess),s=o.equals,t=b,u="",v=[],w=-1;a.consts=n,this.getConstants=function(){return n},this.getConfiguration=function(){return o},this.getContainer=function(){return u},this.getSelectedItemIndex=function(){return w},this.getItems=function(){return v},this.getItemData=function(a){return v.length0},a.assignRandomId=function(b){var c="";do c="eac-"+Math.floor(1e4*Math.random());while(0!==$("#"+c).length);elementId=a.consts.getValue("CONTAINER_ID")+c,$(b).attr("id",c)},a.setHandle=function(b,c){a.eacHandles[c]=b},a}(EasyAutocomplete||{});!function(a){a.fn.easyAutocomplete=function(b){return this.each(function(){var c=a(this),d=new EasyAutocomplete.main(c,b);EasyAutocomplete.inputHasId(c)||EasyAutocomplete.assignRandomId(c),d.init(),EasyAutocomplete.setHandle(d,c.attr("id"))})},a.fn.getSelectedItemIndex=function(){var b=a(this).attr("id");return void 0!==b?EasyAutocomplete.getHandle(b).getSelectedItemIndex():-1},a.fn.getItems=function(){var b=a(this).attr("id");return void 0!==b?EasyAutocomplete.getHandle(b).getItems():-1},a.fn.getItemData=function(b){var c=a(this).attr("id");return void 0!==c&&b>-1?EasyAutocomplete.getHandle(c).getItemData(b):-1},a.fn.getSelectedItemData=function(){var b=a(this).attr("id");return void 0!==b?EasyAutocomplete.getHandle(b).getSelectedItemData():-1}}(jQuery); \ No newline at end of file +var EasyAutocomplete=function(a){return a.Configuration=function(a){function b(){if("xml"===a.dataType&&(a.getValue||(a.getValue=function(a){return $(a).text()}),a.list||(a.list={}),a.list.sort||(a.list.sort={}),a.list.sort.method=function(b,c){return b=a.getValue(b),c=a.getValue(c),bc?1:0},a.list.match||(a.list.match={}),a.list.match.method=function(a,b){return a.search(b)>-1}),void 0!==a.categories&&a.categories instanceof Array){for(var b=[],c=0,d=a.categories.length;cb?1:0}},maxNumberOfElements:6,hideOnEmptyPhrase:!0,match:{enabled:!1,caseSensitive:!1,method:function(a,b){return a.search(b)>-1}},showAnimation:{type:"normal",time:400,callback:function(){}},hideAnimation:{type:"normal",time:400,callback:function(){}},onClickEvent:function(){},onSelectItemEvent:function(){},onLoadEvent:function(){},onChooseEvent:function(){},onKeyEnterEvent:function(){},onMouseOverEvent:function(){},onMouseOutEvent:function(){},onShowListEvent:function(){},onHideListEvent:function(){}},highlightPhrase:!0,theme:"",cssClasses:"",minCharNumber:0,requestDelay:0,adjustWidth:!0,noResults:!1,ajaxSettings:{},preparePostData:function(a,b){return a},loggerEnabled:!0,template:"",categoriesAssigned:!1,categories:[{maxNumberOfElements:4}]},i=["ajaxSettings","template"];this.get=function(a){return h[a]},this.equals=function(a,b){return!(!f(a)||h[a]!==b)},this.checkDataUrlProperties=function(){return"list-required"!==h.url||"list-required"!==h.data},this.checkRequiredProperties=function(){for(var a in h)if("required"===h[a])return logger.error("Option "+a+" must be defined"),!1;return!0},this.printPropertiesThatDoesntExist=function(a,b){g(a,b)},b(),c(),!0===h.loggerEnabled&&g(console,a),e(),d()},a}(EasyAutocomplete||{}),EasyAutocomplete=function(a){return a.Logger=function(){this.error=function(a){console.log("ERROR: "+a)},this.warning=function(a){console.log("WARNING: "+a)}},a}(EasyAutocomplete||{}),EasyAutocomplete=function(a){return a.Constans=function(){var a={CONTAINER_CLASS:"easy-autocomplete-container",CONTAINER_ID:"eac-container-",WRAPPER_CSS_CLASS:"easy-autocomplete"};this.getValue=function(b){return a[b]}},a}(EasyAutocomplete||{}),EasyAutocomplete=function(a){return a.ListBuilderService=function(a,b){function c(b,c){function d(){var d,e={};return void 0!==b.xmlElementName&&(e.xmlElementName=b.xmlElementName),void 0!==b.listLocation?d=b.listLocation:void 0!==a.get("listLocation")&&(d=a.get("listLocation")),void 0!==d?"string"==typeof d?e.data=$(c).find(d):"function"==typeof d&&(e.data=d(c)):e.data=c,e}function e(){var a={};return void 0!==b.listLocation?"string"==typeof b.listLocation?a.data=c[b.listLocation]:"function"==typeof b.listLocation&&(a.data=b.listLocation(c)):a.data=c,a}var f={};if(f="XML"===a.get("dataType").toUpperCase()?d():e(),void 0!==b.header&&(f.header=b.header),void 0!==b.maxNumberOfElements&&(f.maxNumberOfElements=b.maxNumberOfElements),void 0!==a.get("list").maxNumberOfElements&&(f.maxListSize=a.get("list").maxNumberOfElements),void 0!==b.getValue)if("string"==typeof b.getValue){var g=b.getValue;f.getValue=function(a){return a[g]}}else"function"==typeof b.getValue&&(f.getValue=b.getValue);else f.getValue=a.get("getValue");return f}function d(b){var c=[];return void 0===b.xmlElementName&&(b.xmlElementName=a.get("xmlElementName")),$(b.data).find(b.xmlElementName).each(function(){c.push(this)}),c}this.init=function(b){var c=[],d={};return d.data=a.get("listLocation")(b),d.getValue=a.get("getValue"),d.maxListSize=a.get("list").maxNumberOfElements,c.push(d),c},this.updateCategories=function(b,d){if(a.get("categoriesAssigned")){b=[];for(var e=0;e0)return!0;return!1}},a}(EasyAutocomplete||{}),EasyAutocomplete=function(a){return a.proccess=function(b,c,d){function e(a,c){var d=[],e="";if(b.get("list").match.enabled)for(var g=0,h=a.length;gc.maxNumberOfElements&&(a=a.slice(0,c.maxNumberOfElements)),a}function h(a){return b.get("list").sort.enabled&&a.sort(b.get("list").sort.method),a}a.proccess.match=f;var i=c.data;return i=e(i,d),i=g(i),i=h(i)},a}(EasyAutocomplete||{}),EasyAutocomplete=function(a){return a.Template=function(a){var b={basic:{type:"basic",method:function(a){return a},cssClass:""},description:{type:"description",fields:{description:"description"},method:function(a){return a+" - description"},cssClass:"eac-description"},iconLeft:{type:"iconLeft",fields:{icon:""},method:function(a){return a},cssClass:"eac-icon-left"},iconRight:{type:"iconRight",fields:{iconSrc:""},method:function(a){return a},cssClass:"eac-icon-right"},links:{type:"links",fields:{link:""},method:function(a){return a},cssClass:""},custom:{type:"custom",method:function(){},cssClass:""}},c=function(a){var c,d=a.fields;return"description"===a.type?(c=b.description.method,"string"==typeof d.description?c=function(a,b){return a+" - "+b[d.description]+""}:"function"==typeof d.description&&(c=function(a,b){return a+" - "+d.description(b)+""}),c):"iconRight"===a.type?("string"==typeof d.iconSrc?c=function(a,b){return a+""}:"function"==typeof d.iconSrc&&(c=function(a,b){return a+""}),c):"iconLeft"===a.type?("string"==typeof d.iconSrc?c=function(a,b){return""+a}:"function"==typeof d.iconSrc&&(c=function(a,b){return""+a}),c):"links"===a.type?("string"==typeof d.link?c=function(a,b){return""+a+""}:"function"==typeof d.link&&(c=function(a,b){return""+a+""}),c):"custom"===a.type?a.method:b.basic.method},d=function(a){return a&&a.type&&a.type&&b[a.type]?c(a):b.basic.method},e=function(a){var c=function(){return""};return a&&a.type&&a.type&&b[a.type]?function(){var c=b[a.type].cssClass;return function(){return c}}():c};this.getTemplateClass=e(a),this.build=d(a)},a}(EasyAutocomplete||{}),EasyAutocomplete=function(a){return a.main=function(b,c){function d(){return 0===t.length?void p.error("Input field doesn't exist."):o.checkDataUrlProperties()?o.checkRequiredProperties()?(e(),void g()):void p.error("Will not work without mentioned properties."):void p.error("One of options variables 'data' or 'url' must be defined.")}function e(){function a(){var a=$("
      "),c=n.getValue("WRAPPER_CSS_CLASS");o.get("theme")&&""!==o.get("theme")&&(c+=" eac-"+o.get("theme")),o.get("cssClasses")&&""!==o.get("cssClasses")&&(c+=" "+o.get("cssClasses")),""!==q.getTemplateClass()&&(c+=" "+q.getTemplateClass()),a.addClass(c),t.wrap(a),!0===o.get("adjustWidth")&&b()}function b(){var a=t.outerWidth();t.parent().css("width",a)}function c(){t.unwrap()}function d(){var a=$("
      ").addClass(n.getValue("CONTAINER_CLASS"));a.attr("id",f()).prepend($("
        ")),function(){a.on("show.eac",function(){switch(o.get("list").showAnimation.type){case"slide":var b=o.get("list").showAnimation.time,c=o.get("list").showAnimation.callback;a.find("ul").slideDown(b,c);break;case"fade":var b=o.get("list").showAnimation.time,c=o.get("list").showAnimation.callback;a.find("ul").fadeIn(b);break;default:a.find("ul").show()}o.get("list").onShowListEvent()}).on("hide.eac",function(){switch(o.get("list").hideAnimation.type){case"slide":var b=o.get("list").hideAnimation.time,c=o.get("list").hideAnimation.callback;a.find("ul").slideUp(b,c);break;case"fade":var b=o.get("list").hideAnimation.time,c=o.get("list").hideAnimation.callback;a.find("ul").fadeOut(b,c);break;default:a.find("ul").hide()}o.get("list").onHideListEvent()}).on("selectElement.eac",function(){a.find("ul li").removeClass("selected"),a.find("ul li").eq(w).addClass("selected"),o.get("list").onSelectItemEvent()}).on("loadElements.eac",function(b,c,d){var e="",f=a.find("ul");f.empty().detach(),v=[];for(var h=0,i=0,k=c.length;i0&&f.append("
        "+c[i].header+"
        ");for(var m=0,n=l.length;m
        "),function(){var a=m,b=h,f=c[i].getValue(l[a]);e.find(" > div").on("click",function(){t.val(f).trigger("change"),w=b,j(b),o.get("list").onClickEvent(),o.get("list").onChooseEvent()}).mouseover(function(){w=b,j(b),o.get("list").onMouseOverEvent()}).mouseout(function(){o.get("list").onMouseOutEvent()}).html(q.build(g(f,d),l[a]))}(),f.append(e),v.push(l[m]),h+=1}}o.get("noResults")&&0==h&&f.append("
      • "+o.get("noResults")+"
      • "),a.append(f),o.get("list").onLoadEvent()})}(),t.after(a)}function e(){t.next("."+n.getValue("CONTAINER_CLASS")).remove()}function g(a,b){return o.get("highlightPhrase")&&""!==b?i(a,b):a}function h(a){return a.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g,"\\$&")}function i(a,b){var c=h(b);return(a+"").replace(new RegExp("("+c+")","gi"),"$1")}t.parent().hasClass(n.getValue("WRAPPER_CSS_CLASS"))&&(e(),c()),a(),d(),u=$("#"+f()),o.get("placeholder")&&t.attr("placeholder",o.get("placeholder"))}function f(){var a=t.attr("id");return a=n.getValue("CONTAINER_ID")+a}function g(){function a(){s("autocompleteOff",!0)&&n(),b(),c(),d(),e(),f(),g()}function b(){t.focusout(function(){var a,b=t.val();o.get("list").match.caseSensitive||(b=b.toLowerCase());for(var c=0,d=v.length;c0?h():i()}var f=b();void 0!==f.url&&""!==f.url||(f.url=o.get("url")),void 0!==f.dataType&&""!==f.dataType||(f.dataType=o.get("dataType")),void 0!==f.url&&"list-required"!==f.url&&(f.url=f.url(a),f.data=o.get("preparePostData")(f.data,a),$.ajax(f).done(function(b){var d=r.init(b);d=r.updateCategories(d,b),d=r.convertXml(d),c(a,b)&&(d=r.processData(d,a),k(d,a)),r.checkIfDataExists(d)&&t.parent().find("li").length>0||o.get("noResults")?h():i(),o.get("ajaxCallback")()}).fail(function(){p.warning("Fail to load response data")}).always(function(){}))}}switch(a.keyCode){case 27:i(),l();break;case 38:a.preventDefault(),v.length>0&&w>0&&(w-=1,t.val(o.get("getValue")(v[w])),j(w));break;case 40:a.preventDefault(),v.length>0&&w40||8===a.keyCode){var c=t.val();!0!==o.get("list").hideOnEmptyPhrase||8!==a.keyCode||""!==c?o.get("requestDelay")>0?(void 0!==m&&clearTimeout(m),m=setTimeout(function(){b(c)},o.get("requestDelay"))):b(c):i()}}})}function d(){t.on("keydown",function(a){if(a=a||window.event,38===a.keyCode)return suppressKeypress=!0,!1}).keydown(function(a){13===a.keyCode&&w>-1&&(t.val(o.get("getValue")(v[w])),o.get("list").onKeyEnterEvent(),o.get("list").onChooseEvent(),w=-1,i(),a.preventDefault())})}function e(){t.off("keypress")}function f(){t.focus(function(){""!==t.val()&&v.length>0&&(w=-1,h())})}function g(){t.blur(function(){setTimeout(function(){w=-1,i()},250)})}function n(){t.attr("autocomplete","off")}a()}function h(){u.trigger("show.eac")}function i(){u.trigger("hide.eac")}function j(a){u.trigger("selectElement.eac",a)}function k(a,b){u.trigger("loadElements.eac",[a,b])}function l(){t.trigger("blur")}var m,n=new a.Constans,o=new a.Configuration(c),p=new a.Logger,q=new a.Template(c.template),r=new a.ListBuilderService(o,a.proccess),s=o.equals,t=b,u="",v=[],w=-1;a.consts=n,this.getConstants=function(){return n},this.getConfiguration=function(){return o},this.getContainer=function(){return u},this.getSelectedItemIndex=function(){return w},this.getItems=function(){return v},this.getItemData=function(a){return v.length0},a.assignRandomId=function(b){var c="";do{c="eac-"+Math.floor(1e4*Math.random())}while(0!==$("#"+c).length);elementId=a.consts.getValue("CONTAINER_ID")+c,$(b).attr("id",c)},a.setHandle=function(b,c){a.eacHandles[c]=b},a}(EasyAutocomplete||{});!function(a){a.fn.easyAutocomplete=function(b){return this.each(function(){var c=a(this),d=new EasyAutocomplete.main(c,b);EasyAutocomplete.inputHasId(c)||EasyAutocomplete.assignRandomId(c),d.init(),EasyAutocomplete.setHandle(d,c.attr("id"))})},a.fn.getSelectedItemIndex=function(){var b=a(this).attr("id");return void 0!==b?EasyAutocomplete.getHandle(b).getSelectedItemIndex():-1},a.fn.getItems=function(){var b=a(this).attr("id");return void 0!==b?EasyAutocomplete.getHandle(b).getItems():-1},a.fn.getItemData=function(b){var c=a(this).attr("id");return void 0!==c&&b>-1?EasyAutocomplete.getHandle(c).getItemData(b):-1},a.fn.getSelectedItemData=function(){var b=a(this).attr("id");return void 0!==b?EasyAutocomplete.getHandle(b).getSelectedItemData():-1}}(jQuery); \ No newline at end of file diff --git a/dist/maps/easy-autocomplete.css.map b/dist/maps/easy-autocomplete.css.map index 508eaf2..102f734 100644 --- a/dist/maps/easy-autocomplete.css.map +++ b/dist/maps/easy-autocomplete.css.map @@ -3,7 +3,7 @@ * jQuery plugin for autocompletion * * @author Łukasz Pawełczak (http://github.com/pawelczak) - * @version 1.3.5 + * @version 1.3.6 * Copyright License: */ diff --git a/dist/maps/easy-autocomplete.min.css.map b/dist/maps/easy-autocomplete.min.css.map index 7f17ebf..4a6dab2 100644 --- a/dist/maps/easy-autocomplete.min.css.map +++ b/dist/maps/easy-autocomplete.min.css.map @@ -3,7 +3,7 @@ * jQuery plugin for autocompletion * * @author Łukasz Pawełczak (http://github.com/pawelczak) - * @version 1.3.5 + * @version 1.3.6 * Copyright License: */ diff --git a/dist/maps/easy-autocomplete.themes.css.map b/dist/maps/easy-autocomplete.themes.css.map index 25ac1df..771d1f8 100644 --- a/dist/maps/easy-autocomplete.themes.css.map +++ b/dist/maps/easy-autocomplete.themes.css.map @@ -3,7 +3,7 @@ * jQuery plugin for autocompletion * * @author Łukasz Pawełczak (http://github.com/pawelczak) - * @version 1.3.5 + * @version 1.3.6 * Copyright License: */ diff --git a/dist/maps/easy-autocomplete.themes.min.css.map b/dist/maps/easy-autocomplete.themes.min.css.map index a67929b..da54b57 100644 --- a/dist/maps/easy-autocomplete.themes.min.css.map +++ b/dist/maps/easy-autocomplete.themes.min.css.map @@ -3,7 +3,7 @@ * jQuery plugin for autocompletion * * @author Łukasz Pawełczak (http://github.com/pawelczak) - * @version 1.3.5 + * @version 1.3.6 * Copyright License: */ diff --git a/package.json b/package.json index 534782b..6362a8b 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "name": "easy-autocomplete", "title": "jQuery plugin for autocompletion", "author": "Łukasz Pawełczak (http://github.com/pawelczak)", - "version": "1.3.5", + "version": "1.3.6", "keywords": [ "jquery", "jquery-plugin", diff --git a/src/configuration.js b/src/configuration.js index aa734d2..b25f11d 100644 --- a/src/configuration.js +++ b/src/configuration.js @@ -1,5 +1,5 @@ /* - * EasyAutocomplete - Configuration + * EasyAutocomplete - Configuration */ var EasyAutocomplete = (function(scope){ @@ -81,7 +81,7 @@ var EasyAutocomplete = (function(scope){ onChooseEvent: function() {}, onKeyEnterEvent: function() {}, onMouseOverEvent: function() {}, - onMouseOutEvent: function() {}, + onMouseOutEvent: function() {}, onShowListEvent: function() {}, onHideListEvent: function() {} }, @@ -98,6 +98,8 @@ var EasyAutocomplete = (function(scope){ adjustWidth: true, + noResults: false, + ajaxSettings: {}, preparePostData: function(data, inputPhrase) {return data;}, @@ -114,7 +116,7 @@ var EasyAutocomplete = (function(scope){ }] }; - + var externalObjects = ["ajaxSettings", "template"]; this.get = function(propertyName) { @@ -126,8 +128,8 @@ var EasyAutocomplete = (function(scope){ if (defaults[name] === value) { return true; } - } - + } + return false; }; @@ -159,7 +161,7 @@ var EasyAutocomplete = (function(scope){ mergeOptions(); if (defaults.loggerEnabled === true) { - printPropertiesThatDoesntExist(console, options); + printPropertiesThatDoesntExist(console, options); } addAjaxSettings(); @@ -174,7 +176,7 @@ var EasyAutocomplete = (function(scope){ function prepareDefaults() { if (options.dataType === "xml") { - + if (!options.getValue) { options.getValue = function(element) { @@ -182,11 +184,11 @@ var EasyAutocomplete = (function(scope){ }; } - + if (!options.list) { options.list = {}; - } + } if (!options.list.sort) { options.list.sort = {}; @@ -196,7 +198,7 @@ var EasyAutocomplete = (function(scope){ options.list.sort.method = function(a, b) { a = options.getValue(a); b = options.getValue(b); - + //Alphabeticall sort if (a < b) { return -1; @@ -227,7 +229,7 @@ var EasyAutocomplete = (function(scope){ var categories = []; - for (var i = 0, length = options.categories.length; i < length; i += 1) { + for (var i = 0, length = options.categories.length; i < length; i += 1) { var category = options.categories[i]; @@ -258,7 +260,7 @@ var EasyAutocomplete = (function(scope){ for (var propertyName in source) { if (target[propertyName] !== undefined && target[propertyName] !== null) { - if (typeof target[propertyName] !== "object" || + if (typeof target[propertyName] !== "object" || target[propertyName] instanceof Array) { mergedObject[propertyName] = target[propertyName]; } else { @@ -266,7 +268,7 @@ var EasyAutocomplete = (function(scope){ } } } - + /* If data is an object */ if (target.data !== undefined && target.data !== null && typeof target.data === "object") { mergedObject.data = target.data; @@ -274,11 +276,11 @@ var EasyAutocomplete = (function(scope){ return mergedObject; } - } + } function processAfterMerge() { - + if (defaults.url !== "list-required" && typeof defaults.url !== "function") { var defaultUrl = defaults.url; defaults.url = function() { @@ -303,7 +305,7 @@ var EasyAutocomplete = (function(scope){ } else { defaults.listLocation = function(data) { return data[defaultlistLocation]; - }; + }; } } @@ -325,9 +327,9 @@ var EasyAutocomplete = (function(scope){ if (options.ajaxSettings !== undefined && typeof options.ajaxSettings === "object") { defaults.ajaxSettings = options.ajaxSettings; } else { - defaults.ajaxSettings = {}; + defaults.ajaxSettings = {}; } - + } function isAssigned(name) { @@ -341,19 +343,19 @@ var EasyAutocomplete = (function(scope){ //Consol is object that should have method log that prints string //Normally invoke this function with console as consol function printPropertiesThatDoesntExist(consol, optionsToCheck) { - + checkPropertiesIfExist(defaults, optionsToCheck); function checkPropertiesIfExist(source, target) { for(var property in target) { if (source[property] === undefined) { - consol.log("Property '" + property + "' does not exist in EasyAutocomplete options API."); + consol.log("Property '" + property + "' does not exist in EasyAutocomplete options API."); } if (typeof source[property] === "object" && $.inArray(property, externalObjects) === -1) { checkPropertiesIfExist(source[property], target[property]); } - } + } } } }; @@ -361,4 +363,3 @@ var EasyAutocomplete = (function(scope){ return scope; })(EasyAutocomplete || {}); - diff --git a/src/core.js b/src/core.js index 4203dfa..2545ef7 100644 --- a/src/core.js +++ b/src/core.js @@ -4,9 +4,9 @@ */ var EasyAutocomplete = (function(scope) { - + scope.main = function Core($input, options) { - + var module = { name: "EasyAutocomplete", shortcut: "eac" @@ -19,14 +19,14 @@ var EasyAutocomplete = (function(scope) { listBuilderService = new scope.ListBuilderService(config, scope.proccess), checkParam = config.equals, - $field = $input, + $field = $input, $container = "", elementsList = [], selectedElement = -1, requestDelayTimeoutId; scope.consts = consts; - + //------------------------ GETTERS -------------------------- @@ -63,7 +63,7 @@ var EasyAutocomplete = (function(scope) { return this.getItemData(selectedElement); }; - //------------------------ PUBLIC METHODS STARTS -------------------------- + //------------------------ PUBLIC METHODS STARTS -------------------------- this.build = function() { prepareField(); @@ -73,7 +73,7 @@ var EasyAutocomplete = (function(scope) { init(); }; - //------------------------ PUBLIC METHODS ENDS -------------------------- + //------------------------ PUBLIC METHODS ENDS -------------------------- //Main method @@ -96,7 +96,7 @@ var EasyAutocomplete = (function(scope) { prepareField(); - bindEvents(); + bindEvents(); } @@ -109,14 +109,14 @@ var EasyAutocomplete = (function(scope) { //TODO Rebuild this function function prepareField() { - + if ($field.parent().hasClass(consts.getValue("WRAPPER_CSS_CLASS"))) { removeContainer(); removeWrapper(); - } - + } + createWrapper(); - createContainer(); + createContainer(); $container = $("#" + getContainerId()); @@ -131,7 +131,7 @@ var EasyAutocomplete = (function(scope) { var $wrapper = $("
        "), classes = consts.getValue("WRAPPER_CSS_CLASS"); - + if (config.get("theme") && config.get("theme") !== "") { classes += " eac-" + config.get("theme"); } @@ -143,7 +143,7 @@ var EasyAutocomplete = (function(scope) { if (template.getTemplateClass() !== "") { classes += " " + template.getTemplateClass(); } - + $wrapper .addClass(classes); @@ -154,16 +154,16 @@ var EasyAutocomplete = (function(scope) { if (config.get("adjustWidth") === true) { - adjustWrapperWidth(); + adjustWrapperWidth(); } - + } function adjustWrapperWidth() { var fieldWidth = $field.outerWidth(); - $field.parent().css("width", fieldWidth); + $field.parent().css("width", fieldWidth); } function removeWrapper() { @@ -207,7 +207,7 @@ var EasyAutocomplete = (function(scope) { } config.get("list").onShowListEvent(); - + }) /* List hide animation */ .on("hide.eac", function() { @@ -243,7 +243,7 @@ var EasyAutocomplete = (function(scope) { config.get("list").onSelectItemEvent(); }) .on("loadElements.eac", function(event, listBuilders, phrase) { - + var $item = "", $listContainer = $elements_container.find("ul"); @@ -270,7 +270,7 @@ var EasyAutocomplete = (function(scope) { for(var i = 0, listDataLength = listData.length; i < listDataLength && counter < listBuilders[builderIndex].maxListSize; i += 1) { $item = $("
      • "); - + (function() { var j = i, @@ -291,7 +291,7 @@ var EasyAutocomplete = (function(scope) { .mouseover(function() { selectedElement = itemCounter; - selectElement(itemCounter); + selectElement(itemCounter); config.get("list").onMouseOverEvent(); }) @@ -307,6 +307,10 @@ var EasyAutocomplete = (function(scope) { } } + if (config.get("noResults") && counter == 0) { + $listContainer.append("
      • " + config.get("noResults") + "
      • "); + } + $elements_container.append($listContainer); config.get("list").onLoadEvent(); @@ -324,11 +328,11 @@ var EasyAutocomplete = (function(scope) { function highlight(string, phrase) { if(config.get("highlightPhrase") && phrase !== "") { - return highlightPhrase(string, phrase); + return highlightPhrase(string, phrase); } else { return string; } - + } function escapeRegExp(str) { @@ -346,7 +350,7 @@ var EasyAutocomplete = (function(scope) { //Generate unique element id function getContainerId() { - + var elementId = $field.attr("id"); elementId = consts.getValue("CONTAINER_ID") + elementId; @@ -364,8 +368,8 @@ var EasyAutocomplete = (function(scope) { bindAllEvents(); - //------------------------ FUNCTIONS -------------------------- - + //------------------------ FUNCTIONS -------------------------- + function bindAllEvents() { if (checkParam("autocompleteOff", true)) { @@ -439,7 +443,7 @@ var EasyAutocomplete = (function(scope) { selectElement(selectedElement); - } + } break; case 40: @@ -455,7 +459,7 @@ var EasyAutocomplete = (function(scope) { $field.val(config.get("getValue")(elementsList[selectedElement])); selectElement(selectedElement); - + } break; @@ -483,13 +487,13 @@ var EasyAutocomplete = (function(scope) { } else { hideContainer(); } - + } break; } - + function loadData(inputPhrase) { @@ -506,13 +510,13 @@ var EasyAutocomplete = (function(scope) { var listBuilders = listBuilderService.init(data); listBuilders = listBuilderService.updateCategories(listBuilders, data); - + listBuilders = listBuilderService.processData(listBuilders, inputPhrase); loadElements(listBuilders, inputPhrase); if ($field.parent().find("li").length > 0) { - showContainer(); + showContainer(); } else { hideContainer(); } @@ -536,13 +540,13 @@ var EasyAutocomplete = (function(scope) { settings.data = config.get("preparePostData")(settings.data, inputPhrase); - $.ajax(settings) + $.ajax(settings) .done(function(data) { var listBuilders = listBuilderService.init(data); listBuilders = listBuilderService.updateCategories(listBuilders, data); - + listBuilders = listBuilderService.convertXml(listBuilders); @@ -551,12 +555,12 @@ var EasyAutocomplete = (function(scope) { listBuilders = listBuilderService.processData(listBuilders, inputPhrase); - loadElements(listBuilders, inputPhrase); - + loadElements(listBuilders, inputPhrase); + } - if (listBuilderService.checkIfDataExists(listBuilders) && $field.parent().find("li").length > 0) { - showContainer(); + if ((listBuilderService.checkIfDataExists(listBuilders) && $field.parent().find("li").length > 0) || config.get("noResults")) { + showContainer(); } else { hideContainer(); } @@ -572,7 +576,7 @@ var EasyAutocomplete = (function(scope) { }); } - + function createAjaxSettings() { @@ -616,7 +620,7 @@ var EasyAutocomplete = (function(scope) { evt = evt || window.event; var keyCode = evt.keyCode; if (keyCode === 38) { - suppressKeypress = true; + suppressKeypress = true; return false; } }) @@ -648,11 +652,11 @@ var EasyAutocomplete = (function(scope) { $field.focus(function() { if ($field.val() !== "" && elementsList.length > 0) { - + selectedElement = -1; - showContainer(); + showContainer(); } - + }); } @@ -660,8 +664,8 @@ var EasyAutocomplete = (function(scope) { $field.blur(function() { //TODO - setTimeout(function() { - + setTimeout(function() { + selectedElement = -1; hideContainer(); }, 250); @@ -674,7 +678,7 @@ var EasyAutocomplete = (function(scope) { } - + //--------------------------------------------------------------------- //------------------------ EVENTS ------------------------------------- @@ -691,7 +695,7 @@ var EasyAutocomplete = (function(scope) { } function selectElement(index) { - + $container.trigger("selectElement.eac", index); } @@ -729,13 +733,13 @@ var EasyAutocomplete = (function(scope) { var fieldId = ""; do { - fieldId = "eac-" + Math.floor(Math.random() * 10000); + fieldId = "eac-" + Math.floor(Math.random() * 10000); } while ($("#" + fieldId).length !== 0); - + elementId = scope.consts.getValue("CONTAINER_ID") + fieldId; $(input).attr("id", fieldId); - + }; scope.setHandle = function(handle, id) {