~bcsaller/juju-gui/update-reductions

« back to all changes in this revision

Viewing changes to lib/yui/docs/event/outside.html

  • Committer: kapil.foss at gmail
  • Date: 2012-07-13 18:45:59 UTC
  • Revision ID: kapil.foss@gmail.com-20120713184559-2xl7be17egsrz0c9
reshape

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
<!DOCTYPE html>
2
 
<html lang="en">
3
 
<head>
4
 
    <meta charset="utf-8">
5
 
    <title>Outside Events</title>
6
 
    <link rel="stylesheet" href="http://fonts.googleapis.com/css?family=Maven+Pro:400,700">
7
 
    <link rel="stylesheet" href="../../build/cssgrids/grids-min.css">
8
 
    <link rel="stylesheet" href="../assets/css/main.css">
9
 
    <link rel="stylesheet" href="../assets/vendor/prettify/prettify-min.css">
10
 
    <script src="../../build/yui/yui-min.js"></script>
11
 
</head>
12
 
<body>
13
 
 
14
 
<div id="doc">
15
 
    <h1>Outside Events</h1>
16
 
 
17
 
    
18
 
        <a href="#toc" class="jump">Jump to Table of Contents</a>
19
 
    
20
 
 
21
 
    <div class="yui3-g">
22
 
        <div class="yui3-u-3-4">
23
 
            <div id="main">
24
 
                <div class="content"><div class="intro">
25
 
    <p>The <code>event-outside</code> module adds a <a href="predefined">suite of
26
 
    events</a> based on activity occuring <em>outside</em> the subscribed
27
 
    elements.  For example, the "clickoutside" event will fire only if a click
28
 
    occurred on an element <em>other than</em> the Node subscribed or one of
29
 
    its descendants.</p>
30
 
 
31
 
    <p>The module also adds a <code>Y.Event.defineOutside(...)</code> method to <a
32
 
    href="#defineoutside">create additional outside events</a>.</p>
33
 
 
34
 
    <p>This module was contributed by <a
35
 
    href="https://github.com/brettstimmerman">Brett Stimmerman</a>, inspired
36
 
    by <a href="http://benalman.com/projects/jquery-outside-events-plugin/">Ben
37
 
    Alman's Outside Events jQuery plugin</a>.</p>
38
 
</div>
39
 
 
40
 
<h2 id="not-me-those-other-elements">Not me. Those other elements</h2>
41
 
 
42
 
<p>It's a common UX pattern to close popups or trigger save or cancel actions when users do something in another area of a web page.  This family of events makes setting up that behavior easy.</p>
43
 
 
44
 
<pre class="code prettyprint">node.on(&#x27;clickoutside&#x27;, function () {
45
 
    this.hide(&#x27;fadeOut&#x27;);
46
 
});
47
 
 
48
 
survey.on(&#x27;keyupoutside&#x27;, heyYoureNotDoneYet);
49
 
 
50
 
&#x2F;&#x2F; hide the overlay if the page focus moves somewhere outside the overlay&#x27;s
51
 
&#x2F;&#x2F; content area.
52
 
overlay.get(&#x27;boundingBox&#x27;).on(&#x27;focusoutside&#x27;, overlay.hide, overlay);</pre>
53
 
 
54
 
 
55
 
<h2 id="how-they-work">How they work</h2>
56
 
 
57
 
<p>When an outside event subscription is made on an element, the actual
58
 
subscription created is a <code>document</code> level subscription for the corresponding
59
 
DOM event.  When a triggering event occurs on the page and bubbles up to the
60
 
<code>document</code>, its <code>e.target</code> is compared to the outside event subscriber. If the
61
 
event originated from an element outside the subscriber, the outside event
62
 
subscribers are executed.</p>
63
 
 
64
 
<p>An originating target is considered outside the subscriber if it is not the subscriber itself or any of the subscriber's descendants.</p>
65
 
 
66
 
<h2 id="predefined"><code>*outside</code></h2>
67
 
 
68
 
<p>The naming convention for outside events is <code><em>&lt;event&gt;</em>outside</code>.</p>
69
 
 
70
 
<p>The module creates the following events by default:</p>
71
 
 
72
 
<style>
73
 
#eventlist {
74
 
    list-style: none;
75
 
    margin: 0 0 0 1em;
76
 
    padding: 0;
77
 
}
78
 
#eventlist ul {
79
 
    list-style: none;
80
 
    margin-left: 0;
81
 
    margin-right: 2em;
82
 
    padding: 0;
83
 
}
84
 
