docsify/lib/docsify.min.js
2016-11-22 22:46:44 +08:00

2 lines
2.9 KiB
JavaScript

!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t(require("marked"),require("prismjs")):"function"==typeof define&&define.amd?define(["marked","prismjs"],t):e.Docsify=t(e.marked,e.Prism)}(this,function(e,t){"use strict";function n(){function e(){for(var e=0,t=n.length;e<t;e+=1){var r=n[e].parentNode,s=r.getBoundingClientRect();if(s.top<150&&s.bottom>150){var l=i[r.id];if(l===o)return;return o&&o.classList.remove("active"),l.classList.add("active"),void(o=l)}}}function t(){var e=window.location.hash.slice(1);if(e){var t=document.querySelector("#"+e);t&&t.scrollIntoView()}}if(!/mobile/i.test(navigator.userAgent)){for(var n=document.querySelectorAll(".anchor"),i={},r=document.querySelectorAll(".sidebar li"),o=null,s=0,l=r.length;s<l;s+=1){var a=r[s],c=a.querySelector("a");i[c.getAttribute("href").slice(1)]=a}document.querySelector("main .content").addEventListener("scroll",e),e(),window.addEventListener("hashchange",t),t()}}e="default"in e?e.default:e,t="default"in t?t.default:t;var i=function(e,t){void 0===t&&(t={});var n=new XMLHttpRequest;return n.open(t.method||"get",e),n.send(),{then:function(e){return n.addEventListener("load",e)}}},r=function(e){var t=[],n={};return e.forEach(function(e){var i=e.level||1,r=i-1;n[r]?(n[r].children=n[r].children||[],n[r].children.push(e)):(t.push(e),n[i]=e)}),t},o=function(e,t){return void 0===t&&(t=""),e&&e.length?(e.forEach(function(e){t+='<li><a class="section-link" href="#'+e.slug+'">'+e.title+"</a></li>",e.children&&(t+='<li><ul class="children">'+o(e.children)+"</li>")}),t+"</ul>"):""},s=function(e){return o(r(e),"<ul>")},l=[],a=new e.Renderer;a.heading=function(e,t){var n=e.toLowerCase().replace(/[\s\n\t]+/g,"-");return l.push({level:t,slug:n,title:e}),"<h"+t+' id="'+n+'"><a href="#'+n+'" class="anchor"></a>'+e+"</h"+t+">"},e.setOptions({renderer:a,highlight:function(e,n){return t.highlight(e,t.languages[n]||t.languages.markup)}});var c=function(t){var n='<section class="content">\n <article class="markdown-section">'+e(t)+"</article>\n </section>",i='<aside class="sidebar">'+s(l)+"</aside>";return"<main>"+i+n+"</main>"},u=function(){n()},d={el:"#app",title:document.title,sep:" - "},h=function e(t){e.installed=!0,this.replace=!0,this.opts=Object.assign({},t,d),this.dom=document.querySelector(this.opts.el),this.dom||(this.dom=document.body,this.replace=!1),this.loc=document.location.pathname,/\/$/.test(this.loc)&&(this.loc+="README"),this.load()};return h.prototype.load=function(){var e=this;i(this.loc+".md").then(function(t){var n=t.target;n.status>=400?e.render("not found"):(e.render(t.target.response),u())})},h.prototype.render=function(e){document.title=this.loc.slice(1)+this.opts.sep+this.opts.title,this.dom[this.replace?"outerHTML":"innerHTML"]=c(e)},h.use=function(){var e=arguments[0];if("function"!=typeof e)throw TypeError("[docsify] Invalid plugin "+e.name);e.call(h)},window.addEventListener("load",function(){h.installed||new h}),h});