(function(){var t="system-default",e=["comment.postsuccess","comment.posterror"],n={"comment.reply":"comment.reply.start","userinfo.savefromhtml":"userinfo.readfromhtml"},o=function(o,r){if("undefined"==typeof jquery&&void 0===r)throw new error("no jquery!");this.$=r||window.jquery,object.keys||(object.keys=function(t){return this.$.map(t,function(t,e){return e})}),console||(window.console={},console.logs=[],console.log=console.error=console.warn=function(){console.logs.push(arguments)}),e=e.concat(object.keys(n));var s=this;return i(this),o=o||{},o.cookiepath=o.cookiepath||"/",o.bloghost=o.bloghost||location.origin,o.ajaxurl=o.ajaxurl||location.origin,o.commentmaxlength=o.commentmaxlength||1e3,o.lang=o.lang||{},o.comment=o.comment||{},o.comment.inputs=o.comment.inputs||{},o.comment.usedefaultevents=o.comment.usedefaultevents||!1,this.eachoncommentinputs=function(t){return s.$.each(o.comment.inputs,t)},this.eachoncommentinputs(function(t,e){!e.getter&&e.selector&&(e.getter=function(){return s.$(e.selector).val()}),!e.setter&&e.selector&&(e.setter=function(t){return s.$(e.selector).val(t)}),e.validator||(e.validator=function(t,n){for(t=t||e.getter();;){if(t=t||"",t=t.tostring().trim(),""===t){if(e.required)break;return n(null)}if(e.validaterule&&(e.validaterule.lastindex=0,!e.validaterule.test(t)))break;return n(null)}var o=new error(e.validatefailedmessage||s.options.lang.error[e.validatefailederrorcode]);return o.code=e.validatefailederrorcode,n(o)})}),this.options=o,this.plugin.on("userinfo.output","system",function(){s.eachoncommentinputs(function(t,e){e.savelocally&&(s.userinfo[t]=s.cookie.get("zbp_userinfo_"+t),s.userinfo[t]&&e.setter(s.userinfo[t]))})}),this.plugin.on("userinfo.readfromhtml","system",function(){s.eachoncommentinputs(function(t,e){e.savelocally&&(s.userinfo[t]=e.getter())}),s.userinfo.save()}),this.plugin.on("userinfo.save","system",function(){s.eachoncommentinputs(function(t,e){e.savelocally&&(s.userinfo[t]=e.getter(),s.cookie.set("zbp_userinfo_"+t,s.userinfo[t]))})}),this.plugin.on("comment.get","system",function(t,e){s.$.get(s.options.bloghost+"zb_system/cmd.php?act=getcmt&postid="+t+"&page="+e,function(n,o,i){s.plugin.emit("comment.got",[t,e],n,o,i)})}),this.plugin.on("comment.post.validate","system",function(t){var e=0,n=!1,o=function(o){if(!n){if(o)return n=!0,void s.plugin.emit("comment.post.validate.error",o,t);if(e++,e===object.keys(s.options.comment.inputs).length){var i={no:0,msg:""};if(s.plugin.emit("comment.verifydata",i,t),i.no>0){o=new error(i.msg);return o.code=i.no,void s.plugin.emit("comment.post.validate.error",o,t)}s.plugin.emit("comment.post.validate.success",t)}}};s.eachoncommentinputs(function(e,n){n.validator(t[e],o)})}),this.plugin.on("comment.post.start","system",function(t){s.eachoncommentinputs(function(e,n){t[e]=t[e]||n.getter()}),t.commentkey=(new date).gettime()+""+math.random(),s.plugin.emit("comment.post.validate",t)}),this.plugin.on("comment.post.validate.error","system",function(t,e){s.plugin.emit("comment.post.error",t,e)}),this.plugin.on("comment.post.validate.success","system",function(t){s.$.post(t.action,t).done(function(e,n,o){s.plugin.emit("comment.postsuccess",t,e,n,o);var i=s.$.parsejson(e);if(i.err&&i.err.code>0){var r=new error(i.err.msg);r.code=i.err.code,s.plugin.emit("comment.post.error",r,t,i,n,o)}else s.plugin.emit("comment.post.success",t,i,n,o)}).fail(function(e,n){var o=new error(n);o.code=255,s.plugin.emit("comment.post.error",o,t,n,e)})}),this.plugin.on("comment.post.success","system",function(t,e,n,o){s.plugin.emit("comment.post.done",null,t,e,n,o)}),this.plugin.on("comment.post.error","system",function(t,e,n,o,i){s.plugin.emit("comment.posterror",{jqxhr:i,msg:t.message,code:t.code},e),s.plugin.emit("comment.post.done",t,e,n,o,i)}),this.options.comment.usedefaultevents&&(this.plugin.on("comment.reply.start",t,function(t){this.$("#inprevid").val(t),this.$("#cancel-reply").show().bind("click",function(){return s.plugin.emit("comment.reply.cancel"),s.$("#inprevid").val(0),s.$(this).hide(),window.location.hash="#comment",!1}),window.location.hash="#comment"}),this.plugin.on("comment.got",t,function(t,e,n,o){this.$("#ajaxcommentbegin").nextuntil("#ajaxcommentend").remove(),this.$("#ajaxcommentbegin").after(e)}),this.plugin.on("comment.post.start",t,function(){var t=s.$("#inpid").parent("form").find(":submit");t.data("orig",t.val()).val("waiting...").attr("disabled","disabled").addclass("loading")}),this.plugin.on("comment.post.done",t,function(t){var e=s.$("#inpid").parent("form").find(":submit");e.removeclass("loading").removeattr("disabled"),e.data("orig")&&e.val(e.data("orig"))}),this.plugin.on("comment.post.success",t,function(t,e,n,o){"0"===t.replyid.tostring()?this.$(e.data.html).insertafter("#ajaxcommentbegin"):this.$(e.data.html).insertafter("#ajaxcomment"+t.replyid),location.hash="#cmt"+e.data.id,this.$("#txaarticle").val(""),this.userinfo.readfromhtml()}),this.plugin.on("comment.post.error",t,function(t){throw alert(t.message),new error("error - "+t.message)})),this};o.prototype._plugins={};var i=function(o){o.utils={},o.utils.getfromindex=function(t,e){for(var n=[],o=t;o=0&&(console.warn("interface '"+t+"' is deprecated in zbp 1.6, please update your plugin or theme!"),!0)},i.prototype.bind=i.prototype.on=i.prototype.addlistener=function(t,e,i){return this.checkisinterfacedeprecated(t)&&n[t]&&(t=n[t]),void 0===o._plugins[t]&&(o._plugins[t]={}),o._plugins[t][e]=i,o},i.prototype.unbind=i.prototype.removelistener=function(e,i){return i||(i=""),this.checkisinterfacedeprecated(e)&&"system"===i&&(i=t,n[e]&&(e=n[e])),""===i?o._plugins[e]={}:o._plugins[e]&&(o._plugins[e][i]=null,delete o._plugins[e][i]),o},i.prototype.emit=function(t){var e=o.utils.getfromindex(1,arguments);for(var n in o._plugins[t])o._plugins[t][n].apply(o,e);return o},i.prototype.listenercount=function(t){return object.keys(o._plugins[t])},o.plugin=new i;var r=function(){};r.prototype.get=function(t){var e=document.cookie.match(new regexp("(^| )"+t+"=([^;]*)(;|$)"));return e?unescape(e[2]):null},r.prototype.set=function(t,e,n){var i=new date;return n&&i.settime(i.gettime()+parseint(24*n*60*60*1e3)),document.cookie=t+"="+escape(e)+"; "+(n?"expires="+i.togmtstring()+"; ":"")+"path="+o.options.cookiepath,o},o.cookie=new r;var s=function(){};s.prototype.output=function(){return o.plugin.emit("userinfo.output"),o},s.prototype.save=function(){return o.plugin.emit("userinfo.save"),o},s.prototype.savefromhtml=s.prototype.readfromhtml=function(){return o.plugin.emit("userinfo.readfromhtml"),o},o.userinfo=new s;var u=function(){};u.prototype.get=function(t,e){o.plugin.emit("comment.get",t,e)},u.prototype.reply=function(t){o.plugin.emit("comment.reply.start",t)},u.prototype.post=function(t){t=t||{};try{o.plugin.emit("comment.post.start",t)}catch(t){console.error(t)}return!1},o.comment=new u};"function"==typeof define&&define.amd?define("zbp",[],function(){return o}):"function"==typeof define&&define.cmd?define("zbp",[],function(t,e,n){n.exports=o}):"undefined"!=typeof module?module.exports=o:window.zbp=o})();