pixelfed/public/js/search.js

1 line
23 KiB
JavaScript
Raw Normal View History

2020-04-22 05:58:48 +00:00
(window.webpackJsonp=window.webpackJsonp||[]).push([[20],{"80eU":function(t,s,e){"use strict";var r=e("WiWu");e.n(r).a},9:function(t,s,e){t.exports=e("EnJJ")},"9tPo":function(t,s){t.exports=function(t){var s="undefined"!=typeof window&&window.location;if(!s)throw new Error("fixUrls requires window.location");if(!t||"string"!=typeof t)return t;var e=s.protocol+"//"+s.host,r=e+s.pathname.replace(/\/[^\/]*$/,"/");return t.replace(/url\s*\(((?:[^)(]|\((?:[^)(]+|\([^)(]*\))*\))*)\)/gi,(function(t,s){var a,i=s.trim().replace(/^"(.*)"$/,(function(t,s){return s})).replace(/^'(.*)'$/,(function(t,s){return s}));return/^(#|data:|http:\/\/|https:\/\/|file:\/\/\/|\s*$)/i.test(i)?t:(a=0===i.indexOf("//")?i:0===i.indexOf("/")?e+i:r+i.replace(/^\.\//,""),"url("+JSON.stringify(a)+")")}))}},EnJJ:function(t,s,e){Vue.component("search-results",e("IpYn").default)},I1BE:function(t,s){t.exports=function(t){var s=[];return s.toString=function(){return this.map((function(s){var e=function(t,s){var e=t[1]||"",r=t[3];if(!r)return e;if(s&&"function"==typeof btoa){var a=(n=r,"/*# sourceMappingURL=data:application/json;charset=utf-8;base64,"+btoa(unescape(encodeURIComponent(JSON.stringify(n))))+" */"),i=r.sources.map((function(t){return"/*# sourceURL="+r.sourceRoot+t+" */"}));return[e].concat(i).concat([a]).join("\n")}var n;return[e].join("\n")}(s,t);return s[2]?"@media "+s[2]+"{"+e+"}":e})).join("")},s.i=function(t,e){"string"==typeof t&&(t=[[null,t,""]]);for(var r={},a=0;a<this.length;a++){var i=this[a][0];"number"==typeof i&&(r[i]=!0)}for(a=0;a<t.length;a++){var n=t[a];"number"==typeof n[0]&&r[n[0]]||(e&&!n[2]?n[2]=e:e&&(n[2]="("+n[2]+") and ("+e+")"),s.push(n))}},s}},IpYn:function(t,s,e){"use strict";e.r(s);var r={props:["query","profileId"],data:function(){return{loading:!0,networkError:!1,results:{hashtags:[],profiles:[],statuses:[]},filters:{hashtags:!0,profiles:!0,statuses:!0},analysis:"profile"}},beforeMount:function(){this.bootSearch()},mounted:function(){$(".search-bar input").val(this.query)},methods:{bootSearch:function(){var t=this.searchLexer();this.analysis=t,this.fetchSearchResults()},fetchSearchResults:function(){if("remote"==this.analysis){var t=this.query;if(new URL(t).host===window.location.host)return void(window.location.href=t)}this.searchContext(this.analysis)},followProfile:function(t,s){var e=this;this.loading=!0,axios.post("/i/follow",{item:t.entity.id}).then((function(r){return 1==t.entity.local?void e.fetchSearchResults():(e.loading=!1,void(e.results.profiles[s].entity.follow_request=!0))})).catch((function(t){t.response.data.message&&swal("Error",t.response.data.message,"error")}))},searchLexer:function(){var t=this.query;return t.startsWith("#")?"hashtag":2==(t.match(/@/g)||[]).length?"webfinger":t.startsWith("@")?"profile":t.startsWith("https://")?"remote":"all"},buildUrl:function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"hashtag",s=arguments.length>1?arguments[1]:void 0;switch(t){case"hashtag":return s.url+"?src=search";case"profile":return 1==s.entity.local?s.url:"/i/web/profile/_/"+s.entity.id;default:return s.url+"?src=search"}},searchContext:function(t){var s=this;switch(t){case"all":axios.get("/api/search",{params:{q:this.query,src:"metro",v:1,scope:"all"}}).then((function(t){var e=t.data;s.results.hashtags=e.hashtags?e.hashtags:[],s.results.profiles=e.profiles?e.profiles:[],s.results.statuses=e.posts?e.posts:[],s.loading=!1})).catch((function(t){s.loading=!1,console.log(t),s.networkError=!0}));break;case"remote":axios.get("/api/search",{params:{q:this.query,src:"metro",v:1,scope:"remote"}}).then((function(t){var e=t.data;s.results.hashtags=e.hashtags?e.hashtags:[],s.results.profiles=e.profiles?e.profiles:[],s.results.statuses=e.posts?e.posts:[],s.results.profiles.length&&(s.analysis="profile"),s.results.statuses.length&&(s.analysis="remotePost"),s.loading=!1})).catch((function(t){s.loading=!1,console.log(t),s.networkError=!0}));break;case"hashtag":axios.get("/api/search",{params:{q:this.query.slice(1),src:"metro",v:1,scope:"hashtag"}}).then((function(t){var e=t.data;s.results.hashtags=e.h