UNPKG

56.3 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_Client.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_Client.js</h1>
83
84<section>
85 <article>
86 <pre
87 class="sunlight-highlight-javascript linenums">/**
88 * @file Web client (browser or engine) management. Contains the {@link CB_Client} 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 current client. It will return itself if it is tried to be instantiated. It can use [BrowserDetect]{@link https://quirksmode.org/js/detect.html} ([source code rescued]{@link https://gist.github.com/mitchellhislop/2018348}).
96 * @namespace
97 * @todo Think about implementing a getDocumentParents function (similar to {@link CB_Client.getWindowParents}).
98 * @todo Think about implementing "onClose" event (to fire when app/web is going to be closed).
99 */
100var CB_Client = function() { return CB_Client; };
101{
102 CB_Client.initialized = false; //It will tells whether the object has been initialized or not.
103
104
105 //Initializes all values:
106 CB_Client.init = function()
107 {
108 //If this is the fist time:
109 if (CB_Client.initialized) { return CB_Client; }
110
111 //The object has been initialized:
112 CB_Client.initialized = true;
113
114 return CB_Client;
115 }
116
117
118 //Returns the most preferred language:
119 CB_Client._getLanguagePreferred =
120 function(allowNavigatorLanguages, PHPAcceptedLanguagesFirst)
121 {
122 return CB_Client._getLanguagesPreferred(allowNavigatorLanguages, PHPAcceptedLanguagesFirst)[0];
123 };
124
125 /**
126 * Returns the most preferred language as a string.
127 * @function
128 * @param {boolean} [allowNavigatorLanguages={@link CB_Configuration.CrossBase.CB_Client_allowNavigatorLanguages_DEFAULT}] - Defines whether to allow using the [window.navigator.languages]{@link https://developer.mozilla.org/en-US/docs/Web/API/NavigatorLanguage/languages} property (if not available, it will proceed normally).
129 * @param {boolean} [PHPAcceptedLanguagesFirst={@link CB_Configuration.CrossBase.CB_Client_PHPAcceptedLanguagesFirst_DEFAULT}] - If it is set to true, it will try to return the accepted languages found out by [PHP]{@link https://en.wikipedia.org/wiki/PHP} (if [PHP]{@link https://en.wikipedia.org/wiki/PHP} is available) in [$_SERVER]{@link http://php.net/manual/en/reserved.variables.server.php}['HTTP_ACCEPT_LANGUAGE'] or it will proceed normally otherwise.
130 * @returns {string}
131 * @todo Use other back-end ways to calculate the language (using Node.js, for example).
132 */
133 CB_Client.getLanguage = function(allowNavigatorLanguages, PHPAcceptedLanguagesFirst)
134 {
135 return CB_Client._getLanguagePreferred(allowNavigatorLanguages, PHPAcceptedLanguagesFirst);
136 }
137
138
139 //Returns the most preferred languages (an array):
140 CB_Client._getLanguagesPreferred =
141 function(allowNavigatorLanguages, PHPAcceptedLanguagesFirst)
142 {
143 if (typeof(PHPAcceptedLanguagesFirst) !== true &amp;&amp; PHPAcceptedLanguagesFirst !== false) { PHPAcceptedLanguagesFirst = CB_Configuration[CB_BASE_NAME].CB_Client_PHPAcceptedLanguagesFirst_DEFAULT; }
144 if (PHPAcceptedLanguagesFirst &amp;&amp; typeof(CB_PHPAcceptedLanguages) !== "undefined" &amp;&amp; CB_isArray(CB_PHPAcceptedLanguages) &amp;&amp; CB_PHPAcceptedLanguages.length > 0) { return CB_PHPAcceptedLanguages; }
145 if (allowNavigatorLanguages !== true &amp;&amp; allowNavigatorLanguages !== false) { allowNavigatorLanguages = CB_Configuration[CB_BASE_NAME].CB_Client_allowNavigatorLanguages_DEFAULT; }
146 if (allowNavigatorLanguages &amp;&amp; window.navigator.languages) { return window.navigator.languages; }
147 var languages = [];
148 if (window.navigator.language &amp;&amp; CB_indexOf(languages, window.navigator.language) === -1) { languages[languages.length] = window.navigator.language; }
149 if (window.navigator.userLanguage &amp;&amp; CB_indexOf(languages, window.navigator.userLanguage) === -1) { languages[languages.length] = window.navigator.userLanguage; }
150 if (window.navigator.browserLanguage &amp;&amp; CB_indexOf(languages, window.navigator.browserLanguage) === -1) { languages[languages.length] = window.navigator.browserLanguage; }
151 if (window.navigator.systemLanguage &amp;&amp; CB_indexOf(languages, window.navigator.systemLanguage) === -1) { languages[languages.length] = window.navigator.systemLanguage; }
152 if (languages.length > 0) { return languages; }
153 else { return [CB_Configuration[CB_BASE_NAME].CB_Client_language_DEFAULT]; }
154 };
155
156 /**
157 * Returns the most preferred languages as an array of strings.
158 * @function
159 * @param {boolean} [allowNavigatorLanguages={@link CB_Configuration.CrossBase.CB_Client_allowNavigatorLanguages_DEFAULT}] - Defines whether to allow using the [window.navigator.languages]{@link https://developer.mozilla.org/en-US/docs/Web/API/NavigatorLanguage/languages} property (if not available, it will proceed normally).
160 * @param {boolean} [PHPAcceptedLanguagesFirst={@link CB_Configuration.CrossBase.CB_Client_PHPAcceptedLanguagesFirst_DEFAULT}] - If it is set to true, it will try to return the accepted languages found out by [PHP]{@link https://en.wikipedia.org/wiki/PHP} (if [PHP]{@link https://en.wikipedia.org/wiki/PHP} is available) in [$_SERVER]{@link http://php.net/manual/en/reserved.variables.server.php}['HTTP_ACCEPT_LANGUAGE'] or it will proceed normally otherwise.
161 * @returns {array}
162 * @todo Use other back-end ways to calculate languages (using Node.js, for example).
163 */
164 CB_Client.getLanguages = function(allowNavigatorLanguages, PHPAcceptedLanguagesFirst)
165 {
166 return CB_Client._getLanguagesPreferred(allowNavigatorLanguages, PHPAcceptedLanguagesFirst);
167 }
168
169
170 /**
171 * Sets a function to execute when the [languagechange]{@link https://developer.mozilla.org/en-US/docs/Web/Events/languagechange} event is fired (only for some web clients) or removes it.
172 * @function
173 * @param {function|null} eventFunction - Function that represents the event listener that will be called when the event is fired. If a null value is used, the event will be removed.
174 * @param {boolean} [keepOldFunction=true] - Defines whether to also keep the previous listeners or remove them otherwise.
175 * @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.
176 */
177 CB_Client.onLanguageChanges = function(eventFunction, keepOldFunction, useCapture)
178 {
179 CB_Client._setEvent("languagechange", eventFunction, keepOldFunction, useCapture, window);
180 }
181
182
183 /**
184 * Alias for {@link CB_Client.get}.
185 * @function CB_Client.getBrowser
186 * @see {@link CB_Client.get}
187 */
188 /**
189 * Returns the current web client (if possible) as a string. It uses [BrowserDetect]{@link https://quirksmode.org/js/detect.html} ([source code rescued]{@link https://gist.github.com/mitchellhislop/2018348}) internally.
190 * @function
191 * @returns {string}
192 */
193 CB_Client.get = CB_Client.getBrowser = function()
194 {
195 return BrowserDetect.browser;
196 }
197
198
199 /**
200 * Alias for {@link CB_Client.getVersion}.
201 * @function CB_Client.getBrowserVersion
202 * @see {@link CB_Client.getVersion}
203 */
204 /**
205 * Returns the current web client version (if possible) as a string. It uses [BrowserDetect]{@link https://quirksmode.org/js/detect.html} ([source code rescued]{@link https://gist.github.com/mitchellhislop/2018348}) internally.
206 * @function
207 * @returns {string}
208 */
209 CB_Client.getVersion = CB_Client.getBrowserVersion = function()
210 {
211 return BrowserDetect.version + "";
212 }
213
214
215 /**
216 * Alias for {@link CB_Client.getVersionMain}.
217 * @function CB_Client.getBrowserVersionMain
218 * @see {@link CB_Client.getVersionMain}
219 */
220 /**
221 * Returns the current web client main version (first number), if possible, as an integer. It uses [BrowserDetect]{@link https://quirksmode.org/js/detect.html} ([source code rescued]{@link https://gist.github.com/mitchellhislop/2018348}) internally.
222 * @function
223 * @returns {integer}
224 */
225 CB_Client.getVersionMain = CB_Client.getBrowserVersionMain = function()
226 {
227 return parseInt(CB_Client.getBrowserVersion().split(".")[0]);
228 }
229
230
231 CB_Client._getWindowParentsReturnCache; //Stores the return result in order to optimize the execution next times.
232 /**
233 * Returns all the [window]{@link https://developer.mozilla.org/en-US/docs/Web/API/Window} objects, parents and last son (main one) in an array (with the topmost parent in the highest index). Useful in case the script is running in an [iframe]{@link https://developer.mozilla.org/en-US/docs/Web/HTML/Element/iframe} or more.
234 * @function
235 * @returns {array}
236 */
237 CB_Client.getWindowParents = function()
238 {
239 //If it is not the first time we execute this function, uses the cache to return always the same:
240 if (typeof(CB_Client._getWindowParentsReturnCache) !== "undefined" &amp;&amp; CB_Client._getWindowParentsReturnCache !== null)
241 {
242 return CB_Client._getWindowParentsReturnCache;
243 }
244
245 var windowParents = [ window.self ];
246 try
247 {
248 if (typeof(window.parent) !== "undefined" &amp;&amp; window.parent !== null)
249 {
250 var currentParent = windowParents[0];//windowParents[windowParents.length - 1];
251 while (typeof(currentParent.parent) !== "undefined" &amp;&amp; currentParent !== currentParent.parent)
252 {
253 currentParent = currentParent.parent;
254 windowParents[windowParents.length] = currentParent;
255 }
256 ///////windowBase = currentParent;
257 }
258 } catch(E) {}
259
260 CB_Client._getWindowParentsReturnCache = windowParents;
261
262 return windowParents;
263 }
264
265
266 CB_Client._getWindowBaseReturnCache; //Stores the return result in order to optimize the execution next times.
267 /**
268 * Returns the [window]{@link https://developer.mozilla.org/en-US/docs/Web/API/Window} object of the first parent (the topmost one). Useful in case the script is running in an [iframe]{@link https://developer.mozilla.org/en-US/docs/Web/HTML/Element/iframe} or more.
269 * @function
270 * @returns {Object}
271 */
272 CB_Client.getWindowBase = function()
273 {
274 //If it is not the first time we execute this function, uses the cache to return always the same:
275 if (typeof(CB_Client._getWindowBaseReturnCache) !== "undefined" &amp;&amp; CB_Client._getWindowBaseReturnCache !== null)
276 {
277 return CB_Client._getWindowBaseReturnCache;
278 }
279
280 //By default, uses the current window object:
281 var windowBase = window.self; //window;
282
283 //Tries to get the topmost window (it can fail if it is not in the same domain or it is running locally):
284 try
285 {
286 //If defined, we use window.top to get the topmost window:
287 if (typeof(window.top) !== "undefined" &amp;&amp; window.top !== null) { windowBase = window.top; }
288 //...otherwise, we get all the parents and chose the last one (which will be the topmost):
289 else
290 {
291 var windowParents = CB_Client.getWindowParents();
292 windowBase = windowParents[windowParents.length - 1];
293 }
294 } catch(E) {}
295
296 CB_Client._getWindowBaseReturnCache = windowBase;
297
298 return windowBase;
299 }
300
301
302 CB_Client._getWindowReturnCache; //Stores the return result in order to optimize the execution next times.
303 /**
304 * Returns the [window]{@link https://developer.mozilla.org/en-US/docs/Web/API/Window} object (having in mind whether the script is running in one [iframe]{@link https://developer.mozilla.org/en-US/docs/Web/HTML/Element/iframe} or more, if we want).
305 * @function
306 * @param {boolean} [mindIframes={@link CB_Configuration.CrossBase.MIND_IFRAMES}] - If set to true, it will try to get and return the topmost [window]{@link https://developer.mozilla.org/en-US/docs/Web/API/Window} object. Useful in case the script is running in an [iframe]{@link https://developer.mozilla.org/en-US/docs/Web/HTML/Element/iframe} or more.
307 * @returns {Object}
308 */
309 CB_Client.getWindow = function(mindIframes)
310 {
311 if (typeof(mindIframes) === "undefined" || mindIframes === null) { mindIframes = CB_Configuration[CB_BASE_NAME].MIND_IFRAMES; }
312
313 //If it is not the first time we execute this function, uses the cache to return always the same:
314 if (!mindIframes) { return window.self; }
315 else if (typeof(CB_Client._getWindowReturnCache) !== "undefined" &amp;&amp; CB_Client._getWindowReturnCache !== null)
316 {
317 return CB_Client._getWindowReturnCache;
318 }
319
320 //Gets the window chosen (if we arrived here, it means we mind iframes):
321 CB_Client._getWindowReturnCache = CB_Client.getWindowBase(); //Stores the window chosen in the cache:
322
323 return CB_Client._getWindowReturnCache;
324 }
325
326
327 /**
328 * Returns the [document]{@link https://developer.mozilla.org/en-US/docs/Web/API/Window/document} object of the first parent (the topmost one). Useful in case the script is running in an [iframe]{@link https://developer.mozilla.org/en-US/docs/Web/HTML/Element/iframe} or more.
329 * @function
330 * @returns {Object}
331 */
332 CB_Client.getDocumentBase = function()
333 {
334 //By default, uses the current document object:
335 var documentBase = document;
336
337 //Tries to get the document object of the topmost window (it can fail if it is not in the same domain or it is running locally):
338 try { documentBase = CB_Client.getWindowBase().document; } catch(E) {}
339
340 return documentBase;
341 }
342
343
344 /**
345 * Returns the [document]{@link https://developer.mozilla.org/en-US/docs/Web/API/Window/document} object (having in mind whether the script is running in one [iframe]{@link https://developer.mozilla.org/en-US/docs/Web/HTML/Element/iframe} or more, if we want).
346 * @function
347 * @param {boolean} [mindIframes={@link CB_Configuration.CrossBase.MIND_IFRAMES}] - If set to true, it will try to get and return the topmost [document]{@link https://developer.mozilla.org/en-US/docs/Web/API/Window/document} object. Useful in case the script is running in an [iframe]{@link https://developer.mozilla.org/en-US/docs/Web/HTML/Element/iframe} or more.
348 * @returns {Object}
349 */
350 CB_Client.getDocument = function(mindIframes)
351 {
352 if (typeof(mindIframes) === "undefined" || mindIframes === null) { mindIframes = CB_Configuration[CB_BASE_NAME].MIND_IFRAMES; }
353
354 var documentChosen = document;
355 if (mindIframes) { documentChosen = CB_Client.getDocumentBase(); }
356
357 return documentChosen;
358 }
359
360
361 /**
362 * Tells whether the [canvas]{@link https://developer.mozilla.org/en-US/docs/Web/HTML/Element/canvas} element is supported natively or not.
363 * @function
364 * @returns {boolean}
365 */
366 CB_Client.supportsCanvas = function()
367 {
368 return CB_Configuration[CB_BASE_NAME]._supportsCanvas();
369 }
370
371
372 CB_Client._supportsCSS3TransformReturnCache;
373 /**
374 * Tells whether [CSS3]{@link https://developer.mozilla.org/en-US/docs/Web/CSS/CSS3} [transform]{@link https://developer.mozilla.org/en-US/docs/Web/CSS/transform} is supported natively or not.
375 * @function
376 * @returns {boolean}
377 */
378 CB_Client.supportsCSS3Transform = function()
379 {
380 if (typeof(CB_Client._supportsCSS3TransformReturnCache) === "undefined" || CB_Client._supportsCSS3TransformReturnCache === null)
381 {
382 var documentBodyStyle = document.body.style;
383 CB_Client._supportsCSS3TransformReturnCache = (typeof(documentBodyStyle.transform) !== "undefined" || typeof(documentBodyStyle.WebkitTransform) !== "undefined" || typeof(documentBodyStyle.MozTransform) !== "undefined" || typeof(documentBodyStyle.OTransform) !== "undefined" || typeof(documentBodyStyle.MsTransform) !== "undefined" || typeof(documentBodyStyle.KhtmlTransform) !== "undefined");
384 }
385
386 return CB_Client._supportsCSS3TransformReturnCache;
387 }
388
389
390 /**
391 * Function that tells whether [PHP]{@link https://en.wikipedia.org/wiki/PHP} is available or not.
392 * @function
393 * @returns {boolean}
394 */
395 CB_Client.supportsPHP = function()
396 {
397 return (typeof(CB_supportedPHP) !== "undefined" &amp;&amp; CB_supportedPHP === "YES");
398 }
399
400
401 /**
402 * Returns the available version of [PHP]{@link https://en.wikipedia.org/wiki/PHP} (if any), as either an array of strings or as a string.
403 * @function
404 * @param {boolean} [asString=false] - If set to true, returns the version as a string.
405 * @returns {array|string}
406 */
407 CB_Client.getPHPVersion = function(asString)
408 {
409 if (typeof(CB_PHPVersion) === "undefined") { CB_PHPVersion = 0; }
410 return asString ? (CB_PHPVersion + "") : (CB_PHPVersion + "").split(".");
411 }
412
413
414 /**
415 * Function that tells whether [Node.js]{@link https://en.wikipedia.org/wiki/Node.js} is available (checks the availability of [process.versions.node]{@link https://nodejs.org/api/process.html#process_process_versions}) or not.
416 * @function
417 * @returns {boolean}
418 */
419 //* Source: Dan. B. @ http://stackoverflow.com/questions/17575790/environment-detection-node-js-or-browser
420 CB_Client.supportsNodeJS = function()
421 {
422 return (typeof(process) === "object" &amp;&amp; process !== null &amp;&amp; typeof(process.versions) === "object" &amp;&amp; typeof(process.versions.node) !== "undefined");
423 }
424
425
426 /**
427 * Returns the available version of [Node.js]{@link https://en.wikipedia.org/wiki/Node.js} (if any), as either an array of strings or as a string.
428 * @function
429 * @param {boolean} [asString=false] - If set to true, returns the version as a string.
430 * @returns {array|string}
431 */
432 CB_Client.getNodeJSVersion = function(asString)
433 {
434 if (typeof(process) === "object" &amp;&amp; process !== null &amp;&amp; CB_isString(process.version))
435 {
436 return asString ? process.version : process.version.replace(CB_regularExpressionString("-", true, true), ".").split(".");
437 }
438 else { return asString ? "0.0.0" : [0, 0, 0]; }
439 }
440
441
442 /**
443 * Function that tells whether [Microsoft Silverlight]{@link https://en.wikipedia.org/wiki/Microsoft_Silverlight} plugin is available or not.
444 * @function
445 * @returns {boolean}
446 */
447 CB_Client.supportsSilverlight = function()
448 {
449 var isSilverlightInstalled = false;
450 try
451 {
452 isSilverlightInstalled = !!(new ActiveXObject("AgControl.AgControl"));
453 }
454 catch(E)
455 {
456 if (navigator.plugins["Silverlight Plug-In"])
457 {
458 isSilverlightInstalled = true;
459 }
460 else { isSilverlightInstalled = false; }
461 }
462
463 return isSilverlightInstalled;
464 }
465
466
467 /**
468 * Returns the available version of [Microsoft Silverlight]{@link https://en.wikipedia.org/wiki/Microsoft_Silverlight} plugin (if any), as either an array of strings or as a string.
469 * @function
470 * @param {boolean} [asString=false] - If set to true, returns the version as a string.
471 * @returns {array|string}
472 */
473 CB_Client.getSilverlightVersion = function(asString)
474 {
475 if (navigator.plugins["Silverlight Plug-In"] &amp;&amp; navigator.plugins["Silverlight Plug-In"].description &amp;&amp; CB_isString(navigator.plugins["Silverlight Plug-In"].description) &amp;&amp; CB_trim(navigator.plugins["Silverlight Plug-In"].description) !== "")
476 {
477 return asString ? navigator.plugins["Silverlight Plug-In"].description : navigator.plugins["Silverlight Plug-In"].description.replace(CB_regularExpressionString("-", true, true), ".").split(".");
478 }
479 else { return asString ? "0.0.0" : [0, 0, 0]; }
480 }
481
482
483
484 /**
485 * Function that tells whether [Adobe Flash (formerly Macromedia Flash)]{@link https://en.wikipedia.org/wiki/Adobe_Flash_Player} plugin is available or not.
486 * @function
487 * @returns {boolean}
488 */
489 CB_Client.supportsFlash = function()
490 {
491 var isFlashInstalled = false;
492
493 if ("ActiveXObject" in window)
494 {
495 try
496 {
497 isFlashInstalled = !!(new ActiveXObject("ShockwaveFlash.ShockwaveFlash"));
498 }
499 catch(E) { isFlashInstalled = false; }
500 }
501
502 if (!isFlashInstalled &amp;&amp; typeof(navigator.mimeTypes) !== "undefined")
503 {
504 var mime = navigator.mimeTypes['application/x-shockwave-flash']
505 if (typeof(mime) !== "undefined" &amp;&amp; mime !== null &amp;&amp; mime.enabledPlugin)
506 {
507 isFlashInstalled = true;//!!mime;
508 }
509 }
510
511 if (!isFlashInstalled &amp;&amp; typeof(navigator.plugins) !== "undefined")
512 {
513 var plugin = navigator.plugins["Shockwave Flash"];
514 isFlashInstalled = !!plugin;
515 }
516
517 return isFlashInstalled;
518 }
519
520
521 /**
522 * Returns the available version of [Adobe Flash (formerly Macromedia Flash)]{@link https://en.wikipedia.org/wiki/Adobe_Flash_Player} plugin, if any, as either an array of strings or as a string.
523 * @function
524 * @param {boolean} [asString=false] - If set to true, returns the version as a string.
525 * @returns {array|string}
526 */
527 CB_Client.getFlashVersion = function(asString)
528 {
529 var version = "0.0.0";
530
531 try
532 {
533 try
534 {
535 var axo = new ActiveXObject('ShockwaveFlash.ShockwaveFlash.6');
536 try { axo.AllowScriptAccess = 'always'; }
537 catch(E) { return asString ? '6.0.0' : '6.0.0'.split('.'); }
538 }
539 catch(E) {}
540 version = new ActiveXObject('ShockwaveFlash.ShockwaveFlash').GetVariable('$version').replace(/\D+/g, ',').match(/^,?(.+),?$/)[1];
541 version = version.replace(CB_regularExpressionString(",", true, true), ".");
542 return asString ? version : version.split('.');
543 }
544 catch(E)
545 {
546 try
547 {
548 if (navigator.mimeTypes["application/x-shockwave-flash"].enabledPlugin)
549 {
550 version = (navigator.plugins["Shockwave Flash 2.0"] || navigator.plugins["Shockwave Flash"]).description.replace(/\D+/g, ",").match(/^,?(.+),?$/)[1];
551 version = version.replace(CB_regularExpressionString(",", true, true), ".");
552 return asString ? version : version.split('.');
553 }
554 } catch(E) {}
555 }
556
557 return asString ? version : version.split('.');
558 }
559
560
561 /**
562 * Tells whether the script is running locally (using "file:" protocol) or not.
563 * @function
564 * @param {boolean} [mindIframes={@link CB_Configuration.CrossBase.MIND_IFRAMES}] - If set to true, it will try to check the protocol of the topmost [window]{@link https://developer.mozilla.org/en-US/docs/Web/API/Window} object. Useful in case the script is running in an [iframe]{@link https://developer.mozilla.org/en-US/docs/Web/HTML/Element/iframe} or more.
565 * @returns {boolean}
566 */
567 CB_Client.isRunningLocally = function(mindIframes)
568 {
569 if (typeof(mindIframes) === "undefined" || mindIframes === null) { mindIframes = CB_Configuration[CB_BASE_NAME].MIND_IFRAMES; }
570
571 var isRunningLocally = false; //We assume that the script is not running locally by default.
572 var protocolUsed = "";
573
574 try
575 {
576 var windowObject = CB_Client.getWindow(mindIframes);
577 if (typeof(windowObject.location) !== "undefined" &amp;&amp; typeof(windowObject.location.protocol) !== "undefined")
578 {
579 protocolUsed = windowObject.location.protocol;
580 }
581 }
582 catch(E)
583 {
584 if (typeof(window.location) !== "undefined" &amp;&amp; typeof(window.location.protocol) !== "undefined")
585 {
586 protocolUsed = window.location.protocol;
587 }
588 }
589
590 if (protocolUsed === "file:") { isRunningLocally = true; }
591 //else if (protocolUsed === "http:" || protocolUsed === "https:") { isRunningLocally = false; }
592
593 return isRunningLocally;
594 }
595
596
597 CB_Client._isRunningOnNWjsReturnCache = null;
598 /**
599 * Tells whether the script is running on [NW.js (formerly node-webkit)]{@link https://nwjs.io/} or not.
600 * @function
601 * @returns {boolean}
602 */
603 //* Source: Kuf @ http://stackoverflow.com/questions/31968355/detect-if-web-app-is-running-in-nwjs
604 CB_Client.isRunningOnNWjs = function()
605 {
606 if (typeof(CB_Client._isRunningOnNWjsReturnCache) !== "undefined" &amp;&amp; CB_Client._isRunningOnNWjsReturnCache !== null) { return CB_Client._isRunningOnNWjsReturnCache; }
607 if (typeof(nw) !== "undefined" &amp;&amp; nw !== null) { return CB_Client._isRunningOnNWjsReturnCache = true; }
608 try
609 {
610 return CB_Client._isRunningOnNWjsReturnCache = (typeof(require) === "function" &amp;&amp; (typeof(nw) !== "undefined" &amp;&amp; nw !== null &amp;&amp; nw.App || typeof(require("nw.gui")) !== "undefined"));
611 }
612 catch(E) { return CB_Client._isRunningOnNWjsReturnCache = false; }
613 }
614
615
616 CB_Client._isRunningOnElctronReturnCache = null;
617 /**
618 * Tells whether the script is running on [Electron (Electron.js)]{@link https://electronjs.org/} or not.
619 * @function
620 * @returns {boolean}
621 */
622 //* Source: cheton @ https://github.com/cheton/is-electron/blob/master/index.js
623 CB_Client.isRunningOnElectron = function()
624 {
625 if (typeof(CB_Client._isRunningOnElectronReturnCache) !== "undefined" &amp;&amp; CB_Client._isRunningOnElectronReturnCache !== null) { return CB_Client._isRunningOnElectronReturnCache; }
626 //if (typeof(nw) !== "undefined" &amp;&amp; nw !== null) { return CB_Client._isRunningOnElectronReturnCache = true; }
627 try
628 {
629 return CB_Client._isRunningOnElectronReturnCache = (typeof(navigator) === "object" &amp;&amp; navigator !== null &amp;&amp; typeof(navigator.userAgent) === "string" &amp;&amp; navigator.userAgent.indexOf("Electron") !== -1);
630 }
631 catch(E) { return CB_Client._isRunningOnElectronReturnCache = false; }
632 }
633
634
635 /**
636 * Exits and finishes the script. In a browser, it will try to close the window or at least abandon it redirecting to an empty one (or to a desired URL). In an app ([NW.js (formerly node-webkit)]{@link https://nwjs.io/}/[Electron (Electron.js)]{@link https://electronjs.org/}/[Apache Cordova]{@link https://cordova.apache.org/}/[Adobe PhoneGap]{@link https://phonegap.com/}/[Appcelerator Titanium SDK]{@link https://en.wikipedia.org/wiki/Appcelerator_Titanium}/[Appcelerator TideSDK (Titanium Desktop)]{@link https://github.com/appcelerator-archive/titanium_desktop}/[Weixin (WeChat)]{@link https://en.wikipedia.org/wiki/WeChat}/etc.), it will try to close the app.
637 * @function
638 * @param {boolean} [allowWindowCloseFallback=true] - Defines whether to allow using the [window.close]{@link https://developer.mozilla.org/en-US/docs/Web/API/Window/close} method as a fallback.
639 * @param {boolean} [allowRedirectionFallback=true] - Defines whether to redirect the current client as a fallback (to the URL defined in the "redirectionAddress" parameter).
640 * @param {boolean} [redirectionAddress='about:blank'] - Defines the URL where the current client will be redirected to in the case that the window cannot be closed. Only used if the "allowRedirectionFallback" parameter is set to true.
641 * @todo Have in mind iframes (think about it).
642 */
643 CB_Client.exit = function(allowWindowCloseFallback, allowRedirectionFallback, redirectionAddress)
644 {
645 if (typeof(allowRedirectionFallback) === "undefined" || allowRedirectionFallback === null) { allowRedirectionFallback = true; }
646 if (typeof(allowWindowCloseFallback) === "undefined" || allowWindowCloseFallback === null) { allowWindowCloseFallback = true; }
647 if (typeof(redirectionAddress) === "undefined" || redirectionAddress === null) { redirectionAddress = "about:blank"; }
648
649 var useFallback = true;
650
651 //Tries to use NW.js (node-webkit) if available to quit the app:
652 if (CB_Client.isRunningOnNWjs())
653 {
654 if (typeof(nw) !== "undefined" &amp;&amp; nw !== null &amp;&amp; nw.App &amp;&amp; typeof(nw.App.closeAllWindows) === "function") { try { nw.App.closeAllWindows(); useFallback = false; } catch(E) { useFallback = true; } }
655 if (useFallback &amp;&amp; typeof(require) === "function")
656 {
657 try
658 {
659 var gui = require("nw.gui");
660 if (typeof(gui) !== "undefined" &amp;&amp; gui !== null &amp;&amp; gui.App)
661 {
662 if (typeof(gui.App.closeAllWindows) === "function") { try { gui.App.closeAllWindows(); useFallback = false; } catch(E) { useFallback = true; } }
663 if (useFallback &amp;&amp; typeof(gui.App.quit) === "function") { try { gui.App.quit(); useFallback = false; } catch(E) { useFallback = true; } }
664 }
665 }
666 catch(E) { useFallback = true; }
667 }
668 if (useFallback &amp;&amp; typeof(nw) !== "undefined" &amp;&amp; nw !== null &amp;&amp; nw.App &amp;&amp; typeof(nw.App.quit) === "function") { try { nw.App.quit(); useFallback = false; } catch(E) { useFallback = true; } }
669 }
670
671 //Tries to use Electron (Electron.js) if available to quit the app:
672 if (CB_Client.isRunningOnElectron() &amp;&amp; typeof(require) === "function")
673 {
674 try
675 {
676 var app = require('app');
677 app.on("window-all-closed", app.quit);
678 app.quit();
679 useFallback = false;
680 }
681 catch(E) { useFallback = true; }
682 }
683
684 //If able, uses PhoneGap with navigator.app:
685 if (typeof(navigator) !== "undefined" &amp;&amp; typeof(navigator.app) !== "undefined" &amp;&amp; typeof(navigator.app.exitApp) !== "undefined")
686 {
687 try { navigator.app.exitApp(); useFallback = false; } catch(E) { useFallback = true; }
688 }
689
690 //If able uses PhoneGap with navigator.device:
691 if (typeof(navigator) !== "undefined" &amp;&amp; typeof(navigator.device) !== "undefined" &amp;&amp; typeof(navigator.device.exitApp) !== "undefined")
692 {
693 try { navigator.device.exitApp(); useFallback = false; } catch(E) { useFallback = true; }
694 }
695
696 //If able uses WeixinJSBridge (Weixin / Wechat JavaScript Bridge):
697 if (typeof(WeixinJSBridge) !== "undefined" &amp;&amp; typeof(WeixinJSBridge.call) !== "undefined")
698 {
699 //WeixinJSBridge.invoke("closeWindow", {}, function(e){});
700 try { WeixinJSBridge.call("closeWindow"); useFallback = false; } catch(E) { useFallback = true; }
701 }
702
703 //If able uses Titanium/TideSDK:
704 if (typeof(Ti) !== "undefined" &amp;&amp; typeof(Ti.App) !== "undefined" &amp;&amp; typeof(Ti.App.exit) !== "undefined")
705 {
706 try { Ti.App.exit(); useFallback = false; } catch(E) { useFallback = true; }
707 }
708
709 //If we want to close using the fallback:
710 if (useFallback)
711 {
712 //Uses redirection if it is allowed:
713 if (allowRedirectionFallback)
714 {
715 setTimeout(function() { location.href = redirectionAddress; }, 200); //Lets a little bit time to process window.close() (if allowed).
716 }
717
718 //Uses window.close() if it is allowed:
719 if (allowWindowCloseFallback)
720 {
721 try
722 {
723
724 //if (navigator.userAgent.indexOf('MSIE') !== -1 &amp;&amp; (navigator.appVersion.indexOf("MSIE 5") !== -1 || navigator.appVersion.indexOf("MSIE 6") !== -1))
725 //{
726 //CB_Client.getWindow().opener = top;
727 //CB_Client.getWindow().close();
728 //}
729 //else
730 //{
731 //var ventana = CB_Client.getWindow().open("", "_self");
732 //ventana.close();
733 //}
734
735
736 var thisWindow = window.open(allowRedirectionFallback ? redirectionAddress : "", "_self", "", "true");
737 thisWindow.opener = top;
738 CB_windowCloseEncapsulated = thisWindow.close;
739 CB_windowCloseEncapsulated();
740
741 //if (navigator.userAgent.indexOf('MSIE') !== -1 &amp;&amp; (navigator.appVersion.indexOf("MSIE 5") !== -1 || navigator.appVersion.indexOf("MSIE 6") !== -1))
742 //{
743 //window.opener = top;
744 //window.close();
745 //}
746
747 //var thisWindow = window.parent.open(allowRedirectionFallback ? redirectionAddress : location.href, "_self");
748 //window.parent.close();
749
750
751 //else
752 //{
753 //var thisWindow = CB_Client.getWindow(true).open(allowRedirectionFallback ? redirectionAddress : "", "_self", "", "true");
754 //thisWindow.opener = CB_Client.getWindow().top;
755 //CB_windowCloseEncapsulated = thisWindow.close;
756 //CB_windowCloseEncapsulated();
757 //}
758 }
759 catch(E)
760 {
761 try
762 {
763 var thisWindow = window.open(allowRedirectionFallback ? redirectionAddress : location.href, "_self");
764 thisWindow.close();
765 }
766 catch(E)
767 {
768 try
769 {
770 window.opener = top;
771 window.close();
772 }
773 catch(E)
774 {
775 try
776 {
777 window.opener = window;
778 window.close();
779 }
780 catch(E)
781 {
782 try
783 {
784 window.opener = "CB_TryingToCloseWindow";
785 window.close();
786 }
787 catch(E)
788 {
789 try { window.close(); } catch(E) { }
790 }
791 }
792 }
793 }
794 }
795 }
796 }
797 }
798
799
800 /**
801 * Redirects the current client to the desired location (having in mind whether the script is running in one [iframe]{@link https://developer.mozilla.org/en-US/docs/Web/HTML/Element/iframe} or more, if we want).
802 * @function
803 * @param {string} address - The address where we want to go.
804 * @param {string} [getData] - Any URL (GET) variables we want to send (as for example "data1=value1&amp;data2=value2").
805 * @param {boolean} [mindIframes={@link CB_Configuration.CrossBase.MIND_IFRAMES}] - If set to true, it will try to redirect the topmost [window]{@link https://developer.mozilla.org/en-US/docs/Web/API/Window} object. Useful in case the script is running in an [iframe]{@link https://developer.mozilla.org/en-US/docs/Web/HTML/Element/iframe} or more.
806 */
807 CB_Client.redirectTo = function(address, getData, mindIframes)
808 {
809 getData = CB_ltrim(CB_trim(getData), ["&amp;", "?"]);
810 if (getData !== "")
811 {
812 if (address.indexOf("?") === -1) { getData = "?" + getData; }
813 else { getData = "&amp;" + getData; }
814 }
815
816 try { CB_Client.getWindow(mindIframes).location = address + getData; }
817 catch(E) { window.location = address + getData; }
818 }
819
820
821
822 /**
823 * Returns the current URL, if possible (having in mind whether the script is running in one [iframe]{@link https://developer.mozilla.org/en-US/docs/Web/HTML/Element/iframe} or more, if we want).
824 * @function
825 * @param {boolean} [mindIframes={@link CB_Configuration.CrossBase.MIND_IFRAMES}] - If set to true, it will try to get the location of the topmost [window]{@link https://developer.mozilla.org/en-US/docs/Web/API/Window} object. Useful in case the script is running in an [iframe]{@link https://developer.mozilla.org/en-US/docs/Web/HTML/Element/iframe} or more.
826 * @returns {string}
827 */
828 CB_Client.getLocation = function(mindIframes)
829 {
830 var address = "";
831 try
832 {
833 address = CB_Client.getWindow(mindIframes).location.href;
834 }
835 catch(E) { address = ""; }
836 if (!address) { address = window.location.href; }
837 return address;
838 }
839
840 /**
841 * Returns the given address without the file (for example, if "http://whatever.com/index.html" is given, it will return "http://whatever.com/").
842 * @function
843 * @param {string} address - The address that we want to filter.
844 * @param {string} [fallbackURL] - The address that we want it to return in the case that the given one is not allowed (used when "allowsLocal" does not allow a local address). If it contains a file, it will not be stripped out.
845 * @param {boolean} [allowsLocal=true] - Defines whether to allow returning a local address or not. If it is set to false and the address is local, it will return the "fallbackURL" instead (without stripping out the file, if any).
846 * @returns {string}
847 */
848 CB_Client.getAddressWithoutFile = function(address, fallbackURL, allowsLocal)
849 {
850 if (allowsLocal !== true &amp;&amp; allowsLocal !== false) { allowsLocal = true; }
851
852 address = CB_trim(address);
853 address = CB_rtrim(address.substring(0, address.lastIndexOf("/")), "/") + "/";
854
855 if (allowsLocal || address.indexOf("://localhost") === -1 &amp;&amp; address.indexOf("://127.0.0.1") === -1 &amp;&amp; address.indexOf("://192.168") === -1 || !CB_isString(fallbackURL))
856 {
857 return address;
858 }
859 else { return fallbackURL; }
860 }
861
862
863 /**
864 * Returns the current URL without the file (for example, if "http://whatever.com/index.html" is the current URL, it will return "http://whatever.com/"), if possible (having in mind whether the script is running in one [iframe]{@link https://developer.mozilla.org/en-US/docs/Web/HTML/Element/iframe} or more, if we want).
865 * @function
866 * @param {string} [fallbackURL] - The address that we want it to return in the case that the current one is not allowed (used when "allowsLocal" does not allow a local address). If it contains a file, it will not be stripped out.
867 * @param {boolean} [allowsLocal=true] - Defines whether to allow returning a local address or not. If it is set to false and the current address is local, it will return the "fallbackURL" instead (without stripping out the file, if any).
868 * @param {boolean} [mindIframes={@link CB_Configuration.CrossBase.MIND_IFRAMES}] - If set to true, it will try to get the location of the topmost [window]{@link https://developer.mozilla.org/en-US/docs/Web/API/Window} object. Useful in case the script is running in an [iframe]{@link https://developer.mozilla.org/en-US/docs/Web/HTML/Element/iframe} or more.
869 * @returns {string}
870 */
871 CB_Client.getLocationWithoutFile = function(fallbackURL, allowsLocal, mindIframes)
872 {
873 return CB_Client.getAddressWithoutFile(CB_Client.getLocation(mindIframes), fallbackURL, allowsLocal);
874 }
875
876
877 //var firstTimeShit = 0;
878 /**
879 * Gets the starting pixel of top or left coordinates for [getBoundingClientRect]{@link https://developer.mozilla.org/en-US/docs/Web/API/Element/getBoundingClientRect} (it's not 0 in some Internet Explorer versions).
880 * @function
881 * @param {('left'|'top')} [leftOrTop='left'] - String that defines whether we want it to return the values for "left" or for "top".
882 * @returns {integer}
883 */
884 CB_Client.getBoundingClientRectMargin = function(leftOrTop)
885 {
886 leftOrTop = leftOrTop.toLowerCase();
887 if (leftOrTop === "" || leftOrTop !== "left" &amp;&amp; leftOrTop !== "top") { leftOrTop = "left"; }
888
889 var getBoundingClientRectMarginDiv = CB_Elements.id("getBoundingClientRectMarginDiv");
890 if (getBoundingClientRectMarginDiv === null)
891 {
892 var getBoundingClientRectMarginDiv = document.createElement("div");
893 getBoundingClientRectMarginDiv.id = "getBoundingClientRectMarginDiv";
894 getBoundingClientRectMarginDiv.style.position = "absolute";
895 getBoundingClientRectMarginDiv.style.width = getBoundingClientRectMarginDiv.style.height = "0px";
896 getBoundingClientRectMarginDiv.style.visibility = "hidden";
897 getBoundingClientRectMarginDiv.style.left = "0px";
898 getBoundingClientRectMarginDiv.style.top = "0px";
899 var tagBody = CB_Elements.tag("body", document);
900 if (typeof(tagBody) !== "undefined" &amp;&amp; tagBody !== null &amp;&amp; typeof(tagBody[0]) !== "undefined" &amp;&amp; tagBody[0] !== null)
901 {
902 tagBody[0].appendChild(getBoundingClientRectMarginDiv);
903 //firstTimeShit = true;
904 }
905 }
906
907 if (typeof(getBoundingClientRectMarginDiv.getBoundingClientRect) !== "undefined" &amp;&amp; getBoundingClientRectMarginDiv.getBoundingClientRect !== null)
908 {
909 var rectMargin = getBoundingClientRectMarginDiv.getBoundingClientRect();
910 var margin = 0;
911 if (typeof(rectMargin[leftOrTop]) !== "undefined" &amp;&amp; rectMargin[leftOrTop] !== null &amp;&amp; !isNaN(rectMargin[leftOrTop]))
912 {
913 margin = rectMargin[leftOrTop];
914 }
915 }
916
917 if (margin &lt; 0)
918 {
919 if (leftOrTop === "left") { margin += CB_Screen.getScrollLeft(); }
920 else { margin += CB_Screen.getScrollTop(); }
921 if (margin &lt; 0) { margin = 0; }
922 }
923
924 return margin;
925 }
926
927
928 /**
929 * Tries to change the [document title]{@link https://developer.mozilla.org/en-US/docs/Web/API/Document/title} and returns it.
930 * @function
931 * @param {newTitle} newTitle - The desired new title.
932 * @returns {string}
933 */
934 CB_Client.setTitle = function(newTitle)
935 {
936 CB_Client.getDocumentBase().title = newTitle;
937 //Chrome and Opera fix:
938 var tagTitle = CB_Elements.tag("title");
939 if (typeof(tagTitle) !== "undefined" &amp;&amp; tagTitle !== null &amp;&amp; typeof(tagTitle[0]) !== "undefined" &amp;&amp; tagTitle[0] !== null)
940 {
941 tagTitle = tagTitle[0];
942 try { tagTitle.innerHTML = newTitle; } catch(E) {} //Catch to avoid IE8 error.
943 }
944 titleCurrent = CB_Client.getTitle();
945 return titleCurrent;
946 }
947
948
949 /**
950 * Returns the current [document title]{@link https://developer.mozilla.org/en-US/docs/Web/API/Document/title}.
951 * @function
952 * @returns {string}
953 */
954 CB_Client.getTitle = function()
955 {
956 var title = CB_trim(CB_Client.getDocumentBase().title);
957 if (title === "")
958 {
959 //Chrome and Opera fix:
960 var tagTitle = CB_Elements.tag("title");
961 if (typeof(tagTitle) !== "undefined" &amp;&amp; tagTitle !== null &amp;&amp; typeof(tagTitle[0]) !== "undefined" &amp;&amp; tagTitle[0] !== null)
962 {
963 tagTitle = tagTitle[0];
964 try { title = tagTitle.innerHTML; } catch(E) { title = ""; } //Catch to avoid IE8 error.
965 }
966 }
967 return title;
968 }
969
970
971 //Sets a function to execute when a desired event is fired:
972 CB_Client._setEvent = function(eventName, eventFunction, keepOldFunction, useCapture, target)
973 {
974 //If they are not set, use default values for optional parameters:
975 if (typeof(keepOldFunction) === "undefined" || keepOldFunction === null) { keepOldFunction = true; } //If not set, it keeps old function by default.
976 if (typeof(target) === "undefined" || target === null)
977 {
978 target = window;
979 }
980
981 //If a function has been sent:
982 if (typeof(eventFunction) === "function")
983 {
984 //If able, adds the function given to the event:
985 CB_Events.add
986 (
987 target,
988 eventName,
989 function(e)
990 {
991 e = CB_Events.normalize(e);
992 if (typeof(eventFunction) === "function") { return eventFunction(e); }
993 return true;
994 },
995 useCapture,
996 keepOldFunction,
997 true
998 );
999 }
1000 //...but if the function given is null, it will cancel the event:
1001 else if (eventFunction === null)
1002 {
1003 CB_Events.removeByName(target, eventName);
1004 }
1005 }
1006
1007
1008}</pre>
1009 </article>
1010</section>
1011
1012
1013
1014
1015
1016 </div>
1017 </div>
1018
1019 <div class="clearfix"></div>
1020
1021
1022
1023</div>
1024</div>
1025
1026
1027 <div class="modal fade" id="searchResults">
1028 <div class="modal-dialog">
1029 <div class="modal-content">
1030 <div class="modal-header">
1031 <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
1032 <h4 class="modal-title">Search results</h4>
1033 </div>
1034 <div class="modal-body"></div>
1035 <div class="modal-footer">
1036 <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
1037 </div>
1038 </div><!-- /.modal-content -->
1039 </div><!-- /.modal-dialog -->
1040 </div>
1041
1042
1043<footer>
1044
1045
1046 <span class="copyright">
1047 <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>
1048 </span>
1049
1050<span class="jsdoc-message">
1051 Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.5.5</a>
1052
1053 on Mon Feb 3rd 2020
1054
1055 using the <a href="https://github.com/docstrap/docstrap">DocStrap template</a>.
1056</span>
1057</footer>
1058
1059<script src="scripts/docstrap.lib.js"></script>
1060<script src="scripts/toc.js"></script>
1061
1062 <script type="text/javascript" src="scripts/fulltext-search-ui.js"></script>
1063
1064
1065<script>
1066$( function () {
1067 $( "[id*='$']" ).each( function () {
1068 var $this = $( this );
1069
1070 $this.attr( "id", $this.attr( "id" ).replace( "$", "__" ) );
1071 } );
1072
1073 $( ".tutorial-section pre, .readme-section pre, pre.prettyprint.source" ).each( function () {
1074 var $this = $( this );
1075
1076 var example = $this.find( "code" );
1077 exampleText = example.html();
1078 var lang = /{@lang (.*?)}/.exec( exampleText );
1079 if ( lang && lang[1] ) {
1080 exampleText = exampleText.replace( lang[0], "" );
1081 example.html( exampleText );
1082 lang = lang[1];
1083 } else {
1084 var langClassMatch = example.parent()[0].className.match(/lang\-(\S+)/);
1085 lang = langClassMatch ? langClassMatch[1] : "javascript";
1086 }
1087
1088 if ( lang ) {
1089
1090 $this
1091 .addClass( "sunlight-highlight-" + lang )
1092 .addClass( "linenums" )
1093 .html( example.html() );
1094
1095 }
1096 } );
1097
1098 Sunlight.highlightAll( {
1099 lineNumbers : true,
1100 showMenu : true,
1101 enableDoclinks : true
1102 } );
1103
1104 $.catchAnchorLinks( {
1105 navbarOffset: 10
1106 } );
1107 $( "#toc" ).toc( {
1108 anchorName : function ( i, heading, prefix ) {
1109 return $( heading ).attr( "id" ) || ( prefix + i );
1110 },
1111 selectors : "#toc-content h1,#toc-content h2,#toc-content h3,#toc-content h4",
1112 showAndHide : false,
1113 smoothScrolling: true
1114 } );
1115
1116 $( "#main span[id^='toc']" ).addClass( "toc-shim" );
1117 $( '.dropdown-toggle' ).dropdown();
1118
1119 $( "table" ).each( function () {
1120 var $this = $( this );
1121 $this.addClass('table');
1122 } );
1123
1124} );
1125</script>
1126
1127
1128
1129<!--Navigation and Symbol Display-->
1130
1131<script>
1132 $( function () {
1133 $( '#main' ).localScroll( {
1134 offset : { top : 60 } //offset by the height of your header (give or take a few px, see what works for you)
1135 } );
1136 $( "dt.name" ).each( function () {
1137 var $this = $( this ).find("h4");
1138 var icon = $( "<i/>" ).addClass( "icon-plus-sign" ).addClass( "pull-right" ).addClass( "icon-white" );
1139 var dt = $(this);
1140 var children = dt.next( "dd" );
1141
1142 dt.prepend( icon ).css( {cursor : "pointer"} );
1143 dt.addClass( "member-collapsed" ).addClass( "member" );
1144
1145
1146 children.hide();
1147
1148 dt.children().on( "click", function () {
1149 children = dt.next( "dd" );
1150 children.slideToggle( "fast", function () {
1151
1152 if ( children.is( ":visible" ) ) {
1153 icon.addClass( "icon-minus-sign" ).removeClass( "icon-plus-sign" ).removeClass( "icon-white" );
1154 dt.addClass( "member-open" ).animate( "member-collapsed" );
1155 } else {
1156 icon.addClass( "icon-plus-sign" ).removeClass( "icon-minus-sign" ).addClass( "icon-white" );
1157 dt.addClass( "member-collapsed" ).removeClass( "member-open" );
1158 }
1159 } );
1160 } );
1161
1162 } );
1163 } );
1164</script>
1165
1166
1167<!--Google Analytics-->
1168
1169
1170
1171 <script type="text/javascript">
1172 $(document).ready(function() {
1173 SearcherDisplay.init();
1174 });
1175 </script>
1176
1177
1178</body>
1179</html>