-
Notifications
You must be signed in to change notification settings - Fork 0
/
airpub.min.js
2 lines (2 loc) · 9.54 KB
/
airpub.min.js
1
2
!function(e){function t(t,r,n,o){function a(t){var r={};return e.forEach(t,function(e){r[e]={},r[e].templateUrl=d+"/"+e+".html","404"!==e&&(r[e].controller=e),"layout"===e&&(r[e].views={layout:r.layout,"@layout":r.archive,"@layout.home":r.archive})}),r}function i(t,r,n){var o=e.copy(r);return o.url=t,n&&"object"==typeof n&&(o=e.extend(o,n)),o}function u(e){return{data:{title:e}}}var c=airpubConfigs.theme||"chill",d=(airpubConfigs.themePath||"bower_components")+"/"+c,l=a(["archive","single","admin","404","layout"]);r.otherwise("/404"),t.state("layout",i("",l.layout)).state("layout.home",i("/",l.layout)).state("layout.pager",i("/page/:page",l.archive)).state("layout.single",i("/article/:uri",l.single)).state("layout.create",i("/create",l.admin,u("新建文章"))).state("layout.update",i("/article/:uri/update",l.admin,u("更新文章"))).state("layout.404",i("/404",l[404])),n.hashPrefix(airpubConfigs.hashPrefix||"!"),airpubConfigs.html5Mode&&n.html5Mode(!0),airpubConfigs.upyun&&o.config({bucket:airpubConfigs.upyun.bucket,form_api_secret:airpubConfigs.upyun.form_api_secret})}e.module("airpub",["upyun","duoshuo","ui.router","ui.bootstrap","EditorNinja","EditorNinja.upload"]).config(["$stateProvider","$urlRouterProvider","$locationProvider","upyunProvider",t])}(window.angular),function(e){"use strict";function t(e){return function(t){function r(e,t){return e="object"==typeof e?e.join(" "):e,['<section class="'+e+'">','<div class="container">','<div class="row">','<div class="col-lg-8 col-lg-offset-2">',t,"</div>","</div>","</div>","</section>"].join("\n")}function n(e){return hljs.highlightAuto(e).value}if(!t)return"";if(!marked)throw new Error("marked.js required!");var o={};hljs&&(o.highlight=n);var a=new marked.Renderer;return a.code=function(e,t,n){if(this.options.highlight){var o=this.options.highlight(e,t);null!=o&&o!==e&&(n=!0,e=o)}return r("code-section",'<pre><code class="'+t+'">'+e+"</code></pre>")},a.html=function(e){return r("html-section",e)},a.heading=function(e,t){var n=t;return r("heading-section","<h"+n+">"+e+"</h"+n+">")},a.paragraph=function(e){return r("paragraph-section","<p>"+e+"</p>")},a.blockquote=function(e){return r("blockquote-section","<blockquote>"+e+"</blockquote>")},a.list=function(e,t){var n=t?"o":"u";return r("blockquote-section","<"+n+"l>"+e+"</"+n+"l>")},o.renderer=a,marked.setOptions(o),e.trustAsHtml(marked(t))}}e.module("airpub").filter("marked",["$sce",t])}(window.angular),function(e){"use strict";function t(e){return airpubConfigs?void(e.configs=airpubConfigs):console.error(new Error("airpub 缺少必要的配置文件!"))}e.module("airpub").controller("global",["$scope",t])}(window.angular),function(e){"use strict";function t(t,r){t.title=t.configs.name||"Airpub",t.description=t.configs.description||"just another Airpub blog",r.$on("updateMeta",function(r,n){return"string"==typeof n?t.title=n:void e.forEach(n,function(e,r){t[r]=e})})}e.module("airpub").controller("meta",["$scope","$rootScope",t])}(window.angular),function(e){"use strict";function t(t,r,n,o,a){function i(e,r){var n=0===r.user_id;return e||n?void(t.isVisitor=!0):void(t.user=r)}function u(){t.hiddenSigninSection=!t.hiddenSigninSection}function c(e,r,o){t.alerts.push({msg:e,type:r||"success"});var a=t.alerts.length-1;return n(function(){t.closeAlert(a)},o?1e3*o:3e3),a}function d(e){t.alerts.splice(e,1)}function l(t,r){if(t&&(0===t.indexOf("http")||0===t.indexOf("https"))){var n=r||document.getElementsByTagName("header")[0];n&&e.element(n).css({"background-image":"url("+t+")"})}}t.location=o,t.state=r,t.hiddenSigninSection=!0,t.toggleSigninSection=u,t.alerts=[],t.addAlert=c,t.closeAlert=d,t.updateBackground=l,t.copyrightYear=(new Date).getFullYear(),a.on("ready",i)}function r(){}e.module("airpub").controller("layout",["$scope",r]).controller("base",["$scope","$state","$timeout","$location","$duoshuo",t])}(window.angular),function(e){"use strict";function t(e,t,r,n){function o(e){return e&&!isNaN(parseInt(e))?parseInt(e):!1}if(e.itemsPerPage=10,e.currentPage=o(t.params.page)||1,n.$emit("updateMeta",e.configs.name),!(e.articles&&e.articles.length>0)){if(t.params.page)var a=!0,i=e.currentPage;r.get("threads/list",{page:e.currentPage,limit:e.itemsPerPage,with_content:1},function(r,n,o){return t.params.page&&(a=!1),r?e.addAlert("获取信息失败,请重试","danger"):0===n.length?t.go("layout.404"):(e.articles=n||[],e.totalItems=o.cursor.total,void(t.params.page&&(e.currentPage=i)))},function(){return t.go("layout.404")}),e.pageChanged=function(){a||t.go("layout.pager",{page:e.currentPage})}}}e.module("airpub").controller("archive",["$scope","$state","$duoshuo","$rootScope",t])}(window.angular),function(e){"use strict";function t(e,t,n,o){var a=t.params.uri;return a?(e.articleID=a,void(e.article||n.get("threads/details",{thread_id:a},function(t,a){return t?e.addAlert("文章内容获取失败,请稍后再试...","danger"):(e.article=a,o.$emit("updateMeta",{title:a.title,description:r(a.content)}),a.meta&&a.meta.background&&e.updateBackground(a.meta.background),void(a.author_id&&n.get("users/profile",{user_id:a.author_id},function(t,r){t||(e.author=r,e.author.description=r.connected_services.weibo?r.connected_services.weibo.description:null)})))},function(){return t.go("layout.404")}))):t.go("layout.404")}function r(e){var t=80;return e?e.length<=t?e:e.substr(0,t)+"...":""}e.module("airpub").controller("single",["$scope","$state","$duoshuo","$rootScope",t])}(window.angular),function(e){"use strict";function t(t,r,n,o,a){function i(){a.$emit("updateMeta",r.current.data.title),n.get("sites/membership",{},function(e,o){if(e||"administrator"!==o.role)return r.go("layout.home");var a="layout.update"===r.current.name&&r.params.uri;return a?void n.get("threads/details",{thread_id:r.params.uri},function(e,r){return t.isAdmin=!0,e?t.addAlert("文章内容获取失败,请稍后再试...","danger"):void(t.article=r)},function(){return t.addAlert("文章内容获取失败,请稍后再试...","danger")}):void(t.isAdmin=!0)},function(e){t.addAlert(e.errorMessage,"danger"),r.go("layout.home")})}function u(){if(!t.isAdmin)return!1;if(!t.article.title)return t.addAlert("至少写个标题咯...","danger");if(!t.article.content)return t.addAlert("至少写点内容咯...","danger");var e={};e.format="markdown",e.title=t.article.title,e.content=t.article.content,e.thread_key=uuid.v1(),e=l(e),f("beforeCreate",e),n.post("threads/create",e,function(e,o){return e?t.addAlert("发布失败...","danger"):(t.addAlert("发布成功"),n.post("threads/update",{thread_id:o.thread_id,url:g+h+"/article/"+o.thread_id},function(e){e&&console.log(e),r.go("layout.single",{uri:o.thread_id})}),void f("afterCreate",o))},function(){return t.addAlert("发布失败...","danger")})}function c(e){if(!e)return t.createArticle();if(!t.isAdmin)return!1;var o={};o.thread_id=e,o.title=t.article.title,o.content=t.article.content,o.url=g+h+"/article/"+e,o=l(o),f("beforeUpdate",o),n.post("threads/update",o,function(n,o){return n?t.addAlert("更新失败,请稍后再试...","danger"):(t.addAlert("更新成功!"),f("afterUpdate",o),void r.go("layout.single",{uri:e}))},function(){return t.addAlert("更新失败,请稍后再试...","danger")})}function d(e){return e&&t.isAdmin?(f("beforeRemove",e),void n.post("threads/remove",{thread_id:e},function(n){return n?t.addAlert("删除失败,请稍后再试...","danger"):(f("afterRemove",e),t.addAlert("删除成功!"),void r.go("layout.home"))},function(){return t.addAlert("删除失败,请稍后再试...","danger")})):!1}function l(r){return t.article.meta?(e.forEach(t.article.meta,function(e,t){r["meta["+t+"]"]=e}),r):r}function s(e,r){return e&&r&&"function"==typeof r?(t.bindedEvents||(t.bindedEvents={}),t.bindedEvents[e]=r,t.bindedEvents):!1}function f(e,r){return t.bindedEvents&&t.bindedEvents[e]?t.bindedEvents[e](r||t.article,e):void 0}t.isAdmin=!1;var g=t.configs.url||o.host(),p=t.configs.hashPrefix||"!",h="/#"+p;i(),t.createArticle=u,t.updateArticle=c,t.removeArticle=d,t.on=s}e.module("airpub").controller("admin",["$scope","$state","$duoshuo","$location","$rootScope",t])}(window.angular),function(){"use strict";function e(e){function t(t,r,n,o){function a(){c||(c=!0,e.upload("metaBackgroundForm",function(e,t,r){if(c=!1,e)return console.error(e);var n=200===r.code&&"ok"===r.message;n&&(i(r.absUrl),o.$setViewValue(r.absUrl))}))}function i(e){if(e&&0===e.indexOf("http")){var t=document.getElementsByTagName("header")[0],r=document.getElementById("metaBackground");if(t){var n={};n["background-image"]="url("+e+")",u(t).css(n),u(r).css(n)}}}var u=angular.element,c=!1,d=document.getElementById("uploadBackgroundBtn");u(d).on("change",a),o.$render=function(){i(o.$viewValue)}}var r={restrict:"AE",require:"ngModel",replace:!0,link:t,template:['<div id="metaBackground" class="meta-background clearfix">','<form name="metaBackgroundForm">','<input type="file" name="file" id="uploadBackgroundBtn" class="pull-left hidden-input"/>','<span class="upload-background-btn fa fa-cloud-upload">',"上传背景图片","</span>","</form>","</div>"].join("\n")};return r}function t(e){function t(e,t,r,n){function o(){n.$setViewValue(e.checkToShare)}function a(e){return function(e){return}}e.checkToShare=!1,e.updateCheckStatus=o,e.on("afterCreate",a()),e.on("afterUpdate",a())}var r={restrict:"AE",require:"ngModel",replace:!0,link:t,template:['<div id="metaShare" class="meta-share clearfix"">','<input type="checkbox" id="checkToShare" ng-model="checkToShare" ng-change="updateCheckStatus()" />','<label for="checkToShare">分享到微博</label>',"</div>"].join("\n")};return r}angular.module("airpub").directive("metaBackground",["upyun",e]).directive("metaShare",["$duoshuo",t])}();
//# sourceMappingURL=airpub.min.js.map