</style>
85
 
<ul class="yui3-g" id="eventlist">
86
 
    <li class="yui3-u">
87
 
        <ul>
88
 
            <li><code><em>mousedown</em>outside</code></li>
89
 
            <li><code><em>mouseup</em>outside</code></li>
90
 
            <li><code><em>mouseover</em>outside</code></li>
91
 
            <li><code><em>mouseout</em>outside</code></li>
92
 
            <li><code><em>mousemove</em>outside</code></li>
93
 
        </ul>
94
 
    </li>
95
 
    <li class="yui3-u">
96
 
        <ul>
97
 
            <li><code><em>click</em>outside</code></li>
98
 
            <li><code><em>dblclick</em>outside</code></li>
99
 
            <li><code><em>keydown</em>outside</code></li>
100
 
            <li><code><em>keyup</em>outside</code></li>
101
 
            <li><code><em>keypress</em>outside</code></li>
102
 
        </ul>
103
 
    </li>
104
 
    <li class="yui3-u">
105
 
        <ul>
106
 
            <li><code><em>focus</em>outside</code></li>
107
 
            <li><code><em>blur</em>outside</code></li>
108
 
            <li><code><em>change</em>outside</code></li>
109
 
            <li><code><em>select</em>outside</code></li>
110
 
            <li><code><em>submit</em>outside</code></li>
111
 
        </ul>
112
 
    </li>
113
 
</ul>
114
 
 
115
 
<h2 id="defineoutside">Create more outside events</h2>
116
 
 
117
 
<p>Use the module's <code>Y.Event.defineOutside( triggeringEvent, [alternateName] )</code> method to create more outside
118
 
events.</p>
119
 
 
120
 
<pre class="code prettyprint">&#x2F;&#x2F; Create a &#x60;touchstartoutside&#x60; event
121
 
