cordova.js 59 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911
  1. // Platform: ios
  2. // 2fd4bcb84048415922d13d80d35b8d1668e8e150
  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.1.1';
  21. // file: src/scripts/require.js
  22. /*jshint -W079 */
  23. /*jshint -W020 */
  24. var require,
  25. define;
  26. (function () {
  27. var modules = {},
  28. // Stack of moduleIds currently being built.
  29. requireStack = [],
  30. // Map of module ID -> index into requireStack of modules currently being built.
  31. inProgressModules = {},
  32. SEPARATOR = ".";
  33. function build(module) {
  34. var factory = module.factory,
  35. 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)) {
  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. 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. var cordova = {
  155. define:define,
  156. require:require,
  157. version:PLATFORM_VERSION_BUILD_LABEL,
  158. platformVersion:PLATFORM_VERSION_BUILD_LABEL,
  159. platformId:platform.id,
  160. /**
  161. * Methods to add/remove your own addEventListener hijacking on document + window.
  162. */
  163. addWindowEventHandler:function(event) {
  164. return (windowEventHandlers[event] = channel.create(event));
  165. },
  166. addStickyDocumentEventHandler:function(event) {
  167. return (documentEventHandlers[event] = channel.createSticky(event));
  168. },
  169. addDocumentEventHandler:function(event) {
  170. return (documentEventHandlers[event] = channel.create(event));
  171. },
  172. removeWindowEventHandler:function(event) {
  173. delete windowEventHandlers[event];
  174. },
  175. removeDocumentEventHandler:function(event) {
  176. delete documentEventHandlers[event];
  177. },
  178. /**
  179. * Retrieve original event handlers that were replaced by Cordova
  180. *
  181. * @return object
  182. */
  183. getOriginalHandlers: function() {
  184. return {'document': {'addEventListener': m_document_addEventListener, 'removeEventListener': m_document_removeEventListener},
  185. 'window': {'addEventListener': m_window_addEventListener, 'removeEventListener': m_window_removeEventListener}};
  186. },
  187. /**
  188. * Method to fire event from native code
  189. * bNoDetach is required for events which cause an exception which needs to be caught in native code
  190. */
  191. fireDocumentEvent: function(type, data, bNoDetach) {
  192. var evt = createEvent(type, data);
  193. if (typeof documentEventHandlers[type] != 'undefined') {
  194. if( bNoDetach ) {
  195. documentEventHandlers[type].fire(evt);
  196. }
  197. else {
  198. setTimeout(function() {
  199. // Fire deviceready on listeners that were registered before cordova.js was loaded.
  200. if (type == 'deviceready') {
  201. document.dispatchEvent(evt);
  202. }
  203. documentEventHandlers[type].fire(evt);
  204. }, 0);
  205. }
  206. } else {
  207. document.dispatchEvent(evt);
  208. }
  209. },
  210. fireWindowEvent: function(type, data) {
  211. var evt = createEvent(type,data);
  212. if (typeof windowEventHandlers[type] != 'undefined') {
  213. setTimeout(function() {
  214. windowEventHandlers[type].fire(evt);
  215. }, 0);
  216. } else {
  217. window.dispatchEvent(evt);
  218. }
  219. },
  220. /**
  221. * Plugin callback mechanism.
  222. */
  223. // Randomize the starting callbackId to avoid collisions after refreshing or navigating.
  224. // This way, it's very unlikely that any new callback would get the same callbackId as an old callback.
  225. callbackId: Math.floor(Math.random() * 2000000000),
  226. callbacks: {},
  227. callbackStatus: {
  228. NO_RESULT: 0,
  229. OK: 1,
  230. CLASS_NOT_FOUND_EXCEPTION: 2,
  231. ILLEGAL_ACCESS_EXCEPTION: 3,
  232. INSTANTIATION_EXCEPTION: 4,
  233. MALFORMED_URL_EXCEPTION: 5,
  234. IO_EXCEPTION: 6,
  235. INVALID_ACTION: 7,
  236. JSON_EXCEPTION: 8,
  237. ERROR: 9
  238. },
  239. /**
  240. * Called by native code when returning successful result from an action.
  241. */
  242. callbackSuccess: function(callbackId, args) {
  243. cordova.callbackFromNative(callbackId, true, args.status, [args.message], args.keepCallback);
  244. },
  245. /**
  246. * Called by native code when returning error result from an action.
  247. */
  248. callbackError: function(callbackId, args) {
  249. // TODO: Deprecate callbackSuccess and callbackError in favour of callbackFromNative.
  250. // Derive success from status.
  251. cordova.callbackFromNative(callbackId, false, args.status, [args.message], args.keepCallback);
  252. },
  253. /**
  254. * Called by native code when returning the result from an action.
  255. */
  256. callbackFromNative: function(callbackId, isSuccess, status, args, keepCallback) {
  257. try {
  258. var callback = cordova.callbacks[callbackId];
  259. if (callback) {
  260. if (isSuccess && status == cordova.callbackStatus.OK) {
  261. callback.success && callback.success.apply(null, args);
  262. } else if (!isSuccess) {
  263. callback.fail && callback.fail.apply(null, args);
  264. }
  265. /*
  266. else
  267. Note, this case is intentionally not caught.
  268. this can happen if isSuccess is true, but callbackStatus is NO_RESULT
  269. which is used to remove a callback from the list without calling the callbacks
  270. typically keepCallback is false in this case
  271. */
  272. // Clear callback if not expecting any more results
  273. if (!keepCallback) {
  274. delete cordova.callbacks[callbackId];
  275. }
  276. }
  277. }
  278. catch (err) {
  279. var msg = "Error in " + (isSuccess ? "Success" : "Error") + " callbackId: " + callbackId + " : " + err;
  280. console && console.log && console.log(msg);
  281. cordova.fireWindowEvent("cordovacallbackerror", { 'message': msg });
  282. throw err;
  283. }
  284. },
  285. addConstructor: function(func) {
  286. channel.onCordovaReady.subscribe(function() {
  287. try {
  288. func();
  289. } catch(e) {
  290. console.log("Failed to run constructor: " + e);
  291. }
  292. });
  293. }
  294. };
  295. module.exports = cordova;
  296. });
  297. // file: src/common/argscheck.js
  298. define("cordova/argscheck", function(require, exports, module) {
  299. var utils = require('cordova/utils');
  300. var moduleExports = module.exports;
  301. var typeMap = {
  302. 'A': 'Array',
  303. 'D': 'Date',
  304. 'N': 'Number',
  305. 'S': 'String',
  306. 'F': 'Function',
  307. 'O': 'Object'
  308. };
  309. function extractParamName(callee, argIndex) {
  310. return (/.*?\((.*?)\)/).exec(callee)[1].split(', ')[argIndex];
  311. }
  312. function checkArgs(spec, functionName, args, opt_callee) {
  313. if (!moduleExports.enableChecks) {
  314. return;
  315. }
  316. var errMsg = null;
  317. var typeName;
  318. for (var i = 0; i < spec.length; ++i) {
  319. var c = spec.charAt(i),
  320. cUpper = c.toUpperCase(),
  321. arg = args[i];
  322. // Asterix means allow anything.
  323. if (c == '*') {
  324. continue;
  325. }
  326. typeName = utils.typeName(arg);
  327. if ((arg === null || arg === undefined) && c == cUpper) {
  328. continue;
  329. }
  330. if (typeName != typeMap[cUpper]) {
  331. errMsg = 'Expected ' + typeMap[cUpper];
  332. break;
  333. }
  334. }
  335. if (errMsg) {
  336. errMsg += ', but got ' + typeName + '.';
  337. errMsg = 'Wrong type for parameter "' + extractParamName(opt_callee || args.callee, i) + '" of ' + functionName + ': ' + errMsg;
  338. // Don't log when running unit tests.
  339. if (typeof jasmine == 'undefined') {
  340. console.error(errMsg);
  341. }
  342. throw TypeError(errMsg);
  343. }
  344. }
  345. function getValue(value, defaultValue) {
  346. return value === undefined ? defaultValue : value;
  347. }
  348. moduleExports.checkArgs = checkArgs;
  349. moduleExports.getValue = getValue;
  350. moduleExports.enableChecks = true;
  351. });
  352. // file: src/common/base64.js
  353. define("cordova/base64", function(require, exports, module) {
  354. var base64 = exports;
  355. base64.fromArrayBuffer = function(arrayBuffer) {
  356. var array = new Uint8Array(arrayBuffer);
  357. return uint8ToBase64(array);
  358. };
  359. base64.toArrayBuffer = function(str) {
  360. var decodedStr = typeof atob != 'undefined' ? atob(str) : new Buffer(str,'base64').toString('binary');
  361. var arrayBuffer = new ArrayBuffer(decodedStr.length);
  362. var array = new Uint8Array(arrayBuffer);
  363. for (var i=0, len=decodedStr.length; i < len; i++) {
  364. array[i] = decodedStr.charCodeAt(i);
  365. }
  366. return arrayBuffer;
  367. };
  368. //------------------------------------------------------------------------------
  369. /* This code is based on the performance tests at http://jsperf.com/b64tests
  370. * This 12-bit-at-a-time algorithm was the best performing version on all
  371. * platforms tested.
  372. */
  373. var b64_6bit = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
  374. var b64_12bit;
  375. var b64_12bitTable = function() {
  376. b64_12bit = [];
  377. for (var i=0; i<64; i++) {
  378. for (var j=0; j<64; j++) {
  379. b64_12bit[i*64+j] = b64_6bit[i] + b64_6bit[j];
  380. }
  381. }
  382. b64_12bitTable = function() { return b64_12bit; };
  383. return b64_12bit;
  384. };
  385. function uint8ToBase64(rawData) {
  386. var numBytes = rawData.byteLength;
  387. var output="";
  388. var segment;
  389. var table = b64_12bitTable();
  390. for (var i=0;i<numBytes-2;i+=3) {
  391. segment = (rawData[i] << 16) + (rawData[i+1] << 8) + rawData[i+2];
  392. output += table[segment >> 12];
  393. output += table[segment & 0xfff];
  394. }
  395. if (numBytes - i == 2) {
  396. segment = (rawData[i] << 16) + (rawData[i+1] << 8);
  397. output += table[segment >> 12];
  398. output += b64_6bit[(segment & 0xfff) >> 6];
  399. output += '=';
  400. } else if (numBytes - i == 1) {
  401. segment = (rawData[i] << 16);
  402. output += table[segment >> 12];
  403. output += '==';
  404. }
  405. return output;
  406. }
  407. });
  408. // file: src/common/builder.js
  409. define("cordova/builder", function(require, exports, module) {
  410. var utils = require('cordova/utils');
  411. function each(objects, func, context) {
  412. for (var prop in objects) {
  413. if (objects.hasOwnProperty(prop)) {
  414. func.apply(context, [objects[prop], prop]);
  415. }
  416. }
  417. }
  418. function clobber(obj, key, value) {
  419. exports.replaceHookForTesting(obj, key);
  420. var needsProperty = false;
  421. try {
  422. obj[key] = value;
  423. } catch (e) {
  424. needsProperty = true;
  425. }
  426. // Getters can only be overridden by getters.
  427. if (needsProperty || obj[key] !== value) {
  428. utils.defineGetter(obj, key, function() {
  429. return value;
  430. });
  431. }
  432. }
  433. function assignOrWrapInDeprecateGetter(obj, key, value, message) {
  434. if (message) {
  435. utils.defineGetter(obj, key, function() {
  436. console.log(message);
  437. delete obj[key];
  438. clobber(obj, key, value);
  439. return value;
  440. });
  441. } else {
  442. clobber(obj, key, value);
  443. }
  444. }
  445. function include(parent, objects, clobber, merge) {
  446. each(objects, function (obj, key) {
  447. try {
  448. var result = obj.path ? require(obj.path) : {};
  449. if (clobber) {
  450. // Clobber if it doesn't exist.
  451. if (typeof parent[key] === 'undefined') {
  452. assignOrWrapInDeprecateGetter(parent, key, result, obj.deprecated);
  453. } else if (typeof obj.path !== 'undefined') {
  454. // If merging, merge properties onto parent, otherwise, clobber.
  455. if (merge) {
  456. recursiveMerge(parent[key], result);
  457. } else {
  458. assignOrWrapInDeprecateGetter(parent, key, result, obj.deprecated);
  459. }
  460. }
  461. result = parent[key];
  462. } else {
  463. // Overwrite if not currently defined.
  464. if (typeof parent[key] == 'undefined') {
  465. assignOrWrapInDeprecateGetter(parent, key, result, obj.deprecated);
  466. } else {
  467. // Set result to what already exists, so we can build children into it if they exist.
  468. result = parent[key];
  469. }
  470. }
  471. if (obj.children) {
  472. include(result, obj.children, clobber, merge);
  473. }
  474. } catch(e) {
  475. utils.alert('Exception building Cordova JS globals: ' + e + ' for key "' + key + '"');
  476. }
  477. });
  478. }
  479. /**
  480. * Merge properties from one object onto another recursively. Properties from
  481. * the src object will overwrite existing target property.
  482. *
  483. * @param target Object to merge properties into.
  484. * @param src Object to merge properties from.
  485. */
  486. function recursiveMerge(target, src) {
  487. for (var prop in src) {
  488. if (src.hasOwnProperty(prop)) {
  489. if (target.prototype && target.prototype.constructor === target) {
  490. // If the target object is a constructor override off prototype.
  491. clobber(target.prototype, prop, src[prop]);
  492. } else {
  493. if (typeof src[prop] === 'object' && typeof target[prop] === 'object') {
  494. recursiveMerge(target[prop], src[prop]);
  495. } else {
  496. clobber(target, prop, src[prop]);
  497. }
  498. }
  499. }
  500. }
  501. }
  502. exports.buildIntoButDoNotClobber = function(objects, target) {
  503. include(target, objects, false, false);
  504. };
  505. exports.buildIntoAndClobber = function(objects, target) {
  506. include(target, objects, true, false);
  507. };
  508. exports.buildIntoAndMerge = function(objects, target) {
  509. include(target, objects, true, true);
  510. };
  511. exports.recursiveMerge = recursiveMerge;
  512. exports.assignOrWrapInDeprecateGetter = assignOrWrapInDeprecateGetter;
  513. exports.replaceHookForTesting = function() {};
  514. });
  515. // file: src/common/channel.js
  516. define("cordova/channel", function(require, exports, module) {
  517. var utils = require('cordova/utils'),
  518. nextGuid = 1;
  519. /**
  520. * Custom pub-sub "channel" that can have functions subscribed to it
  521. * This object is used to define and control firing of events for
  522. * cordova initialization, as well as for custom events thereafter.
  523. *
  524. * The order of events during page load and Cordova startup is as follows:
  525. *
  526. * onDOMContentLoaded* Internal event that is received when the web page is loaded and parsed.
  527. * onNativeReady* Internal event that indicates the Cordova native side is ready.
  528. * onCordovaReady* Internal event fired when all Cordova JavaScript objects have been created.
  529. * onDeviceReady* User event fired to indicate that Cordova is ready
  530. * onResume User event fired to indicate a start/resume lifecycle event
  531. * onPause User event fired to indicate a pause lifecycle event
  532. *
  533. * The events marked with an * are sticky. Once they have fired, they will stay in the fired state.
  534. * All listeners that subscribe after the event is fired will be executed right away.
  535. *
  536. * The only Cordova events that user code should register for are:
  537. * deviceready Cordova native code is initialized and Cordova APIs can be called from JavaScript
  538. * pause App has moved to background
  539. * resume App has returned to foreground
  540. *
  541. * Listeners can be registered as:
  542. * document.addEventListener("deviceready", myDeviceReadyListener, false);
  543. * document.addEventListener("resume", myResumeListener, false);
  544. * document.addEventListener("pause", myPauseListener, false);
  545. *
  546. * The DOM lifecycle events should be used for saving and restoring state
  547. * window.onload
  548. * window.onunload
  549. *
  550. */
  551. /**
  552. * Channel
  553. * @constructor
  554. * @param type String the channel name
  555. */
  556. var Channel = function(type, sticky) {
  557. this.type = type;
  558. // Map of guid -> function.
  559. this.handlers = {};
  560. // 0 = Non-sticky, 1 = Sticky non-fired, 2 = Sticky fired.
  561. this.state = sticky ? 1 : 0;
  562. // Used in sticky mode to remember args passed to fire().
  563. this.fireArgs = null;
  564. // Used by onHasSubscribersChange to know if there are any listeners.
  565. this.numHandlers = 0;
  566. // Function that is called when the first listener is subscribed, or when
  567. // the last listener is unsubscribed.
  568. this.onHasSubscribersChange = null;
  569. },
  570. channel = {
  571. /**
  572. * Calls the provided function only after all of the channels specified
  573. * have been fired. All channels must be sticky channels.
  574. */
  575. join: function(h, c) {
  576. var len = c.length,
  577. i = len,
  578. f = function() {
  579. if (!(--i)) h();
  580. };
  581. for (var j=0; j<len; j++) {
  582. if (c[j].state === 0) {
  583. throw Error('Can only use join with sticky channels.');
  584. }
  585. c[j].subscribe(f);
  586. }
  587. if (!len) h();
  588. },
  589. create: function(type) {
  590. return channel[type] = new Channel(type, false);
  591. },
  592. createSticky: function(type) {
  593. return channel[type] = new Channel(type, true);
  594. },
  595. /**
  596. * cordova Channels that must fire before "deviceready" is fired.
  597. */
  598. deviceReadyChannelsArray: [],
  599. deviceReadyChannelsMap: {},
  600. /**
  601. * Indicate that a feature needs to be initialized before it is ready to be used.
  602. * This holds up Cordova's "deviceready" event until the feature has been initialized
  603. * and Cordova.initComplete(feature) is called.
  604. *
  605. * @param feature {String} The unique feature name
  606. */
  607. waitForInitialization: function(feature) {
  608. if (feature) {
  609. var c = channel[feature] || this.createSticky(feature);
  610. this.deviceReadyChannelsMap[feature] = c;
  611. this.deviceReadyChannelsArray.push(c);
  612. }
  613. },
  614. /**
  615. * Indicate that initialization code has completed and the feature is ready to be used.
  616. *
  617. * @param feature {String} The unique feature name
  618. */
  619. initializationComplete: function(feature) {
  620. var c = this.deviceReadyChannelsMap[feature];
  621. if (c) {
  622. c.fire();
  623. }
  624. }
  625. };
  626. function forceFunction(f) {
  627. if (typeof f != 'function') throw "Function required as first argument!";
  628. }
  629. /**
  630. * Subscribes the given function to the channel. Any time that
  631. * Channel.fire is called so too will the function.
  632. * Optionally specify an execution context for the function
  633. * and a guid that can be used to stop subscribing to the channel.
  634. * Returns the guid.
  635. */
  636. Channel.prototype.subscribe = function(f, c) {
  637. // need a function to call
  638. forceFunction(f);
  639. if (this.state == 2) {
  640. f.apply(c || this, this.fireArgs);
  641. return;
  642. }
  643. var func = f,
  644. guid = f.observer_guid;
  645. if (typeof c == "object") { func = utils.close(c, f); }
  646. if (!guid) {
  647. // first time any channel has seen this subscriber
  648. guid = '' + nextGuid++;
  649. }
  650. func.observer_guid = guid;
  651. f.observer_guid = guid;
  652. // Don't add the same handler more than once.
  653. if (!this.handlers[guid]) {
  654. this.handlers[guid] = func;
  655. this.numHandlers++;
  656. if (this.numHandlers == 1) {
  657. this.onHasSubscribersChange && this.onHasSubscribersChange();
  658. }
  659. }
  660. };
  661. /**
  662. * Unsubscribes the function with the given guid from the channel.
  663. */
  664. Channel.prototype.unsubscribe = function(f) {
  665. // need a function to unsubscribe
  666. forceFunction(f);
  667. var guid = f.observer_guid,
  668. handler = this.handlers[guid];
  669. if (handler) {
  670. delete this.handlers[guid];
  671. this.numHandlers--;
  672. if (this.numHandlers === 0) {
  673. this.onHasSubscribersChange && this.onHasSubscribersChange();
  674. }
  675. }
  676. };
  677. /**
  678. * Calls all functions subscribed to this channel.
  679. */
  680. Channel.prototype.fire = function(e) {
  681. var fail = false,
  682. fireArgs = Array.prototype.slice.call(arguments);
  683. // Apply stickiness.
  684. if (this.state == 1) {
  685. this.state = 2;
  686. this.fireArgs = fireArgs;
  687. }
  688. if (this.numHandlers) {
  689. // Copy the values first so that it is safe to modify it from within
  690. // callbacks.
  691. var toCall = [];
  692. for (var item in this.handlers) {
  693. toCall.push(this.handlers[item]);
  694. }
  695. for (var i = 0; i < toCall.length; ++i) {
  696. toCall[i].apply(this, fireArgs);
  697. }
  698. if (this.state == 2 && this.numHandlers) {
  699. this.numHandlers = 0;
  700. this.handlers = {};
  701. this.onHasSubscribersChange && this.onHasSubscribersChange();
  702. }
  703. }
  704. };
  705. // defining them here so they are ready super fast!
  706. // DOM event that is received when the web page is loaded and parsed.
  707. channel.createSticky('onDOMContentLoaded');
  708. // Event to indicate the Cordova native side is ready.
  709. channel.createSticky('onNativeReady');
  710. // Event to indicate that all Cordova JavaScript objects have been created
  711. // and it's time to run plugin constructors.
  712. channel.createSticky('onCordovaReady');
  713. // Event to indicate that all automatically loaded JS plugins are loaded and ready.
  714. // FIXME remove this
  715. channel.createSticky('onPluginsReady');
  716. // Event to indicate that Cordova is ready
  717. channel.createSticky('onDeviceReady');
  718. // Event to indicate a resume lifecycle event
  719. channel.create('onResume');
  720. // Event to indicate a pause lifecycle event
  721. channel.create('onPause');
  722. // Channels that must fire before "deviceready" is fired.
  723. channel.waitForInitialization('onCordovaReady');
  724. channel.waitForInitialization('onDOMContentLoaded');
  725. module.exports = channel;
  726. });
  727. // file: /Users/ednamorales/dev/apache_plugins/cordova-ios/cordova-js-src/exec.js
  728. define("cordova/exec", function(require, exports, module) {
  729. /*global require, module, atob, document */
  730. /**
  731. * Creates a gap bridge iframe used to notify the native code about queued
  732. * commands.
  733. */
  734. var cordova = require('cordova'),
  735. utils = require('cordova/utils'),
  736. base64 = require('cordova/base64'),
  737. execIframe,
  738. commandQueue = [], // Contains pending JS->Native messages.
  739. isInContextOfEvalJs = 0,
  740. failSafeTimerId = 0;
  741. function massageArgsJsToNative(args) {
  742. if (!args || utils.typeName(args) != 'Array') {
  743. return args;
  744. }
  745. var ret = [];
  746. args.forEach(function(arg, i) {
  747. if (utils.typeName(arg) == 'ArrayBuffer') {
  748. ret.push({
  749. 'CDVType': 'ArrayBuffer',
  750. 'data': base64.fromArrayBuffer(arg)
  751. });
  752. } else {
  753. ret.push(arg);
  754. }
  755. });
  756. return ret;
  757. }
  758. function massageMessageNativeToJs(message) {
  759. if (message.CDVType == 'ArrayBuffer') {
  760. var stringToArrayBuffer = function(str) {
  761. var ret = new Uint8Array(str.length);
  762. for (var i = 0; i < str.length; i++) {
  763. ret[i] = str.charCodeAt(i);
  764. }
  765. return ret.buffer;
  766. };
  767. var base64ToArrayBuffer = function(b64) {
  768. return stringToArrayBuffer(atob(b64));
  769. };
  770. message = base64ToArrayBuffer(message.data);
  771. }
  772. return message;
  773. }
  774. function convertMessageToArgsNativeToJs(message) {
  775. var args = [];
  776. if (!message || !message.hasOwnProperty('CDVType')) {
  777. args.push(message);
  778. } else if (message.CDVType == 'MultiPart') {
  779. message.messages.forEach(function(e) {
  780. args.push(massageMessageNativeToJs(e));
  781. });
  782. } else {
  783. args.push(massageMessageNativeToJs(message));
  784. }
  785. return args;
  786. }
  787. function iOSExec() {
  788. var successCallback, failCallback, service, action, actionArgs;
  789. var callbackId = null;
  790. if (typeof arguments[0] !== 'string') {
  791. // FORMAT ONE
  792. successCallback = arguments[0];
  793. failCallback = arguments[1];
  794. service = arguments[2];
  795. action = arguments[3];
  796. actionArgs = arguments[4];
  797. // Since we need to maintain backwards compatibility, we have to pass
  798. // an invalid callbackId even if no callback was provided since plugins
  799. // will be expecting it. The Cordova.exec() implementation allocates
  800. // an invalid callbackId and passes it even if no callbacks were given.
  801. callbackId = 'INVALID';
  802. } else {
  803. throw new Error('The old format of this exec call has been removed (deprecated since 2.1). Change to: ' +
  804. 'cordova.exec(null, null, \'Service\', \'action\', [ arg1, arg2 ]);'
  805. );
  806. }
  807. // If actionArgs is not provided, default to an empty array
  808. actionArgs = actionArgs || [];
  809. // Register the callbacks and add the callbackId to the positional
  810. // arguments if given.
  811. if (successCallback || failCallback) {
  812. callbackId = service + cordova.callbackId++;
  813. cordova.callbacks[callbackId] =
  814. {success:successCallback, fail:failCallback};
  815. }
  816. actionArgs = massageArgsJsToNative(actionArgs);
  817. var command = [callbackId, service, action, actionArgs];
  818. // Stringify and queue the command. We stringify to command now to
  819. // effectively clone the command arguments in case they are mutated before
  820. // the command is executed.
  821. commandQueue.push(JSON.stringify(command));
  822. // If we're in the context of a stringByEvaluatingJavaScriptFromString call,
  823. // then the queue will be flushed when it returns; no need for a poke.
  824. // Also, if there is already a command in the queue, then we've already
  825. // poked the native side, so there is no reason to do so again.
  826. if (!isInContextOfEvalJs && commandQueue.length == 1) {
  827. pokeNative();
  828. }
  829. }
  830. // CB-10530
  831. function proxyChanged() {
  832. var cexec = cordovaExec();
  833. return (execProxy !== cexec && // proxy objects are different
  834. iOSExec !== cexec // proxy object is not the current iOSExec
  835. );
  836. }
  837. // CB-10106
  838. function handleBridgeChange() {
  839. if (proxyChanged()) {
  840. var commandString = commandQueue.shift();
  841. while(commandString) {
  842. var command = JSON.parse(commandString);
  843. var callbackId = command[0];
  844. var service = command[1];
  845. var action = command[2];
  846. var actionArgs = command[3];
  847. var callbacks = cordova.callbacks[callbackId] || {};
  848. execProxy(callbacks.success, callbacks.fail, service, action, actionArgs);
  849. commandString = commandQueue.shift();
  850. };
  851. return true;
  852. }
  853. return false;
  854. }
  855. function pokeNative() {
  856. // CB-5488 - Don't attempt to create iframe before document.body is available.
  857. if (!document.body) {
  858. setTimeout(pokeNative);
  859. return;
  860. }
  861. // Check if they've removed it from the DOM, and put it back if so.
  862. if (execIframe && execIframe.contentWindow) {
  863. execIframe.contentWindow.location = 'gap://ready';
  864. } else {
  865. execIframe = document.createElement('iframe');
  866. execIframe.style.display = 'none';
  867. execIframe.src = 'gap://ready';
  868. document.body.appendChild(execIframe);
  869. }
  870. // Use a timer to protect against iframe being unloaded during the poke (CB-7735).
  871. // This makes the bridge ~ 7% slower, but works around the poke getting lost
  872. // when the iframe is removed from the DOM.
  873. // An onunload listener could be used in the case where the iframe has just been
  874. // created, but since unload events fire only once, it doesn't work in the normal
  875. // case of iframe reuse (where unload will have already fired due to the attempted
  876. // navigation of the page).
  877. failSafeTimerId = setTimeout(function() {
  878. if (commandQueue.length) {
  879. // CB-10106 - flush the queue on bridge change
  880. if (!handleBridgeChange()) {
  881. pokeNative();
  882. }
  883. }
  884. }, 50); // Making this > 0 improves performance (marginally) in the normal case (where it doesn't fire).
  885. }
  886. iOSExec.nativeFetchMessages = function() {
  887. // Stop listing for window detatch once native side confirms poke.
  888. if (failSafeTimerId) {
  889. clearTimeout(failSafeTimerId);
  890. failSafeTimerId = 0;
  891. }
  892. // Each entry in commandQueue is a JSON string already.
  893. if (!commandQueue.length) {
  894. return '';
  895. }
  896. var json = '[' + commandQueue.join(',') + ']';
  897. commandQueue.length = 0;
  898. return json;
  899. };
  900. iOSExec.nativeCallback = function(callbackId, status, message, keepCallback, debug) {
  901. return iOSExec.nativeEvalAndFetch(function() {
  902. var success = status === 0 || status === 1;
  903. var args = convertMessageToArgsNativeToJs(message);
  904. function nc2() {
  905. cordova.callbackFromNative(callbackId, success, status, args, keepCallback);
  906. }
  907. setTimeout(nc2, 0);
  908. });
  909. };
  910. iOSExec.nativeEvalAndFetch = function(func) {
  911. // This shouldn't be nested, but better to be safe.
  912. isInContextOfEvalJs++;
  913. try {
  914. func();
  915. return iOSExec.nativeFetchMessages();
  916. } finally {
  917. isInContextOfEvalJs--;
  918. }
  919. };
  920. // Proxy the exec for bridge changes. See CB-10106
  921. function cordovaExec() {
  922. var cexec = require('cordova/exec');
  923. var cexec_valid = (typeof cexec.nativeFetchMessages === 'function') && (typeof cexec.nativeEvalAndFetch === 'function') && (typeof cexec.nativeCallback === 'function');
  924. return (cexec_valid && execProxy !== cexec)? cexec : iOSExec;
  925. }
  926. function execProxy() {
  927. cordovaExec().apply(null, arguments);
  928. };
  929. execProxy.nativeFetchMessages = function() {
  930. return cordovaExec().nativeFetchMessages.apply(null, arguments);
  931. };
  932. execProxy.nativeEvalAndFetch = function() {
  933. return cordovaExec().nativeEvalAndFetch.apply(null, arguments);
  934. };
  935. execProxy.nativeCallback = function() {
  936. return cordovaExec().nativeCallback.apply(null, arguments);
  937. };
  938. module.exports = execProxy;
  939. });
  940. // file: src/common/exec/proxy.js
  941. define("cordova/exec/proxy", function(require, exports, module) {
  942. // internal map of proxy function
  943. var CommandProxyMap = {};
  944. module.exports = {
  945. // example: cordova.commandProxy.add("Accelerometer",{getCurrentAcceleration: function(successCallback, errorCallback, options) {...},...);
  946. add:function(id,proxyObj) {
  947. console.log("adding proxy for " + id);
  948. CommandProxyMap[id] = proxyObj;
  949. return proxyObj;
  950. },
  951. // cordova.commandProxy.remove("Accelerometer");
  952. remove:function(id) {
  953. var proxy = CommandProxyMap[id];
  954. delete CommandProxyMap[id];
  955. CommandProxyMap[id] = null;
  956. return proxy;
  957. },
  958. get:function(service,action) {
  959. return ( CommandProxyMap[service] ? CommandProxyMap[service][action] : null );
  960. }
  961. };
  962. });
  963. // file: src/common/init.js
  964. define("cordova/init", function(require, exports, module) {
  965. var channel = require('cordova/channel');
  966. var cordova = require('cordova');
  967. var modulemapper = require('cordova/modulemapper');
  968. var platform = require('cordova/platform');
  969. var pluginloader = require('cordova/pluginloader');
  970. var utils = require('cordova/utils');
  971. var platformInitChannelsArray = [channel.onNativeReady, channel.onPluginsReady];
  972. function logUnfiredChannels(arr) {
  973. for (var i = 0; i < arr.length; ++i) {
  974. if (arr[i].state != 2) {
  975. console.log('Channel not fired: ' + arr[i].type);
  976. }
  977. }
  978. }
  979. window.setTimeout(function() {
  980. if (channel.onDeviceReady.state != 2) {
  981. console.log('deviceready has not fired after 5 seconds.');
  982. logUnfiredChannels(platformInitChannelsArray);
  983. logUnfiredChannels(channel.deviceReadyChannelsArray);
  984. }
  985. }, 5000);
  986. // Replace navigator before any modules are required(), to ensure it happens as soon as possible.
  987. // We replace it so that properties that can't be clobbered can instead be overridden.
  988. function replaceNavigator(origNavigator) {
  989. var CordovaNavigator = function() {};
  990. CordovaNavigator.prototype = origNavigator;
  991. var newNavigator = new CordovaNavigator();
  992. // This work-around really only applies to new APIs that are newer than Function.bind.
  993. // Without it, APIs such as getGamepads() break.
  994. if (CordovaNavigator.bind) {
  995. for (var key in origNavigator) {
  996. if (typeof origNavigator[key] == 'function') {
  997. newNavigator[key] = origNavigator[key].bind(origNavigator);
  998. }
  999. else {
  1000. (function(k) {
  1001. utils.defineGetterSetter(newNavigator,key,function() {
  1002. return origNavigator[k];
  1003. });
  1004. })(key);
  1005. }
  1006. }
  1007. }
  1008. return newNavigator;
  1009. }
  1010. if (window.navigator) {
  1011. window.navigator = replaceNavigator(window.navigator);
  1012. }
  1013. if (!window.console) {
  1014. window.console = {
  1015. log: function(){}
  1016. };
  1017. }
  1018. if (!window.console.warn) {
  1019. window.console.warn = function(msg) {
  1020. this.log("warn: " + msg);
  1021. };
  1022. }
  1023. // Register pause, resume and deviceready channels as events on document.
  1024. channel.onPause = cordova.addDocumentEventHandler('pause');
  1025. channel.onResume = cordova.addDocumentEventHandler('resume');
  1026. channel.onActivated = cordova.addDocumentEventHandler('activated');
  1027. channel.onDeviceReady = cordova.addStickyDocumentEventHandler('deviceready');
  1028. // Listen for DOMContentLoaded and notify our channel subscribers.
  1029. if (document.readyState == 'complete' || document.readyState == 'interactive') {
  1030. channel.onDOMContentLoaded.fire();
  1031. } else {
  1032. document.addEventListener('DOMContentLoaded', function() {
  1033. channel.onDOMContentLoaded.fire();
  1034. }, false);
  1035. }
  1036. // _nativeReady is global variable that the native side can set
  1037. // to signify that the native code is ready. It is a global since
  1038. // it may be called before any cordova JS is ready.
  1039. if (window._nativeReady) {
  1040. channel.onNativeReady.fire();
  1041. }
  1042. modulemapper.clobbers('cordova', 'cordova');
  1043. modulemapper.clobbers('cordova/exec', 'cordova.exec');
  1044. modulemapper.clobbers('cordova/exec', 'Cordova.exec');
  1045. // Call the platform-specific initialization.
  1046. platform.bootstrap && platform.bootstrap();
  1047. // Wrap in a setTimeout to support the use-case of having plugin JS appended to cordova.js.
  1048. // The delay allows the attached modules to be defined before the plugin loader looks for them.
  1049. setTimeout(function() {
  1050. pluginloader.load(function() {
  1051. channel.onPluginsReady.fire();
  1052. });
  1053. }, 0);
  1054. /**
  1055. * Create all cordova objects once native side is ready.
  1056. */
  1057. channel.join(function() {
  1058. modulemapper.mapModules(window);
  1059. platform.initialize && platform.initialize();
  1060. // Fire event to notify that all objects are created
  1061. channel.onCordovaReady.fire();
  1062. // Fire onDeviceReady event once page has fully loaded, all
  1063. // constructors have run and cordova info has been received from native
  1064. // side.
  1065. channel.join(function() {
  1066. require('cordova').fireDocumentEvent('deviceready');
  1067. }, channel.deviceReadyChannelsArray);
  1068. }, platformInitChannelsArray);
  1069. });
  1070. // file: src/common/init_b.js
  1071. define("cordova/init_b", function(require, exports, module) {
  1072. var channel = require('cordova/channel');
  1073. var cordova = require('cordova');
  1074. var modulemapper = require('cordova/modulemapper');
  1075. var platform = require('cordova/platform');
  1076. var pluginloader = require('cordova/pluginloader');
  1077. var utils = require('cordova/utils');
  1078. var platformInitChannelsArray = [channel.onDOMContentLoaded, channel.onNativeReady, channel.onPluginsReady];
  1079. // setting exec
  1080. cordova.exec = require('cordova/exec');
  1081. function logUnfiredChannels(arr) {
  1082. for (var i = 0; i < arr.length; ++i) {
  1083. if (arr[i].state != 2) {
  1084. console.log('Channel not fired: ' + arr[i].type);
  1085. }
  1086. }
  1087. }
  1088. window.setTimeout(function() {
  1089. if (channel.onDeviceReady.state != 2) {
  1090. console.log('deviceready has not fired after 5 seconds.');
  1091. logUnfiredChannels(platformInitChannelsArray);
  1092. logUnfiredChannels(channel.deviceReadyChannelsArray);
  1093. }
  1094. }, 5000);
  1095. // Replace navigator before any modules are required(), to ensure it happens as soon as possible.
  1096. // We replace it so that properties that can't be clobbered can instead be overridden.
  1097. function replaceNavigator(origNavigator) {
  1098. var CordovaNavigator = function() {};
  1099. CordovaNavigator.prototype = origNavigator;
  1100. var newNavigator = new CordovaNavigator();
  1101. // This work-around really only applies to new APIs that are newer than Function.bind.
  1102. // Without it, APIs such as getGamepads() break.
  1103. if (CordovaNavigator.bind) {
  1104. for (var key in origNavigator) {
  1105. if (typeof origNavigator[key] == 'function') {
  1106. newNavigator[key] = origNavigator[key].bind(origNavigator);
  1107. }
  1108. else {
  1109. (function(k) {
  1110. utils.defineGetterSetter(newNavigator,key,function() {
  1111. return origNavigator[k];
  1112. });
  1113. })(key);
  1114. }
  1115. }
  1116. }
  1117. return newNavigator;
  1118. }
  1119. if (window.navigator) {
  1120. window.navigator = replaceNavigator(window.navigator);
  1121. }
  1122. if (!window.console) {
  1123. window.console = {
  1124. log: function(){}
  1125. };
  1126. }
  1127. if (!window.console.warn) {
  1128. window.console.warn = function(msg) {
  1129. this.log("warn: " + msg);
  1130. };
  1131. }
  1132. // Register pause, resume and deviceready channels as events on document.
  1133. channel.onPause = cordova.addDocumentEventHandler('pause');
  1134. channel.onResume = cordova.addDocumentEventHandler('resume');
  1135. channel.onActivated = cordova.addDocumentEventHandler('activated');
  1136. channel.onDeviceReady = cordova.addStickyDocumentEventHandler('deviceready');
  1137. // Listen for DOMContentLoaded and notify our channel subscribers.
  1138. if (document.readyState == 'complete' || document.readyState == 'interactive') {
  1139. channel.onDOMContentLoaded.fire();
  1140. } else {
  1141. document.addEventListener('DOMContentLoaded', function() {
  1142. channel.onDOMContentLoaded.fire();
  1143. }, false);
  1144. }
  1145. // _nativeReady is global variable that the native side can set
  1146. // to signify that the native code is ready. It is a global since
  1147. // it may be called before any cordova JS is ready.
  1148. if (window._nativeReady) {
  1149. channel.onNativeReady.fire();
  1150. }
  1151. // Call the platform-specific initialization.
  1152. platform.bootstrap && platform.bootstrap();
  1153. // Wrap in a setTimeout to support the use-case of having plugin JS appended to cordova.js.
  1154. // The delay allows the attached modules to be defined before the plugin loader looks for them.
  1155. setTimeout(function() {
  1156. pluginloader.load(function() {
  1157. channel.onPluginsReady.fire();
  1158. });
  1159. }, 0);
  1160. /**
  1161. * Create all cordova objects once native side is ready.
  1162. */
  1163. channel.join(function() {
  1164. modulemapper.mapModules(window);
  1165. platform.initialize && platform.initialize();
  1166. // Fire event to notify that all objects are created
  1167. channel.onCordovaReady.fire();
  1168. // Fire onDeviceReady event once page has fully loaded, all
  1169. // constructors have run and cordova info has been received from native
  1170. // side.
  1171. channel.join(function() {
  1172. require('cordova').fireDocumentEvent('deviceready');
  1173. }, channel.deviceReadyChannelsArray);
  1174. }, platformInitChannelsArray);
  1175. });
  1176. // file: src/common/modulemapper.js
  1177. define("cordova/modulemapper", function(require, exports, module) {
  1178. var builder = require('cordova/builder'),
  1179. moduleMap = define.moduleMap,
  1180. symbolList,
  1181. deprecationMap;
  1182. exports.reset = function() {
  1183. symbolList = [];
  1184. deprecationMap = {};
  1185. };
  1186. function addEntry(strategy, moduleName, symbolPath, opt_deprecationMessage) {
  1187. if (!(moduleName in moduleMap)) {
  1188. throw new Error('Module ' + moduleName + ' does not exist.');
  1189. }
  1190. symbolList.push(strategy, moduleName, symbolPath);
  1191. if (opt_deprecationMessage) {
  1192. deprecationMap[symbolPath] = opt_deprecationMessage;
  1193. }
  1194. }
  1195. // Note: Android 2.3 does have Function.bind().
  1196. exports.clobbers = function(moduleName, symbolPath, opt_deprecationMessage) {
  1197. addEntry('c', moduleName, symbolPath, opt_deprecationMessage);
  1198. };
  1199. exports.merges = function(moduleName, symbolPath, opt_deprecationMessage) {
  1200. addEntry('m', moduleName, symbolPath, opt_deprecationMessage);
  1201. };
  1202. exports.defaults = function(moduleName, symbolPath, opt_deprecationMessage) {
  1203. addEntry('d', moduleName, symbolPath, opt_deprecationMessage);
  1204. };
  1205. exports.runs = function(moduleName) {
  1206. addEntry('r', moduleName, null);
  1207. };
  1208. function prepareNamespace(symbolPath, context) {
  1209. if (!symbolPath) {
  1210. return context;
  1211. }
  1212. var parts = symbolPath.split('.');
  1213. var cur = context;
  1214. for (var i = 0, part; part = parts[i]; ++i) {
  1215. cur = cur[part] = cur[part] || {};
  1216. }
  1217. return cur;
  1218. }
  1219. exports.mapModules = function(context) {
  1220. var origSymbols = {};
  1221. context.CDV_origSymbols = origSymbols;
  1222. for (var i = 0, len = symbolList.length; i < len; i += 3) {
  1223. var strategy = symbolList[i];
  1224. var moduleName = symbolList[i + 1];
  1225. var module = require(moduleName);
  1226. // <runs/>
  1227. if (strategy == 'r') {
  1228. continue;
  1229. }
  1230. var symbolPath = symbolList[i + 2];
  1231. var lastDot = symbolPath.lastIndexOf('.');
  1232. var namespace = symbolPath.substr(0, lastDot);
  1233. var lastName = symbolPath.substr(lastDot + 1);
  1234. var deprecationMsg = symbolPath in deprecationMap ? 'Access made to deprecated symbol: ' + symbolPath + '. ' + deprecationMsg : null;
  1235. var parentObj = prepareNamespace(namespace, context);
  1236. var target = parentObj[lastName];
  1237. if (strategy == 'm' && target) {
  1238. builder.recursiveMerge(target, module);
  1239. } else if ((strategy == 'd' && !target) || (strategy != 'd')) {
  1240. if (!(symbolPath in origSymbols)) {
  1241. origSymbols[symbolPath] = target;
  1242. }
  1243. builder.assignOrWrapInDeprecateGetter(parentObj, lastName, module, deprecationMsg);
  1244. }
  1245. }
  1246. };
  1247. exports.getOriginalSymbol = function(context, symbolPath) {
  1248. var origSymbols = context.CDV_origSymbols;
  1249. if (origSymbols && (symbolPath in origSymbols)) {
  1250. return origSymbols[symbolPath];
  1251. }
  1252. var parts = symbolPath.split('.');
  1253. var obj = context;
  1254. for (var i = 0; i < parts.length; ++i) {
  1255. obj = obj && obj[parts[i]];
  1256. }
  1257. return obj;
  1258. };
  1259. exports.reset();
  1260. });
  1261. // file: src/common/modulemapper_b.js
  1262. define("cordova/modulemapper_b", function(require, exports, module) {
  1263. var builder = require('cordova/builder'),
  1264. symbolList = [],
  1265. deprecationMap;
  1266. exports.reset = function() {
  1267. symbolList = [];
  1268. deprecationMap = {};
  1269. };
  1270. function addEntry(strategy, moduleName, symbolPath, opt_deprecationMessage) {
  1271. symbolList.push(strategy, moduleName, symbolPath);
  1272. if (opt_deprecationMessage) {
  1273. deprecationMap[symbolPath] = opt_deprecationMessage;
  1274. }
  1275. }
  1276. // Note: Android 2.3 does have Function.bind().
  1277. exports.clobbers = function(moduleName, symbolPath, opt_deprecationMessage) {
  1278. addEntry('c', moduleName, symbolPath, opt_deprecationMessage);
  1279. };
  1280. exports.merges = function(moduleName, symbolPath, opt_deprecationMessage) {
  1281. addEntry('m', moduleName, symbolPath, opt_deprecationMessage);
  1282. };
  1283. exports.defaults = function(moduleName, symbolPath, opt_deprecationMessage) {
  1284. addEntry('d', moduleName, symbolPath, opt_deprecationMessage);
  1285. };
  1286. exports.runs = function(moduleName) {
  1287. addEntry('r', moduleName, null);
  1288. };
  1289. function prepareNamespace(symbolPath, context) {
  1290. if (!symbolPath) {
  1291. return context;
  1292. }
  1293. var parts = symbolPath.split('.');
  1294. var cur = context;
  1295. for (var i = 0, part; part = parts[i]; ++i) {
  1296. cur = cur[part] = cur[part] || {};
  1297. }
  1298. return cur;
  1299. }
  1300. exports.mapModules = function(context) {
  1301. var origSymbols = {};
  1302. context.CDV_origSymbols = origSymbols;
  1303. for (var i = 0, len = symbolList.length; i < len; i += 3) {
  1304. var strategy = symbolList[i];
  1305. var moduleName = symbolList[i + 1];
  1306. var module = require(moduleName);
  1307. // <runs/>
  1308. if (strategy == 'r') {
  1309. continue;
  1310. }
  1311. var symbolPath = symbolList[i + 2];
  1312. var lastDot = symbolPath.lastIndexOf('.');
  1313. var namespace = symbolPath.substr(0, lastDot);
  1314. var lastName = symbolPath.substr(lastDot + 1);
  1315. var deprecationMsg = symbolPath in deprecationMap ? 'Access made to deprecated symbol: ' + symbolPath + '. ' + deprecationMsg : null;
  1316. var parentObj = prepareNamespace(namespace, context);
  1317. var target = parentObj[lastName];
  1318. if (strategy == 'm' && target) {
  1319. builder.recursiveMerge(target, module);
  1320. } else if ((strategy == 'd' && !target) || (strategy != 'd')) {
  1321. if (!(symbolPath in origSymbols)) {
  1322. origSymbols[symbolPath] = target;
  1323. }
  1324. builder.assignOrWrapInDeprecateGetter(parentObj, lastName, module, deprecationMsg);
  1325. }
  1326. }
  1327. };
  1328. exports.getOriginalSymbol = function(context, symbolPath) {
  1329. var origSymbols = context.CDV_origSymbols;
  1330. if (origSymbols && (symbolPath in origSymbols)) {
  1331. return origSymbols[symbolPath];
  1332. }
  1333. var parts = symbolPath.split('.');
  1334. var obj = context;
  1335. for (var i = 0; i < parts.length; ++i) {
  1336. obj = obj && obj[parts[i]];
  1337. }
  1338. return obj;
  1339. };
  1340. exports.reset();
  1341. });
  1342. // file: /Users/ednamorales/dev/apache_plugins/cordova-ios/cordova-js-src/platform.js
  1343. define("cordova/platform", function(require, exports, module) {
  1344. module.exports = {
  1345. id: 'ios',
  1346. bootstrap: function() {
  1347. require('cordova/channel').onNativeReady.fire();
  1348. }
  1349. };
  1350. });
  1351. // file: src/common/pluginloader.js
  1352. define("cordova/pluginloader", function(require, exports, module) {
  1353. var modulemapper = require('cordova/modulemapper');
  1354. var urlutil = require('cordova/urlutil');
  1355. // Helper function to inject a <script> tag.
  1356. // Exported for testing.
  1357. exports.injectScript = function(url, onload, onerror) {
  1358. var script = document.createElement("script");
  1359. // onload fires even when script fails loads with an error.
  1360. script.onload = onload;
  1361. // onerror fires for malformed URLs.
  1362. script.onerror = onerror;
  1363. script.src = url;
  1364. document.head.appendChild(script);
  1365. };
  1366. function injectIfNecessary(id, url, onload, onerror) {
  1367. onerror = onerror || onload;
  1368. if (id in define.moduleMap) {
  1369. onload();
  1370. } else {
  1371. exports.injectScript(url, function() {
  1372. if (id in define.moduleMap) {
  1373. onload();
  1374. } else {
  1375. onerror();
  1376. }
  1377. }, onerror);
  1378. }
  1379. }
  1380. function onScriptLoadingComplete(moduleList, finishPluginLoading) {
  1381. // Loop through all the plugins and then through their clobbers and merges.
  1382. for (var i = 0, module; module = moduleList[i]; i++) {
  1383. if (module.clobbers && module.clobbers.length) {
  1384. for (var j = 0; j < module.clobbers.length; j++) {
  1385. modulemapper.clobbers(module.id, module.clobbers[j]);
  1386. }
  1387. }
  1388. if (module.merges && module.merges.length) {
  1389. for (var k = 0; k < module.merges.length; k++) {
  1390. modulemapper.merges(module.id, module.merges[k]);
  1391. }
  1392. }
  1393. // Finally, if runs is truthy we want to simply require() the module.
  1394. if (module.runs) {
  1395. modulemapper.runs(module.id);
  1396. }
  1397. }
  1398. finishPluginLoading();
  1399. }
  1400. // Handler for the cordova_plugins.js content.
  1401. // See plugman's plugin_loader.js for the details of this object.
  1402. // This function is only called if the really is a plugins array that isn't empty.
  1403. // Otherwise the onerror response handler will just call finishPluginLoading().
  1404. function handlePluginsObject(path, moduleList, finishPluginLoading) {
  1405. // Now inject the scripts.
  1406. var scriptCounter = moduleList.length;
  1407. if (!scriptCounter) {
  1408. finishPluginLoading();
  1409. return;
  1410. }
  1411. function scriptLoadedCallback() {
  1412. if (!--scriptCounter) {
  1413. onScriptLoadingComplete(moduleList, finishPluginLoading);
  1414. }
  1415. }
  1416. for (var i = 0; i < moduleList.length; i++) {
  1417. injectIfNecessary(moduleList[i].id, path + moduleList[i].file, scriptLoadedCallback);
  1418. }
  1419. }
  1420. function findCordovaPath() {
  1421. var path = null;
  1422. var scripts = document.getElementsByTagName('script');
  1423. var term = '/cordova.js';
  1424. for (var n = scripts.length-1; n>-1; n--) {
  1425. var src = scripts[n].src.replace(/\?.*$/, ''); // Strip any query param (CB-6007).
  1426. if (src.indexOf(term) == (src.length - term.length)) {
  1427. path = src.substring(0, src.length - term.length) + '/';
  1428. break;
  1429. }
  1430. }
  1431. return path;
  1432. }
  1433. // Tries to load all plugins' js-modules.
  1434. // This is an async process, but onDeviceReady is blocked on onPluginsReady.
  1435. // onPluginsReady is fired when there are no plugins to load, or they are all done.
  1436. exports.load = function(callback) {
  1437. var pathPrefix = findCordovaPath();
  1438. if (pathPrefix === null) {
  1439. console.log('Could not find cordova.js script tag. Plugin loading may fail.');
  1440. pathPrefix = '';
  1441. }
  1442. injectIfNecessary('cordova/plugin_list', pathPrefix + 'cordova_plugins.js', function() {
  1443. var moduleList = require("cordova/plugin_list");
  1444. handlePluginsObject(pathPrefix, moduleList, callback);
  1445. }, callback);
  1446. };
  1447. });
  1448. // file: src/common/pluginloader_b.js
  1449. define("cordova/pluginloader_b", function(require, exports, module) {
  1450. var modulemapper = require('cordova/modulemapper');
  1451. // Handler for the cordova_plugins.js content.
  1452. // See plugman's plugin_loader.js for the details of this object.
  1453. function handlePluginsObject(moduleList) {
  1454. // if moduleList is not defined or empty, we've nothing to do
  1455. if (!moduleList || !moduleList.length) {
  1456. return;
  1457. }
  1458. // Loop through all the modules and then through their clobbers and merges.
  1459. for (var i = 0, module; module = moduleList[i]; i++) {
  1460. if (module.clobbers && module.clobbers.length) {
  1461. for (var j = 0; j < module.clobbers.length; j++) {
  1462. modulemapper.clobbers(module.id, module.clobbers[j]);
  1463. }
  1464. }
  1465. if (module.merges && module.merges.length) {
  1466. for (var k = 0; k < module.merges.length; k++) {
  1467. modulemapper.merges(module.id, module.merges[k]);
  1468. }
  1469. }
  1470. // Finally, if runs is truthy we want to simply require() the module.
  1471. if (module.runs) {
  1472. modulemapper.runs(module.id);
  1473. }
  1474. }
  1475. }
  1476. // Loads all plugins' js-modules. Plugin loading is syncronous in browserified bundle
  1477. // but the method accepts callback to be compatible with non-browserify flow.
  1478. // onDeviceReady is blocked on onPluginsReady. onPluginsReady is fired when there are
  1479. // no plugins to load, or they are all done.
  1480. exports.load = function(callback) {
  1481. var moduleList = require("cordova/plugin_list");
  1482. handlePluginsObject(moduleList);
  1483. callback();
  1484. };
  1485. });
  1486. // file: src/common/urlutil.js
  1487. define("cordova/urlutil", function(require, exports, module) {
  1488. /**
  1489. * For already absolute URLs, returns what is passed in.
  1490. * For relative URLs, converts them to absolute ones.
  1491. */
  1492. exports.makeAbsolute = function makeAbsolute(url) {
  1493. var anchorEl = document.createElement('a');
  1494. anchorEl.href = url;
  1495. return anchorEl.href;
  1496. };
  1497. });
  1498. // file: src/common/utils.js
  1499. define("cordova/utils", function(require, exports, module) {
  1500. var utils = exports;
  1501. /**
  1502. * Defines a property getter / setter for obj[key].
  1503. */
  1504. utils.defineGetterSetter = function(obj, key, getFunc, opt_setFunc) {
  1505. if (Object.defineProperty) {
  1506. var desc = {
  1507. get: getFunc,
  1508. configurable: true
  1509. };
  1510. if (opt_setFunc) {
  1511. desc.set = opt_setFunc;
  1512. }
  1513. Object.defineProperty(obj, key, desc);
  1514. } else {
  1515. obj.__defineGetter__(key, getFunc);
  1516. if (opt_setFunc) {
  1517. obj.__defineSetter__(key, opt_setFunc);
  1518. }
  1519. }
  1520. };
  1521. /**
  1522. * Defines a property getter for obj[key].
  1523. */
  1524. utils.defineGetter = utils.defineGetterSetter;
  1525. utils.arrayIndexOf = function(a, item) {
  1526. if (a.indexOf) {
  1527. return a.indexOf(item);
  1528. }
  1529. var len = a.length;
  1530. for (var i = 0; i < len; ++i) {
  1531. if (a[i] == item) {
  1532. return i;
  1533. }
  1534. }
  1535. return -1;
  1536. };
  1537. /**
  1538. * Returns whether the item was found in the array.
  1539. */
  1540. utils.arrayRemove = function(a, item) {
  1541. var index = utils.arrayIndexOf(a, item);
  1542. if (index != -1) {
  1543. a.splice(index, 1);
  1544. }
  1545. return index != -1;
  1546. };
  1547. utils.typeName = function(val) {
  1548. return Object.prototype.toString.call(val).slice(8, -1);
  1549. };
  1550. /**
  1551. * Returns an indication of whether the argument is an array or not
  1552. */
  1553. utils.isArray = Array.isArray ||
  1554. function(a) {return utils.typeName(a) == 'Array';};
  1555. /**
  1556. * Returns an indication of whether the argument is a Date or not
  1557. */
  1558. utils.isDate = function(d) {
  1559. return (d instanceof Date);
  1560. };
  1561. /**
  1562. * Does a deep clone of the object.
  1563. */
  1564. utils.clone = function(obj) {
  1565. if(!obj || typeof obj == 'function' || utils.isDate(obj) || typeof obj != 'object') {
  1566. return obj;
  1567. }
  1568. var retVal, i;
  1569. if(utils.isArray(obj)){
  1570. retVal = [];
  1571. for(i = 0; i < obj.length; ++i){
  1572. retVal.push(utils.clone(obj[i]));
  1573. }
  1574. return retVal;
  1575. }
  1576. retVal = {};
  1577. for(i in obj){
  1578. if(!(i in retVal) || retVal[i] != obj[i]) {
  1579. retVal[i] = utils.clone(obj[i]);
  1580. }
  1581. }
  1582. return retVal;
  1583. };
  1584. /**
  1585. * Returns a wrapped version of the function
  1586. */
  1587. utils.close = function(context, func, params) {
  1588. return function() {
  1589. var args = params || arguments;
  1590. return func.apply(context, args);
  1591. };
  1592. };
  1593. //------------------------------------------------------------------------------
  1594. function UUIDcreatePart(length) {
  1595. var uuidpart = "";
  1596. for (var i=0; i<length; i++) {
  1597. var uuidchar = parseInt((Math.random() * 256), 10).toString(16);
  1598. if (uuidchar.length == 1) {
  1599. uuidchar = "0" + uuidchar;
  1600. }
  1601. uuidpart += uuidchar;
  1602. }
  1603. return uuidpart;
  1604. }
  1605. /**
  1606. * Create a UUID
  1607. */
  1608. utils.createUUID = function() {
  1609. return UUIDcreatePart(4) + '-' +
  1610. UUIDcreatePart(2) + '-' +
  1611. UUIDcreatePart(2) + '-' +
  1612. UUIDcreatePart(2) + '-' +
  1613. UUIDcreatePart(6);
  1614. };
  1615. /**
  1616. * Extends a child object from a parent object using classical inheritance
  1617. * pattern.
  1618. */
  1619. utils.extend = (function() {
  1620. // proxy used to establish prototype chain
  1621. var F = function() {};
  1622. // extend Child from Parent
  1623. return function(Child, Parent) {
  1624. F.prototype = Parent.prototype;
  1625. Child.prototype = new F();
  1626. Child.__super__ = Parent.prototype;
  1627. Child.prototype.constructor = Child;
  1628. };
  1629. }());
  1630. /**
  1631. * Alerts a message in any available way: alert or console.log.
  1632. */
  1633. utils.alert = function(msg) {
  1634. if (window.alert) {
  1635. window.alert(msg);
  1636. } else if (console && console.log) {
  1637. console.log(msg);
  1638. }
  1639. };
  1640. });
  1641. window.cordova = require('cordova');
  1642. // file: src/scripts/bootstrap.js
  1643. require('cordova/init');
  1644. })();