\addons\theme\stv1\_static\js\module.js
里面定义了一个类module
,然后赋值给了window.M
。
代码地址:https://gist.github.com/zhoumengkang/e713d2591d7e3c8dc6b2
别人说:通过元素的
event-node
或者model-node
添加事件监听,加快js运行速度。我想,可能是因为绕过了jquery的庞大的选择器系统,速度可能有所提升吧!但是代码我还是没看懂。
然后在页面就可以通过M.addModelFns()
或者M.addEventFns()
方法来添加自定义监听事件了。例如微吧里面:
<a href="javascript:void(0);" event-node="do_weiba_reply" event-args="" weiba_id="1" post_id="1" post_uid="1" feed_id="1" addtoend="0" to_reply_id="0" to_uid="0"><span>回复</span></a>
M.addModelFns({ do_weiba_reply:{ click:function(){ } } })
下面是针对ThinkSNS的弹出框的效果(http://zhoumengkang.com/298.html)的详细分析:
\addons\theme\stv1\_static\js\module.common.js
是ThinkSNS全站公用的Js监听文件,里面就定义了“分享”事件
<a event-args="sid=1&stable=weiba_post&curtable=feed&curid=1&initHTML=&appname=weiba&cancomment=1&feedtype=weiba_post" href="javascript:void(0)" event-node="share">转发到微博</a>
M.addEventFns({ share:{//分享操作 click : function(){ var attrs =M.getEventArgs(this); var sid = attrs.sid; var stable = attrs.stable; var initHTML = attrs.initHTML; var curtable =attrs.curtable; var curid = attrs.curid; var appname = attrs.appname; var cancomment = attrs.cancomment; var is_repost = attrs.is_repost; share(sid,stable,initHTML,curid,curtable,appname,cancomment,is_repost); return false; } } }) //分享 var share=function(sid,stable,initHTML,curid,curtable,appname,cancomment,is_repost){ if("undefined" == typeof(cancomment)){ cancomment = 0; } var url = U('public/Share/index')+'&sid='+sid+'&stable='+stable+'&curid='+curid+'&curtable='+curtable+'&appname='+appname+'&initHTML='+initHTML+'&cancomment='+cancomment+'&is_repost='+is_repost; if($('#tsbox').length>0){ return false; } ui.box.load(url,L('PUBLIC_SHARE'),function(){ $('#at-view').hide(); var share_id="feed"+curid; window.location.hash=share_id; }); return false; };