Y.Event.defineOutside(&#x27;touchstart&#x27;);
122
 
 
123
 
&#x2F;&#x2F; Create an outside event for another synthetic event and give it
124
 
&#x2F;&#x2F; a different name.
125
 
Y.Event.defineOutside(&#x27;tripleclick&#x27;, &#x27;omgletmeout&#x27;);
126
 
 
127
 
&#x2F;&#x2F; would have been tripleclickoutside
128
 
gooeymess.on(&#x27;omgletmeout&#x27;, okYouCanGo);</pre>
129
 
 
130
 
 
131
 
<h2 id="caveats">Caveats</h2>
132
 
 
133
 
<p>Outside events require DOM events to bubble to the <code>document</code> so the following caveats apply to their use:</p>
134
 
 
135
 
<ol>
136
 
    <li>
137
 
        Separate subscriptions for the triggering event added to any element
138
 
        below the <code>document</code> will execute before the outside event.
139
 
    </li>
140
 
    <li>
141
 
        If a subcriber from #1 calls <code>e.stopPropagation()</code>, the outside event
142
 
        won't fire.
143
 
    </li>
144
 
    <li>
145
 
        "outside" is determined by DOM hierarchy, not visual placement of an
146
 
        element, so if a child element of the outside subscriber is placed
147
 
        elsewhere on the page, clicking on that child will not trigger the
148
 
        outside event.
149
 
    </li>
150
 
    <li>
151
 
        Some DOM events do not bubble, and some (e.g. <code>submit</code> and <code>reset</code>)
152
 
        bubble only in certain browsers.  Unless a workaround synthetic event
153
 
        such as <a href="focus.html"><code>event-focus</code></a> is in place,
154
 
        outside versions of these events won't fire.
155
 
    </li>
156
 
</ol>
157
 
</div>
158
 
            </div>
159
 
        </div>
160
 
 
161
 
        <div class="yui3-u-1-4">
162
 
            <div class="sidebar">
163
 
                
164
 
                    <div id="toc" class="sidebox">
165
 
                        <div class="hd">
166
 
                            <h2 class="no-toc">Table of Contents</h2>
167
 
                        </div>
168
 
 
169
 
                        <div class="bd">
170
 
                            <ul class="toc">
171
 
<li>
172
 
<a href="#not-me-those-other-elements">Not me. Those other elements</a>
173
 
</li>
174
 
<li>
175
 
<a href="#how-they-work">How they work</a>
176
 
</li>
177
 
<li>
178
 
<a href="#predefined"><code>*outside</code></a>
179
 
</li>
180
 
<li>
181
 
<a href="#defineoutside">Create more outside events</a>
182
 
</li>
183
 
<li>
184
 
<a href="#caveats">Caveats</a>
185
 
</li>
186
 
</ul>
187
 
                        </div>
188
 
                    </div>
189
 
                
190
 
 
191
 
                
192
 
                    <div class="sidebox">
193
 
                        <div class="hd">
194
 
                            <h2 class="no-toc">Examples</h2>
195
 
                        </div>
196
 
 
197
 
                        <div class="bd">
198
 
                            <ul class="examples">
199
 
                                
200
 
                                    
201
 
                                        <li data-description="Use the Event Utility to attach simple DOM event handlers.">
202
 
                                            <a href="basic-example.html">Simple DOM Events</a>
203
 
                                        </li>
204
 
                                    
205
 
                                
206
 
                                    
207
 
                                        <li data-description="Using the synthetic event API to create a DOM event that fires in response to arrow keys being pressed.">
208
 
                                            <a href="synth-example.html">Creating an Arrow Event for DOM Subscription</a>
209
 
                                        </li>
210
 
                                    
211
 
                                
212
 
                                    
213
 
                                        <li data-description="Supporting cross-device swipe gestures, using the event-move gesture events">
214
 
                                            <a href="swipe-example.html">Supporting A Swipe Left Gesture</a>
215
 
                                        </li>
216
 
                                    
217
 
                                
218
 
                                    
219
 
                                
220
 
                                    
221
 
                                
222
 
                                    
223
 
                                
224
 
                                    
225
 
                                
226
 
                                    
227
 
                                
228
 
                            </ul>
229
 
                        </div>
230
 
                    </div>
231
 
                
232
 
 
233
 
                
234
 
                    <div class="sidebox">
235
 
                        <div class="hd">
236
 
                            <h2 class="no-toc">Examples That Use This Component</h2>
237
 
                        </div>
238
 
 
239
 
                        <div class="bd">
240
 
                            <ul class="examples">
241
 
                                
242
 
                                    
243
 
                                
244
 
                                    
245
 
                                
246
 
                                    
247
 
                                
248
 
                                    
249
 
                                        <li data-description="Shows how to extend the base widget class, to create your own Widgets.">
250
 
                                            <a href="../widget/widget-extend.html">Extending the Base Widget Class</a>
251
 
                                        </li>
252
 
                                    
253
 
                                
254
 
                                    
255
 
                                        <li data-description="Creating an accessible menu button using the Focus Manager Node Plugin, Event&#x27;s delegation support and mouseenter event, along with the Overlay widget and Node&#x27;s support for the WAI-ARIA Roles and States.">
256
 
                                            <a href="../node-focusmanager/node-focusmanager-3.html">Accessible Menu Button</a>
257
 
                                        </li>
258
 
                                    
259
 
                                
260
 
                                    
261
 
                                        <li data-description="Use IO to request data over HTTP.">
262
 
                                            <a href="../io/get.html">HTTP GET to request data</a>
263
 
                                        </li>
264
 
                                    
265
 
                                
266
 
                                    
267
 
                                        <li data-description="Example Photo Browser application.">
268
 
                                            <a href="../dd/photo-browser.html">Photo Browser</a>
269
 
                                        </li>
270
 
                                    
271
 
                                
272
 
                                    
273
 
                                        <li data-description="Portal style example using Drag &amp; Drop Event Bubbling and Animation.">
274
 
                                            <a href="../dd/portal-drag.html">Portal Style Example</a>
275
 
                                        </li>
276
 
                                    
277
 
                                
278
 
                            </ul>
279
 
                        </div>
280
 
                    </div>
281
 
                
282
 
            </div>
283
 
        </div>
284
 
    </div>
285
 
</div>
286
 
 
287
 
<script src="../assets/vendor/prettify/prettify-min.js"></script>
288
 
<script>prettyPrint();</script>
289
 
 
290
 
</body>
291
 
</html>