UNPKG

angular-weibo-emotify

Version:

Angular directive and service to emotify weibo text

10 lines 1.56 kB
/*! * angular-weibo-emotify - Angular directive and service to emotify weibo text * https://github.com/RoberMac/angular-weibo-emotify * * Copyright (c) 2015 RoberTu <robertu0717@gmail.com> * @license MIT * @version v0.3.0 */ angular.module("weibo-emotify",[]).provider("weiboEmotify",function(){this.setEmotionsURL=function(t){this.emotionsURL=t},this.$get=["$window","$http","$q",function(t,i,e){function o(t){if(t){var i=t.replace(/\[[\u4e00-\u9fa5\w]+\]/g,function(t){var i=t.replace(/[\[\]]/g,""),e=r[i];if(!e)return t;var o="http://img.t.sinajs.cn/t4/appstyle/expression/ext/normal/",n=e.replace(/\-|\+|\@/g,"/").replace("?",""),s=e.indexOf("-")>0?"_org":e.indexOf("+")>0?"_thumb":"",c=e.indexOf("?")>0?".png":".gif";return'<img text="'+t+'" alt="'+t+'" src="'+o+n+s+c+'">'});return i||""}}if(!this.emotionsURL)throw new Error("`emotionsURL` is required");var n=t.localStorage,r=n&&JSON.parse(n.getItem("weiboEmotions")),s=this.emotionsURL;return e(function(t,e){r&&"2.0"===r._v?t():i.get(s).success(function(i){return"[object Object]"!==Object.prototype.toString.call(i)?void e("`emotions_list` is not a Object"):"2.0"!==i._v?void e("`emotions_list` is not v2.0"):(n&&n.setItem("weiboEmotions",JSON.stringify(i)),r=i,void t())}).error(function(t){e(t)})}).then(function(){return o})["catch"](function(t){throw new Error(t)})}]}).directive("weiboEmotify",["$timeout","weiboEmotify",function(t,i){return{restrict:"A",link:function(e,o,n){i.then(function(i){t(function(){o.html(i(o.html()))})})}}}]); //# sourceMappingURL=angular-weibo-emotify.min.js.map