From 22347b7cf63f8a74e6db2c6b894fb25f9cc0d3e8 Mon Sep 17 00:00:00 2001 From: Tom Bertrand Date: Tue, 17 Oct 2017 12:54:54 -0400 Subject: [PATCH] Version 2.10.4 Fix - #383 Missing `href` property on a clicked item --- bower.json | 2 +- dist/jquery.typeahead.min.js | 4 ++-- package.json | 2 +- src/jquery.typeahead.js | 4 ++-- typeahead.jquery.json | 2 +- 5 files changed, 7 insertions(+), 7 deletions(-) diff --git a/bower.json b/bower.json index 2aca129..ce27a27 100644 --- a/bower.json +++ b/bower.json @@ -1,6 +1,6 @@ { "name": "jquery-typeahead", - "version": "2.10.3", + "version": "2.10.4", "authors": [ "Tom Bertrand" ], diff --git a/dist/jquery.typeahead.min.js b/dist/jquery.typeahead.min.js index 8c7ac26..57d68f0 100644 --- a/dist/jquery.typeahead.min.js +++ b/dist/jquery.typeahead.min.js @@ -4,8 +4,8 @@ * Licensed under the MIT license * * @author Tom Bertrand - * @version 2.10.3 (2017-10-17) + * @version 2.10.4 (2017-10-17) * @link http://www.runningcoder.org/jquerytypeahead/ */ -!function(t){"function"==typeof define&&define.amd?define("jquery-typeahead",["jquery"],function(e){return t(e)}):"object"==typeof module&&module.exports?module.exports=function(e,i){return void 0===e&&(e="undefined"!=typeof window?require("jquery"):require("jquery")(i)),t(e)}():t(jQuery)}(function(t){"use strict";window.Typeahead={version:"2.10.3"};var e={input:null,minLength:2,maxLength:!1,maxItem:8,dynamic:!1,delay:300,order:null,offset:!1,hint:!1,accent:!1,highlight:!0,multiselect:null,group:!1,groupOrder:null,maxItemPerGroup:null,dropdownFilter:!1,dynamicFilter:null,backdrop:!1,backdropOnFocus:!1,cache:!1,ttl:36e5,compression:!1,searchOnFocus:!1,blurOnTab:!0,resultContainer:null,generateOnLoad:null,mustSelectItem:!1,href:null,display:["display"],template:null,templateValue:null,groupTemplate:null,correlativeTemplate:!1,emptyTemplate:!1,cancelButton:!0,loadingAnimation:!0,filter:!0,matcher:null,source:null,callback:{onInit:null,onReady:null,onShowLayout:null,onHideLayout:null,onSearch:null,onResult:null,onLayoutBuiltBefore:null,onLayoutBuiltAfter:null,onNavigateBefore:null,onNavigateAfter:null,onEnter:null,onLeave:null,onClickBefore:null,onClickAfter:null,onDropdownFilter:null,onSendRequest:null,onReceiveRequest:null,onPopulateSource:null,onCacheSave:null,onSubmit:null,onCancel:null},selector:{container:"typeahead__container",result:"typeahead__result",list:"typeahead__list",group:"typeahead__group",item:"typeahead__item",empty:"typeahead__empty",display:"typeahead__display",query:"typeahead__query",filter:"typeahead__filter",filterButton:"typeahead__filter-button",dropdown:"typeahead__dropdown",dropdownItem:"typeahead__dropdown-item",labelContainer:"typeahead__label-container",label:"typeahead__label",button:"typeahead__button",backdrop:"typeahead__backdrop",hint:"typeahead__hint",cancelButton:"typeahead__cancel-button"},debug:!1},i=".typeahead",s={from:"ãàáäâẽèéëêìíïîõòóöôùúüûñç",to:"aaaaaeeeeeiiiiooooouuuunc"},o=~window.navigator.appVersion.indexOf("MSIE 9."),n=~window.navigator.appVersion.indexOf("MSIE 10"),r=~window.navigator.userAgent.indexOf("Trident")?~window.navigator.userAgent.indexOf("rv:11"):!1,a=function(t,e){this.rawQuery=t.val()||"",this.query=t.val()||"",this.selector=t[0].selector,this.deferred=null,this.tmpSource={},this.source={},this.dynamicGroups=[],this.hasDynamicGroups=!1,this.generatedGroupCount=0,this.groupBy="group",this.groups=[],this.searchGroups=[],this.generateGroups=[],this.requestGroups=[],this.result=[],this.tmpResult={},this.groupTemplate="",this.resultHtml=null,this.resultCount=0,this.resultCountPerGroup={},this.options=e,this.node=t,this.namespace="."+this.helper.slugify.call(this,this.selector)+i,this.isContentEditable="undefined"!=typeof this.node.attr("contenteditable")&&"false"!==this.node.attr("contenteditable"),this.container=null,this.resultContainer=null,this.item=null,this.items=null,this.comparedItems=null,this.xhr={},this.hintIndex=null,this.filters={dropdown:{},dynamic:{}},this.dropdownFilter={"static":[],dynamic:[]},this.dropdownFilterAll=null,this.isDropdownEvent=!1,this.requests={},this.backdrop={},this.hint={},this.label={},this.hasDragged=!1,this.focusOnly=!1,this.__construct()};a.prototype={_validateCacheMethod:function(t){var e,i=["localStorage","sessionStorage"];if(t===!0)t="localStorage";else if("string"==typeof t&&!~i.indexOf(t))return!1;e="undefined"!=typeof window[t];try{window[t].setItem("typeahead","typeahead"),window[t].removeItem("typeahead")}catch(s){e=!1}return e&&t||!1},extendOptions:function(){if(this.options.cache=this._validateCacheMethod(this.options.cache),this.options.compression&&("object"==typeof LZString&&this.options.cache||(this.options.compression=!1)),(!this.options.maxLength||isNaN(this.options.maxLength))&&(this.options.maxLength=1/0),"undefined"!=typeof this.options.maxItem&&~[0,!1].indexOf(this.options.maxItem)&&(this.options.maxItem=1/0),this.options.maxItemPerGroup&&!/^\d+$/.test(this.options.maxItemPerGroup)&&(this.options.maxItemPerGroup=null),this.options.display&&!Array.isArray(this.options.display)&&(this.options.display=[this.options.display]),this.options.multiselect&&(this.items=[],this.comparedItems=[],"string"==typeof this.options.multiselect.matchOn&&(this.options.multiselect.matchOn=[this.options.multiselect.matchOn])),this.options.group&&(Array.isArray(this.options.group)||("string"==typeof this.options.group?this.options.group={key:this.options.group}:"boolean"==typeof this.options.group&&(this.options.group={key:"group"}),this.options.group.key=this.options.group.key||"group")),this.options.highlight&&!~["any",!0].indexOf(this.options.highlight)&&(this.options.highlight=!1),this.options.dropdownFilter&&this.options.dropdownFilter instanceof Object){Array.isArray(this.options.dropdownFilter)||(this.options.dropdownFilter=[this.options.dropdownFilter]);for(var i=0,o=this.options.dropdownFilter.length;o>i;++i)this.dropdownFilter[this.options.dropdownFilter[i].value?"static":"dynamic"].push(this.options.dropdownFilter[i])}this.options.dynamicFilter&&!Array.isArray(this.options.dynamicFilter)&&(this.options.dynamicFilter=[this.options.dynamicFilter]),this.options.accent&&("object"==typeof this.options.accent?this.options.accent.from&&this.options.accent.to&&this.options.accent.from.length!==this.options.accent.to.length:this.options.accent=s),this.options.groupTemplate&&(this.groupTemplate=this.options.groupTemplate),this.options.resultContainer&&("string"==typeof this.options.resultContainer&&(this.options.resultContainer=t(this.options.resultContainer)),this.options.resultContainer instanceof t&&this.options.resultContainer[0]&&(this.resultContainer=this.options.resultContainer)),this.options.maxItemPerGroup&&this.options.group&&this.options.group.key&&(this.groupBy=this.options.group.key),this.options.callback&&this.options.callback.onClick&&(this.options.callback.onClickBefore=this.options.callback.onClick,delete this.options.callback.onClick),this.options.callback&&this.options.callback.onNavigate&&(this.options.callback.onNavigateBefore=this.options.callback.onNavigate,delete this.options.callback.onNavigate),this.options=t.extend(!0,{},e,this.options)},unifySourceFormat:function(){this.dynamicGroups=[],Array.isArray(this.options.source)&&(this.options.source={group:{data:this.options.source}}),"string"==typeof this.options.source&&(this.options.source={group:{ajax:{url:this.options.source}}}),this.options.source.ajax&&(this.options.source={group:{ajax:this.options.source.ajax}}),(this.options.source.url||this.options.source.data)&&(this.options.source={group:this.options.source});var t,e,i;for(t in this.options.source)if(this.options.source.hasOwnProperty(t)){if(e=this.options.source[t],"string"==typeof e&&(e={ajax:{url:e}}),i=e.url||e.ajax,Array.isArray(i)?(e.ajax="string"==typeof i[0]?{url:i[0]}:i[0],e.ajax.path=e.ajax.path||i[1]||null,delete e.url):("object"==typeof e.url?e.ajax=e.url:"string"==typeof e.url&&(e.ajax={url:e.url}),delete e.url),!e.data&&!e.ajax)return!1;e.display&&!Array.isArray(e.display)&&(e.display=[e.display]),e.minLength="number"==typeof e.minLength?e.minLength:this.options.minLength,e.maxLength="number"==typeof e.maxLength?e.maxLength:this.options.maxLength,e.dynamic="boolean"==typeof e.dynamic||this.options.dynamic,e.minLength>e.maxLength&&(e.minLength=e.maxLength),this.options.source[t]=e,this.options.source[t].dynamic&&this.dynamicGroups.push(t),e.cache="undefined"!=typeof e.cache?this._validateCacheMethod(e.cache):this.options.cache,e.compression&&("object"==typeof LZString&&e.cache||(e.compression=!1))}return this.hasDynamicGroups=this.options.dynamic||!!this.dynamicGroups.length,!0},init:function(){this.helper.executeCallback.call(this,this.options.callback.onInit,[this.node]),this.container=this.node.closest("."+this.options.selector.container)},delegateEvents:function(){var e=this,i=["focus"+this.namespace,"input"+this.namespace,"propertychange"+this.namespace,"keydown"+this.namespace,"keyup"+this.namespace,"search"+this.namespace,"generate"+this.namespace];t("html").on("touchmove",function(){e.hasDragged=!0}).on("touchstart",function(){e.hasDragged=!1}),this.node.closest("form").on("submit",function(t){return e.options.mustSelectItem&&e.helper.isEmpty(e.item)?void t.preventDefault():(e.options.backdropOnFocus||e.hideLayout(),e.options.callback.onSubmit?e.helper.executeCallback.call(e,e.options.callback.onSubmit,[e.node,this,e.item||e.items,t]):void 0)}).on("reset",function(){setTimeout(function(){e.node.trigger("input"+e.namespace),e.hideLayout()})});var s=!1;if(this.node.attr("placeholder")&&(n||r)){var a=!0;this.node.on("focusin focusout",function(){a=!(this.value||!this.placeholder)}),this.node.on("input",function(t){a&&(t.stopImmediatePropagation(),a=!1)})}this.node.off(this.namespace).on(i.join(" "),function(i,n){switch(i.type){case"generate":e.generateSource(Object.keys(e.options.source));break;case"focus":if(e.focusOnly){e.focusOnly=!1;break}e.options.backdropOnFocus&&(e.buildBackdropLayout(),e.showLayout()),e.options.searchOnFocus&&!e.item&&(e.deferred=t.Deferred(),e.assignQuery(),e.generateSource());break;case"keydown":8===i.keyCode&&e.options.multiselect&&e.options.multiselect.cancelOnBackspace&&""===e.query&&e.items.length?e.cancelMultiselectItem(e.items.length-1,null,i):i.keyCode&&~[9,13,27,38,39,40].indexOf(i.keyCode)&&(s=!0,e.navigate(i));break;case"keyup":o&&e.node[0].value.replace(/^\s+/,"").toString().length=this.options.source[t].minLength&&this.query.length<=this.options.source[t].maxLength){if(this.searchGroups.push(t),!this.options.source[t].dynamic&&this.source[t])continue;this.generateGroups.push(t)}},generateSource:function(e){if(this.filterGenerateSource(),Array.isArray(e)&&e.length)this.generateGroups=e;else if(!this.generateGroups.length)return void this.node.trigger("search"+this.namespace);if(this.requestGroups=[],this.generatedGroupCount=0,this.options.loadingAnimation&&this.container.addClass("loading"),!this.helper.isEmpty(this.xhr)){for(var i in this.xhr)this.xhr.hasOwnProperty(i)&&this.xhr[i].abort();this.xhr={}}for(var s,o,n,r,a,l,h,c=this,i=0,u=this.generateGroups.length;u>i;++i){if(s=this.generateGroups[i],n=this.options.source[s],r=n.cache,a=n.compression,r&&(l=window[r].getItem("TYPEAHEAD_"+this.selector+":"+s))){a&&(l=LZString.decompressFromUTF16(l)),h=!1;try{l=JSON.parse(l+""),l.data&&l.ttl>(new Date).getTime()?(this.populateSource(l.data,s),h=!0):window[r].removeItem("TYPEAHEAD_"+this.selector+":"+s)}catch(p){}if(h)continue}!n.data||n.ajax?n.ajax&&(this.requests[s]||(this.requests[s]=this.generateRequestObject(s)),this.requestGroups.push(s)):"function"==typeof n.data?(o=n.data.call(this),Array.isArray(o)?c.populateSource(o,s):"function"==typeof o.promise&&!function(e){t.when(o).then(function(t){t&&Array.isArray(t)&&c.populateSource(t,e)})}(s)):this.populateSource(t.extend(!0,[],n.data),s)}return this.requestGroups.length&&this.handleRequests(),!!this.generateGroups.length},generateRequestObject:function(t){var e=this,i=this.options.source[t],s={request:{url:i.ajax.url||null,dataType:"json",beforeSend:function(s,o){e.xhr[t]=s;var n=e.requests[t].callback.beforeSend||i.ajax.beforeSend;"function"==typeof n&&n.apply(null,arguments)}},callback:{beforeSend:null,done:null,fail:null,then:null,always:null},extra:{path:i.ajax.path||null,group:t},validForGroup:[t]};if("function"!=typeof i.ajax&&(i.ajax instanceof Object&&(s=this.extendXhrObject(s,i.ajax)),Object.keys(this.options.source).length>1))for(var o in this.requests)this.requests.hasOwnProperty(o)&&(this.requests[o].isDuplicated||s.request.url&&s.request.url===this.requests[o].request.url&&(this.requests[o].validForGroup.push(t),s.isDuplicated=!0,delete s.validForGroup));return s},extendXhrObject:function(e,i){return"object"==typeof i.callback&&(e.callback=i.callback,delete i.callback),"function"==typeof i.beforeSend&&(e.callback.beforeSend=i.beforeSend,delete i.beforeSend),e.request=t.extend(!0,e.request,i),"jsonp"!==e.request.dataType.toLowerCase()||e.request.jsonpCallback||(e.request.jsonpCallback="callback_"+e.extra.group),e},handleRequests:function(){var e,i=this,s=this.requestGroups.length;if(this.helper.executeCallback.call(this,this.options.callback.onSendRequest,[this.node,this.query])!==!1)for(var o=0,n=this.requestGroups.length;n>o;++o)e=this.requestGroups[o],this.requests[e].isDuplicated||!function(e,o){if("function"==typeof i.options.source[e].ajax){var n=i.options.source[e].ajax.call(i,i.query);if(o=i.extendXhrObject(i.generateRequestObject(e),"object"==typeof n?n:{}),"object"!=typeof o.request||!o.request.url)return void i.populateSource([],e);i.requests[e]=o}var r,a=!1,l={};if(~o.request.url.indexOf("{{query}}")&&(a||(o=t.extend(!0,{},o),a=!0),o.request.url=o.request.url.replace("{{query}}",encodeURIComponent(i.query))),o.request.data)for(var h in o.request.data)if(o.request.data.hasOwnProperty(h)&&~String(o.request.data[h]).indexOf("{{query}}")){a||(o=t.extend(!0,{},o),a=!0),o.request.data[h]=o.request.data[h].replace("{{query}}",i.query);break}t.ajax(o.request).done(function(t,e,s){for(var n,a=0,h=o.validForGroup.length;h>a;a++)n=o.validForGroup[a],r=i.requests[n],r.callback.done instanceof Function&&(l[n]=r.callback.done.call(i,t,e,s))}).fail(function(t,e,s){for(var n=0,a=o.validForGroup.length;a>n;n++)r=i.requests[o.validForGroup[n]],r.callback.fail instanceof Function&&r.callback.fail.call(i,t,e,s)}).always(function(t,e,n){for(var a,h=0,c=o.validForGroup.length;c>h;h++){if(a=o.validForGroup[h],r=i.requests[a],r.callback.always instanceof Function&&r.callback.always.call(i,t,e,n),"object"!=typeof n)return;i.populateSource(null!==t&&"function"==typeof t.promise&&[]||l[a]||t,r.extra.group,r.extra.path||r.request.path),s-=1,0===s&&i.helper.executeCallback.call(i,i.options.callback.onReceiveRequest,[i.node,i.query])}}).then(function(t,e){for(var s=0,n=o.validForGroup.length;n>s;s++)r=i.requests[o.validForGroup[s]],r.callback.then instanceof Function&&r.callback.then.call(i,t,e)})}(e,this.requests[e])},populateSource:function(e,i,s){var o=this,n=this.options.source[i],r=n.ajax&&n.data;s&&"string"==typeof s&&(e=this.helper.namespace.call(this,s,e)),Array.isArray(e)||(e=[]),r&&("function"==typeof r&&(r=r()),Array.isArray(r)&&(e=e.concat(r)));for(var a,l=n.display?"compiled"===n.display[0]?n.display[1]:n.display[0]:"compiled"===this.options.display[0]?this.options.display[1]:this.options.display[0],h=0,c=e.length;c>h;h++)null!==e[h]&&"boolean"!=typeof e[h]&&("string"==typeof e[h]&&(a={},a[l]=e[h],e[h]=a),e[h].group=i);if(!this.hasDynamicGroups&&this.dropdownFilter.dynamic.length)for(var u,p,d={},h=0,c=e.length;c>h;h++)for(var f=0,m=this.dropdownFilter.dynamic.length;m>f;f++)u=this.dropdownFilter.dynamic[f].key,p=e[h][u],p&&(this.dropdownFilter.dynamic[f].value||(this.dropdownFilter.dynamic[f].value=[]),d[u]||(d[u]=[]),~d[u].indexOf(p.toLowerCase())||(d[u].push(p.toLowerCase()),this.dropdownFilter.dynamic[f].value.push(p)));if(this.options.correlativeTemplate){var g=n.template||this.options.template,y="";if("function"==typeof g&&(g=g.call(this,"",{})),g){if(Array.isArray(this.options.correlativeTemplate))for(var h=0,c=this.options.correlativeTemplate.length;c>h;h++)y+="{{"+this.options.correlativeTemplate[h]+"}} ";else y=g.replace(/<.+?>/g," ").replace(/\s{2,}/," ").trim();for(var h=0,c=e.length;c>h;h++)e[h].compiled=t("