发布主题,然后由用户订阅的机制就是一个典型的观察者模式 dojo.event.disconnect
解除绑定,调用参数与 connect 一致,即可解除之前的绑定操作 summary: // // // //
Takes the same parameters as dojo.event.connect() but destroys an existing connection instead of building a new one. For multiple identical connections, multiple disconnect() calls will unroll one each time it's called.
这里所说的基础对象和方法是指的不 Require 任何包就能够调用的对象和方法 匿名函数
在开始前,我想介绍一下 js 里的匿名函数,这个在阅读 dojo 的源代码的时候,会发现到处都有匿名 函数
;(function(){ alert(123); })();
//前面的分号是一个空语句,是可以不要的
匿名函数。一个匿名函数就是一个没有名字的函数。
你可以认为他们是一次性函数。当你只需要用一次某个函数时,他们就特别有用。通过使用匿名函数, 没有必要把函数一直放在内存中,所以使用匿名函数更加有效率。
当然你也可以根本不定义函数,但是使用匿名函数可以把你的代码分段,就像 C#中的#region 一样 dojo.event.MethodInvocation
function(/*dojo.event.MethodJoinPoint*/join_point, /*Object*/obj, /*Array*/args){ // summary: // //
a class the models the call into a function. This is used under the covers for all method invocations on both ends of a // //
connect()‐wrapped function dispatch. This allows us to \calls, such as in the case of around advice. // join_point: //
// obj: //
// args: //
a dojo.event.MethodJoinPoint object that represents a connection the scope the call will execute in
an array of parameters that will get passed to the callee dojo.event.MethodInvocation.protot ype.proceed // summary: // //
proceed with the method call that's represented by this invocation object
模块:dojo.event.browser dojo.event.browser.clean function(/*DOMNode*/node) summary: // // //
// node:
//
removes native event handlers so that destruction of the node will not leak memory. On most browsers this is a no‐op, but it's critical for manual node removal on IE.
A DOM node. All of it's children will also be cleaned dojo.event.browser.addClobberNode function(/*DOMNode*/node) summary: //
// node: //
register the passed node to support event stripping A DOM node
dojo.event.browser.addClobberNodeA ttrs
function(/*DOMNode*/node, /*Array*/props) summary: //
// node: //
// props: //
register the passed node to support event stripping A DOM node to stip properties from later A list of propeties to strip from the node dojo.event.browser.removeListener function( /*DOMNode*/ node, /*String*/ evtName, /*Function*/fp, /*Boolean*/ capture) // summary: //
clobbers the listener from the node // evtName: //
// node: //
// fp: //
the name of the handler to remove the function from DOM node to attach the event to the function to register // capture: //
Optional. should this listener prevent propigation? 清除监听器(这个方法似乎是无效的) dojo.event.browser.addListener function(/*DOMNode*/node, /*String*/evtName, /*Boolean*/dontFix){ // summary: //
adds a listener to the node // evtName: // //
// node: //
// fp: //
/*Function*/fp, /*Boolean*/capture, the name of the handler to add the listener to can be either of the form \DOM node to attach the event to the function to register // capture: //
Optional. Should this listener prevent propigation? // dontFix: // // //
增加监听器
Usage Example:
function listener() {
alert( \}
Optional. Should we avoid registering a new closure around the listener to enable fixEvent for dispatch of the registered function?
dojo.event.browser.addListener(document, 'mousedown', listener); //事件名称可以加上\, 也可以没有\
dojo.event.browser.addListener(document, 'onmousedown', listener, true); //capture 为真表 示不受上层元素的事件控制 dojo.event.browser.isEvent function(/*Object*/obj){ // summary: //
Tries to determine whether or not the object is a DOM event.
// FIXME: event detection hack ... could test for additional attributes // if necessary
判断指定对象是否为 event 对象 Usage Example:
dojo.event.browser.isEvent(dojo.event.browser.currentEvent); //当 dojo.event.browser.currentEvent 不为 null 时返回 t rue
dojo.event.browser.callListener
function(/*Function*/listener, /*DOMNode*/curTarget){ // summary: // //
calls the specified listener in the context of the passed node with the current DOM event object as the only parameter // listener: //
the function to call // curTarget: //
调用监听器
Usage Example:
the Node to call the function in the scope of
dojo.event.browser.callListener(listener, document); dojo.event.browser.fixEvent
function(/*Event*/evt, /*DOMNode*/sender){ // summary: // //
normalizes properties on the event object including event bubbling methods, keystroke normalization, and x/y positions
// evt: the native event object
// sender: the node to treat as \dojo.event.browser.stopEvent function(/*Event*/evt){ // summary: // //
prevents propigation and clobbers the default action of the passed event
// evt: Optional for IE. The native event object. dojo.event.browser.stopPropagation 阻止 Event 传播 Usage Example:
dojo.event.browser.stopPropagation(); dojo.event.browser.preventDefault 将当前事件的返回值设置为 false Usage Example:
dojo.event.browser.preventDefault(); dojo.event.browser.keys 键定义:
KEY_BACKSPACE: 8, KEY_TAB: 9, KEY_ENTER: 13, KEY_SHIFT: 16, KEY_CTRL: 17, KEY_ALT: 18, KEY_PAUSE: 19,
KEY_CAPS_LOCK: 20, KEY_ESCAPE: 27, KEY_SPACE: 32, KEY_PAGE_UP: 33, KEY_PAGE_DOWN: 34, KEY_END: 35, KEY_HOME: 36,
KEY_LEFT_ARROW: 37, KEY_UP_ARROW: 38, KEY_RIGHT_ARROW: 39, KEY_DOWN_ARROW: 40, KEY_INSERT: 45, KEY_DELETE: 46,
KEY_LEFT_WINDOW: 91, KEY_RIGHT_WINDOW: 92, KEY_SELECT: 93, KEY_F1: 112, KEY_F2: 113, KEY_F3: 114, KEY_F4: 115, KEY_F5: 116, KEY_F6: 117, KEY_F7: 118, KEY_F8: 119, KEY_F9: 120, KEY_F10: 121, KEY_F11: 122, KEY_F12: 123,
KEY_NUM_LOCK: 144, KEY_SCROLL_LOCK: 145
dojo.event.browser.currentEvent 最近一次的 Event,其属性包括:
altKey //检查 alt 键的状态,当 alt 键按下时,值为 true button //检查按下的鼠标键,0 没按键,1 按左键,2 按右键,3 按左右键,4 按中间键,5 按左键和中间键,6 按右 键和中间键,7 按所有的键
//这个属性仅用于 onmousedown, onmouseup, 和 onmousemove 事件。对其他事件,不管鼠标状态如何,都返回 0(比如 onclick)
clientX //返回鼠标在窗口客户区域中的 X 坐标 clientY //返回鼠标在窗口客户区域中的 Y 坐标
ctrlKey //检查 ctrl 键的状态,当 ctrl 键按下时,值为 true fromElement //检测 onmouseover 和 onmouseout 事件发生时,鼠标所离开的元素
keyCode //检测键盘事件相对应的内码,仅当 type 为 keydown,keyup,keypress 时才有效 offsetX //检查相对于触发事件的对象,鼠标位置的水平坐标 offsetY //检查相对于触发事件的对象,鼠标位置的垂直坐标
propertyName //设置或返回元素的变化了的属性的名称,你可以通过使用 onpropertychange 事件,得到 propertyNa me 的值
screenX //检测鼠标相对于用户屏幕的水平位置 screenY //检测鼠标相对于用户屏幕的垂直位置
shiftKey //检查 shift 键的状态,当 shift 键按下时,值为 true srcElement //返回触发事件的元素
srcFilter //返回触发 onfilterchange 事件的滤镜 toElement //检测 onmouseover 和 onmouseout 事件发生时,鼠标所进入的元素 type //返回没有“on”作为前缀的事件名,比如 click, mousedown
x //返回鼠标相对于 css 属性中有 position 属性的上级元素的 x 轴坐标。如果没有 css 属性中有 position 属性的上级元
素,默认以 BODY 元素作为参考对象
y //返回鼠标相对于 css 属性中有 position 属性的上级元素的 y 轴坐标。如果没有 css 属性中有 position 属性的上级元
素,默认以 BODY 元素作为参考对象 target //同 srcElement currentTarget
layerX //同 offsetX layerY //同 offsetY
pageX //无水平滚动条的情况下与 clientX 同 pageY //无水平滚动条的情况下与 clientY 同 relatedTarget // 仅当 type 为 mouseover,mouseout 时才有效
keys //与 dojo.event.browser.keys 相同,仅当 type 为 keydown,keyup,keypress 时才有效 charCode //键值,仅当 type 为 keypress 时才有效 dojo.byId
非常有用的一个方法,与 prototype.js 的著名的$一样
似乎以前的版本还有 dojo.byIdArray, 不过最新的版本已经找不到这个函数了(除了 src\\compat\\0.2.2.js)
如果有多个元素具有指定的 id,则返回的是一个集合 Usage Example:
dojo.byId(\
dojo.byId(\
dojo.byId(document.getElementById(\dojo.version
dojo 的版本,可以取得 major, minor, patch, flag 和 revision
这个对象没什么太大用处,除非你要根据 dojo 的版本选择执行你的代码 dojo.raise
抛出一个异常 dojo.errorToString 将异常转换为字符串 Usage Example: try {
dojo.raise(\打印失败\文件不存在\ }