UNPKG

47.6 kBHTMLView Raw
1<!DOCTYPE html>
2
3<html lang="en">
4<head>
5 <meta charset="utf-8">
6 <meta name="viewport" content="width=device-width">
7 <title>CrossBrowdy API documentation Source: CrossBase/general/CB_Collisions.js</title>
8
9 <!--[if lt IE 9]>
10 <script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script>
11 <![endif]-->
12 <link type="text/css" rel="stylesheet" href="styles/sunlight.default.css">
13
14 <link type="text/css" rel="stylesheet" href="styles/site.cosmo.css">
15
16</head>
17
18<body style="min-width:800px; overflow-wrap:break-word; word-wrap:break-word; word-break:break-word; line-break:strict; hyphens:none; -webkit-hyphens:none; -moz-hyphens:none;">
19
20<div class="navbar navbar-default navbar-fixed-top ">
21<div class="container">
22 <div class="navbar-header">
23 <a class="navbar-brand" href="index.html">CrossBrowdy API documentation</a>
24 <button class="navbar-toggle" type="button" data-toggle="collapse" data-target="#topNavigation">
25 <span class="icon-bar"></span>
26 <span class="icon-bar"></span>
27 <span class="icon-bar"></span>
28 </button>
29 </div>
30 <div class="navbar-collapse collapse" id="topNavigation">
31 <ul class="nav navbar-nav">
32
33 <li class="dropdown">
34 <a href="namespaces.list.html" class="dropdown-toggle" data-toggle="dropdown">Namespaces<b class="caret"></b></a>
35 <ul class="dropdown-menu inline">
36 <li><a href="CB_Arrays.html">CB_Arrays</a></li><li><a href="CB_AudioDetector.html">CB_AudioDetector</a></li><li><a href="CB_baseSymbols.html">CB_baseSymbols</a></li><li><a href="CB_Client.html">CB_Client</a></li><li><a href="CB_Collisions.html">CB_Collisions</a></li><li><a href="CB_Configuration.html">CB_Configuration</a></li><li><a href="CB_Configuration.CrossBase.html">CB_Configuration.CrossBase</a></li><li><a href="CB_Configuration.CrossBrowdy.html">CB_Configuration.CrossBrowdy</a></li><li><a href="CB_Controllers.html">CB_Controllers</a></li><li><a href="CB_Controllers_Proprietary.html">CB_Controllers_Proprietary</a></li><li><a href="CB_Controllers_Proprietary.WII.html">CB_Controllers_Proprietary.WII</a></li><li><a href="CB_Controllers_Proprietary.WII_U.html">CB_Controllers_Proprietary.WII_U</a></li><li><a href="CB_Device.html">CB_Device</a></li><li><a href="CB_Device.AmbientLight.html">CB_Device.AmbientLight</a></li><li><a href="CB_Device.Battery.html">CB_Device.Battery</a></li><li><a href="CB_Device.Location.html">CB_Device.Location</a></li><li><a href="CB_Device.Motion.html">CB_Device.Motion</a></li><li><a href="CB_Device.Orientation.html">CB_Device.Orientation</a></li><li><a href="CB_Device.Proximity.html">CB_Device.Proximity</a></li><li><a href="CB_Device.Vibration.html">CB_Device.Vibration</a></li><li><a href="CB_Elements.html">CB_Elements</a></li><li><a href="CB_Events.html">CB_Events</a></li><li><a href="CB_Keyboard.html">CB_Keyboard</a></li><li><a href="CB_Keyboard.chars.html">CB_Keyboard.chars</a></li><li><a href="CB_Keyboard.extended.html">CB_Keyboard.extended</a></li><li><a href="CB_Keyboard.keys.html">CB_Keyboard.keys</a></li><li><a href="CB_Modules.html">CB_Modules</a></li><li><a href="CB_Mouse.html">CB_Mouse</a></li><li><a href="CB_Mouse.CursorImage.html">CB_Mouse.CursorImage</a></li><li><a href="CB_Net.html">CB_Net</a></li><li><a href="CB_Net.Fetch.html">CB_Net.Fetch</a></li><li><a href="CB_Net.REST.html">CB_Net.REST</a></li><li><a href="CB_Net.Sockets.html">CB_Net.Sockets</a></li><li><a href="CB_Net.Sockets.SockJS.html">CB_Net.Sockets.SockJS</a></li><li><a href="CB_Net.XHR.html">CB_Net.XHR</a></li><li><a href="CB_Pointer.html">CB_Pointer</a></li><li><a href="CB_Screen.html">CB_Screen</a></li><li><a href="CB_Speaker.html">CB_Speaker</a></li><li><a href="CB_Touch.html">CB_Touch</a></li>
37 </ul>
38 </li>
39
40 <li class="dropdown">
41 <a href="classes.list.html" class="dropdown-toggle" data-toggle="dropdown">Classes<b class="caret"></b></a>
42 <ul class="dropdown-menu inline">
43 <li><a href="CB_AudioFile.html">CB_AudioFile</a></li><li><a href="CB_AudioFile_API.AAPI.html">CB_AudioFile_API.AAPI</a></li><li><a href="CB_AudioFile_API.ACMP.html">CB_AudioFile_API.ACMP</a></li><li><a href="CB_AudioFile_API.SM2.html">CB_AudioFile_API.SM2</a></li><li><a href="CB_AudioFile_API.WAAPI.html">CB_AudioFile_API.WAAPI</a></li><li><a href="CB_AudioFileCache.html">CB_AudioFileCache</a></li><li><a href="CB_AudioFileSprites.html">CB_AudioFileSprites</a></li><li><a href="CB_AudioFileSpritesPool.html">CB_AudioFileSpritesPool</a></li><li><a href="CB_Canvas.html">CB_Canvas</a></li><li><a href="CB_GraphicSprites.html">CB_GraphicSprites</a></li><li><a href="CB_GraphicSpritesScene.html">CB_GraphicSpritesScene</a></li>
44 </ul>
45 </li>
46
47 <li class="dropdown">
48 <a href="global.html" class="dropdown-toggle" data-toggle="dropdown">Global<b class="caret"></b></a>
49 <ul class="dropdown-menu inline">
50 <li><a href="global.html#CB_addCredits">CB_addCredits</a></li><li><a href="global.html#CB_BASE_NAME">CB_BASE_NAME</a></li><li><a href="global.html#CB_baseToBase">CB_baseToBase</a></li><li><a href="global.html#CB_baseToInt">CB_baseToInt</a></li><li><a href="global.html#CB_br2nl">CB_br2nl</a></li><li><a href="global.html#CB_brToNl">CB_brToNl</a></li><li><a href="global.html#CB_combineArraysOrObjects">CB_combineArraysOrObjects</a></li><li><a href="global.html#CB_combineAutomatically">CB_combineAutomatically</a></li><li><a href="global.html#CB_combineJSON">CB_combineJSON</a></li><li><a href="global.html#CB_combineURIParameters">CB_combineURIParameters</a></li><li><a href="global.html#CB_combineURLParameters">CB_combineURLParameters</a></li><li><a href="global.html#CB_console">CB_console</a></li><li><a href="global.html#CB_copyObject">CB_copyObject</a></li><li><a href="global.html#CB_countDecimalDigits">CB_countDecimalDigits</a></li><li><a href="global.html#CB_countDecimalPart">CB_countDecimalPart</a></li><li><a href="global.html#CB_countDecimals">CB_countDecimals</a></li><li><a href="global.html#CB_countIntegerDigits">CB_countIntegerDigits</a></li><li><a href="global.html#CB_countIntegerPart">CB_countIntegerPart</a></li><li><a href="global.html#CB_credits">CB_credits</a></li><li><a href="global.html#CB_CREDITS_DEFAULT">CB_CREDITS_DEFAULT</a></li><li><a href="global.html#CB_forceString">CB_forceString</a></li><li><a href="global.html#CB_forEach">CB_forEach</a></li><li><a href="global.html#CB_getBase64StringObject">CB_getBase64StringObject</a></li><li><a href="global.html#CB_getCookie">CB_getCookie</a></li><li><a href="global.html#CB_getDatum">CB_getDatum</a></li><li><a href="global.html#CB_getJSONPropertyValue">CB_getJSONPropertyValue</a></li><li><a href="global.html#CB_getLZStringObject">CB_getLZStringObject</a></li><li><a href="global.html#CB_getValueIndex">CB_getValueIndex</a></li><li><a href="global.html#CB_getValuePath">CB_getValuePath</a></li><li><a href="global.html#CB_includeJSFile">CB_includeJSFile</a></li><li><a href="global.html#CB_indexOf">CB_indexOf</a></li><li><a href="global.html#CB_init">CB_init</a></li><li><a href="global.html#CB_intToBase">CB_intToBase</a></li><li><a href="global.html#CB_isArray">CB_isArray</a></li><li><a href="global.html#CB_isEmail">CB_isEmail</a></li><li><a href="global.html#CB_isFileLocal">CB_isFileLocal</a></li><li><a href="global.html#CB_isString">CB_isString</a></li><li><a href="global.html#CB_lastIndexOf">CB_lastIndexOf</a></li><li><a href="global.html#CB_ltrim">CB_ltrim</a></li><li><a href="global.html#CB_NAME">CB_NAME</a></li><li><a href="global.html#CB_nl2br">CB_nl2br</a></li><li><a href="global.html#CB_nlToBr">CB_nlToBr</a></li><li><a href="global.html#CB_numberFormat">CB_numberFormat</a></li><li><a href="global.html#CB_numberOfDecimalDigits">CB_numberOfDecimalDigits</a></li><li><a href="global.html#CB_numberOfDecimals">CB_numberOfDecimals</a></li><li><a href="global.html#CB_numberOfIntegerDigits">CB_numberOfIntegerDigits</a></li><li><a href="global.html#CB_OPTIONS">CB_OPTIONS</a></li><li><a href="global.html#CB_parseJSON">CB_parseJSON</a></li><li><a href="global.html#CB_parseString">CB_parseString</a></li><li><a href="global.html#CB_regularExpressionString">CB_regularExpressionString</a></li><li><a href="global.html#CB_renderString">CB_renderString</a></li><li><a href="global.html#CB_replaceAll">CB_replaceAll</a></li><li><a href="global.html#CB_rtrim">CB_rtrim</a></li><li><a href="global.html#CB_scriptPath">CB_scriptPath</a></li><li><a href="global.html#CB_scriptPathCalculate">CB_scriptPathCalculate</a></li><li><a href="global.html#CB_setCookie">CB_setCookie</a></li><li><a href="global.html#CB_setDatum">CB_setDatum</a></li><li><a href="global.html#CB_sizeof">CB_sizeof</a></li><li><a href="global.html#CB_sizeOf">CB_sizeOf</a></li><li><a href="global.html#CB_stringifyJSON">CB_stringifyJSON</a></li><li><a href="global.html#CB_symmetricCall">CB_symmetricCall</a></li><li><a href="global.html#CB_symmetricCallClear">CB_symmetricCallClear</a></li><li><a href="global.html#CB_this">CB_this</a></li><li><a href="global.html#CB_trim">CB_trim</a></li><li><a href="global.html#CB_VERSION">CB_VERSION</a></li>
51 </ul>
52 </li>
53
54 </ul>
55
56 <div class="col-sm-3 col-md-3">
57 <form class="navbar-form" role="search">
58 <div class="input-group">
59 <input type="text" class="form-control" placeholder="Search" name="q" id="search-input">
60 <div class="input-group-btn">
61 <button class="btn btn-default" id="search-submit"><i class="glyphicon glyphicon-search"></i></button>
62 </div>
63 </div>
64 </form>
65 </div>
66
67 </div>
68
69</div>
70</div>
71
72
73<div class="container" id="toc-content" style="width:100%;">
74<div class="row" style="width:100%;">
75
76
77 <div class="col-md-12">
78
79 <div id="main">
80
81
82 <h1 class="page-title">Source: CrossBase/general/CB_Collisions.js</h1>
83
84<section>
85 <article>
86 <pre
87 class="sunlight-highlight-javascript linenums">/**
88 * @file Collisions management. Contains the {@link CB_Collisions} 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 collisions. It will return itself if it is tried to be instantiated.
96 * @namespace
97 * @todo Finish many functions for many more kinds of collisions.
98 * @todo Add triangles, polygons, arcs, etc.
99 * @todo Add support to more dimensions (at least to 3D).
100 * @todo Add lacking "touching" functions, equivalent to the "over" ones.
101 * @todo Add a boolean parameter and a border parameter to detect collision just when it hits the border (not when it is inside of the object without touching the border), for "hollow" shapes.
102 * @todo Think about adding function aliases with reversed names (for example, "isElementOverPoint" that points to "isPointOverElement", etc.). Think about whether the aliases should or not have some parameters in reversed order.
103 */
104var CB_Collisions = function() { return CB_Collisions; };
105{
106 CB_Collisions.initialized = false; //It will tells whether the object has been initialized or not.
107
108
109 //Initializes all values:
110 CB_Collisions.init = function()
111 {
112 if (CB_Collisions.initialized) { return CB_Collisions; }
113
114 //The object has been initialized:
115 CB_Collisions.initialized = true;
116
117 //TODO.
118
119 return CB_Collisions;
120 }
121
122
123 //TODO: add polygons, arcs, etc.
124
125
126 /**
127 * Tells the distance between two points.
128 * @function
129 * @param {number} x - The "X" coordinate of the first point.
130 * @param {number} y - The "Y" coordinate of the first point.
131 * @param {number} x2 - The "X" coordinate of the second point.
132 * @param {number} y2 - The "Y" coordinate of the second point.
133 * @returns {number|null} Returns the distance between the two points. In the case that it could not be calculated, returns null.
134 */
135 CB_Collisions.getDistancePoints = function(x, y, x2, y2)
136 {
137 var distance = parseFloat(Math.sqrt(Math.pow(x - x2, 2) + Math.pow(y - y2, 2)));
138 return isNaN(distance) ? null : distance;
139 }
140
141
142 /**
143 * Tells whether a given point is over a given DOM element (it will be considered a rectangle).
144 * @function
145 * @param {number} x - The "X" coordinate of the point.
146 * @param {number} y - The "Y" coordinate of the point.
147 * @param {Element} element - The DOM element that we want to check (it will be considered a rectangle).
148 * @returns {boolean} Returns whether the point is over the given DOM element (it will be considered a rectangle).
149 */
150 CB_Collisions.isPointOverElement = function(x, y, element)
151 {
152 if (typeof(element) === "undefined" || element === null) { return false; }
153 return CB_Collisions.isPointOverRectangle(x, y, CB_Elements.getLeft(element), CB_Elements.getTop(element), CB_Elements.getWidth(element), CB_Elements.getHeight(element));
154 }
155
156
157 /**
158 * Tells whether a given point is touching (maybe over) a given DOM element (it will be considered a rectangle). This will also return true if they are adjacent (next to each other).
159 * @function
160 * @param {number} x - The "X" coordinate of the point.
161 * @param {number} y - The "Y" coordinate of the point.
162 * @param {Element} element - The DOM element that we want to check (it will be considered a rectangle).
163 * @returns {boolean} Returns whether the point is touching (maybe over) the given DOM element (it will be considered a rectangle). This will also return true if they are adjacent (next to each other).
164 */
165 CB_Collisions.isPointTouchingElement = function(x, y, element)
166 {
167 if (typeof(element) === "undefined" || element === null) { return false; }
168 return CB_Collisions.isPointTouchingRectangle(x, y, CB_Elements.getLeft(element), CB_Elements.getTop(element), CB_Elements.getWidth(element), CB_Elements.getHeight(element));
169 }
170
171
172 /**
173 * Tells whether a point is over a line (infinite).
174 * @function
175 * @param {number} x - The "X" coordinate of the point.
176 * @param {number} y - The "Y" coordinate of the point.
177 * @param {number} lineX1 - The "X" coordinate of a first point of the line.
178 * @param {number} lineY1 - The "Y" coordinate of a first point of the line.
179 * @param {number} lineX2 - The "X" coordinate of a second point of the line.
180 * @param {number} lineY2 - The "Y" coordinate of a second point of the line.
181 * @param {number} [tolerance=0.001] - The amount of loss of precision we can tolerate to consider a collision.
182 * @returns {boolean} Returns whether the point is over the line (infinite).
183 * @todo Think about using a "width" parameter (apart from the "tolerance" parameter).
184 * @todo Create a CB_Collisions.isPointTouchingLine function.
185 */
186 CB_Collisions.isPointOverLine = function(x, y, lineX1, lineY1, lineX2, lineY2, tolerance)
187 {
188 if (typeof(tolerance) === "undefined" || tolerance === null) { tolerance = 0.001; }
189
190 //If the line is vertical (infinite slope) or just a point:
191 if (lineX1 === lineX2)
192 {
193 //If the point is in the same X axis:
194 if (x === lineX1)
195 {
196 //If the line has the same Y at both ends, it's in fact just a point:
197 if (lineY1 === lineY2)
198 {
199 //If the point is in the same Y axis:
200 if (y === lineY1) { return true; } //The line is a point and the point given is the same one.
201 }
202 else if (lineY1 &lt; lineY2)
203 {
204 if (y >= lineY1 &amp;&amp; y &lt;= lineY2) { return true; }
205 }
206 else //lineY1 > lineY2
207 {
208 if (y >= lineY2 &amp;&amp; y &lt;= lineY1) { return true; }
209 }
210 }
211 }
212 else
213 {
214 var slope = (lineY2 - lineY1) / (lineX2 - lineX1);
215 var yIntercept = lineY1 - slope * lineX1;
216 if (Math.abs(y - (slope * x + yIntercept)) &lt;= tolerance)
217 {
218 return true;
219 }
220 }
221
222 return false;
223 }
224
225
226 /**
227 * Tells whether a point is over a line segment.
228 * @function
229 * @param {number} x - The "X" coordinate of the point.
230 * @param {number} y - The "Y" coordinate of the point.
231 * @param {number} segmentX1 - The "X" coordinate of the beginning point of the line.
232 * @param {number} segmentY1 - The "Y" coordinate of the beginning point of the line.
233 * @param {number} segmentX2 - The "X" coordinate of the end point of the line.
234 * @param {number} segmentY2 - The "Y" coordinate of the end point of the line.
235 * @param {number} [tolerance=0.001] - The amount of loss of precision we can tolerate to consider a collision.
236 * @returns {boolean} Returns whether the point is over the line segment.
237 * @todo Think about using a "width" parameter (apart from the "tolerance" parameter).
238 * @todo Create a CB_Collisions.isPointTouchingSegment function.
239 */
240 CB_Collisions.isPointOverSegment = function(x, y, segmentX1, segmentY1, segmentX2, segmentY2, tolerance)
241 {
242 var rectangleX1 = segmentX1;
243 var rectangleY1 = segmentY1;
244 var rectangleX2 = segmentX2;
245 var rectangleY2 = segmentY2;
246
247 if (segmentX2 &lt; segmentX1)
248 {
249 rectangleX1 = segmentX2;
250 rectangleX2 = segmentX1;
251 }
252 if (segmentY2 &lt; segmentY1)
253 {
254 rectangleY1 = segmentY2;
255 rectangleY2 = segmentY1;
256 }
257
258 if (CB_Collisions.isPointOverRectangle(x, y, rectangleX1, rectangleY1, rectangleX2 - rectangleX1 /*rectangleWidth*/, rectangleY2 - rectangleY1 /*rectangleHeight*/))
259 {
260 return CB_Collisions.isPointOverLine(x, y, segmentX1, segmentY1, segmentX2, segmentY2, tolerance);
261 }
262
263 return false;
264 }
265
266
267 /**
268 * Tells whether a point is over a rectangle.
269 * @function
270 * @param {number} x - The "X" coordinate of the point.
271 * @param {number} y - The "Y" coordinate of the point.
272 * @param {number} rectangleX - The "X" coordinate of the upper left corner of the rectangle.
273 * @param {number} rectangleY - The "Y" coordinate of the upper left corner of the rectangle.
274 * @param {number} rectangleWidth - The width of the rectangle.
275 * @param {number} rectangleHeight - The height of the rectangle.
276 * @returns {boolean} Returns whether the point is over the rectangle.
277 * @todo Think about using a "rotation" parameter to accept rotated rectangles.
278 */
279 CB_Collisions.isPointOverRectangle = function(x, y, rectangleX, rectangleY, rectangleWidth, rectangleHeight)
280 {
281 return (x > rectangleX &amp;&amp; x &lt; rectangleX + rectangleWidth &amp;&amp; y > rectangleY &amp;&amp; y &lt; rectangleY + rectangleHeight);
282 }
283
284
285 /**
286 * Tells whether a point is touching (maybe over) a rectangle. This will also return true if they are adjacent (next to each other).
287 * @function
288 * @param {number} x - The "X" coordinate of the point.
289 * @param {number} y - The "Y" coordinate of the point.
290 * @param {number} rectangleX - The "X" coordinate of the upper left corner of the rectangle.
291 * @param {number} rectangleY - The "Y" coordinate of the upper left corner of the rectangle.
292 * @param {number} rectangleWidth - The width of the rectangle.
293 * @param {number} rectangleHeight - The height of the rectangle.
294 * @returns {boolean} Returns whether the point is touching (maybe over) the rectangle. This will also return true if they are adjacent (next to each other).
295 * @todo Think about using a "rotation" parameter to accept rotated rectangles.
296 */
297 CB_Collisions.isPointTouchingRectangle = function(x, y, rectangleX, rectangleY, rectangleWidth, rectangleHeight)
298 {
299 /*
300 if (x >= rectangleX &amp;&amp; x &lt;= rectangleX + rectangleWidth)
301 {
302 if (y >= rectangleY &amp;&amp; y &lt;= rectangleY + rectangleHeight)
303 {
304 return true;
305 }
306 }
307 return false;
308 */
309 return (x >= rectangleX &amp;&amp; x &lt;= rectangleX + rectangleWidth &amp;&amp; y >= rectangleY &amp;&amp; y &lt;= rectangleY + rectangleHeight);
310 }
311
312
313 /**
314 * Tells whether a point is over a circle.
315 * @function
316 * @param {number} x - The "X" coordinate of the point.
317 * @param {number} y - The "Y" coordinate of the point.
318 * @param {number} centreX - The "X" coordinate of the center of the circle.
319 * @param {number} centreY - The "Y" coordinate of the center of the circle.
320 * @param {number} radius - The radius of the circle.
321 * @returns {boolean} Returns whether the point is over the circle.
322 */
323 CB_Collisions.isPointOverCircle = function(x, y, centreX, centreY, radius)
324 {
325 //If the distance is lower than the radius, there is a collision:
326 //return (Math.sqrt(Math.pow(centreX - x, 2) + Math.pow(centreY - y, 2)) &lt; radius);
327 return CB_Collisions.getDistancePoints(centreX, centreY, x, y) &lt; radius;
328 }
329
330
331 /**
332 * Tells whether a point is touching (maybe over) a circle. This will also return true if they are adjacent (next to each other).
333 * @function
334 * @param {number} x - The "X" coordinate of the point.
335 * @param {number} y - The "Y" coordinate of the point.
336 * @param {number} centreX - The "X" coordinate of the center of the circle.
337 * @param {number} centreY - The "Y" coordinate of the center of the circle.
338 * @param {number} radius - The radius of the circle.
339 * @returns {boolean} Returns whether the point is touching (maybe over) the circle. This will also return true if they are adjacent (next to each other).
340 */
341 CB_Collisions.isPointTouchingCircle = function(x, y, centreX, centreY, radius)
342 {
343 //If the distance is lower than the radius, there is a collision:
344 //return (Math.sqrt(Math.pow(centreX - x, 2) + Math.pow(centreY - y, 2)) &lt; radius);
345 return CB_Collisions.getDistancePoints(centreX, centreY, x, y) &lt;= radius;
346 }
347
348
349 /**
350 * Tells whether a point is over an ellipse.
351 * @function
352 * @param {number} x - The "X" coordinate of the point.
353 * @param {number} y - The "Y" coordinate of the point.
354 * @param {number} centreX - The "X" coordinate of the center of the ellipse.
355 * @param {number} centreY - The "Y" coordinate of the center of the ellipse.
356 * @param {number} radiusX - The X (horizontal) radius of the ellipse.
357 * @param {number} radiusY - The Y (vertical) radius of the ellipse.
358 * @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!
359 * @param {boolean} [rotationUseDegrees=false] - Defines whether the "rotation" given should be considered degrees or not (radians). Not implemented yet!
360 * @returns {boolean} Returns whether the point is over the ellipse.
361 * @todo Make the "rotation" parameter work (check https://math.stackexchange.com/questions/426150/what-is-the-general-equation-of-the-ellipse-that-is-not-in-the-origin-and-rotate).
362 */
363 CB_Collisions.isPointOverEllipse = function(x, y, centreX, centreY, radiusX, radiusY, rotation, rotationUseDegrees)
364 {
365 if (typeof(rotation) === "undefined" || rotation === null || isNaN(rotation)) { rotation = 0; }
366 if (rotationUseDegrees &amp;&amp; rotation !== 0) { rotation *= Math.PI / 180 }
367
368 var dx = x - centreX;
369 var dy = y - centreY;
370 return (dx * dx) / (radiusX * radiusX) + (dy * dy) / (radiusY * radiusY) &lt; 1;
371 }
372
373
374 /**
375 * Tells whether a point is touching (maybe over) a ellipse. This will also return true if they are adjacent (next to each other).
376 * @function
377 * @param {number} x - The "X" coordinate of the point.
378 * @param {number} y - The "Y" coordinate of the point.
379 * @param {number} centreX - The "X" coordinate of the center of the ellipse.
380 * @param {number} centreY - The "Y" coordinate of the center of the ellipse.
381 * @param {number} radiusX - The X (horizontal) radius of the ellipse.
382 * @param {number} radiusY - The Y (vertical) radius of the ellipse.
383 * @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!
384 * @param {boolean} [rotationUseDegrees=false] - Defines whether the "rotation" given should be considered degrees or not (radians). Not implemented yet!
385 * @returns {boolean} Returns whether the point is touching (maybe over) the ellipse. This will also return true if they are adjacent (next to each other).
386 * @todo Make the "rotation" parameter work (check https://math.stackexchange.com/questions/426150/what-is-the-general-equation-of-the-ellipse-that-is-not-in-the-origin-and-rotate).
387 */
388 CB_Collisions.isPointTouchingEllipse = function(x, y, centreX, centreY, radiusX, radiusY, rotation, rotationUseDegrees)
389 {
390 if (typeof(rotation) === "undefined" || rotation === null || isNaN(rotation)) { rotation = 0; }
391 if (rotationUseDegrees &amp;&amp; rotation !== 0) { rotation *= Math.PI / 180 }
392
393 var dx = x - centreX;
394 var dy = y - centreY;
395 return (dx * dx) / (radiusX * radiusX) + (dy * dy) / (radiusY * radiusY) &lt;= 1;
396 }
397
398
399 /**
400 * Tells whether a rectangle is over another rectangle.
401 * @function
402 * @param {number} rectangleX - The "X" coordinate of the upper left corner of the first rectangle.
403 * @param {number} rectangleY - The "Y" coordinate of the upper left corner of the first rectangle.
404 * @param {number} rectangleWidth - The width of the first rectangle.
405 * @param {number} rectangleHeight - The height of the first rectangle.
406 * @param {number} rectangleX2 - The "X" coordinate of the upper left corner of the second rectangle.
407 * @param {number} rectangleY2 - The "Y" coordinate of the upper left corner of the second rectangle.
408 * @param {number} rectangleWidth2 - The width of the second rectangle.
409 * @param {number} rectangleHeight2 - The height of the second rectangle.
410 * @returns {boolean} Returns whether the rectangle is over the other rectangle.
411 * @todo Think about using "rotation" and "rotation2" parameters to accept rotated rectangles.
412 */
413 CB_Collisions.isRectangleOverRectangle = function(rectangleX, rectangleY, rectangleWidth, rectangleHeight, rectangleX2, rectangleY2, rectangleWidth2, rectangleHeight2)
414 {
415 return (
416 Math.max(rectangleX, rectangleX2) &lt; Math.min(rectangleX + rectangleWidth, rectangleX2 + rectangleWidth2) &amp;&amp;
417 Math.max(rectangleY, rectangleY2) &lt; Math.min(rectangleY + rectangleHeight, rectangleY2 + rectangleHeight2)
418 );
419 }
420
421
422 /**
423 * Tells whether a rectangle is touching (maybe over) another rectangle. This will also return true if they are adjacent (next to each other).
424 * @function
425 * @param {number} rectangleX - The "X" coordinate of the upper left corner of the first rectangle.
426 * @param {number} rectangleY - The "Y" coordinate of the upper left corner of the first rectangle.
427 * @param {number} rectangleWidth - The width of the first rectangle.
428 * @param {number} rectangleHeight - The height of the first rectangle.
429 * @param {number} rectangleX2 - The "X" coordinate of the upper left corner of the second rectangle.
430 * @param {number} rectangleY2 - The "Y" coordinate of the upper left corner of the second rectangle.
431 * @param {number} rectangleWidth2 - The width of the second rectangle.
432 * @param {number} rectangleHeight2 - The height of the second rectangle.
433 * @returns {boolean} Returns whether the rectangle is touching (maybe over) the other rectangle. This will also return true if they are adjacent (next to each other).
434 * @todo Think about using "rotation" and "rotation2" parameters to accept rotated rectangles.
435 */
436 CB_Collisions.isRectangleTouchingRectangle = function(rectangleX, rectangleY, rectangleWidth, rectangleHeight, rectangleX2, rectangleY2, rectangleWidth2, rectangleHeight2)
437 {
438 return (
439 Math.max(rectangleX, rectangleX2) &lt;= Math.min(rectangleX + rectangleWidth, rectangleX2 + rectangleWidth2) &amp;&amp;
440 Math.max(rectangleY, rectangleY2) &lt;= Math.min(rectangleY + rectangleHeight, rectangleY2 + rectangleHeight2)
441 );
442 }
443
444
445 /**
446 * Tells whether a rectangle is over a given DOM element (it will be considered a rectangle).
447 * @function
448 * @param {number} rectangleX - The "X" coordinate of the upper left corner of the first rectangle.
449 * @param {number} rectangleY - The "Y" coordinate of the upper left corner of the first rectangle.
450 * @param {number} rectangleWidth - The width of the first rectangle.
451 * @param {number} rectangleHeight - The height of the first rectangle.
452 * @param {Element} element - The DOM element that we want to check (it will be considered a rectangle).
453 * @returns {boolean} Returns whether the rectangle is over the given DOM element (it will be considered a rectangle).
454 * @todo Think about using a "rotation" parameter to accept rotated rectangles.
455 */
456 CB_Collisions.isRectangleOverElement = function(rectangleX, rectangleY, rectangleWidth, rectangleHeight, element)
457 {
458 if (typeof(element) === "undefined" || element === null) { return false; }
459 return CB_Collisions.isRectangleOverRectangle(rectangleX, rectangleY, rectangleWidth, rectangleHeight, CB_Elements.getLeft(element), CB_Elements.getTop(element), CB_Elements.getWidth(element), CB_Elements.getHeight(element));
460 }
461
462
463 /**
464 * Tells whether a rectangle is touching (maybe over) a given DOM element (it will be considered a rectangle). This will also return true if they are adjacent (next to each other).
465 * @function
466 * @param {number} rectangleX - The "X" coordinate of the upper left corner of the first rectangle.
467 * @param {number} rectangleY - The "Y" coordinate of the upper left corner of the first rectangle.
468 * @param {number} rectangleWidth - The width of the first rectangle.
469 * @param {number} rectangleHeight - The height of the first rectangle.
470 * @param {Element} element - The DOM element that we want to check (it will be considered a rectangle).
471 * @returns {boolean} Returns whether the rectangle is touching (maybe over) the given DOM element (it will be considered a rectangle). This will also return true if they are adjacent (next to each other).
472 * @todo Think about using a "rotation" parameter to accept rotated rectangles.
473 */
474 CB_Collisions.isRectangleTouchingElement = function(rectangleX, rectangleY, rectangleWidth, rectangleHeight, element)
475 {
476 if (typeof(element) === "undefined" || element === null) { return false; }
477 return CB_Collisions.isRectangleTouchingRectangle(rectangleX, rectangleY, rectangleWidth, rectangleHeight, CB_Elements.getLeft(element), CB_Elements.getTop(element), CB_Elements.getWidth(element), CB_Elements.getHeight(element));
478 }
479
480
481 /**
482 * Tells whether two given DOM elements are over each other (they will be considered a rectangle).
483 * @function
484 * @param {Element} element - The first DOM element that we want to check (it will be considered a rectangle).
485 * @param {Element} element2 - The second DOM element that we want to check (it will be considered a rectangle).
486 * @returns {boolean} Returns whether the two given DOM elements are over each other (they will be considered a rectangle).
487 */
488 CB_Collisions.isElementOverElement = function(element, element2)
489 {
490 if (typeof(element) === "undefined" || element === null) { return false; }
491 return CB_Collisions.isRectangleOverElement(CB_Elements.getLeft(element), CB_Elements.getTop(element), CB_Elements.getWidth(element), CB_Elements.getHeight(element), element2);
492 }
493
494
495 /**
496 * Tells whether two given DOM elements are touching each other, maybe over each other (they will be considered a rectangle). This will also return true if they are adjacent (next to each other).
497 * @function
498 * @param {Element} element - The first DOM element that we want to check (it will be considered a rectangle).
499 * @param {Element} element2 - The second DOM element that we want to check (it will be considered a rectangle).
500 * @returns {boolean} Returns whether the two given DOM elements are touching each other, maybe over each other (they will be considered a rectangle). This will also return true if they are adjacent (next to each other).
501 */
502 CB_Collisions.isElementTouchingElement = function(element, element2)
503 {
504 if (typeof(element) === "undefined" || element === null) { return false; }
505 return CB_Collisions.isRectangleTouchingElement(CB_Elements.getLeft(element), CB_Elements.getTop(element), CB_Elements.getWidth(element), CB_Elements.getHeight(element), element2);
506 }
507
508
509 /**
510 * Tells whether a circle is over another circle.
511 * @function
512 * @param {number} centreX - The "X" coordinate of the center of the first circle.
513 * @param {number} centreY - The "Y" coordinate of the center of the first circle.
514 * @param {number} radius - The radius of the first circle.
515 * @param {number} centreX2 - The "X" coordinate of the center of the second circle.
516 * @param {number} centreY2 - The "Y" coordinate of the center of the second circle.
517 * @param {number} radius2 - The radius of the second circle.
518 * @returns {boolean} Returns whether the circle is over the other circle.
519 */
520 CB_Collisions.isCircleOverCircle = function(centreX, centreY, radius, centreX2, centreY2, radius2)
521 {
522 //return (Math.sqrt(Math.pow(centreX - centreX2, 2) + Math.pow(centreY - centreY2, 2)) &lt; radius + radius2);
523 return CB_Collisions.getDistancePoints(centreX, centreY, centreX2, centreY2) &lt; radius + radius2;
524 }
525
526
527 /**
528 * Tells whether a circle is touching (maybe over) another circle. This will also return true if they are adjacent (next to each other).
529 * @function
530 * @param {number} centreX - The "X" coordinate of the center of the first circle.
531 * @param {number} centreY - The "Y" coordinate of the center of the first circle.
532 * @param {number} radius - The radius of the first circle.
533 * @param {number} centreX2 - The "X" coordinate of the center of the second circle.
534 * @param {number} centreY2 - The "Y" coordinate of the center of the second circle.
535 * @param {number} radius2 - The radius of the second circle.
536 * @returns {boolean} Returns whether the circle is touching (maybe over) the other circle. This will also return true if they are adjacent (next to each other).
537 */
538 CB_Collisions.isCircleTouchingCircle = function(centreX, centreY, radius, centreX2, centreY2, radius2)
539 {
540 //return (Math.sqrt(Math.pow(centreX - centreX2, 2) + Math.pow(centreY - centreY2, 2)) &lt;= radius + radius2);
541 return CB_Collisions.getDistancePoints(centreX, centreY, centreX2, centreY2) &lt;= radius + radius2;
542 }
543
544
545 /**
546 * Tells whether a circle is over a given rectangle.
547 * @function
548 * @param {number} centreX - The "X" coordinate of the center of the first circle.
549 * @param {number} centreY - The "Y" coordinate of the center of the first circle.
550 * @param {number} radius - The radius of the first circle.
551 * @param {number} rectangleX - The "X" coordinate of the upper left corner of the first rectangle.
552 * @param {number} rectangleY - The "Y" coordinate of the upper left corner of the first rectangle.
553 * @param {number} rectangleWidth - The width of the first rectangle.
554 * @param {number} rectangleHeight - The height of the first rectangle.
555 * @returns {boolean} Returns whether the circle is over the rectangle.
556 * @todo Think about using a "rotation" parameter to accept rotated rectangles.
557 */
558 //* Source (modified): markE at https://stackoverflow.com/questions/21089959/detecting-collision-of-rectangle-with-circle
559 CB_Collisions.isRectangleOverCircle = function(centreX, centreY, radius, rectangleX, rectangleY, rectangleWidth, rectangleHeight)
560 {
561 var distanceX = Math.abs(centreX - rectangleX - rectangleWidth / 2);
562 var distanceY = Math.abs(centreY - rectangleY - rectangleHeight / 2);
563
564 if (distanceX > rectangleWidth / 2 + radius) { return false; }
565 if (distanceY > rectangleHeight / 2 + radius) { return false; }
566
567 if (distanceX &lt; rectangleWidth / 2) { return true; }
568 if (distanceY &lt; rectangleHeight / 2) { return true; }
569
570 var dx = distanceX - rectangleWidth / 2;
571 var dy = distanceY - rectangleHeight / 2;
572
573 return (dx * dx + dy * dy &lt; radius * radius);
574 }
575
576
577 /**
578 * Tells whether a circle is touching (maybe over) a given rectangle.
579 * @function
580 * @param {number} rectangleX - The "X" coordinate of the upper left corner of the first rectangle.
581 * @param {number} rectangleY - The "Y" coordinate of the upper left corner of the first rectangle.
582 * @param {number} rectangleWidth - The width of the first rectangle.
583 * @param {number} rectangleHeight - The height of the first rectangle.
584 * @param {number} centreX - The "X" coordinate of the center of the first circle.
585 * @param {number} centreY - The "Y" coordinate of the center of the first circle.
586 * @param {number} radius - The radius of the first circle.
587 * @returns {boolean} Returns whether the circle is touching (maybe over) the rectangle. This will also return true if they are adjacent (next to each other).
588 * @todo Think about using a "rotation" parameter to accept rotated rectangles.
589 //* Source (modified): markE at https://stackoverflow.com/questions/21089959/detecting-collision-of-rectangle-with-circle
590 */
591 CB_Collisions.isRectangleTouchingCircle = function(rectangleX, rectangleY, rectangleWidth, rectangleHeight, centreX, centreY, radius)
592 {
593 var distanceX = Math.abs(centreX - rectangleX - rectangleWidth / 2);
594 var distanceY = Math.abs(centreY - rectangleY - rectangleHeight / 2);
595
596 if (distanceX > rectangleWidth / 2 + radius) { return false; }
597 if (distanceY > rectangleHeight / 2 + radius) { return false; }
598
599 if (distanceX &lt;= rectangleWidth / 2) { return true; }
600 if (distanceY &lt;= rectangleHeight / 2) { return true; }
601
602 var dx = distanceX - rectangleWidth / 2;
603 var dy = distanceY - rectangleHeight / 2;
604
605 return (dx * dx + dy * dy &lt;= radius * radius);
606 }
607
608
609 /**
610 * Tells whether a line (infinite) is over a given circle.
611 * @function
612 * @param {number} lineX1 - The "X" coordinate of a first point of the line.
613 * @param {number} lineY1 - The "Y" coordinate of a first point of the line.
614 * @param {number} lineX2 - The "X" coordinate of a second point of the line.
615 * @param {number} lineY2 - The "Y" coordinate of a second point of the line.
616 * @param {number} centreX - The "X" coordinate of the center of the first circle.
617 * @param {number} centreY - The "Y" coordinate of the center of the first circle.
618 * @param {number} radius - The radius of the first circle.
619 * @returns {boolean} Returns whether the line (infinite) is over the circle.
620 */
621 //* Source (modified): https://github.com/mattdesl/line-circle-collision
622 CB_Collisions.isLineOverCircle = function(lineX1, lineY1, lineX2, lineY2, centreX, centreY, radius)
623 {
624 if (CB_Collisions.isPointOverCircle(lineX1, lineY1, centreX, centreY, radius)) { return true; }
625 else if (CB_Collisions.isPointOverCircle(lineX2, lineY2, centreX, centreY, radius)) { return true; }
626
627 var dx = lineX2 - lineX1;
628 var dy = lineY2 - lineY1;
629
630 var lcx = centreX - lineX1;
631 var lcy = centreY - lineY1;
632
633 var dLen2 = dx * dx + dy * dy;
634 var px = dx;
635 var py = dy;
636
637 if (dLen2 > 0)
638 {
639 var dp = (lcx * dx + lcy * dy) / dLen2;
640 px *= dp;
641 py *= dp;
642 }
643
644 var pLen2 = px * px + py * py;
645
646 return CB_Collisions.isPointOverCircle(lineX1 + px, lineY1 + py, centreX, centreY, radius) &amp;&amp; pLen2 &lt; dLen2 &amp;&amp; (px * dx + py * dy) > 0; //TODO: test it well (some equal signs removed).
647 }
648
649
650 /**
651 * Tells whether a line (infinite) is touching (maybe over) a given circle.
652 * @function
653 * @param {number} lineX1 - The "X" coordinate of a first point of the line.
654 * @param {number} lineY1 - The "Y" coordinate of a first point of the line.
655 * @param {number} lineX2 - The "X" coordinate of a second point of the line.
656 * @param {number} lineY2 - The "Y" coordinate of a second point of the line.
657 * @param {number} centreX - The "X" coordinate of the center of the first circle.
658 * @param {number} centreY - The "Y" coordinate of the center of the first circle.
659 * @param {number} radius - The radius of the first circle.
660 * @returns {boolean} Returns whether the line (infinite) is touching (maybe over) the circle.
661 */
662 //* Source (modified): https://github.com/mattdesl/line-circle-collision
663 CB_Collisions.isLineTouchingCircle = function(lineX1, lineY1, lineX2, lineY2, centreX, centreY, radius)
664 {
665 if (CB_Collisions.isPointTouchingCircle(lineX1, lineY1, centreX, centreY, radius)) { return true; }
666 else if (CB_Collisions.isPointTouchingCircle(lineX2, lineY2, centreX, centreY, radius)) { return true; }
667
668 var dx = lineX2 - lineX1;
669 var dy = lineY2 - lineY1;
670
671 var lcx = centreX - lineX1;
672 var lcy = centreY - lineY1;
673
674 var dLen2 = dx * dx + dy * dy;
675 var px = dx;
676 var py = dy;
677
678 if (dLen2 > 0)
679 {
680 var dp = (lcx * dx + lcy * dy) / dLen2;
681 px *= dp;
682 py *= dp;
683 }
684
685 var pLen2 = px * px + py * py;
686
687 return CB_Collisions.isPointTouchingCircle(lineX1 + px, lineY1 + py, centreX, centreY, radius) &amp;&amp; pLen2 &lt;= dLen2 &amp;&amp; (px * dx + py * dy) >= 0;
688 }
689
690
691 //Function that returns whether a line is over another line:
692 CB_Collisions.isLineOverLine = function()
693 {
694
695 }
696
697 //Function that returns whether a line segment is over another line segment:
698 CB_Collisions.isSegmentOverSegment = function()
699 {
700
701 }
702
703
704 //Function that returns whether a line is over a segment:
705 CB_Collisions.isLineOverSegment = function()
706 {
707
708 }
709
710
711 //Function that returns whether a line is over a rectangle:
712 CB_Collisions.isLineOverRectangle = function()
713 {
714
715 }
716
717 //Function that returns whether a line is over a circle:
718 CB_Collisions.isLineOverCircle = function()
719 {
720
721 }
722
723
724 //Function that returns whether a line segment is over a rectangle:
725 CB_Collisions.isSegmentOverRectangle = function()
726 {
727
728 }
729
730 //Function that returns whether a line segment is over a circle:
731 CB_Collisions.isSegmentOverCircle = function()
732 {
733
734 }
735
736
737 //Function that returns whether a line is touching (maybe over) another line:
738 CB_Collisions.isLineTouchingLine = function()
739 {
740
741 }
742
743
744 //Function that returns whether a line is touching (maybe over) a line segment:
745 CB_Collisions.isLineTouchingSegment = function()
746 {
747
748 }
749
750
751 //Function that returns whether a line is touching (maybe over) a rectangle:
752 CB_Collisions.isLineTouchingRectangle = function()
753 {
754
755 }
756
757
758 //Function that returns whether a line segment is touching (maybe over) a rectangle:
759 CB_Collisions.isSegmentTouchingRectangle = function()
760 {
761
762 }
763
764
765 //Function that returns whether a line segment is touching (maybe over) a circle:
766 CB_Collisions.isSegmentTouchingCircle = function()
767 {
768
769 }
770
771}</pre>
772 </article>
773</section>
774
775
776
777
778
779 </div>
780 </div>
781
782 <div class="clearfix"></div>
783
784
785
786</div>
787</div>
788
789
790 <div class="modal fade" id="searchResults">
791 <div class="modal-dialog">
792 <div class="modal-content">
793 <div class="modal-header">
794 <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
795 <h4 class="modal-title">Search results</h4>
796 </div>
797 <div class="modal-body"></div>
798 <div class="modal-footer">
799 <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
800 </div>
801 </div><!-- /.modal-content -->
802 </div><!-- /.modal-dialog -->
803 </div>
804
805
806<footer>
807
808
809 <span class="copyright">
810 <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>
811 </span>
812
813<span class="jsdoc-message">
814 Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.5.5</a>
815
816 on Mon Feb 3rd 2020
817
818 using the <a href="https://github.com/docstrap/docstrap">DocStrap template</a>.
819</span>
820</footer>
821
822<script src="scripts/docstrap.lib.js"></script>
823<script src="scripts/toc.js"></script>
824
825 <script type="text/javascript" src="scripts/fulltext-search-ui.js"></script>
826
827
828<script>
829$( function () {
830 $( "[id*='$']" ).each( function () {
831 var $this = $( this );
832
833 $this.attr( "id", $this.attr( "id" ).replace( "$", "__" ) );
834 } );
835
836 $( ".tutorial-section pre, .readme-section pre, pre.prettyprint.source" ).each( function () {
837 var $this = $( this );
838
839 var example = $this.find( "code" );
840 exampleText = example.html();
841 var lang = /{@lang (.*?)}/.exec( exampleText );
842 if ( lang && lang[1] ) {
843 exampleText = exampleText.replace( lang[0], "" );
844 example.html( exampleText );
845 lang = lang[1];
846 } else {
847 var langClassMatch = example.parent()[0].className.match(/lang\-(\S+)/);
848 lang = langClassMatch ? langClassMatch[1] : "javascript";
849 }
850
851 if ( lang ) {
852
853 $this
854 .addClass( "sunlight-highlight-" + lang )
855 .addClass( "linenums" )
856 .html( example.html() );
857
858 }
859 } );
860
861 Sunlight.highlightAll( {
862 lineNumbers : true,
863 showMenu : true,
864 enableDoclinks : true
865 } );
866
867 $.catchAnchorLinks( {
868 navbarOffset: 10
869 } );
870 $( "#toc" ).toc( {
871 anchorName : function ( i, heading, prefix ) {
872 return $( heading ).attr( "id" ) || ( prefix + i );
873 },
874 selectors : "#toc-content h1,#toc-content h2,#toc-content h3,#toc-content h4",
875 showAndHide : false,
876 smoothScrolling: true
877 } );
878
879 $( "#main span[id^='toc']" ).addClass( "toc-shim" );
880 $( '.dropdown-toggle' ).dropdown();
881
882 $( "table" ).each( function () {
883 var $this = $( this );
884 $this.addClass('table');
885 } );
886
887} );
888</script>
889
890
891
892<!--Navigation and Symbol Display-->
893
894<script>
895 $( function () {
896 $( '#main' ).localScroll( {
897 offset : { top : 60 } //offset by the height of your header (give or take a few px, see what works for you)
898 } );
899 $( "dt.name" ).each( function () {
900 var $this = $( this ).find("h4");
901 var icon = $( "<i/>" ).addClass( "icon-plus-sign" ).addClass( "pull-right" ).addClass( "icon-white" );
902 var dt = $(this);
903 var children = dt.next( "dd" );
904
905 dt.prepend( icon ).css( {cursor : "pointer"} );
906 dt.addClass( "member-collapsed" ).addClass( "member" );
907
908
909 children.hide();
910
911 dt.children().on( "click", function () {
912 children = dt.next( "dd" );
913 children.slideToggle( "fast", function () {
914
915 if ( children.is( ":visible" ) ) {
916 icon.addClass( "icon-minus-sign" ).removeClass( "icon-plus-sign" ).removeClass( "icon-white" );
917 dt.addClass( "member-open" ).animate( "member-collapsed" );
918 } else {
919 icon.addClass( "icon-plus-sign" ).removeClass( "icon-minus-sign" ).addClass( "icon-white" );
920 dt.addClass( "member-collapsed" ).removeClass( "member-open" );
921 }
922 } );
923 } );
924
925 } );
926 } );
927</script>
928
929
930<!--Google Analytics-->
931
932
933
934 <script type="text/javascript">
935 $(document).ready(function() {
936 SearcherDisplay.init();
937 });
938 </script>
939
940
941</body>
942</html>