diff --git a/dist/jquery.easy-autocomplete.js b/dist/jquery.easy-autocomplete.js index 88f2951..3066d26 100644 --- a/dist/jquery.easy-autocomplete.js +++ b/dist/jquery.easy-autocomplete.js @@ -8,7 +8,7 @@ */ /* - * 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() {} }, @@ -120,7 +120,7 @@ var EasyAutocomplete = (function(scope){ }] }; - + var externalObjects = ["ajaxSettings", "template"]; this.get = function(propertyName) { @@ -132,8 +132,8 @@ var EasyAutocomplete = (function(scope){ if (defaults[name] === value) { return true; } - } - + } + return false; }; @@ -163,7 +163,7 @@ var EasyAutocomplete = (function(scope){ mergeOptions(); if (defaults.loggerEnabled === true) { - printPropertiesThatDoesntExist(console, options); + printPropertiesThatDoesntExist(console, options); } addAjaxSettings(); @@ -172,19 +172,19 @@ var EasyAutocomplete = (function(scope){ function prepareDefaults() { if (options.dataType === "xml") { - + if (!options.getValue) { options.getValue = function(element) { - return $(element).text(); + return jQuery(element).text(); }; } - + if (!options.list) { options.list = {}; - } + } if (!options.list.sort) { options.list.sort = {}; @@ -221,7 +221,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 +249,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 +257,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 +265,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() { @@ -289,12 +289,12 @@ var EasyAutocomplete = (function(scope){ if (defaults.dataType.toUpperCase() === "XML") { defaults.listLocation = function(data) { - return $(data).find(defaultlistLocation); + return jQuery(data).find(defaultlistLocation); }; } else { defaults.listLocation = function(data) { return data[defaultlistLocation]; - }; + }; } } @@ -316,9 +316,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 +329,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) { + if (typeof source[property] === "object" && jQuery.inArray(property, externalObjects) === -1) { checkPropertiesIfExist(source[property], target[property]); } - } + } } } }; @@ -396,9 +396,9 @@ var EasyAutocomplete = (function(scope){ })(EasyAutocomplete || {}); /* - * EasyAutocomplete - ListBuilderService + * EasyAutocomplete - ListBuilderService * - * @author Łukasz Pawełczak + * @author Łukasz Pawełczak * */ var EasyAutocomplete = (function(scope) { @@ -414,14 +414,14 @@ var EasyAutocomplete = (function(scope) { builder.getValue = configuration.get("getValue"); builder.maxListSize = configuration.get("list").maxNumberOfElements; - + listBuilder.push(builder); return listBuilder; }; this.updateCategories = function(listBuilder, data) { - + if (configuration.get("categoriesAssigned")) { listBuilder = []; @@ -433,7 +433,7 @@ var EasyAutocomplete = (function(scope) { listBuilder.push(builder); } - } + } return listBuilder; }; @@ -466,7 +466,7 @@ var EasyAutocomplete = (function(scope) { if (listBuilders[i].data.length > 0) { return true; } - } + } } return false; @@ -484,7 +484,7 @@ var EasyAutocomplete = (function(scope) { builder = convertDataToListBuilder(); } - + if (category.header !== undefined) { builder.header = category.header; @@ -511,9 +511,9 @@ var EasyAutocomplete = (function(scope) { } } else { - builder.getValue = configuration.get("getValue"); + builder.getValue = configuration.get("getValue"); } - + return builder; @@ -537,7 +537,7 @@ var EasyAutocomplete = (function(scope) { if (listLocation !== undefined) { if (typeof listLocation === "string") { - builder.data = $(data).find(listLocation); + builder.data = jQuery(data).find(listLocation); } else if (typeof listLocation === "function") { builder.data = listLocation(data); @@ -578,7 +578,7 @@ var EasyAutocomplete = (function(scope) { } - $(builder.data).find(builder.xmlElementName).each(function() { + jQuery(builder.data).find(builder.xmlElementName).each(function() { simpleList.push(this); }); @@ -882,9 +882,9 @@ var EasyAutocomplete = (function(scope){ */ var EasyAutocomplete = (function(scope) { - + scope.main = function Core($input, options) { - + var module = { name: "EasyAutocomplete", shortcut: "eac" @@ -897,7 +897,7 @@ var EasyAutocomplete = (function(scope) { listBuilderService = new scope.ListBuilderService(config, scope.proccess), checkParam = config.equals, - $field = $input, + $field = $input, $container = "", elementsList = [], selectedElement = -1, @@ -964,31 +964,31 @@ 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()); + $container = jQuery("#" + getContainerId()); if (config.get("placeholder")) { $field.attr("placeholder", config.get("placeholder")); } function createWrapper() { - var $wrapper = $("
"), + var $wrapper = jQuery("
"), classes = consts.getValue("WRAPPER_CSS_CLASS"); - + if (config.get("theme") && config.get("theme") !== "") { classes += " eac-" + config.get("theme"); } @@ -1000,7 +1000,7 @@ var EasyAutocomplete = (function(scope) { if (template.getTemplateClass() !== "") { classes += " " + template.getTemplateClass(); } - + $wrapper .addClass(classes); @@ -1008,16 +1008,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() { @@ -1025,11 +1025,11 @@ var EasyAutocomplete = (function(scope) { } function createContainer() { - var $elements_container = $("
").addClass(consts.getValue("CONTAINER_CLASS")); + var $elements_container = jQuery("
").addClass(consts.getValue("CONTAINER_CLASS")); $elements_container .attr("id", getContainerId()) - .prepend($("
    ")); + .prepend(jQuery("
      ")); (function() { @@ -1060,7 +1060,7 @@ var EasyAutocomplete = (function(scope) { } config.get("list").onShowListEvent(); - + }) /* List hide animation */ .on("hide.eac", function() { @@ -1096,7 +1096,7 @@ var EasyAutocomplete = (function(scope) { config.get("list").onSelectItemEvent(); }) .on("loadElements.eac", function(event, listBuilders, phrase) { - + var $item = "", $listContainer = $elements_container.find("ul"); @@ -1120,8 +1120,8 @@ var EasyAutocomplete = (function(scope) { } for(var i = 0, listDataLength = listData.length; i < listDataLength && counter < listBuilders[builderIndex].maxListSize; i += 1) { - $item = $("
    • "); - + $item = jQuery("
    • "); + (function() { var j = i, @@ -1142,7 +1142,7 @@ var EasyAutocomplete = (function(scope) { .mouseover(function() { selectedElement = itemCounter; - selectElement(itemCounter); + selectElement(itemCounter); config.get("list").onMouseOverEvent(); }) @@ -1175,11 +1175,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 +1195,7 @@ var EasyAutocomplete = (function(scope) { } function getContainerId() { - + var elementId = $field.attr("id"); elementId = consts.getValue("CONTAINER_ID") + elementId; @@ -1205,7 +1205,7 @@ var EasyAutocomplete = (function(scope) { function bindEvents() { bindAllEvents(); - + function bindAllEvents() { if (checkParam("autocompleteOff", true)) { @@ -1271,7 +1271,7 @@ var EasyAutocomplete = (function(scope) { selectElement(selectedElement); - } + } break; case 40: @@ -1285,7 +1285,7 @@ var EasyAutocomplete = (function(scope) { $field.val(config.get("getValue")(elementsList[selectedElement])); selectElement(selectedElement); - + } break; @@ -1311,13 +1311,13 @@ var EasyAutocomplete = (function(scope) { } else { hideContainer(); } - + } break; } - + function loadData(inputPhrase) { @@ -1334,13 +1334,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 +1364,24 @@ var EasyAutocomplete = (function(scope) { settings.data = config.get("preparePostData")(settings.data, inputPhrase); - $.ajax(settings) + jQuery.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(); + showContainer(); } else { hideContainer(); } @@ -1397,7 +1397,7 @@ var EasyAutocomplete = (function(scope) { }); } - + function createAjaxSettings() { @@ -1441,7 +1441,7 @@ var EasyAutocomplete = (function(scope) { evt = evt || window.event; var keyCode = evt.keyCode; if (keyCode === 38) { - suppressKeypress = true; + suppressKeypress = true; return false; } }) @@ -1471,18 +1471,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 +1504,7 @@ var EasyAutocomplete = (function(scope) { } function selectElement(index) { - + $container.trigger("selectElement.eac", index); } @@ -1526,7 +1526,7 @@ var EasyAutocomplete = (function(scope) { scope.inputHasId = function(input) { - if($(input).attr("id") !== undefined && $(input).attr("id").length > 0) { + if(jQuery(input).attr("id") !== undefined && jQuery(input).attr("id").length > 0) { return true; } else { return false; @@ -1539,13 +1539,13 @@ var EasyAutocomplete = (function(scope) { var fieldId = ""; do { - fieldId = "eac-" + Math.floor(Math.random() * 10000); - } while ($("#" + fieldId).length !== 0); - + fieldId = "eac-" + Math.floor(Math.random() * 10000); + } while (jQuery("#" + fieldId).length !== 0); + elementId = scope.consts.getValue("CONTAINER_ID") + fieldId; - $(input).attr("id", fieldId); - + jQuery(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..cf02cd8 100644 --- a/dist/jquery.easy-autocomplete.min.js +++ b/dist/jquery.easy-autocomplete.min.js @@ -7,4 +7,4 @@ * 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 jQuery(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,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=jQuery(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")),jQuery(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=jQuery("
        "),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=jQuery("
        ").addClass(n.getValue("CONTAINER_CLASS"));a.attr("id",f()).prepend(jQuery("
          ")),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}}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=jQuery("#"+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),jQuery.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();!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!==jQuery("#"+c).length);elementId=a.consts.getValue("CONTAINER_ID")+c,jQuery(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/src/configuration.js b/src/configuration.js index aa734d2..59b8de0 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() {} }, @@ -114,7 +114,7 @@ var EasyAutocomplete = (function(scope){ }] }; - + var externalObjects = ["ajaxSettings", "template"]; this.get = function(propertyName) { @@ -126,8 +126,8 @@ var EasyAutocomplete = (function(scope){ if (defaults[name] === value) { return true; } - } - + } + return false; }; @@ -159,7 +159,7 @@ var EasyAutocomplete = (function(scope){ mergeOptions(); if (defaults.loggerEnabled === true) { - printPropertiesThatDoesntExist(console, options); + printPropertiesThatDoesntExist(console, options); } addAjaxSettings(); @@ -174,19 +174,19 @@ var EasyAutocomplete = (function(scope){ function prepareDefaults() { if (options.dataType === "xml") { - + if (!options.getValue) { options.getValue = function(element) { - return $(element).text(); + return jQuery(element).text(); }; } - + if (!options.list) { options.list = {}; - } + } if (!options.list.sort) { options.list.sort = {}; @@ -196,7 +196,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 +227,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 +258,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 +266,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 +274,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() { @@ -298,12 +298,12 @@ var EasyAutocomplete = (function(scope){ if (defaults.dataType.toUpperCase() === "XML") { defaults.listLocation = function(data) { - return $(data).find(defaultlistLocation); + return jQuery(data).find(defaultlistLocation); }; } else { defaults.listLocation = function(data) { return data[defaultlistLocation]; - }; + }; } } @@ -325,9 +325,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 +341,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) { + if (typeof source[property] === "object" && jQuery.inArray(property, externalObjects) === -1) { checkPropertiesIfExist(source[property], target[property]); } - } + } } } }; @@ -361,4 +361,3 @@ var EasyAutocomplete = (function(scope){ return scope; })(EasyAutocomplete || {}); - diff --git a/src/core.js b/src/core.js index 4203dfa..5edbde9 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,16 +109,16 @@ 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()); + $container = jQuery("#" + getContainerId()); //Set placeholder for element @@ -128,10 +128,10 @@ var EasyAutocomplete = (function(scope) { function createWrapper() { - var $wrapper = $("
          "), + var $wrapper = jQuery("
          "), 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() { @@ -171,11 +171,11 @@ var EasyAutocomplete = (function(scope) { } function createContainer() { - var $elements_container = $("
          ").addClass(consts.getValue("CONTAINER_CLASS")); + var $elements_container = jQuery("
          ").addClass(consts.getValue("CONTAINER_CLASS")); $elements_container .attr("id", getContainerId()) - .prepend($("
            ")); + .prepend(jQuery("
              ")); (function() { @@ -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"); @@ -269,8 +269,8 @@ var EasyAutocomplete = (function(scope) { } for(var i = 0, listDataLength = listData.length; i < listDataLength && counter < listBuilders[builderIndex].maxListSize; i += 1) { - $item = $("
            • "); - + $item = jQuery("
            • "); + (function() { var j = i, @@ -291,7 +291,7 @@ var EasyAutocomplete = (function(scope) { .mouseover(function() { selectedElement = itemCounter; - selectElement(itemCounter); + selectElement(itemCounter); config.get("list").onMouseOverEvent(); }) @@ -324,11 +324,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 +346,7 @@ var EasyAutocomplete = (function(scope) { //Generate unique element id function getContainerId() { - + var elementId = $field.attr("id"); elementId = consts.getValue("CONTAINER_ID") + elementId; @@ -364,8 +364,8 @@ var EasyAutocomplete = (function(scope) { bindAllEvents(); - //------------------------ FUNCTIONS -------------------------- - + //------------------------ FUNCTIONS -------------------------- + function bindAllEvents() { if (checkParam("autocompleteOff", true)) { @@ -439,7 +439,7 @@ var EasyAutocomplete = (function(scope) { selectElement(selectedElement); - } + } break; case 40: @@ -455,7 +455,7 @@ var EasyAutocomplete = (function(scope) { $field.val(config.get("getValue")(elementsList[selectedElement])); selectElement(selectedElement); - + } break; @@ -483,13 +483,13 @@ var EasyAutocomplete = (function(scope) { } else { hideContainer(); } - + } break; } - + function loadData(inputPhrase) { @@ -506,13 +506,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 +536,13 @@ var EasyAutocomplete = (function(scope) { settings.data = config.get("preparePostData")(settings.data, inputPhrase); - $.ajax(settings) + jQuery.ajax(settings) .done(function(data) { var listBuilders = listBuilderService.init(data); listBuilders = listBuilderService.updateCategories(listBuilders, data); - + listBuilders = listBuilderService.convertXml(listBuilders); @@ -551,12 +551,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(); + showContainer(); } else { hideContainer(); } @@ -572,7 +572,7 @@ var EasyAutocomplete = (function(scope) { }); } - + function createAjaxSettings() { @@ -616,7 +616,7 @@ var EasyAutocomplete = (function(scope) { evt = evt || window.event; var keyCode = evt.keyCode; if (keyCode === 38) { - suppressKeypress = true; + suppressKeypress = true; return false; } }) @@ -648,11 +648,11 @@ var EasyAutocomplete = (function(scope) { $field.focus(function() { if ($field.val() !== "" && elementsList.length > 0) { - + selectedElement = -1; - showContainer(); + showContainer(); } - + }); } @@ -660,8 +660,8 @@ var EasyAutocomplete = (function(scope) { $field.blur(function() { //TODO - setTimeout(function() { - + setTimeout(function() { + selectedElement = -1; hideContainer(); }, 250); @@ -674,7 +674,7 @@ var EasyAutocomplete = (function(scope) { } - + //--------------------------------------------------------------------- //------------------------ EVENTS ------------------------------------- @@ -691,7 +691,7 @@ var EasyAutocomplete = (function(scope) { } function selectElement(index) { - + $container.trigger("selectElement.eac", index); } @@ -716,7 +716,7 @@ var EasyAutocomplete = (function(scope) { scope.inputHasId = function(input) { - if($(input).attr("id") !== undefined && $(input).attr("id").length > 0) { + if(jQuery(input).attr("id") !== undefined && jQuery(input).attr("id").length > 0) { return true; } else { return false; @@ -729,13 +729,13 @@ var EasyAutocomplete = (function(scope) { var fieldId = ""; do { - fieldId = "eac-" + Math.floor(Math.random() * 10000); - } while ($("#" + fieldId).length !== 0); - + fieldId = "eac-" + Math.floor(Math.random() * 10000); + } while (jQuery("#" + fieldId).length !== 0); + elementId = scope.consts.getValue("CONTAINER_ID") + fieldId; - $(input).attr("id", fieldId); - + jQuery(input).attr("id", fieldId); + }; scope.setHandle = function(handle, id) { diff --git a/src/listBuilder.js b/src/listBuilder.js index d9c9fd0..4600042 100644 --- a/src/listBuilder.js +++ b/src/listBuilder.js @@ -1,7 +1,7 @@ /* - * EasyAutocomplete - ListBuilderService + * EasyAutocomplete - ListBuilderService * - * @author Łukasz Pawełczak + * @author Łukasz Pawełczak * */ var EasyAutocomplete = (function(scope) { @@ -17,14 +17,14 @@ var EasyAutocomplete = (function(scope) { builder.getValue = configuration.get("getValue"); builder.maxListSize = configuration.get("list").maxNumberOfElements; - + listBuilder.push(builder); return listBuilder; }; this.updateCategories = function(listBuilder, data) { - + if (configuration.get("categoriesAssigned")) { listBuilder = []; @@ -36,7 +36,7 @@ var EasyAutocomplete = (function(scope) { listBuilder.push(builder); } - } + } return listBuilder; }; @@ -69,7 +69,7 @@ var EasyAutocomplete = (function(scope) { if (listBuilders[i].data.length > 0) { return true; } - } + } } return false; @@ -87,7 +87,7 @@ var EasyAutocomplete = (function(scope) { builder = convertDataToListBuilder(); } - + if (category.header !== undefined) { builder.header = category.header; @@ -114,9 +114,9 @@ var EasyAutocomplete = (function(scope) { } } else { - builder.getValue = configuration.get("getValue"); + builder.getValue = configuration.get("getValue"); } - + return builder; @@ -140,7 +140,7 @@ var EasyAutocomplete = (function(scope) { if (listLocation !== undefined) { if (typeof listLocation === "string") { - builder.data = $(data).find(listLocation); + builder.data = jQuery(data).find(listLocation); } else if (typeof listLocation === "function") { builder.data = listLocation(data); @@ -181,7 +181,7 @@ var EasyAutocomplete = (function(scope) { } - $(builder.data).find(builder.xmlElementName).each(function() { + jQuery(builder.data).find(builder.xmlElementName).each(function() { simpleList.push(this); }); @@ -193,4 +193,3 @@ var EasyAutocomplete = (function(scope) { return scope; })(EasyAutocomplete || {}); -