all repos — simplyrpg @ 05a250383b5037effb602fc3ca4d2bb1cdf4da90

Fork of https://github.com/harperd1/simplyRPG — multi-map VTT, token visibility, dark theme, stream HUD

libraries/EaselJS_docs/files/easeljs_ui_Touch.js.html (view raw)

  1<!DOCTYPE html>
  2<html lang="en">
  3<head>
  4    <meta charset="utf-8">
  5    <link rel="stylesheet" href="../assets/css/yui-cssgrids-min.css">
  6    <link rel="stylesheet" href="../assets/vendor/prettify/prettify-min.css">
  7    <link rel="stylesheet" href="../assets/css/main.css" id="site_styles">
  8    <link rel="shortcut icon" type="image/x-icon" href="../assets/favicon.ico">
  9    <script src="../assets/js/yui-source.js"></script>
 10	<title>EaselJS v1.0.0 API Documentation : easeljs/ui/Touch.js</title>
 11</head>
 12<body class="yui3-skin-sam">
 13
 14<div id="doc">
 15    <div id="hd" class="yui3-g header">
 16        <div class="yui3-u-3-4">
 17            
 18                <h1><a href="http://www.createjs.com/easeljs"><img src="../assets/docs-icon-EaselJS.png" title="EaselJS"></a></h1>
 19            
 20        </div>
 21        <div class="version">
 22            <em>API Documentation for: 1.0.0</em>
 23        </div>
 24    </div>
 25    <div id="bd" class="yui3-g">
 26
 27        <div class="yui3-u-1-4">
 28            <div id="docs-sidebar" class="sidebar apidocs">
 29                <div id="api-list">
 30    <h2 class="off-left">APIs</h2>
 31    <div id="api-tabview" class="tabview">
 32        <ul class="tabs">
 33            <li><a href="#api-classes">Classes</a></li>
 34        </ul>
 35
 36        <div id="api-tabview-filter">
 37            <input type="search" id="api-filter" placeholder="Type to filter APIs">
 38        </div>
 39
 40        <div id="api-tabview-panel">
 41            <ul id="api-classes" class="apis classes">
 42            
 43                <li><a href="../classes/AlphaMapFilter.html">AlphaMapFilter</a></li>
 44            
 45                <li><a href="../classes/AlphaMaskFilter.html">AlphaMaskFilter</a></li>
 46            
 47                <li><a href="../classes/Bitmap.html">Bitmap</a></li>
 48            
 49                <li><a href="../classes/BitmapCache.html">BitmapCache</a></li>
 50            
 51                <li><a href="../classes/BitmapText.html">BitmapText</a></li>
 52            
 53                <li><a href="../classes/BlurFilter.html">BlurFilter</a></li>
 54            
 55                <li><a href="../classes/ButtonHelper.html">ButtonHelper</a></li>
 56            
 57                <li><a href="../classes/ColorFilter.html">ColorFilter</a></li>
 58            
 59                <li><a href="../classes/ColorMatrix.html">ColorMatrix</a></li>
 60            
 61                <li><a href="../classes/ColorMatrixFilter.html">ColorMatrixFilter</a></li>
 62            
 63                <li><a href="../classes/Container.html">Container</a></li>
 64            
 65                <li><a href="../classes/DisplayObject.html">DisplayObject</a></li>
 66            
 67                <li><a href="../classes/DisplayProps.html">DisplayProps</a></li>
 68            
 69                <li><a href="../classes/DOMElement.html">DOMElement</a></li>
 70            
 71                <li><a href="../classes/EaselJS.html">EaselJS</a></li>
 72            
 73                <li><a href="../classes/Event.html">Event</a></li>
 74            
 75                <li><a href="../classes/EventDispatcher.html">EventDispatcher</a></li>
 76            
 77                <li><a href="../classes/Filter.html">Filter</a></li>
 78            
 79                <li><a href="../classes/Graphics.html">Graphics</a></li>
 80            
 81                <li><a href="../classes/Graphics.Arc.html">Graphics.Arc</a></li>
 82            
 83                <li><a href="../classes/Graphics.ArcTo.html">Graphics.ArcTo</a></li>
 84            
 85                <li><a href="../classes/Graphics.BeginPath.html">Graphics.BeginPath</a></li>
 86            
 87                <li><a href="../classes/Graphics.BezierCurveTo.html">Graphics.BezierCurveTo</a></li>
 88            
 89                <li><a href="../classes/Graphics.Circle.html">Graphics.Circle</a></li>
 90            
 91                <li><a href="../classes/Graphics.ClosePath.html">Graphics.ClosePath</a></li>
 92            
 93                <li><a href="../classes/Graphics.Ellipse.html">Graphics.Ellipse</a></li>
 94            
 95                <li><a href="../classes/Graphics.Fill.html">Graphics.Fill</a></li>
 96            
 97                <li><a href="../classes/Graphics.LineTo.html">Graphics.LineTo</a></li>
 98            
 99                <li><a href="../classes/Graphics.MoveTo.html">Graphics.MoveTo</a></li>
