Changeset 27911
- Timestamp:
- 04/02/2014 07:04:56 PM (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/js/jquery/suggest.min.js
r24372 r27911 1 (function(a){a.suggest=function(n,f){var c,e,m,d,p,o;c=a(n).attr("autocomplete","off");e=a("<ul/>");m=false;d=0;p=[];o=0;e.addClass(f.resultsClass).appendTo("body");i();a(window).load(i).resize(i);c.blur(function(){setTimeout(function(){e.hide()},200)});c.keydown(l);function i(){var u=c.offset();e.css({top:(u.top+n.offsetHeight)+"px",left:u.left+"px"})}function l(u){if((/27$|38$|40$/.test(u.keyCode)&&e.is(":visible"))||(/^13$|^9$/.test(u.keyCode)&&s())){if(u.preventDefault){u.preventDefault()}if(u.stopPropagation){u.stopPropagation()}u.cancelBubble=true;u.returnValue=false;switch(u.keyCode){case 38:j();break;case 40:r();break;case 9:case 13:q();break;case 27:e.hide();break}}else{if(c.val().length!=d){if(m){clearTimeout(m)}m=setTimeout(k,f.delay);d=c.val().length}}}function k(){var w=a.trim(c.val()),v,u;if(f.multiple){v=w.lastIndexOf(f.multipleSep);if(v!=-1){w=a.trim(w.substr(v+f.multipleSep.length))}}if(w.length>=f.minchars){cached=t(w);if(cached){h(cached.items)}else{a.get(f.source,{q:w},function(x){e.hide();u=b(x,w);h(u);g(w,u,x.length)})}}else{e.hide()}}function t(v){var u;for(u=0;u<p.length;u++){if(p[u]["q"]==v){p.unshift(p.splice(u,1)[0]);return p[0]}}return false}function g(x,u,v){var w;while(p.length&&(o+v>f.maxCacheSize)){w=p.pop();o-=w.size}p.push({q:x,size:v,items:u});o+=v}function h(u){var w="",v;if(!u){return}if(!u.length){e.hide();return}i();for(v=0;v<u.length;v++){w+="<li>"+u[v]+"</li>"}e.html(w).show();e.children("li").mouseover(function(){e.children("li").removeClass(f.selectClass);a(this).addClass(f.selectClass)}).click(function(x){x.preventDefault();x.stopPropagation();q()})}function b(u,y){var v=[],z=u.split(f.delimiter),x,w;for(x=0;x<z.length;x++){w=a.trim(z[x]);if(w){w=w.replace(new RegExp(y,"ig"),function(A){return'<span class="'+f.matchClass+'">'+A+"</span>"});v[v.length]=w}}return v}function s(){var u;if(!e.is(":visible")){return false}u=e.children("li."+f.selectClass);if(!u.length){u=false}return u}function q(){$currentResult=s();if($currentResult){if(f.multiple){if(c.val().indexOf(f.multipleSep)!=-1){$currentVal=c.val().substr(0,(c.val().lastIndexOf(f.multipleSep)+f.multipleSep.length))}else{$currentVal=""}c.val($currentVal+$currentResult.text()+f.multipleSep);c.focus()}else{c.val($currentResult.text())}e.hide();if(f.onSelect){f.onSelect.apply(c[0])}}}function r(){$currentResult=s();if($currentResult){$currentResult.removeClass(f.selectClass).next().addClass(f.selectClass)}else{e.children("li:first-child").addClass(f.selectClass)}}function j(){var u=s();if(u){u.removeClass(f.selectClass).prev().addClass(f.selectClass)}else{e.children("li:last-child").addClass(f.selectClass)}}};a.fn.suggest=function(c,b){if(!c){return}b=b||{};b.multiple=b.multiple||false;b.multipleSep=b.multipleSep||", ";b.source=c;b.delay=b.delay||100;b.resultsClass=b.resultsClass||"ac_results";b.selectClass=b.selectClass||"ac_over";b.matchClass=b.matchClass||"ac_match";b.minchars=b.minchars||2;b.delimiter=b.delimiter||"\n";b.onSelect=b.onSelect||false;b.maxCacheSize=b.maxCacheSize||65536;this.each(function(){new a.suggest(this,b)});return this}})(jQuery);1 !function(a){a.suggest=function(b,c){function d(){var a=o.offset();p.css({top:a.top+b.offsetHeight+"px",left:a.left+"px"})}function e(a){if(/27$|38$|40$/.test(a.keyCode)&&p.is(":visible")||/^13$|^9$/.test(a.keyCode)&&k())switch(a.preventDefault&&a.preventDefault(),a.stopPropagation&&a.stopPropagation(),a.cancelBubble=!0,a.returnValue=!1,a.keyCode){case 38:n();break;case 40:m();break;case 9:case 13:l();break;case 27:p.hide()}else o.val().length!=r&&(q&&clearTimeout(q),q=setTimeout(f,c.delay),r=o.val().length)}function f(){var b,d,e=a.trim(o.val());c.multiple&&(b=e.lastIndexOf(c.multipleSep),-1!=b&&(e=a.trim(e.substr(b+c.multipleSep.length)))),e.length>=c.minchars?(cached=g(e),cached?i(cached.items):a.get(c.source,{q:e},function(a){p.hide(),d=j(a,e),i(d),h(e,d,a.length)})):p.hide()}function g(a){var b;for(b=0;b<s.length;b++)if(s[b].q==a)return s.unshift(s.splice(b,1)[0]),s[0];return!1}function h(a,b,d){for(var e;s.length&&t+d>c.maxCacheSize;)e=s.pop(),t-=e.size;s.push({q:a,size:d,items:b}),t+=d}function i(b){var e,f="";if(b){if(!b.length)return void p.hide();for(d(),e=0;e<b.length;e++)f+="<li>"+b[e]+"</li>";p.html(f).show(),p.children("li").mouseover(function(){p.children("li").removeClass(c.selectClass),a(this).addClass(c.selectClass)}).click(function(a){a.preventDefault(),a.stopPropagation(),l()})}}function j(b,d){var e,f,g=[],h=b.split(c.delimiter);for(e=0;e<h.length;e++)f=a.trim(h[e]),f&&(f=f.replace(new RegExp(d,"ig"),function(a){return'<span class="'+c.matchClass+'">'+a+"</span>"}),g[g.length]=f);return g}function k(){var a;return p.is(":visible")?(a=p.children("li."+c.selectClass),a.length||(a=!1),a):!1}function l(){$currentResult=k(),$currentResult&&(c.multiple?($currentVal=-1!=o.val().indexOf(c.multipleSep)?o.val().substr(0,o.val().lastIndexOf(c.multipleSep)+c.multipleSep.length):"",o.val($currentVal+$currentResult.text()+c.multipleSep),o.focus()):o.val($currentResult.text()),p.hide(),o.trigger("change"),c.onSelect&&c.onSelect.apply(o[0]))}function m(){$currentResult=k(),$currentResult?$currentResult.removeClass(c.selectClass).next().addClass(c.selectClass):p.children("li:first-child").addClass(c.selectClass)}function n(){var a=k();a?a.removeClass(c.selectClass).prev().addClass(c.selectClass):p.children("li:last-child").addClass(c.selectClass)}var o,p,q,r,s,t;o=a(b).attr("autocomplete","off"),p=a("<ul/>"),q=!1,r=0,s=[],t=0,p.addClass(c.resultsClass).appendTo("body"),d(),a(window).load(d).resize(d),o.blur(function(){setTimeout(function(){p.hide()},200)}),o.keydown(e)},a.fn.suggest=function(b,c){return b?(c=c||{},c.multiple=c.multiple||!1,c.multipleSep=c.multipleSep||", ",c.source=b,c.delay=c.delay||100,c.resultsClass=c.resultsClass||"ac_results",c.selectClass=c.selectClass||"ac_over",c.matchClass=c.matchClass||"ac_match",c.minchars=c.minchars||2,c.delimiter=c.delimiter||"\n",c.onSelect=c.onSelect||!1,c.maxCacheSize=c.maxCacheSize||65536,this.each(function(){new a.suggest(this,c)}),this):void 0}}(jQuery);
Note: See TracChangeset
for help on using the changeset viewer.