UNPKG

31.6 kBHTMLView Raw
1<!DOCTYPE html>
2
3<html lang="en">
4<head>
5 <meta charset="utf-8">
6 <meta name="viewport" content="width=device-width">
7 <title>CrossBrowdy API documentation Source: CrossBase/general/CB_Events.js</title>
8
9 <!--[if lt IE 9]>
10 <script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script>
11 <![endif]-->
12 <link type="text/css" rel="stylesheet" href="styles/sunlight.default.css">
13
14 <link type="text/css" rel="stylesheet" href="styles/site.cosmo.css">
15
16</head>
17
18<body style="min-width:800px; overflow-wrap:break-word; word-wrap:break-word; word-break:break-word; line-break:strict; hyphens:none; -webkit-hyphens:none; -moz-hyphens:none;">
19
20<div class="navbar navbar-default navbar-fixed-top ">
21<div class="container">
22 <div class="navbar-header">
23 <a class="navbar-brand" href="index.html">CrossBrowdy API documentation</a>
24 <button class="navbar-toggle" type="button" data-toggle="collapse" data-target="#topNavigation">
25 <span class="icon-bar"></span>
26 <span class="icon-bar"></span>
27 <span class="icon-bar"></span>
28 </button>
29 </div>
30 <div class="navbar-collapse collapse" id="topNavigation">
31 <ul class="nav navbar-nav">
32
33 <li class="dropdown">
34 <a href="namespaces.list.html" class="dropdown-toggle" data-toggle="dropdown">Namespaces<b class="caret"></b></a>
35 <ul class="dropdown-menu inline">
36 <li><a href="CB_Arrays.html">CB_Arrays</a></li><li><a href="CB_AudioDetector.html">CB_AudioDetector</a></li><li><a href="CB_baseSymbols.html">CB_baseSymbols</a></li><li><a href="CB_Client.html">CB_Client</a></li><li><a href="CB_Collisions.html">CB_Collisions</a></li><li><a href="CB_Configuration.html">CB_Configuration</a></li><li><a href="CB_Configuration.CrossBase.html">CB_Configuration.CrossBase</a></li><li><a href="CB_Configuration.CrossBrowdy.html">CB_Configuration.CrossBrowdy</a></li><li><a href="CB_Controllers.html">CB_Controllers</a></li><li><a href="CB_Controllers_Proprietary.html">CB_Controllers_Proprietary</a></li><li><a href="CB_Controllers_Proprietary.WII.html">CB_Controllers_Proprietary.WII</a></li><li><a href="CB_Controllers_Proprietary.WII_U.html">CB_Controllers_Proprietary.WII_U</a></li><li><a href="CB_Device.html">CB_Device</a></li><li><a href="CB_Device.AmbientLight.html">CB_Device.AmbientLight</a></li><li><a href="CB_Device.Battery.html">CB_Device.Battery</a></li><li><a href="CB_Device.Location.html">CB_Device.Location</a></li><li><a href="CB_Device.Motion.html">CB_Device.Motion</a></li><li><a href="CB_Device.Orientation.html">CB_Device.Orientation</a></li><li><a href="CB_Device.Proximity.html">CB_Device.Proximity</a></li><li><a href="CB_Device.Vibration.html">CB_Device.Vibration</a></li><li><a href="CB_Elements.html">CB_Elements</a></li><li><a href="CB_Events.html">CB_Events</a></li><li><a href="CB_Keyboard.html">CB_Keyboard</a></li><li><a href="CB_Keyboard.chars.html">CB_Keyboard.chars</a></li><li><a href="CB_Keyboard.extended.html">CB_Keyboard.extended</a></li><li><a href="CB_Keyboard.keys.html">CB_Keyboard.keys</a></li><li><a href="CB_Modules.html">CB_Modules</a></li><li><a href="CB_Mouse.html">CB_Mouse</a></li><li><a href="CB_Mouse.CursorImage.html">CB_Mouse.CursorImage</a></li><li><a href="CB_Net.html">CB_Net</a></li><li><a href="CB_Net.Fetch.html">CB_Net.Fetch</a></li><li><a href="CB_Net.REST.html">CB_Net.REST</a></li><li><a href="CB_Net.Sockets.html">CB_Net.Sockets</a></li><li><a href="CB_Net.Sockets.SockJS.html">CB_Net.Sockets.SockJS</a></li><li><a href="CB_Net.XHR.html">CB_Net.XHR</a></li><li><a href="CB_Pointer.html">CB_Pointer</a></li><li><a href="CB_Screen.html">CB_Screen</a></li><li><a href="CB_Speaker.html">CB_Speaker</a></li><li><a href="CB_Touch.html">CB_Touch</a></li>
37 </ul>
38 </li>
39
40 <li class="dropdown">
41 <a href="classes.list.html" class="dropdown-toggle" data-toggle="dropdown">Classes<b class="caret"></b></a>
42 <ul class="dropdown-menu inline">
43 <li><a href="CB_AudioFile.html">CB_AudioFile</a></li><li><a href="CB_AudioFile_API.AAPI.html">CB_AudioFile_API.AAPI</a></li><li><a href="CB_AudioFile_API.ACMP.html">CB_AudioFile_API.ACMP</a></li><li><a href="CB_AudioFile_API.SM2.html">CB_AudioFile_API.SM2</a></li><li><a href="CB_AudioFile_API.WAAPI.html">CB_AudioFile_API.WAAPI</a></li><li><a href="CB_AudioFileCache.html">CB_AudioFileCache</a></li><li><a href="CB_AudioFileSprites.html">CB_AudioFileSprites</a></li><li><a href="CB_AudioFileSpritesPool.html">CB_AudioFileSpritesPool</a></li><li><a href="CB_Canvas.html">CB_Canvas</a></li><li><a href="CB_GraphicSprites.html">CB_GraphicSprites</a></li><li><a href="CB_GraphicSpritesScene.html">CB_GraphicSpritesScene</a></li>
44 </ul>
45 </li>
46
47 <li class="dropdown">
48 <a href="global.html" class="dropdown-toggle" data-toggle="dropdown">Global<b class="caret"></b></a>
49 <ul class="dropdown-menu inline">
50 <li><a href="global.html#CB_addCredits">CB_addCredits</a></li><li><a href="global.html#CB_BASE_NAME">CB_BASE_NAME</a></li><li><a href="global.html#CB_baseToBase">CB_baseToBase</a></li><li><a href="global.html#CB_baseToInt">CB_baseToInt</a></li><li><a href="global.html#CB_br2nl">CB_br2nl</a></li><li><a href="global.html#CB_brToNl">CB_brToNl</a></li><li><a href="global.html#CB_combineArraysOrObjects">CB_combineArraysOrObjects</a></li><li><a href="global.html#CB_combineAutomatically">CB_combineAutomatically</a></li><li><a href="global.html#CB_combineJSON">CB_combineJSON</a></li><li><a href="global.html#CB_combineURIParameters">CB_combineURIParameters</a></li><li><a href="global.html#CB_combineURLParameters">CB_combineURLParameters</a></li><li><a href="global.html#CB_console">CB_console</a></li><li><a href="global.html#CB_copyObject">CB_copyObject</a></li><li><a href="global.html#CB_countDecimalDigits">CB_countDecimalDigits</a></li><li><a href="global.html#CB_countDecimalPart">CB_countDecimalPart</a></li><li><a href="global.html#CB_countDecimals">CB_countDecimals</a></li><li><a href="global.html#CB_countIntegerDigits">CB_countIntegerDigits</a></li><li><a href="global.html#CB_countIntegerPart">CB_countIntegerPart</a></li><li><a href="global.html#CB_credits">CB_credits</a></li><li><a href="global.html#CB_CREDITS_DEFAULT">CB_CREDITS_DEFAULT</a></li><li><a href="global.html#CB_forceString">CB_forceString</a></li><li><a href="global.html#CB_forEach">CB_forEach</a></li><li><a href="global.html#CB_getBase64StringObject">CB_getBase64StringObject</a></li><li><a href="global.html#CB_getCookie">CB_getCookie</a></li><li><a href="global.html#CB_getDatum">CB_getDatum</a></li><li><a href="global.html#CB_getJSONPropertyValue">CB_getJSONPropertyValue</a></li><li><a href="global.html#CB_getLZStringObject">CB_getLZStringObject</a></li><li><a href="global.html#CB_getValueIndex">CB_getValueIndex</a></li><li><a href="global.html#CB_getValuePath">CB_getValuePath</a></li><li><a href="global.html#CB_includeJSFile">CB_includeJSFile</a></li><li><a href="global.html#CB_indexOf">CB_indexOf</a></li><li><a href="global.html#CB_init">CB_init</a></li><li><a href="global.html#CB_intToBase">CB_intToBase</a></li><li><a href="global.html#CB_isArray">CB_isArray</a></li><li><a href="global.html#CB_isEmail">CB_isEmail</a></li><li><a href="global.html#CB_isFileLocal">CB_isFileLocal</a></li><li><a href="global.html#CB_isString">CB_isString</a></li><li><a href="global.html#CB_lastIndexOf">CB_lastIndexOf</a></li><li><a href="global.html#CB_ltrim">CB_ltrim</a></li><li><a href="global.html#CB_NAME">CB_NAME</a></li><li><a href="global.html#CB_nl2br">CB_nl2br</a></li><li><a href="global.html#CB_nlToBr">CB_nlToBr</a></li><li><a href="global.html#CB_numberFormat">CB_numberFormat</a></li><li><a href="global.html#CB_numberOfDecimalDigits">CB_numberOfDecimalDigits</a></li><li><a href="global.html#CB_numberOfDecimals">CB_numberOfDecimals</a></li><li><a href="global.html#CB_numberOfIntegerDigits">CB_numberOfIntegerDigits</a></li><li><a href="global.html#CB_OPTIONS">CB_OPTIONS</a></li><li><a href="global.html#CB_parseJSON">CB_parseJSON</a></li><li><a href="global.html#CB_parseString">CB_parseString</a></li><li><a href="global.html#CB_regularExpressionString">CB_regularExpressionString</a></li><li><a href="global.html#CB_renderString">CB_renderString</a></li><li><a href="global.html#CB_replaceAll">CB_replaceAll</a></li><li><a href="global.html#CB_rtrim">CB_rtrim</a></li><li><a href="global.html#CB_scriptPath">CB_scriptPath</a></li><li><a href="global.html#CB_scriptPathCalculate">CB_scriptPathCalculate</a></li><li><a href="global.html#CB_setCookie">CB_setCookie</a></li><li><a href="global.html#CB_setDatum">CB_setDatum</a></li><li><a href="global.html#CB_sizeof">CB_sizeof</a></li><li><a href="global.html#CB_sizeOf">CB_sizeOf</a></li><li><a href="global.html#CB_stringifyJSON">CB_stringifyJSON</a></li><li><a href="global.html#CB_symmetricCall">CB_symmetricCall</a></li><li><a href="global.html#CB_symmetricCallClear">CB_symmetricCallClear</a></li><li><a href="global.html#CB_this">CB_this</a></li><li><a href="global.html#CB_trim">CB_trim</a></li><li><a href="global.html#CB_VERSION">CB_VERSION</a></li>
51 </ul>
52 </li>
53
54 </ul>
55
56 <div class="col-sm-3 col-md-3">
57 <form class="navbar-form" role="search">
58 <div class="input-group">
59 <input type="text" class="form-control" placeholder="Search" name="q" id="search-input">
60 <div class="input-group-btn">
61 <button class="btn btn-default" id="search-submit"><i class="glyphicon glyphicon-search"></i></button>
62 </div>
63 </div>
64 </form>
65 </div>
66
67 </div>
68
69</div>
70</div>
71
72
73<div class="container" id="toc-content" style="width:100%;">
74<div class="row" style="width:100%;">
75
76
77 <div class="col-md-12">
78
79 <div id="main">
80
81
82 <h1 class="page-title">Source: CrossBase/general/CB_Events.js</h1>
83
84<section>
85 <article>
86 <pre
87 class="sunlight-highlight-javascript linenums">/**
88 * @file Events management. Contains the {@link CB_Events} static class.
89 * @author Joan Alba Maldonado &lt;workindalian@gmail.com>
90 * @license Creative Commons Attribution 4.0 International. See more at {@link https://crossbrowdy.com/about#what_is_the_crossbrowdy_copyright_and_license}.
91 */
92
93
94/**
95 * Static class to manage events. It will return itself if it is tried to be instantiated.
96 * @namespace
97 */
98var CB_Events = function() { return CB_Events; };
99{
100 CB_Events.initialized = false; //It will tells whether the object has been initialized or not.
101
102 CB_Events._stored = []; //Array that stores the events (so we could delete all from one type if we wanted).
103
104
105 //Initializes all values:
106 CB_Events.init = function()
107 {
108 if (CB_Events.initialized) { return CB_Events; }
109
110 //The object has been initialized:
111 CB_Events.initialized = true;
112
113 //TODO.
114
115 return CB_Events;
116 }
117
118 /**
119 * Gets the right event object for the current web client and normalizes it attaching to it some methods and properties if they were not present (as preventDefault, stopPropagation, target, etc.). The new attached methods and properties may include polyfills, etc.
120 * @function
121 * @param {Event} e - Event object. If not provided, it will use the value of "event", "window.event", "Event" or an empty object ("{}").
122 * @returns {Event} Returns the event object normalized.
123 */
124 CB_Events.normalize = function(e)
125 {
126 if (!e)
127 {
128 if (typeof(event) !== "undefined") { e = event; }
129 else if (typeof(window.event) !== "undefined") { e = window.event; }
130 else if (typeof(Event) !== "undefined") { e = Event; }
131 if (!e) { e = {}; }
132 }
133
134 try { e._writable = true; } catch(E) { e._writable = false; }
135 if (!e._writable) { e = CB_copyObject(e); } //If the event object cannot be written, copies it.
136
137 //NOTE: Think about using Object.defineProperty with writable: true as option to prevent some web client problems that have readonly properties.
138
139 //If not supported, adds preventDefault compatibility to the event object:
140 if (typeof(e.preventDefault) === "undefined" || e.preventDefault === null)
141 {
142 if ("returnValue" in e)
143 {
144 e.preventDefault = function() { e.returnValue = false; return false; };
145 }
146 else if (typeof(window.event) !== "undefined" &amp;&amp; "returnValue" in window.event)
147 {
148 e.preventDefault = function() { window.event.returnValue = false; return false; };
149 }
150 else { e.preventDefault = function() { return false; } }
151 }
152
153 //If not supported, adds stopPropagation compatibility to the event object:
154 if (typeof(e.stopPropagation) === "undefined" || e.stopPropagation === null)
155 {
156 if (typeof(e.cancelBubble) !== "undefined" &amp;&amp; e.cancelBubble !== null)
157 {
158 e.stopPropagation = function() { e.cancelBubble = true; };
159 }
160 else if (typeof(window.event) !== "undefined" &amp;&amp; typeof(window.event.cancelBubble) !== "undefined")
161 {
162 e.stopPropagation = function() { window.event.cancelBubble = true; };
163 }
164 else { e.stopPropagation = function() { } }
165 }
166
167 //If not supported, adds the target property to the object:
168 if (typeof(e.target) === "undefined" &amp;&amp; typeof(e.srcElement) !== "undefined")
169 {
170 e.target = e.srcElement;
171 }
172
173 //Prevents Safari bug (source: http://www.quirksmode.org/js/events_properties.html):
174 if (typeof(e.target) !== "undefined" &amp;&amp; typeof(e.target.nodeType) !== "undefined" &amp;&amp; e.target.nodeType === 3)
175 {
176 try
177 {
178 e.target = e.target.parentNode;
179 } catch(E) {}
180 }
181
182 //Adds target property (if possible):
183 if (typeof(e.target) === "undefined" &amp;&amp; typeof(e.srcElement) !== "undefined") { e.target = e.srcElement; }
184
185 return e;
186 }
187
188
189 /**
190 * Returns the type of an event, if any (otherwise, returns an empty string).
191 * @function
192 * @param {Event} e - Event object.
193 * @returns {string}
194 */
195 CB_Events.getType = function(e)
196 {
197 e = CB_Events.normalize(e);
198 if (typeof(e.type) !== "undefined" &amp;&amp; e.type !== null) { return e.type; }
199 else { return ""; }
200 }
201
202
203 /**
204 * Removes an event listener (even if it is not erasable).
205 * @function
206 * @param {Object} eventTarget - The target whose event listener we want to remove.
207 * @param {string} eventName - The name of the event that we want to remove.
208 * @param {function} eventFunction - The function (event listener) of the event that we want to remove.
209 * @param {boolean} [useCapture=false] - Defines whether the event we want to remove was defined to use capture or not.
210 */
211 CB_Events.remove = function(eventTarget, eventName, eventFunction, useCapture)
212 {
213 //If the target (node) is null or is not an object, exits:
214 if (typeof(eventTarget) === "undefined" || eventTarget === null || typeof(eventTarget) !== "object") { return; }
215
216 //If not defined, set default value for useCapture parameter:
217 if (useCapture !== true &amp;&amp; useCapture !== false) { useCapture = false; }
218
219 //Removes the event from the array:
220 CB_Events._storedClear(eventTarget, eventName, eventFunction, useCapture);
221
222 //Removes the event:
223 if (typeof(eventTarget.addEventListener) !== "undefined" &amp;&amp; eventTarget.removeEventListener)
224 {
225 eventTarget.removeEventListener(eventName, eventFunction, useCapture);
226 }
227 else if (typeof(eventTarget.attachEvent) !== "undefined" &amp;&amp; eventTarget.detachEvent)
228 {
229 eventTarget.detachEvent("on" + eventName, eventFunction);
230 }
231 }
232
233
234 /**
235 * Alias for {@link CB_Events.on}.
236 * @function CB_Events.add
237 * @see {@link CB_Events.on}
238 */
239 /**
240 * Adds an event listener.
241 * @function
242 * @param {Object} eventTarget - The target where we want to attach the event listener.
243 * @param {string} eventName - The name of the event that we want to add.
244 * @param {function} eventFunction - The function (event listener) of the event that we want to add.
245 * @param {boolean} [useCapture=false] - Defines whether the event we want to add will use capture or not. This parameter will be effective only if the current client supports the [addEventListener]{@link https://developer.mozilla.org/en-US/docs/Web/API/EventTarget/addEventListener} method and will be used as its third parameter.
246 * @param {boolean} [keepOldEventFunction=true] - Defines whether we want to keep any possible previous event listener for the same target and event name or not.
247 * @param {boolean} [erasable=true] - Defines whether the event listener will be erasable by {@link CB_Events.removeAll} or {@link CB_Events.removeByName} functions later or not (it will always be erasable if we force delete).
248 * @todo Try to simulate "useCapture" when the "addEventListener" method is not available.
249 */
250 CB_Events.on = CB_Events.add = function(eventTarget, eventName, eventFunction, useCapture, keepOldEventFunction, erasable)
251 {
252 //If the target (node) is null or is not an object, exits:
253 if (typeof(eventTarget) === "undefined" || eventTarget === null || typeof(eventTarget) !== "object") { return; }
254
255 //If not defined, set default values for optional parameters:
256 if (useCapture !== true &amp;&amp; useCapture !== false) { useCapture = false; }
257 if (typeof(keepOldEventFunction) === "undefined" || keepOldEventFunction === null) { keepOldEventFunction = true; }
258 if (typeof(erasable) === "undefined" || erasable === null) { erasable = true; }
259
260 //If we don't want to keep the old event functions, we delete them:
261 if (!keepOldEventFunction)
262 {
263 CB_Events.removeByName(eventTarget, eventName);
264 }
265
266 //Adds the new event listeners:
267 if (typeof(eventTarget.addEventListener) !== "undefined" &amp;&amp; eventTarget.addEventListener)
268 {
269 eventTarget.addEventListener(eventName, eventFunction, useCapture);
270 }
271 else if (typeof(eventTarget.attachEvent) !== "undefined" &amp;&amp; eventTarget.attachEvent)
272 {
273 eventTarget.attachEvent("on" + eventName, eventFunction);
274 }
275 //else if (eventTarget &amp;&amp; typeof( eval("eventTarget.on" + eventName) ) !== "undefined")
276 else if (eventTarget &amp;&amp; typeof(eventTarget["on" + eventName]) !== "undefined")
277 {
278 var newEventFunction =
279 function(e)
280 {
281 //e = CB_Events.normalize(e);
282 return CB_Events.executeByName(eventTarget, eventName, e);
283 }
284 eventTarget["on" + eventName] = newEventFunction;
285 }
286
287 //Stores the event (so we could delete all from one type if we wanted):
288 CB_Events._store(eventTarget, eventName, eventFunction, useCapture, erasable);
289
290 //If we mind Iframes:
291 if (CB_Configuration[CB_BASE_NAME].MIND_IFRAMES)
292 {
293 //If the event is "keydown", "keyup", "keypress", "mousedown" or "click":
294 eventName = eventName.toLowerCase();
295 if (eventName === "keydown" || eventName === "keyup" || eventName === "keydown" || eventName === "mousedown" || eventName === "click")
296 {
297 try
298 {
299 var eventTargetParents = [];
300 //If the event is the main window object (no one of its possible parents):
301 if (eventTarget === window)
302 {
303 eventTargetParents = CB_Client.getWindowParents();
304 }
305 //...otherwise if the event is the main document object (no one of its possible parents):
306 else if (eventTarget === document)
307 {
308 eventTargetParents = CB_Client.getWindowParents().slice(0);
309 CB_forEach
310 (
311 eventTargetParents,
312 function(element, index, array)
313 {
314 if (index > 0) { array[index] = element.document; }
315 }
316 );
317 }
318
319 //If there are parents, applies the same event listener to them:
320 if (eventTargetParents.length > 1)
321 {
322 CB_forEach
323 (
324 eventTargetParents,
325 function(element, index, array)
326 {
327 if (index > 0)
328 {
329 CB_Events.add(element, eventName, eventFunction, useCapture, keepOldEventFunction, erasable);
330 }
331 }
332 );
333 }
334 } catch(E) { }
335 }
336 }
337 }
338
339
340 /**
341 * Object that contains an event handler.
342 * @memberof CB_Events
343 * @typedef {Object} CB_Events.EVENT_HANDLER
344 * @property {Object} eventTarget - The target of the event.
345 * @property {string} eventName - The name of the event.
346 * @property {function} eventFunction - The event listener.
347 * @property {boolean} useCapture - Defines whether the event listener was defined to use capture or not.
348 * @property {boolean} erasable - Defines whether the event handler is erasable (without forcing delete) or not.
349 */
350
351 //Function that stores an event (so we could delete all from one type if we wanted):
352 CB_Events._store = function(eventTarget, eventName, eventFunction, useCapture, erasable)
353 {
354 var x = CB_Events._stored.length;
355 CB_Events._stored[x] = new Array(5);
356 CB_Events._stored[x]["eventTarget"] = eventTarget;
357 CB_Events._stored[x]["eventName"] = eventName;
358 CB_Events._stored[x]["eventFunction"] = eventFunction; //Stores the function.
359 CB_Events._stored[x]["useCapture"] = useCapture; //Stores the capture mode.
360 CB_Events._stored[x]["erasable"] = erasable; //Stores whether is erasable or not.
361 }
362
363
364 //Function that clears (deletes) a stored event:
365 CB_Events._storedClear = function(eventTarget, eventName, eventFunction, useCapture)
366 {
367 var CB_storedEventsLength = CB_Events._stored.length
368 for (var x = 0; x &lt; CB_storedEventsLength; x++)
369 {
370 //If the target (node) exists:
371 if (eventTarget === CB_Events._stored[x]["eventTarget"])
372 {
373 //If the event exists
374 if (eventName === CB_Events._stored[x]["eventName"])
375 {
376 //If the function (event handler) exists:
377 if (eventFunction === CB_Events._stored[x]["eventFunction"])
378 {
379 //If it's the same capture mode:
380 if (useCapture === CB_Events._stored[x]["useCapture"])
381 {
382 CB_Events._stored[x] = Array(5); //Clears the array (deletes the stored event).
383 break; //It exits so that way only one element will be cleared.
384 }
385 }
386 }
387 }
388 }
389 }
390
391
392 /**
393 * Deletes all handlers for an specific event from a node (target).
394 * @function
395 * @param {Object} eventTarget - The target whose event listeners we want to remove.
396 * @param {string} eventName - The name of the event whose event listeners we want to remove.
397 * @param {boolean} [forceDelete=false] - If it is set to true, it will remove any listener (even the ones which were added as not erasable).
398 */
399 CB_Events.removeByName = function(eventTarget, eventName, forceDelete)
400 {
401 var CB_storedEventsLength = CB_Events._stored.length;
402 for (var x = 0; x &lt; CB_storedEventsLength; x++)
403 {
404 //If the target (node) exists:
405 if (eventTarget === CB_Events._stored[x]["eventTarget"])
406 {
407 //If the event exists
408 if (eventName === CB_Events._stored[x]["eventName"])
409 {
410 //Removes the element if is erasable or is in force delete mode:
411 if (forceDelete || CB_Events._stored[x]["erasable"])
412 {
413 CB_Events.remove(eventTarget, eventName, CB_Events._stored[x]["eventFunction"], CB_Events._stored[x]["useCapture"]);
414 }
415 }
416 }
417 }
418 }
419
420
421 /**
422 * Removes all event listeners.
423 * @function
424 * @param {boolean} [forceDelete=false] - If it is set to true, it will remove all event listeners (even the ones which were added as not erasable).
425 */
426 CB_Events.removeAll = function(forceDelete)
427 {
428 //For every targets (nodes):
429 var CB_storedEventsLength = CB_Events._stored.length;
430 for (var x = 0; x &lt; CB_storedEventsLength; x++)
431 {
432 //If the event has not been cleared before:
433 if (typeof(CB_Events._stored[x]["eventTarget"]) !== "undefined" &amp;&amp; typeof(CB_Events._stored[x]["eventName"]) !== "undefined")
434 {
435 CB_Events.removeByName(CB_Events._stored[x]["eventTarget"], CB_Events._stored[x]["eventName"], forceDelete);
436 }
437 }
438 }
439
440
441 /**
442 * Executes all event listeners for an specific event from a node (target).
443 * @function
444 * @param {Object} eventTarget - The target whose event listeners we want to execute. It will be the value of "this" for every call to each listener.
445 * @param {string} eventName - The name of the event whose event listeners we want to execute.
446 * @param {Event} [e] - Event object that will be passed as the first and unique parameter for every call to each listener.
447 * @param {*} [returnOnNothingExecuted] - The value that will be returned by the function if nothing is executed.
448 * @returns {boolean} Returns the result of doing the AND operator of all return values of each listener executed. If only one listener is executed, it will return the result of doing the AND operator with its returning value and "true". Returns the value of the "returnOnNothingExecuted" parameter if nothing is executed.
449 */
450 CB_Events.executeByName = function(eventTarget, eventName, e, returnOnNothingExecuted)
451 {
452 var CB_storedEventsLength = CB_Events._stored.length;
453 var returnValue = true;
454 var somethingExecuted = false;
455 for (var x = 0; x &lt; CB_storedEventsLength; x++)
456 {
457 //If the target (node) exists:
458 if (eventTarget === CB_Events._stored[x]["eventTarget"])
459 {
460 //If the event exists
461 if (eventName === CB_Events._stored[x]["eventName"])
462 {
463 //if an event function exists:
464 if (typeof(CB_Events._stored[x]["eventFunction"]) === "function")
465 {
466 returnValue = CB_Events._stored[x]["eventFunction"].call(eventTarget, e) &amp;&amp; returnValue;
467 somethingExecuted = true;
468 }
469 }
470 }
471 }
472 return somethingExecuted ? returnValue : returnOnNothingExecuted;
473 }
474
475
476 /**
477 * Returns all handlers for an specific event from a node (target), if any.
478 * @function
479 * @param {Object} eventTarget - The target whose event listeners we want to get.
480 * @param {string} eventName - The name of the event whose event listeners we want to get.
481 * @param {boolean} [onlyWithFunction=false] - Defines whether to return only the handlers which have a function as the listener.
482 * @returns {array} Returns an array of {@link CB_Events.EVENT_HANDLER} objects.
483 */
484 CB_Events.getByName = function(eventTarget, eventName, onlyWithFunction)
485 {
486 var found = [];
487 var CB_storedEventsLength = CB_Events._stored.length;
488 for (var x = 0; x &lt; CB_storedEventsLength; x++)
489 {
490 //If the target (node) exists:
491 if (eventTarget === CB_Events._stored[x]["eventTarget"])
492 {
493 //If the event exists
494 if (eventName === CB_Events._stored[x]["eventName"])
495 {
496 if (!onlyWithFunction || typeof(CB_Events._stored[x]["eventFunction"]) === "function")
497 {
498 found[found.length] = CB_Events._stored[x];
499 }
500 }
501 }
502 }
503 return found;
504 }
505
506
507 /**
508 * Returns all stored event handlers (if any).
509 * @function
510 * @returns {array} Returns an array of {@link CB_Events.EVENT_HANDLER} objects.
511 */
512 CB_Events.getAll = function()
513 {
514 return CB_Events._stored;
515 }
516}</pre>
517 </article>
518</section>
519
520
521
522
523
524 </div>
525 </div>
526
527 <div class="clearfix"></div>
528
529
530
531</div>
532</div>
533
534
535 <div class="modal fade" id="searchResults">
536 <div class="modal-dialog">
537 <div class="modal-content">
538 <div class="modal-header">
539 <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
540 <h4 class="modal-title">Search results</h4>
541 </div>
542 <div class="modal-body"></div>
543 <div class="modal-footer">
544 <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
545 </div>
546 </div><!-- /.modal-content -->
547 </div><!-- /.modal-dialog -->
548 </div>
549
550
551<footer>
552
553
554 <span class="copyright">
555 <a href="printable/" target="_blank">See a more printer-friendly version</a><hr /><span style="color:#000000">© <address style="display:inline; font-style:normal;"><a href="https://crossbrowdy.com/" target="_blank">CrossBrowdy</a> API documentation</address> by <a href="https://joanalbamaldonado.com/" target="_blank">Joan Alba Maldonado</a> - <a href="https://creativecommons.org/licenses/by/4.0/" target="_blank">Creative Commons Attribution 4.0 International</a><br />DocStrap Copyright © 2012-2015 The contributors to the JSDoc3 and DocStrap projects.</span>
556 </span>
557
558<span class="jsdoc-message">
559 Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.5.5</a>
560
561 on Mon Feb 3rd 2020
562
563 using the <a href="https://github.com/docstrap/docstrap">DocStrap template</a>.
564</span>
565</footer>
566
567<script src="scripts/docstrap.lib.js"></script>
568<script src="scripts/toc.js"></script>
569
570 <script type="text/javascript" src="scripts/fulltext-search-ui.js"></script>
571
572
573<script>
574$( function () {
575 $( "[id*='$']" ).each( function () {
576 var $this = $( this );
577
578 $this.attr( "id", $this.attr( "id" ).replace( "$", "__" ) );
579 } );
580
581 $( ".tutorial-section pre, .readme-section pre, pre.prettyprint.source" ).each( function () {
582 var $this = $( this );
583
584 var example = $this.find( "code" );
585 exampleText = example.html();
586 var lang = /{@lang (.*?)}/.exec( exampleText );
587 if ( lang && lang[1] ) {
588 exampleText = exampleText.replace( lang[0], "" );
589 example.html( exampleText );
590 lang = lang[1];
591 } else {
592 var langClassMatch = example.parent()[0].className.match(/lang\-(\S+)/);
593 lang = langClassMatch ? langClassMatch[1] : "javascript";
594 }
595
596 if ( lang ) {
597
598 $this
599 .addClass( "sunlight-highlight-" + lang )
600 .addClass( "linenums" )
601 .html( example.html() );
602
603 }
604 } );
605
606 Sunlight.highlightAll( {
607 lineNumbers : true,
608 showMenu : true,
609 enableDoclinks : true
610 } );
611
612 $.catchAnchorLinks( {
613 navbarOffset: 10
614 } );
615 $( "#toc" ).toc( {
616 anchorName : function ( i, heading, prefix ) {
617 return $( heading ).attr( "id" ) || ( prefix + i );
618 },
619 selectors : "#toc-content h1,#toc-content h2,#toc-content h3,#toc-content h4",
620 showAndHide : false,
621 smoothScrolling: true
622 } );
623
624 $( "#main span[id^='toc']" ).addClass( "toc-shim" );
625 $( '.dropdown-toggle' ).dropdown();
626
627 $( "table" ).each( function () {
628 var $this = $( this );
629 $this.addClass('table');
630 } );
631
632} );
633</script>
634
635
636
637<!--Navigation and Symbol Display-->
638
639<script>
640 $( function () {
641 $( '#main' ).localScroll( {
642 offset : { top : 60 } //offset by the height of your header (give or take a few px, see what works for you)
643 } );
644 $( "dt.name" ).each( function () {
645 var $this = $( this ).find("h4");
646 var icon = $( "<i/>" ).addClass( "icon-plus-sign" ).addClass( "pull-right" ).addClass( "icon-white" );
647 var dt = $(this);
648 var children = dt.next( "dd" );
649
650 dt.prepend( icon ).css( {cursor : "pointer"} );
651 dt.addClass( "member-collapsed" ).addClass( "member" );
652
653
654 children.hide();
655
656 dt.children().on( "click", function () {
657 children = dt.next( "dd" );
658 children.slideToggle( "fast", function () {
659
660 if ( children.is( ":visible" ) ) {
661 icon.addClass( "icon-minus-sign" ).removeClass( "icon-plus-sign" ).removeClass( "icon-white" );
662 dt.addClass( "member-open" ).animate( "member-collapsed" );
663 } else {
664 icon.addClass( "icon-plus-sign" ).removeClass( "icon-minus-sign" ).addClass( "icon-white" );
665 dt.addClass( "member-collapsed" ).removeClass( "member-open" );
666 }
667 } );
668 } );
669
670 } );
671 } );
672</script>
673
674
675<!--Google Analytics-->
676
677
678
679 <script type="text/javascript">
680 $(document).ready(function() {
681 SearcherDisplay.init();
682 });
683 </script>
684
685
686</body>
687</html>