UNPKG

tool-search

Version:

Tool-Search一个自定义搜索引擎的搜索框组件

2 lines 14.1 kB
(function(t){var e={};function r(n){if(e[n])return e[n].exports;var o=e[n]={i:n,l:!1,exports:{}};return t[n].call(o.exports,o,o.exports,r),o.l=!0,o.exports}r.m=t,r.c=e,r.d=function(t,e,n){r.o(t,e)||Object.defineProperty(t,e,{enumerable:!0,get:n})},r.r=function(t){"undefined"!==typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},r.t=function(t,e){if(1&e&&(t=r(t)),8&e)return t;if(4&e&&"object"===typeof t&&t&&t.__esModule)return t;var n=Object.create(null);if(r.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:t}),2&e&&"string"!=typeof t)for(var o in t)r.d(n,o,function(e){return t[e]}.bind(null,o));return n},r.n=function(t){var e=t&&t.__esModule?function(){return t["default"]}:function(){return t};return r.d(e,"a",e),e},r.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},r.p="",r(r.s="5a74")})({"24fb":function(t,e,r){"use strict";function n(t,e){var r=t[1]||"",n=t[3];if(!n)return r;if(e&&"function"===typeof btoa){var i=o(n),s=n.sources.map((function(t){return"/*# sourceURL=".concat(n.sourceRoot||"").concat(t," */")}));return[r].concat(s).concat([i]).join("\n")}return[r].join("\n")}function o(t){var e=btoa(unescape(encodeURIComponent(JSON.stringify(t)))),r="sourceMappingURL=data:application/json;charset=utf-8;base64,".concat(e);return"/*# ".concat(r," */")}t.exports=function(t){var e=[];return e.toString=function(){return this.map((function(e){var r=n(e,t);return e[2]?"@media ".concat(e[2]," {").concat(r,"}"):r})).join("")},e.i=function(t,r,n){"string"===typeof t&&(t=[[null,t,""]]);var o={};if(n)for(var i=0;i<this.length;i++){var s=this[i][0];null!=s&&(o[s]=!0)}for(var a=0;a<t.length;a++){var c=[].concat(t[a]);n&&o[c[0]]||(r&&(c[2]?c[2]="".concat(r," and ").concat(c[2]):c[2]=r),e.push(c))}},e}},"2a98":function(t,e,r){var n=r("24fb");e=n(!1),e.push([t.i,'.site_search *[data-v-31d1d7f3]{margin:0;padding:0;box-sizing:border-box}.site_search[data-v-31d1d7f3]{max-width:717px;margin:56px auto 14px}.search_list[data-v-31d1d7f3]{padding:5px 5px 0 5px}.search_list .search_group[data-v-31d1d7f3]{display:inline-block;position:relative;z-index:999}.search_list .search_group span[data-v-31d1d7f3]{display:block;font-size:16px;line-height:32px;color:#aabfb9;text-align:center;cursor:pointer}.search_list .search_group__list[data-v-31d1d7f3]{display:block;position:absolute;top:31px;padding:12px 0;width:75px;background:#fff;border-radius:4px;box-shadow:0 5px 11px rgba(0,0,0,.16);list-style:none}.search_list .search_group__list--visible[data-v-31d1d7f3]{display:none}.search_list .search_group:hover .search_group__list--visible[data-v-31d1d7f3]{display:block}.search_list .search_group__list[data-v-31d1d7f3]:before{position:absolute;top:-16px;left:10px;content:" ";display:block;width:0;height:0;border:10px solid transparent;border-bottom-color:#fff}.search_list .search_group__list li[data-v-31d1d7f3]{display:block;font-size:16px;line-height:32px;color:#aabfb9;text-align:center;cursor:pointer}.search_list .search_group__list li[data-v-31d1d7f3]:hover{color:#5b6662}.website_list[data-v-31d1d7f3]{list-style:none;display:inline-block;overflow:hidden;vertical-align:middle;margin-left:8px}.website_list li[data-v-31d1d7f3]{float:left;padding:0 11px;font-size:13px;line-height:31px;border-radius:3px 3px 0 0;cursor:pointer}.website_list .website_list__item--isActivity[data-v-31d1d7f3]{background-color:#fff}.search_form[data-v-31d1d7f3]{position:relative;box-shadow:0 2px 4px rgba(0,0,0,.1);color:#518193;font-size:15px}.search_form__input[data-v-31d1d7f3]{padding:12px;width:100%;height:52px;line-height:52px;font-size:16px;border:0;border-radius:4px;outline:none}.search_form__button[data-v-31d1d7f3]{position:absolute;top:0;right:0;background:#008b5f;border:0;width:52px;height:52px;line-height:52px;border-radius:0 4px 4px 0;font-weight:400;color:#fff}.search_form__button[data-v-31d1d7f3]:hover{background:#1ca479;cursor:pointer}',""]),t.exports=e},"35d6":function(t,e,r){"use strict";function n(t,e){for(var r=[],n={},o=0;o<e.length;o++){var i=e[o],s=i[0],a=i[1],c=i[2],u=i[3],l={id:t+":"+o,css:a,media:c,sourceMap:u};n[s]?n[s].parts.push(l):r.push(n[s]={id:s,parts:[l]})}return r}function o(t,e,r){var o=n(t,e);i(o,r)}function i(t,e){const r=e._injectedStyles||(e._injectedStyles={});for(var n=0;n<t.length;n++){var o=t[n],i=r[o.id];if(!i){for(var s=0;s<o.parts.length;s++)a(o.parts[s],e);r[o.id]=!0}}}function s(t){var e=document.createElement("style");return e.type="text/css",t.appendChild(e),e}function a(t,e){var r=s(e),n=t.css,o=t.media,i=t.sourceMap;if(o&&r.setAttribute("media",o),i&&(n+="\n/*# sourceURL="+i.sources[0]+" */",n+="\n/*# sourceMappingURL=data:application/json;base64,"+btoa(unescape(encodeURIComponent(JSON.stringify(i))))+" */"),r.styleSheet)r.styleSheet.cssText=n;else{while(r.firstChild)r.removeChild(r.firstChild);r.appendChild(document.createTextNode(n))}}r.r(e),r.d(e,"default",(function(){return o}))},"5a74":function(t,e,r){"use strict";if(r.r(e),"undefined"!==typeof window){var n=window.document.currentScript;if(Object({NODE_ENV:"production",BASE_URL:"/"}).NEED_CURRENTSCRIPT_POLYFILL){var o=r("8875");n=o(),"currentScript"in document||Object.defineProperty(document,"currentScript",{get:o})}var i=n&&n.src.match(/(.+\/)[^/]+\.js(\?.*)?$/);i&&(r.p=i[1])}var s=r("8bbf"),a=r.n(s);const c=/-(\w)/g,u=t=>t.replace(c,(t,e)=>e?e.toUpperCase():""),l=/\B([A-Z])/g,p=t=>t.replace(l,"-$1").toLowerCase();function d(t){const e={};return t.forEach(t=>{e[t]=void 0}),e}function f(t,e,r){t[e]=[].concat(t[e]||[]),t[e].unshift(r)}function h(t,e){if(t){const r=t.$options[e]||[];r.forEach(e=>{e.call(t)})}}function _(t,e){return new CustomEvent(t,{bubbles:!1,cancelable:!1,detail:e})}const b=t=>/function Boolean/.test(String(t)),m=t=>/function Number/.test(String(t));function g(t,e,{type:r}={}){if(b(r))return"true"===t||"false"===t?"true"===t:""===t||t===e||null!=t||t;if(m(r)){const e=parseFloat(t,10);return isNaN(e)?t:e}return t}function v(t,e){const r=[];for(let n=0,o=e.length;n<o;n++)r.push(y(t,e[n]));return r}function y(t,e){if(3===e.nodeType)return e.data.trim()?e.data:null;if(1===e.nodeType){const r={attrs:w(e),domProps:{innerHTML:e.innerHTML}};return r.attrs.slot&&(r.slot=r.attrs.slot,delete r.attrs.slot),t(e.tagName,r)}return null}function w(t){const e={};for(let r=0,n=t.attributes.length;r<n;r++){const n=t.attributes[r];e[n.nodeName]=n.nodeValue}return e}function x(t,e){const r="function"===typeof e&&!e.cid;let n,o,i,s=!1;function a(t){if(s)return;const e="function"===typeof t?t.options:t,r=Array.isArray(e.props)?e.props:Object.keys(e.props||{});n=r.map(p),o=r.map(u);const a=Array.isArray(e.props)?{}:e.props||{};i=o.reduce((t,e,n)=>(t[e]=a[r[n]],t),{}),f(e,"beforeCreate",(function(){const t=this.$emit;this.$emit=(e,...r)=>(this.$root.$options.customElement.dispatchEvent(_(e,r)),t.call(this,e,...r))})),f(e,"created",(function(){o.forEach(t=>{this.$root.props[t]=this[t]})})),o.forEach(t=>{Object.defineProperty(l.prototype,t,{get(){return this._wrapper.props[t]},set(e){this._wrapper.props[t]=e},enumerable:!1,configurable:!0})}),s=!0}function c(t,e){const r=u(e),n=t.hasAttribute(e)?t.getAttribute(e):void 0;t._wrapper.props[r]=g(n,e,i[r])}class l extends HTMLElement{constructor(){const r=super();r.attachShadow({mode:"open"});const n=r._wrapper=new t({name:"shadow-root",customElement:r,shadowRoot:r.shadowRoot,data(){return{props:{},slotChildren:[]}},render(t){return t(e,{ref:"inner",props:this.props},this.slotChildren)}}),o=new MutationObserver(t=>{let e=!1;for(let n=0;n<t.length;n++){const o=t[n];s&&"attributes"===o.type&&o.target===r?c(r,o.attributeName):e=!0}e&&(n.slotChildren=Object.freeze(v(n.$createElement,r.childNodes)))});o.observe(r,{childList:!0,subtree:!0,characterData:!0,attributes:!0})}get vueComponent(){return this._wrapper.$refs.inner}connectedCallback(){const t=this._wrapper;if(t._isMounted)h(this.vueComponent,"activated");else{const r=()=>{t.props=d(o),n.forEach(t=>{c(this,t)})};s?r():e().then(t=>{(t.__esModule||"Module"===t[Symbol.toStringTag])&&(t=t.default),a(t),r()}),t.slotChildren=Object.freeze(v(t.$createElement,this.childNodes)),t.$mount(),this.shadowRoot.appendChild(t.$el)}}disconnectedCallback(){h(this.vueComponent,"deactivated")}}return r||a(e),l}var C=x;r("24fb"),r("35d6");function S(t,e,r,n,o,i,s,a){var c,u="function"===typeof t?t.options:t;if(e&&(u.render=e,u.staticRenderFns=r,u._compiled=!0),n&&(u.functional=!0),i&&(u._scopeId="data-v-"+i),s?(c=function(t){t=t||this.$vnode&&this.$vnode.ssrContext||this.parent&&this.parent.$vnode&&this.parent.$vnode.ssrContext,t||"undefined"===typeof __VUE_SSR_CONTEXT__||(t=__VUE_SSR_CONTEXT__),o&&o.call(this,t),t&&t._registeredComponents&&t._registeredComponents.add(s)},u._ssrRegister=c):o&&(c=a?function(){o.call(this,(u.functional?this.parent:this).$root.$options.shadowRoot)}:o),c)if(u.functional){u._injectStyles=c;var l=u.render;u.render=function(t,e){return c.call(e),l(t,e)}}else{var p=u.beforeCreate;u.beforeCreate=p?[].concat(p,c):[c]}return{exports:t,options:u}}var E=function(){var t=this,e=t.$createElement,r=t._self._c||e;return r("div",{staticClass:"site_search"},[r("div",{staticClass:"search_list"},[r("div",{staticClass:"search_group"},[r("span",[t._v(t._s(t.groupName)),r("i",{staticClass:"mi-chevron-right"})]),r("ul",{staticClass:"search_group__list search_group__list--visible"},t._l(t.groupData,(function(e,n){return r("li",{key:n,on:{click:function(r){return t.handleGroup(e)}}},[t._v(t._s(e.group))])})),0)]),r("ul",{staticClass:"website_list"},t._l(t.groupList,(function(e,n){return r("li",{key:n,class:n==t.activity?"website_list__item--isActivity":"",style:{color:e.color},on:{click:function(r){return t.handleWebsite(e,n)}}},[t._v(t._s(e.name)+" ")])})),0)]),r("form",{ref:"site_search_from",staticClass:"search_form",attrs:{action:t.website.url,target:t.pageNew?"_blank":"_self"},on:{submit:function(e){return e.preventDefault(),t.handleSubmit.apply(null,arguments)}}},[r("input",{directives:[{name:"model",rawName:"v-model",value:t.content,expression:"content"}],staticClass:"search_form__input",attrs:{type:"text",name:t.website.keyword,placeholder:t.website.description,autocomplete:"off"},domProps:{value:t.content},on:{input:function(e){e.target.composing||(t.content=e.target.value)}}}),r("button",{staticClass:"search_form__button",attrs:{type:"submit"}},[r("svg",{staticStyle:{"vertical-align":"middle"},attrs:{"font-size":"18px","font-weight":"400",viewBox:"0 0 24 24",height:"24",width:"24",xmlns:"http://www.w3.org/2000/svg"}},[r("path",{attrs:{xmlns:"http://www.w3.org/2000/svg",d:"M10 4C6.68629 4 4 6.68629 4 10C4 13.3137 6.68629 16 10 16C13.3137 16 16 13.3137 16 10C16 6.68629 13.3137 4 10 4ZM2 10C2 5.58172 5.58172 2 10 2C14.4183 2 18 5.58172 18 10C18 11.8487 17.3729 13.551 16.3199 14.9056L21.7071 20.2929C22.0976 20.6834 22.0976 21.3166 21.7071 21.7071C21.3166 22.0976 20.6834 22.0976 20.2929 21.7071L14.9056 16.3199C13.551 17.3729 11.8487 18 10 18C5.58172 18 2 14.4183 2 10Z",fill:"#FFF"}})])])])])},k=[];const j=[{group:"常用",list:[{name:"百度",color:"#2100E0",url:"https://www.baidu.com",keyword:"wd",description:"百度一下"},{name:"必应",color:"#E35452",url:"https://cn.bing.com/search",keyword:"q",description:"必应搜索"},{name:"Google",color:"#F54231",url:"http://www.google.com.hk/search",keyword:"q",description:"Google searcb"}]},{group:"社区",list:[{name:"掘金",color:"#2100E0",url:"https://juejin.cn/search",keyword:"query",description:"探索掘金稀土"},{name:"CSDN",color:"#E35452",url:"https://so.csdn.net/so/search",keyword:"q",description:"CSDN搜索"},{name:"Github",color:"#F54231",url:"https://github.com/search",keyword:"q",description:"Github searcb"},{name:"Gitee",color:"#bd081c",url:"https://search.gitee.com/",keyword:"q",description:"Gitee searcb"}]}];var N={name:"tool-search",props:{groupData:{type:Array,default:function(){return j}},autoSubmit:{type:Boolean,default:!0},pageNew:{type:Boolean,default:!0}},data(){return{groupList:this.groupData[0].list,groupName:this.groupData[0].group,website:this.groupData[0].list[0],activity:0,content:""}},methods:{handleSubmit(){if(this.website.content=this.content,this.$emit("submitEvent",this.website),!this.autoSubmit)return!1;this.$refs.site_search_from.submit()},handleGroup(t){this.groupList=t.list,this.groupName=t.group},handleWebsite(t,e){this.activity=e,this.website=t}}},$=N;function O(t){var e=r("85a7");e.__inject__&&e.__inject__(t)}var L=S($,E,k,!1,O,"31d1d7f3",null,!0),M=L.exports;window.customElements.define("tool-search",C(a.a,M))},"85a7":function(t,e,r){"use strict";r.r(e);var n=r("ba30");for(var o in n)["default"].indexOf(o)<0&&function(t){r.d(e,t,(function(){return n[t]}))}(o)},8875:function(t,e,r){var n,o,i;(function(r,s){o=[],n=s,i="function"===typeof n?n.apply(e,o):n,void 0===i||(t.exports=i)})("undefined"!==typeof self&&self,(function(){function t(){var e=Object.getOwnPropertyDescriptor(document,"currentScript");if(!e&&"currentScript"in document&&document.currentScript)return document.currentScript;if(e&&e.get!==t&&document.currentScript)return document.currentScript;try{throw new Error}catch(f){var r,n,o,i=/.*at [^(]*\((.*):(.+):(.+)\)$/gi,s=/@([^@]*):(\d+):(\d+)\s*$/gi,a=i.exec(f.stack)||s.exec(f.stack),c=a&&a[1]||!1,u=a&&a[2]||!1,l=document.location.href.replace(document.location.hash,""),p=document.getElementsByTagName("script");c===l&&(r=document.documentElement.outerHTML,n=new RegExp("(?:[^\\n]+?\\n){0,"+(u-2)+"}[^<]*<script>([\\d\\D]*?)<\\/script>[\\d\\D]*","i"),o=r.replace(n,"$1").trim());for(var d=0;d<p.length;d++){if("interactive"===p[d].readyState)return p[d];if(p[d].src===c)return p[d];if(c===l&&p[d].innerHTML&&p[d].innerHTML.trim()===o)return p[d]}return null}}return t}))},"8bbf":function(t,e){t.exports=Vue},ba30:function(t,e,r){var n=r("2a98");n.__esModule&&(n=n.default),"string"===typeof n&&(n=[[t.i,n,""]]),n.locals&&(t.exports=n.locals);var o=r("35d6").default;t.exports.__inject__=function(t){o("31add5ba",n,t)}}}); //# sourceMappingURL=tool-search.min.js.map