UNPKG

90.2 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_Mouse.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_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><li><a href="CB_baseSymbols.html">CB_baseSymbols</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_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_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_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_BASE_NAME">CB_BASE_NAME</a></li><li><a href="global.html#CB_CREDITS_DEFAULT">CB_CREDITS_DEFAULT</a></li><li><a href="global.html#CB_NAME">CB_NAME</a></li><li><a href="global.html#CB_OPTIONS">CB_OPTIONS</a></li><li><a href="global.html#CB_VERSION">CB_VERSION</a></li><li><a href="global.html#CB_addCredits">CB_addCredits</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_forEach">CB_forEach</a></li><li><a href="global.html#CB_forceString">CB_forceString</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_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_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>
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_Mouse.js</h1>
83
84<section>
85 <article>
86 <pre
87 class="sunlight-highlight-javascript linenums">/**
88 * @file Mouse and related management. Contains the {@link CB_Mouse} 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 mouse and related. It will return itself if it is tried to be instantiated.
96 * @namespace
97 */
98var CB_Mouse = function() { return CB_Mouse; };
99{
100 CB_Mouse.initialized = false; //It will tells whether the object has been initialized or not.
101
102 CB_Mouse._x = 0; //Keeps the X position of the mouse (relative to the window).
103 CB_Mouse._y = 0; //Keeps the X position of the mouse (relative to the window).
104 CB_Mouse._xMovement = 0; //Keeps the X movement of the mouser when its pointer is locked.
105 CB_Mouse._yMovement = 0; //Keeps the Y movement of the mouser when its pointer is locked.
106 CB_Mouse._buttonsDown = { LEFT : false, MIDDLE : false, RIGHT : false }; //Object with the buttons of the mouse which being pressed.
107
108 CB_Mouse._isLockedNow = false; //Contains whether the mouse pointer is locked or not.
109 CB_Mouse._isLockedPrevious = false; //Contains whether the mouse pointer was locked before or not.
110 CB_Mouse._lockElement = null; //Contains the element that the mouse pointer is locked to (if any).
111
112 //CB_Mouse._showingCursor = {}; //Tells whether the cursor is showing or not (by default is showing).
113
114 /**
115 Property that keeps an object to manage the mouse cursor using a [DOM element]{@link https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement} containing an image for clients that do not support changing the cursor image by CSS.
116 &lt;br />
117 Caution: Performance could be dramatically decreased while using this workaround.
118 * @namespace CB_Mouse.CursorImage
119 */
120 CB_Mouse.CursorImage = {}; //Keeps the cursor object.
121 CB_Mouse.CursorImage._cursorImageDiv = null; //DIV that contains the IMG tag for the fake cursor image.
122 CB_Mouse.CursorImage._cursorImage = null; //IMG that contains the fake cursor image.
123 CB_Mouse.CursorImage._showCursorImage = false; //Defines whether the fake cursor image is shown or not.
124 CB_Mouse.CursorImage._cursorImageSpriteAnimationTimeout = null;
125
126
127 //Initializes all values:
128 CB_Mouse.init = function()
129 {
130 if (CB_Mouse.initialized) { return CB_Mouse; }
131
132 //The object has been initialized:
133 CB_Mouse.initialized = true;
134
135 //Adds event that updates X and Y position of the mouse when it moves (and moves the cursor image if it is necessary):
136 CB_Events.add(document, "mousemove", function(e) { e = CB_Mouse.normalizeEvent(e); CB_Mouse.getX(e); CB_Mouse.getY(e); CB_Mouse.CursorImage.move(); }, true, true, false);
137 CB_Events.add(window, "scroll", function() { CB_Mouse.CursorImage.move(); }, true, true, false);
138
139 //Sets the event that will check if a button is down:
140 CB_Events.add
141 (
142 document,
143 "mousedown",
144 function(e)
145 {
146 e = CB_Mouse.normalizeEvent(e);
147 //Uses setCapture/releaseCapture to force IE and Firefox to release mouse buttons when dragging outside the web client window:
148 //if (typeof(document.body) !== "undefined" &amp;&amp; typeof(document.body.setCapture) !== "undefined")
149 if (typeof(e.target) !== "undefined" &amp;&amp; typeof(e.target.setCapture) !== "undefined")
150 {
151 //document.body.setCapture();
152 e.target.setCapture();
153 }
154 CB_Mouse._updateButtonsDown(e, true);
155 },
156 true,
157 true,
158 false
159 );
160
161 //Sets the event that will check if a button is released:
162 CB_Events.add
163 (
164 document,
165 "mouseup",
166 function(e)
167 {
168 e = CB_Mouse.normalizeEvent(e);
169 //Uses setCapture/releaseCapture to force IE and Firefox to release mouse buttons when dragging outside the web client window:
170 //if (typeof(document.body) !== "undefined" &amp;&amp; typeof(document.body.releaseCapture) !== "undefined")
171 if (typeof(e.target) !== "undefined" &amp;&amp; typeof(e.target.releaseCapture) !== "undefined")
172 {
173 //document.body.releaseCapture();
174 e.target.releaseCapture();
175 }
176 CB_Mouse._updateButtonsDown(e, false);
177 },
178 true,
179 true,
180 false
181 );
182
183 //Sets the event for when the lock pointer status changes:
184 var onPointerLockChange =
185 function()
186 {
187 CB_Mouse.isLocked(true); //Also updates the cache of the current lock element (if any).
188 };
189 CB_Events.add(document, "pointerlockchange", onPointerLockChange, true, true, false);
190 CB_Events.add(document, "mozpointerlockchange", onPointerLockChange, true, true, false);
191 CB_Events.add(document, "webkitpointerlockchange", onPointerLockChange, true, true, false);
192 CB_Events.add(document, "pointerlocklost", onPointerLockChange, true, true, false);
193 CB_Events.add(document, "webkitpointerlocklost", onPointerLockChange, true, true, false);
194 CB_Events.add(document, "mozpointerlocklost", onPointerLockChange, true, true, false);
195
196 //Clears buttonsDown array when the mouse leaves the web client:
197 //CB_Events.add(window, "mouseleave", function() { CB_Mouse._buttonsDown = { LEFT : false, MIDDLE : false, RIGHT : false }; }, true, true, false);
198 //CB_Events.add(document, "mouseout", function() { CB_Mouse._buttonsDown = { LEFT : false, MIDDLE : false, RIGHT : false }; }, true, true, false);
199
200 //Sets the focus to force a mousemove event and get the proper mouse coordinates (some web clients at the start don't get the proper mouse coordinates):
201 CB_Screen.focus();
202
203 return CB_Mouse;
204 }
205
206
207 /**
208 * Tries to return the given [mouse event object]{@link https://developer.mozilla.org/en-US/docs/Web/API/MouseEvent} with some properties normalized (since different clients can use different values) and perhaps some new properties added (in the case they were missing), when possible. The new attached methods and properties may include polyfills, etc. It also calls the {@link CB_Events.normalize} function internally. Some properties added or affected could be [deltaX]{@link https://developer.mozilla.org/en-US/docs/Web/API/WheelEvent/deltaX}, [deltaY]{@link https://developer.mozilla.org/en-US/docs/Web/API/WheelEvent/deltaY}, [deltaZ]{@link https://developer.mozilla.org/en-US/docs/Web/API/WheelEvent/deltaZ}, [force]{@link https://developer.mozilla.org/es/docs/Web/API/MouseEvent/webkitForce}, [clientX]{@link https://developer.mozilla.org/en-US/docs/Web/API/MouseEvent/clientX}, [clientY]{@link https://developer.mozilla.org/en-US/docs/Web/API/MouseEvent/clientY}, etc.
209 * @function
210 * @param {Event} e - [Mouse event object]{@link https://developer.mozilla.org/en-US/docs/Web/API/MouseEvent}. If not provided, it will use the value of "event", "window.event", "Event" or an empty object ("{}").
211 * @returns {Event} Returns the [mouse event object]{@link https://developer.mozilla.org/en-US/docs/Web/API/MouseEvent} normalized.
212 * @todo Add more properties and methods to normalize ([pageX]{@link https://developer.mozilla.org/en-US/docs/Web/API/MouseEvent/pageX}, [pageY]{@link https://developer.mozilla.org/en-US/docs/Web/API/MouseEvent/pageY}, [offsetX]{@link https://developer.mozilla.org/en-US/docs/Web/API/MouseEvent/offsetX}, [offsetY]{@link https://developer.mozilla.org/en-US/docs/Web/API/MouseEvent/offsetY}, etc.).
213 */
214 CB_Mouse.normalizeEvent = function(e)
215 {
216 e = CB_Events.normalize(e);
217
218 //If wheel event is not supported, normalizes the event:
219 var onWheelEventName = CB_Mouse._getOnWheelEventName();
220 if (onWheelEventName !== "wheel")
221 {
222 if (typeof(e.type) !== "undefined" &amp;&amp; e.type === "MozMousePixelScroll")
223 {
224 e.deltaMode = 0;
225 }
226 else
227 {
228 e.deltaMode = 1;
229 }
230
231 if (typeof(e.deltaX) === "undefined") { e.deltaX = 0; }
232 if (typeof(e.deltaZ) === "undefined") { e.deltaZ = 0; }
233 if (typeof(e.deltaY) === "undefined")
234 {
235 if (onWheelEventName === "mousewheel" &amp;&amp; typeof(e.wheelDelta) !== "undefined")
236 {
237 e.deltaY = -(1/40 * e.wheelDelta);
238 //e.deltaY = e.wheelDelta / -40;
239 //e.deltaY = e.wheelDelta / 120;
240 if (typeof(e.wheelDeltaX) !== "undefined")
241 {
242 event.deltaX = -(1/40 * e.wheelDeltaX);
243 }
244 }
245 else if (typeof(e.detail) !== "undefined")
246 {
247 e.deltaY = e.detail;
248 //e.deltaY = -40 * e.detail;
249 //e.deltaY = e.detail * -120;
250 //e.deltaY = -e.detail / 3;
251 }
252 else
253 {
254 e.deltaY = 0;
255 }
256 }
257 }
258
259 //Normalizes the force property (if any):
260 if (typeof(e.force) === "undefined" || e.force === null || isNaN(e.force))
261 {
262 if (typeof(e.webkitForce) !== "undefined" &amp;&amp; e.webkitForce !== null &amp;&amp; !isNaN(e.webkitForce)) { e.force = e.webkitForce; }
263 else if (CB_Touch._force !== null) { e.force = CB_Touch._force; } //Uses force detected by Pressure.js.
264 }
265 if (!e.forceNormalized) { e.force = CB_Touch.normalizeForce(e.force); }
266 e.forceNormalized = true;
267
268 //TODO: add more properties and methods to normalize (pageX, pageY, offsetX, offsetY, ).
269
270 //Normalize other properties:
271 //* Source: http://www.jacklmoore.com/notes/mouse-position/
272 if (typeof(e.clientX) === "undefined" &amp;&amp; typeof(e.pageX) !== "undefined") { e.clientX = e.pageX; }
273 if (typeof(e.clientY) === "undefined" &amp;&amp; typeof(e.pageY) !== "undefined") { e.clientY = e.pageY; }
274 if (document.body &amp;&amp; document.documentElement)
275 {
276 if (typeof(e.pageX) === "undefined" &amp;&amp; typeof(e.clientX) !== "undefined")
277 {
278 if (typeof(document.body.scrollLeft) !== "undefined" &amp;&amp; typeof(document.documentElement.scrollLeft) !== "undefined")
279 {
280 e.pageX = e.clientX + (document.body.scrollLeft) + document.documentElement.scrollLeft;
281 }
282 else if (typeof(document.body.scrollWidth) !== "undefined" &amp;&amp; typeof(document.documentElement.scrollWidth) !== "undefined")
283 {
284 e.pageX = e.clientX + (document.body.scrollWidth) + document.documentElement.scrollWidth;
285 }
286 }
287 if (typeof(e.pageY) === "undefined" &amp;&amp; typeof(e.clientY) !== "undefined")
288 {
289 if (typeof(document.body.scrollTop) !== "undefined" &amp;&amp; typeof(document.documentElement.scrollTop) !== "undefined")
290 {
291 e.pageY = e.clientY + (document.body.scrollTop) + document.documentElement.scrollTop;
292 }
293 else if (typeof(document.body.scrollHeight) !== "undefined" &amp;&amp; typeof(document.documentElement.scrollHeight) !== "undefined")
294 {
295 e.pageY = e.clientY + (document.body.scrollHeight) + document.documentElement.scrollHeight;
296 }
297 }
298 }
299 try
300 {
301 var targetStyle = CB_Elements.getStyle(e.target, true);
302 } catch(E) {}
303 if (targetStyle !== null &amp;&amp; typeof(e.clientX) !== "undefined" &amp;&amp; e.clientX !== null &amp;&amp; typeof(e.clientY) !== "undefined" &amp;&amp; e.clientY !== null)
304 {
305 try
306 {
307 e.offsetX = e.clientX - parseInt(targetStyle['borderLeftWidth'], 10) - CB_Client.getBoundingClientRectMargin("left");
308 e.offsetY = e.clientY - parseInt(targetStyle['borderTopWidth'], 10) - CB_Client.getBoundingClientRectMargin("top");
309 } catch(E) {}
310 }
311
312 return e;
313 }
314
315
316 CB_Mouse._getOnWheelEventNameReturnCache = null;
317 CB_Mouse._getOnWheelEventName = function()
318 {
319 if (typeof(CB_Mouse._getOnWheelEventNameReturnCache) === "undefined" || CB_Mouse._getOnWheelEventNameReturnCache === null)
320 {
321 CB_Mouse._getOnWheelEventNameReturnCache =
322 ("onwheel" in document.createElement("div")) ? "wheel" : //"wheel" supported.
323 (typeof(document.onmousewheel) !== "undefined") ? "mousewheel" : //"onmousewheel" supported.
324 "DOMMouseScroll"; //assumes "DOMMouseScroll" support.
325 }
326 return CB_Mouse._getOnWheelEventNameReturnCache;
327 }
328
329
330 //Returns which button is down given a mouse event:
331 CB_Mouse._updateButtonsDown = function(e, buttonDown)
332 {
333 e = CB_Mouse.normalizeEvent(e);
334
335 var buttonsDown = CB_Mouse._buttonsDown;
336
337 if (e.which)
338 {
339 if (e.which === 1) { buttonsDown.LEFT = buttonDown; }
340 else if (CB_Client.getBrowser() === "Opera" &amp;&amp; CB_Client.getBrowserVersionMain() &lt; 8)
341 {
342 if (e.which === 2) { buttonsDown.RIGHT = buttonDown; }
343 else if (e.which === 3) { buttonsDown.MIDDLE = buttonDown; }
344 }
345 else
346 {
347 if (e.which === 2) { buttonsDown.MIDDLE = buttonDown; }
348 else if (e.which === 3) { buttonsDown.RIGHT = buttonDown; }
349 }
350 }
351 else if (e.button)
352 {
353 if (CB_Client.getBrowser() === "Explorer")
354 {
355 //TODO: think about performing bitwise operations.
356 if (e.button === 1) { buttonsDown.LEFT = buttonDown; }
357 else if (e.button === 2) { buttonsDown.RIGHT = buttonDown; }
358 else if (e.button === 3) { buttonsDown.LEFT = buttonsDown.RIGHT = buttonDown; }
359 else if (e.button === 4) { buttonsDown.MIDDLE = buttonDown; }
360 else if (e.button === 5) { buttonsDown.LEFT = buttonsDown.MIDDLE = buttonDown; }
361 else if (e.button === 6) { buttonsDown.RIGHT = buttonsDown.MIDDLE = buttonDown; }
362 else if (e.button === 7) { buttonsDown.LEFT = buttonsDown.RIGHT = buttonsDown.MIDDLE = buttonDown; }
363 //else if (e.button === 0) { buttonsDown.LEFT = buttonsDown.RIGHT = buttonsDown.MIDDLE = false; }
364 }
365 else
366 {
367 if (e.button === 0) { buttonsDown.LEFT = buttonDown; }
368 else if (e.button === 1) { buttonsDown.MIDDLE = buttonDown; }
369 else if (e.button === 2) { buttonsDown.RIGHT = buttonDown; }
370 }
371 }
372
373 CB_Mouse._buttonsDown = buttonsDown;
374 }
375
376
377 /**
378 * Alias for {@link CB_Client.getButtons}.
379 * @function CB_Client.getButtonsDown
380 * @see {@link CB_Client.getButtons}
381 */
382 /**
383 * Tells what mouse buttons are down (LEFT, MIDDLE and/or RIGHT buttons).
384 * @function
385 * @returns {Object} Returns an object using the following format (where "true" means that the button is being pressed): { LEFT : boolean, MIDDLE : boolean, RIGHT : boolean }
386 */
387 CB_Mouse.getButtons = CB_Mouse.getButtonsDown = function()
388 {
389 return CB_Mouse._buttonsDown;
390 }
391
392
393 /**
394 * Gets and returns the X coordinate (horizontal position) of the mouse (relative to the window in desktop) in pixels.
395 * @function
396 * @param {Event} [e] - [Mouse event object]{@link https://developer.mozilla.org/en-US/docs/Web/API/MouseEvent}. If not provided, the returning value will use the previously-cached value (updated the last time that the [onMouseMove]{@link https://developer.mozilla.org/en-US/docs/Web/API/Element/mousemove_event} event was fired).
397 * @param {boolean} [ignoreScroll=false] - If set to true, the horizontal scroll position will not be added to the returning value.
398 * @param {boolean} [ignoreLock=false] - If set to true, it will ignore whether the cursor is being locked or not. Otherwise, if set to false and the cursor is locked, the returning value will only have in mind the position in the locking element.
399 * @returns {number} Returns the X coordinate (horizontal position) of the mouse (relative to the window in desktop) in pixels.
400 */
401 CB_Mouse.getX = function(e, ignoreScroll, ignoreLock)
402 {
403 //If this function has not been called from an event, we return stored values:
404 if (!e)
405 {
406 if (CB_Mouse.isLocked(false) &amp;&amp; !ignoreLock) { return CB_Mouse.getXMovement(e); }
407 else
408 {
409 if (ignoreScroll) { return CB_Mouse._x; }
410 else { return CB_Mouse._x + CB_Screen.getScrollLeft(); }
411 }
412 }
413
414 var mouseX = 0;
415
416 //If it is compatible with the W3C draft:
417 if (typeof(e.x) !== "undefined") { mouseX = e.x; }
418 //...otherwise, if we are using Internet Explorer:
419 else if (typeof(e.clientX) !== "undefined")
420 {
421 mouseX = e.clientX;// + document.body.scrollLeft;
422 }
423 //...otherwise we don't use Internet Explorer:
424 else if (typeof(e.pageX) !== "undefined")
425 {
426 //document.captureEvents(Event.MOUSEMOVE);
427 mouseX = e.pageX;
428 }
429
430 //If the coordinate is lower than zero, it should be zero:
431 if (mouseX &lt; 0) { mouseX = 0; }
432
433 //We set the value for the property of the class:
434 CB_Mouse._x = mouseX;
435
436 //Updates the mose movement (useful when the mouse pointer is locked):
437 CB_Mouse._xMovement = CB_Mouse.getXMovement(e);
438
439 //If the mouse pointer is locked and we do not want to ignore it:
440 if (CB_Mouse.isLocked(false) &amp;&amp; !ignoreLock)
441 {
442 return CB_Mouse._xMovement;
443 }
444 //...otherwise, returns the normal position instead of the movement:
445 else
446 {
447 if (ignoreScroll) { return CB_Mouse._x; }
448 else { return CB_Mouse._x + CB_Screen.getScrollLeft(); }
449 }
450 }
451
452
453 /**
454 * Gets and returns the Y coordinate (vertical position) of the mouse (relative to the window in desktop) in pixels.
455 * @function
456 * @param {Event} [e] - [Mouse event object]{@link https://developer.mozilla.org/en-US/docs/Web/API/MouseEvent}. If not provided, the returning value will use the previously-cached value (updated the last time that the [onMouseMove]{@link https://developer.mozilla.org/en-US/docs/Web/API/Element/mousemove_event} event was fired).
457 * @param {boolean} [ignoreScroll=false] - If set to true, the vertical scroll position will not be added to the returning value.
458 * @param {boolean} [ignoreLock=false] - If set to true, it will ignore whether the cursor is being locked or not. Otherwise, if set to false and the cursor is locked, the returning value will only have in mind the position in the locking element.
459 * @returns {number} Returns the Y coordinate (vertical position) of the mouse (relative to the window in desktop) in pixels.
460 */
461 CB_Mouse.getY = function(e, ignoreScroll, ignoreLock)
462 {
463 //If this function has not been called from an event, we return stored values:
464 if (!e)
465 {
466 if (CB_Mouse.isLocked(false) &amp;&amp; !ignoreLock) { return CB_Mouse.getYMovement(e); }
467 else
468 {
469 if (ignoreScroll) { return CB_Mouse._y; }
470 else { return CB_Mouse._y + CB_Screen.getScrollTop(); }
471 }
472 }
473
474 var mouseY = 0;
475
476 //If it is compatible with the W3C draft:
477 if (typeof(e.y) !== "undefined") { mouseY = e.y; }
478 //...otherwise, if we are using Internet Explorer:
479 else if (typeof(e.clientY) !== "undefined")
480 {
481 mouseY = e.clientY;// + document.body.scrollTop;
482 }
483 //...otherwise we don't use Internet Explorer:
484 else if (typeof(e.pageY) !== "undefined")
485 {
486 //document.captureEvents(Event.MOUSEMOVE);
487 mouseY = e.pageY;
488 }
489
490 //If the coordinate is lower than zero, it should be zero:
491 if (mouseY &lt; 0) { mouseY = 0; }
492
493 //We set the value for the property of the class:
494 CB_Mouse._y = mouseY;
495
496 //Updates the mose movement (useful when the mouse pointer is locked):
497 CB_Mouse._yMovement = CB_Mouse.getYMovement(e);
498
499 //If the mouse pointer is locked and we do not want to ignore it:
500 if (CB_Mouse.isLocked(false) &amp;&amp; !ignoreLock)
501 {
502 return CB_Mouse._yMovement;
503 }
504 //...otherwise, returns the normal position instead of the movement:
505 else
506 {
507 if (ignoreScroll) { return CB_Mouse._y; }
508 else { return CB_Mouse._y + CB_Screen.getScrollTop(); }
509 }
510 }
511
512
513 /**
514 * Gets and returns the current X coordinate (horizontal position) in pixels of the mouse relative to a given X position. The returning value uses the previously-cached value (updated the last time that the [onMouseMove]{@link https://developer.mozilla.org/en-US/docs/Web/API/Element/mousemove_event} event was fired).
515 * @function
516 * @param {number} x - The X coordinate (horizontal position) in pixels. The returning value will be calculated relatively to it.
517 * @param {boolean} [ignoreScroll=false] - If set to true, the horizontal scroll position will not be added to the returning value.
518 * @returns {number} Returns the current X coordinate (horizontal position) in pixels of the mouse relative to a given X position.
519 * @todo Think about allowing to define an "e" parameter with the [mouse event object]{@link https://developer.mozilla.org/en-US/docs/Web/API/MouseEvent}.
520 */
521 CB_Mouse.getXRelative = function(x, ignoreScroll)
522 {
523 //Gets the X position of the mouse:
524 var mouseX = CB_Mouse.getX(null, ignoreScroll);
525
526 if (ignoreScroll) { x -= CB_Screen.getScrollLeft(); }
527
528 var mouseRelativeX = mouseX - x;
529
530 return mouseRelativeX;
531 }
532
533
534 /**
535 * Gets and returns the current Y coordinate (vertical position) in pixels of the mouse relative to a given Y position. The returning value uses the previously-cached value (updated the last time that the [onMouseMove]{@link https://developer.mozilla.org/en-US/docs/Web/API/Element/mousemove_event} event was fired).
536 * @function
537 * @param {number} y - The Y coordinate (vertical position) in pixels. The returning value will be calculated relatively to it.
538 * @param {boolean} [ignoreScroll=false] - If set to true, the vertical scroll position will not be added to the returning value.
539 * @returns {number} Returns the current Y coordinate (vertical position) in pixels of the mouse relative to a given Y position.
540 * @todo Think about allowing to define an "e" parameter with the [mouse event object]{@link https://developer.mozilla.org/en-US/docs/Web/API/MouseEvent}.
541 */
542 CB_Mouse.getYRelative = function(y, ignoreScroll)
543 {
544 //Gets the Y position of the mouse:
545 var mouseY = CB_Mouse.getY(null, ignoreScroll);
546
547 if (ignoreScroll) { y -= CB_Screen.getScrollTop(); }
548
549 var mouseRelativeY = mouseY - y;
550
551 return mouseRelativeY;
552 }
553
554
555 /**
556 * Returns the current X (horizontal) movement (useful when the mouse pointer is locked) in pixels. More information: [MouseEvent.movementX]{@link https://developer.mozilla.org/en-US/docs/Web/API/MouseEvent/movementX}.
557 * @function
558 * @param {Event} [e] - [Mouse event object]{@link https://developer.mozilla.org/en-US/docs/Web/API/MouseEvent}. If not provided, the returning value will use the previously-cached value (updated the last time that the [onMouseMove]{@link https://developer.mozilla.org/en-US/docs/Web/API/Element/mousemove_event} event was fired).
559 * @returns {number} Returns the current X (horizontal) movement (useful when the mouse pointer is locked) in pixels.
560 */
561 CB_Mouse.getXMovement = function(e)
562 {
563 //If this function has been called from an event, updates the current values:
564 if (e) { CB_Mouse._xMovement = e.movementX || e.mozMovementX || e.webkitMovementX || 0; }
565 return CB_Mouse._xMovement;
566 }
567
568
569 /**
570 * Returns the current Y (vertical) movement (useful when the mouse pointer is locked) in pixels. More information: [MouseEvent.movementY]{@link https://developer.mozilla.org/en-US/docs/Web/API/MouseEvent/movementY}.
571 * @function
572 * @param {Event} [e] - [Mouse event object]{@link https://developer.mozilla.org/en-US/docs/Web/API/MouseEvent}. If not provided, the returning value will use the previously-cached value (updated the last time that the [onMouseMove]{@link https://developer.mozilla.org/en-US/docs/Web/API/Element/mousemove_event} event was fired).
573 * @returns {number} Returns the current Y (vertical) movement (useful when the mouse pointer is locked) in pixels.
574 */
575 CB_Mouse.getYMovement = function(e)
576 {
577 //If this function has been called from an event, updates the current values:
578 if (e) { CB_Mouse._yMovement = e.movementY || e.mozMovementY || e.webkitMovementY || 0; }
579 return CB_Mouse._yMovement;
580 }
581
582
583 /**
584 * Sets a function to execute when a click happens ([onMouseMove]{@link https://developer.mozilla.org/en-US/docs/Web/API/Element/mousemove_event} event) or removes it.
585 * @function
586 * @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 [mouse event object]{@link https://developer.mozilla.org/en-US/docs/Web/API/MouseEvent} (already normalized by the {@link CB_Mouse.normalizeEvent} function). If a null value is used, the event will be removed.
587 * @param {boolean} [keepOldFunction=true] - Defines whether we want to keep any possible previous event listener for the same target and event name or not.
588 * @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.
589 * @param {Object} [target=document] - The target where we want to attach the event listener.
590 */
591 CB_Mouse.onMove = function(callbackFunction, keepOldFunction, useCapture, target)
592 {
593 return CB_Mouse._setEvent("mousemove", callbackFunction, keepOldFunction, useCapture, target);
594 }
595
596
597 /**
598 * Sets a function to execute when a click happens ([onClick]{@link https://developer.mozilla.org/en-US/docs/Web/API/Element/click_event} event) or removes it.
599 * @function
600 * @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 [mouse event object]{@link https://developer.mozilla.org/en-US/docs/Web/API/MouseEvent} (already normalized by the {@link CB_Mouse.normalizeEvent} function). If a null value is used, the event will be removed.
601 * @param {boolean} [keepOldFunction=true] - Defines whether we want to keep any possible previous event listener for the same target and event name or not.
602 * @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.
603 * @param {Object} [target=document] - The target where we want to attach the event listener.
604 */
605 CB_Mouse.onClick = function(callbackFunction, keepOldFunction, useCapture, target)
606 {
607 return CB_Mouse._setEvent("click", callbackFunction, keepOldFunction, useCapture, target);
608 }
609
610
611 /**
612 * Sets a function to execute when a click happens ([onDblClick]{@link https://developer.mozilla.org/en-US/docs/Web/API/Element/dblclick_event} event) or removes it.
613 * @function
614 * @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 [mouse event object]{@link https://developer.mozilla.org/en-US/docs/Web/API/MouseEvent} (already normalized by the {@link CB_Mouse.normalizeEvent} function). If a null value is used, the event will be removed.
615 * @param {boolean} [keepOldFunction=true] - Defines whether we want to keep any possible previous event listener for the same target and event name or not.
616 * @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.
617 * @param {Object} [target=document] - The target where we want to attach the event listener.
618 */
619 CB_Mouse.onDblClick = CB_Mouse.onDoubleClick = function(callbackFunction, keepOldFunction, useCapture, target)
620 {
621 return CB_Mouse._setEvent("dblclick", callbackFunction, keepOldFunction, useCapture, target);
622 }
623
624
625 /**
626 * Sets a function to execute when a mouse button is down ([onMouseDown]{@link https://developer.mozilla.org/en-US/docs/Web/API/Element/mousedown_event} event) or removes it.
627 * @function
628 * @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 [mouse event object]{@link https://developer.mozilla.org/en-US/docs/Web/API/MouseEvent} (already normalized by the {@link CB_Mouse.normalizeEvent} function). If a null value is used, the event will be removed.
629 * @param {boolean} [keepOldFunction=true] - Defines whether we want to keep any possible previous event listener for the same target and event name or not.
630 * @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.
631 * @param {Object} [target=document] - The target where we want to attach the event listener.
632 */
633 CB_Mouse.onButtonDown = function(callbackFunction, keepOldFunction, useCapture, target)
634 {
635 return CB_Mouse._setEvent("mousedown", callbackFunction, keepOldFunction, useCapture, target);
636 }
637
638
639 /**
640 * Sets a function to execute when a mouse button is up ([onMouseUp]{@link https://developer.mozilla.org/en-US/docs/Web/API/Element/mouseup_event} event) or removes it.
641 * @function
642 * @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 [mouse event object]{@link https://developer.mozilla.org/en-US/docs/Web/API/MouseEvent} (already normalized by the {@link CB_Mouse.normalizeEvent} function). If a null value is used, the event will be removed.
643 * @param {boolean} [keepOldFunction=true] - Defines whether we want to keep any possible previous event listener for the same target and event name or not.
644 * @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.
645 * @param {Object} [target=document] - The target where we want to attach the event listener.
646 */
647 CB_Mouse.onButtonUp = function(callbackFunction, keepOldFunction, useCapture, target)
648 {
649 return CB_Mouse._setEvent("mouseup", callbackFunction, keepOldFunction, useCapture, target);
650 }
651
652
653 /**
654 * Sets a function to execute when a mouse leaves a [DOM element]{@link https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement} ([onMouseLeave]{@link https://developer.mozilla.org/en-US/docs/Web/API/Element/mouseleave_event} event) or removes it.
655 * @function
656 * @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 [mouse event object]{@link https://developer.mozilla.org/en-US/docs/Web/API/MouseEvent} (already normalized by the {@link CB_Mouse.normalizeEvent} function). If a null value is used, the event will be removed.
657 * @param {boolean} [keepOldFunction=true] - Defines whether we want to keep any possible previous event listener for the same target and event name or not.
658 * @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.
659 * @param {Object} [target=window] - The target where we want to attach the event listener.
660 */
661 CB_Mouse.onLeave = function(callbackFunction, keepOldFunction, useCapture, target)
662 {
663 return CB_Mouse._setEvent("mouseleave", callbackFunction, keepOldFunction, useCapture, target);
664 }
665
666
667 /**
668 * Sets a function to execute when a mouse is over a [DOM element]{@link https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement} ([onMouseOver]{@link https://developer.mozilla.org/en-US/docs/Web/API/Element/mouseover_event} event) or removes it.
669 * @function
670 * @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 [mouse event object]{@link https://developer.mozilla.org/en-US/docs/Web/API/MouseEvent} (already normalized by the {@link CB_Mouse.normalizeEvent} function). If a null value is used, the event will be removed.
671 * @param {boolean} [keepOldFunction=true] - Defines whether we want to keep any possible previous event listener for the same target and event name or not.
672 * @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.
673 * @param {Object} [target=document] - The target where we want to attach the event listener.
674 */
675 CB_Mouse.onOver = function(callbackFunction, keepOldFunction, useCapture, target)
676 {
677 return CB_Mouse._setEvent("mouseover", callbackFunction, keepOldFunction, useCapture, target);
678 }
679
680
681 /**
682 * Sets a function to execute when a mouse gets out of a [DOM element]{@link https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement} ([onMouseOut]{@link https://developer.mozilla.org/en-US/docs/Web/API/Element/mouseout_event} event) or removes it.
683 * @function
684 * @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 [mouse event object]{@link https://developer.mozilla.org/en-US/docs/Web/API/MouseEvent} (already normalized by the {@link CB_Mouse.normalizeEvent} function). If a null value is used, the event will be removed.
685 * @param {boolean} [keepOldFunction=true] - Defines whether we want to keep any possible previous event listener for the same target and event name or not.
686 * @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.
687 * @param {Object} [target=document] - The target where we want to attach the event listener.
688 */
689 CB_Mouse.onOut = function(callbackFunction, keepOldFunction, useCapture, target)
690 {
691 return CB_Mouse._setEvent("mouseout", callbackFunction, keepOldFunction, useCapture, target);
692 }
693
694
695 /**
696 * Sets a function to execute when the mouse wheel is used ([onWheel]{@link https://developer.mozilla.org/en-US/docs/Web/Events/wheel}, [onMouseWheel]{@link https://developer.mozilla.org/en-US/docs/Web/API/Element/mousewheel_event} or [DOMMouseScroll]{@link https://developer.mozilla.org/en-US/docs/Web/API/Element/DOMMouseScroll_event} event) or removes it.
697 * @function
698 * @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 [mouse event object]{@link https://developer.mozilla.org/en-US/docs/Web/API/MouseEvent} (already normalized by the {@link CB_Mouse.normalizeEvent} function). If a null value is used, the event will be removed.
699 * @param {boolean} [keepOldFunction=true] - Defines whether we want to keep any possible previous event listener for the same target and event name or not.
700 * @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.
701 * @param {Object} [target=document] - The target where we want to attach the event listener.
702 */
703 CB_Mouse.onWheel = function(callbackFunction, keepOldFunction, useCapture, target)
704 {
705 var onWheelEventName = CB_Mouse._getOnWheelEventName();
706
707 var valueToReturn = CB_Mouse._setEvent(onWheelEventName, callbackFunction, keepOldFunction, useCapture, target);
708
709 //If DOMMouseScroll is detected, adds MozMousePixelScroll event for older Firefox versions:
710 if (onWheelEventName === "DOMMouseScroll")
711 {
712 valueToReturn = CB_Mouse._setEvent("MozMousePixelScroll", callbackFunction, keepOldFunction, useCapture, target);
713 }
714
715 return valueToReturn;
716 }
717
718
719 CB_Mouse.isLockSupportedReturnCache = null;
720 /**
721 * Tells whether mouse pointer lock is supported or not. More information: [Pointer Lock API]{@link https://developer.mozilla.org/en-US/docs/Web/API/Pointer_Lock_API}.
722 * @function
723 * @returns {boolean} Returns whether mouse pointer lock is supported or not.
724 */
725 CB_Mouse.isLockSupported = function()
726 {
727 if (CB_Mouse.isLockSupportedReturnCache === null)
728 {
729 CB_Mouse.isLockSupportedReturnCache = "pointerLockElement" in document || "mozPointerLockElement" in document || "webkitPointerLockElement" in document || (navigator &amp;&amp; (navigator.pointer || navigator.webkitPointer || navigator.mozPointer));
730 }
731 return CB_Mouse.isLockSupportedReturnCache;
732 }
733
734
735 /**
736 * Tells whether the mouse pointer is locked or not. More information: [Pointer Lock API]{@link https://developer.mozilla.org/en-US/docs/Web/API/Pointer_Lock_API}.
737 * @function
738 * @param {boolean} [avoidCache=false] - Used as the parameter to call the {@link CB_Mouse.getLockElement} function internally.
739 * @returns {boolean} Returns whether the mouse pointer is locked or not.
740 */
741 CB_Mouse.isLocked = function(avoidCache)
742 {
743 CB_Mouse._isLockedPrevious = CB_Mouse._isLockedNow;
744 var isLockedNow = (CB_Mouse.getLockElement(avoidCache) !== null);
745 if (!isLockedNow &amp;&amp; navigator)
746 {
747 navigator.pointer = navigator.pointer || navigator.webkitPointer || navigator.mozPointer;
748 if (navigator.pointer)
749 {
750 if (typeof(navigator.pointer.isLocked) === "function") { isLockedNow = navigator.pointer.isLocked(); }
751 else if (typeof(navigator.pointer.islocked) === "function") { isLockedNow = navigator.pointer.islocked(); }
752 else if (typeof(navigator.pointer.isLocked) !== "undefined") { isLockedNow = navigator.pointer.isLocked; }
753 }
754 }
755 CB_Mouse._isLockedNow = isLockedNow;
756 return CB_Mouse._isLockedNow;
757 }
758
759
760 /**
761 * Tells whether the mouse pointer was locked before or not when the {@link CB_Mouse.isLocked} function was called the last time. More information: [Pointer Lock API]{@link https://developer.mozilla.org/en-US/docs/Web/API/Pointer_Lock_API}.
762 * @function
763 * @returns {boolean} Returns whether the mouse pointer was locked before or not when the {@link CB_Mouse.isLocked} function was called the last time.
764 */
765 CB_Mouse.wasLocked = function()
766 {
767 return CB_Mouse._isLockedPrevious;
768 }
769
770
771 /**
772 * Gets the lock element for the mouse pointer (if any) or null otherwise. More information: [Pointer Lock API]{@link https://developer.mozilla.org/en-US/docs/Web/API/Pointer_Lock_API}.
773 * @function
774 * @param {boolean} [avoidCache=false] - If set to false, the returning value will use the previously-cached value (updated when this function is called with this parameter set to true or the [onPointerLockChange]{@link https://developer.mozilla.org/en-US/docs/Web/API/Document/pointerlockchange_event} or analog event is fired or when the {@link CB_Mouse.lock} or {@link CB_Mouse.unlock} functions are called successfully).
775 * @returns {Element|null} Returns the lock element for the mouse pointer (if any) or null otherwise.
776 */
777 CB_Mouse.getLockElement = function(avoidCache)
778 {
779 if (avoidCache)
780 {
781 if (typeof(document.pointerLockElement) !== "undefined" &amp;&amp; document.pointerLockElement !== null) { CB_Mouse._lockElement = document.pointerLockElement; }
782 else if (typeof(document.mozPointerLockElement) !== "undefined" &amp;&amp; document.mozPointerLockElement !== null) { CB_Mouse._lockElement = document.mozPointerLockElement; }
783 else if (typeof(document.webkitPointerLockElement) !== "undefined" &amp;&amp; document.webkitPointerLockElement !== null) { CB_Mouse._lockElement = document.webkitPointerLockElement; }
784 else { CB_Mouse._lockElement = null; }
785 return CB_Mouse._lockElement;
786 }
787 else { return CB_Mouse._lockElement; }
788 }
789
790
791 /**
792 * Locks the mouse pointer (if possible). More information: [Pointer Lock API]{@link https://developer.mozilla.org/en-US/docs/Web/API/Pointer_Lock_API}.
793 * @function
794 * @param {Element} [target=document.body] - The [DOM element]{@link https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement} that the mouse pointer will be locked to.
795 * @param {function} callbackOk - Function callback that will be called (without parameters) if the mouse pointer could be locked successfully.
796 * @param {function} callbackError - Function callback that will be called (without parameters) if the mouse pointer could not be locked successfully.
797 * @returns {Element|null} Returns the current lock element for the mouse pointer (if any) or null otherwise.
798 */
799 CB_Mouse.lock = function(target, callbackOk, callbackError)
800 {
801 if (typeof(target) === "undefined" || target === null) { target = document.body; }
802 if (typeof(target) !== "undefined" &amp;&amp; target !== null)
803 {
804 target.requestPointerLock = target.requestPointerLock || target.mozRequestPointerLock || target.webkitRequestPointerLock;
805 if (typeof(target.requestPointerLock) === "function")
806 {
807 target.requestPointerLock();
808 if (CB_Mouse.isLocked(true)) //Also updates CB_Mouse.isLocked cache.
809 {
810 if (typeof(callbackOk) === "function") { callbackOk(); }
811 }
812 else if (typeof(callbackError) === "function") { callbackError(); }
813 return CB_Mouse.getLockElement(true);
814 }
815 else if (navigator)
816 {
817 navigator.pointer = navigator.pointer || navigator.webkitPointer || navigator.mozPointer;
818 if (navigator.pointer &amp;&amp; typeof(navigator.pointer.lock) === "function")
819 {
820 navigator.pointer.lock(target, callbackOk, callbackError);
821 CB_Mouse.isLocked(true); //Updates CB_Mouse.isLocked cache.
822 return CB_Mouse.getLockElement(true);
823 }
824 }
825 }
826 if (typeof(callbackError) === "function") { callbackError(); }
827 CB_Mouse.isLocked(true); //Updates CB_Mouse.isLocked cache.
828 return null;
829 }
830
831
832 /**
833 * Unlocks the mouse pointer (if possible). More information: [Pointer Lock API]{@link https://developer.mozilla.org/en-US/docs/Web/API/Pointer_Lock_API}.
834 * @function
835 * @returns {boolean} Returns true if the mouse pointer has been unlocked or false otherwise.
836 */
837 CB_Mouse.unlock = function()
838 {
839 document.exitPointerLock = document.exitPointerLock || document.mozExitPointerLock || document.webkitExitPointerLock;
840 if (typeof(document.exitPointerLock) === "function")
841 {
842 document.exitPointerLock();
843 }
844 else if (navigator)
845 {
846 navigator.pointer = navigator.pointer || navigator.webkitPointer || navigator.mozPointer;
847 if (navigator.pointer &amp;&amp; typeof(navigator.pointer.unlock) === "function")
848 {
849 navigator.pointer.unlock();
850 }
851 }
852 return (!CB_Mouse.isLocked(true));
853 }
854
855
856 /**
857 * Sets a function to execute when the mouse pointer lock functionality changes its state (it has been either locked or unlocked, using [pointerlockchange]{@link [onPointerLockChange]{@link https://developer.mozilla.org/en-US/docs/Web/API/Document/pointerlockchange_event}}, [mozpointerlockchange]{@link https://developer.mozilla.org/en-US/docs/Web/API/Pointer_Lock_API} or [webkitpointerlockchange]{@link https://developer.mozilla.org/en-US/docs/Web/API/Pointer_Lock_API} event) or removes it. More information: [Pointer Lock API]{@link https://developer.mozilla.org/en-US/docs/Web/API/Pointer_Lock_API}.
858 * @function
859 * @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 [mouse event object]{@link https://developer.mozilla.org/en-US/docs/Web/API/MouseEvent} (already normalized by the {@link CB_Mouse.normalizeEvent} function). If a null value is used, the event will be removed.
860 * @param {boolean} [keepOldFunction=true] - Defines whether we want to keep any possible previous event listener for the same target and event name or not.
861 * @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.
862 */
863 CB_Mouse.onLockChange = function(callbackFunction, keepOldFunction, useCapture)
864 {
865 CB_Mouse._setEvent("pointerlockchange", callbackFunction, keepOldFunction, useCapture, document);
866 CB_Mouse._setEvent("mozpointerlockchange", callbackFunction, keepOldFunction, useCapture, document);
867 CB_Mouse._setEvent("webkitpointerlockchange", callbackFunction, keepOldFunction, useCapture, document);
868 }
869
870
871 /**
872 * Sets a function to execute when the mouse pointer fails to either lock or unlock (using [pointerlockerror]{@link https://developer.mozilla.org/en-US/docs/Web/API/Document/pointerlockerror_event}, [mozpointerlockerror]{@link https://developer.mozilla.org/en-US/docs/Web/API/Pointer_Lock_API} or [webkitpointerlockerror]{@link https://developer.mozilla.org/en-US/docs/Web/API/Pointer_Lock_API} event) or removes it. More information: [Pointer Lock API]{@link https://developer.mozilla.org/en-US/docs/Web/API/Pointer_Lock_API}.
873 * @function
874 * @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 [mouse event object]{@link https://developer.mozilla.org/en-US/docs/Web/API/MouseEvent} (already normalized by the {@link CB_Mouse.normalizeEvent} function). If a null value is used, the event will be removed.
875 * @param {boolean} [keepOldFunction=true] - Defines whether we want to keep any possible previous event listener for the same target and event name or not.
876 * @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.
877 */
878 CB_Mouse.onLockError = function(callbackFunction, keepOldFunction, useCapture)
879 {
880 CB_Mouse._setEvent("pointerlockerror", callbackFunction, keepOldFunction, useCapture, document);
881 CB_Mouse._setEvent("mozpointerlockerror", callbackFunction, keepOldFunction, useCapture, document);
882 CB_Mouse._setEvent("webkitpointerlockerror", callbackFunction, keepOldFunction, useCapture, document);
883 }
884
885
886 //Sets a function to execute when a desired event is fired:
887 CB_Mouse._setEvent = function(eventName, eventFunction, keepOldFunction, useCapture, target)
888 {
889 //If they are not set, use default values for optional parameters:
890 if (typeof(keepOldFunction) === "undefined" || keepOldFunction === null) { keepOldFunction = true; } //If not set, it keeps old function by default.
891 if (typeof(target) === "undefined" || target === null)
892 {
893 if (eventName === "mouseleave") { target = window; }
894 else { target = document; }
895 }
896
897 //If a function has been sent:
898 if (typeof(eventFunction) === "function")
899 {
900 //If able, adds the function given to the event:
901 CB_Events.add
902 (
903 target,
904 eventName,
905 function(e)
906 {
907 e = CB_Mouse.normalizeEvent(e);
908 CB_Mouse.getX(e); //Updates mouse X position.
909 CB_Mouse.getY(e); //Updates mouse Y position.
910
911 if (eventName === "mousedown" || eventName === "mouseup")
912 {
913 CB_Mouse._updateButtonsDown(e, (eventName === "mousedown")); //Updates buttons down.
914 }
915
916 if (typeof(eventFunction) === "function") { return eventFunction(e); }
917
918 return true;
919 },
920 useCapture,
921 keepOldFunction,
922 true
923 );
924 }
925 //...but if the function given is null, it will cancel the event:
926 else if (eventFunction === null)
927 {
928 CB_Events.removeByName(target, eventName);
929 }
930 }
931
932
933 /**
934 * Tells whether the mouse is over a given [DOM element]{@link https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement} or not.
935 * @function
936 * @param {Element} element - The [DOM element]{@link https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement} where we want to know whether the mouse is over or not.
937 * @returns {boolean} Returns whether the mouse is over the given [DOM element]{@link https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement} or not.
938 */
939 CB_Mouse.isOverElement = function(element)
940 {
941 return CB_Collisions.isPointOverElement(CB_Mouse.getX(), CB_Mouse.getY(), element);
942 }
943
944
945 /**
946 * Tells whether the mouse is over a given line (infinite line) or not.
947 * @function
948 * @param {number} lineX1 - The X coordinate (horizontal position) of the first pixel of the line.
949 * @param {number} lineY1 - The Y coordinate (vertical position) of the first pixel of the line.
950 * @param {number} lineX2 - The X coordinate (horizontal position) of the second pixel of the line.
951 * @param {number} lineY2 - The Y coordinate (vertical position) of the second pixel of the line.
952 * @param {number} [tolerance=1] - The amount of loss of precision we can tolerate to consider a collision.
953 * @param {Element} [element] - If a [DOM element]{@link https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement} is given, the mouse coordinates will be calculated relatively to the position of this [DOM element]{@link https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement}.
954 * @returns {boolean} Returns whether the mouse is over the given line (infinite line) or not.
955 * @todo Think about using a "width" parameter (apart from the "tolerance" parameter).
956 */
957 CB_Mouse.isOverLine = function(lineX1, lineY1, lineX2, lineY2, tolerance, element)
958 {
959 if (typeof(tolerance) === "undefined" || tolerance === null) { tolerance = 1; }
960
961 if (typeof(element) !== "undefined" &amp;&amp; element !== null)
962 {
963 var mouseX = CB_Mouse.getXRelative(CB_Elements.getLeft(element));
964 var mouseY = CB_Mouse.getYRelative(CB_Elements.getTop(element));
965 }
966 else
967 {
968 var mouseX = CB_Mouse.getX();
969 var mouseY = CB_Mouse.getY();
970 }
971
972 return CB_Collisions.isPointOverLine(mouseX, mouseY, lineX1, lineY1, lineX2, lineY2, tolerance);
973 }
974
975
976 /**
977 * Tells whether the mouse is over a given line segment or not.
978 * @function
979 * @param {number} lineX1 - The X coordinate (horizontal position) of the first pixel of the line segment.
980 * @param {number} lineY1 - The Y coordinate (vertical position) of the first pixel of the line segment.
981 * @param {number} lineX2 - The X coordinate (horizontal position) of the second pixel of the line segment.
982 * @param {number} lineY2 - The Y coordinate (vertical position) of the second pixel of the line segment.
983 * @param {number} [tolerance=1] - The amount of loss of precision we can tolerate to consider a collision.
984 * @param {Element} [element] - If a [DOM element]{@link https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement} is given, the mouse coordinates will be calculated relatively to the position of this [DOM element]{@link https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement}.
985 * @returns {boolean} Returns whether the mouse is over the given line segment or not.
986 * @todo Think about using a "width" parameter (apart from the "tolerance" parameter).
987 */
988 CB_Mouse.isOverSegment = function(lineX1, lineY1, lineX2, lineY2, tolerance, element)
989 {
990 if (typeof(tolerance) === "undefined" || tolerance === null) { tolerance = 1; }
991
992 if (typeof(element) !== "undefined" &amp;&amp; element !== null)
993 {
994 var mouseX = CB_Mouse.getXRelative(CB_Elements.getLeft(element));
995 var mouseY = CB_Mouse.getYRelative(CB_Elements.getTop(element));
996 }
997 else
998 {
999 var mouseX = CB_Mouse.getX();
1000 var mouseY = CB_Mouse.getY();
1001 }
1002
1003 return CB_Collisions.isPointOverSegment(mouseX, mouseY, lineX1, lineY1, lineX2, lineY2, tolerance);
1004 }
1005
1006
1007 /**
1008 * Tells whether the mouse is over a given rectangle or not.
1009 * @function
1010 * @param {number} rectangleX - The X coordinate (horizontal position) of the first pixel of the rectangle (upper left corner).
1011 * @param {number} rectangleY - The Y coordinate (vertical position) of the first pixel of the rectangle (upper left corner).
1012 * @param {number} rectangleWidth - The width of the rectangle in pixels.
1013 * @param {number} rectangleHeight - The height of the rectangle in pixels.
1014 * @param {Element} [element] - If a [DOM element]{@link https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement} is given, the mouse coordinates will be calculated relatively to the position of this [DOM element]{@link https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement}.
1015 * @returns {boolean} Returns whether the mouse is over the given rectangle or not.
1016 */
1017 CB_Mouse.isOverRectangle = function(rectangleX, rectangleY, rectangleWidth, rectangleHeight, element)
1018 {
1019 if (typeof(element) !== "undefined" &amp;&amp; element !== null)
1020 {
1021 var mouseX = CB_Mouse.getXRelative(CB_Elements.getLeft(element));
1022 var mouseY = CB_Mouse.getYRelative(CB_Elements.getTop(element));
1023 }
1024 else
1025 {
1026 var mouseX = CB_Mouse.getX();
1027 var mouseY = CB_Mouse.getY();
1028 }
1029
1030 return CB_Collisions.isPointOverRectangle(mouseX, mouseY, rectangleX, rectangleY, rectangleWidth, rectangleHeight);
1031 }
1032
1033
1034 /**
1035 * Tells whether the mouse is over a given circle or not.
1036 * @function
1037 * @param {number} centreX - The X coordinate (horizontal position) of the center of the circle in pixels.
1038 * @param {number} centreY - The Y coordinate (vertical position) of the center of the circle in pixels.
1039 * @param {number} radius - The radius of the circle in pixels.
1040 * @param {Element} [element] - If a [DOM element]{@link https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement} is given, the mouse coordinates will be calculated relatively to the position of this [DOM element]{@link https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement}.
1041 * @returns {boolean} Returns whether the mouse is over the given circle or not.
1042 */
1043 CB_Mouse.isOverCircle = function(centreX, centreY, radius, element)
1044 {
1045 if (typeof(element) !== "undefined" &amp;&amp; element !== null)
1046 {
1047 mouseX = CB_Mouse.getXRelative(CB_Elements.getLeft(element));
1048 mouseY = CB_Mouse.getYRelative(CB_Elements.getTop(element));
1049 }
1050 else
1051 {
1052 var mouseX = CB_Mouse.getX();
1053 var mouseY = CB_Mouse.getY();
1054 }
1055
1056 return CB_Collisions.isPointOverCircle(mouseX, mouseY, centreX, centreY, radius);
1057 }
1058
1059
1060 /**
1061 * Tells whether the mouse is over a given ellipse or not.
1062 * @function
1063 * @param {number} centreX - The "X" coordinate of the center of the ellipse.
1064 * @param {number} centreY - The "Y" coordinate of the center of the ellipse.
1065 * @param {number} radiusX - The X (horizontal) radius of the ellipse.
1066 * @param {number} radiusY - The Y (vertical) radius of the ellipse.
1067 * @param {number} [rotation=0] - The ellipse rotation. The value given will be considered either degrees or radians depending on the given "rotationUseDegrees" parameter (by default, it is considered radians). Not implemented yet!
1068 * @param {boolean} [rotationUseDegrees=false] - Defines whether the "rotation" given should be considered degrees or not (radians). Not implemented yet!
1069 * @returns {boolean} Returns whether the mouse is over the given ellipse or not.
1070 */
1071 CB_Mouse.isOverEllipse = function(centreX, centreY, radiusX, radiusY, rotation, rotationUseDegrees, radius, element)
1072 {
1073 if (typeof(element) !== "undefined" &amp;&amp; element !== null)
1074 {
1075 mouseX = CB_Mouse.getXRelative(CB_Elements.getLeft(element));
1076 mouseY = CB_Mouse.getYRelative(CB_Elements.getTop(element));
1077 }
1078 else
1079 {
1080 var mouseX = CB_Mouse.getX();
1081 var mouseY = CB_Mouse.getY();
1082 }
1083
1084 return CB_Collisions.isPointOverEllipse(mouseX, mouseY, centreX, centreY, radiusX, radiusY, rotation, rotationUseDegrees, radius);
1085 }
1086
1087
1088 /**
1089 * Hides the mouse cursor in a given [DOM element]{@link https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement} by changing its internal CSS code of the [style.cursor]{@link https://developer.mozilla.org/en-US/docs/Web/CSS/cursor} property.
1090 * @function
1091 * @param {Element} [element=document.body] - If a [DOM element]{@link https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement} is given, the mouse cursor will be hidden when it is over this [DOM element]{@link https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement}. Otherwise, it will be hidden in the whole document (using [document.body]{@link https://developer.mozilla.org/en-US/docs/Web/API/Document/body} as element).
1092 * @param {boolean} [recursive=true] - If it is set to true, all the child [DOM elements]{@link https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement} will also be affected.
1093 * @todo Check whether the path used in the "url" is right or not (now it uses the {@link CB_scriptPath} variable).
1094 */
1095 CB_Mouse.hide = function(element, recursive)
1096 {
1097 var CSS = "url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsMAAA7DAcdvqGQAAAAZdEVYdFNvZnR3YXJlAFBhaW50Lk5FVCB2My41LjbQg61aAAAADUlEQVQYV2P4//8/IwAI/QL/+TZZdwAAAABJRU5ErkJggg=='), url(" + CB_scriptPath + CB_Configuration[CB_BASE_NAME].SCRIPT_PATH + "input/cursors/almost_blank.png), url(" + CB_scriptPath + CB_Configuration[CB_BASE_NAME].SCRIPT_PATH + "input/cursors/blank.gif), url(" + CB_scriptPath + CB_Configuration[CB_BASE_NAME].SCRIPT_PATH + "input/cursors/blank.cur), none";
1098 if (CB_Client.getBrowser() === "Explorer")
1099 {
1100 CSS = "url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsMAAA7DAcdvqGQAAAAZdEVYdFNvZnR3YXJlAFBhaW50Lk5FVCB2My41LjbQg61aAAAADUlEQVQYV2P4//8/IwAI/QL/+TZZdwAAAABJRU5ErkJggg=='), url(" + CB_scriptPath + CB_Configuration[CB_BASE_NAME].SCRIPT_PATH + "input/cursors/blank.cur), url(" + CB_scriptPath + CB_Configuration[CB_BASE_NAME].SCRIPT_PATH + "input/cursors/blank.gif), url(" + CB_scriptPath + CB_Configuration[CB_BASE_NAME].SCRIPT_PATH + "input/cursors/almost_blank.png), none";
1101 }
1102 CB_Mouse.setCSS(CSS, element, recursive);
1103 //CB_Mouse._showingCursor[element||document.body] = false;
1104 }
1105
1106
1107 /**
1108 * Restores (unhides) the mouse cursor in a given [DOM element]{@link https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement} by changing its internal CSS code of the [style.cursor]{@link https://developer.mozilla.org/en-US/docs/Web/CSS/cursor} property to the default one (using "default" as the CSS code).
1109 * @function
1110 * @param {Element} [element=document.body] - If a [DOM element]{@link https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement} is given, the mouse cursor will be restored (unhidden) when it is over this [DOM element]{@link https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement}. Otherwise, it will be restored (unhidden) in the whole document (using [document.body]{@link https://developer.mozilla.org/en-US/docs/Web/API/Document/body} as the "element").
1111 * @param {boolean} [recursive=true] - If it is set to true, all the child [DOM elements]{@link https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement} will also be affected.
1112 */
1113 CB_Mouse.restore = function(element, recursive)
1114 {
1115 var CSS = "default";
1116 CB_Mouse.setCSS(CSS, element, recursive);
1117 //CB_Mouse._showingCursor[element||document.body] = true;
1118 }
1119
1120
1121 /*
1122 CB_Mouse.isShowing = function(element)
1123 {
1124 return CB_Mouse._showingCursor[element||document.body];
1125 }
1126 */
1127
1128
1129 /**
1130 * Sets the desired CSS code for the [style.cursor]{@link https://developer.mozilla.org/en-US/docs/Web/CSS/cursor} property of the given [DOM element]{@link https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement}.
1131 * @function
1132 * @param {string} [CSS=""] - CSS code for the [style.cursor]{@link https://developer.mozilla.org/en-US/docs/Web/CSS/cursor} property of the given [DOM element]{@link https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement}. If not given, an empty string will be used.
1133 * @param {Element} [element=document.body] - If a [DOM element]{@link https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement} is given, the CSS code updated will affect the given [DOM element]{@link https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement}. Otherwise, it will affect the whole document (using [document.body]{@link https://developer.mozilla.org/en-US/docs/Web/API/Document/body} as the "element").
1134 * @param {boolean} [recursive=true] - If it is set to true, all the child [DOM elements]{@link https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement} will also be affected.
1135 */
1136 CB_Mouse.setCSS = function(CSS, element, recursive)
1137 {
1138 //If they are not set, use default values for optional parameters:
1139 if (typeof(CSS) === "undefined" || CSS === null) { CSS = ""; }
1140 if (typeof(element) === "undefined" || element === null) { element = document.body; }
1141 if (typeof(recursive) === "undefined" || recursive === null) { recursive = true; } //It is recursive by default.
1142
1143 //Sets the CSS style for the given element:
1144 if (typeof(element) !== "undefined" &amp;&amp; element !== null &amp;&amp; typeof(element.style) !== "undefined" &amp;&amp; element.style !== null)
1145 {
1146 element.style.cursor = CSS;
1147 }
1148
1149 //If it is recursive, it affects the children of the given element:
1150 if (recursive)
1151 {
1152 var elementsChildren = element.childNodes;
1153 var elementsChildrenLength = elementsChildren.length;
1154 for (var x = 0; x &lt; elementsChildrenLength; x++)
1155 {
1156 CB_Mouse.setCSS(CSS, elementsChildren[x], true);
1157 }
1158 }
1159 }
1160
1161
1162 /**
1163 * Uses an [IMG element]{@link https://developer.mozilla.org/en-US/docs/Web/HTML/Element/img} inside a [DIV element]{@link https://developer.mozilla.org/en-US/docs/Web/HTML/Element/div} (fakes the cursor) to simulate the mouse cursor (following its movements). If it was already called before and a fake cursor is already being used, the {@link CB_Mouse.CursorImage.hide} function must be called before in order to start using a different fake cursor image.
1164 &lt;br />
1165 Caution: Performance could be dramatically decreased while using this workaround.
1166 * @function
1167 * @param {boolean} [showCursorImage=true] - If set to true and a valid cursor image is given, the fake cursor functionality will be used. Otherwise, the fake cursor will stop being used.
1168 * @param {string} [cursorImage] - If a valid image path is given and "showCursorImage" is set to true, the fake cursor functionality will be used with the given image. Otherwise, the fake cursor will stop being used.
1169 * @param {number} [cursorImageWidth=32] - Width in pixels of the cursor image.
1170 * @param {number} [cursorImageHeight=32] - Height in pixels of the cursor image.
1171 * @param {boolean} [hideNormalCursor=true] - If set to true, hides the system cursor (calls the {@link CB_Mouse.hide} function internally). Otherwise, shows the system cursor (calls the {@link CB_Mouse.restore} function internally).
1172 * @param {boolean} [isSprite=false] - Defines whether the cursor will be animated (using sprites) or not. If so, the cursorImage must be an image containing sprites horizontally (their individual width is defined by the "cursorImageWidth" parameter). Once the last sprite is reached, it returns to the first one automatically and continues to the next one again (without stopping).
1173 * @param {number} [numberOfFrames=1] - Number of frames (sprites) being used from the cursor image ("cursorImage" parameter). Used when the "isSprite" parameter is set to true.
1174 * @param {number} [framesMs=100] - Number of milliseconds between each frame (between one sprite and next one). Used when the "isSprite" parameter is set to true.
1175 * @param {Element} [divElement=CB_Elements.id('CB_fakeCursorImageDiv')] - The ID of the [DIV element]{@link https://developer.mozilla.org/en-US/docs/Web/HTML/Element/div} that will contain the image of the fake cursor (uses a [DOM element]{@link https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement} with "CB_fakeCursorImageDiv" ID by default).
1176 * @param {Element} [imageElement=CB_Elements.id('CB_fakeCursorImage')] - The ID of the [IMG element]{@link https://developer.mozilla.org/en-US/docs/Web/HTML/Element/img} that will contain the fake cursor (uses a [DOM element]{@link https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement} with "CB_fakeCursorImage" ID by default).
1177 * @todo Allow defining an "onMove" parameter (a callback) to be able to call the "move" method with non-default parameters, etc.
1178 */
1179 CB_Mouse.CursorImage.set = function(showCursorImage, cursorImage, cursorImageWidth, cursorImageHeight, hideNormalCursor, isSprite, numberOfFrames, framesMs, divElement, imageElement)
1180 {
1181 //If they are not set, use default values for optional parameters:
1182 if (typeof(showCursorImage) === "undefined" || showCursorImage === null) { showCursorImage = true; } //Shows the image by default.
1183 if (typeof(hideNormalCursor) === "undefined" || hideNormalCursor === null) { hideNormalCursor = true; } //Hides the cursor by default (unless we want to hide the image).
1184 if (typeof(cursorImageWidth) === "undefined" || cursorImageWidth === null) { cursorImageWidth = 32; } //If not set, uses the default width.
1185 if (typeof(cursorImageHeight) === "undefined" || cursorImageHeight === null) { cursorImageHeight = 32; } //If not set, uses the default height.
1186 if (typeof(numberOfFrames) === "undefined" || numberOfFrames === null) { numberOfFrames = 1; } //By default, the number of frames is only one.
1187 if (typeof(framesMs) === "undefined" || framesMs === null) { framesMs = 100; } //Sets the number of milliseconds between frames by default.
1188
1189 //Select the image element or creates it if it doesn't exist yet:
1190 var CB_fakeCursorImageDiv = divElement || CB_Elements.id("CB_fakeCursorImageDiv");
1191 var CB_fakeCursorImage = imageElement || CB_Elements.id("CB_fakeCursorImage");
1192 if (typeof(CB_fakeCursorImageDiv) === "undefined" || CB_fakeCursorImageDiv === null || typeof(CB_fakeCursorImage) === "undefined" || CB_fakeCursorImage === null)
1193 {
1194 CB_fakeCursorImageDiv = document.createElement("div"); //Creathes the DIV element.
1195 CB_fakeCursorImageDiv.setAttribute("id", "CB_fakeCursorImageDiv"); //Sets DIV element id.
1196 CB_fakeCursorImage = document.createElement("img"); //Creathes the IMG element.
1197 CB_fakeCursorImage.setAttribute("id", "CB_fakeCursorImage"); //Sets IMG element id.
1198 CB_fakeCursorImageDiv.style.position = CB_fakeCursorImage.style.position = "absolute"; //DIV and IMG position is absolute.
1199 CB_fakeCursorImageDiv.style.visibility = "hidden"; //First it will be hidden.
1200 CB_fakeCursorImageDiv.style.zIndex = CB_fakeCursorImage.style.zIndex = 999999;
1201
1202 CB_fakeCursorImageDiv.style.overflow = "hidden";
1203
1204 CB_fakeCursorImageDiv.appendChild(CB_fakeCursorImage); //DIV will contains the IMG element.
1205 document.body.appendChild(CB_fakeCursorImageDiv); //BODY will contains the DIV.
1206 }
1207
1208 //If we don't want to show the image (or the image has not been given), we hide it:
1209 if (!showCursorImage || typeof(cursorImage) === "undefined" || cursorImage === null)
1210 {
1211 CB_fakeCursorImageDiv.style.visibility = "hidden";
1212 CB_Mouse.CursorImage._showCursorImage = false;
1213 CB_Mouse.CursorImage._cursorImageSpriteAnimation(false); //Stops the possible sprite animation.
1214
1215 //If set, restores the normal cursor:
1216 if (!hideNormalCursor) { CB_Mouse.restore(); }
1217 }
1218 //...otherwise, forces it to follow the cursor:
1219 else if (!CB_Mouse.CursorImage._showCursorImage)
1220 {
1221 //Sets the image given as the SRC:
1222 if (CB_fakeCursorImage.src !== cursorImage)
1223 {
1224 CB_fakeCursorImage.src = cursorImage;
1225 }
1226
1227 //The image (sprite or not) has to start with 0px in its left:
1228 CB_fakeCursorImage.style.left = "0px";
1229
1230 //Sets the proper width and height:
1231 if (isSprite) //If it is a sprite, the IMG will be wider than the DIV:
1232 {
1233 CB_fakeCursorImageDiv.style.width = cursorImageWidth + "px";
1234 CB_fakeCursorImage.style.width = (cursorImageWidth * numberOfFrames) + "px";
1235 CB_fakeCursorImageDiv.style.height = CB_fakeCursorImage.style.height = cursorImageHeight + "px";
1236 }
1237 else //...otherwise, if it is not a sprite, the use of pixels is not mandatory:
1238 {
1239 if (!isNaN(cursorImageWidth)) { cursorImageWidth += "px"; } //If it is a number, they are considered pixels.
1240 if (!isNaN(cursorImageHeight)) { cursorImageHeight += "px"; } //If it is a number, they are considered pixels.
1241 CB_fakeCursorImageDiv.style.width = CB_fakeCursorImage.style.width = cursorImageWidth;
1242 CB_fakeCursorImageDiv.style.height = CB_fakeCursorImage.style.height = cursorImageHeight;
1243 }
1244
1245 //Forces the image to follow the cursor:
1246 CB_Mouse.CursorImage._showCursorImage = true;
1247
1248 //Stores the DIV and IMG elements:
1249 CB_Mouse.CursorImage._cursorImageDiv = CB_fakeCursorImageDiv;
1250 CB_Mouse.CursorImage._cursorImage = CB_fakeCursorImage;
1251
1252 //Refreshes the image coordinates:
1253 CB_Mouse.CursorImage.move();
1254
1255 //Show the image:
1256 CB_fakeCursorImageDiv.style.visibility = "visible";
1257
1258 //If set, hides the cursor:
1259 if (hideNormalCursor) { CB_Mouse.hide(); }
1260 //...otherwise, shows it:
1261 else { CB_Mouse.restore(); }
1262
1263 //If it is a sprite, starts the animation:
1264 if (isSprite)
1265 {
1266 CB_Mouse.CursorImage._cursorImageSpriteAnimation(true, cursorImageWidth, numberOfFrames, framesMs);
1267 }
1268 }
1269 }
1270
1271
1272 /**
1273 * Gets the [DIV element]{@link https://developer.mozilla.org/en-US/docs/Web/HTML/Element/div} that contains the [IMG element]{@link https://developer.mozilla.org/en-US/docs/Web/HTML/Element/img} of the fake cursor (if any).
1274 * @function
1275 * @returns {Element} Returns the [DIV element]{@link https://developer.mozilla.org/en-US/docs/Web/HTML/Element/div} that contains the [IMG element]{@link https://developer.mozilla.org/en-US/docs/Web/HTML/Element/img} of the fake cursor (if any).
1276 */
1277 CB_Mouse.CursorImage.get = function()
1278 {
1279 return CB_Mouse.CursorImage._cursorImageDiv;
1280 }
1281
1282
1283 /**
1284 * Gets the [IMG element]{@link https://developer.mozilla.org/en-US/docs/Web/HTML/Element/img} of the fake cursor (if any).
1285 * @function
1286 * @returns {Element} Returns the [IMG element]{@link https://developer.mozilla.org/en-US/docs/Web/HTML/Element/img} of the fake cursor (if any).
1287 */
1288 CB_Mouse.CursorImage.getImage = function()
1289 {
1290 return CB_Mouse.CursorImage._cursorImage;
1291 }
1292
1293
1294 /**
1295 * Tells whether the fake cursor is showing or not
1296 * @function
1297 * @returns {boolean} Returns whether the fake cursor is showing or not.
1298 */
1299 CB_Mouse.CursorImage.isShowing = function()
1300 {
1301 return CB_Mouse.CursorImage._showCursorImage;
1302 }
1303
1304
1305 /**
1306 * Hides the fake cursor image.
1307 * @function
1308 * @param {boolean} [showNormalCursor=true] - If set to true, restores (shows) the system cursor (calls the {@link CB_Mouse.restore} function internally).
1309 */
1310 CB_Mouse.CursorImage.hide = function(showNormalCursor)
1311 {
1312 //If they are not set, use default values for optional parameters:
1313 if (typeof(showNormalCursor) === "undefined" || showNormalCursor === null) { showNormalCursor = true; } //Shows normal cursor by default.
1314
1315 //If it is being displayed, hides the fake cursor image:
1316 if (CB_Mouse.CursorImage._showCursorImage)
1317 {
1318 CB_Mouse.CursorImage.set(false, null, null, null, !showNormalCursor);
1319 }
1320 }
1321
1322
1323 /**
1324 * Moves the fake cursor image (if it is not hidden). Automatically called when the [onMouseMove]{@link https://developer.mozilla.org/en-US/docs/Web/API/Element/mousemove_event} event is fired.
1325 * @function
1326 * @param {number} [x=CB_Mouse.getX(null, false)] - The X coordinate (horizontal position) in pixels where the fake cursor image wants to be moved to. If not provided, it will use the value returned by calling CB_Mouse.getX(null, false) internally.
1327 * @param {number} [y=CB_Mouse.getY(null, false)] - The Y coordinate (vertical position) in pixels where the fake cursor image wants to be moved to. If not provided, it will use the value returned by calling CB_Mouse.getY(null, false) internally.
1328 */
1329 CB_Mouse.CursorImage.move = function(x, y)
1330 {
1331 if (CB_Mouse.CursorImage._showCursorImage)
1332 {
1333 if (typeof(CB_Mouse.CursorImage._cursorImageDiv) !== "undefined" &amp;&amp; CB_Mouse.CursorImage._cursorImageDiv !== null &amp;&amp; typeof(CB_Mouse.CursorImage._cursorImageDiv.style) !== "undefined")
1334 {
1335 try //IE6 throws errors sometimes.
1336 {
1337 CB_Mouse.CursorImage._cursorImageDiv.style.left = (x || CB_Mouse.getX(null, false) || 0) + "px";
1338 CB_Mouse.CursorImage._cursorImageDiv.style.top = (y || CB_Mouse.getY(null, false) || 0) + "px";
1339 }
1340 catch(E) {}
1341 }
1342 }
1343 }
1344
1345
1346 //Starts or stops the sprite animation for the fake cursor image:
1347 CB_Mouse.CursorImage._cursorImageSpriteAnimation = function(runAnimation, cursorImageWidth, numberOfFrames, framesMs)
1348 {
1349 //If the number of frames is 1, it doesn't need to do anything:
1350 if (numberOfFrames &lt;= 1) { return; }
1351
1352 //If set, stops the animation:
1353 if (!runAnimation)
1354 {
1355 clearTimeout(CB_Mouse.CursorImage._cursorImageSpriteAnimationTimeout);
1356 CB_Mouse.CursorImage._cursorImageSpriteAnimationTimeout = null;
1357 }
1358 //...otherwise, the animation starts or continues it:
1359 else
1360 {
1361 //Continues to next frame after the given milliseconds:
1362 CB_Mouse.CursorImage._cursorImageSpriteAnimationTimeout =
1363 CB_symmetricCall
1364 (
1365 function()
1366 {
1367 if (CB_Mouse.CursorImage._cursorImageSpriteAnimationTimeout !== null)
1368 {
1369 var cursorImageLeft = CB_Elements.getStylePropertyInteger(CB_Mouse.CursorImage._cursorImage, "left")[0] - cursorImageWidth;
1370 cursorImageLeft %= (cursorImageWidth * numberOfFrames);
1371 CB_Mouse.CursorImage._cursorImage.style.left = cursorImageLeft + "px";
1372
1373 CB_Mouse.CursorImage._cursorImageSpriteAnimation(runAnimation, cursorImageWidth, numberOfFrames, framesMs);
1374 }
1375 },
1376 framesMs,
1377 "CB_MOUSE_CURSOR_IMAGE"
1378 );
1379 }
1380 }
1381} //End of the static class CB_Mouse.</pre>
1382 </article>
1383</section>
1384
1385
1386
1387
1388
1389 </div>
1390 </div>
1391
1392 <div class="clearfix"></div>
1393
1394
1395
1396</div>
1397</div>
1398
1399
1400 <div class="modal fade" id="searchResults">
1401 <div class="modal-dialog">
1402 <div class="modal-content">
1403 <div class="modal-header">
1404 <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
1405 <h4 class="modal-title">Search results</h4>
1406 </div>
1407 <div class="modal-body"></div>
1408 <div class="modal-footer">
1409 <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
1410 </div>
1411 </div><!-- /.modal-content -->
1412 </div><!-- /.modal-dialog -->
1413 </div>
1414
1415
1416<footer>
1417
1418
1419 <span class="copyright">
1420 <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>
1421 </span>
1422
1423<span class="jsdoc-message">
1424 Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 4.0.2</a>
1425
1426 on Wed Mar 22nd 2023
1427
1428 using the <a href="https://github.com/docstrap/docstrap">DocStrap template</a>.
1429</span>
1430</footer>
1431
1432<script src="scripts/docstrap.lib.js"></script>
1433<script src="scripts/toc.js"></script>
1434
1435 <script type="text/javascript" src="scripts/fulltext-search-ui.js"></script>
1436
1437
1438<script>
1439$( function () {
1440 $( "[id*='$']" ).each( function () {
1441 var $this = $( this );
1442
1443 $this.attr( "id", $this.attr( "id" ).replace( "$", "__" ) );
1444 } );
1445
1446 $( ".tutorial-section pre, .readme-section pre, pre.prettyprint.source" ).each( function () {
1447 var $this = $( this );
1448
1449 var example = $this.find( "code" );
1450 exampleText = example.html();
1451 var lang = /{@lang (.*?)}/.exec( exampleText );
1452 if ( lang && lang[1] ) {
1453 exampleText = exampleText.replace( lang[0], "" );
1454 example.html( exampleText );
1455 lang = lang[1];
1456 } else {
1457 var langClassMatch = example.parent()[0].className.match(/lang\-(\S+)/);
1458 lang = langClassMatch ? langClassMatch[1] : "javascript";
1459 }
1460
1461 if ( lang ) {
1462
1463 $this
1464 .addClass( "sunlight-highlight-" + lang )
1465 .addClass( "linenums" )
1466 .html( example.html() );
1467
1468 }
1469 } );
1470
1471 Sunlight.highlightAll( {
1472 lineNumbers : true,
1473 showMenu : true,
1474 enableDoclinks : true
1475 } );
1476
1477 $.catchAnchorLinks( {
1478 navbarOffset: 10
1479 } );
1480 $( "#toc" ).toc( {
1481 anchorName : function ( i, heading, prefix ) {
1482 return $( heading ).attr( "id" ) || ( prefix + i );
1483 },
1484 selectors : "#toc-content h1,#toc-content h2,#toc-content h3,#toc-content h4",
1485 showAndHide : false,
1486 smoothScrolling: true
1487 } );
1488
1489 $( "#main span[id^='toc']" ).addClass( "toc-shim" );
1490 $( '.dropdown-toggle' ).dropdown();
1491
1492 $( "table" ).each( function () {
1493 var $this = $( this );
1494 $this.addClass('table');
1495 } );
1496
1497} );
1498</script>
1499
1500
1501
1502<!--Navigation and Symbol Display-->
1503
1504<script>
1505 $( function () {
1506 $( '#main' ).localScroll( {
1507 offset : { top : 60 } //offset by the height of your header (give or take a few px, see what works for you)
1508 } );
1509 $( "dt.name" ).each( function () {
1510 var $this = $( this ).find("h4");
1511 var icon = $( "<i/>" ).addClass( "icon-plus-sign" ).addClass( "pull-right" ).addClass( "icon-white" );
1512 var dt = $(this);
1513 var children = dt.next( "dd" );
1514
1515 dt.prepend( icon ).css( {cursor : "pointer"} );
1516 dt.addClass( "member-collapsed" ).addClass( "member" );
1517
1518
1519 children.hide();
1520
1521 dt.children().on( "click", function () {
1522 children = dt.next( "dd" );
1523 children.slideToggle( "fast", function () {
1524
1525 if ( children.is( ":visible" ) ) {
1526 icon.addClass( "icon-minus-sign" ).removeClass( "icon-plus-sign" ).removeClass( "icon-white" );
1527 dt.addClass( "member-open" ).animate( "member-collapsed" );
1528 } else {
1529 icon.addClass( "icon-plus-sign" ).removeClass( "icon-minus-sign" ).addClass( "icon-white" );
1530 dt.addClass( "member-collapsed" ).removeClass( "member-open" );
1531 }
1532 } );
1533 } );
1534
1535 } );
1536 } );
1537</script>
1538
1539
1540<!--Google Analytics-->
1541
1542
1543
1544 <script type="text/javascript">
1545 $(document).ready(function() {
1546 SearcherDisplay.init();
1547 });
1548 </script>
1549
1550
1551</body>
1552</html>