libraries/EaselJS_docs/files/easeljs_display_DOMElement.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/display/DOMElement.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/display/DOMElement.js
200</script>
201<h1 class="file-heading">File:DOMElement.js</h1>
202
203<div class="file">
204 <pre class="code prettyprint linenums">
205/*
206* DOMElement
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 "Software"), 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 "AS IS", 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 "use strict";
242
243
244// constructor:
245 /**
246 * <b>This class is still experimental, and more advanced use is likely to be buggy. Please report bugs.</b>
247 *
248 * A DOMElement allows you to associate a HTMLElement with the display list. It will be transformed
249 * within the DOM as though it is child of the {{#crossLink "Container"}}{{/crossLink}} it is added to. However, it is
250 * not rendered to canvas, and as such will retain whatever z-index it has relative to the canvas (ie. it will be
251 * drawn in front of or behind the canvas).
252 *
253 * The position of a DOMElement is relative to their parent node in the DOM. It is recommended that
254 * the DOM Object be added to a div that also contains the canvas so that they share the same position
255 * on the page.
256 *
257 * DOMElement is useful for positioning HTML elements over top of canvas content, and for elements
258 * that you want to display outside the bounds of the canvas. For example, a tooltip with rich HTML
259 * content.
260 *
261 * <h4>Mouse Interaction</h4>
262 *
263 * DOMElement instances are not full EaselJS display objects, and do not participate in EaselJS mouse
264 * events or support methods like hitTest. To get mouse events from a DOMElement, you must instead add handlers to
265 * the htmlElement (note, this does not support EventDispatcher)
266 *
267 * var domElement = new createjs.DOMElement(htmlElement);
268 * domElement.htmlElement.onclick = function() {
269 * console.log("clicked");
270 * }
271 *
272 * <strong>Important:</strong> This class needs to be notified it is about to be drawn, this will happen automatically
273 * if you call stage.update, calling stage.draw or disabling tickEnabled will miss important steps and it will render
274 * stale information.
275 *
276 * @class DOMElement
277 * @extends DisplayObject
278 * @constructor
279 * @param {HTMLElement} htmlElement A reference or id for the DOM element to manage.
280 */
281 function DOMElement(htmlElement) {
282 this.DisplayObject_constructor();
283
284 if (typeof(htmlElement)=="string") { htmlElement = document.getElementById(htmlElement); }
285 this.mouseEnabled = false;
286
287 var style = htmlElement.style;
288 style.position = "absolute";
289 style.transformOrigin = style.WebkitTransformOrigin = style.msTransformOrigin = style.MozTransformOrigin = style.OTransformOrigin = "0% 0%";
290
291
292 // public properties:
293 /**
294 * The DOM object to manage.
295 * @property htmlElement
296 * @type HTMLElement
297 */
298 this.htmlElement = htmlElement;
299
300
301 // private properties:
302 /**
303 * @property _oldMtx
304 * @type Matrix2D
305 * @protected
306 */
307 this._oldProps = null;
308
309 /**
310 * Used to track the object which this class attached listeners to, helps optimize listener attachment.
311 * @property _oldStage
312 * @type Stage
313 * @protected
314 */
315 this._oldStage = null;
316 /**
317 * The event listener proxy triggered drawing draw for special circumstances.
318 * @property _drawAction
319 * @type function
320 * @protected
321 */
322 this._drawAction = null;
323 }
324 var p = createjs.extend(DOMElement, createjs.DisplayObject);
325
326 // TODO: deprecated
327 // p.initialize = function() {}; // searchable for devs wondering where it is. REMOVED. See docs for details.
328
329
330// public methods:
331 /**
332 * Returns true or false indicating whether the display object would be visible if drawn to a canvas.
333 * This does not account for whether it would be visible within the boundaries of the stage.
334 * NOTE: This method is mainly for internal use, though it may be useful for advanced uses.
335 * @method isVisible
336 * @return {Boolean} Boolean indicating whether the display object would be visible if drawn to a canvas
337 */
338 p.isVisible = function() {
339 return this.htmlElement != null;
340 };
341
342 /**
343 * Draws the display object into the specified context ignoring its visible, alpha, shadow, and transform.
344 * Returns true if the draw was handled (useful for overriding functionality).
345 * NOTE: This method is mainly for internal use, though it may be useful for advanced uses.
346 * @method draw
347 * @param {CanvasRenderingContext2D} ctx The canvas 2D context object to draw into.
348 * @param {Boolean} ignoreCache Indicates whether the draw operation should ignore any current cache.
349 * For example, used for drawing the cache (to prevent it from simply drawing an existing cache back
350 * into itself).
351 * @return {Boolean}
352 */
353 p.draw = function(ctx, ignoreCache) {
354 // this relies on the _tick method because draw isn't called if the parent is not visible.
355 // the actual update happens in _handleDrawEnd
356 return true;
357 };
358
359 /**
360 * Not applicable to DOMElement.
361 * @method cache
362 */
363 p.cache = function() {};
364
365 /**
366 * Not applicable to DOMElement.
367 * @method uncache
368 */
369 p.uncache = function() {};
370
371 /**
372 * Not applicable to DOMElement.
373 * @method updateCache
374 */
375 p.updateCache = function() {};
376
377 /**
378 * Not applicable to DOMElement.
379 * @method hitTest
380 */
381 p.hitTest = function() {};
382
383 /**
384 * Not applicable to DOMElement.
385 * @method localToGlobal
386 */
387 p.localToGlobal = function() {};
388
389 /**
390 * Not applicable to DOMElement.
391 * @method globalToLocal
392 */
393 p.globalToLocal = function() {};
394
395 /**
396 * Not applicable to DOMElement.
397 * @method localToLocal
398 */
399 p.localToLocal = function() {};
400
401 /**
402 * DOMElement cannot be cloned. Throws an error.
403 * @method clone
404 */
405 p.clone = function() {
406 throw("DOMElement cannot be cloned.")
407 };
408
409 /**
410 * Returns a string representation of this object.
411 * @method toString
412 * @return {String} a string representation of the instance.
413 */
414 p.toString = function() {
415 return "[DOMElement (name="+ this.name +")]";
416 };
417
418 /**
419 * Interaction events should be added to `htmlElement`, and not the DOMElement instance, since DOMElement instances
420 * are not full EaselJS display objects and do not participate in EaselJS mouse events.
421 * @event click
422 */
423
424 /**
425 * Interaction events should be added to `htmlElement`, and not the DOMElement instance, since DOMElement instances
426 * are not full EaselJS display objects and do not participate in EaselJS mouse events.
427 * @event dblClick
428 */
429
430 /**
431 * Interaction events should be added to `htmlElement`, and not the DOMElement instance, since DOMElement instances
432 * are not full EaselJS display objects and do not participate in EaselJS mouse events.
433 * @event mousedown
434 */
435
436 /**
437 * The HTMLElement can listen for the mouseover event, not the DOMElement instance.
438 * Since DOMElement instances are not full EaselJS display objects and do not participate in EaselJS mouse events.
439 * @event mouseover
440 */
441
442 /**
443 * Not applicable to DOMElement.
444 * @event tick
445 */
446
447
448// private methods:
449 /**
450 * @method _tick
451 * @param {Object} evtObj An event object that will be dispatched to all tick listeners. This object is reused between dispatchers to reduce construction & GC costs.
452 * function.
453 * @protected
454 */
455 p._tick = function(evtObj) {
456 var stage = this.stage;
457 if(stage && stage !== this._oldStage) {
458 this._drawAction && stage.off("drawend", this._drawAction);
459 this._drawAction = stage.on("drawend", this._handleDrawEnd, this);
460 this._oldStage = stage;
461 }
462 this.DisplayObject__tick(evtObj);
463 };
464
465 /**
466 * @method _handleDrawEnd
467 * @param {Event} evt
468 * @protected
469 */
470 p._handleDrawEnd = function(evt) {
471 var o = this.htmlElement;
472 if (!o) { return; }
473 var style = o.style;
474
475 var props = this.getConcatenatedDisplayProps(this._props), mtx = props.matrix;
476
477 var visibility = props.visible ? "visible" : "hidden";
478 if (visibility != style.visibility) { style.visibility = visibility; }
479 if (!props.visible) { return; }
480
481 var oldProps = this._oldProps, oldMtx = oldProps&&oldProps.matrix;
482 var n = 10000; // precision
483
484 if (!oldMtx || !oldMtx.equals(mtx)) {
485 var str = "matrix(" + (mtx.a*n|0)/n +","+ (mtx.b*n|0)/n +","+ (mtx.c*n|0)/n +","+ (mtx.d*n|0)/n +","+ (mtx.tx+0.5|0);
486 style.transform = style.WebkitTransform = style.OTransform = style.msTransform = str +","+ (mtx.ty+0.5|0) +")";
487 style.MozTransform = str +"px,"+ (mtx.ty+0.5|0) +"px)";
488 if (!oldProps) { oldProps = this._oldProps = new createjs.DisplayProps(true, null); }
489 oldProps.matrix.copy(mtx);
490 }
491
492 if (oldProps.alpha != props.alpha) {
493 style.opacity = ""+(props.alpha*n|0)/n;
494 oldProps.alpha = props.alpha;
495 }
496 };
497
498
499 createjs.DOMElement = createjs.promote(DOMElement, "DisplayObject");
500}());
501
502 </pre>
503</div>
504
505 </div>
506 </div>
507 </div>
508 </div>
509 </div>
510</div>
511<script src="../assets/vendor/prettify/prettify-min.js"></script>
512<script>prettyPrint();</script>
513<script src="../assets/js/yui-prettify.js"></script>
514<script src="../assets/../api.js"></script>
515<script src="../assets/js/api-filter.js"></script>
516<script src="../assets/js/api-list.js"></script>
517<script src="../assets/js/api-search.js"></script>
518<script src="../assets/js/apidocs.js"></script>
519</body>
520</html>