-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.min.js
More file actions
2 lines (2 loc) · 6.47 KB
/
Copy pathindex.min.js
File metadata and controls
2 lines (2 loc) · 6.47 KB
1
2
var getIconForOs,getOs,getTagClass,injectCss,isYaml,isYamlOrJson,splitThenAdd,stripQuotes,getEngine,getTypeIcon,setDefaults,suggestionFn;injectCss=function(t){var e,n;return"inject-css",n=void 0,"string"==typeof t&&(n=0===(t=t.trim()).indexOf("/")||0===t.indexOf("http:")||0===t.indexOf("https:")?"link":"style",null!=(e=document.getElementById("inject-css"))&&e.parentNode.removeChild(e),(e=document.createElement(n)).type="text/css",e.id="inject-css","link"===n?(e.rel="stylesheet",e.href=t):e.innerHTML=t,document.head.appendChild(e),e)},getOs=function(){var t;return(t=navigator.platform.toUpperCase()).indexOf("MAC")>-1?"mac":t.indexOf("WIN")>-1?"windows":t.indexOf("LINUX")>-1?"linux":"windows"},isYamlOrJson=function(t){return/\.(ya?ml|json)$/.test(t)},isYaml=function(t){return/\.(ya?ml)$/.test(t)},stripQuotes=function(t){return t.replace(/^"(.*)"$/,"$1")},getTagClass=function(t){var e;return e=1,t>10&&(e=10),t>25&&(e=25),t>50&&(e=50),t>100&&(e=100),"tag-"+e},splitThenAdd=function(t,e){return t.split("\n").concat(e).join("\n")},getIconForOs=function(t){return t.includes("mac")?"fa-apple":t.includes("windows")?"fa-windows":t.includes("linux")?"fa-linux":""},setDefaults=function(t){return t.map((function(t){return void 0===t.type&&(t.type="page"),t}))},getEngine=function(t){return t=setDefaults(t),new Bloodhound({datumTokenizer:function(t){return[].concat(Bloodhound.tokenizers.whitespace(t.name.replace(/[\(\)]/g,""))).concat(t.tags.map((function(t){return"#"+t}))).concat(":"+t.type).concat(t.url)},queryTokenizer:Bloodhound.tokenizers.whitespace,local:t,identify:function(t){return t.name}})},getTypeIcon=function(t){var e;switch(e="",t){case"file":e="fa-download";break;case"bookmark":e="fa-bookmark";break;default:e="fa-external-link-square"}return e},suggestionFn=function(t){var e;return e=t.tags.map((function(t){return"#"+t})).join(" "),`<div><div class="ta-obj">\n <div class="ta-row">\n <span class="name">${t.name}</span>\n <span class="type"><i class="fa ${getTypeIcon(t.type)}"></i></span>\n <span class="tags">${e}</span>\n </div>\n <div class="ta-row">\n <span class="url">${t._url}</span>\n </div>\n</div></div>`},angular.module("App",["ngRoute","ngStorage","angular-cache"]).constant("sourcesUrl","https://api.github.com/repos/links-js/db/contents/").filter("tagReplace",(function(){return function(t){return t?t.replace(/tag:/gi,"#"):""}})).filter("noReferrer",(function(){return function(t){return"https://href.li/?"+t}})).filter("filename",(function(){return function(t){return t.split("/").slice(-1)[0]}})).filter("getFaviconUrl",(function(){return function(t){return"https://www.google.com/s2/favicons?domain_url="+t}})).filter("getLastItem",(function(){return function(t){return t.slice(-1)[0]}})).filter("hasYamlOrJson",(function(){return function(t){return isYamlOrJson(t.name)}})).filter("getIconForOs",(function(){return getIconForOs})).factory("LinksLoader",["$http","$q","$rootScope","$filter",function(t,e,n,r){var o,s,i,a;return s=function(t){var e,n;return n=t.config.url,e=null,(e=e=isYaml(n)?jsyaml.load(t.data):t.data)._url=n,e},i=function(t){return!!(Boolean(t)&&t instanceof Object&&t.hasOwnProperty("links"))||(console.error("Incorrect object:",t),!1)},a=function(t,e){var n;return n=e.links.map((function(t){return t._url=e._url,t._source=window.btoa(e._url),t})),t.concat(n)},o=function(t){return t.push(t.filter(i).reduce(a,[])),t},{load:function(){var i;return i=n.settings.url.split("\n").filter((function(t){return t.length>0})).map((function(n){return t.get(n).then(s,(function(t){return console.error("HTTP error:",t),e.reject(t)}))})),e.all(i).then(o).then(r("getLastItem"))}}}]).directive("myTypeahead",(function(){return{restrict:"C",scope:!0,link:function(t,e,n){var r,o,s;return s={hint:!1,highlight:!0,minLength:1},r={name:"links",source:null,limit:t.$root.settings.limit,templates:{suggestion:suggestionFn},display:"name"},o=$(e[0]),null,t.$root.$watch("loadedLinks",(function(e,n){return e&&(r.source=getEngine(t.$root.loadedLinks),o.typeahead(s,r),o.bind("typeahead:select",(function(e,n){var r;return r=t.$root.settings["page"===n.type?"openPage":"openFile"],r="new"===(r=stripQuotes(r))?"_blank":"_self",window.open(n.url,r)}))),o.focus()})),t.$watch("term",(function(){return o.val(t.term).trigger("input").focus()}))}}})).factory("Settings",["$localStorage",function(t){var e,n;return n=["/db/db-global.yml","/db/db-"+getOs()+".yml"].join("\n"),e={url:n,openFile:"current",openPage:"new",cache:!0,limit:10},{reset:function(){return t.$reset(e)},storage:t.$default(e)}}]).controller("SettingsCtrl",["$scope","$rootScope","Settings","$http","sourcesUrl","$filter",function(t,e,n,r,o,s){var i;return i=function(){return t.status="Please reload page"},r.get(o).then((function(e){return t.sources=e.data.filter(s("hasYamlOrJson"))})),t.addSource=function(t){return e.settings.url=splitThenAdd(e.settings.url,"/db/"+t.path)},t.applyStyle=function(){injectCss(e.settings.css)},t.style=function(n){return e.settings.css=`/styles/${n}.css`,t.applyStyle()},t.reset=function(){return n.reset(),i()},t.clear=function(){return r.defaults.cache.destroy(),i()}}]).controller("TagsCtrl",["$scope","$rootScope",function(t,e){var n;return n={},e.loadedLinks.map((function(t){return t.tags})).forEach((function(t){return t.forEach((function(t){return n[t]=n.hasOwnProperty(t)?n[t]+1:1}))})),t.getClass=getTagClass,t.tags=n}]).controller("TypeCtrl",["$scope","$routeParams","$filter",function(t,e,n){return t.term=n("tagReplace")(e.term)}]).controller("ListCtrl",["$scope","$routeParams","$filter",function(t,e,n){var r,o;return r=null,o=function(){if(t.term.length>0)return t.change()},t.$root.$watch("loadedLinks",(function(e,n){return r=getEngine(t.$root.loadedLinks),o()})),t.searchResults=[],t.change=function(){if(r)return r.search(t.term.trim(),(function(e){return t.searchResults=e}))},t.term=n("tagReplace")(e.term),o()}]).config(["$routeProvider",function(t){return t.when("/type/:term?",{templateUrl:"typeahead.html",controller:"TypeCtrl"}).when("/list/:term?",{templateUrl:"list.html",controller:"ListCtrl"}).when("/tags",{templateUrl:"tags.html"}).otherwise({redirectTo:"/type"})}]).run(["$http","$rootScope","Settings","CacheFactory","LinksLoader",function(t,e,n,r,o){return e.settings=n.storage,null!==e.settings.css&&injectCss(e.settings.css),!0===e.settings.cache&&(t.defaults.cache=r("defaultCache",{maxAge:9e5,cacheFlushInterval:36e5,deleteOnExpire:"aggressive",storageMode:"localStorage"})),o.load().then((function(t){return console.log("Links are loaded:",t.length),e.loadedLinks=t}))}]);
//# sourceMappingURL=index.min.js.map