Changeset 750
- Timestamp:
- 04/24/06 23:50:04 (2 years ago)
- Files:
-
- mochikit/trunk/doc/html/MochiKit/Signal.html (modified) (8 diffs)
- mochikit/trunk/doc/rst/MochiKit/Signal.rst (modified) (9 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
mochikit/trunk/doc/html/MochiKit/Signal.html
r742 r750 73 73 <p>This module takes care of all the hard work—figuring out which event 74 74 model to use, trying to retrieve the event object, and handling your own 75 internal events, as well as cleanup when the page is unloaded to handleIE's75 internal events, as well as cleanup when the page is unloaded to clean up IE's 76 76 nasty memory leakage.</p> 77 <p>This event system is largely based on Qt's signal/slot system. You should read78 more on how that is handled and also how it is used in model/view programming 79 at:<a class="reference" href="http://doc.trolltech.com/">http://doc.trolltech.com/</a></p>77 <p>This event system is largely based on Qt's signal/slot system. Read more on 78 how that is handled and also how it is used in model/view programming at: 79 <a class="reference" href="http://doc.trolltech.com/">http://doc.trolltech.com/</a></p> 80 80 </div> 81 81 <div class="section"> … … 90 90 <div class="section"> 91 91 <h2><a id="using-signal-for-dom-events" name="using-signal-for-dom-events">Using Signal for DOM Events</a></h2> 92 <p>When using MochiKit.Signal, you should not directly use the browser's native93 event handling for the same events. That means, no <tt class="docutils literal"><span class="pre">onclick="blah"</span></tt>, 94 no <tt class="docutils literal"><span class="pre">elem.attachEvent(...)</span></tt>, and certainly no <tt class="docutils literal"><span class="pre">elem.addEventListener(...)</span></tt>. 95 This also means that<a class="mochiref reference" href="DOM.html#fn-addtocallstack">MochiKit.DOM.addToCallStack</a> and92 <p>When using MochiKit.Signal, do not use the browser's native event API. 93 That means, no <tt class="docutils literal"><span class="pre">onclick="blah"</span></tt>, no <tt class="docutils literal"><span class="pre">elem.addEventListener(...)</span></tt>, and 94 certainly no <tt class="docutils literal"><span class="pre">elem.attachEvent(...)</span></tt>. This also means that 95 <a class="mochiref reference" href="DOM.html#fn-addtocallstack">MochiKit.DOM.addToCallStack</a> and 96 96 <a class="mochiref reference" href="DOM.html#fn-addloadevent">MochiKit.DOM.addLoadEvent</a> should not be used in combination with 97 97 this module.</p> 98 <p>Signals for DOM objects are named with the 'on' prefix, e.g.:99 'onclick', 'onkeyup', etc.</p>100 <p>When the signal fires, your slot will be called with exactly one parameter,101 the customevent object.</p>98 <p>Signals for DOM objects are named with the <tt class="docutils literal"><span class="pre">on</span></tt> prefix, e.g.: <tt class="docutils literal"><span class="pre">onclick</span></tt>, 99 <tt class="docutils literal"><span class="pre">onkeyup</span></tt>, etc.</p> 100 <p>When the signal fires, your slot will be called with one parameter, the custom 101 event object.</p> 102 102 </div> 103 103 <div class="section"> … … 107 107 across all supported platforms and browsers, and provides many conveniences 108 108 not available even in a correct W3C implementation.</p> 109 <p>Here is a complete list of this object's methods:</p>110 <blockquote>111 <p>These are always generated:</p>112 <dl class="docutils">113 <dt>event():</dt>114 <dd>The native event produced by the browser. You should not need to115 access this.</dd>116 <dt>type():</dt>117 <dd>The event type: click, mouseover, keypress, etc. (Does not include118 the 'on' prefix.)</dd>119 <dt>target():</dt>120 <dd>The element that triggered the event.</dd>121 <dt>modifier().alt, modifier().ctrl, modifier().meta, modifier().shift:</dt>122 <dd><tt class="docutils literal"><span class="pre">true</span></tt> if pressed, <tt class="docutils literal"><span class="pre">false</span></tt> if not. <tt class="docutils literal"><span class="pre">modifier().meta</span></tt> will be123 <tt class="docutils literal"><span class="pre">false</span></tt> instead of <tt class="docutils literal"><span class="pre">undefined</span></tt> in IE.</dd>124 <dt>modifier().any:</dt>125 <dd><tt class="docutils literal"><span class="pre">true</span></tt> if any modifier is pressed, <tt class="docutils literal"><span class="pre">false</span></tt> if not.</dd>126 <dt>stopPropagation():</dt>127 <dd>Works like W3C's <tt class="docutils literal"><span class="pre">stopPropagation()</span></tt>.</dd>128 <dt>preventDefault():</dt>129 <dd>Works like W3C's <tt class="docutils literal"><span class="pre">preventDefault()</span></tt>.</dd>130 <dt>stop():</dt>131 <dd>Shortcut that calls <tt class="docutils literal"><span class="pre">stopPropagation()</span></tt> and <tt class="docutils literal"><span class="pre">preventDefault()</span></tt>.</dd>132 </dl>133 <p>You should use keydown and keyup to detect control characters,134 and keypressed to detect "printable" characters. key().code will be set to135 0 and key().string will be set to an empty string in a keypress handler if136 a user presses a control character like F1 or Escape. IE will not fire137 your keypressed handler when you press a control character like KEY_F1 or138 KEY_ESCAPE. In your keyup and keydown handlers, Signal will pass the139 keyboard code and a human-readable string like KEY_A or KEY_ARROW_DOWN or140 KEY_NUM_PAD_ASTERISK. See <tt class="docutils literal"><span class="pre">_specialKeys</span></tt> for a comprehensive list. These141 are generated for keydown and keyup events:</p>142 <dl class="docutils">143 <dt>key().code:</dt>144 <dd>contains the raw key code, such as 8 for backspace.</dd>145 <dt>key().string:</dt>146 <dd>contains a human readable string, such as 'KEY_BACKSPACE' or '!'.147 The complete list is defined in MochiKit.Signal._specialKeys.</dd>148 </dl>149 <p>These are only generated for mouse*, click, dblclick, and contextmenu150 (contextmenu doesn't work in Opera):</p>151 <dl class="docutils">152 <dt>mouse().page.x, mouse().page.y:</dt>153 <dd>represents the cursor position relative to the HTML document.154 (Equivalent to pageX/Y in Safari, Mozilla, and Opera.)</dd>155 <dt>mouse().client.x, mouse().client.y:</dt>156 <dd>represents the cursor position relative to the visible portion of the157 HTML document. (Equivalent to clientX/Y on all browsers.)</dd>158 </dl>159 <p>These are only generated for mouseup, mousedown, click, and dblclick:</p>160 <dl class="docutils">161 <dt>mouse().button.left, mouse().button.right, mouse().button.middle:</dt>162 <dd><p class="first"><tt class="docutils literal"><span class="pre">true</span></tt> or <tt class="docutils literal"><span class="pre">false</span></tt>. Mac browsers don't report right click163 consistently. Firefox fires the click and sets modifier().ctrl to164 true, Opera fires the click and sets modifier().meta to true, and165 Safari doesn't fire the click (<a class="reference" href="http://bugzilla.opendarwin.org/show_bug.cgi?id=6595">Safari Bug 6595</a>).</p>166 <p>If you want a right click, I suggest that instead of looking for167 a right click, look for a contextmenu event.</p>168 <p class="last">Current versions of Safari won't fire a dblclick event when attached169 via <tt class="docutils literal"><span class="pre">connect()</span></tt> (<a class="reference" href="http://bugzilla.opendarwin.org/show_bug.cgi?id=7790">Safari Bug 7790</a>).</p>170 </dd>171 </dl>172 <p>This is generated on mouseover and mouseout:</p>173 <dl class="docutils">174 <dt>relatedTarget():</dt>175 <dd>the document element that the mouse has moved to.</dd>176 </dl>177 </blockquote>178 109 <p>If you find that you're accessing the native event for any reason, create a 179 110 <a class="reference" href="http://trac.mochikit.com/newticket">new ticket</a> and we'll look into normalizing the behavior you're looking for.</p> … … 184 115 by the Signal mechanism until it is disconnected via <a class="mochiref reference" href="#fn-disconnect">disconnect()</a> 185 116 or <a class="mochiref reference" href="#fn-disconnectall">disconnectAll()</a>.</p> 186 <p>Signal does not leak. It registers an 'onunload'event that disconnects all117 <p>Signal does not leak. It registers an <tt class="docutils literal"><span class="pre">onunload</span></tt> event that disconnects all 187 118 objects on the page when the browser leaves the page. However, memory usage 188 119 will grow during the page view for every connection made until it is 189 120 disconnected. Even if the DOM object is removed from the document, it 190 121 will still be referenced by Signal until it is explicitly disconnected.</p> 191 <p>In order to conserve memory during the page view, you should ensure to use 192 <a class="mochiref reference" href="#fn-disconnectall">disconnectAll()</a> any DOM elements that are about to be removed 193 from the document.</p> 122 <p>In order to conserve memory during the page view, <a class="mochiref reference" href="#fn-disconnectall">disconnectAll()</a> 123 any DOM elements that are about to be removed from the document.</p> 194 124 </div> 195 125 <div class="section"> … … 215 145 <h1><a id="api-reference" name="api-reference">API Reference</a></h1> 216 146 <div class="section"> 217 <h2><a id=" functions" name="functions">Functions</a></h2>147 <h2><a id="signal-api-reference" name="signal-api-reference">Signal API Reference</a></h2> 218 148 <p> 219 149 <a name="fn-connect"></a> … … 223 153 used to disconnect that signal.</p> 224 154 <p><tt class="docutils literal"><span class="pre">src</span></tt> is the object that has the signal. You may pass in a string, in 225 which case, it is interpreted as an id for an HTML Element.</p>155 which case, it is interpreted as an id for an HTML element.</p> 226 156 <p><tt class="docutils literal"><span class="pre">signal</span></tt> is a string that represents a signal name. If 'src' is an HTML 227 Element, Window, or the Document, then it can be one of the 'on-XYZ'228 events. You must include the 'on' prefix, and it must be all157 Element, <tt class="docutils literal"><span class="pre">window</span></tt>, or the <tt class="docutils literal"><span class="pre">document</span></tt>, then it can be one of the 158 'on-XYZ' events. You must include the 'on' prefix, and it must be all 229 159 lower-case.</p> 230 160 <p><tt class="docutils literal"><span class="pre">dest</span></tt> and <tt class="docutils literal"><span class="pre">func</span></tt> describe the slot, or the action to take when the … … 243 173 </ul> 244 174 </blockquote> 245 <p>No other combinations are allowed and should raise andexception.</p>175 <p>No other combinations are allowed and will raise an exception.</p> 246 176 <p>The return value can be passed to <a class="mochiref reference" href="#fn-disconnect">disconnect</a> to disconnect 247 177 the signal.</p> … … 262 192 <a class="mochiref reference" href="#fn-connect">connect()</a>.</blockquote> 263 193 </div> 194 <div class="section"> 195 <h2><a id="dom-event-api-reference" name="dom-event-api-reference">DOM Event API Reference</a></h2> 196 <dl class="docutils"> 197 <dt> 198 <a name="fn-event"></a> 199 <a class="mochidef reference" href="#fn-event">event()</a>:</dt> 200 <dd>The native event produced by the browser. You should not need to 201 access this.</dd> 202 <dt> 203 <a name="fn-type"></a> 204 <a class="mochidef reference" href="#fn-type">type()</a>:</dt> 205 <dd>Returns the event type (<tt class="docutils literal"><span class="pre">click</span></tt>, <tt class="docutils literal"><span class="pre">mouseover</span></tt>, <tt class="docutils literal"><span class="pre">keypress</span></tt>, etc.) as a 206 string. Does not include the <tt class="docutils literal"><span class="pre">on</span></tt> prefix.</dd> 207 <dt> 208 <a name="fn-target"></a> 209 <a class="mochidef reference" href="#fn-target">target()</a>:</dt> 210 <dd>Returns the element that triggered the event.</dd> 211 <dt> 212 <a name="fn-modifier"></a> 213 <a class="mochidef reference" href="#fn-modifier">modifier()</a>:</dt> 214 <dd>Returns <tt class="docutils literal"><span class="pre">{shift,</span> <span class="pre">ctrl,</span> <span class="pre">meta,</span> <span class="pre">alt,</span> <span class="pre">any}</span></tt>, where each property is <tt class="docutils literal"><span class="pre">true</span></tt> 215 if its respective modifier key was pressed, <tt class="docutils literal"><span class="pre">false</span></tt> otherwise. <tt class="docutils literal"><span class="pre">any</span></tt> 216 is <tt class="docutils literal"><span class="pre">true</span></tt> if any modifier is pressed, <tt class="docutils literal"><span class="pre">false</span></tt> otherwise.</dd> 217 <dt> 218 <a name="fn-stoppropagation"></a> 219 <a class="mochidef reference" href="#fn-stoppropagation">stopPropagation()</a>:</dt> 220 <dd>Works like W3C's <tt class="docutils literal"><span class="pre">stopPropagation()</span></tt>.</dd> 221 <dt> 222 <a name="fn-preventdefault"></a> 223 <a class="mochidef reference" href="#fn-preventdefault">preventDefault()</a>:</dt> 224 <dd>Works like W3C's <tt class="docutils literal"><span class="pre">preventDefault()</span></tt>.</dd> 225 <dt> 226 <a name="fn-stop"></a> 227 <a class="mochidef reference" href="#fn-stop">stop()</a>:</dt> 228 <dd>Shortcut that calls <tt class="docutils literal"><span class="pre">stopPropagation()</span></tt> and <tt class="docutils literal"><span class="pre">preventDefault()</span></tt>.</dd> 229 <dt> 230 <a name="fn-key"></a> 231 <a class="mochidef reference" href="#fn-key">key()</a>:</dt> 232 <dd><p class="first">Returns {code, string}.</p> 233 <p>Use <tt class="docutils literal"><span class="pre">onkeydown</span></tt> and <tt class="docutils literal"><span class="pre">onkeyup</span></tt> handlers to detect control characters 234 such as <tt class="docutils literal"><span class="pre">KEY_F1</span></tt>. Use the <tt class="docutils literal"><span class="pre">onkeypressed</span></tt> handler to detect "printable" 235 characters, such as <tt class="docutils literal"><span class="pre">é</span></tt>.</p> 236 <p>When a user presses F1, in <tt class="docutils literal"><span class="pre">onkeydown</span></tt> and <tt class="docutils literal"><span class="pre">onkeyup</span></tt> this method 237 returns <tt class="docutils literal"><span class="pre">{code:</span> <span class="pre">122,</span> <span class="pre">string:</span> <span class="pre">'KEY_F1'}</span></tt>. In <tt class="docutils literal"><span class="pre">onkeypress</span></tt>, it returns 238 <tt class="docutils literal"><span class="pre">{code:</span> <span class="pre">0,</span> <span class="pre">string:</span> <span class="pre">''}</span></tt>.</p> 239 <p>If a user presses Shift+2 on a US keyboard, this method returns <tt class="docutils literal"><span class="pre">{code:</span> 240 <span class="pre">50,</span> <span class="pre">string:</span> <span class="pre">'KEY_2'}</span></tt> in <tt class="docutils literal"><span class="pre">onkeydown</span></tt> and <tt class="docutils literal"><span class="pre">onkeyup</span></tt>. In 241 <tt class="docutils literal"><span class="pre">onkeypress</span></tt>, it returns <tt class="docutils literal"><span class="pre">{code:</span> <span class="pre">64,</span> <span class="pre">string:</span> <span class="pre">'@'}</span></tt>.</p> 242 <p class="last">See <tt class="docutils literal"><span class="pre">_specialKeys</span></tt> for a comprehensive list of control characters.</p> 243 </dd> 244 <dt> 245 <a name="fn-mouse"></a> 246 <a class="mochidef reference" href="#fn-mouse">mouse()</a>:</dt> 247 <dd><p class="first">Properties for <tt class="docutils literal"><span class="pre">onmouse*</span></tt>, <tt class="docutils literal"><span class="pre">onclick</span></tt>, <tt class="docutils literal"><span class="pre">ondblclick</span></tt>, and 248 <tt class="docutils literal"><span class="pre">oncontextmenu</span></tt> events. (<tt class="docutils literal"><span class="pre">contextmenu</span></tt> doesn't work in Opera).</p> 249 <blockquote> 250 <ul class="simple"> 251 <li><tt class="docutils literal"><span class="pre">page</span></tt> is a <a class="mochiref reference" href="DOM.html#fn-coordinates">MochiKit.DOM.Coordinates</a> object that 252 represents the cursor position relative to the HTML document. 253 Equivalent to <tt class="docutils literal"><span class="pre">pageX</span></tt> and <tt class="docutils literal"><span class="pre">pageY</span></tt> in Safari, Mozilla, and Opera.</li> 254 <li><tt class="docutils literal"><span class="pre">client</span></tt> is a <a class="mochiref reference" href="DOM.html#fn-coordinates">MochiKit.DOM.Coordinates</a> object that 255 represents the cursor position relative to the visible portion of 256 the HTML document. Equivalent to <tt class="docutils literal"><span class="pre">clientX</span></tt> and <tt class="docutils literal"><span class="pre">clientY</span></tt> on 257 all browsers.</li> 258 </ul> 259 </blockquote> 260 <p>Properties for <tt class="docutils literal"><span class="pre">onmouseup</span></tt>, <tt class="docutils literal"><span class="pre">onmousedown</span></tt>, <tt class="docutils literal"><span class="pre">onclick</span></tt>, and 261 <tt class="docutils literal"><span class="pre">ondblclick</span></tt>:</p> 262 <blockquote> 263 <ul class="simple"> 264 <li><tt class="docutils literal"><span class="pre">mouse().button</span></tt> returns {left, right, middle} where each 265 property is <tt class="docutils literal"><span class="pre">true</span></tt> if the mouse button was pressed, <tt class="docutils literal"><span class="pre">false</span></tt> 266 otherwise.</li> 267 </ul> 268 </blockquote> 269 <p>Mac browsers don't report right click consistently. Firefox fires the 270 click and sets <tt class="docutils literal"><span class="pre">modifier().ctrl</span></tt> to true, Opera fires the click and sets 271 <tt class="docutils literal"><span class="pre">modifier().meta</span></tt> to <tt class="docutils literal"><span class="pre">true</span></tt>, and Safari doesn't fire the click 272 (<a class="reference" href="http://bugzilla.opendarwin.org/show_bug.cgi?id=6595">Safari Bug 6595</a>).</p> 273 <p>If you want a right click, we suggest that instead of looking for a right 274 click, look for a <tt class="docutils literal"><span class="pre">contextmenu</span></tt> event.</p> 275 <p class="last">Current versions of Safari won't fire a <tt class="docutils literal"><span class="pre">dblclick</span></tt> event when attached 276 via <tt class="docutils literal"><span class="pre">connect()</span></tt> (<a class="reference" href="http://bugzilla.opendarwin.org/show_bug.cgi?id=7790">Safari Bug 7790</a>).</p> 277 </dd> 278 <dt> 279 <a name="fn-relatedtarget"></a> 280 <a class="mochidef reference" href="#fn-relatedtarget">relatedTarget()</a>:</dt> 281 <dd>This is generated on <tt class="docutils literal"><span class="pre">mouseover</span></tt> and <tt class="docutils literal"><span class="pre">mouseout</span></tt>. Returns the document 282 element that the mouse has moved to.</dd> 283 </dl> 284 </div> 264 285 </div> 265 286 <div class="section"> mochikit/trunk/doc/rst/MochiKit/Signal.rst
r742 r750 68 68 This module takes care of all the hard work |---| figuring out which event 69 69 model to use, trying to retrieve the event object, and handling your own 70 internal events, as well as cleanup when the page is unloaded to handleIE's70 internal events, as well as cleanup when the page is unloaded to clean up IE's 71 71 nasty memory leakage. 72 72 73 This event system is largely based on Qt's signal/slot system. You should read74 more on how that is handled and also how it is used in model/view programming 75 at:http://doc.trolltech.com/73 This event system is largely based on Qt's signal/slot system. Read more on 74 how that is handled and also how it is used in model/view programming at: 75 http://doc.trolltech.com/ 76 76 77 77 … … 89 89 --------------------------- 90 90 91 When using MochiKit.Signal, you should not directly use the browser's native92 event handling for the same events. That means, no ``onclick="blah"``, 93 no ``elem.attachEvent(...)``, and certainly no ``elem.addEventListener(...)``. 94 This also means that:mochiref:`MochiKit.DOM.addToCallStack` and91 When using MochiKit.Signal, do not use the browser's native event API. 92 That means, no ``onclick="blah"``, no ``elem.addEventListener(...)``, and 93 certainly no ``elem.attachEvent(...)``. This also means that 94 :mochiref:`MochiKit.DOM.addToCallStack` and 95 95 :mochiref:`MochiKit.DOM.addLoadEvent` should not be used in combination with 96 96 this module. 97 97 98 Signals for DOM objects are named with the 'on' prefix, e.g.:99 'onclick', 'onkeyup', etc.100 101 When the signal fires, your slot will be called with exactly one parameter,102 the customevent object.98 Signals for DOM objects are named with the ``on`` prefix, e.g.: ``onclick``, 99 ``onkeyup``, etc. 100 101 When the signal fires, your slot will be called with one parameter, the custom 102 event object. 103 103 104 104 … … 111 111 not available even in a correct W3C implementation. 112 112 113 Here is a complete list of this object's methods:114 115 These are always generated:116 117 event():118 The native event produced by the browser. You should not need to119 access this.120 121 type():122 The event type: click, mouseover, keypress, etc. (Does not include123 the 'on' prefix.)124 125 target():126 The element that triggered the event.127 128 modifier().alt, modifier().ctrl, modifier().meta, modifier().shift:129 ``true`` if pressed, ``false`` if not. ``modifier().meta`` will be130 ``false`` instead of ``undefined`` in IE.131 132 modifier().any:133 ``true`` if any modifier is pressed, ``false`` if not.134 135 stopPropagation():136 Works like W3C's ``stopPropagation()``.137 138 preventDefault():139 Works like W3C's ``preventDefault()``.140 141 stop():142 Shortcut that calls ``stopPropagation()`` and ``preventDefault()``.143 144 You should use keydown and keyup to detect control characters,145 and keypressed to detect "printable" characters. key().code will be set to146 0 and key().string will be set to an empty string in a keypress handler if147 a user presses a control character like F1 or Escape. IE will not fire148 your keypressed handler when you press a control character like KEY_F1 or149 KEY_ESCAPE. In your keyup and keydown handlers, Signal will pass the150 keyboard code and a human-readable string like KEY_A or KEY_ARROW_DOWN or151 KEY_NUM_PAD_ASTERISK. See ``_specialKeys`` for a comprehensive list. These152 are generated for keydown and keyup events:153 154 key().code:155 contains the raw key code, such as 8 for backspace.156 157 key().string:158 contains a human readable string, such as 'KEY_BACKSPACE' or '!'.159 The complete list is defined in MochiKit.Signal._specialKeys.160 161 These are only generated for mouse*, click, dblclick, and contextmenu162 (contextmenu doesn't work in Opera):163 164 mouse().page.x, mouse().page.y:165 represents the cursor position relative to the HTML document.166 (Equivalent to pageX/Y in Safari, Mozilla, and Opera.)167 168 mouse().client.x, mouse().client.y:169 represents the cursor position relative to the visible portion of the170 HTML document. (Equivalent to clientX/Y on all browsers.)171 172 These are only generated for mouseup, mousedown, click, and dblclick:173 174 mouse().button.left, mouse().button.right, mouse().button.middle:175 ``true`` or ``false``. Mac browsers don't report right click176 consistently. Firefox fires the click and sets modifier().ctrl to177 true, Opera fires the click and sets modifier().meta to true, and178 Safari doesn't fire the click (`Safari Bug 6595`_).179 180 If you want a right click, I suggest that instead of looking for181 a right click, look for a contextmenu event.182 183 Current versions of Safari won't fire a dblclick event when attached184 via ``connect()`` (`Safari Bug 7790`_).185 186 This is generated on mouseover and mouseout:187 188 relatedTarget():189 the document element that the mouse has moved to.190 191 113 If you find that you're accessing the native event for any reason, create a 192 114 `new ticket`_ and we'll look into normalizing the behavior you're looking for. … … 204 126 or :mochiref:`disconnectAll()`. 205 127 206 Signal does not leak. It registers an 'onunload'event that disconnects all128 Signal does not leak. It registers an ``onunload`` event that disconnects all 207 129 objects on the page when the browser leaves the page. However, memory usage 208 130 will grow during the page view for every connection made until it is … … 210 132 will still be referenced by Signal until it is explicitly disconnected. 211 133 212 In order to conserve memory during the page view, you should ensure to use 213 :mochiref:`disconnectAll()` any DOM elements that are about to be removed 214 from the document. 134 In order to conserve memory during the page view, :mochiref:`disconnectAll()` 135 any DOM elements that are about to be removed from the document. 215 136 216 137 … … 240 161 ============= 241 162 242 Functions 243 --------- 163 164 Signal API Reference 165 -------------------- 244 166 245 167 :mochidef:`connect(src, signal, dest[, func])`: … … 249 171 250 172 ``src`` is the object that has the signal. You may pass in a string, in 251 which case, it is interpreted as an id for an HTML Element.173 which case, it is interpreted as an id for an HTML element. 252 174 253 175 ``signal`` is a string that represents a signal name. If 'src' is an HTML 254 Element, Window, or the Document, then it can be one of the 'on-XYZ'255 events. You must include the 'on' prefix, and it must be all176 Element, ``window``, or the ``document``, then it can be one of the 177 'on-XYZ' events. You must include the 'on' prefix, and it must be all 256 178 lower-case. 257 179 … … 271 193 signalled. 272 194 273 No other combinations are allowed and should raise andexception.195 No other combinations are allowed and will raise an exception. 274 196 275 197 The return value can be passed to :mochiref:`disconnect` to disconnect … … 289 211 the connected slots. ``src`` and ``signal`` are the same as for 290 212 :mochiref:`connect()`. 213 214 215 DOM Event API Reference 216 ----------------------- 217 218 :mochidef:`event()`: 219 The native event produced by the browser. You should not need to 220 access this. 221 222 :mochidef:`type()`: 223 Returns the event type (``click``, ``mouseover``, ``keypress``, etc.) as a 224 string. Does not include the ``on`` prefix. 225 226 :mochidef:`target()`: 227 Returns the element that triggered the event. 228 229 :mochidef:`modifier()`: 230 Returns ``{shift, ctrl, meta, alt, any}``, where each property is ``true`` 231 if its respective modifier key was pressed, ``false`` otherwise. ``any`` 232 is ``true`` if any modifier is pressed, ``false`` otherwise. 233 234 :mochidef:`stopPropagation()`: 235 Works like W3C's ``stopPropagation()``. 236 237 :mochidef:`preventDefault()`: 238 Works like W3C's ``preventDefault()``. 239 240 :mochidef:`stop()`: 241 Shortcut that calls ``stopPropagation()`` and ``preventDefault()``. 242 243 :mochidef:`key()`: 244 Returns {code, string}. 245 246 Use ``onkeydown`` and ``onkeyup`` handlers to detect control characters 247 such as ``KEY_F1``. Use the ``onkeypressed`` handler to detect "printable" 248 characters, such as ``é``. 249 250 When a user presses F1, in ``onkeydown`` and ``onkeyup`` this method 251 returns ``{code: 122, string: 'KEY_F1'}``. In ``onkeypress``, it returns 252 ``{code: 0, string: ''}``. 253 254 If a user presses Shift+2 on a US keyboard, this method returns ``{code: 255 50, string: 'KEY_2'}`` in ``onkeydown`` and ``onkeyup``. In 256 ``onkeypress``, it returns ``{code: 64, string: '@'}``. 257 258 See ``_specialKeys`` for a comprehensive list of control characters. 259 260 :mochidef:`mouse()`: 261 Properties for ``onmouse*``, ``onclick``, ``ondblclick``, and 262 ``oncontextmenu`` events. (``contextmenu`` doesn't work in Opera). 263 264 - ``page`` is a :mochiref:`MochiKit.DOM.Coordinates` object that 265 represents the cursor position relative to the HTML document. 266 Equivalent to ``pageX`` and ``pageY`` in Safari, Mozilla, and Opera. 267 268 - ``client`` is a :mochiref:`MochiKit.DOM.Coordinates` object that 269 represents the cursor position relative to the visible portion of 270 the HTML document. Equivalent to ``clientX`` and ``clientY`` on 271 all browsers. 272 273 Properties for ``onmouseup``, ``onmousedown``, ``onclick``, and 274 ``ondblclick``: 275 276 - ``mouse().button`` returns {left, right, middle} where each 277 property is ``true`` if the mouse button was pressed, ``false`` 278 otherwise. 279 280 Mac browsers don't report right click consistently. Firefox fires the 281 click and sets ``modifier().ctrl`` to true, Opera fires the click and sets 282 ``modifier().meta`` to ``true``, and Safari doesn't fire the click 283 (`Safari Bug 6595`_). 284 285 If you want a right click, we suggest that instead of looking for a right 286 click, look for a ``contextmenu`` event. 287 288 Current versions of Safari won't fire a ``dblclick`` event when attached 289 via ``connect()`` (`Safari Bug 7790`_). 290 291 292 :mochidef:`relatedTarget()`: 293 This is generated on ``mouseover`` and ``mouseout``. Returns the document 294 element that the mouse has moved to. 291 295 292 296
