diff --git a/bower.json b/bower.json index 2886ff6..6ca317a 100644 --- a/bower.json +++ b/bower.json @@ -1,6 +1,5 @@ { "name": "duoshuo", - "version": "0.5.0", "authors": [ "turing " ], diff --git a/dist/duoshuo.min.js b/dist/duoshuo.min.js index 622e392..fd9e30a 100644 --- a/dist/duoshuo.min.js +++ b/dist/duoshuo.min.js @@ -1,2 +1,2 @@ -!function(e,r){"use strict";function o(){function o(e){if(e){if(!e.short_name)throw new Error("duoshuo.config(); `short_name` is required");window.duoshuoQuery=e}}this.config=o,this.$get=["$rootScope",function(o){var n={};return e.forEach(["get","post","ajax"],function(e){n[e]=function(n,i,d,s,u){if(!window.DUOSHUO)throw new Error("duoshuo embed.js is required!");var c=window.DUOSHUO.API;if(!c)throw new Error("duoshuo embed.js must be unstable version!");return t&&r.start(),c[e](n,i,function(e){t&&r.done(),d(0===e.code?null:new Error(e.code+" "+e.errorMessage),e.response,e),u||o.$apply()},function(e){return t&&r.done(),s&&"function"==typeof s?s(e):void 0})}}),n.on=function(e,r,n){if(0===["reset","ready"].indexOf(e))return r(new Error("event not found"));var t=e;return"ready"===t&&(t="reset"),window.DUOSHUO.visitor.on(t,function(){var e=this,t=this.data;r(null,t,e),n||o.$apply()})},n.render=function(){if(!window.DUOSHUO||!window.DUOSHUO.initSelector)throw new Error("createDirective(); duoshuo embed.js is required!");return window.DUOSHUO.initSelector(window.DUOSHUO.selectors[".ds-thread"])},n}]}function n(e){return function(){return{restrict:"AE",replace:!0,template:'
',link:function(){window.DUOSHUO&&window.DUOSHUO.initSelector&&window.DUOSHUO.initSelector(window.DUOSHUO.selectors["."+e])}}}}if(!e)throw new Error("Angular.js required!");var t=r&&r.start&&r.done;e.module("duoshuo",[]).provider("duoshuo",o).directive("dsThread",n("ds-thread")).directive("dsRecentComments",n("ds-recent-comments")).directive("dsRecentVisitors",n("ds-recent-visitors")).directive("dsThreadCount",n("ds-thread-count")).directive("dsTopThreads",n("ds-top-threads")).directive("dsLogin",n("ds-login"))}(window.angular,window.NProgress); +!function(e,r){"use strict";function t(){function t(e){if(e){if(!e.short_name)throw new Error("duoshuo.config(); `short_name` is required");window.duoshuoQuery=e}}this.config=t,this.$get=["$rootScope",function(t){var n={};return e.forEach(["get","post","ajax"],function(e){n[e]=function(n,i,d,s,u){if(!window.DUOSHUO)throw new Error("duoshuo embed.js is required!");var c=window.DUOSHUO.API;if(!c)throw new Error("duoshuo embed.js must be unstable version!");return o&&r.start(),c[e](n,i,function(e){o&&r.done(),d(0===e.code?null:new Error(e.code+" "+e.errorMessage),e.response,e),u||t.$apply()},function(e){return o&&r.done(),s&&"function"==typeof s?s(e):void 0})}}),n.on=function(e,r,n){if(0===["reset","ready"].indexOf(e))return r(new Error("event not found"));var o=e;return"ready"===o&&(o="reset"),window.DUOSHUO.visitor.on(o,function(){var e=this,o=this.data;r(null,o,e),n||t.$apply()})},n.render=function(){if(!window.DUOSHUO||!window.DUOSHUO.initSelector)throw new Error("createDirective(); duoshuo embed.js is required!");return window.DUOSHUO.initSelector(window.DUOSHUO.selectors[".ds-thread"])},n}]}function n(r){return"ds-thread"===r?function(){return{restrict:"AE",replace:!0,template:'
',link:function(r,t,n){e.element(document).ready(function(){var r={};n.threadId&&(r["thread-id"]=n.threadId),n.threadKey&&(r["thread-key"]=n.threadKey),e.element(t[0]).append(window.DUOSHUO.createEmbedThread("div",r))})}}}:function(){return{restrict:"AE",replace:!0,template:'
',link:function(){e.element(document).ready(function(){window.DUOSHUO&&window.DUOSHUO.initSelector&&window.DUOSHUO.initSelector(r,window.DUOSHUO.selectors["."+r])})}}}}if(!e)throw new Error("Angular.js required!");var o=r&&r.start&&r.done;e.module("duoshuo",[]).provider("duoshuo",t).directive("dsThread",n("ds-thread")).directive("dsRecentComments",n("ds-recent-comments")).directive("dsRecentVisitors",n("ds-recent-visitors")).directive("dsThreadCount",n("ds-thread-count")).directive("dsTopThreads",n("ds-top-threads")).directive("dsLogin",n("ds-login"))}(window.angular,window.NProgress); //# sourceMappingURL=duoshuo.min.js.map \ No newline at end of file diff --git a/dist/duoshuo.min.js.map b/dist/duoshuo.min.js.map index f5ca097..476717d 100644 --- a/dist/duoshuo.min.js.map +++ b/dist/duoshuo.min.js.map @@ -1 +1 @@ -{"version":3,"file":"dist/duoshuo.min.js","sources":["src/duoshuo.js"],"names":["angular","NProgress","duoshuoProvider","config","configs","short_name","Error","window","duoshuoQuery","this","$get","$rootScope","duoshuo","forEach","method","endpoint","data","callback","errorCallback","skipCheck","DUOSHUO","API","NProgressExist","start","result","done","code","errorMessage","response","$apply","err","on","eve","indexOf","e","visitor","self","render","initSelector","selectors","createDirective","type","restrict","replace","template","link","module","provider","directive"],"mappings":"CAAC,SAAUA,EAASC,GAClB,YAmBA,SAASC,KAGP,QAASC,GAAOC,GACd,GAAKA,EAAL,CAEA,IAAKA,EAAQC,WACX,KAAM,IAAIC,OAAM,6CAElBC,QAAOC,aAAeJ,GARxBK,KAAKN,OAASA,EAWdM,KAAKC,MAAQ,aACX,SAASC,GACP,GAAIC,KAgEJ,OA7DAZ,GAAQa,SAAS,MAAO,OAAQ,QAAS,SAASC,GAChDF,EAAQE,GAAU,SAASC,EAAUC,EAAMC,EAAUC,EAAeC,GAClE,IAAKZ,OAAOa,QACV,KAAM,IAAId,OAAM,gCAElB,IAAIe,GAAMd,OAAOa,QAAQC,GACzB,KAAKA,EACH,KAAM,IAAIf,OAAM,6CAIlB,OAFIgB,IAAgBrB,EAAUsB,QAEvBF,EAAIP,GAAQC,EAAUC,EAAM,SAASQ,GACtCF,GAAgBrB,EAAUwB,OAE9BR,EACmB,IAAhBO,EAAOE,KAAc,KAAO,GAAIpB,OAAMkB,EAAOE,KAAO,IAAMF,EAAOG,cAClEH,EAAOI,SACPJ,GAGGL,GACHR,EAAWkB,UAGZ,SAASC,GAIV,MAHIR,IACFrB,EAAUwB,OAERP,GAA2C,kBAApB,GAClBA,EAAcY,GADvB,YASNlB,EAAQmB,GAAK,SAASC,EAAKf,EAAUE,GACnC,GAAwC,KAAnC,QAAS,SAASc,QAAQD,GAC7B,MAAOf,GAAS,GAAIX,OAAM,mBAC5B,IAAI4B,GAAIF,CAER,OADU,UAANE,IAAeA,EAAI,SAChB3B,OAAOa,QAAQe,QAAQJ,GAAGG,EAAG,WAClC,GAAIE,GAAO3B,KACPO,EAAOP,KAAKO,IAChBC,GAAS,KAAMD,EAAMoB,GAChBjB,GAAWR,EAAWkB,YAM/BjB,EAAQyB,OAAS,WACf,IAAK9B,OAAOa,UAAYb,OAAOa,QAAQkB,aACrC,KAAM,IAAIhC,OAAM,mDAElB,OAAOC,QAAOa,QAAQkB,aACpB/B,OAAOa,QAAQmB,UAAU,gBAItB3B,IAKb,QAAS4B,GAAgBC,GACvB,MAAO,YACL,OACEC,SAAU,KACVC,SAAS,EACTC,SAAU,eAAiBH,EAAO,KAClCI,KAAM,WACCtC,OAAOa,SAAYb,OAAOa,QAAQkB,cAIvC/B,OAAOa,QACJkB,aAAa/B,OAAOa,QAAQmB,UAAU,IAAME,OAhHvD,IAAKzC,EACH,KAAM,IAAIM,OAAM,uBAElB,IAAIgB,GAAiBrB,GAAaA,EAAUsB,OAAStB,EAAUwB,IAE/DzB,GACG8C,OAAO,cAEPC,SAAS,UAAW7C,GAEpB8C,UAAU,WAAYR,EAAgB,cACtCQ,UAAU,mBAAoBR,EAAgB,uBAC9CQ,UAAU,mBAAoBR,EAAgB,uBAC9CQ,UAAU,gBAAiBR,EAAgB,oBAC3CQ,UAAU,eAAgBR,EAAgB,mBAC1CQ,UAAU,UAAWR,EAAgB,cAuGvCjC,OAAOP,QAASO,OAAON","sourceRoot":"../src/duoshuo.js"} \ No newline at end of file +{"version":3,"file":"dist/duoshuo.min.js","sources":["src/duoshuo.js"],"names":["angular","NProgress","duoshuoProvider","config","configs","short_name","Error","window","duoshuoQuery","this","$get","$rootScope","duoshuo","forEach","method","endpoint","data","callback","errorCallback","skipCheck","DUOSHUO","API","NProgressExist","start","result","done","code","errorMessage","response","$apply","err","on","eve","indexOf","e","visitor","self","render","initSelector","selectors","createDirective","type","restrict","replace","template","link","scope","element","attrs","document","ready","threadId","threadKey","append","createEmbedThread","module","provider","directive"],"mappings":"CAAC,SAAUA,EAASC,GAClB,YAmBA,SAASC,KAGP,QAASC,GAAOC,GACd,GAAKA,EAAL,CAEA,IAAKA,EAAQC,WACX,KAAM,IAAIC,OAAM,6CAElBC,QAAOC,aAAeJ,GARxBK,KAAKN,OAASA,EAWdM,KAAKC,MAAQ,aACX,SAASC,GACP,GAAIC,KAgEJ,OA7DAZ,GAAQa,SAAS,MAAO,OAAQ,QAAS,SAASC,GAChDF,EAAQE,GAAU,SAASC,EAAUC,EAAMC,EAAUC,EAAeC,GAClE,IAAKZ,OAAOa,QACV,KAAM,IAAId,OAAM,gCAElB,IAAIe,GAAMd,OAAOa,QAAQC,GACzB,KAAKA,EACH,KAAM,IAAIf,OAAM,6CAIlB,OAFIgB,IAAgBrB,EAAUsB,QAEvBF,EAAIP,GAAQC,EAAUC,EAAM,SAASQ,GACtCF,GAAgBrB,EAAUwB,OAE9BR,EACmB,IAAhBO,EAAOE,KAAc,KAAO,GAAIpB,OAAMkB,EAAOE,KAAO,IAAMF,EAAOG,cAClEH,EAAOI,SACPJ,GAGGL,GACHR,EAAWkB,UAGZ,SAASC,GAIV,MAHIR,IACFrB,EAAUwB,OAERP,GAA2C,kBAApB,GAClBA,EAAcY,GADvB,YASNlB,EAAQmB,GAAK,SAASC,EAAKf,EAAUE,GACnC,GAAwC,KAAnC,QAAS,SAASc,QAAQD,GAC7B,MAAOf,GAAS,GAAIX,OAAM,mBAC5B,IAAI4B,GAAIF,CAER,OADU,UAANE,IAAeA,EAAI,SAChB3B,OAAOa,QAAQe,QAAQJ,GAAGG,EAAG,WAClC,GAAIE,GAAO3B,KACPO,EAAOP,KAAKO,IAChBC,GAAS,KAAMD,EAAMoB,GAChBjB,GAAWR,EAAWkB,YAM/BjB,EAAQyB,OAAS,WACf,IAAK9B,OAAOa,UAAYb,OAAOa,QAAQkB,aACrC,KAAM,IAAIhC,OAAM,mDAElB,OAAOC,QAAOa,QAAQkB,aACpB/B,OAAOa,QAAQmB,UAAU,gBAItB3B,IAKb,QAAS4B,GAAgBC,GACvB,MAAa,cAATA,EACK,WACL,OACEC,SAAU,KACVC,SAAS,EACTC,SAAU,wCACVC,KAAM,SAASC,EAAOC,EAASC,GAE7BhD,EAAQ+C,QAAQE,UAAUC,MAAM,WAC9B,GAAIlC,KACAgC,GAAMG,WAAUnC,EAAK,aAAegC,EAAMG,UAC1CH,EAAMI,YAAWpC,EAAK,cAAgBgC,EAAMI,WAGhDpD,EACG+C,QAAQA,EAAQ,IAChBM,OAAO9C,OAAOa,QAAQkC,kBAAkB,MAAOtC,SAOrD,WACL,OACE0B,SAAU,KACVC,SAAS,EACTC,SAAU,eAAiBH,EAAO,KAClCI,KAAM,WACJ7C,EAAQ+C,QAAQE,UAAUC,MAAM,WACzB3C,OAAOa,SAAYb,OAAOa,QAAQkB,cAIvC/B,OAAOa,QACJkB,aAAaG,EAAMlC,OAAOa,QAAQmB,UAAU,IAAME,SAxI/D,IAAKzC,EACH,KAAM,IAAIM,OAAM,uBAElB,IAAIgB,GAAiBrB,GAAaA,EAAUsB,OAAStB,EAAUwB,IAE/DzB,GACGuD,OAAO,cAEPC,SAAS,UAAWtD,GAEpBuD,UAAU,WAAYjB,EAAgB,cACtCiB,UAAU,mBAAoBjB,EAAgB,uBAC9CiB,UAAU,mBAAoBjB,EAAgB,uBAC9CiB,UAAU,gBAAiBjB,EAAgB,oBAC3CiB,UAAU,eAAgBjB,EAAgB,mBAC1CiB,UAAU,UAAWjB,EAAgB,cAgIvCjC,OAAOP,QAASO,OAAON","sourceRoot":"../src/duoshuo.js"} \ No newline at end of file diff --git a/package.json b/package.json index 61e0359..f8cb699 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "angular-duoshuo", - "version": "0.5.0", + "version": "0.5.1", "description": "a duoshuo SDK for angular.js, pure front-end, cross-domain request supported.", "main": "dist/duoshuo.min.js", "scripts": { diff --git a/src/duoshuo.js b/src/duoshuo.js index 1e88830..39c6fba 100644 --- a/src/duoshuo.js +++ b/src/duoshuo.js @@ -102,18 +102,43 @@ } function createDirective(type) { + if (type === 'ds-thread') { + return function dsThreadDirective() { + return { + restrict: 'AE', + replace: true, + template: '
', + link: function(scope, element, attrs) { + // Render comments when DOM has been injected. + angular.element(document).ready(function() { + var data = {}; + if (attrs.threadId) data['thread-id'] = attrs.threadId; + if (attrs.threadKey) data['thread-key'] = attrs.threadKey; + + // Fired after DOM ready + angular + .element(element[0]) + .append(window.DUOSHUO.createEmbedThread('div', data)); + }); + } + }; + }; + } + return function directive() { return { restrict: 'AE', replace: true, template: '
', link: function(scope, element, attrs) { - if (!window.DUOSHUO || !window.DUOSHUO.initSelector) - return; + angular.element(document).ready(function() { + if (!window.DUOSHUO || !window.DUOSHUO.initSelector) + return; - // Trigger init selector function - window.DUOSHUO - .initSelector(window.DUOSHUO.selectors['.' + type]) + // Trigger init selector function + window.DUOSHUO + .initSelector(type, window.DUOSHUO.selectors['.' + type]) + }); } }; }