100            
101                <li><a href="../classes/Graphics.PolyStar.html">Graphics.PolyStar</a></li>
102            
103                <li><a href="../classes/Graphics.QuadraticCurveTo.html">Graphics.QuadraticCurveTo</a></li>
104            
105                <li><a href="../classes/Graphics.Rect.html">Graphics.Rect</a></li>
106            
107                <li><a href="../classes/Graphics.RoundRect.html">Graphics.RoundRect</a></li>
108            
109                <li><a href="../classes/Graphics.Stroke.html">Graphics.Stroke</a></li>
110            
111                <li><a href="../classes/Graphics.StrokeDash.html">Graphics.StrokeDash</a></li>
112            
113                <li><a href="../classes/Graphics.StrokeStyle.html">Graphics.StrokeStyle</a></li>
114            
115                <li><a href="../classes/Matrix2D.html">Matrix2D</a></li>
116            
117                <li><a href="../classes/MouseEvent.html">MouseEvent</a></li>
118            
119                <li><a href="../classes/MovieClip.html">MovieClip</a></li>
120            
121                <li><a href="../classes/MovieClipPlugin.html">MovieClipPlugin</a></li>
122            
123                <li><a href="../classes/Point.html">Point</a></li>
124            
125                <li><a href="../classes/Rectangle.html">Rectangle</a></li>
126            
127                <li><a href="../classes/Shadow.html">Shadow</a></li>
128            
129                <li><a href="../classes/Shape.html">Shape</a></li>
130            
131                <li><a href="../classes/Sprite.html">Sprite</a></li>
132            
133                <li><a href="../classes/SpriteSheet.html">SpriteSheet</a></li>
134            
135                <li><a href="../classes/SpriteSheetBuilder.html">SpriteSheetBuilder</a></li>
136            
137                <li><a href="../classes/SpriteSheetUtils.html">SpriteSheetUtils</a></li>
138            
139                <li><a href="../classes/Stage.html">Stage</a></li>
140            
141                <li><a href="../classes/StageGL.html">StageGL</a></li>
142            
143                <li><a href="../classes/Text.html">Text</a></li>
144            
145                <li><a href="../classes/Ticker.html">Ticker</a></li>
146            
147                <li><a href="../classes/Touch.html">Touch</a></li>
148            
149                <li><a href="../classes/UID.html">UID</a></li>
150            
151                <li><a href="../classes/Utility Methods.html">Utility Methods</a></li>
152            
153                <li><a href="../classes/VideoBuffer.html">VideoBuffer</a></li>
154            
155                <li><a href="../classes/WebGLInspector.html">WebGLInspector</a></li>
156            
157            </ul>
158
159            <ul id="api-modules" class="apis modules">
160            
161                <li><a href="../modules/CreateJS.html">CreateJS</a></li>
162            
163                <li><a href="../modules/EaselJS.html">EaselJS</a></li>
164            
165            </ul>
166        </div>
167    </div>
168</div>
169
170            </div>
171        </div>
172        <div class="yui3-u-3-4">
173            <div id="api-options">
174        Show:
175        <label for="api-show-inherited">
176            <input type="checkbox" id="api-show-inherited" checked>
177            Inherited
178        </label>
179
180        <label for="api-show-protected">
181            <input type="checkbox" id="api-show-protected">
182            Protected
183        </label>
184
185        <label for="api-show-private">
186            <input type="checkbox" id="api-show-private">
187            Private
188        </label>
189        <label for="api-show-deprecated">
190            <input type="checkbox" id="api-show-deprecated">
191            Deprecated
192        </label>
193
194    </div>
195            <div class="apidocs">
196                <div id="docs-main">
197                    <div class="content source-content">
198                        <script>
199	var name = easeljs/ui/Touch.js      
200</script>
201<h1 class="file-heading">File:Touch.js</h1>
202
203<div class="file">
204    <pre class="code prettyprint linenums">
205/*
206* Touch
207* Visit http://createjs.com/ for documentation, updates and examples.
208*
209* Copyright (c) 2010 gskinner.com, inc.
210*
211* Permission is hereby granted, free of charge, to any person
212* obtaining a copy of this software and associated documentation
213* files (the &quot;Software&quot;), to deal in the Software without
214* restriction, including without limitation the rights to use,
215* copy, modify, merge, publish, distribute, sublicense, and/or sell
216* copies of the Software, and to permit persons to whom the
217* Software is furnished to do so, subject to the following
218* conditions:
219*
220* The above copyright notice and this permission notice shall be
221* included in all copies or substantial portions of the Software.
222*
223* THE SOFTWARE IS PROVIDED &quot;AS IS&quot;, WITHOUT WARRANTY OF ANY KIND,
224* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
225* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
226* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
227* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
228* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
229* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
230* OTHER DEALINGS IN THE SOFTWARE.
231*/
232
233/**
234 * @module EaselJS
235 */
236
237// namespace:
238this.createjs = this.createjs||{};
239
240(function() {
241	&quot;use strict&quot;;
242
243
244// constructor:
245	/**
246 * Global utility for working with multi-touch enabled devices in EaselJS. Currently supports W3C Touch API (iOS and
247 * modern Android browser) and the Pointer API (IE), including ms-prefixed events in IE10, and unprefixed in IE11.
248 *
249 * Ensure that you {{#crossLink &quot;Touch/disable&quot;}}{{/crossLink}} touch when cleaning up your application. You do not have
250 * to check if touch is supported to enable it, as it will fail gracefully if it is not supported.
251 *
252 * &lt;h4&gt;Example&lt;/h4&gt;
253 *
254 *      var stage = new createjs.Stage(&quot;canvasId&quot;);
255 *      createjs.Touch.enable(stage);
256 *
257 * &lt;strong&gt;Note:&lt;/strong&gt; It is important to disable Touch on a stage that you are no longer using:
258 *
259 *      createjs.Touch.disable(stage);
260 *
261 * @class Touch
262 * @static
263 **/
264	function Touch() {
265		throw &quot;Touch cannot be instantiated&quot;;
266	}
267
268
269// public static methods:
270	/**
271	 * Returns &#x60;true&#x60; if touch is supported in the current browser.
272	 * @method isSupported
273	 * @return {Boolean} Indicates whether touch is supported in the current browser.
274	 * @static
275	 **/
276	Touch.isSupported = function() {
277		return	!!((&#x27;ontouchstart&#x27; in window) // iOS &amp; Android
278			|| (window.navigator[&#x27;msPointerEnabled&#x27;] &amp;&amp; window.navigator[&#x27;msMaxTouchPoints&#x27;] &gt; 0) // IE10
279			|| (window.navigator[&#x27;pointerEnabled&#x27;] &amp;&amp; window.navigator[&#x27;maxTouchPoints&#x27;] &gt; 0)); // IE11+
280	};
281
282	/**
283	 * Enables touch interaction for the specified EaselJS {{#crossLink &quot;Stage&quot;}}{{/crossLink}}. Currently supports iOS
284	 * (and compatible browsers, such as modern Android browsers), and IE10/11. Supports both single touch and
285	 * multi-touch modes. Extends the EaselJS {{#crossLink &quot;MouseEvent&quot;}}{{/crossLink}} model, but without support for
286	 * double click or over/out events. See the MouseEvent {{#crossLink &quot;MouseEvent/pointerId:property&quot;}}{{/crossLink}}
287	 * for more information.
288	 * @method enable
289	 * @param {Stage} stage The {{#crossLink &quot;Stage&quot;}}{{/crossLink}} to enable touch on.
290	 * @param {Boolean} [singleTouch=false] If &#x60;true&#x60;, only a single touch will be active at a time.
291	 * @param {Boolean} [allowDefault=false] If &#x60;true&#x60;, then default gesture actions (ex. scrolling, zooming) will be
292	 * allowed when the user is interacting with the target canvas.
293	 * @return {Boolean} Returns &#x60;true&#x60; if touch was successfully enabled on the target stage.
294	 * @static
295	 **/
296	Touch.enable = function(stage, singleTouch, allowDefault) {
297		if (!stage || !stage.canvas || !Touch.isSupported()) { return false; }
298		if (stage.__touch) { return true; }
299
300		// inject required properties on stage:
301		stage.__touch = {pointers:{}, multitouch:!singleTouch, preventDefault:!allowDefault, count:0};
302
303		// note that in the future we may need to disable the standard mouse event model before adding
304		// these to prevent duplicate calls. It doesn&#x27;t seem to be an issue with iOS devices though.
305		if (&#x27;ontouchstart&#x27; in window) { Touch._IOS_enable(stage); }
306		else if (window.navigator[&#x27;msPointerEnabled&#x27;] || window.navigator[&quot;pointerEnabled&quot;]) { Touch._IE_enable(stage); }
307		return true;
308	};
309
310	/**
311	 * Removes all listeners that were set up when calling &#x60;Touch.enable()&#x60; on a stage.
312	 * @method disable
313	 * @param {Stage} stage The {{#crossLink &quot;Stage&quot;}}{{/crossLink}} to disable touch on.
314	 * @static
315	 **/
316	Touch.disable = function(stage) {
317		if (!stage) { return; }
318		if (&#x27;ontouchstart&#x27; in window) { Touch._IOS_disable(stage); }
319		else if (window.navigator[&#x27;msPointerEnabled&#x27;] || window.navigator[&quot;pointerEnabled&quot;]) { Touch._IE_disable(stage); }
320		
321		delete stage.__touch;
322	};
323
324
325// Private static methods:
326	/**
327	 * @method _IOS_enable
328	 * @protected
329	 * @param {Stage} stage
330	 * @static
331	 **/
332	Touch._IOS_enable = function(stage) {
333		var canvas = stage.canvas;
334		var f = stage.__touch.f = function(e) { Touch._IOS_handleEvent(stage,e); };
335		canvas.addEventListener(&quot;touchstart&quot;, f, false);
336		canvas.addEventListener(&quot;touchmove&quot;, f, false);
337		canvas.addEventListener(&quot;touchend&quot;, f, false);
338		canvas.addEventListener(&quot;touchcancel&quot;, f, false);
339	};
340
341	/**
342	 * @method _IOS_disable
343	 * @protected
344	 * @param {Stage} stage
345	 * @static
346	 **/
347	Touch._IOS_disable = function(stage) {
348		var canvas = stage.canvas;
349		if (!canvas) { return; }
350		var f = stage.__touch.f;
351		canvas.removeEventListener(&quot;touchstart&quot;, f, false);
352		canvas.removeEventListener(&quot;touchmove&quot;, f, false);
353		canvas.removeEventListener(&quot;touchend&quot;, f, false);
354		canvas.removeEventListener(&quot;touchcancel&quot;, f, false);
355	};
356
357	/**
358	 * @method _IOS_handleEvent
359	 * @param {Stage} stage
360	 * @param {Object} e The event to handle
361	 * @protected
362	 * @static
363	 **/
364	Touch._IOS_handleEvent = function(stage, e) {
365		if (!stage) { return; }
366		if (stage.__touch.preventDefault) { e.preventDefault&amp;&amp;e.preventDefault(); }
367		var touches = e.changedTouches;
368		var type = e.type;
369		for (var i= 0,l=touches.length; i&lt;l; i++) {
370			var touch = touches[i];
371			var id = touch.identifier;
372			if (touch.target != stage.canvas) { continue; }
373
374			if (type == &quot;touchstart&quot;) {
375				this._handleStart(stage, id, e, touch.pageX, touch.pageY);
376			} else if (type == &quot;touchmove&quot;) {
377				this._handleMove(stage, id, e, touch.pageX, touch.pageY);
378			} else if (type == &quot;touchend&quot; || type == &quot;touchcancel&quot;) {
379				this._handleEnd(stage, id, e);
380			}
381		}
382	};
383
384	/**
385	 * @method _IE_enable
386	 * @protected
387	 * @param {Stage} stage
388	 * @static
389	 **/
390	Touch._IE_enable = function(stage) {
391		var canvas = stage.canvas;
392		var f = stage.__touch.f = function(e) { Touch._IE_handleEvent(stage,e); };
393
394		if (window.navigator[&quot;pointerEnabled&quot;] === undefined) {
395			canvas.addEventListener(&quot;MSPointerDown&quot;, f, false);
396			window.addEventListener(&quot;MSPointerMove&quot;, f, false);
397			window.addEventListener(&quot;MSPointerUp&quot;, f, false);
398			window.addEventListener(&quot;MSPointerCancel&quot;, f, false);
399			if (stage.__touch.preventDefault) { canvas.style.msTouchAction = &quot;none&quot;; }
400		} else {
401			canvas.addEventListener(&quot;pointerdown&quot;, f, false);
402			window.addEventListener(&quot;pointermove&quot;, f, false);
403			window.addEventListener(&quot;pointerup&quot;, f, false);
404			window.addEventListener(&quot;pointercancel&quot;, f, false);
405			if (stage.__touch.preventDefault) { canvas.style.touchAction = &quot;none&quot;; }
406
407		}
408		stage.__touch.activeIDs = {};
409	};
410
411	/**
412	 * @method _IE_disable
413	 * @protected
414	 * @param {Stage} stage
415	 * @static
416	 **/
417	Touch._IE_disable = function(stage) {
418		var f = stage.__touch.f;
419
420		if (window.navigator[&quot;pointerEnabled&quot;] === undefined) {
421			window.removeEventListener(&quot;MSPointerMove&quot;, f, false);
422			window.removeEventListener(&quot;MSPointerUp&quot;, f, false);
423			window.removeEventListener(&quot;MSPointerCancel&quot;, f, false);
424			if (stage.canvas) {
425				stage.canvas.removeEventListener(&quot;MSPointerDown&quot;, f, false);
426			}
427		} else {
428			window.removeEventListener(&quot;pointermove&quot;, f, false);
429			window.removeEventListener(&quot;pointerup&quot;, f, false);
430			window.removeEventListener(&quot;pointercancel&quot;, f, false);
431			if (stage.canvas) {
432				stage.canvas.removeEventListener(&quot;pointerdown&quot;, f, false);
433			}
434		}
435	};
436
437	/**
438	 * @method _IE_handleEvent
439	 * @param {Stage} stage
440	 * @param {Object} e The event to handle.
441	 * @protected
442	 * @static
443	 **/
444	Touch._IE_handleEvent = function(stage, e) {
445		if (!stage) { return; }
446		if (stage.__touch.preventDefault) { e.preventDefault &amp;&amp; e.preventDefault(); }
447		var type = e.type;
448		var id = e.pointerId;
449		var ids = stage.__touch.activeIDs;
450
451		if (type == &quot;MSPointerDown&quot; || type == &quot;pointerdown&quot;) {
452			if (e.srcElement != stage.canvas) { return; }
453			ids[id] = true;
454			this._handleStart(stage, id, e, e.pageX, e.pageY);
455		} else if (ids[id]) { // it&#x27;s an id we&#x27;re watching
456			if (type == &quot;MSPointerMove&quot; || type == &quot;pointermove&quot;) {
457				this._handleMove(stage, id, e, e.pageX, e.pageY);
458			} else if (type == &quot;MSPointerUp&quot; || type == &quot;MSPointerCancel&quot;
459					|| type == &quot;pointerup&quot; || type == &quot;pointercancel&quot;) {
460				delete(ids[id]);
461				this._handleEnd(stage, id, e);
462			}
463		}
464	};
465
466	/**
467	 * @method _handleStart
468	 * @param {Stage} stage
469	 * @param {String|Number} id
470	 * @param {Object} e
471	 * @param {Number} x
472	 * @param {Number} y
473	 * @protected
474	 **/
475	Touch._handleStart = function(stage, id, e, x, y) {
476		var props = stage.__touch;
477		if (!props.multitouch &amp;&amp; props.count) { return; }
478		var ids = props.pointers;
479		if (ids[id]) { return; }
480		ids[id] = true;
481		props.count++;
482		stage._handlePointerDown(id, e, x, y);
483	};
484
485	/**
486	 * @method _handleMove
487	 * @param {Stage} stage
488	 * @param {String|Number} id
489	 * @param {Object} e
490	 * @param {Number} x
491	 * @param {Number} y
492	 * @protected
493	 **/
494	Touch._handleMove = function(stage, id, e, x, y) {
495		if (!stage.__touch.pointers[id]) { return; }
496		stage._handlePointerMove(id, e, x, y);
497	};
498
499	/**
500	 * @method _handleEnd
501	 * @param {Stage} stage
502	 * @param {String|Number} id
503	 * @param {Object} e
504	 * @protected
505	 **/
506	Touch._handleEnd = function(stage, id, e) {
507		// TODO: cancel should be handled differently for proper UI (ex. an up would trigger a click, a cancel would more closely resemble an out).
508		var props = stage.__touch;
509		var ids = props.pointers;
510		if (!ids[id]) { return; }
511		props.count--;
512		stage._handlePointerUp(id, e, true);
513		delete(ids[id]);
514	};
515
516
517	createjs.Touch = Touch;
518}());
519
520    </pre>
521</div>
522
523                    </div>
524                </div>
525            </div>
526        </div>
527    </div>
528</div>
529<script src="../assets/vendor/prettify/prettify-min.js"></script>
530<script>prettyPrint();</script>
531<script src="../assets/js/yui-prettify.js"></script>
532<script src="../assets/../api.js"></script>
533<script src="../assets/js/api-filter.js"></script>
534<script src="../assets/js/api-list.js"></script>
535<script src="../assets/js/api-search.js"></script>
536<script src="../assets/js/apidocs.js"></script>
537</body>
538</html>