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