-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpsythemes-live-search.min.js
1 lines (1 loc) · 9.04 KB
/
psythemes-live-search.min.js
1
!function(t,e){"object"==typeof module&&module.exports?module.exports=e():"function"==typeof define&&define.amd?define(e):t.Spinner=e()}(this,function(){"use strict";var t,e,i=["webkit","Moz","ms","O"],s={};function n(t,e){var i,s=document.createElement(t||"div");for(i in e)s[i]=e[i];return s}function r(t){for(var e=1,i=arguments.length;e<i;e++)t.appendChild(arguments[e]);return t}function o(t,e){var s,n,r=t.style;if(void 0!==r[e=e.charAt(0).toUpperCase()+e.slice(1)])return e;for(n=0;n<i.length;n++)if(void 0!==r[s=i[n]+e])return s}function a(t,e){for(var i in e)t.style[o(t,i)||i]=e[i];return t}function l(t){for(var e=1;e<arguments.length;e++){var i=arguments[e];for(var s in i)void 0===t[s]&&(t[s]=i[s])}return t}function h(t,e){return"string"==typeof t?t:t[e%t.length]}var c,p={lines:12,length:7,width:5,radius:10,scale:1,corners:1,color:"#000",opacity:.25,rotate:0,direction:1,speed:1,trail:100,fps:20,zIndex:2e9,className:"spinner",top:"50%",left:"50%",shadow:!1,hwaccel:!1,position:"absolute"};function u(t){this.opts=l(t||{},u.defaults,p)}if(u.defaults={},l(u.prototype,{spin:function(e){this.stop();var i=this,s=i.opts,r=i.el=n(null,{className:s.className});if(a(r,{position:s.position,width:0,zIndex:s.zIndex,left:s.left,top:s.top}),e&&e.insertBefore(r,e.firstChild||null),r.setAttribute("role","progressbar"),i.lines(r,i.opts),!t){var o,l=0,h=(s.lines-1)*(1-s.direction)/2,c=s.fps,p=c/s.speed,u=(1-s.opacity)/(p*s.trail/100),d=p/s.lines;!function t(){l++;for(var e=0;e<s.lines;e++)o=Math.max(1-(l+(s.lines-e)*d)%p*u,s.opacity),i.opacity(r,e*s.direction+h,o,s);i.timeout=i.el&&setTimeout(t,~~(1e3/c))}()}return i},stop:function(){var t=this.el;return t&&(clearTimeout(this.timeout),t.parentNode&&t.parentNode.removeChild(t),this.el=void 0),this},lines:function(i,o){var l,c,p,u,d,f,_,g,m,v,w=0,y=(o.lines-1)*(1-o.direction)/2;function x(t,e){return a(n(),{position:"absolute",width:o.scale*(o.length+o.width)+"px",height:o.scale*o.width+"px",background:t,boxShadow:e,transformOrigin:"left",transform:"rotate("+~~(360/o.lines*w+o.rotate)+"deg) translate("+o.scale*o.radius+"px,0)",borderRadius:(o.corners*o.scale*o.width>>1)+"px"})}for(;w<o.lines;w++)l=a(n(),{position:"absolute",top:1+~(o.scale*o.width/2)+"px",transform:o.hwaccel?"translate3d(0,0,0)":"",opacity:o.opacity,animation:t&&(c=o.opacity,p=o.trail,u=y+w*o.direction,d=o.lines,void 0,void 0,void 0,void 0,void 0,f=["opacity",p,~~(100*c),u,d].join("-"),_=.01+u/d*100,g=Math.max(1-(1-c)/p*(100-_),c),m=t.substring(0,t.indexOf("Animation")).toLowerCase(),v=m&&"-"+m+"-"||"",s[f]||(e.insertRule("@"+v+"keyframes "+f+"{0%{opacity:"+g+"}"+_+"%{opacity:"+c+"}"+(_+.01)+"%{opacity:1}"+(_+p)%100+"%{opacity:"+c+"}100%{opacity:"+g+"}}",e.cssRules.length),s[f]=1),f+" "+1/o.speed+"s linear infinite")}),o.shadow&&r(l,a(x("#000","0 0 4px #000"),{top:"2px"})),r(i,r(l,x(h(o.color,w),"0 0 1px rgba(0,0,0,.1)")));return i},opacity:function(t,e,i){e<t.childNodes.length&&(t.childNodes[e].style.opacity=i)}}),"undefined"!=typeof document){c=n("style",{type:"text/css"}),r(document.getElementsByTagName("head")[0],c),e=c.sheet||c.styleSheet;var d=a(n("group"),{behavior:"url(#default#VML)"});!o(d,"transform")&&d.adj?function(){function t(t,e){return n("<"+t+' xmlns="urn:schemas-microsoft.com:vml" class="spin-vml">',e)}e.addRule(".spin-vml","behavior:url(#default#VML)"),u.prototype.lines=function(e,i){var s=i.scale*(i.length+i.width),n=2*i.scale*s;function o(){return a(t("group",{coordsize:n+" "+n,coordorigin:-s+" "+-s}),{width:n,height:n})}var l,c=-(i.width+i.length)*i.scale*2+"px",p=a(o(),{position:"absolute",top:c,left:c});function u(e,n,l){r(p,r(a(o(),{rotation:360/i.lines*e+"deg",left:~~n}),r(a(t("roundrect",{arcsize:i.corners}),{width:s,height:i.scale*i.width,left:i.scale*i.radius,top:-i.scale*i.width>>1,filter:l}),t("fill",{color:h(i.color,e),opacity:i.opacity}),t("stroke",{opacity:0}))))}if(i.shadow)for(l=1;l<=i.lines;l++)u(l,-2,"progid:DXImageTransform.Microsoft.Blur(pixelradius=2,makeshadow=1,shadowopacity=.3)");for(l=1;l<=i.lines;l++)u(l);return r(e,p)},u.prototype.opacity=function(t,e,i,s){var n=t.firstChild;s=s.shadow&&s.lines||0,n&&e+s<n.childNodes.length&&(n=(n=(n=n.childNodes[e+s])&&n.firstChild)&&n.firstChild)&&(n.opacity=i)}}():t=o(d,"animation")}return u}),function(t){var e="searchwp_live_search";function i(t){this.config=null,this.input_el=t,this.results_id=null,this.results_el=null,this.parent_el=null,this.results_showing=!1,this.form_el=null,this.timer=!1,this.last_string="",this.spinner=null,this.spinner_showing=!1,this.has_results=!1,this.current_request=!1,this.results_destroy_on_blur=!0,this.init()}i.prototype={init:function(){var e=this,i=this.input_el;this.form_el=i.parents("form:eq(0)"),this.results_id=this.uniqid("searchwp_live_search_results_");var s=!1,n=i.data("swpconfig");if(n&&void 0!==n)for(var r in searchwp_live_search_params.config)n===r&&(s=!0,this.config=searchwp_live_search_params.config[r]);else for(var o in searchwp_live_search_params.config)"default"===o&&(s=!0,this.config=searchwp_live_search_params.config[o]);if(s){var a=i.data("swpengine");a&&(this.config.engine=a),i.data("swpengine",this.config.engine),i.attr("autocomplete","off");var l='<div class="search-suggest searchwp-live-search-results" id="'+this.results_id+'"></div>',h=i.data("swpparentel");h?(this.parent_el=t(h),this.parent_el.html(l)):this.config.parent_el?(this.parent_el=t(this.config.parent_el),this.parent_el.html(l)):t(".search-content").append(t(l)),this.results_el=t("#"+this.results_id),this.position_results(),t(window).resize(function(){e.position_results()}),this.config.spinner&&(this.spinner=new Spinner(this.config.spinner)),void 0===this.config.abort_on_enter&&(this.config.abort_on_enter=!0),i.keyup(function(i){e.current_request&&e.config.abort_on_enter&&13===i.keyCode&&e.current_request.abort(),t.trim(e.input_el.val()).length?e.results_showing||(e.position_results(),e.results_el.addClass("searchwp-live-search-results-showing"),e.show_spinner(),e.results_showing=!0):e.destroy_results(),e.has_results&&!e.spinner_showing&&e.last_string!==t.trim(e.input_el.val())&&(e.results_el.empty(),e.show_spinner())}).keyup(t.proxy(this.maybe_search,this)),(this.config.results_destroy_on_blur||void 0===this.config.results_destroy_on_blur)&&t("html").click(function(){e.destroy_results()}),i.click(function(t){t.stopPropagation()}),this.results_el.click(function(t){t.stopPropagation()})}else alert(searchwp_live_search_params.msg_no_config_found)},position_results:function(){var e=this.input_el,i=e.offset(),s=this.results_el,n=0;if(!e.is(":hidden")){switch(i.left+=parseInt(this.config.results.offset.x,10),i.top+=parseInt(this.config.results.offset.y,10),this.config.results.position){case"top":n=0-s.height();break;default:n=e.outerHeight()}s.css("left",i.left),s.css("top",i.top+n+"px"),"auto"===this.config.results.width&&s.width(e.outerWidth()-parseInt(s.css("paddingRight").replace("px",""),10)-parseInt(s.css("paddingLeft").replace("px",""),10)),t(document).trigger("searchwp_live_position_results",[s.css("left"),s.css("top"),s.width()])}},destroy_results:function(e){this.hide_spinner(),this.results_el.empty().removeClass("searchwp-live-search-results-showing"),this.results_showing=!1,this.has_results=!1,t(document).trigger("searchwp_live_destroy_results")},maybe_search:function(e){clearTimeout(this.timer),e.currentTarget.value.length>=this.config.input.min_chars&&(this.timer=setTimeout(t.proxy(this.search,this,e),this.config.input.delay))},show_spinner:function(){this.config.spinner&&!this.spinner_showing&&(this.spinner.spin(document.getElementById(this.results_id)),this.spinner_showing=!0,t(document).trigger("searchwp_live_show_spinner"))},hide_spinner:function(){this.config.spinner&&(this.spinner.stop(),this.spinner_showing=!1,t(document).trigger("searchwp_live_hide_spinner"))},search:function(e){var i=this,s=this.form_el,n=s.serialize(),r=s.attr("action")?s.attr("action"):"",o=this.input_el,a=this.results_el;t(document).trigger("searchwp_live_search_start",[o,a,s,r,n]),n+="&action=searchwp_live_search&swpengine="+o.data("swpengine")+"&swpquery="+o.val(),-1!==r.indexOf("?")&&(r=r.split("?"),n+="&"+r[1]),this.last_string=o.val(),this.has_results=!0,this.current_request=t.ajax({url:searchwp_live_search_params.ajaxurl,type:"POST",data:n,complete:function(){t(document).trigger("searchwp_live_search_complete",[o,a,s,r,n]),i.spinner_showing=!1,i.hide_spinner(),this.current_request=!1},success:function(e){0===e&&(e=""),t(document).trigger("searchwp_live_search_success",[o,a,s,r,n]),i.position_results(),a.html(e)}})},uniqid:function(t,e){var i;void 0===t&&(t="");var s=function(t,e){return e<(t=parseInt(t,10).toString(16)).length?t.slice(t.length-e):e>t.length?new Array(e-t.length+1).join("0")+t:t};return this.php_js||(this.php_js={}),this.php_js.uniqidSeed||(this.php_js.uniqidSeed=Math.floor(123456789*Math.random())),this.php_js.uniqidSeed++,i=t,i+=s(parseInt((new Date).getTime()/1e3,10),8),i+=s(this.php_js.uniqidSeed,5),e&&(i+=(10*Math.random()).toFixed(8).toString()),i}},t.fn[e]=function(s){return this.each(function(){t.data(this,"plugin_"+e)||t.data(this,"plugin_"+e,new i(t(this),s))}),this}}(jQuery),jQuery(document).ready(function(t){t('input[data-swplive="true"]').searchwp_live_search()});