UNPKG

36.7 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/input/CB_Touch.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/input/CB_Touch.js</h1>
83
84<section>
85 <article>
86 <pre
87 class="sunlight-highlight-javascript linenums">/**
88 * @file Touch events management. Contains the {@link CB_Touch} 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 the [touch events]{@link https://developer.mozilla.org/en-US/docs/Web/API/Touch_events}. It will return itself if it is tried to be instantiated. It can also use [Pressure.js]{@link https://pressurejs.com/} and [Hammer.js]{@link https://hammerjs.github.io/}.
96 * @namespace
97 */
98var CB_Touch = function() { return CB_Touch; };
99{
100 CB_Touch._data = null; //Stores the information about the touch points.
101 CB_Touch._force = null; //Stores the force of the touch point (just one, using Pressure.js).
102
103 /**
104 * Default value for the force attribute if no one is detected.
105 * @var
106 * @readonly
107 * @type {number}
108 * @default
109 */
110 CB_Touch.DEFAULT_FORCE = 1; //Default value for the force attribute if no one is detected.
111
112 CB_Touch._hammerJSObject = null; //Stores the Hammer.js object (if any).
113 CB_Touch._pressureJSObject = null; //Stores the Pressure.js object (if any).
114
115 CB_Touch.initialized = false; //It will tells whether the object has been initialized or not.
116
117
118 //Initializes all values:
119 CB_Touch.init = function()
120 {
121 if (CB_Touch.initialized) { return CB_Touch; }
122
123 //The object has been initialized:
124 CB_Touch.initialized = true;
125
126 //Gets the touch data constantly:
127 CB_Events.add(document, "touchstart", function(e) { CB_Touch._data = CB_Touch.normalizeEvent(e) || null; }, true, true, false);
128 CB_Events.add(document, "touchenter", function(e) { CB_Touch._data = CB_Touch.normalizeEvent(e) || null; }, true, true, false);
129 CB_Events.add(document, "touchmove", function(e) { CB_Touch._data = CB_Touch.normalizeEvent(e) || null; }, true, true, false);
130 CB_Events.add(document, "touchend", function(e) { CB_Touch._force = 0; CB_Touch._data = null; }, true, true, false);
131 CB_Events.add(document, "touchleave", function(e) { CB_Touch._force = 0; CB_Touch._data = null; }, true, true, false);
132
133 //Gets and stores the Hammer.js object (if any):
134 CB_Touch._hammerJSObject = (typeof(Hammer) !== "undefined" &amp;&amp; Hammer !== null) ? Hammer : null;
135 if (typeof(Hammer) !== "undefined" &amp;&amp; Hammer !== null &amp;&amp; Hammer.defaults)
136 {
137 //Chromium workaround (Chrome, Opera...) for Android thanks to Desiderius77, found on https://github.com/hammerjs/hammer.js/issues/1130#issuecomment-378851243.
138 Hammer.defaults.inputClass = ((CB_Client.get() === "Chrome" || CB_Client.get() === "Opera") &amp;&amp; Hammer.SUPPORT_POINTER_EVENTS) ? Hammer.PointerEventInput : Hammer.TouchInput;
139 }
140
141 //Gets and stores the Pressure.js object (if any):
142 CB_Touch._pressureJSObject = (typeof(Pressure) !== "undefined" &amp;&amp; Pressure !== null) ? Pressure : null;
143
144 //Gets the touch force (using pressure.js) constantly:
145 if (CB_Touch._pressureJSObject !== null &amp;&amp; typeof(CB_Touch._pressureJSObject.set) === "function")
146 {
147 CB_Touch._pressureJSObject.set
148 (
149 document,
150 {
151 //start: function(event) { },
152 end: function() { CB_Touch._force = 0; },
153 //startDeepPress: function(event) { },
154 //endDeepPress: function() { },
155 change: function(force, event) { CB_Touch._force = typeof(force) !== "undefined" &amp;&amp; !isNaN(force) ? force : null; }//,
156 //unsupported: function() { }
157 }
158 );
159 }
160
161 return CB_Touch;
162 }
163
164
165 //Allows for interpolating a value from one range of values to another:
166 //* Source: Pressure.js by Stuart Yamartino and Arduino documentation: https://www.arduino.cc/en/Reference/Map
167 CB_Touch._map = function _map(x, in_min, in_max, out_min, out_max) { return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min; };
168
169
170 /**
171 * Normalizes the given "force" property value across different clients. The new attached methods and properties may include polyfills, etc. This function is called by {@link CB_Touch.normalizePoint} automatically.
172 * @function
173 * @param {number} force - Force value to be normalized.
174 * @returns {Event} Returns the force value normalized.
175 * @todo Not all web clients are the same, so not all should be normalized.
176 */
177 //* Source: Pressure.js by Stuart Yamartino.
178 CB_Touch.normalizeForce = function(force)
179 {
180 //TODO: not all web clients are the same! so not all should normalize.
181 if (typeof(force) === "undefined" || force === null || isNaN(force)) { return CB_Touch.DEFAULT_FORCE; }
182 force = CB_Touch._map(force, 1, 3, 0, 1);
183 force = force > 0.999 ? 1 : force;
184 force = Math.abs(force);
185 return force;
186 }
187
188
189 /**
190 * Tries to return the [touch event]{@link https://developer.mozilla.org/en-US/docs/Web/API/TouchEvent} object with some properties normalized (since different clients can use different values), when possible. It also calls the {@link CB_Events.normalize} and {@link CB_Touch.normalizePoints} functions internally. Some properties affected could be [targetTouches]{@link https://developer.mozilla.org/en-US/docs/Web/API/TouchEvent/targetTouches}, [touches]{@link https://developer.mozilla.org/en-US/docs/Web/API/TouchEvent/touches}, [changedTouches]{@link https://developer.mozilla.org/en-US/docs/Web/API/TouchEvent/changedTouches}, etc.
191 * @function
192 * @param {Event} e - [Touch event]{@link https://developer.mozilla.org/en-US/docs/Web/API/TouchEvent} object. If not provided, it will use the value of "event", "window.event", "Event" or an empty object ("{}").
193 * @returns {Event} Returns the [touch event]{@link https://developer.mozilla.org/en-US/docs/Web/API/TouchEvent} object normalized.
194 * @todo Add more properties and methods to normalize (if needed)
195 */
196 CB_Touch.normalizeEvent = function(e)
197 {
198 e = CB_Events.normalize(e);
199
200 //TODO: add more properties and methods to normalize (if needed).
201
202 //Normalize the points:
203 e.targetTouches = CB_Touch.normalizePoints(e.targetTouches);
204 e.touches = CB_Touch.normalizePoints(e.touches);
205 e.changedTouches = CB_Touch.normalizePoints(e.changedTouches);
206
207 return e;
208 }
209
210
211 /**
212 * Normalizes a given list of points. Calls {@link CB_Touch.normalizePoint} internally. This function is called by {@link CB_Touch.normalizeEvent} automatically.
213 * @function
214 * @param {TouchList|array} points - [TouchList]{@link https://developer.mozilla.org/en-US/docs/Web/API/TouchList} or array with the points ([Touch objects]{@link https://developer.mozilla.org/en-US/docs/Web/API/Touch}) to be normalized.
215 * @returns {TouchList|array} Returns the given points normalized.
216 */
217 CB_Touch.normalizePoints = function(points)
218 {
219 if (typeof(points) === "undefined" || points === null || typeof(points) === "undefined" || points === null) { return []; }
220 for (var x = 0; x &lt; points.length; x++)
221 {
222 points[x] = CB_Touch.normalizePoint(points[x]);
223 }
224 return points;
225 }
226
227
228 /**
229 * Normalizes a given point. Calls {@link CB_Touch.normalizeForce} internally. This function is called by {@link CB_Touch.normalizePoints} automatically.
230 * @function
231 * @param {Touch} point - [Touch object]{@link https://developer.mozilla.org/en-US/docs/Web/API/Touch} to be normalized.
232 * @returns {Touch} Returns the given point normalized.
233 */
234 CB_Touch.normalizePoint = function(point)
235 {
236 if (typeof(point) !== "undefined" &amp;&amp; point !== null)
237 {
238 if (typeof(point.force) === "undefined" || point.force === null || isNaN(point.force))
239 {
240 if (typeof(point.webkitForce) !== "undefined" &amp;&amp; point.webkitForce !== null &amp;&amp; !isNaN(point.webkitForce)) { point.force = point.webkitForce; }
241 else if (CB_Touch._force !== null) { point.force = CB_Touch._force; } //Uses force detected by Pressure.js.
242 else { e.force = CB_Touch.DEFAULT_FORCE; }
243 }
244 point.force = CB_Touch.normalizeForce(point.force);
245 }
246 return point;
247 }
248
249
250 /**
251 * Returns the last [touch event]{@link https://developer.mozilla.org/en-US/docs/Web/API/TouchEvent} object (if any), processed by {@link CB_Touch.normalizeEvent} internally, which was used in the last touch event fired, if that touch event was [touchstart]{@link https://developer.mozilla.org/en-US/docs/Web/API/Element/touchstart_event}, [touchenter]{@link https://w3.org/TR/2011/WD-touch-events-20110505/#the-touchenter-event} or [touchmove]{@link https://developer.mozilla.org/en-US/docs/Web/API/Element/touchmove_event}. The [touchend]{@link https://developer.mozilla.org/en-US/docs/Web/API/Element/touchend_event} and [touchleave]{@link https://w3.org/TR/2011/WD-touch-events-20110505/#the-touchleave-event} events set it to "null".
252 * @function
253 * @returns {Event|null} Returns the last [touch event]{@link https://developer.mozilla.org/en-US/docs/Web/API/TouchEvent} affected, if any.
254 */
255 CB_Touch.getData = function()
256 {
257 return CB_Touch._data;
258 }
259
260
261 /**
262 * Returns the maximum of touch points supported by the device (if possible).
263 * @function
264 * @returns {integer|null} Maximum touch points supported by the device (if possible). If it cannot be detected, returns null.
265 */
266 CB_Touch.getMaxTouchPoints = function()
267 {
268 if (window.navigator)
269 {
270 if (window.navigator.maxTouchPoints) { return window.navigator.maxTouchPoints; }
271 else if (window.navigator.msMaxTouchPoints) { return window.navigator.msMaxTouchPoints; }
272 }
273 return null;
274 }
275
276
277 /**
278 * Sets a function to execute when the [onTouchStart]{@link https://developer.mozilla.org/en-US/docs/Web/API/Element/touchstart_event} event is fired or removes it. More information: [Touch events]{@link https://developer.mozilla.org/en-US/docs/DOM/Touch_events}.
279 * @function
280 * @param {function|null} callbackFunction - The function (event listener) that we want to execute when the event is fired. The first and unique parameter received for this function will be the event object (already normalized by the {@link CB_Touch.normalizeEvent} function). If a null value is used, the event will be removed.
281 * @param {boolean} [keepOldFunction=true] - Defines whether we want to keep any possible previous event listener for the same target and event name or not.
282 * @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.
283 * @param {Object} [target=document] - The target where we want to attach the event listener.
284 */
285 CB_Touch.onStart = function(callbackFunction, keepOldFunction, useCapture, target)
286 {
287 return CB_Touch._setEvent("touchstart", callbackFunction, keepOldFunction, useCapture, target);
288 }
289
290
291 /**
292 * Sets a function to execute when the [onTouchEnd]{@link https://developer.mozilla.org/en-US/docs/Web/API/Element/touchend_event} event is fired or removes it. More information: [Touch events]{@link https://developer.mozilla.org/en-US/docs/DOM/Touch_events}.
293 * @function
294 * @param {function|null} callbackFunction - The function (event listener) that we want to execute when the event is fired. The first and unique parameter received for this function will be the event object (already normalized by the {@link CB_Touch.normalizeEvent} function). If a null value is used, the event will be removed.
295 * @param {boolean} [keepOldFunction=true] - Defines whether we want to keep any possible previous event listener for the same target and event name or not.
296 * @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.
297 * @param {Object} [target=document] - The target where we want to attach the event listener.
298 */
299 CB_Touch.onEnd = function(callbackFunction, keepOldFunction, useCapture, target)
300 {
301 return CB_Touch._setEvent("touchend", callbackFunction, keepOldFunction, useCapture, target);
302 }
303
304
305 /**
306 * Sets a function to execute when the [onTouchCancel]{@link https://developer.mozilla.org/en-US/docs/Web/API/Element/touchcancel_event} event is fired or removes it. More information: [Touch events]{@link https://developer.mozilla.org/en-US/docs/DOM/Touch_events}.
307 * @function
308 * @param {function|null} callbackFunction - The function (event listener) that we want to execute when the event is fired. The first and unique parameter received for this function will be the event object (already normalized by the {@link CB_Touch.normalizeEvent} function). If a null value is used, the event will be removed.
309 * @param {boolean} [keepOldFunction=true] - Defines whether we want to keep any possible previous event listener for the same target and event name or not.
310 * @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.
311 * @param {Object} [target=document] - The target where we want to attach the event listener.
312 */
313 CB_Touch.onCancel = function(callbackFunction, keepOldFunction, useCapture, target)
314 {
315 return CB_Touch._setEvent("touchcancel", callbackFunction, keepOldFunction, useCapture, target);
316 }
317
318
319 /**
320 * Sets a function to execute when the [onTouchEnter]{@link https://w3.org/TR/2011/WD-touch-events-20110505/#the-touchenter-event} event is fired or removes it. More information: [Touch events]{@link https://developer.mozilla.org/en-US/docs/DOM/Touch_events}.
321 * @function
322 * @param {function|null} callbackFunction - The function (event listener) that we want to execute when the event is fired. The first and unique parameter received for this function will be the event object (already normalized by the {@link CB_Touch.normalizeEvent} function). If a null value is used, the event will be removed.
323 * @param {boolean} [keepOldFunction=true] - Defines whether we want to keep any possible previous event listener for the same target and event name or not.
324 * @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.
325 * @param {Object} [target=document] - The target where we want to attach the event listener.
326 */
327 CB_Touch.onEnter = function(callbackFunction, keepOldFunction, useCapture, target)
328 {
329 return CB_Touch._setEvent("touchenter", callbackFunction, keepOldFunction, useCapture, target);
330 }
331
332
333 /**
334 * Sets a function to execute when the [onTouchLeave]{@link https://w3.org/TR/2011/WD-touch-events-20110505/#the-touchleave-event} event is fired or removes it. More information: [Touch events]{@link https://developer.mozilla.org/en-US/docs/DOM/Touch_events}.
335 * @function
336 * @param {function|null} callbackFunction - The function (event listener) that we want to execute when the event is fired. The first and unique parameter received for this function will be the event object (already normalized by the {@link CB_Touch.normalizeEvent} function). If a null value is used, the event will be removed.
337 * @param {boolean} [keepOldFunction=true] - Defines whether we want to keep any possible previous event listener for the same target and event name or not.
338 * @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.
339 * @param {Object} [target=document] - The target where we want to attach the event listener.
340 */
341 CB_Touch.onLeave = function(callbackFunction, keepOldFunction, useCapture, target)
342 {
343 return CB_Touch._setEvent("touchleave", callbackFunction, keepOldFunction, useCapture, target);
344 }
345
346
347 /**
348 * Sets a function to execute when the [onTouchMove]{@link https://developer.mozilla.org/en-US/docs/Web/API/Element/touchmove_event} event is fired or removes it. More information: [Touch events]{@link https://developer.mozilla.org/en-US/docs/DOM/Touch_events}.
349 * @function
350 * @param {function|null} callbackFunction - The function (event listener) that we want to execute when the event is fired. The first and unique parameter received for this function will be the event object (already normalized by the {@link CB_Touch.normalizeEvent} function). If a null value is used, the event will be removed.
351 * @param {boolean} [keepOldFunction=true] - Defines whether we want to keep any possible previous event listener for the same target and event name or not.
352 * @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.
353 * @param {Object} [target=document] - The target where we want to attach the event listener.
354 */
355 CB_Touch.onMove = function(callbackFunction, keepOldFunction, useCapture, target)
356 {
357 return CB_Touch._setEvent("touchmove", callbackFunction, keepOldFunction, useCapture, target);
358 }
359
360
361 //Sets a function to execute when a touch event happens:
362 CB_Touch._setEvent = function(eventName, eventFunction, keepOldFunction, useCapture, target)
363 {
364 //If they are not set, use default values for optional parameters:
365 if (typeof(keepOldFunction) === "undefined" || keepOldFunction === null) { keepOldFunction = true; } //If not set, it keeps old function by default.
366 if (typeof(target) === "undefined" || target === null) { target = document; }
367
368 //If a function has been sent:
369 if (typeof(eventFunction) === "function")
370 {
371 //If able, adds the function given to the event:
372 CB_Events.add
373 (
374 target,
375 eventName,
376 function(e)
377 {
378 e = CB_Touch.normalizeEvent(e);
379
380 //TODO.
381
382 if (typeof(eventFunction) === "function") { return eventFunction(e); }
383 return true;
384 },
385 useCapture,
386 keepOldFunction,
387 true
388 );
389 }
390 //...but if the function given is null, it will cancel the event:
391 else if (eventFunction === null)// &amp;&amp; eventFunctionHolder !== null)
392 {
393 CB_Events.removeByName(target, eventName);
394 }
395 }
396
397
398 /**
399 * Returns the [Hammer.js]{@link https://hammerjs.github.io/} object (if any). Useful for managing touch gestures.
400 * @function
401 * @returns {Object} Returns the [Hammer.js]{@link https://hammerjs.github.io/} object (if any).
402 */
403 CB_Touch.getHammerJSObject = function()
404 {
405 return CB_Touch._hammerJSObject;
406 }
407
408
409 /**
410 * Returns the [Pressure.js]{@link https://pressurejs.com/} object (if any). Useful for managing [Force Touch/3D Touch]{@link https://en.wikipedia.org/wiki/Force_Touch} and [Pointer Pressure]{@link https://developer.mozilla.org/en-US/docs/Web/API/PointerEvent/pressure} features.
411 * @function
412 * @returns {Object} Returns the [Pressure.js]{@link https://pressurejs.com/} object (if any).
413 */
414 CB_Touch.getPressureJSObject = function()
415 {
416 return CB_Touch._pressureJSObject;
417 }
418
419
420 CB_Touch._delayTimeout = {};
421 CB_Touch._delayPerforming = {};
422 CB_Touch._delayMsDefault = 200;
423 /**
424 * First time, this function will return true. Next calls, with same index, returns false during the previously-defined time set in the previous call and true after that delay. After the first call, next calls of this function with same index will be ignored (returning always false) until the delay provided expires. If it is called after a previous call with the same index and the delay of the previous call already expired, it will act as it was the first call again. Useful, for example, to prevent the [onTouchStart]{@link https://developer.mozilla.org/en-US/docs/Web/API/Element/touchstart_event} event to fire twice or more when a layer (container) is closed and behind there is another one with also the [onTouchStart]{@link https://developer.mozilla.org/en-US/docs/Web/API/Element/touchstart_event} event.
425 * @function
426 * @param {integer} [delayMs=CB_Touch._delayMsDefault] - Delay desired in milliseconds. For same indexes, this parameter will be ignored if there was a previous call to this function whose delay did not expire yet.
427 * @param {integer|string} [index=0] - Desired index to identify the process.
428 * @returns {boolean} First time, this function will return true. Next calls with the same index, returns false during the given time and true after that delay. After the first call, next calls with same index of this function will be ignored (returning always false) until the delay provided expires. If it is called after a previous call with the same index and the delay of the previous call already expired, it will act as it was the first call again.
429 */
430 CB_Touch.delay = function(delayMs, index)
431 {
432 if (!index) { index = 0; }
433 if (CB_Touch._delayPerforming[index]) { return false; }
434 clearTimeout(CB_Touch._delayTimeout[index]);
435 CB_Touch._delayPerforming[index] = true;
436 if (typeof(delayMs) === "undefined" || delayMs === null || isNaN(delayMs)) { delayMs = CB_Touch._delayMsDefault; }
437 CB_Touch._delayTimeout[index] = setTimeout(function() { CB_Touch._delayPerforming[index] = false; }, delayMs);
438 return true;
439 }
440
441}</pre>
442 </article>
443</section>
444
445
446
447
448
449 </div>
450 </div>
451
452 <div class="clearfix"></div>
453
454
455
456</div>
457</div>
458
459
460 <div class="modal fade" id="searchResults">
461 <div class="modal-dialog">
462 <div class="modal-content">
463 <div class="modal-header">
464 <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
465 <h4 class="modal-title">Search results</h4>
466 </div>
467 <div class="modal-body"></div>
468 <div class="modal-footer">
469 <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
470 </div>
471 </div><!-- /.modal-content -->
472 </div><!-- /.modal-dialog -->
473 </div>
474
475
476<footer>
477
478
479 <span class="copyright">
480 <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>
481 </span>
482
483<span class="jsdoc-message">
484 Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.5.5</a>
485
486 on Mon Feb 3rd 2020
487
488 using the <a href="https://github.com/docstrap/docstrap">DocStrap template</a>.
489</span>
490</footer>
491
492<script src="scripts/docstrap.lib.js"></script>
493<script src="scripts/toc.js"></script>
494
495 <script type="text/javascript" src="scripts/fulltext-search-ui.js"></script>
496
497
498<script>
499$( function () {
500 $( "[id*='$']" ).each( function () {
501 var $this = $( this );
502
503 $this.attr( "id", $this.attr( "id" ).replace( "$", "__" ) );
504 } );
505
506 $( ".tutorial-section pre, .readme-section pre, pre.prettyprint.source" ).each( function () {
507 var $this = $( this );
508
509 var example = $this.find( "code" );
510 exampleText = example.html();
511 var lang = /{@lang (.*?)}/.exec( exampleText );
512 if ( lang && lang[1] ) {
513 exampleText = exampleText.replace( lang[0], "" );
514 example.html( exampleText );
515 lang = lang[1];
516 } else {
517 var langClassMatch = example.parent()[0].className.match(/lang\-(\S+)/);
518 lang = langClassMatch ? langClassMatch[1] : "javascript";
519 }
520
521 if ( lang ) {
522
523 $this
524 .addClass( "sunlight-highlight-" + lang )
525 .addClass( "linenums" )
526 .html( example.html() );
527
528 }
529 } );
530
531 Sunlight.highlightAll( {
532 lineNumbers : true,
533 showMenu : true,
534 enableDoclinks : true
535 } );
536
537 $.catchAnchorLinks( {
538 navbarOffset: 10
539 } );
540 $( "#toc" ).toc( {
541 anchorName : function ( i, heading, prefix ) {
542 return $( heading ).attr( "id" ) || ( prefix + i );
543 },
544 selectors : "#toc-content h1,#toc-content h2,#toc-content h3,#toc-content h4",
545 showAndHide : false,
546 smoothScrolling: true
547 } );
548
549 $( "#main span[id^='toc']" ).addClass( "toc-shim" );
550 $( '.dropdown-toggle' ).dropdown();
551
552 $( "table" ).each( function () {
553 var $this = $( this );
554 $this.addClass('table');
555 } );
556
557} );
558</script>
559
560
561
562<!--Navigation and Symbol Display-->
563
564<script>
565 $( function () {
566 $( '#main' ).localScroll( {
567 offset : { top : 60 } //offset by the height of your header (give or take a few px, see what works for you)
568 } );
569 $( "dt.name" ).each( function () {
570 var $this = $( this ).find("h4");
571 var icon = $( "<i/>" ).addClass( "icon-plus-sign" ).addClass( "pull-right" ).addClass( "icon-white" );
572 var dt = $(this);
573 var children = dt.next( "dd" );
574
575 dt.prepend( icon ).css( {cursor : "pointer"} );
576 dt.addClass( "member-collapsed" ).addClass( "member" );
577
578
579 children.hide();
580
581 dt.children().on( "click", function () {
582 children = dt.next( "dd" );
583 children.slideToggle( "fast", function () {
584
585 if ( children.is( ":visible" ) ) {
586 icon.addClass( "icon-minus-sign" ).removeClass( "icon-plus-sign" ).removeClass( "icon-white" );
587 dt.addClass( "member-open" ).animate( "member-collapsed" );
588 } else {
589 icon.addClass( "icon-plus-sign" ).removeClass( "icon-minus-sign" ).addClass( "icon-white" );
590 dt.addClass( "member-collapsed" ).removeClass( "member-open" );
591 }
592 } );
593 } );
594
595 } );
596 } );
597</script>
598
599
600<!--Google Analytics-->
601
602
603
604 <script type="text/javascript">
605 $(document).ready(function() {
606 SearcherDisplay.init();
607 });
608 </script>
609
610
611</body>
612</html>