From 48c52b4449ab1e2a5f43c0011ff2418d39409048 Mon Sep 17 00:00:00 2001 From: tom bertrand Date: Sun, 30 Nov 2014 15:21:46 -0500 Subject: [PATCH] Version 1.7.5 - Added the possibility to process the data from ajax request. --- jquery.typeahead.js | 13 +++++++++---- jquery.typeahead.min.js | 4 ++-- typeahead.jquery.json | 2 +- 3 files changed, 12 insertions(+), 7 deletions(-) diff --git a/jquery.typeahead.js b/jquery.typeahead.js index 5071447..6e99a28 100644 --- a/jquery.typeahead.js +++ b/jquery.typeahead.js @@ -2,7 +2,7 @@ * jQuery Typeahead * * @author Tom Bertrand - * @version 1.7.3 (2014-11-24) + * @version 1.7.5 (2014-11-30) * * @copyright * Copyright (C) 2014 RunningCoder. @@ -159,7 +159,7 @@ options.debug && window.Debug.log({ 'node': node.selector, 'function': 'extendOptions()', - 'arguments': "{options.source}", + 'arguments': "{options.source: " + JSON.stringify(options[option]) + "}", 'message': 'ERROR - source.group.url or source.group.data is Required' }); } @@ -190,7 +190,7 @@ // {/debug} // {debug} - if (!options[option][group].url && !options[option][group].data) { + if (!options[option][group].url && !options[option][group].data && !(options[option][group] instanceof Array)) { options.debug && window.Debug.log({ 'node': node.selector, 'function': 'extendOptions()', @@ -961,7 +961,7 @@ if (!options.source[group].data && !options.source[group].url) { - if (typeof options.source[group] === "string") { + if (typeof options.source[group] === "string" || options.source[group] instanceof Array) { options.source[group] = { url: options.source[group] }; @@ -1063,10 +1063,15 @@ ajaxTimestamp: timestamp }, ajaxObj)).done( function(data) { + // Only process the data from the latest generate if (this.ajaxTimestamp !== timestamp) { return false; } + if (typeof this.process === "function") { + data = this.process(data); + } + _request.set(url, data); _request.processQueue(url); diff --git a/jquery.typeahead.min.js b/jquery.typeahead.min.js index 6f82e6c..48ced68 100644 --- a/jquery.typeahead.min.js +++ b/jquery.typeahead.min.js @@ -2,7 +2,7 @@ * jQuery Typeahead * * @author Tom Bertrand - * @version 1.7.3 (2014-11-24) + * @version 1.7.5 (2014-11-30) * * @copyright * Copyright (C) 2014 RunningCoder. @@ -13,4 +13,4 @@ * @license * Licensed under the MIT license. */ -(function(e,t,n,r){e.Typeahead={source:{}};if(typeof Object.preventExtensions!=="function"){Object.preventExtensions=function(e){return e}}var i={input:null,minLength:2,maxItem:8,dynamic:false,delay:300,order:null,offset:false,hint:false,accent:false,highlight:true,list:false,group:false,groupMaxItem:false,filter:false,backdrop:false,cache:false,ttl:36e5,compression:false,selector:{container:"typeahead-container",group:"typeahead-group",result:"typeahead-result",list:"typeahead-list",display:"typeahead-display",query:"typeahead-query",filter:"typeahead-filter",filterButton:"typeahead-filter-button",filterValue:"typeahead-filter-value",dropdown:"typeahead-dropdown",button:"typeahead-button",backdrop:"typeahead-backdrop",hint:"typeahead-hint"},display:"display",template:null,source:null,callback:{onInit:null,onResult:null,onMouseEnter:null,onMouseLeave:null,onClick:null,onSubmit:null},debug:false};var s={dynamic:[true,false],order:["asc","desc"],offset:[true,false],accent:[true,false],highlight:[true,false],cache:[true,false],compression:[true,false],debug:[true,false]};var o=".typeahead.input";var u={from:"ãàáäâẽèéëêìíïîõòóöôùúüûñç",to:"aaaaaeeeeeiiiiooooouuuunc"};var a=function(r,a){function S(){for(var t in a){if(!a.hasOwnProperty(t)){continue}if(t==="source"){for(var r in a[t]){if(!a[t].hasOwnProperty(r)){continue}if(!(a[t][r]instanceof Object)||r==="data"){r="group";a[t]={group:a[t]}}}}else if(s[t]&&n.inArray(a[t],s[t])===-1){delete a[t]}}if(a.dynamic){a.cache=false;a.compression=false}if(a.cache){a.cache=function(){var t=typeof e.localStorage!=="undefined";if(t){try{localStorage.setItem("typeahead","typeahead");localStorage.removeItem("typeahead")}catch(n){t=false}}return t}()}a=n.extend(true,Object.preventExtensions(n.extend(true,{},i)),a)}function x(){I(a.callback.onInit,[r]);v=r.parents("."+a.selector.container);var e=["focus"+o,"input"+o,"propertychange"+o,"keydown"+o,"dynamic"+o];n("html").on("click"+o,function(e){k()});v.on("click"+o,function(e){e.stopPropagation();if(a.filter){v.find("."+a.selector.dropdown.replace(" ",".")).hide()}});r.parents("form").on("submit",function(e){if(I(a.callback.onSubmit,[r,this,e])){return false}});r.on(e.join(" "),function(e){switch(e.type){case"keydown":if(e.keyCode&&~[9,13,27,38,39,40].indexOf(e.keyCode)){C(e)}break;case"focus":if(l===null){if(!a.dynamic){L()}}break;case"input":case"propertychange":if(!l){if(a.dynamic){f=n(this).val().trim();F(function(){if(f.length>=a.minLength&&f!==""){L()}},a.delay)}return};case"dynamic":default:f=n(this).val().trim();k();if(f.length>=a.minLength&&f!==""){T();N()}if(e.type==="dynamic"&&a.dynamic){l=false;w=0}break}})}function T(){if(f===""){return false}if(d&&!a.source[d]){d=false}var e,t=f,n=0,i=/\d/.test(a.groupMaxItem)&&a.groupMaxItem,s;if(a.accent){t=B(f)}for(var o in h){if(!h.hasOwnProperty(o)||d&&o!==d){continue}if(i){s=0}for(var u in h[o]){if(!h[o].hasOwnProperty(u)){continue}if((p.length>=a.maxItem||i&&s>=i)&&!a.callback.onResult){break}if(a.source[o]&&a.source[o].display){h[o][u].display=h[o][u][a.source[o].display]}else{h[o][u].display=h[o][u][a.display]}e=h[o][u].display.toString();if(!e){continue}if(a.accent){e=B(e)}if(e.toLowerCase().indexOf(t.toLowerCase())!==-1&&(!a.offset||e.toLowerCase().indexOf(t.toLowerCase())===0)){if(a.source[o].ignore&&~a.source[o].ignore.indexOf(e)){continue}n++;if(a.callback.onResult&&(p.length>=a.maxItem||i&&s>=i)){continue}h[o][u].group=o;p.push(h[o][u]);if(i){s++}}}}if(a.order){p.sort(H("display",a.order==="asc",function(e){return e.toString().toUpperCase()}))}if(a.group){var l=[];for(var o in h){for(var c in p){if(p[c].group===o){l.push(p[c])}}}p=l}I(a.callback.onResult,[r,f,p,n]);return true}function N(){if(f===""||p.length===0){return false}var e=n("
",{"class":a.selector.result,html:n("