cordova.js 76 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432
  1. // Platform: ios
  2. // 9e8e1b716252c4a08abcd31a13013b868d6f4141
  3. /*
  4. Licensed to the Apache Software Foundation (ASF) under one
  5. or more contributor license agreements. See the NOTICE file
  6. distributed with this work for additional information
  7. regarding copyright ownership. The ASF licenses this file
  8. to you under the Apache License, Version 2.0 (the
  9. "License"); you may not use this file except in compliance
  10. with the License. You may obtain a copy of the License at
  11. http://www.apache.org/licenses/LICENSE-2.0
  12. Unless required by applicable law or agreed to in writing,
  13. software distributed under the License is distributed on an
  14. "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  15. KIND, either express or implied. See the License for the
  16. specific language governing permissions and limitations
  17. under the License.
  18. */
  19. ;(function() {
  20. var PLATFORM_VERSION_BUILD_LABEL = '4.5.5';
  21. // file: src/scripts/require.js
  22. /* jshint -W079 */
  23. /* jshint -W020 */
  24. var require;
  25. var define;
  26. (function () {
  27. var modules = {};
  28. // Stack of moduleIds currently being built.
  29. var requireStack = [];
  30. // Map of module ID -> index into requireStack of modules currently being built.
  31. var inProgressModules = {};
  32. var SEPARATOR = '.';
  33. function build (module) {
  34. var factory = module.factory;
  35. var localRequire = function (id) {
  36. var resultantId = id;
  37. // Its a relative path, so lop off the last portion and add the id (minus "./")
  38. if (id.charAt(0) === '.') {
  39. resultantId = module.id.slice(0, module.id.lastIndexOf(SEPARATOR)) + SEPARATOR + id.slice(2);
  40. }
  41. return require(resultantId);
  42. };
  43. module.exports = {};
  44. delete module.factory;
  45. factory(localRequire, module.exports, module);
  46. return module.exports;
  47. }
  48. require = function (id) {
  49. if (!modules[id]) {
  50. throw 'module ' + id + ' not found';
  51. } else if (id in inProgressModules) {
  52. var cycle = requireStack.slice(inProgressModules[id]).join('->') + '->' + id;
  53. throw 'Cycle in require graph: ' + cycle;
  54. }
  55. if (modules[id].factory) {
  56. try {
  57. inProgressModules[id] = requireStack.length;
  58. requireStack.push(id);
  59. return build(modules[id]);
  60. } finally {
  61. delete inProgressModules[id];
  62. requireStack.pop();
  63. }
  64. }
  65. return modules[id].exports;
  66. };
  67. define = function (id, factory) {
  68. if (modules[id]) {
  69. throw 'module ' + id + ' already defined';
  70. }
  71. modules[id] = {
  72. id: id,
  73. factory: factory
  74. };
  75. };
  76. define.remove = function (id) {
  77. delete modules[id];
  78. };
  79. define.moduleMap = modules;
  80. })();
  81. // Export for use in node
  82. if (typeof module === 'object' && typeof require === 'function') {
  83. module.exports.require = require;
  84. module.exports.define = define;
  85. }
  86. // file: src/cordova.js
  87. define("cordova", function(require, exports, module) {
  88. // Workaround for Windows 10 in hosted environment case
  89. // http://www.w3.org/html/wg/drafts/html/master/browsers.html#named-access-on-the-window-object
  90. if (window.cordova && !(window.cordova instanceof HTMLElement)) { // eslint-disable-line no-undef
  91. throw new Error('cordova already defined');
  92. }
  93. var channel = require('cordova/channel');
  94. var platform = require('cordova/platform');
  95. /**
  96. * Intercept calls to addEventListener + removeEventListener and handle deviceready,
  97. * resume, and pause events.
  98. */
  99. var m_document_addEventListener = document.addEventListener;
  100. var m_document_removeEventListener = document.removeEventListener;
  101. var m_window_addEventListener = window.addEventListener;
  102. var m_window_removeEventListener = window.removeEventListener;
  103. /**
  104. * Houses custom event handlers to intercept on document + window event listeners.
  105. */
  106. var documentEventHandlers = {};
  107. var windowEventHandlers = {};
  108. document.addEventListener = function (evt, handler, capture) {
  109. var e = evt.toLowerCase();
  110. if (typeof documentEventHandlers[e] !== 'undefined') {
  111. documentEventHandlers[e].subscribe(handler);
  112. } else {
  113. m_document_addEventListener.call(document, evt, handler, capture);
  114. }
  115. };
  116. window.addEventListener = function (evt, handler, capture) {
  117. var e = evt.toLowerCase();
  118. if (typeof windowEventHandlers[e] !== 'undefined') {
  119. windowEventHandlers[e].subscribe(handler);
  120. } else {
  121. m_window_addEventListener.call(window, evt, handler, capture);
  122. }
  123. };
  124. document.removeEventListener = function (evt, handler, capture) {
  125. var e = evt.toLowerCase();
  126. // If unsubscribing from an event that is handled by a plugin
  127. if (typeof documentEventHandlers[e] !== 'undefined') {
  128. documentEventHandlers[e].unsubscribe(handler);
  129. } else {
  130. m_document_removeEventListener.call(document, evt, handler, capture);
  131. }
  132. };
  133. window.removeEventListener = function (evt, handler, capture) {
  134. var e = evt.toLowerCase();
  135. // If unsubscribing from an event that is handled by a plugin
  136. if (typeof windowEventHandlers[e] !== 'undefined') {
  137. windowEventHandlers[e].unsubscribe(handler);
  138. } else {
  139. m_window_removeEventListener.call(window, evt, handler, capture);
  140. }
  141. };
  142. function createEvent (type, data) {
  143. var event = document.createEvent('Events');
  144. event.initEvent(type, false, false);
  145. if (data) {
  146. for (var i in data) {
  147. if (data.hasOwnProperty(i)) {
  148. event[i] = data[i];
  149. }
  150. }
  151. }
  152. return event;
  153. }
  154. /* eslint-disable no-undef */
  155. var cordova = {
  156. define: define,
  157. require: require,
  158. version: PLATFORM_VERSION_BUILD_LABEL,
  159. platformVersion: PLATFORM_VERSION_BUILD_LABEL,
  160. platformId: platform.id,
  161. /* eslint-enable no-undef */
  162. /**
  163. * Methods to add/remove your own addEventListener hijacking on document + window.
  164. */
  165. addWindowEventHandler: function (event) {
  166. return (windowEventHandlers[event] = channel.create(event));
  167. },
  168. addStickyDocumentEventHandler: function (event) {
  169. return (documentEventHandlers[event] = channel.createSticky(event));
  170. },
  171. addDocumentEventHandler: function (event) {
  172. return (documentEventHandlers[event] = channel.create(event));
  173. },
  174. removeWindowEventHandler: function (event) {
  175. delete windowEventHandlers[event];
  176. },
  177. removeDocumentEventHandler: function (event) {
  178. delete documentEventHandlers[event];
  179. },
  180. /**
  181. * Retrieve original event handlers that were replaced by Cordova
  182. *
  183. * @return object
  184. */
  185. getOriginalHandlers: function () {
  186. return {'document': {'addEventListener': m_document_addEventListener, 'removeEventListener': m_document_removeEventListener},
  187. 'window': {'addEventListener': m_window_addEventListener, 'removeEventListener': m_window_removeEventListener}};
  188. },
  189. /**
  190. * Method to fire event from native code
  191. * bNoDetach is required for events which cause an exception which needs to be caught in native code
  192. */
  193. fireDocumentEvent: function (type, data, bNoDetach) {
  194. var evt = createEvent(type, data);
  195. if (typeof documentEventHandlers[type] !== 'undefined') {
  196. if (bNoDetach) {
  197. documentEventHandlers[type].fire(evt);
  198. } else {
  199. setTimeout(function () {
  200. // Fire deviceready on listeners that were registered before cordova.js was loaded.
  201. if (type === 'deviceready') {
  202. document.dispatchEvent(evt);
  203. }
  204. documentEventHandlers[type].fire(evt);
  205. }, 0);
  206. }
  207. } else {
  208. document.dispatchEvent(evt);
  209. }
  210. },
  211. fireWindowEvent: function (type, data) {
  212. var evt = createEvent(type, data);
  213. if (typeof windowEventHandlers[type] !== 'undefined') {
  214. setTimeout(function () {
  215. windowEventHandlers[type].fire(evt);
  216. }, 0);
  217. } else {
  218. window.dispatchEvent(evt);
  219. }
  220. },
  221. /**
  222. * Plugin callback mechanism.
  223. */
  224. // Randomize the starting callbackId to avoid collisions after refreshing or navigating.
  225. // This way, it's very unlikely that any new callback would get the same callbackId as an old callback.
  226. callbackId: Math.floor(Math.random() * 2000000000),
  227. callbacks: {},
  228. callbackStatus: {
  229. NO_RESULT: 0,
  230. OK: 1,
  231. CLASS_NOT_FOUND_EXCEPTION: 2,
  232. ILLEGAL_ACCESS_EXCEPTION: 3,
  233. INSTANTIATION_EXCEPTION: 4,
  234. MALFORMED_URL_EXCEPTION: 5,
  235. IO_EXCEPTION: 6,
  236. INVALID_ACTION: 7,
  237. JSON_EXCEPTION: 8,
  238. ERROR: 9
  239. },
  240. /**
  241. * Called by native code when returning successful result from an action.
  242. */
  243. callbackSuccess: function (callbackId, args) {
  244. cordova.callbackFromNative(callbackId, true, args.status, [args.message], args.keepCallback);
  245. },
  246. /**
  247. * Called by native code when returning error result from an action.
  248. */
  249. callbackError: function (callbackId, args) {
  250. // TODO: Deprecate callbackSuccess and callbackError in favour of callbackFromNative.
  251. // Derive success from status.
  252. cordova.callbackFromNative(callbackId, false, args.status, [args.message], args.keepCallback);
  253. },
  254. /**
  255. * Called by native code when returning the result from an action.
  256. */
  257. callbackFromNative: function (callbackId, isSuccess, status, args, keepCallback) {
  258. try {
  259. var callback = cordova.callbacks[callbackId];
  260. if (callback) {
  261. if (isSuccess && status === cordova.callbackStatus.OK) {
  262. callback.success && callback.success.apply(null, args);
  263. } else if (!isSuccess) {
  264. callback.fail && callback.fail.apply(null, args);
  265. }
  266. /*
  267. else
  268. Note, this case is intentionally not caught.
  269. this can happen if isSuccess is true, but callbackStatus is NO_RESULT
  270. which is used to remove a callback from the list without calling the callbacks
  271. typically keepCallback is false in this case
  272. */
  273. // Clear callback if not expecting any more results
  274. if (!keepCallback) {
  275. delete cordova.callbacks[callbackId];
  276. }
  277. }
  278. } catch (err) {
  279. var msg = 'Error in ' + (isSuccess ? 'Success' : 'Error') + ' callbackId: ' + callbackId + ' : ' + err;
  280. console && console.log && console.log(msg);
  281. console && console.log && err.stack && console.log(err.stack);
  282. cordova.fireWindowEvent('cordovacallbackerror', { 'message': msg });
  283. throw err;
  284. }
  285. },
  286. addConstructor: function (func) {
  287. channel.onCordovaReady.subscribe(function () {
  288. try {
  289. func();
  290. } catch (e) {
  291. console.log('Failed to run constructor: ' + e);
  292. }
  293. });
  294. }
  295. };
  296. module.exports = cordova;
  297. });
  298. // file: src/common/argscheck.js
  299. define("cordova/argscheck", function(require, exports, module) {
  300. var utils = require('cordova/utils');
  301. var moduleExports = module.exports;
  302. var typeMap = {
  303. 'A': 'Array',
  304. 'D': 'Date',
  305. 'N': 'Number',
  306. 'S': 'String',
  307. 'F': 'Function',
  308. 'O': 'Object'
  309. };
  310. function extractParamName (callee, argIndex) {
  311. return (/.*?\((.*?)\)/).exec(callee)[1].split(', ')[argIndex];
  312. }
  313. function checkArgs (spec, functionName, args, opt_callee) {
  314. if (!moduleExports.enableChecks) {
  315. return;
  316. }
  317. var errMsg = null;
  318. var typeName;
  319. for (var i = 0; i < spec.length; ++i) {
  320. var c = spec.charAt(i);
  321. var cUpper = c.toUpperCase();
  322. var arg = args[i];
  323. // Asterix means allow anything.
  324. if (c === '*') {
  325. continue;
  326. }
  327. typeName = utils.typeName(arg);
  328. if ((arg === null || arg === undefined) && c === cUpper) {
  329. continue;
  330. }
  331. if (typeName !== typeMap[cUpper]) {
  332. errMsg = 'Expected ' + typeMap[cUpper];
  333. break;
  334. }
  335. }
  336. if (errMsg) {
  337. errMsg += ', but got ' + typeName + '.';
  338. errMsg = 'Wrong type for parameter "' + extractParamName(opt_callee || args.callee, i) + '" of ' + functionName + ': ' + errMsg;
  339. // Don't log when running unit tests.
  340. if (typeof jasmine === 'undefined') {
  341. console.error(errMsg);
  342. }
  343. throw TypeError(errMsg);
  344. }
  345. }
  346. function getValue (value, defaultValue) {
  347. return value === undefined ? defaultValue : value;
  348. }
  349. moduleExports.checkArgs = checkArgs;
  350. moduleExports.getValue = getValue;
  351. moduleExports.enableChecks = true;
  352. });
  353. // file: src/common/base64.js
  354. define("cordova/base64", function(require, exports, module) {
  355. var base64 = exports;
  356. base64.fromArrayBuffer = function (arrayBuffer) {
  357. var array = new Uint8Array(arrayBuffer);
  358. return uint8ToBase64(array);
  359. };
  360. base64.toArrayBuffer = function (str) {
  361. var decodedStr = typeof atob !== 'undefined' ? atob(str) : Buffer.from(str, 'base64').toString('binary'); // eslint-disable-line no-undef
  362. var arrayBuffer = new ArrayBuffer(decodedStr.length);
  363. var array = new Uint8Array(arrayBuffer);
  364. for (var i = 0, len = decodedStr.length; i < len; i++) {
  365. array[i] = decodedStr.charCodeAt(i);
  366. }
  367. return arrayBuffer;
  368. };
  369. // ------------------------------------------------------------------------------
  370. /* This code is based on the performance tests at http://jsperf.com/b64tests
  371. * This 12-bit-at-a-time algorithm was the best performing version on all
  372. * platforms tested.
  373. */
  374. var b64_6bit = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/';
  375. var b64_12bit;
  376. var b64_12bitTable = function () {
  377. b64_12bit = [];
  378. for (var i = 0; i < 64; i++) {
  379. for (var j = 0; j < 64; j++) {
  380. b64_12bit[i * 64 + j] = b64_6bit[i] + b64_6bit[j];
  381. }
  382. }
  383. b64_12bitTable = function () { return b64_12bit; };
  384. return b64_12bit;
  385. };
  386. function uint8ToBase64 (rawData) {
  387. var numBytes = rawData.byteLength;
  388. var output = '';
  389. var segment;
  390. var table = b64_12bitTable();
  391. for (var i = 0; i < numBytes - 2; i += 3) {
  392. segment = (rawData[i] << 16) + (rawData[i + 1] << 8) + rawData[i + 2];
  393. output += table[segment >> 12];
  394. output += table[segment & 0xfff];
  395. }
  396. if (numBytes - i === 2) {
  397. segment = (rawData[i] << 16) + (rawData[i + 1] << 8);
  398. output += table[segment >> 12];
  399. output += b64_6bit[(segment & 0xfff) >> 6];
  400. output += '=';
  401. } else if (numBytes - i === 1) {
  402. segment = (rawData[i] << 16);
  403. output += table[segment >> 12];
  404. output += '==';
  405. }
  406. return output;
  407. }
  408. });
  409. // file: src/common/builder.js
  410. define("cordova/builder", function(require, exports, module) {
  411. var utils = require('cordova/utils');
  412. function each (objects, func, context) {
  413. for (var prop in objects) {
  414. if (objects.hasOwnProperty(prop)) {
  415. func.apply(context, [objects[prop], prop]);
  416. }
  417. }
  418. }
  419. function clobber (obj, key, value) {
  420. exports.replaceHookForTesting(obj, key);
  421. var needsProperty = false;
  422. try {
  423. obj[key] = value;
  424. } catch (e) {
  425. needsProperty = true;
  426. }
  427. // Getters can only be overridden by getters.
  428. if (needsProperty || obj[key] !== value) {
  429. utils.defineGetter(obj, key, function () {
  430. return value;
  431. });
  432. }
  433. }
  434. function assignOrWrapInDeprecateGetter (obj, key, value, message) {
  435. if (message) {
  436. utils.defineGetter(obj, key, function () {
  437. console.log(message);
  438. delete obj[key];
  439. clobber(obj, key, value);
  440. return value;
  441. });
  442. } else {
  443. clobber(obj, key, value);
  444. }
  445. }
  446. function include (parent, objects, clobber, merge) {
  447. each(objects, function (obj, key) {
  448. try {
  449. var result = obj.path ? require(obj.path) : {};
  450. if (clobber) {
  451. // Clobber if it doesn't exist.
  452. if (typeof parent[key] === 'undefined') {
  453. assignOrWrapInDeprecateGetter(parent, key, result, obj.deprecated);
  454. } else if (typeof obj.path !== 'undefined') {
  455. // If merging, merge properties onto parent, otherwise, clobber.
  456. if (merge) {
  457. recursiveMerge(parent[key], result);
  458. } else {
  459. assignOrWrapInDeprecateGetter(parent, key, result, obj.deprecated);
  460. }
  461. }
  462. result = parent[key];
  463. } else {
  464. // Overwrite if not currently defined.
  465. if (typeof parent[key] === 'undefined') {
  466. assignOrWrapInDeprecateGetter(parent, key, result, obj.deprecated);
  467. } else {
  468. // Set result to what already exists, so we can build children into it if they exist.
  469. result = parent[key];
  470. }
  471. }
  472. if (obj.children) {
  473. include(result, obj.children, clobber, merge);
  474. }
  475. } catch (e) {
  476. utils.alert('Exception building Cordova JS globals: ' + e + ' for key "' + key + '"');
  477. }
  478. });
  479. }
  480. /**
  481. * Merge properties from one object onto another recursively. Properties from
  482. * the src object will overwrite existing target property.
  483. *
  484. * @param target Object to merge properties into.
  485. * @param src Object to merge properties from.
  486. */
  487. function recursiveMerge (target, src) {
  488. for (var prop in src) {
  489. if (src.hasOwnProperty(prop)) {
  490. if (target.prototype && target.prototype.constructor === target) {
  491. // If the target object is a constructor override off prototype.
  492. clobber(target.prototype, prop, src[prop]);
  493. } else {
  494. if (typeof src[prop] === 'object' && typeof target[prop] === 'object') {
  495. recursiveMerge(target[prop], src[prop]);
  496. } else {
  497. clobber(target, prop, src[prop]);
  498. }
  499. }
  500. }
  501. }
  502. }
  503. exports.buildIntoButDoNotClobber = function (objects, target) {
  504. include(target, objects, false, false);
  505. };
  506. exports.buildIntoAndClobber = function (objects, target) {
  507. include(target, objects, true, false);
  508. };
  509. exports.buildIntoAndMerge = function (objects, target) {
  510. include(target, objects, true, true);
  511. };
  512. exports.recursiveMerge = recursiveMerge;
  513. exports.assignOrWrapInDeprecateGetter = assignOrWrapInDeprecateGetter;
  514. exports.replaceHookForTesting = function () {};
  515. });
  516. // file: src/common/channel.js
  517. define("cordova/channel", function(require, exports, module) {
  518. var utils = require('cordova/utils');
  519. var nextGuid = 1;
  520. /**
  521. * Custom pub-sub "channel" that can have functions subscribed to it
  522. * This object is used to define and control firing of events for
  523. * cordova initialization, as well as for custom events thereafter.
  524. *
  525. * The order of events during page load and Cordova startup is as follows:
  526. *
  527. * onDOMContentLoaded* Internal event that is received when the web page is loaded and parsed.
  528. * onNativeReady* Internal event that indicates the Cordova native side is ready.
  529. * onCordovaReady* Internal event fired when all Cordova JavaScript objects have been created.
  530. * onDeviceReady* User event fired to indicate that Cordova is ready
  531. * onResume User event fired to indicate a start/resume lifecycle event
  532. * onPause User event fired to indicate a pause lifecycle event
  533. *
  534. * The events marked with an * are sticky. Once they have fired, they will stay in the fired state.
  535. * All listeners that subscribe after the event is fired will be executed right away.
  536. *
  537. * The only Cordova events that user code should register for are:
  538. * deviceready Cordova native code is initialized and Cordova APIs can be called from JavaScript
  539. * pause App has moved to background
  540. * resume App has returned to foreground
  541. *
  542. * Listeners can be registered as:
  543. * document.addEventListener("deviceready", myDeviceReadyListener, false);
  544. * document.addEventListener("resume", myResumeListener, false);
  545. * document.addEventListener("pause", myPauseListener, false);
  546. *
  547. * The DOM lifecycle events should be used for saving and restoring state
  548. * window.onload
  549. * window.onunload
  550. *
  551. */
  552. /**
  553. * Channel
  554. * @constructor
  555. * @param type String the channel name
  556. */
  557. var Channel = function (type, sticky) {
  558. this.type = type;
  559. // Map of guid -> function.
  560. this.handlers = {};
  561. // 0 = Non-sticky, 1 = Sticky non-fired, 2 = Sticky fired.
  562. this.state = sticky ? 1 : 0;
  563. // Used in sticky mode to remember args passed to fire().
  564. this.fireArgs = null;
  565. // Used by onHasSubscribersChange to know if there are any listeners.
  566. this.numHandlers = 0;
  567. // Function that is called when the first listener is subscribed, or when
  568. // the last listener is unsubscribed.
  569. this.onHasSubscribersChange = null;
  570. };
  571. var channel = {
  572. /**
  573. * Calls the provided function only after all of the channels specified
  574. * have been fired. All channels must be sticky channels.
  575. */
  576. join: function (h, c) {
  577. var len = c.length;
  578. var i = len;
  579. var f = function () {
  580. if (!(--i)) h();
  581. };
  582. for (var j = 0; j < len; j++) {
  583. if (c[j].state === 0) {
  584. throw Error('Can only use join with sticky channels.');
  585. }
  586. c[j].subscribe(f);
  587. }
  588. if (!len) h();
  589. },
  590. /* eslint-disable no-return-assign */
  591. create: function (type) {
  592. return channel[type] = new Channel(type, false);
  593. },
  594. createSticky: function (type) {
  595. return channel[type] = new Channel(type, true);
  596. },
  597. /* eslint-enable no-return-assign */
  598. /**
  599. * cordova Channels that must fire before "deviceready" is fired.
  600. */
  601. deviceReadyChannelsArray: [],
  602. deviceReadyChannelsMap: {},
  603. /**
  604. * Indicate that a feature needs to be initialized before it is ready to be used.
  605. * This holds up Cordova's "deviceready" event until the feature has been initialized
  606. * and Cordova.initComplete(feature) is called.
  607. *
  608. * @param feature {String} The unique feature name
  609. */
  610. waitForInitialization: function (feature) {
  611. if (feature) {
  612. var c = channel[feature] || this.createSticky(feature);
  613. this.deviceReadyChannelsMap[feature] = c;
  614. this.deviceReadyChannelsArray.push(c);
  615. }
  616. },
  617. /**
  618. * Indicate that initialization code has completed and the feature is ready to be used.
  619. *
  620. * @param feature {String} The unique feature name
  621. */
  622. initializationComplete: function (feature) {
  623. var c = this.deviceReadyChannelsMap[feature];
  624. if (c) {
  625. c.fire();
  626. }
  627. }
  628. };
  629. function checkSubscriptionArgument (argument) {
  630. if (typeof argument !== 'function' && typeof argument.handleEvent !== 'function') {
  631. throw new Error(
  632. 'Must provide a function or an EventListener object ' +
  633. 'implementing the handleEvent interface.'
  634. );
  635. }
  636. }
  637. /**
  638. * Subscribes the given function to the channel. Any time that
  639. * Channel.fire is called so too will the function.
  640. * Optionally specify an execution context for the function
  641. * and a guid that can be used to stop subscribing to the channel.
  642. * Returns the guid.
  643. */
  644. Channel.prototype.subscribe = function (eventListenerOrFunction, eventListener) {
  645. checkSubscriptionArgument(eventListenerOrFunction);
  646. var handleEvent, guid;
  647. if (eventListenerOrFunction && typeof eventListenerOrFunction === 'object') {
  648. // Received an EventListener object implementing the handleEvent interface
  649. handleEvent = eventListenerOrFunction.handleEvent;
  650. eventListener = eventListenerOrFunction;
  651. } else {
  652. // Received a function to handle event
  653. handleEvent = eventListenerOrFunction;
  654. }
  655. if (this.state === 2) {
  656. handleEvent.apply(eventListener || this, this.fireArgs);
  657. return;
  658. }
  659. guid = eventListenerOrFunction.observer_guid;
  660. if (typeof eventListener === 'object') {
  661. handleEvent = utils.close(eventListener, handleEvent);
  662. }
  663. if (!guid) {
  664. // First time any channel has seen this subscriber
  665. guid = '' + nextGuid++;
  666. }
  667. handleEvent.observer_guid = guid;
  668. eventListenerOrFunction.observer_guid = guid;
  669. // Don't add the same handler more than once.
  670. if (!this.handlers[guid]) {
  671. this.handlers[guid] = handleEvent;
  672. this.numHandlers++;
  673. if (this.numHandlers === 1) {
  674. this.onHasSubscribersChange && this.onHasSubscribersChange();
  675. }
  676. }
  677. };
  678. /**
  679. * Unsubscribes the function with the given guid from the channel.
  680. */
  681. Channel.prototype.unsubscribe = function (eventListenerOrFunction) {
  682. checkSubscriptionArgument(eventListenerOrFunction);
  683. var handleEvent, guid, handler;
  684. if (eventListenerOrFunction && typeof eventListenerOrFunction === 'object') {
  685. // Received an EventListener object implementing the handleEvent interface
  686. handleEvent = eventListenerOrFunction.handleEvent;
  687. } else {
  688. // Received a function to handle event
  689. handleEvent = eventListenerOrFunction;
  690. }
  691. guid = handleEvent.observer_guid;
  692. handler = this.handlers[guid];
  693. if (handler) {
  694. delete this.handlers[guid];
  695. this.numHandlers--;
  696. if (this.numHandlers === 0) {
  697. this.onHasSubscribersChange && this.onHasSubscribersChange();
  698. }
  699. }
  700. };
  701. /**
  702. * Calls all functions subscribed to this channel.
  703. */
  704. Channel.prototype.fire = function (e) {
  705. var fail = false; // eslint-disable-line no-unused-vars
  706. var fireArgs = Array.prototype.slice.call(arguments);
  707. // Apply stickiness.
  708. if (this.state === 1) {
  709. this.state = 2;
  710. this.fireArgs = fireArgs;
  711. }
  712. if (this.numHandlers) {
  713. // Copy the values first so that it is safe to modify it from within
  714. // callbacks.
  715. var toCall = [];
  716. for (var item in this.handlers) {
  717. toCall.push(this.handlers[item]);
  718. }
  719. for (var i = 0; i < toCall.length; ++i) {
  720. toCall[i].apply(this, fireArgs);
  721. }
  722. if (this.state === 2 && this.numHandlers) {
  723. this.numHandlers = 0;
  724. this.handlers = {};
  725. this.onHasSubscribersChange && this.onHasSubscribersChange();
  726. }
  727. }
  728. };
  729. // defining them here so they are ready super fast!
  730. // DOM event that is received when the web page is loaded and parsed.
  731. channel.createSticky('onDOMContentLoaded');
  732. // Event to indicate the Cordova native side is ready.
  733. channel.createSticky('onNativeReady');
  734. // Event to indicate that all Cordova JavaScript objects have been created
  735. // and it's time to run plugin constructors.
  736. channel.createSticky('onCordovaReady');
  737. // Event to indicate that all automatically loaded JS plugins are loaded and ready.
  738. // FIXME remove this
  739. channel.createSticky('onPluginsReady');
  740. // Event to indicate that Cordova is ready
  741. channel.createSticky('onDeviceReady');
  742. // Event to indicate a resume lifecycle event
  743. channel.create('onResume');
  744. // Event to indicate a pause lifecycle event
  745. channel.create('onPause');
  746. // Channels that must fire before "deviceready" is fired.
  747. channel.waitForInitialization('onCordovaReady');
  748. channel.waitForInitialization('onDOMContentLoaded');
  749. module.exports = channel;
  750. });
  751. // file: /Users/brodybits/Documents/cordova/cordova-ios/cordova-js-src/exec.js
  752. define("cordova/exec", function(require, exports, module) {
  753. /*global require, module, atob, document */
  754. /**
  755. * Creates a gap bridge iframe used to notify the native code about queued
  756. * commands.
  757. */
  758. var cordova = require('cordova'),
  759. utils = require('cordova/utils'),
  760. base64 = require('cordova/base64'),
  761. execIframe,
  762. commandQueue = [], // Contains pending JS->Native messages.
  763. isInContextOfEvalJs = 0,
  764. failSafeTimerId = 0;
  765. function massageArgsJsToNative(args) {
  766. if (!args || utils.typeName(args) != 'Array') {
  767. return args;
  768. }
  769. var ret = [];
  770. args.forEach(function(arg, i) {
  771. if (utils.typeName(arg) == 'ArrayBuffer') {
  772. ret.push({
  773. 'CDVType': 'ArrayBuffer',
  774. 'data': base64.fromArrayBuffer(arg)
  775. });
  776. } else {
  777. ret.push(arg);
  778. }
  779. });
  780. return ret;
  781. }
  782. function massageMessageNativeToJs(message) {
  783. if (message.CDVType == 'ArrayBuffer') {
  784. var stringToArrayBuffer = function(str) {
  785. var ret = new Uint8Array(str.length);
  786. for (var i = 0; i < str.length; i++) {
  787. ret[i] = str.charCodeAt(i);
  788. }
  789. return ret.buffer;
  790. };
  791. var base64ToArrayBuffer = function(b64) {
  792. return stringToArrayBuffer(atob(b64));
  793. };
  794. message = base64ToArrayBuffer(message.data);
  795. }
  796. return message;
  797. }
  798. function convertMessageToArgsNativeToJs(message) {
  799. var args = [];
  800. if (!message || !message.hasOwnProperty('CDVType')) {
  801. args.push(message);
  802. } else if (message.CDVType == 'MultiPart') {
  803. message.messages.forEach(function(e) {
  804. args.push(massageMessageNativeToJs(e));
  805. });
  806. } else {
  807. args.push(massageMessageNativeToJs(message));
  808. }
  809. return args;
  810. }
  811. function iOSExec() {
  812. var successCallback, failCallback, service, action, actionArgs;
  813. var callbackId = null;
  814. if (typeof arguments[0] !== 'string') {
  815. // FORMAT ONE
  816. successCallback = arguments[0];
  817. failCallback = arguments[1];
  818. service = arguments[2];
  819. action = arguments[3];
  820. actionArgs = arguments[4];
  821. // Since we need to maintain backwards compatibility, we have to pass
  822. // an invalid callbackId even if no callback was provided since plugins
  823. // will be expecting it. The Cordova.exec() implementation allocates
  824. // an invalid callbackId and passes it even if no callbacks were given.
  825. callbackId = 'INVALID';
  826. } else {
  827. throw new Error('The old format of this exec call has been removed (deprecated since 2.1). Change to: ' +
  828. 'cordova.exec(null, null, \'Service\', \'action\', [ arg1, arg2 ]);'
  829. );
  830. }
  831. // If actionArgs is not provided, default to an empty array
  832. actionArgs = actionArgs || [];
  833. // Register the callbacks and add the callbackId to the positional
  834. // arguments if given.
  835. if (successCallback || failCallback) {
  836. callbackId = service + cordova.callbackId++;
  837. cordova.callbacks[callbackId] =
  838. {success:successCallback, fail:failCallback};
  839. }
  840. actionArgs = massageArgsJsToNative(actionArgs);
  841. var command = [callbackId, service, action, actionArgs];
  842. // Stringify and queue the command. We stringify to command now to
  843. // effectively clone the command arguments in case they are mutated before
  844. // the command is executed.
  845. commandQueue.push(JSON.stringify(command));
  846. // If we're in the context of a stringByEvaluatingJavaScriptFromString call,
  847. // then the queue will be flushed when it returns; no need for a poke.
  848. // Also, if there is already a command in the queue, then we've already
  849. // poked the native side, so there is no reason to do so again.
  850. if (!isInContextOfEvalJs && commandQueue.length == 1) {
  851. pokeNative();
  852. }
  853. }
  854. // CB-10530
  855. function proxyChanged() {
  856. var cexec = cordovaExec();
  857. return (execProxy !== cexec && // proxy objects are different
  858. iOSExec !== cexec // proxy object is not the current iOSExec
  859. );
  860. }
  861. // CB-10106
  862. function handleBridgeChange() {
  863. if (proxyChanged()) {
  864. var commandString = commandQueue.shift();
  865. while(commandString) {
  866. var command = JSON.parse(commandString);
  867. var callbackId = command[0];
  868. var service = command[1];
  869. var action = command[2];
  870. var actionArgs = command[3];
  871. var callbacks = cordova.callbacks[callbackId] || {};
  872. execProxy(callbacks.success, callbacks.fail, service, action, actionArgs);
  873. commandString = commandQueue.shift();
  874. };
  875. return true;
  876. }
  877. return false;
  878. }
  879. function pokeNative() {
  880. // CB-5488 - Don't attempt to create iframe before document.body is available.
  881. if (!document.body) {
  882. setTimeout(pokeNative);
  883. return;
  884. }
  885. // Check if they've removed it from the DOM, and put it back if so.
  886. if (execIframe && execIframe.contentWindow) {
  887. execIframe.contentWindow.location = 'gap://ready';
  888. } else {
  889. execIframe = document.createElement('iframe');
  890. execIframe.style.display = 'none';
  891. execIframe.src = 'gap://ready';
  892. document.body.appendChild(execIframe);
  893. }
  894. // Use a timer to protect against iframe being unloaded during the poke (CB-7735).
  895. // This makes the bridge ~ 7% slower, but works around the poke getting lost
  896. // when the iframe is removed from the DOM.
  897. // An onunload listener could be used in the case where the iframe has just been
  898. // created, but since unload events fire only once, it doesn't work in the normal
  899. // case of iframe reuse (where unload will have already fired due to the attempted
  900. // navigation of the page).
  901. failSafeTimerId = setTimeout(function() {
  902. if (commandQueue.length) {
  903. // CB-10106 - flush the queue on bridge change
  904. if (!handleBridgeChange()) {
  905. pokeNative();
  906. }
  907. }
  908. }, 50); // Making this > 0 improves performance (marginally) in the normal case (where it doesn't fire).
  909. }
  910. iOSExec.nativeFetchMessages = function() {
  911. // Stop listing for window detatch once native side confirms poke.
  912. if (failSafeTimerId) {
  913. clearTimeout(failSafeTimerId);
  914. failSafeTimerId = 0;
  915. }
  916. // Each entry in commandQueue is a JSON string already.
  917. if (!commandQueue.length) {
  918. return '';
  919. }
  920. var json = '[' + commandQueue.join(',') + ']';
  921. commandQueue.length = 0;
  922. return json;
  923. };
  924. iOSExec.nativeCallback = function(callbackId, status, message, keepCallback, debug) {
  925. return iOSExec.nativeEvalAndFetch(function() {
  926. var success = status === 0 || status === 1;
  927. var args = convertMessageToArgsNativeToJs(message);
  928. function nc2() {
  929. cordova.callbackFromNative(callbackId, success, status, args, keepCallback);
  930. }
  931. setTimeout(nc2, 0);
  932. });
  933. };
  934. iOSExec.nativeEvalAndFetch = function(func) {
  935. // This shouldn't be nested, but better to be safe.
  936. isInContextOfEvalJs++;
  937. try {
  938. func();
  939. return iOSExec.nativeFetchMessages();
  940. } finally {
  941. isInContextOfEvalJs--;
  942. }
  943. };
  944. // Proxy the exec for bridge changes. See CB-10106
  945. function cordovaExec() {
  946. var cexec = require('cordova/exec');
  947. var cexec_valid = (typeof cexec.nativeFetchMessages === 'function') && (typeof cexec.nativeEvalAndFetch === 'function') && (typeof cexec.nativeCallback === 'function');
  948. return (cexec_valid && execProxy !== cexec)? cexec : iOSExec;
  949. }
  950. function execProxy() {
  951. cordovaExec().apply(null, arguments);
  952. };
  953. execProxy.nativeFetchMessages = function() {
  954. return cordovaExec().nativeFetchMessages.apply(null, arguments);
  955. };
  956. execProxy.nativeEvalAndFetch = function() {
  957. return cordovaExec().nativeEvalAndFetch.apply(null, arguments);
  958. };
  959. execProxy.nativeCallback = function() {
  960. return cordovaExec().nativeCallback.apply(null, arguments);
  961. };
  962. module.exports = execProxy;
  963. });
  964. // file: src/common/exec/proxy.js
  965. define("cordova/exec/proxy", function(require, exports, module) {
  966. // internal map of proxy function
  967. var CommandProxyMap = {};
  968. module.exports = {
  969. // example: cordova.commandProxy.add("Accelerometer",{getCurrentAcceleration: function(successCallback, errorCallback, options) {...},...);
  970. add: function (id, proxyObj) {
  971. console.log('adding proxy for ' + id);
  972. CommandProxyMap[id] = proxyObj;
  973. return proxyObj;
  974. },
  975. // cordova.commandProxy.remove("Accelerometer");
  976. remove: function (id) {
  977. var proxy = CommandProxyMap[id];
  978. delete CommandProxyMap[id];
  979. CommandProxyMap[id] = null;
  980. return proxy;
  981. },
  982. get: function (service, action) {
  983. return (CommandProxyMap[service] ? CommandProxyMap[service][action] : null);
  984. }
  985. };
  986. });
  987. // file: src/common/init.js
  988. define("cordova/init", function(require, exports, module) {
  989. var channel = require('cordova/channel');
  990. var cordova = require('cordova');
  991. var modulemapper = require('cordova/modulemapper');
  992. var platform = require('cordova/platform');
  993. var pluginloader = require('cordova/pluginloader');
  994. var utils = require('cordova/utils');
  995. var platformInitChannelsArray = [channel.onNativeReady, channel.onPluginsReady];
  996. function logUnfiredChannels (arr) {
  997. for (var i = 0; i < arr.length; ++i) {
  998. if (arr[i].state !== 2) {
  999. console.log('Channel not fired: ' + arr[i].type);
  1000. }
  1001. }
  1002. }
  1003. window.setTimeout(function () {
  1004. if (channel.onDeviceReady.state !== 2) {
  1005. console.log('deviceready has not fired after 5 seconds.');
  1006. logUnfiredChannels(platformInitChannelsArray);
  1007. logUnfiredChannels(channel.deviceReadyChannelsArray);
  1008. }
  1009. }, 5000);
  1010. // Replace navigator before any modules are required(), to ensure it happens as soon as possible.
  1011. // We replace it so that properties that can't be clobbered can instead be overridden.
  1012. function replaceNavigator (origNavigator) {
  1013. var CordovaNavigator = function () {};
  1014. CordovaNavigator.prototype = origNavigator;
  1015. var newNavigator = new CordovaNavigator();
  1016. // This work-around really only applies to new APIs that are newer than Function.bind.
  1017. // Without it, APIs such as getGamepads() break.
  1018. if (CordovaNavigator.bind) {
  1019. for (var key in origNavigator) {
  1020. if (typeof origNavigator[key] === 'function') {
  1021. newNavigator[key] = origNavigator[key].bind(origNavigator);
  1022. } else {
  1023. (function (k) {
  1024. utils.defineGetterSetter(newNavigator, key, function () {
  1025. return origNavigator[k];
  1026. });
  1027. })(key);
  1028. }
  1029. }
  1030. }
  1031. return newNavigator;
  1032. }
  1033. if (window.navigator) {
  1034. window.navigator = replaceNavigator(window.navigator);
  1035. }
  1036. if (!window.console) {
  1037. window.console = {
  1038. log: function () {}
  1039. };
  1040. }
  1041. if (!window.console.warn) {
  1042. window.console.warn = function (msg) {
  1043. this.log('warn: ' + msg);
  1044. };
  1045. }
  1046. // Register pause, resume and deviceready channels as events on document.
  1047. channel.onPause = cordova.addDocumentEventHandler('pause');
  1048. channel.onResume = cordova.addDocumentEventHandler('resume');
  1049. channel.onActivated = cordova.addDocumentEventHandler('activated');
  1050. channel.onDeviceReady = cordova.addStickyDocumentEventHandler('deviceready');
  1051. // Listen for DOMContentLoaded and notify our channel subscribers.
  1052. if (document.readyState === 'complete' || document.readyState === 'interactive') {
  1053. channel.onDOMContentLoaded.fire();
  1054. } else {
  1055. document.addEventListener('DOMContentLoaded', function () {
  1056. channel.onDOMContentLoaded.fire();
  1057. }, false);
  1058. }
  1059. // _nativeReady is global variable that the native side can set
  1060. // to signify that the native code is ready. It is a global since
  1061. // it may be called before any cordova JS is ready.
  1062. if (window._nativeReady) {
  1063. channel.onNativeReady.fire();
  1064. }
  1065. modulemapper.clobbers('cordova', 'cordova');
  1066. modulemapper.clobbers('cordova/exec', 'cordova.exec');
  1067. modulemapper.clobbers('cordova/exec', 'Cordova.exec');
  1068. // Call the platform-specific initialization.
  1069. platform.bootstrap && platform.bootstrap();
  1070. // Wrap in a setTimeout to support the use-case of having plugin JS appended to cordova.js.
  1071. // The delay allows the attached modules to be defined before the plugin loader looks for them.
  1072. setTimeout(function () {
  1073. pluginloader.load(function () {
  1074. channel.onPluginsReady.fire();
  1075. });
  1076. }, 0);
  1077. /**
  1078. * Create all cordova objects once native side is ready.
  1079. */
  1080. channel.join(function () {
  1081. modulemapper.mapModules(window);
  1082. platform.initialize && platform.initialize();
  1083. // Fire event to notify that all objects are created
  1084. channel.onCordovaReady.fire();
  1085. // Fire onDeviceReady event once page has fully loaded, all
  1086. // constructors have run and cordova info has been received from native
  1087. // side.
  1088. channel.join(function () {
  1089. require('cordova').fireDocumentEvent('deviceready');
  1090. }, channel.deviceReadyChannelsArray);
  1091. }, platformInitChannelsArray);
  1092. });
  1093. // file: src/common/init_b.js
  1094. define("cordova/init_b", function(require, exports, module) {
  1095. var channel = require('cordova/channel');
  1096. var cordova = require('cordova');
  1097. var modulemapper = require('cordova/modulemapper');
  1098. var platform = require('cordova/platform');
  1099. var pluginloader = require('cordova/pluginloader');
  1100. var utils = require('cordova/utils');
  1101. var platformInitChannelsArray = [channel.onDOMContentLoaded, channel.onNativeReady, channel.onPluginsReady];
  1102. // setting exec
  1103. cordova.exec = require('cordova/exec');
  1104. function logUnfiredChannels (arr) {
  1105. for (var i = 0; i < arr.length; ++i) {
  1106. if (arr[i].state !== 2) {
  1107. console.log('Channel not fired: ' + arr[i].type);
  1108. }
  1109. }
  1110. }
  1111. window.setTimeout(function () {
  1112. if (channel.onDeviceReady.state !== 2) {
  1113. console.log('deviceready has not fired after 5 seconds.');
  1114. logUnfiredChannels(platformInitChannelsArray);
  1115. logUnfiredChannels(channel.deviceReadyChannelsArray);
  1116. }
  1117. }, 5000);
  1118. // Replace navigator before any modules are required(), to ensure it happens as soon as possible.
  1119. // We replace it so that properties that can't be clobbered can instead be overridden.
  1120. function replaceNavigator (origNavigator) {
  1121. var CordovaNavigator = function () {};
  1122. CordovaNavigator.prototype = origNavigator;
  1123. var newNavigator = new CordovaNavigator();
  1124. // This work-around really only applies to new APIs that are newer than Function.bind.
  1125. // Without it, APIs such as getGamepads() break.
  1126. if (CordovaNavigator.bind) {
  1127. for (var key in origNavigator) {
  1128. if (typeof origNavigator[key] === 'function') {
  1129. newNavigator[key] = origNavigator[key].bind(origNavigator);
  1130. } else {
  1131. (function (k) {
  1132. utils.defineGetterSetter(newNavigator, key, function () {
  1133. return origNavigator[k];
  1134. });
  1135. })(key);
  1136. }
  1137. }
  1138. }
  1139. return newNavigator;
  1140. }
  1141. if (window.navigator) {
  1142. window.navigator = replaceNavigator(window.navigator);
  1143. }
  1144. if (!window.console) {
  1145. window.console = {
  1146. log: function () {}
  1147. };
  1148. }
  1149. if (!window.console.warn) {
  1150. window.console.warn = function (msg) {
  1151. this.log('warn: ' + msg);
  1152. };
  1153. }
  1154. // Register pause, resume and deviceready channels as events on document.
  1155. channel.onPause = cordova.addDocumentEventHandler('pause');
  1156. channel.onResume = cordova.addDocumentEventHandler('resume');
  1157. channel.onActivated = cordova.addDocumentEventHandler('activated');
  1158. channel.onDeviceReady = cordova.addStickyDocumentEventHandler('deviceready');
  1159. // Listen for DOMContentLoaded and notify our channel subscribers.
  1160. if (document.readyState === 'complete' || document.readyState === 'interactive') {
  1161. channel.onDOMContentLoaded.fire();
  1162. } else {
  1163. document.addEventListener('DOMContentLoaded', function () {
  1164. channel.onDOMContentLoaded.fire();
  1165. }, false);
  1166. }
  1167. // _nativeReady is global variable that the native side can set
  1168. // to signify that the native code is ready. It is a global since
  1169. // it may be called before any cordova JS is ready.
  1170. if (window._nativeReady) {
  1171. channel.onNativeReady.fire();
  1172. }
  1173. // Call the platform-specific initialization.
  1174. platform.bootstrap && platform.bootstrap();
  1175. // Wrap in a setTimeout to support the use-case of having plugin JS appended to cordova.js.
  1176. // The delay allows the attached modules to be defined before the plugin loader looks for them.
  1177. setTimeout(function () {
  1178. pluginloader.load(function () {
  1179. channel.onPluginsReady.fire();
  1180. });
  1181. }, 0);
  1182. /**
  1183. * Create all cordova objects once native side is ready.
  1184. */
  1185. channel.join(function () {
  1186. modulemapper.mapModules(window);
  1187. platform.initialize && platform.initialize();
  1188. // Fire event to notify that all objects are created
  1189. channel.onCordovaReady.fire();
  1190. // Fire onDeviceReady event once page has fully loaded, all
  1191. // constructors have run and cordova info has been received from native
  1192. // side.
  1193. channel.join(function () {
  1194. require('cordova').fireDocumentEvent('deviceready');
  1195. }, channel.deviceReadyChannelsArray);
  1196. }, platformInitChannelsArray);
  1197. });
  1198. // file: src/common/modulemapper.js
  1199. define("cordova/modulemapper", function(require, exports, module) {
  1200. var builder = require('cordova/builder');
  1201. var moduleMap = define.moduleMap; // eslint-disable-line no-undef
  1202. var symbolList;
  1203. var deprecationMap;
  1204. exports.reset = function () {
  1205. symbolList = [];
  1206. deprecationMap = {};
  1207. };
  1208. function addEntry (strategy, moduleName, symbolPath, opt_deprecationMessage) {
  1209. if (!(moduleName in moduleMap)) {
  1210. throw new Error('Module ' + moduleName + ' does not exist.');
  1211. }
  1212. symbolList.push(strategy, moduleName, symbolPath);
  1213. if (opt_deprecationMessage) {
  1214. deprecationMap[symbolPath] = opt_deprecationMessage;
  1215. }
  1216. }
  1217. // Note: Android 2.3 does have Function.bind().
  1218. exports.clobbers = function (moduleName, symbolPath, opt_deprecationMessage) {
  1219. addEntry('c', moduleName, symbolPath, opt_deprecationMessage);
  1220. };
  1221. exports.merges = function (moduleName, symbolPath, opt_deprecationMessage) {
  1222. addEntry('m', moduleName, symbolPath, opt_deprecationMessage);
  1223. };
  1224. exports.defaults = function (moduleName, symbolPath, opt_deprecationMessage) {
  1225. addEntry('d', moduleName, symbolPath, opt_deprecationMessage);
  1226. };
  1227. exports.runs = function (moduleName) {
  1228. addEntry('r', moduleName, null);
  1229. };
  1230. function prepareNamespace (symbolPath, context) {
  1231. if (!symbolPath) {
  1232. return context;
  1233. }
  1234. var parts = symbolPath.split('.');
  1235. var cur = context;
  1236. for (var i = 0, part; part = parts[i]; ++i) { // eslint-disable-line no-cond-assign
  1237. cur = cur[part] = cur[part] || {};
  1238. }
  1239. return cur;
  1240. }
  1241. exports.mapModules = function (context) {
  1242. var origSymbols = {};
  1243. context.CDV_origSymbols = origSymbols;
  1244. for (var i = 0, len = symbolList.length; i < len; i += 3) {
  1245. var strategy = symbolList[i];
  1246. var moduleName = symbolList[i + 1];
  1247. var module = require(moduleName);
  1248. // <runs/>
  1249. if (strategy === 'r') {
  1250. continue;
  1251. }
  1252. var symbolPath = symbolList[i + 2];
  1253. var lastDot = symbolPath.lastIndexOf('.');
  1254. var namespace = symbolPath.substr(0, lastDot);
  1255. var lastName = symbolPath.substr(lastDot + 1);
  1256. var deprecationMsg = symbolPath in deprecationMap ? 'Access made to deprecated symbol: ' + symbolPath + '. ' + deprecationMsg : null;
  1257. var parentObj = prepareNamespace(namespace, context);
  1258. var target = parentObj[lastName];
  1259. if (strategy === 'm' && target) {
  1260. builder.recursiveMerge(target, module);
  1261. } else if ((strategy === 'd' && !target) || (strategy !== 'd')) {
  1262. if (!(symbolPath in origSymbols)) {
  1263. origSymbols[symbolPath] = target;
  1264. }
  1265. builder.assignOrWrapInDeprecateGetter(parentObj, lastName, module, deprecationMsg);
  1266. }
  1267. }
  1268. };
  1269. exports.getOriginalSymbol = function (context, symbolPath) {
  1270. var origSymbols = context.CDV_origSymbols;
  1271. if (origSymbols && (symbolPath in origSymbols)) {
  1272. return origSymbols[symbolPath];
  1273. }
  1274. var parts = symbolPath.split('.');
  1275. var obj = context;
  1276. for (var i = 0; i < parts.length; ++i) {
  1277. obj = obj && obj[parts[i]];
  1278. }
  1279. return obj;
  1280. };
  1281. exports.reset();
  1282. });
  1283. // file: src/common/modulemapper_b.js
  1284. define("cordova/modulemapper_b", function(require, exports, module) {
  1285. var builder = require('cordova/builder');
  1286. var symbolList = [];
  1287. var deprecationMap;
  1288. exports.reset = function () {
  1289. symbolList = [];
  1290. deprecationMap = {};
  1291. };
  1292. function addEntry (strategy, moduleName, symbolPath, opt_deprecationMessage) {
  1293. symbolList.push(strategy, moduleName, symbolPath);
  1294. if (opt_deprecationMessage) {
  1295. deprecationMap[symbolPath] = opt_deprecationMessage;
  1296. }
  1297. }
  1298. // Note: Android 2.3 does have Function.bind().
  1299. exports.clobbers = function (moduleName, symbolPath, opt_deprecationMessage) {
  1300. addEntry('c', moduleName, symbolPath, opt_deprecationMessage);
  1301. };
  1302. exports.merges = function (moduleName, symbolPath, opt_deprecationMessage) {
  1303. addEntry('m', moduleName, symbolPath, opt_deprecationMessage);
  1304. };
  1305. exports.defaults = function (moduleName, symbolPath, opt_deprecationMessage) {
  1306. addEntry('d', moduleName, symbolPath, opt_deprecationMessage);
  1307. };
  1308. exports.runs = function (moduleName) {
  1309. addEntry('r', moduleName, null);
  1310. };
  1311. function prepareNamespace (symbolPath, context) {
  1312. if (!symbolPath) {
  1313. return context;
  1314. }
  1315. var parts = symbolPath.split('.');
  1316. var cur = context;
  1317. for (var i = 0, part; part = parts[i]; ++i) { // eslint-disable-line no-cond-assign
  1318. cur = cur[part] = cur[part] || {};
  1319. }
  1320. return cur;
  1321. }
  1322. exports.mapModules = function (context) {
  1323. var origSymbols = {};
  1324. context.CDV_origSymbols = origSymbols;
  1325. for (var i = 0, len = symbolList.length; i < len; i += 3) {
  1326. var strategy = symbolList[i];
  1327. var moduleName = symbolList[i + 1];
  1328. var module = require(moduleName);
  1329. // <runs/>
  1330. if (strategy === 'r') {
  1331. continue;
  1332. }
  1333. var symbolPath = symbolList[i + 2];
  1334. var lastDot = symbolPath.lastIndexOf('.');
  1335. var namespace = symbolPath.substr(0, lastDot);
  1336. var lastName = symbolPath.substr(lastDot + 1);
  1337. var deprecationMsg = symbolPath in deprecationMap ? 'Access made to deprecated symbol: ' + symbolPath + '. ' + deprecationMsg : null;
  1338. var parentObj = prepareNamespace(namespace, context);
  1339. var target = parentObj[lastName];
  1340. if (strategy === 'm' && target) {
  1341. builder.recursiveMerge(target, module);
  1342. } else if ((strategy === 'd' && !target) || (strategy !== 'd')) {
  1343. if (!(symbolPath in origSymbols)) {
  1344. origSymbols[symbolPath] = target;
  1345. }
  1346. builder.assignOrWrapInDeprecateGetter(parentObj, lastName, module, deprecationMsg);
  1347. }
  1348. }
  1349. };
  1350. exports.getOriginalSymbol = function (context, symbolPath) {
  1351. var origSymbols = context.CDV_origSymbols;
  1352. if (origSymbols && (symbolPath in origSymbols)) {
  1353. return origSymbols[symbolPath];
  1354. }
  1355. var parts = symbolPath.split('.');
  1356. var obj = context;
  1357. for (var i = 0; i < parts.length; ++i) {
  1358. obj = obj && obj[parts[i]];
  1359. }
  1360. return obj;
  1361. };
  1362. exports.reset();
  1363. });
  1364. // file: /Users/brodybits/Documents/cordova/cordova-ios/cordova-js-src/platform.js
  1365. define("cordova/platform", function(require, exports, module) {
  1366. module.exports = {
  1367. id: 'ios',
  1368. bootstrap: function () {
  1369. // Attach the console polyfill that is iOS-only to window.console
  1370. // see the file under plugin/ios/console.js
  1371. require('cordova/modulemapper').clobbers('cordova/plugin/ios/console', 'window.console');
  1372. require('cordova/channel').onNativeReady.fire();
  1373. }
  1374. };
  1375. });
  1376. // file: /Users/brodybits/Documents/cordova/cordova-ios/cordova-js-src/plugin/ios/console.js
  1377. define("cordova/plugin/ios/console", function(require, exports, module) {
  1378. //------------------------------------------------------------------------------
  1379. var logger = require('cordova/plugin/ios/logger');
  1380. //------------------------------------------------------------------------------
  1381. // object that we're exporting
  1382. //------------------------------------------------------------------------------
  1383. var console = module.exports;
  1384. //------------------------------------------------------------------------------
  1385. // copy of the original console object
  1386. //------------------------------------------------------------------------------
  1387. var WinConsole = window.console;
  1388. //------------------------------------------------------------------------------
  1389. // whether to use the logger
  1390. //------------------------------------------------------------------------------
  1391. var UseLogger = false;
  1392. //------------------------------------------------------------------------------
  1393. // Timers
  1394. //------------------------------------------------------------------------------
  1395. var Timers = {};
  1396. //------------------------------------------------------------------------------
  1397. // used for unimplemented methods
  1398. //------------------------------------------------------------------------------
  1399. function noop() {}
  1400. //------------------------------------------------------------------------------
  1401. // used for unimplemented methods
  1402. //------------------------------------------------------------------------------
  1403. console.useLogger = function (value) {
  1404. if (arguments.length) UseLogger = !!value;
  1405. if (UseLogger) {
  1406. if (logger.useConsole()) {
  1407. throw new Error("console and logger are too intertwingly");
  1408. }
  1409. }
  1410. return UseLogger;
  1411. };
  1412. //------------------------------------------------------------------------------
  1413. console.log = function() {
  1414. if (logger.useConsole()) return;
  1415. logger.log.apply(logger, [].slice.call(arguments));
  1416. };
  1417. //------------------------------------------------------------------------------
  1418. console.error = function() {
  1419. if (logger.useConsole()) return;
  1420. logger.error.apply(logger, [].slice.call(arguments));
  1421. };
  1422. //------------------------------------------------------------------------------
  1423. console.warn = function() {
  1424. if (logger.useConsole()) return;
  1425. logger.warn.apply(logger, [].slice.call(arguments));
  1426. };
  1427. //------------------------------------------------------------------------------
  1428. console.info = function() {
  1429. if (logger.useConsole()) return;
  1430. logger.info.apply(logger, [].slice.call(arguments));
  1431. };
  1432. //------------------------------------------------------------------------------
  1433. console.debug = function() {
  1434. if (logger.useConsole()) return;
  1435. logger.debug.apply(logger, [].slice.call(arguments));
  1436. };
  1437. //------------------------------------------------------------------------------
  1438. console.assert = function(expression) {
  1439. if (expression) return;
  1440. var message = logger.format.apply(logger.format, [].slice.call(arguments, 1));
  1441. console.log("ASSERT: " + message);
  1442. };
  1443. //------------------------------------------------------------------------------
  1444. console.clear = function() {};
  1445. //------------------------------------------------------------------------------
  1446. console.dir = function(object) {
  1447. console.log("%o", object);
  1448. };
  1449. //------------------------------------------------------------------------------
  1450. console.dirxml = function(node) {
  1451. console.log(node.innerHTML);
  1452. };
  1453. //------------------------------------------------------------------------------
  1454. console.trace = noop;
  1455. //------------------------------------------------------------------------------
  1456. console.group = console.log;
  1457. //------------------------------------------------------------------------------
  1458. console.groupCollapsed = console.log;
  1459. //------------------------------------------------------------------------------
  1460. console.groupEnd = noop;
  1461. //------------------------------------------------------------------------------
  1462. console.time = function(name) {
  1463. Timers[name] = new Date().valueOf();
  1464. };
  1465. //------------------------------------------------------------------------------
  1466. console.timeEnd = function(name) {
  1467. var timeStart = Timers[name];
  1468. if (!timeStart) {
  1469. console.warn("unknown timer: " + name);
  1470. return;
  1471. }
  1472. var timeElapsed = new Date().valueOf() - timeStart;
  1473. console.log(name + ": " + timeElapsed + "ms");
  1474. };
  1475. //------------------------------------------------------------------------------
  1476. console.timeStamp = noop;
  1477. //------------------------------------------------------------------------------
  1478. console.profile = noop;
  1479. //------------------------------------------------------------------------------
  1480. console.profileEnd = noop;
  1481. //------------------------------------------------------------------------------
  1482. console.count = noop;
  1483. //------------------------------------------------------------------------------
  1484. console.exception = console.log;
  1485. //------------------------------------------------------------------------------
  1486. console.table = function(data, columns) {
  1487. console.log("%o", data);
  1488. };
  1489. //------------------------------------------------------------------------------
  1490. // return a new function that calls both functions passed as args
  1491. //------------------------------------------------------------------------------
  1492. function wrappedOrigCall(orgFunc, newFunc) {
  1493. return function() {
  1494. var args = [].slice.call(arguments);
  1495. try { orgFunc.apply(WinConsole, args); } catch (e) {}
  1496. try { newFunc.apply(console, args); } catch (e) {}
  1497. };
  1498. }
  1499. //------------------------------------------------------------------------------
  1500. // For every function that exists in the original console object, that
  1501. // also exists in the new console object, wrap the new console method
  1502. // with one that calls both
  1503. //------------------------------------------------------------------------------
  1504. for (var key in console) {
  1505. if (typeof WinConsole[key] == "function") {
  1506. console[key] = wrappedOrigCall(WinConsole[key], console[key]);
  1507. }
  1508. }
  1509. });
  1510. // file: /Users/brodybits/Documents/cordova/cordova-ios/cordova-js-src/plugin/ios/logger.js
  1511. define("cordova/plugin/ios/logger", function(require, exports, module) {
  1512. //------------------------------------------------------------------------------
  1513. // The logger module exports the following properties/functions:
  1514. //
  1515. // LOG - constant for the level LOG
  1516. // ERROR - constant for the level ERROR
  1517. // WARN - constant for the level WARN
  1518. // INFO - constant for the level INFO
  1519. // DEBUG - constant for the level DEBUG
  1520. // logLevel() - returns current log level
  1521. // logLevel(value) - sets and returns a new log level
  1522. // useConsole() - returns whether logger is using console
  1523. // useConsole(value) - sets and returns whether logger is using console
  1524. // log(message,...) - logs a message at level LOG
  1525. // error(message,...) - logs a message at level ERROR
  1526. // warn(message,...) - logs a message at level WARN
  1527. // info(message,...) - logs a message at level INFO
  1528. // debug(message,...) - logs a message at level DEBUG
  1529. // logLevel(level,message,...) - logs a message specified level
  1530. //
  1531. //------------------------------------------------------------------------------
  1532. var logger = exports;
  1533. var exec = require('cordova/exec');
  1534. var UseConsole = false;
  1535. var UseLogger = true;
  1536. var Queued = [];
  1537. var DeviceReady = false;
  1538. var CurrentLevel;
  1539. var originalConsole = console;
  1540. /**
  1541. * Logging levels
  1542. */
  1543. var Levels = [
  1544. "LOG",
  1545. "ERROR",
  1546. "WARN",
  1547. "INFO",
  1548. "DEBUG"
  1549. ];
  1550. /*
  1551. * add the logging levels to the logger object and
  1552. * to a separate levelsMap object for testing
  1553. */
  1554. var LevelsMap = {};
  1555. for (var i=0; i<Levels.length; i++) {
  1556. var level = Levels[i];
  1557. LevelsMap[level] = i;
  1558. logger[level] = level;
  1559. }
  1560. CurrentLevel = LevelsMap.WARN;
  1561. /**
  1562. * Getter/Setter for the logging level
  1563. *
  1564. * Returns the current logging level.
  1565. *
  1566. * When a value is passed, sets the logging level to that value.
  1567. * The values should be one of the following constants:
  1568. * logger.LOG
  1569. * logger.ERROR
  1570. * logger.WARN
  1571. * logger.INFO
  1572. * logger.DEBUG
  1573. *
  1574. * The value used determines which messages get printed. The logging
  1575. * values above are in order, and only messages logged at the logging
  1576. * level or above will actually be displayed to the user. E.g., the
  1577. * default level is WARN, so only messages logged with LOG, ERROR, or
  1578. * WARN will be displayed; INFO and DEBUG messages will be ignored.
  1579. */
  1580. logger.level = function (value) {
  1581. if (arguments.length) {
  1582. if (LevelsMap[value] === null) {
  1583. throw new Error("invalid logging level: " + value);
  1584. }
  1585. CurrentLevel = LevelsMap[value];
  1586. }
  1587. return Levels[CurrentLevel];
  1588. };
  1589. /**
  1590. * Getter/Setter for the useConsole functionality
  1591. *
  1592. * When useConsole is true, the logger will log via the
  1593. * browser 'console' object.
  1594. */
  1595. logger.useConsole = function (value) {
  1596. if (arguments.length) UseConsole = !!value;
  1597. if (UseConsole) {
  1598. if (typeof console == "undefined") {
  1599. throw new Error("global console object is not defined");
  1600. }
  1601. if (typeof console.log != "function") {
  1602. throw new Error("global console object does not have a log function");
  1603. }
  1604. if (typeof console.useLogger == "function") {
  1605. if (console.useLogger()) {
  1606. throw new Error("console and logger are too intertwingly");
  1607. }
  1608. }
  1609. }
  1610. return UseConsole;
  1611. };
  1612. /**
  1613. * Getter/Setter for the useLogger functionality
  1614. *
  1615. * When useLogger is true, the logger will log via the
  1616. * native Logger plugin.
  1617. */
  1618. logger.useLogger = function (value) {
  1619. // Enforce boolean
  1620. if (arguments.length) UseLogger = !!value;
  1621. return UseLogger;
  1622. };
  1623. /**
  1624. * Logs a message at the LOG level.
  1625. *
  1626. * Parameters passed after message are used applied to
  1627. * the message with utils.format()
  1628. */
  1629. logger.log = function(message) { logWithArgs("LOG", arguments); };
  1630. /**
  1631. * Logs a message at the ERROR level.
  1632. *
  1633. * Parameters passed after message are used applied to
  1634. * the message with utils.format()
  1635. */
  1636. logger.error = function(message) { logWithArgs("ERROR", arguments); };
  1637. /**
  1638. * Logs a message at the WARN level.
  1639. *
  1640. * Parameters passed after message are used applied to
  1641. * the message with utils.format()
  1642. */
  1643. logger.warn = function(message) { logWithArgs("WARN", arguments); };
  1644. /**
  1645. * Logs a message at the INFO level.
  1646. *
  1647. * Parameters passed after message are used applied to
  1648. * the message with utils.format()
  1649. */
  1650. logger.info = function(message) { logWithArgs("INFO", arguments); };
  1651. /**
  1652. * Logs a message at the DEBUG level.
  1653. *
  1654. * Parameters passed after message are used applied to
  1655. * the message with utils.format()
  1656. */
  1657. logger.debug = function(message) { logWithArgs("DEBUG", arguments); };
  1658. // log at the specified level with args
  1659. function logWithArgs(level, args) {
  1660. args = [level].concat([].slice.call(args));
  1661. logger.logLevel.apply(logger, args);
  1662. }
  1663. // return the correct formatString for an object
  1664. function formatStringForMessage(message) {
  1665. return (typeof message === "string") ? "" : "%o";
  1666. }
  1667. /**
  1668. * Logs a message at the specified level.
  1669. *
  1670. * Parameters passed after message are used applied to
  1671. * the message with utils.format()
  1672. */
  1673. logger.logLevel = function(level /* , ... */) {
  1674. // format the message with the parameters
  1675. var formatArgs = [].slice.call(arguments, 1);
  1676. var fmtString = formatStringForMessage(formatArgs[0]);
  1677. if (fmtString.length > 0){
  1678. formatArgs.unshift(fmtString); // add formatString
  1679. }
  1680. var message = logger.format.apply(logger.format, formatArgs);
  1681. if (LevelsMap[level] === null) {
  1682. throw new Error("invalid logging level: " + level);
  1683. }
  1684. if (LevelsMap[level] > CurrentLevel) return;
  1685. // queue the message if not yet at deviceready
  1686. if (!DeviceReady && !UseConsole) {
  1687. Queued.push([level, message]);
  1688. return;
  1689. }
  1690. // Log using the native logger if that is enabled
  1691. if (UseLogger) {
  1692. exec(null, null, "Console", "logLevel", [level, message]);
  1693. }
  1694. // Log using the console if that is enabled
  1695. if (UseConsole) {
  1696. // make sure console is not using logger
  1697. if (console.useLogger()) {
  1698. throw new Error("console and logger are too intertwingly");
  1699. }
  1700. // log to the console
  1701. switch (level) {
  1702. case logger.LOG: originalConsole.log(message); break;
  1703. case logger.ERROR: originalConsole.log("ERROR: " + message); break;
  1704. case logger.WARN: originalConsole.log("WARN: " + message); break;
  1705. case logger.INFO: originalConsole.log("INFO: " + message); break;
  1706. case logger.DEBUG: originalConsole.log("DEBUG: " + message); break;
  1707. }
  1708. }
  1709. };
  1710. /**
  1711. * Formats a string and arguments following it ala console.log()
  1712. *
  1713. * Any remaining arguments will be appended to the formatted string.
  1714. *
  1715. * for rationale, see FireBug's Console API:
  1716. * http://getfirebug.com/wiki/index.php/Console_API
  1717. */
  1718. logger.format = function(formatString, args) {
  1719. return __format(arguments[0], [].slice.call(arguments,1)).join(' ');
  1720. };
  1721. //------------------------------------------------------------------------------
  1722. /**
  1723. * Formats a string and arguments following it ala vsprintf()
  1724. *
  1725. * format chars:
  1726. * %j - format arg as JSON
  1727. * %o - format arg as JSON
  1728. * %c - format arg as ''
  1729. * %% - replace with '%'
  1730. * any other char following % will format it's
  1731. * arg via toString().
  1732. *
  1733. * Returns an array containing the formatted string and any remaining
  1734. * arguments.
  1735. */
  1736. function __format(formatString, args) {
  1737. if (formatString === null || formatString === undefined) return [""];
  1738. if (arguments.length == 1) return [formatString.toString()];
  1739. if (typeof formatString != "string")
  1740. formatString = formatString.toString();
  1741. var pattern = /(.*?)%(.)(.*)/;
  1742. var rest = formatString;
  1743. var result = [];
  1744. while (args.length) {
  1745. var match = pattern.exec(rest);
  1746. if (!match) break;
  1747. var arg = args.shift();
  1748. rest = match[3];
  1749. result.push(match[1]);
  1750. if (match[2] == '%') {
  1751. result.push('%');
  1752. args.unshift(arg);
  1753. continue;
  1754. }
  1755. result.push(__formatted(arg, match[2]));
  1756. }
  1757. result.push(rest);
  1758. var remainingArgs = [].slice.call(args);
  1759. remainingArgs.unshift(result.join(''));
  1760. return remainingArgs;
  1761. }
  1762. function __formatted(object, formatChar) {
  1763. try {
  1764. switch(formatChar) {
  1765. case 'j':
  1766. case 'o': return JSON.stringify(object);
  1767. case 'c': return '';
  1768. }
  1769. }
  1770. catch (e) {
  1771. return "error JSON.stringify()ing argument: " + e;
  1772. }
  1773. if ((object === null) || (object === undefined)) {
  1774. return Object.prototype.toString.call(object);
  1775. }
  1776. return object.toString();
  1777. }
  1778. //------------------------------------------------------------------------------
  1779. // when deviceready fires, log queued messages
  1780. logger.__onDeviceReady = function() {
  1781. if (DeviceReady) return;
  1782. DeviceReady = true;
  1783. for (var i=0; i<Queued.length; i++) {
  1784. var messageArgs = Queued[i];
  1785. logger.logLevel(messageArgs[0], messageArgs[1]);
  1786. }
  1787. Queued = null;
  1788. };
  1789. // add a deviceready event to log queued messages
  1790. document.addEventListener("deviceready", logger.__onDeviceReady, false);
  1791. });
  1792. // file: src/common/pluginloader.js
  1793. define("cordova/pluginloader", function(require, exports, module) {
  1794. var modulemapper = require('cordova/modulemapper');
  1795. // Helper function to inject a <script> tag.
  1796. // Exported for testing.
  1797. exports.injectScript = function (url, onload, onerror) {
  1798. var script = document.createElement('script');
  1799. // onload fires even when script fails loads with an error.
  1800. script.onload = onload;
  1801. // onerror fires for malformed URLs.
  1802. script.onerror = onerror;
  1803. script.src = url;
  1804. document.head.appendChild(script);
  1805. };
  1806. function injectIfNecessary (id, url, onload, onerror) {
  1807. onerror = onerror || onload;
  1808. if (id in define.moduleMap) { // eslint-disable-line no-undef
  1809. onload();
  1810. } else {
  1811. exports.injectScript(url, function () {
  1812. if (id in define.moduleMap) { // eslint-disable-line no-undef
  1813. onload();
  1814. } else {
  1815. onerror();
  1816. }
  1817. }, onerror);
  1818. }
  1819. }
  1820. function onScriptLoadingComplete (moduleList, finishPluginLoading) {
  1821. // Loop through all the plugins and then through their clobbers and merges.
  1822. for (var i = 0, module; module = moduleList[i]; i++) { // eslint-disable-line no-cond-assign
  1823. if (module.clobbers && module.clobbers.length) {
  1824. for (var j = 0; j < module.clobbers.length; j++) {
  1825. modulemapper.clobbers(module.id, module.clobbers[j]);
  1826. }
  1827. }
  1828. if (module.merges && module.merges.length) {
  1829. for (var k = 0; k < module.merges.length; k++) {
  1830. modulemapper.merges(module.id, module.merges[k]);
  1831. }
  1832. }
  1833. // Finally, if runs is truthy we want to simply require() the module.
  1834. if (module.runs) {
  1835. modulemapper.runs(module.id);
  1836. }
  1837. }
  1838. finishPluginLoading();
  1839. }
  1840. // Handler for the cordova_plugins.js content.
  1841. // See plugman's plugin_loader.js for the details of this object.
  1842. // This function is only called if the really is a plugins array that isn't empty.
  1843. // Otherwise the onerror response handler will just call finishPluginLoading().
  1844. function handlePluginsObject (path, moduleList, finishPluginLoading) {
  1845. // Now inject the scripts.
  1846. var scriptCounter = moduleList.length;
  1847. if (!scriptCounter) {
  1848. finishPluginLoading();
  1849. return;
  1850. }
  1851. function scriptLoadedCallback () {
  1852. if (!--scriptCounter) {
  1853. onScriptLoadingComplete(moduleList, finishPluginLoading);
  1854. }
  1855. }
  1856. for (var i = 0; i < moduleList.length; i++) {
  1857. injectIfNecessary(moduleList[i].id, path + moduleList[i].file, scriptLoadedCallback);
  1858. }
  1859. }
  1860. function findCordovaPath () {
  1861. var path = null;
  1862. var scripts = document.getElementsByTagName('script');
  1863. var term = '/cordova.js';
  1864. for (var n = scripts.length - 1; n > -1; n--) {
  1865. var src = scripts[n].src.replace(/\?.*$/, ''); // Strip any query param (CB-6007).
  1866. if (src.indexOf(term) === (src.length - term.length)) {
  1867. path = src.substring(0, src.length - term.length) + '/';
  1868. break;
  1869. }
  1870. }
  1871. return path;
  1872. }
  1873. // Tries to load all plugins' js-modules.
  1874. // This is an async process, but onDeviceReady is blocked on onPluginsReady.
  1875. // onPluginsReady is fired when there are no plugins to load, or they are all done.
  1876. exports.load = function (callback) {
  1877. var pathPrefix = findCordovaPath();
  1878. if (pathPrefix === null) {
  1879. console.log('Could not find cordova.js script tag. Plugin loading may fail.');
  1880. pathPrefix = '';
  1881. }
  1882. injectIfNecessary('cordova/plugin_list', pathPrefix + 'cordova_plugins.js', function () {
  1883. var moduleList = require('cordova/plugin_list');
  1884. handlePluginsObject(pathPrefix, moduleList, callback);
  1885. }, callback);
  1886. };
  1887. });
  1888. // file: src/common/pluginloader_b.js
  1889. define("cordova/pluginloader_b", function(require, exports, module) {
  1890. var modulemapper = require('cordova/modulemapper');
  1891. // Handler for the cordova_plugins.js content.
  1892. // See plugman's plugin_loader.js for the details of this object.
  1893. function handlePluginsObject (moduleList) {
  1894. // if moduleList is not defined or empty, we've nothing to do
  1895. if (!moduleList || !moduleList.length) {
  1896. return;
  1897. }
  1898. // Loop through all the modules and then through their clobbers and merges.
  1899. for (var i = 0, module; module = moduleList[i]; i++) { // eslint-disable-line no-cond-assign
  1900. if (module.clobbers && module.clobbers.length) {
  1901. for (var j = 0; j < module.clobbers.length; j++) {
  1902. modulemapper.clobbers(module.id, module.clobbers[j]);
  1903. }
  1904. }
  1905. if (module.merges && module.merges.length) {
  1906. for (var k = 0; k < module.merges.length; k++) {
  1907. modulemapper.merges(module.id, module.merges[k]);
  1908. }
  1909. }
  1910. // Finally, if runs is truthy we want to simply require() the module.
  1911. if (module.runs) {
  1912. modulemapper.runs(module.id);
  1913. }
  1914. }
  1915. }
  1916. // Loads all plugins' js-modules. Plugin loading is syncronous in browserified bundle
  1917. // but the method accepts callback to be compatible with non-browserify flow.
  1918. // onDeviceReady is blocked on onPluginsReady. onPluginsReady is fired when there are
  1919. // no plugins to load, or they are all done.
  1920. exports.load = function (callback) {
  1921. var moduleList = require('cordova/plugin_list');
  1922. handlePluginsObject(moduleList);
  1923. callback();
  1924. };
  1925. });
  1926. // file: src/common/urlutil.js
  1927. define("cordova/urlutil", function(require, exports, module) {
  1928. /**
  1929. * For already absolute URLs, returns what is passed in.
  1930. * For relative URLs, converts them to absolute ones.
  1931. */
  1932. exports.makeAbsolute = function makeAbsolute (url) {
  1933. var anchorEl = document.createElement('a');
  1934. anchorEl.href = url;
  1935. return anchorEl.href;
  1936. };
  1937. });
  1938. // file: src/common/utils.js
  1939. define("cordova/utils", function(require, exports, module) {
  1940. var utils = exports;
  1941. /**
  1942. * Defines a property getter / setter for obj[key].
  1943. */
  1944. utils.defineGetterSetter = function (obj, key, getFunc, opt_setFunc) {
  1945. if (Object.defineProperty) {
  1946. var desc = {
  1947. get: getFunc,
  1948. configurable: true
  1949. };
  1950. if (opt_setFunc) {
  1951. desc.set = opt_setFunc;
  1952. }
  1953. Object.defineProperty(obj, key, desc);
  1954. } else {
  1955. obj.__defineGetter__(key, getFunc);
  1956. if (opt_setFunc) {
  1957. obj.__defineSetter__(key, opt_setFunc);
  1958. }
  1959. }
  1960. };
  1961. /**
  1962. * Defines a property getter for obj[key].
  1963. */
  1964. utils.defineGetter = utils.defineGetterSetter;
  1965. utils.arrayIndexOf = function (a, item) {
  1966. if (a.indexOf) {
  1967. return a.indexOf(item);
  1968. }
  1969. var len = a.length;
  1970. for (var i = 0; i < len; ++i) {
  1971. if (a[i] === item) {
  1972. return i;
  1973. }
  1974. }
  1975. return -1;
  1976. };
  1977. /**
  1978. * Returns whether the item was found in the array.
  1979. */
  1980. utils.arrayRemove = function (a, item) {
  1981. var index = utils.arrayIndexOf(a, item);
  1982. if (index !== -1) {
  1983. a.splice(index, 1);
  1984. }
  1985. return index !== -1;
  1986. };
  1987. utils.typeName = function (val) {
  1988. return Object.prototype.toString.call(val).slice(8, -1);
  1989. };
  1990. /**
  1991. * Returns an indication of whether the argument is an array or not
  1992. */
  1993. utils.isArray = Array.isArray ||
  1994. function (a) { return utils.typeName(a) === 'Array'; };
  1995. /**
  1996. * Returns an indication of whether the argument is a Date or not
  1997. */
  1998. utils.isDate = function (d) {
  1999. return (d instanceof Date);
  2000. };
  2001. /**
  2002. * Does a deep clone of the object.
  2003. */
  2004. utils.clone = function (obj) {
  2005. if (!obj || typeof obj === 'function' || utils.isDate(obj) || typeof obj !== 'object') {
  2006. return obj;
  2007. }
  2008. var retVal, i;
  2009. if (utils.isArray(obj)) {
  2010. retVal = [];
  2011. for (i = 0; i < obj.length; ++i) {
  2012. retVal.push(utils.clone(obj[i]));
  2013. }
  2014. return retVal;
  2015. }
  2016. retVal = {};
  2017. for (i in obj) {
  2018. // https://issues.apache.org/jira/browse/CB-11522 'unknown' type may be returned in
  2019. // custom protocol activation case on Windows Phone 8.1 causing "No such interface supported" exception
  2020. // on cloning.
  2021. if ((!(i in retVal) || retVal[i] !== obj[i]) && typeof obj[i] !== 'undefined' && typeof obj[i] !== 'unknown') { // eslint-disable-line valid-typeof
  2022. retVal[i] = utils.clone(obj[i]);
  2023. }
  2024. }
  2025. return retVal;
  2026. };
  2027. /**
  2028. * Returns a wrapped version of the function
  2029. */
  2030. utils.close = function (context, func, params) {
  2031. return function () {
  2032. var args = params || arguments;
  2033. return func.apply(context, args);
  2034. };
  2035. };
  2036. // ------------------------------------------------------------------------------
  2037. function UUIDcreatePart (length) {
  2038. var uuidpart = '';
  2039. for (var i = 0; i < length; i++) {
  2040. var uuidchar = parseInt((Math.random() * 256), 10).toString(16);
  2041. if (uuidchar.length === 1) {
  2042. uuidchar = '0' + uuidchar;
  2043. }
  2044. uuidpart += uuidchar;
  2045. }
  2046. return uuidpart;
  2047. }
  2048. /**
  2049. * Create a UUID
  2050. */
  2051. utils.createUUID = function () {
  2052. return UUIDcreatePart(4) + '-' +
  2053. UUIDcreatePart(2) + '-' +
  2054. UUIDcreatePart(2) + '-' +
  2055. UUIDcreatePart(2) + '-' +
  2056. UUIDcreatePart(6);
  2057. };
  2058. /**
  2059. * Extends a child object from a parent object using classical inheritance
  2060. * pattern.
  2061. */
  2062. utils.extend = (function () {
  2063. // proxy used to establish prototype chain
  2064. var F = function () {};
  2065. // extend Child from Parent
  2066. return function (Child, Parent) {
  2067. F.prototype = Parent.prototype;
  2068. Child.prototype = new F();
  2069. Child.__super__ = Parent.prototype;
  2070. Child.prototype.constructor = Child;
  2071. };
  2072. }());
  2073. /**
  2074. * Alerts a message in any available way: alert or console.log.
  2075. */
  2076. utils.alert = function (msg) {
  2077. if (window.alert) {
  2078. window.alert(msg);
  2079. } else if (console && console.log) {
  2080. console.log(msg);
  2081. }
  2082. };
  2083. });
  2084. window.cordova = require('cordova');
  2085. // file: src/scripts/bootstrap.js
  2086. require('cordova/init');
  2087. })();