@mlikiowa/nanaeo
Version:
Volantis nanaeo
3 lines (2 loc) • 10.5 kB
JavaScript
;function _typeof(t){return _typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},_typeof(t)}function _regeneratorRuntime(){_regeneratorRuntime=function(){return e};var t,e={},r=Object.prototype,n=r.hasOwnProperty,o="function"==typeof Symbol?Symbol:{},a=o.iterator||"@@iterator",i=o.asyncIterator||"@@asyncIterator",u=o.toStringTag||"@@toStringTag";function c(t,e,r,n){return Object.defineProperty(t,e,{value:r,enumerable:!n,configurable:!n,writable:!n})}try{c({},"")}catch(t){c=function(t,e,r){return t[e]=r}}function s(e,r,n,o){var a=r&&r.prototype instanceof f?r:f,i=Object.create(a.prototype);return c(i,"_invoke",function(e,r,n){var o=1;return function(a,i){if(3===o)throw Error("Generator is already running");if(4===o){if("throw"===a)throw i;return{value:t,done:!0}}for(n.method=a,n.arg=i;;){var u=n.delegate;if(u){var c=x(u,n);if(c){if(c===h)continue;return c}}if("next"===n.method)n.sent=n._sent=n.arg;else if("throw"===n.method){if(1===o)throw o=4,n.arg;n.dispatchException(n.arg)}else"return"===n.method&&n.abrupt("return",n.arg);o=3;var s=l(e,r,n);if("normal"===s.type){if(o=n.done?4:2,s.arg===h)continue;return{value:s.arg,done:n.done}}"throw"===s.type&&(o=4,n.method="throw",n.arg=s.arg)}}}(e,n,new _(o||[])),!0),i}function l(t,e,r){try{return{type:"normal",arg:t.call(e,r)}}catch(t){return{type:"throw",arg:t}}}e.wrap=s;var h={};function f(){}function d(){}function p(){}var y={};c(y,a,(function(){return this}));var v=Object.getPrototypeOf,m=v&&v(v(O([])));m&&m!==r&&n.call(m,a)&&(y=m);var g=p.prototype=f.prototype=Object.create(y);function b(t){["next","throw","return"].forEach((function(e){c(t,e,(function(t){return this._invoke(e,t)}))}))}function w(t,e){function r(o,a,i,u){var c=l(t[o],t,a);if("throw"!==c.type){var s=c.arg,h=s.value;return h&&"object"==_typeof(h)&&n.call(h,"__await")?e.resolve(h.__await).then((function(t){r("next",t,i,u)}),(function(t){r("throw",t,i,u)})):e.resolve(h).then((function(t){s.value=t,i(s)}),(function(t){return r("throw",t,i,u)}))}u(c.arg)}var o;c(this,"_invoke",(function(t,n){function a(){return new e((function(e,o){r(t,n,e,o)}))}return o=o?o.then(a,a):a()}),!0)}function x(e,r){var n=r.method,o=e.i[n];if(o===t)return r.delegate=null,"throw"===n&&e.i["return"]&&(r.method="return",r.arg=t,x(e,r),"throw"===r.method)||"return"!==n&&(r.method="throw",r.arg=new TypeError("The iterator does not provide a '"+n+"' method")),h;var a=l(o,e.i,r.arg);if("throw"===a.type)return r.method="throw",r.arg=a.arg,r.delegate=null,h;var i=a.arg;return i?i.done?(r[e.r]=i.value,r.next=e.n,"return"!==r.method&&(r.method="next",r.arg=t),r.delegate=null,h):i:(r.method="throw",r.arg=new TypeError("iterator result is not an object"),r.delegate=null,h)}function S(t){this.tryEntries.push(t)}function E(e){var r=e[4]||{};r.type="normal",r.arg=t,e[4]=r}function _(t){this.tryEntries=[[-1]],t.forEach(S,this),this.reset(!0)}function O(e){if(null!=e){var r=e[a];if(r)return r.call(e);if("function"==typeof e.next)return e;if(!isNaN(e.length)){var o=-1,i=function r(){for(;++o<e.length;)if(n.call(e,o))return r.value=e[o],r.done=!1,r;return r.value=t,r.done=!0,r};return i.next=i}}throw new TypeError(_typeof(e)+" is not iterable")}return d.prototype=p,c(g,"constructor",p),c(p,"constructor",d),d.displayName=c(p,u,"GeneratorFunction"),e.isGeneratorFunction=function(t){var e="function"==typeof t&&t.constructor;return!!e&&(e===d||"GeneratorFunction"===(e.displayName||e.name))},e.mark=function(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,p):(t.__proto__=p,c(t,u,"GeneratorFunction")),t.prototype=Object.create(g),t},e.awrap=function(t){return{__await:t}},b(w.prototype),c(w.prototype,i,(function(){return this})),e.AsyncIterator=w,e.async=function(t,r,n,o,a){void 0===a&&(a=Promise);var i=new w(s(t,r,n,o),a);return e.isGeneratorFunction(r)?i:i.next().then((function(t){return t.done?t.value:i.next()}))},b(g),c(g,u,"Generator"),c(g,a,(function(){return this})),c(g,"toString",(function(){return"[object Generator]"})),e.keys=function(t){var e=Object(t),r=[];for(var n in e)r.unshift(n);return function o(){for(;r.length;)if((n=r.pop())in e)return o.value=n,o.done=!1,o;return o.done=!0,o}},e.values=O,_.prototype={constructor:_,reset:function(e){if(this.prev=this.next=0,this.sent=this._sent=t,this.done=!1,this.delegate=null,this.method="next",this.arg=t,this.tryEntries.forEach(E),!e)for(var r in this)"t"===r.charAt(0)&&n.call(this,r)&&!isNaN(+r.slice(1))&&(this[r]=t)},stop:function(){this.done=!0;var t=this.tryEntries[0][4];if("throw"===t.type)throw t.arg;return this.rval},dispatchException:function(e){if(this.done)throw e;var r=this;function n(t){i.type="throw",i.arg=e,r.next=t}for(var o=r.tryEntries.length-1;o>=0;--o){var a=this.tryEntries[o],i=a[4],u=this.prev,c=a[1],s=a[2];if(-1===a[0])return n("end"),!1;if(!c&&!s)throw Error("try statement without catch or finally");if(null!=a[0]&&a[0]<=u){if(u<c)return this.method="next",this.arg=t,n(c),!0;if(u<s)return n(s),!1}}},abrupt:function(t,e){for(var r=this.tryEntries.length-1;r>=0;--r){var n=this.tryEntries[r];if(n[0]>-1&&n[0]<=this.prev&&this.prev<n[2]){var o=n;break}}o&&("break"===t||"continue"===t)&&o[0]<=e&&e<=o[2]&&(o=null);var a=o?o[4]:{};return a.type=t,a.arg=e,o?(this.method="next",this.next=o[2],h):this.complete(a)},complete:function(t,e){if("throw"===t.type)throw t.arg;return"break"===t.type||"continue"===t.type?this.next=t.arg:"return"===t.type?(this.rval=this.arg=t.arg,this.method="return",this.next="end"):"normal"===t.type&&e&&(this.next=e),h},finish:function(t){for(var e=this.tryEntries.length-1;e>=0;--e){var r=this.tryEntries[e];if(r[2]===t)return this.complete(r[4],r[3]),E(r),h}},"catch":function(t){for(var e=this.tryEntries.length-1;e>=0;--e){var r=this.tryEntries[e];if(r[0]===t){var n=r[4];if("throw"===n.type){var o=n.arg;E(r)}return o}}throw Error("illegal catch attempt")},delegateYield:function(e,r,n){return this.delegate={i:O(e),r,n},"next"===this.method&&(this.arg=t),h}},e}function asyncGeneratorStep(t,e,r,n,o,a,i){try{var u=t[a](i),c=u.value}catch(t){return void r(t)}u.done?e(c):Promise.resolve(c).then(n,o)}function _asyncToGenerator(t){return function(){var e=this,r=arguments;return new Promise((function(n,o){var a=t.apply(e,r);function i(t){asyncGeneratorStep(a,n,o,i,u,"next",t)}function u(t){asyncGeneratorStep(a,n,o,i,u,"throw",t)}i(void 0)}))}}var SearchService=function(){var t={queryText:null,data:null,template:'<div id="u-search">\n <div class="modal">\n <header class="modal-header" class="clearfix">\n <form id="u-search-modal-form" class="u-search-form" name="uSearchModalForm">\n <input type="text" id="u-search-modal-input" class="u-search-input" />\n <button type="submit" id="u-search-modal-btn-submit" class="u-search-btn-submit">\n <span class="fa-solid fa-search"></span>\n </button>\n </form>\n <a id="u-search-btn-close" class="btn-close"> <span class="fa-solid fa-times"></span> </a>\n </header>\n <main class="modal-body">\n <ul class="modal-results"></ul>\n </main>\n </div>\n <div id="modal-overlay" class="modal-overlay"></div>\n</div>\n',init:function(){var e=document.createElement("div");e.innerHTML+=t.template,document.body.append(e),document.querySelectorAll(".u-search-form").forEach((function(e){e.addEventListener("submit",t.onSubmit,!1)})),document.querySelector("#u-search-modal-input").addEventListener("input",t.onSubmit),document.querySelector("#u-search-btn-close").addEventListener("click",t.close,!1),document.querySelector("#modal-overlay").addEventListener("click",t.close,!1)},onSubmit:function(e){e.preventDefault();var r=e.target.querySelector(".u-search-input");t.queryText=r?r.value:e.target.value,t.queryText&&t.search()}};return t.search=_asyncToGenerator(_regeneratorRuntime().mark((function e(){var r;return _regeneratorRuntime().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(document.querySelectorAll(".u-search-input").forEach((function(e){e.value=t.queryText})),document.querySelector("#u-search").style.display="block",t.data){e.next=6;break}return e.next=5,t.fetchData();case 5:t.data=e.sent;case 6:r="",r+=t.buildResultList(t.data.pages),r+=t.buildResultList(t.data.posts),document.querySelector("#u-search .modal-results").innerHTML=r,window.pjax&&pjax.refresh(document.querySelector("#u-search")),document.addEventListener("keydown",(function n(e){"Escape"===e.code&&(t.close(),document.removeEventListener("keydown",n))}));case 12:case"end":return e.stop()}}),e)}))),t.close=function(){document.querySelector("#u-search").style.display="none"},t.fetchData=function(){return fetch(SearchServiceDataPath).then((function(t){return t.text()})).then((function(t){return JSON.parse(t)}))},t.buildResultList=function(e){var r="";return e.forEach((function(e){e.text&&(e.text=e.text.replace(/12345\d*/g,"")),!e.title&&e.text&&(e.title=e.text.trim().slice(0,15)),t.contentSearch(e)&&(r+=t.buildResult(e.permalink,e.title,e.digest))})),r},t.contentSearch=function(e){var r=e.title.trim().toLowerCase(),n=e.text.trim().toLowerCase(),o=t.queryText.trim().toLowerCase().split(/[-\s]+/),a=!1,i=-1,u=-1,c=-1;return r&&n&&o.forEach((function(t,s){if(i=r.indexOf(t),u=n.indexOf(t),i<0&&u<0?a=!1:(a=!0,u<0&&(u=0),0===s&&(c=u)),a){n=e.text.trim();var l=0,h=0;if(c>=0){h=0===(l=Math.max(c-40,0))?Math.min(200,n.length):Math.min(c+120,n.length);var f=n.substring(l,h);o.forEach((function(t){var e=new RegExp(t,"gi");f=f.replace(e,"<b mark>"+t+"</b>")})),e.digest=f+"......"}else h=Math.min(200,n.length),e.digest=n.trim().substring(0,h)}})),a},t.buildResult=function(e,r,n){var o="";return o+="<li>",o+="<a class='result' href='"+t.getUrlRelativePath(e)+"?keyword="+t.queryText+"'>",o+="<span class='title'>"+r+"</span>",""!==n&&(o+="<span class='digest'>"+n+"</span>"),o+="</a>",o+="</li>"},t.getUrlRelativePath=function(t){var e=t.split("//"),r=e[1].indexOf("/"),n=e[1].substring(r);return-1!=n.indexOf("?")&&(n=n.split("?")[0]),n},{init:function(){t.init()},setQueryText:function(e){t.queryText=e},search:function(){t.search()}}}();Object.freeze(SearchService),SearchService.init(),document.addEventListener("pjax:success",SearchService.init),document.addEventListener("pjax:send",(function(){document.querySelector("#u-search").style.display="none"}));
//# sourceMappingURL=../../maps/js/search/hexo.js.map