No Description

loader.js 64KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486
  1. /**
  2. * This is an auto-generated code by Monaca JS/CSS Components.
  3. * Please do not edit by hand.
  4. */
  5. /*** <GENERATED> ***/
  6. /*** <Start:monaca-cordova-loader> ***/
  7. /*** <Start:monaca-cordova-loader LoadJs:"components/monaca-cordova-loader/cordova-loader.js"> ***/
  8. (function(){
  9. function getDeviceObjectForPreview() {
  10. var raw_values = window.location.search.substring(1).split('&');
  11. var values = {};
  12. var device = { platform: "" };
  13. if (raw_values) {
  14. for (var key in raw_values) {
  15. var tmp = raw_values[key].split('=');
  16. values[tmp[0]] = decodeURIComponent(tmp[1]);
  17. }
  18. device.platform = values.platform;
  19. }
  20. return device;
  21. }
  22. if (/^https:\/\/preview-.+monaca\.(local||mobi)/.test(location.href)) {
  23. window.device = getDeviceObjectForPreview();
  24. }
  25. if ((navigator.userAgent.match(/Android/i)) || (navigator.userAgent.match(/iPhone|iPad|iPod/i))) {
  26. if (typeof location.href === "string") {
  27. var relativePath = location.href.split("/www")[1];
  28. var paths = relativePath.split("/");
  29. var cordovaJsUrl = "";
  30. for (var i = 0; i < paths.length - 2; i++) {
  31. cordovaJsUrl += "../";
  32. }
  33. document.write("<script src=\"" + cordovaJsUrl+ "cordova.js" + "\"></script>");
  34. }
  35. } else if ( ((navigator.userAgent.match(/MSIE\s10.0/)) && (navigator.userAgent.match(/Windows\sNT\s6.2/)) ) || navigator.userAgent.match(/MSAppHost/) || navigator.userAgent.match(/Electron/gi)) {
  36. var elm = document.createElement('script');
  37. elm.setAttribute("src", "cordova.js");
  38. document.getElementsByTagName("head")[0].appendChild(elm);
  39. };
  40. })();
  41. /*** <End:monaca-cordova-loader LoadJs:"components/monaca-cordova-loader/cordova-loader.js"> ***/
  42. /*** <End:monaca-cordova-loader> ***/
  43. /*** <Start:monaca-core-utils> ***/
  44. /*** <Start:monaca-core-utils LoadJs:"components/monaca-core-utils/monaca-core-utils.js"> ***/
  45. /**
  46. * Monaca Core Utility Library
  47. * This library requires cordova.js
  48. *
  49. * @version 2.0.7
  50. * @author Asial Corporation
  51. */
  52. window.monaca = window.monaca || {};
  53. (function() {
  54. /*
  55. * monaca api queue.
  56. */
  57. monaca.apiQueue = monaca.apiQueue || {};
  58. monaca.apiQueue.paramsArray = [];
  59. monaca.apiQueue.exec = function(a,b,c,d,e){
  60. if (!monaca.isDeviceReady) {
  61. monaca.apiQueue.paramsArray.push([a,b,c,d,e]);
  62. } else {
  63. window.cordova.exec(a,b,c,d,e);
  64. }
  65. };
  66. monaca.apiQueue.next = function(){
  67. var params = monaca.apiQueue.paramsArray.shift();
  68. if (params) {
  69. window.cordova.exec(
  70. function(r) {
  71. if (typeof params[0] === 'function') params[0](r);
  72. monaca.apiQueue.next();
  73. },
  74. function(r) {
  75. if (typeof params[1] === 'function') params[1](r);
  76. monaca.apiQueue.next();
  77. },
  78. params[2],
  79. params[3],
  80. params[4]
  81. );
  82. }
  83. };
  84. monaca.isDeviceReady = monaca.isDeviceReady || false;
  85. document.addEventListener('deviceready', function(){
  86. window.monaca.isDeviceReady = true;
  87. monaca.apiQueue.next();
  88. }, false);
  89. /**
  90. * Check User-Agent
  91. */
  92. var isAndroid = !!(navigator.userAgent.match(/Android/i));
  93. var isIOS = !!(navigator.userAgent.match(/iPhone|iPad|iPod/i));
  94. monaca.isAndroid = isAndroid;
  95. monaca.isIOS = isIOS;
  96. /**
  97. * Obtain style property
  98. */
  99. monaca.retrieveUIStyle = function() {
  100. var argsArray = [].slice.apply(arguments);
  101. monaca.apiQueue.exec(arguments[arguments.length-1], null, "mobi.monaca.nativecomponent", "retrieve", argsArray);
  102. };
  103. /**
  104. * Update style property
  105. */
  106. monaca.updateUIStyle = function(id, name, value) {
  107. if (typeof id == "string") {
  108. var argsArray = [].slice.apply(arguments);
  109. monaca.apiQueue.exec(null, null, "mobi.monaca.nativecomponent", "update", argsArray);
  110. } else {
  111. for (var i = 0; i < id.length; i++) {
  112. monaca.apiQueue.exec(null, null, "mobi.monaca.nativecomponent", "update", [id[i], name, value]);
  113. }
  114. }
  115. };
  116. if (isAndroid) {
  117. monaca.retrieveUIStyle = function(id, name, success, failure) {
  118. monaca.apiQueue.exec(
  119. function(style) { success(style[name]); } || function() { },
  120. failure || function() { },
  121. "mobi.monaca.nativecomponent",
  122. "retrieve",
  123. [id]
  124. );
  125. };
  126. monaca.updateUIStyle = function(id, name, value, success, failure) {
  127. var style = {};
  128. style[name] = value;
  129. monaca.apiQueue.exec(
  130. success || function() { },
  131. failure || function() { },
  132. "mobi.monaca.nativecomponent",
  133. "update",
  134. [id, style]
  135. );
  136. };
  137. }
  138. /**
  139. * Spinner handling
  140. */
  141. monaca.showSpinner = function (options) {
  142. options = options || {};
  143. var src = options.src ? options.src : null;
  144. var frames = options.frames != null ? options.frames : null;
  145. var interval = options.interval != null ? options.interval : null;
  146. var backgroundColor = options.backgroundColor ? options.backgroundColor : null;
  147. var backgroundOpacity = options.backgroundOpacity != null ? options.backgroundOpacity : null;
  148. var title = options.title ? options.title : null;
  149. var titleColor = options.titleColor ? options.titleColor : null;
  150. var titleFontScale = options.titleFontScale != null ? options.titleFontScale : null;
  151. monaca.apiQueue.exec(null, null, "mobi.monaca.nativecomponent", 'showSpinner', [ src, frames, interval, backgroundColor, backgroundOpacity, title, titleColor, titleFontScale, null ]);
  152. };
  153. monaca.hideSpinner = function(){
  154. monaca.apiQueue.exec(null, null, "mobi.monaca.nativecomponent", 'hideSpinner', []);
  155. };
  156. monaca.updateSpinnerTitle = function(newTitle){
  157. if (!newTitle) newTitle = "";
  158. monaca.apiQueue.exec(null, null, "mobi.monaca.nativecomponent", 'updateSpinnerTitle', [ newTitle ]);
  159. };
  160. var transitionPluginName = "Transit";
  161. /**
  162. * Open new page.
  163. */
  164. monaca.pushPage = function(path, options, param) {
  165. options = options || {};
  166. var animation = null;
  167. switch (options.animation) {
  168. case "lift":
  169. animation = "modal"; break;
  170. case "slide":
  171. case "slideLeft":
  172. animation = "push"; break;
  173. case "slideRight":
  174. animation = "slideRight"; break;
  175. default:
  176. animation = "push";
  177. }
  178. monaca.apiQueue.exec(null, null, transitionPluginName, animation, [path, options, param]);
  179. };
  180. /**
  181. * Close current page.
  182. */
  183. monaca.popPage = function(options) {
  184. options = options || {};
  185. var name = options.animation == 'lift' ? 'dismiss' : 'pop';
  186. monaca.apiQueue.exec(null, null, transitionPluginName, name, [options]);
  187. };
  188. /**
  189. * Open in browser.
  190. */
  191. monaca.invokeBrowser = function(url) {
  192. monaca.apiQueue.exec(null, null, transitionPluginName, "browse", [url]);
  193. };
  194. /**
  195. * Load in current page.
  196. */
  197. monaca.load = function(path, options, param) {
  198. monaca.apiQueue.exec(null, null, transitionPluginName, "link", [path, options, param]);
  199. };
  200. /**
  201. * return to top page.
  202. */
  203. monaca.home = function(options) {
  204. options = options || {};
  205. monaca.apiQueue.exec(null, null, transitionPluginName, "home", [options]);
  206. };
  207. /**
  208. * Clear stack
  209. */
  210. monaca.clearPageStack = function(clearAll) {
  211. clearAll = clearAll || false;
  212. monaca.apiQueue.exec(null, null, transitionPluginName, "clearPageStack", [clearAll]);
  213. };
  214. /**
  215. * Console API from independent PhoneGap.
  216. */
  217. window.monaca.console = window.monaca.console || {};
  218. /**
  219. * base method for send log.
  220. */
  221. monaca.console.sendLog = function(level, url, line, char, arguments) {
  222. var message;
  223. for (var i=0; i<arguments.length; i++){
  224. if (typeof arguments[i] == "string") {
  225. message = arguments[i];
  226. } else {
  227. message = JSON.stringify(arguments[i]);
  228. }
  229. if (message === undefined) {
  230. message = "undefined";
  231. }
  232. if (isIOS) {
  233. // not checked yet or confirmed MonacaDebugger
  234. if (! monaca.isMonacaDebuggerChecked || monaca.isMonacaDebugger ) {
  235. var head = message.substr(0, 5);
  236. if (window.monaca.isDeviceReady !== true || (head != 'ERROR' && head != 'WARN:')) {
  237. var xhr = new XMLHttpRequest();
  238. var path = "https://monaca-debugger.local/log?level=" + encodeURIComponent(level) + "&message=" + encodeURIComponent(message) + "&at=" + (new Date()).getTime();
  239. xhr.open("GET", path);
  240. xhr.send();
  241. }
  242. }
  243. window.orig_console[level](message);
  244. } else {
  245. window.console[level](message);
  246. }
  247. }
  248. }
  249. /**
  250. * monaca console methods
  251. */
  252. var methods = ["debug", "info", "log", "warn", "error"];
  253. for (var i=0; i<methods.length; i++) {
  254. var method = methods[i];
  255. monaca.console[method] = function(method) {
  256. return function() {
  257. monaca.console.sendLog(method, null, null, null, arguments);
  258. };
  259. }(method);
  260. }
  261. /** Replace window.console if iOS **/
  262. if (isIOS) {
  263. window.orig_console = window.console;
  264. window.console = window.monaca.console;
  265. window.addEventListener( "error" , function (desc, page, line, char) {
  266. monaca.console.sendLog("error", null, null, null, [ { "message" : desc.message , "page" : desc.filename , "line" : desc.lineno , "char" : desc.colno } ]);
  267. } , false );
  268. // window.onerror = function (desc, page, line, char) {
  269. // monaca.console.sendLog("error", page, line, char, [ { "message" : desc , "page" : page , "line" : line, "char" : char } ] );
  270. // };
  271. }
  272. /* Comment out for now
  273. window.onerror = function (desc, page, line, char) {
  274. monaca.console.sendLog("error", page, line, char, [desc]);
  275. };
  276. */
  277. window.monaca.splashScreen = window.monaca.splashScreen || {};
  278. var splashScreenPluginName = "MonacaSplashScreen";
  279. /**
  280. * hide SplashScreen.
  281. */
  282. monaca.splashScreen.hide = function() {
  283. if (isAndroid) {
  284. monaca.apiQueue.exec(null, null, splashScreenPluginName, "hide", []);
  285. } else {
  286. navigator.splashscreen.hide();
  287. }
  288. };
  289. // Set monaca.baseUrl
  290. if (typeof location.href !== "string") {
  291. console.warn("Cannot find base url");
  292. monaca.baseUrl = null;
  293. } else {
  294. monaca.baseUrl = location.href.split("/www/")[0] + "/www/";
  295. }
  296. /**
  297. * Get device ID
  298. */
  299. monaca.getDeviceId = function(callback) {
  300. monaca.apiQueue.exec(function(result) { callback(result.deviceId); }, null, "Monaca", "getRuntimeConfiguration", []);
  301. };
  302. monaca.getRuntimeConfiguration = function(success,failure) {
  303. monaca.apiQueue.exec( success , failure , "Monaca" , "getRuntimeConfiguration" , []);
  304. };
  305. monaca.isMonacaDebuggerChecked = false;
  306. monaca.isMonacaDebugger = null;
  307. monaca.getRuntimeConfiguration( function(result) {
  308. monaca.isMonacaDebuggerChecked = true;
  309. monaca.isMonacaDebugger = !! result.isMonacaDebugger;
  310. });
  311. })();
  312. /**
  313. * iOS Status Bar Plugin
  314. *
  315. * @author Asial Corporation
  316. * @date 2014/1/15
  317. */
  318. window.StatusBar = window.StatusBar || {};
  319. (function() {
  320. /*
  321. hideStatusBar
  322. support : iOS6,iOS7
  323. */
  324. StatusBar.hideStatusBar = function() {
  325. monaca.apiQueue.exec(null, null, "mobi.monaca.nativecomponent", 'hideStatusBar', []);
  326. }
  327. /*
  328. showStatusBar
  329. support : iOS6,iOS7
  330. */
  331. StatusBar.showStatusBar = function() {
  332. monaca.apiQueue.exec(null, null, "mobi.monaca.nativecomponent", 'showStatusBar', []);
  333. }
  334. /*
  335. statusBarStyleDefault
  336. support : iOS6,iOS7
  337. */
  338. StatusBar.statusBarStyleDefault = function() {
  339. monaca.apiQueue.exec(null, null, "mobi.monaca.nativecomponent", 'statusBarStyleDefault', []);
  340. }
  341. /*
  342. statusBarStyleLightContent
  343. support : iOS7
  344. */
  345. StatusBar.statusBarStyleLightContent = function() {
  346. monaca.apiQueue.exec(null, null, "mobi.monaca.nativecomponent", 'statusBarStyleLightContent', []);
  347. }
  348. /*
  349. statusBarStyleBlackOpaque
  350. support : iOS6
  351. */
  352. StatusBar.statusBarStyleBlackOpaque = function() {
  353. monaca.apiQueue.exec(null, null, "mobi.monaca.nativecomponent", 'statusBarStyleBlackOpaque', []);
  354. }
  355. /*
  356. statusBarStyleBlackTranslucent
  357. support : iOS6
  358. */
  359. StatusBar.statusBarStyleBlackTranslucent = function() {
  360. monaca.apiQueue.exec(null, null, "mobi.monaca.nativecomponent", 'statusBarStyleBlackTranslucent', []);
  361. }
  362. })();
  363. /**
  364. * Monaca Cloud Functions
  365. * Version 1.5.0
  366. *
  367. * @author Masahiro TANAKA <info@monaca.mobi>
  368. * @date 2013/03/17
  369. */
  370. window.monaca = window.monaca || {};
  371. window.monaca.cloud = window.monaca.cloud || {};
  372. (function() {
  373. /**
  374. * Push Notification
  375. */
  376. monaca.cloud.Push = {};
  377. monaca.cloud.Push.callback = null;
  378. monaca.cloud.Push.callbackData = null;
  379. monaca.cloud.Push.send = function(data) {
  380. if (typeof monaca.cloud.Push.callback === "function") {
  381. monaca.cloud.Push.callback(data);
  382. } else {
  383. monaca.cloud.Push.callbackData = data;
  384. }
  385. };
  386. monaca.cloud.Push.setHandler = function(fn) {
  387. if (typeof fn !== "function") {
  388. console.warn("Push callback must be a function");
  389. } else {
  390. monaca.cloud.Push.callback = fn;
  391. if (monaca.cloud.Push.callbackData) {
  392. monaca.cloud.Push.callback(monaca.cloud.Push.callbackData);
  393. monaca.cloud.Push.callbackData = null;
  394. }
  395. }
  396. };
  397. })();
  398. /*
  399. * cloud
  400. */
  401. (function(root) {
  402. var original$ = root.$;
  403. var originalZepto = root.Zepto;
  404. /* Zepto 1.1.3 - zepto event ajax deferred callbacks - zeptojs.com/license */
  405. var Zepto=function(){function k(t){return null==t?String(t):j[T.call(t)]||"object"}function $(t){return"function"==k(t)}function L(t){return null!=t&&t==t.window}function D(t){return null!=t&&t.nodeType==t.DOCUMENT_NODE}function F(t){return"object"==k(t)}function Z(t){return F(t)&&!L(t)&&Object.getPrototypeOf(t)==Object.prototype}function M(t){return"number"==typeof t.length}function R(t){return s.call(t,function(t){return null!=t})}function _(t){return t.length>0?n.fn.concat.apply([],t):t}function q(t){return t.replace(/::/g,"/").replace(/([A-Z]+)([A-Z][a-z])/g,"$1_$2").replace(/([a-z\d])([A-Z])/g,"$1_$2").replace(/_/g,"-").toLowerCase()}function W(t){return t in f?f[t]:f[t]=new RegExp("(^|\\s)"+t+"(\\s|$)")}function z(t,e){return"number"!=typeof e||c[q(t)]?e:e+"px"}function H(t){var e,n;return u[t]||(e=a.createElement(t),a.body.appendChild(e),n=getComputedStyle(e,"").getPropertyValue("display"),e.parentNode.removeChild(e),"none"==n&&(n="block"),u[t]=n),u[t]}function V(t){return"children"in t?o.call(t.children):n.map(t.childNodes,function(t){return 1==t.nodeType?t:void 0})}function I(n,i,r){for(e in i)r&&(Z(i[e])||A(i[e]))?(Z(i[e])&&!Z(n[e])&&(n[e]={}),A(i[e])&&!A(n[e])&&(n[e]=[]),I(n[e],i[e],r)):i[e]!==t&&(n[e]=i[e])}function B(t,e){return null==e?n(t):n(t).filter(e)}function J(t,e,n,i){return $(e)?e.call(t,n,i):e}function U(t,e,n){null==n?t.removeAttribute(e):t.setAttribute(e,n)}function X(e,n){var i=e.className,r=i&&i.baseVal!==t;return n===t?r?i.baseVal:i:void(r?i.baseVal=n:e.className=n)}function Y(t){var e;try{return t?"true"==t||("false"==t?!1:"null"==t?null:/^0/.test(t)||isNaN(e=Number(t))?/^[\[\{]/.test(t)?n.parseJSON(t):t:e):t}catch(i){return t}}function G(t,e){e(t);for(var n in t.childNodes)G(t.childNodes[n],e)}var t,e,n,i,C,N,r=[],o=r.slice,s=r.filter,a=window.document,u={},f={},c={"column-count":1,columns:1,"font-weight":1,"line-height":1,opacity:1,"z-index":1,zoom:1},l=/^\s*<(\w+|!)[^>]*>/,h=/^<(\w+)\s*\/?>(?:<\/\1>|)$/,p=/<(?!area|br|col|embed|hr|img|input|link|meta|param)(([\w:]+)[^>]*)\/>/gi,d=/^(?:body|html)$/i,m=/([A-Z])/g,g=["val","css","html","text","data","width","height","offset"],v=["after","prepend","before","append"],y=a.createElement("table"),x=a.createElement("tr"),b={tr:a.createElement("tbody"),tbody:y,thead:y,tfoot:y,td:x,th:x,"*":a.createElement("div")},w=/complete|loaded|interactive/,E=/^[\w-]*$/,j={},T=j.toString,S={},O=a.createElement("div"),P={tabindex:"tabIndex",readonly:"readOnly","for":"htmlFor","class":"className",maxlength:"maxLength",cellspacing:"cellSpacing",cellpadding:"cellPadding",rowspan:"rowSpan",colspan:"colSpan",usemap:"useMap",frameborder:"frameBorder",contenteditable:"contentEditable"},A=Array.isArray||function(t){return t instanceof Array};return S.matches=function(t,e){if(!e||!t||1!==t.nodeType)return!1;var n=t.webkitMatchesSelector||t.mozMatchesSelector||t.oMatchesSelector||t.matchesSelector;if(n)return n.call(t,e);var i,r=t.parentNode,o=!r;return o&&(r=O).appendChild(t),i=~S.qsa(r,e).indexOf(t),o&&O.removeChild(t),i},C=function(t){return t.replace(/-+(.)?/g,function(t,e){return e?e.toUpperCase():""})},N=function(t){return s.call(t,function(e,n){return t.indexOf(e)==n})},S.fragment=function(e,i,r){var s,u,f;return h.test(e)&&(s=n(a.createElement(RegExp.$1))),s||(e.replace&&(e=e.replace(p,"<$1></$2>")),i===t&&(i=l.test(e)&&RegExp.$1),i in b||(i="*"),f=b[i],f.innerHTML=""+e,s=n.each(o.call(f.childNodes),function(){f.removeChild(this)})),Z(r)&&(u=n(s),n.each(r,function(t,e){g.indexOf(t)>-1?u[t](e):u.attr(t,e)})),s},S.Z=function(t,e){return t=t||[],t.__proto__=n.fn,t.selector=e||"",t},S.isZ=function(t){return t instanceof S.Z},S.init=function(e,i){var r;if(!e)return S.Z();if("string"==typeof e)if(e=e.trim(),"<"==e[0]&&l.test(e))r=S.fragment(e,RegExp.$1,i),e=null;else{if(i!==t)return n(i).find(e);r=S.qsa(a,e)}else{if($(e))return n(a).ready(e);if(S.isZ(e))return e;if(A(e))r=R(e);else if(F(e))r=[e],e=null;else if(l.test(e))r=S.fragment(e.trim(),RegExp.$1,i),e=null;else{if(i!==t)return n(i).find(e);r=S.qsa(a,e)}}return S.Z(r,e)},n=function(t,e){return S.init(t,e)},n.extend=function(t){var e,n=o.call(arguments,1);return"boolean"==typeof t&&(e=t,t=n.shift()),n.forEach(function(n){I(t,n,e)}),t},S.qsa=function(t,e){var n,i="#"==e[0],r=!i&&"."==e[0],s=i||r?e.slice(1):e,a=E.test(s);return D(t)&&a&&i?(n=t.getElementById(s))?[n]:[]:1!==t.nodeType&&9!==t.nodeType?[]:o.call(a&&!i?r?t.getElementsByClassName(s):t.getElementsByTagName(e):t.querySelectorAll(e))},n.contains=function(t,e){return t!==e&&t.contains(e)},n.type=k,n.isFunction=$,n.isWindow=L,n.isArray=A,n.isPlainObject=Z,n.isEmptyObject=function(t){var e;for(e in t)return!1;return!0},n.inArray=function(t,e,n){return r.indexOf.call(e,t,n)},n.camelCase=C,n.trim=function(t){return null==t?"":String.prototype.trim.call(t)},n.uuid=0,n.support={},n.expr={},n.map=function(t,e){var n,r,o,i=[];if(M(t))for(r=0;r<t.length;r++)n=e(t[r],r),null!=n&&i.push(n);else for(o in t)n=e(t[o],o),null!=n&&i.push(n);return _(i)},n.each=function(t,e){var n,i;if(M(t)){for(n=0;n<t.length;n++)if(e.call(t[n],n,t[n])===!1)return t}else for(i in t)if(e.call(t[i],i,t[i])===!1)return t;return t},n.grep=function(t,e){return s.call(t,e)},window.JSON&&(n.parseJSON=JSON.parse),n.each("Boolean Number String Function Array Date RegExp Object Error".split(" "),function(t,e){j["[object "+e+"]"]=e.toLowerCase()}),n.fn={forEach:r.forEach,reduce:r.reduce,push:r.push,sort:r.sort,indexOf:r.indexOf,concat:r.concat,map:function(t){return n(n.map(this,function(e,n){return t.call(e,n,e)}))},slice:function(){return n(o.apply(this,arguments))},ready:function(t){return w.test(a.readyState)&&a.body?t(n):a.addEventListener("DOMContentLoaded",function(){t(n)},!1),this},get:function(e){return e===t?o.call(this):this[e>=0?e:e+this.length]},toArray:function(){return this.get()},size:function(){return this.length},remove:function(){return this.each(function(){null!=this.parentNode&&this.parentNode.removeChild(this)})},each:function(t){return r.every.call(this,function(e,n){return t.call(e,n,e)!==!1}),this},filter:function(t){return $(t)?this.not(this.not(t)):n(s.call(this,function(e){return S.matches(e,t)}))},add:function(t,e){return n(N(this.concat(n(t,e))))},is:function(t){return this.length>0&&S.matches(this[0],t)},not:function(e){var i=[];if($(e)&&e.call!==t)this.each(function(t){e.call(this,t)||i.push(this)});else{var r="string"==typeof e?this.filter(e):M(e)&&$(e.item)?o.call(e):n(e);this.forEach(function(t){r.indexOf(t)<0&&i.push(t)})}return n(i)},has:function(t){return this.filter(function(){return F(t)?n.contains(this,t):n(this).find(t).size()})},eq:function(t){return-1===t?this.slice(t):this.slice(t,+t+1)},first:function(){var t=this[0];return t&&!F(t)?t:n(t)},last:function(){var t=this[this.length-1];return t&&!F(t)?t:n(t)},find:function(t){var e,i=this;return e="object"==typeof t?n(t).filter(function(){var t=this;return r.some.call(i,function(e){return n.contains(e,t)})}):1==this.length?n(S.qsa(this[0],t)):this.map(function(){return S.qsa(this,t)})},closest:function(t,e){var i=this[0],r=!1;for("object"==typeof t&&(r=n(t));i&&!(r?r.indexOf(i)>=0:S.matches(i,t));)i=i!==e&&!D(i)&&i.parentNode;return n(i)},parents:function(t){for(var e=[],i=this;i.length>0;)i=n.map(i,function(t){return(t=t.parentNode)&&!D(t)&&e.indexOf(t)<0?(e.push(t),t):void 0});return B(e,t)},parent:function(t){return B(N(this.pluck("parentNode")),t)},children:function(t){return B(this.map(function(){return V(this)}),t)},contents:function(){return this.map(function(){return o.call(this.childNodes)})},siblings:function(t){return B(this.map(function(t,e){return s.call(V(e.parentNode),function(t){return t!==e})}),t)},empty:function(){return this.each(function(){this.innerHTML=""})},pluck:function(t){return n.map(this,function(e){return e[t]})},show:function(){return this.each(function(){"none"==this.style.display&&(this.style.display=""),"none"==getComputedStyle(this,"").getPropertyValue("display")&&(this.style.display=H(this.nodeName))})},replaceWith:function(t){return this.before(t).remove()},wrap:function(t){var e=$(t);if(this[0]&&!e)var i=n(t).get(0),r=i.parentNode||this.length>1;return this.each(function(o){n(this).wrapAll(e?t.call(this,o):r?i.cloneNode(!0):i)})},wrapAll:function(t){if(this[0]){n(this[0]).before(t=n(t));for(var e;(e=t.children()).length;)t=e.first();n(t).append(this)}return this},wrapInner:function(t){var e=$(t);return this.each(function(i){var r=n(this),o=r.contents(),s=e?t.call(this,i):t;o.length?o.wrapAll(s):r.append(s)})},unwrap:function(){return this.parent().each(function(){n(this).replaceWith(n(this).children())}),this},clone:function(){return this.map(function(){return this.cloneNode(!0)})},hide:function(){return this.css("display","none")},toggle:function(e){return this.each(function(){var i=n(this);(e===t?"none"==i.css("display"):e)?i.show():i.hide()})},prev:function(t){return n(this.pluck("previousElementSibling")).filter(t||"*")},next:function(t){return n(this.pluck("nextElementSibling")).filter(t||"*")},html:function(t){return 0===arguments.length?this.length>0?this[0].innerHTML:null:this.each(function(e){var i=this.innerHTML;n(this).empty().append(J(this,t,e,i))})},text:function(e){return 0===arguments.length?this.length>0?this[0].textContent:null:this.each(function(){this.textContent=e===t?"":""+e})},attr:function(n,i){var r;return"string"==typeof n&&i===t?0==this.length||1!==this[0].nodeType?t:"value"==n&&"INPUT"==this[0].nodeName?this.val():!(r=this[0].getAttribute(n))&&n in this[0]?this[0][n]:r:this.each(function(t){if(1===this.nodeType)if(F(n))for(e in n)U(this,e,n[e]);else U(this,n,J(this,i,t,this.getAttribute(n)))})},removeAttr:function(t){return this.each(function(){1===this.nodeType&&U(this,t)})},prop:function(e,n){return e=P[e]||e,n===t?this[0]&&this[0][e]:this.each(function(t){this[e]=J(this,n,t,this[e])})},data:function(e,n){var i=this.attr("data-"+e.replace(m,"-$1").toLowerCase(),n);return null!==i?Y(i):t},val:function(t){return 0===arguments.length?this[0]&&(this[0].multiple?n(this[0]).find("option").filter(function(){return this.selected}).pluck("value"):this[0].value):this.each(function(e){this.value=J(this,t,e,this.value)})},offset:function(t){if(t)return this.each(function(e){var i=n(this),r=J(this,t,e,i.offset()),o=i.offsetParent().offset(),s={top:r.top-o.top,left:r.left-o.left};"static"==i.css("position")&&(s.position="relative"),i.css(s)});if(0==this.length)return null;var e=this[0].getBoundingClientRect();return{left:e.left+window.pageXOffset,top:e.top+window.pageYOffset,width:Math.round(e.width),height:Math.round(e.height)}},css:function(t,i){if(arguments.length<2){var r=this[0],o=getComputedStyle(r,"");if(!r)return;if("string"==typeof t)return r.style[C(t)]||o.getPropertyValue(t);if(A(t)){var s={};return n.each(A(t)?t:[t],function(t,e){s[e]=r.style[C(e)]||o.getPropertyValue(e)}),s}}var a="";if("string"==k(t))i||0===i?a=q(t)+":"+z(t,i):this.each(function(){this.style.removeProperty(q(t))});else for(e in t)t[e]||0===t[e]?a+=q(e)+":"+z(e,t[e])+";":this.each(function(){this.style.removeProperty(q(e))});return this.each(function(){this.style.cssText+=";"+a})},index:function(t){return t?this.indexOf(n(t)[0]):this.parent().children().indexOf(this[0])},hasClass:function(t){return t?r.some.call(this,function(t){return this.test(X(t))},W(t)):!1},addClass:function(t){return t?this.each(function(e){i=[];var r=X(this),o=J(this,t,e,r);o.split(/\s+/g).forEach(function(t){n(this).hasClass(t)||i.push(t)},this),i.length&&X(this,r+(r?" ":"")+i.join(" "))}):this},removeClass:function(e){return this.each(function(n){return e===t?X(this,""):(i=X(this),J(this,e,n,i).split(/\s+/g).forEach(function(t){i=i.replace(W(t)," ")}),void X(this,i.trim()))})},toggleClass:function(e,i){return e?this.each(function(r){var o=n(this),s=J(this,e,r,X(this));s.split(/\s+/g).forEach(function(e){(i===t?!o.hasClass(e):i)?o.addClass(e):o.removeClass(e)})}):this},scrollTop:function(e){if(this.length){var n="scrollTop"in this[0];return e===t?n?this[0].scrollTop:this[0].pageYOffset:this.each(n?function(){this.scrollTop=e}:function(){this.scrollTo(this.scrollX,e)})}},scrollLeft:function(e){if(this.length){var n="scrollLeft"in this[0];return e===t?n?this[0].scrollLeft:this[0].pageXOffset:this.each(n?function(){this.scrollLeft=e}:function(){this.scrollTo(e,this.scrollY)})}},position:function(){if(this.length){var t=this[0],e=this.offsetParent(),i=this.offset(),r=d.test(e[0].nodeName)?{top:0,left:0}:e.offset();return i.top-=parseFloat(n(t).css("margin-top"))||0,i.left-=parseFloat(n(t).css("margin-left"))||0,r.top+=parseFloat(n(e[0]).css("border-top-width"))||0,r.left+=parseFloat(n(e[0]).css("border-left-width"))||0,{top:i.top-r.top,left:i.left-r.left}}},offsetParent:function(){return this.map(function(){for(var t=this.offsetParent||a.body;t&&!d.test(t.nodeName)&&"static"==n(t).css("position");)t=t.offsetParent;return t})}},n.fn.detach=n.fn.remove,["width","height"].forEach(function(e){var i=e.replace(/./,function(t){return t[0].toUpperCase()});n.fn[e]=function(r){var o,s=this[0];return r===t?L(s)?s["inner"+i]:D(s)?s.documentElement["scroll"+i]:(o=this.offset())&&o[e]:this.each(function(t){s=n(this),s.css(e,J(this,r,t,s[e]()))})}}),v.forEach(function(t,e){var i=e%2;n.fn[t]=function(){var t,o,r=n.map(arguments,function(e){return t=k(e),"object"==t||"array"==t||null==e?e:S.fragment(e)}),s=this.length>1;return r.length<1?this:this.each(function(t,a){o=i?a:a.parentNode,a=0==e?a.nextSibling:1==e?a.firstChild:2==e?a:null,r.forEach(function(t){if(s)t=t.cloneNode(!0);else if(!o)return n(t).remove();G(o.insertBefore(t,a),function(t){null==t.nodeName||"SCRIPT"!==t.nodeName.toUpperCase()||t.type&&"text/javascript"!==t.type||t.src||window.eval.call(window,t.innerHTML)})})})},n.fn[i?t+"To":"insert"+(e?"Before":"After")]=function(e){return n(e)[t](this),this}}),S.Z.prototype=n.fn,S.uniq=N,S.deserializeValue=Y,n.zepto=S,n}();window.Zepto=Zepto,void 0===window.$&&(window.$=Zepto),function(t){function l(t){return t._zid||(t._zid=e++)}function h(t,e,n,i){if(e=p(e),e.ns)var r=d(e.ns);return(s[l(t)]||[]).filter(function(t){return!(!t||e.e&&t.e!=e.e||e.ns&&!r.test(t.ns)||n&&l(t.fn)!==l(n)||i&&t.sel!=i)})}function p(t){var e=(""+t).split(".");return{e:e[0],ns:e.slice(1).sort().join(" ")}}function d(t){return new RegExp("(?:^| )"+t.replace(" "," .* ?")+"(?: |$)")}function m(t,e){return t.del&&!u&&t.e in f||!!e}function g(t){return c[t]||u&&f[t]||t}function v(e,i,r,o,a,u,f){var h=l(e),d=s[h]||(s[h]=[]);i.split(/\s/).forEach(function(i){if("ready"==i)return t(document).ready(r);var s=p(i);s.fn=r,s.sel=a,s.e in c&&(r=function(e){var n=e.relatedTarget;return!n||n!==this&&!t.contains(this,n)?s.fn.apply(this,arguments):void 0}),s.del=u;var l=u||r;s.proxy=function(t){if(t=j(t),!t.isImmediatePropagationStopped()){t.data=o;var i=l.apply(e,t._args==n?[t]:[t].concat(t._args));return i===!1&&(t.preventDefault(),t.stopPropagation()),i}},s.i=d.length,d.push(s),"addEventListener"in e&&e.addEventListener(g(s.e),s.proxy,m(s,f))})}function y(t,e,n,i,r){var o=l(t);(e||"").split(/\s/).forEach(function(e){h(t,e,n,i).forEach(function(e){delete s[o][e.i],"removeEventListener"in t&&t.removeEventListener(g(e.e),e.proxy,m(e,r))})})}function j(e,i){return(i||!e.isDefaultPrevented)&&(i||(i=e),t.each(E,function(t,n){var r=i[t];e[t]=function(){return this[n]=x,r&&r.apply(i,arguments)},e[n]=b}),(i.defaultPrevented!==n?i.defaultPrevented:"returnValue"in i?i.returnValue===!1:i.getPreventDefault&&i.getPreventDefault())&&(e.isDefaultPrevented=x)),e}function T(t){var e,i={originalEvent:t};for(e in t)w.test(e)||t[e]===n||(i[e]=t[e]);return j(i,t)}var n,e=1,i=Array.prototype.slice,r=t.isFunction,o=function(t){return"string"==typeof t},s={},a={},u="onfocusin"in window,f={focus:"focusin",blur:"focusout"},c={mouseenter:"mouseover",mouseleave:"mouseout"};a.click=a.mousedown=a.mouseup=a.mousemove="MouseEvents",t.event={add:v,remove:y},t.proxy=function(e,n){if(r(e)){var i=function(){return e.apply(n,arguments)};return i._zid=l(e),i}if(o(n))return t.proxy(e[n],e);throw new TypeError("expected function")},t.fn.bind=function(t,e,n){return this.on(t,e,n)},t.fn.unbind=function(t,e){return this.off(t,e)},t.fn.one=function(t,e,n,i){return this.on(t,e,n,i,1)};var x=function(){return!0},b=function(){return!1},w=/^([A-Z]|returnValue$|layer[XY]$)/,E={preventDefault:"isDefaultPrevented",stopImmediatePropagation:"isImmediatePropagationStopped",stopPropagation:"isPropagationStopped"};t.fn.delegate=function(t,e,n){return this.on(e,t,n)},t.fn.undelegate=function(t,e,n){return this.off(e,t,n)},t.fn.live=function(e,n){return t(document.body).delegate(this.selector,e,n),this},t.fn.die=function(e,n){return t(document.body).undelegate(this.selector,e,n),this},t.fn.on=function(e,s,a,u,f){var c,l,h=this;return e&&!o(e)?(t.each(e,function(t,e){h.on(t,s,a,e,f)}),h):(o(s)||r(u)||u===!1||(u=a,a=s,s=n),(r(a)||a===!1)&&(u=a,a=n),u===!1&&(u=b),h.each(function(n,r){f&&(c=function(t){return y(r,t.type,u),u.apply(this,arguments)}),s&&(l=function(e){var n,o=t(e.target).closest(s,r).get(0);return o&&o!==r?(n=t.extend(T(e),{currentTarget:o,liveFired:r}),(c||u).apply(o,[n].concat(i.call(arguments,1)))):void 0}),v(r,e,u,a,s,l||c)}))},t.fn.off=function(e,i,s){var a=this;return e&&!o(e)?(t.each(e,function(t,e){a.off(t,i,e)}),a):(o(i)||r(s)||s===!1||(s=i,i=n),s===!1&&(s=b),a.each(function(){y(this,e,s,i)}))},t.fn.trigger=function(e,n){return e=o(e)||t.isPlainObject(e)?t.Event(e):j(e),e._args=n,this.each(function(){"dispatchEvent"in this?this.dispatchEvent(e):t(this).triggerHandler(e,n)})},t.fn.triggerHandler=function(e,n){var i,r;return this.each(function(s,a){i=T(o(e)?t.Event(e):e),i._args=n,i.target=a,t.each(h(a,e.type||e),function(t,e){return r=e.proxy(i),i.isImmediatePropagationStopped()?!1:void 0})}),r},"focusin focusout load resize scroll unload click dblclick mousedown mouseup mousemove mouseover mouseout mouseenter mouseleave change select keydown keypress keyup error".split(" ").forEach(function(e){t.fn[e]=function(t){return t?this.bind(e,t):this.trigger(e)}}),["focus","blur"].forEach(function(e){t.fn[e]=function(t){return t?this.bind(e,t):this.each(function(){try{this[e]()}catch(t){}}),this}}),t.Event=function(t,e){o(t)||(e=t,t=e.type);var n=document.createEvent(a[t]||"Events"),i=!0;if(e)for(var r in e)"bubbles"==r?i=!!e[r]:n[r]=e[r];return n.initEvent(t,i,!0),j(n)}}(Zepto),function(t){function l(e,n,i){var r=t.Event(n);return t(e).trigger(r,i),!r.isDefaultPrevented()}function h(t,e,i,r){return t.global?l(e||n,i,r):void 0}function p(e){e.global&&0===t.active++&&h(e,null,"ajaxStart")}function d(e){e.global&&!--t.active&&h(e,null,"ajaxStop")}function m(t,e){var n=e.context;return e.beforeSend.call(n,t,e)===!1||h(e,n,"ajaxBeforeSend",[t,e])===!1?!1:void h(e,n,"ajaxSend",[t,e])}function g(t,e,n,i){var r=n.context,o="success";n.success.call(r,t,o,e),i&&i.resolveWith(r,[t,o,e]),h(n,r,"ajaxSuccess",[e,n,t]),y(o,e,n)}function v(t,e,n,i,r){var o=i.context;i.error.call(o,n,e,t),r&&r.rejectWith(o,[n,e,t]),h(i,o,"ajaxError",[n,i,t||e]),y(e,n,i)}function y(t,e,n){var i=n.context;n.complete.call(i,e,t),h(n,i,"ajaxComplete",[e,n]),d(n)}function x(){}function b(t){return t&&(t=t.split(";",2)[0]),t&&(t==f?"html":t==u?"json":s.test(t)?"script":a.test(t)&&"xml")||"text"}function w(t,e){return""==e?t:(t+"&"+e).replace(/[&?]{1,2}/,"?")}function E(e){e.processData&&e.data&&"string"!=t.type(e.data)&&(e.data=t.param(e.data,e.traditional)),!e.data||e.type&&"GET"!=e.type.toUpperCase()||(e.url=w(e.url,e.data),e.data=void 0)}function j(e,n,i,r){return t.isFunction(n)&&(r=i,i=n,n=void 0),t.isFunction(i)||(r=i,i=void 0),{url:e,data:n,success:i,dataType:r}}function S(e,n,i,r){var o,s=t.isArray(n),a=t.isPlainObject(n);t.each(n,function(n,u){o=t.type(u),r&&(n=i?r:r+"["+(a||"object"==o||"array"==o?n:"")+"]"),!r&&s?e.add(u.name,u.value):"array"==o||!i&&"object"==o?S(e,u,i,n):e.add(n,u)})}var i,r,e=0,n=window.document,o=/<script\b[^<]*(?:(?!<\/script>)<[^<]*)*<\/script>/gi,s=/^(?:text|application)\/javascript/i,a=/^(?:text|application)\/xml/i,u="application/json",f="text/html",c=/^\s*$/;t.active=0,t.ajaxJSONP=function(i,r){if(!("type"in i))return t.ajax(i);var f,h,o=i.jsonpCallback,s=(t.isFunction(o)?o():o)||"jsonp"+ ++e,a=n.createElement("script"),u=window[s],c=function(e){t(a).triggerHandler("error",e||"abort")},l={abort:c};return r&&r.promise(l),t(a).on("load error",function(e,n){clearTimeout(h),t(a).off().remove(),"error"!=e.type&&f?g(f[0],l,i,r):v(null,n||"error",l,i,r),window[s]=u,f&&t.isFunction(u)&&u(f[0]),u=f=void 0}),m(l,i)===!1?(c("abort"),l):(window[s]=function(){f=arguments},a.src=i.url.replace(/\?(.+)=\?/,"?$1="+s),n.head.appendChild(a),i.timeout>0&&(h=setTimeout(function(){c("timeout")},i.timeout)),l)},t.ajaxSettings={type:"GET",beforeSend:x,success:x,error:x,complete:x,context:null,global:!0,xhr:function(){return new window.XMLHttpRequest},accepts:{script:"text/javascript, application/javascript, application/x-javascript",json:u,xml:"application/xml, text/xml",html:f,text:"text/plain"},crossDomain:!1,timeout:0,processData:!0,cache:!0},t.ajax=function(e){var n=t.extend({},e||{}),o=t.Deferred&&t.Deferred();for(i in t.ajaxSettings)void 0===n[i]&&(n[i]=t.ajaxSettings[i]);p(n),n.crossDomain||(n.crossDomain=/^([\w-]+:)?\/\/([^\/]+)/.test(n.url)&&RegExp.$2!=window.location.host),n.url||(n.url=window.location.toString()),E(n),n.cache===!1&&(n.url=w(n.url,"_="+Date.now()));var s=n.dataType,a=/\?.+=\?/.test(n.url);if("jsonp"==s||a)return a||(n.url=w(n.url,n.jsonp?n.jsonp+"=?":n.jsonp===!1?"":"callback=?")),t.ajaxJSONP(n,o);var j,u=n.accepts[s],f={},l=function(t,e){f[t.toLowerCase()]=[t,e]},h=/^([\w-]+:)\/\//.test(n.url)?RegExp.$1:window.location.protocol,d=n.xhr(),y=d.setRequestHeader;if(o&&o.promise(d),n.crossDomain||l("X-Requested-With","XMLHttpRequest"),l("Accept",u||"*/*"),(u=n.mimeType||u)&&(u.indexOf(",")>-1&&(u=u.split(",",2)[0]),d.overrideMimeType&&d.overrideMimeType(u)),(n.contentType||n.contentType!==!1&&n.data&&"GET"!=n.type.toUpperCase())&&l("Content-Type",n.contentType||"application/x-www-form-urlencoded"),n.headers)for(r in n.headers)l(r,n.headers[r]);if(d.setRequestHeader=l,d.onreadystatechange=function(){if(4==d.readyState){d.onreadystatechange=x,clearTimeout(j);var e,i=!1;if(d.status>=200&&d.status<300||304==d.status||0==d.status&&"file:"==h){s=s||b(n.mimeType||d.getResponseHeader("content-type")),e=d.responseText;try{"script"==s?(1,eval)(e):"xml"==s?e=d.responseXML:"json"==s&&(e=c.test(e)?null:t.parseJSON(e))}catch(r){i=r}i?v(i,"parsererror",d,n,o):g(e,d,n,o)}else v(d.statusText||null,d.status?"error":"abort",d,n,o)}},m(d,n)===!1)return d.abort(),v(null,"abort",d,n,o),d;if(n.xhrFields)for(r in n.xhrFields)d[r]=n.xhrFields[r];var T="async"in n?n.async:!0;d.open(n.type,n.url,T,n.username,n.password);for(r in f)y.apply(d,f[r]);return n.timeout>0&&(j=setTimeout(function(){d.onreadystatechange=x,d.abort(),v(null,"timeout",d,n,o)},n.timeout)),d.send(n.data?n.data:null),d},t.get=function(){return t.ajax(j.apply(null,arguments))},t.post=function(){var e=j.apply(null,arguments);return e.type="POST",t.ajax(e)},t.getJSON=function(){var e=j.apply(null,arguments);return e.dataType="json",t.ajax(e)},t.fn.load=function(e,n,i){if(!this.length)return this;var a,r=this,s=e.split(/\s/),u=j(e,n,i),f=u.success;return s.length>1&&(u.url=s[0],a=s[1]),u.success=function(e){r.html(a?t("<div>").html(e.replace(o,"")).find(a):e),f&&f.apply(r,arguments)},t.ajax(u),this};var T=encodeURIComponent;t.param=function(t,e){var n=[];return n.add=function(t,e){this.push(T(t)+"="+T(e))},S(n,t,e),n.join("&").replace(/%20/g,"+")}}(Zepto),function(t){function n(e){var i=[["resolve","done",t.Callbacks({once:1,memory:1}),"resolved"],["reject","fail",t.Callbacks({once:1,memory:1}),"rejected"],["notify","progress",t.Callbacks({memory:1})]],r="pending",o={state:function(){return r},always:function(){return s.done(arguments).fail(arguments),this},then:function(){var e=arguments;return n(function(n){t.each(i,function(i,r){var a=t.isFunction(e[i])&&e[i];s[r[1]](function(){var e=a&&a.apply(this,arguments);if(e&&t.isFunction(e.promise))e.promise().done(n.resolve).fail(n.reject).progress(n.notify);else{var i=this===o?n.promise():this,s=a?[e]:arguments;n[r[0]+"With"](i,s)}})}),e=null}).promise()},promise:function(e){return null!=e?t.extend(e,o):o}},s={};return t.each(i,function(t,e){var n=e[2],a=e[3];o[e[1]]=n.add,a&&n.add(function(){r=a},i[1^t][2].disable,i[2][2].lock),s[e[0]]=function(){return s[e[0]+"With"](this===s?o:this,arguments),this},s[e[0]+"With"]=n.fireWith}),o.promise(s),e&&e.call(s,s),s}var e=Array.prototype.slice;t.when=function(i){var f,c,l,r=e.call(arguments),o=r.length,s=0,a=1!==o||i&&t.isFunction(i.promise)?o:0,u=1===a?i:n(),h=function(t,n,i){return function(r){n[t]=this,i[t]=arguments.length>1?e.call(arguments):r,i===f?u.notifyWith(n,i):--a||u.resolveWith(n,i)}};if(o>1)for(f=new Array(o),c=new Array(o),l=new Array(o);o>s;++s)r[s]&&t.isFunction(r[s].promise)?r[s].promise().done(h(s,l,r)).fail(u.reject).progress(h(s,c,f)):--a;return a||u.resolveWith(l,r),u.promise()},t.Deferred=n}(Zepto),function(t){t.Callbacks=function(e){e=t.extend({},e);var n,i,r,o,s,a,u=[],f=!e.once&&[],c=function(t){for(n=e.memory&&t,i=!0,a=o||0,o=0,s=u.length,r=!0;u&&s>a;++a)if(u[a].apply(t[0],t[1])===!1&&e.stopOnFalse){n=!1;break}r=!1,u&&(f?f.length&&c(f.shift()):n?u.length=0:l.disable())},l={add:function(){if(u){var i=u.length,a=function(n){t.each(n,function(t,n){"function"==typeof n?e.unique&&l.has(n)||u.push(n):n&&n.length&&"string"!=typeof n&&a(n)})};a(arguments),r?s=u.length:n&&(o=i,c(n))}return this},remove:function(){return u&&t.each(arguments,function(e,n){for(var i;(i=t.inArray(n,u,i))>-1;)u.splice(i,1),r&&(s>=i&&--s,a>=i&&--a)}),this},has:function(e){return!(!u||!(e?t.inArray(e,u)>-1:u.length))},empty:function(){return s=u.length=0,this},disable:function(){return u=f=n=void 0,this},disabled:function(){return!u},lock:function(){return f=void 0,n||l.disable(),this},locked:function(){return!f},fireWith:function(t,e){return!u||i&&!f||(e=e||[],e=[t,e.slice?e.slice():e],r?f.push(e):c(e)),this},fire:function(){return l.fireWith(this,arguments)},fired:function(){return!!i}};return l}}(Zepto);
  406. root.$ = original$;
  407. root.Zepto = originalZepto;
  408. var monaca = root.monaca = root.monaca || {};
  409. monaca.cloud = monaca.cloud || {};
  410. monaca.cloud.timeout = 30000;
  411. monaca.cloud.url = '%%%CLOUD_HOST%%%';
  412. monaca.cloud.backendId = '%%%BACKEND_ID%%%';
  413. monaca.cloud.apiKey = '%%%BACKEND_API_KEY%%%';
  414. monaca.cloud.deviceId = null;
  415. monaca.cloud.postQueue = [];
  416. /**
  417. * @property {jQuery} .
  418. */
  419. monaca.cloud.$ = Zepto;
  420. var MonacaCloudError = (function() {
  421. function MonacaCloudError(code, message, data) {
  422. if (typeof data === "undefined") {
  423. data = {};
  424. }
  425. this.code = code;
  426. this.message = message;
  427. this.data = data;
  428. }
  429. return MonacaCloudError;
  430. })();
  431. /**
  432. * @class
  433. */
  434. monaca.cloud.Error = function(code, message, data) {
  435. return new MonacaCloudError(code, message, data);
  436. };
  437. /**
  438. * @param {Number} msec .
  439. */
  440. monaca.cloud.setTimeout = function(msec) {
  441. this.timeout = msec;
  442. };
  443. // Get device id
  444. document.addEventListener("deviceready", function() {
  445. cordova.exec(function(result) {
  446. monaca.cloud.deviceId = new String(result.deviceId);
  447. monaca.cloud.url = new String(result.url);
  448. monaca.cloud.backendId = new String(result.backendId);
  449. monaca.cloud.apiKey = new String(result.apiKey);
  450. // execute and clear postQueue
  451. for (var i = 0; i < monaca.cloud.postQueue.length; i++) {
  452. monaca.cloud._doPost.apply(monaca.cloud, monaca.cloud.postQueue[i]);
  453. }
  454. monaca.cloud.postQueue = [];
  455. }, function(error) {
  456. console.error(error);
  457. },
  458. "Monaca",
  459. "getRuntimeConfiguration", []
  460. );
  461. }, false);
  462. // Others
  463. monaca.cloud._post = function(method, params, dfd, ajaxOptions, beforeSuccess) {
  464. if (monaca.cloud.deviceId == null) {
  465. monaca.cloud.postQueue.push([method, params, dfd, ajaxOptions, beforeSuccess]);
  466. } else {
  467. monaca.cloud._doPost(method, params, dfd, ajaxOptions, beforeSuccess);
  468. }
  469. };
  470. monaca.cloud._doPost = function(method, params, dfd, ajaxOptions, beforeSuccess) {
  471. var $ = monaca.cloud.$;
  472. if (typeof(ajaxOptions) === 'undefined') ajaxOptions = {};
  473. if ((typeof(method) === 'undefined') && (typeof(params) === 'undefined')) {
  474. throw new Error('Invalid arguments');
  475. }
  476. params['__api_key'] = monaca.cloud.apiKey;
  477. params['__device'] = monaca.cloud.deviceId;
  478. var sid = monaca.cloud._getSessionId();
  479. if (sid.length > 0) {
  480. params['__session'] = sid;
  481. }
  482. var data = JSON.stringify({
  483. jsonrpc: '2.0',
  484. method: method,
  485. params: params,
  486. id: '1'
  487. });
  488. var o = $.extend(true, {
  489. url: this.url + this.backendId,
  490. data: data,
  491. dataType: 'json',
  492. type: 'POST',
  493. timeout: this.timeout,
  494. success: function(jsonResponse, status, xhr) {
  495. var sessionHeader = xhr.getResponseHeader('X-Set-Monaca-Cloud-Session');
  496. if (sessionHeader) {
  497. monaca.cloud._setSessionId(sessionHeader);
  498. }
  499. if (typeof(jsonResponse.error) !== 'undefined') {
  500. // has error code
  501. dfd.reject(jsonResponse.error);
  502. } else {
  503. // success
  504. if (typeof(jsonResponse.result.loginToken) !== 'undefined') {
  505. localStorage.monacaCloudLoginToken = jsonResponse.result.loginToken;
  506. }
  507. if (typeof(beforeSuccess) !== 'undefined') {
  508. beforeSuccess(jsonResponse, status, xhr, dfd);
  509. }
  510. dfd.resolve(jsonResponse.result);
  511. }
  512. },
  513. error: function(xhr, status) {
  514. switch (status) {
  515. case 'timeout':
  516. var err = monaca.cloud.Error(-11, 'Connection timeout');
  517. break;
  518. case 'parsererror':
  519. var err = monaca.cloud.Error(-12, 'Invalid response');
  520. break;
  521. default:
  522. var err = monaca.cloud.Error(-13, 'Invalid status code');
  523. }
  524. dfd.reject(err);
  525. }
  526. }, ajaxOptions);
  527. $.ajax(o);
  528. };
  529. var _sessionId = '';
  530. monaca.cloud._getSessionId = function() {
  531. return _sessionId;
  532. };
  533. monaca.cloud._setSessionId = function(id) {
  534. if (typeof id != 'string') {
  535. id = '';
  536. }
  537. _sessionId = id;
  538. };
  539. })(window);
  540. /*
  541. * CollectionItem
  542. */
  543. (function(root) {
  544. var monaca = root.monaca = root.monaca || {};
  545. monaca.cloud = monaca.cloud || {};
  546. var $ = monaca.cloud.$;
  547. /**
  548. * @class
  549. */
  550. MonacaCloudCollectionItem = (function() {
  551. function MonacaCloudCollectionItem(item, collection) {
  552. /**
  553. * @property {String} .
  554. */
  555. this._id = item._id;
  556. /**
  557. * @property {String} .
  558. */
  559. this._ownerUserOid = item._ownerUserOid;
  560. /**
  561. * @property {Date} .
  562. */
  563. this._createdAt = new Date(item._createdAt);
  564. /**
  565. * @property {Date} .
  566. */
  567. this._updatedAt = new Date(item._updatedAt);
  568. /**
  569. * @property {MonacaCloudCollection} .
  570. */
  571. this._collection = collection;
  572. for (var key in item) {
  573. if (key.substr(0, 1) != '_') {
  574. this[key] = item[key];
  575. }
  576. }
  577. }
  578. MonacaCloudCollectionItem.prototype = {
  579. /**
  580. * @return {$.Promise} .
  581. */
  582. update: function() {
  583. var dfd = new $.Deferred();
  584. var col = this._collection;
  585. var data = {};
  586. for (var key in this) {
  587. if (key.indexOf('_') !== 0) {
  588. data[key] = this[key];
  589. }
  590. }
  591. monaca.cloud._post('Collection.update', {
  592. collectionName: col.name,
  593. itemOid: this._id,
  594. data: data,
  595. }, dfd, {});
  596. return dfd.promise();
  597. },
  598. /**
  599. * @return {$.Promise} .
  600. */
  601. getPermission: function() {
  602. var dfd = new $.Deferred();
  603. var col = this._collection;
  604. monaca.cloud._post('Collection.getPermission', {
  605. collectionName: col.name,
  606. itemOid: this._id
  607. }, dfd, {});
  608. return dfd.promise();
  609. },
  610. /**
  611. * @param {Object} permission .
  612. * @param {Object} [options] .
  613. * @return {$.Promise} .
  614. */
  615. updatePermission: function(permission, options) {
  616. var dfd = new $.Deferred();
  617. var col = this._collection;
  618. if (typeof(options) === 'undefined') {
  619. options = {};
  620. }
  621. monaca.cloud._post('Collection.updatePermission', {
  622. collectionName: col.name,
  623. criteria: '_id == ?',
  624. bindParams: [this._id],
  625. permission: permission,
  626. options: options
  627. }, dfd, {});
  628. return dfd.promise();
  629. },
  630. /**
  631. * @return {$.Promise} .
  632. */
  633. remove: function() {
  634. var dfd = new $.Deferred();
  635. var col = this._collection;
  636. monaca.cloud._post('Collection.delete', {
  637. collectionName: col.name,
  638. itemOid: this._id,
  639. }, dfd, {});
  640. return dfd.promise();
  641. },
  642. 'delete': function() {
  643. return this.remove();
  644. }
  645. };
  646. return MonacaCloudCollectionItem;
  647. })();
  648. monaca.cloud.CollectionItem = function(item, collection) {
  649. return new MonacaCloudCollectionItem(item, collection);
  650. };
  651. })(window);
  652. /*
  653. * Collection
  654. */
  655. (function(root) {
  656. var monaca = root.monaca = root.monaca || {};
  657. monaca.cloud = monaca.cloud || {};
  658. var $ = monaca.cloud.$;
  659. /**
  660. * @class
  661. */
  662. MonacaCloudCollection = (function() {
  663. function MonacaCloudCollection(name) {
  664. this.name = name;
  665. }
  666. MonacaCloudCollection.prototype = {
  667. /**
  668. * @param {Object|Array} items .
  669. * @return {Array} result .
  670. */
  671. _makeCollectionItem: function(items) {
  672. var result = [];
  673. if (items instanceof Array) {
  674. for (var i = 0; i < items.length; i++) {
  675. result[i] = monaca.cloud.CollectionItem(items[i], this);
  676. }
  677. } else {
  678. result = monaca.cloud.CollectionItem(items, this);
  679. }
  680. return result;
  681. },
  682. /**
  683. * @param {Criteria|Array} criteria .
  684. */
  685. _validateCriteria: function(criteria) {
  686. if ((typeof(criteria) === 'undefined') || (typeof(criteria) === 'null')) {
  687. criteria = monaca.cloud.Criteria('');
  688. } else if (typeof(criteria) === 'string') {
  689. criteria = monaca.cloud.Criteria(criteria);
  690. }
  691. return criteria;
  692. },
  693. /**
  694. * @param {Object|Array} orderBy .
  695. * @param {Object} options .
  696. */
  697. _validateOptions: function(orderBy, options) {
  698. //if orderBy is hash, consider it as "options"
  699. if ((typeof(orderBy) === 'object') && (typeof(orderBy.length) === 'undefined')) {
  700. options = orderBy;
  701. if (typeof(options.orderBy) !== 'undefined') {
  702. orderBy = orderBy.orderBy;
  703. } else {
  704. orderBy = null;
  705. }
  706. }
  707. if (orderBy === '') {
  708. orderBy = null;
  709. }
  710. return {
  711. orderBy: orderBy,
  712. options: options
  713. };
  714. },
  715. /**
  716. * @param {Criteria|String} criteria .
  717. * @param {String|Array} [orderBy] .
  718. * @param {Object} [options] .
  719. * @return {$.Promise} .
  720. */
  721. find: function(criteria, orderBy, options) {
  722. var self = this;
  723. var dfd = new $.Deferred();
  724. criteria = self._validateCriteria(criteria);
  725. var o = self._validateOptions(orderBy, options);
  726. monaca.cloud._post('Collection.find', {
  727. collectionName: this.name,
  728. criteria: criteria.query,
  729. bindParams: criteria.bindParams,
  730. orderBy: o.orderBy,
  731. options: o.options
  732. }, dfd, {},
  733. function(e, status, xhr, dfd) {
  734. e.result.items = self._makeCollectionItem(e.result.items);
  735. dfd.resolve(e.result);
  736. });
  737. return dfd.promise();
  738. },
  739. /**
  740. * @param {Criteria|String} criteria .
  741. * @param {String|Array} [orderBy] .
  742. * @param {Object} [options] .
  743. * @return {$.Promise} .
  744. */
  745. findMine: function(criteria, orderBy, options) {
  746. var self = this;
  747. var dfd = new $.Deferred();
  748. criteria = self._validateCriteria(criteria);
  749. var o = self._validateOptions(orderBy, options);
  750. var userOid = monaca.cloud.User._oid;
  751. if (criteria.query != '') {
  752. criteria.query = '(' + criteria.query + ') && ';
  753. }
  754. if (userOid != null) {
  755. criteria.query += '(_ownerUserOid == ?)';
  756. criteria.bindParams.push(userOid);
  757. } else {
  758. criteria.query += '(_ownerDeviceOid == ?)';
  759. criteria.bindParams.push(monaca.cloud.deviceId);
  760. }
  761. monaca.cloud._post('Collection.find', {
  762. collectionName: this.name,
  763. criteria: criteria.query,
  764. bindParams: criteria.bindParams,
  765. orderBy: o.orderBy,
  766. options: o.options
  767. }, dfd, {},
  768. function(e, status, xhr, dfd) {
  769. e.result.items = self._makeCollectionItem(e.result.items);
  770. dfd.resolve(e.result);
  771. });
  772. return dfd.promise();
  773. },
  774. /**
  775. * @param {Criteria|String} criteria .
  776. * @param {String|Array} [orderBy] .
  777. * @param {Object} [options] .
  778. * @return {$.Promise} .
  779. */
  780. findOne: function(criteria, orderBy, options) {
  781. var self = this;
  782. var dfd = new $.Deferred();
  783. criteria = self._validateCriteria(criteria);
  784. var o = self._validateOptions(orderBy, options);
  785. monaca.cloud._post('Collection.find', {
  786. collectionName: this.name,
  787. criteria: criteria.query,
  788. bindParams: criteria.bindParams,
  789. orderBy: o.orderBy,
  790. options: o.options
  791. }, dfd, {},
  792. function(e, status, xhr, dfd) {
  793. var result = (e.result.totalItems > 0) ? self._makeCollectionItem(e.result.items[0]) : null;
  794. dfd.resolve(result);
  795. });
  796. return dfd.promise();
  797. },
  798. /**
  799. * @param {Criteria|String} criteria .
  800. * @param {String|Array} [orderBy] .
  801. * @param {Object} [options] .
  802. * @return {$.Promise} .
  803. */
  804. findOneMine: function(criteria, orderBy, options) {
  805. var self = this;
  806. var dfd = new $.Deferred();
  807. criteria = self._validateCriteria(criteria);
  808. var o = self._validateOptions(orderBy, options);
  809. var userOid = monaca.cloud.User._oid;
  810. if (criteria.query != '') {
  811. criteria.query = '(' + criteria.query + ') && ';
  812. }
  813. if (userOid != null) {
  814. criteria.query += '(_ownerUserOid == ?)';
  815. criteria.bindParams.push(userOid);
  816. } else {
  817. criteria.query += '(_ownerDeviceOid == ?)';
  818. criteria.bindParams.push(monaca.cloud.deviceId);
  819. }
  820. monaca.cloud._post('Collection.find', {
  821. collectionName: this.name,
  822. criteria: criteria.query,
  823. bindParams: criteria.bindParams,
  824. orderBy: o.orderBy,
  825. options: o.options
  826. }, dfd, {},
  827. function(e, status, xhr, dfd) {
  828. var result = (e.result.totalItems > 0) ? self._makeCollectionItem(e.result.items[0]) : null;
  829. dfd.resolve(result);
  830. });
  831. return dfd.promise();
  832. },
  833. /**
  834. * @param {Object} item .
  835. * @param {Object} [permission] .
  836. * @return {$.Promise} .
  837. */
  838. insert: function(item, permission) {
  839. var self = this;
  840. var dfd = new $.Deferred();
  841. if (typeof(permission) === 'undefined') {
  842. permission = {};
  843. }
  844. monaca.cloud._post('Collection.insert', {
  845. collectionName: this.name,
  846. item: item,
  847. permission: permission
  848. }, dfd, {},
  849. function(e, status, xhr, dfd) {
  850. var item = self._makeCollectionItem(e.result.item);
  851. dfd.resolve(item);
  852. });
  853. return dfd.promise();
  854. },
  855. /**
  856. * @param {Criteria|String} criteria .
  857. * @param {Object} permission .
  858. * @param {Object} [options] .
  859. * @return {$.Promise} .
  860. */
  861. updatePermission: function(criteria, permission, options) {
  862. var self = this;
  863. var dfd = new $.Deferred();
  864. criteria = self._validateCriteria(criteria);
  865. monaca.cloud._post('Collection.updatePermission', {
  866. collectionName: this.name,
  867. criteria: criteria.query,
  868. bindParams: criteria.bindParams,
  869. permission: permission,
  870. options: options
  871. }, dfd, {});
  872. return dfd.promise();
  873. }
  874. };
  875. return MonacaCloudCollection;
  876. })();
  877. monaca.cloud.Collection = function(name) {
  878. return new MonacaCloudCollection(name);
  879. };
  880. })(window);
  881. /*
  882. * Criteria
  883. */
  884. (function(root) {
  885. var monaca = root.monaca = root.monaca || {};
  886. monaca.cloud = monaca.cloud || {};
  887. var $ = monaca.cloud.$;
  888. /**
  889. * @class
  890. */
  891. MonacaCloudCriteria = (function() {
  892. function MonacaCloudCriteria(query, bindParams) {
  893. this.query = query;
  894. this.bindParams = (typeof(bindParams) !== 'undefined') ? bindParams : [];
  895. }
  896. return MonacaCloudCriteria;
  897. })();
  898. monaca.cloud.Criteria = function(query, bindParams) {
  899. return new MonacaCloudCriteria(query, bindParams);
  900. };
  901. })(window);
  902. /*
  903. * Device
  904. */
  905. (function(root) {
  906. var monaca = root.monaca = root.monaca || {};
  907. monaca.cloud = monaca.cloud || {};
  908. var $ = monaca.cloud.$;
  909. /**
  910. * @class
  911. */
  912. monaca.cloud.Device = {
  913. /**
  914. * @param {String} name .
  915. * @return {$.Promise} .
  916. */
  917. getProperty: function(name) {
  918. var dfd = new $.Deferred();
  919. monaca.cloud._post('Device.getProperties', {
  920. names: [name]
  921. }, dfd, {},
  922. function(e, status, xhr, dfd) {
  923. dfd.resolve(e.result.properties[name]);
  924. }
  925. );
  926. return dfd.promise();
  927. },
  928. /**
  929. * @param {Array} names .
  930. * @return {$.Promise} .
  931. */
  932. getProperties: function(names) {
  933. var dfd = new $.Deferred();
  934. monaca.cloud._post('Device.getProperties', {
  935. names: names
  936. }, dfd, {},
  937. function(e, status, xhr, dfd) {
  938. dfd.resolve(e.result.properties);
  939. }
  940. );
  941. return dfd.promise();
  942. },
  943. /**
  944. * @param {String} name .
  945. * @param {String} value .
  946. * @return {$.Promise} .
  947. */
  948. saveProperty: function(name, value) {
  949. var dfd = new $.Deferred();
  950. var param = {};
  951. if ((typeof(name) !== 'undefined') && (typeof(value) !== 'undefined')) {
  952. param = {
  953. properties: {}
  954. };
  955. param.properties[name] = value;
  956. }
  957. monaca.cloud._post('Device.saveProperties', param, dfd);
  958. return dfd.promise();
  959. },
  960. /**
  961. * @param {Object} properties .
  962. * @return {$.Promise} .
  963. */
  964. saveProperties: function(properties) {
  965. var dfd = new $.Deferred();
  966. var param = {};
  967. if (typeof(properties) !== 'undefined') param.properties = properties;
  968. monaca.cloud._post('Device.saveProperties', param, dfd);
  969. return dfd.promise();
  970. }
  971. };
  972. })(window);
  973. /*
  974. * Mailer
  975. */
  976. (function(root) {
  977. var monaca = root.monaca = root.monaca || {};
  978. monaca.cloud = monaca.cloud || {};
  979. var $ = monaca.cloud.$;
  980. /**
  981. * @class
  982. */
  983. monaca.cloud.Mailer = {
  984. /**
  985. * @param {String} userOid .
  986. * @param {String} templateName .
  987. * @param {Object} substituteParams .
  988. * @param {Object} [options] .
  989. * @return {$.Promise} .
  990. */
  991. sendMail: function(userOid, templateName, substituteParams, options) {
  992. var dfd = new $.Deferred();
  993. if (typeof(options) === 'undefined') {
  994. options = {};
  995. }
  996. monaca.cloud._post('Mailer.sendMail', {
  997. userOid: userOid,
  998. templateName: templateName,
  999. substituteParams: substituteParams,
  1000. options: options
  1001. }, dfd);
  1002. return dfd.promise();
  1003. }
  1004. };
  1005. })(window);
  1006. /*
  1007. * User
  1008. */
  1009. (function(root) {
  1010. var monaca = root.monaca = root.monaca || {};
  1011. monaca.cloud = monaca.cloud || {};
  1012. var $ = monaca.cloud.$;
  1013. /**
  1014. * @class
  1015. */
  1016. monaca.cloud.User = (function() {
  1017. return {
  1018. _oid: null,
  1019. /**
  1020. * @return {Boolean} .
  1021. */
  1022. isAuthenticated: function() {
  1023. return (this._oid === null) ? false : true;
  1024. },
  1025. /**
  1026. * @param {String} username .
  1027. * @param {String} password .
  1028. * @param {Object} [properties] .
  1029. * @return {$.Promise} .
  1030. */
  1031. register: function(username, password, properties) {
  1032. var dfd = new $.Deferred();
  1033. var self = this;
  1034. if (typeof(properties) === 'undefined') properties = {};
  1035. monaca.cloud._post('User.register', {
  1036. username: username,
  1037. password: password,
  1038. properties: properties
  1039. }, dfd, {},
  1040. function(jsonResponse) {
  1041. self._oid = jsonResponse.result.user._id;
  1042. }
  1043. );
  1044. return dfd.promise();
  1045. },
  1046. /**
  1047. * @param {String} username .
  1048. * @param {Object} properties .
  1049. * @return {$.Promise} .
  1050. */
  1051. validate: function(username, properties) {
  1052. var dfd = new $.Deferred();
  1053. monaca.cloud._post('User.validate', {
  1054. username: username,
  1055. properties: properties
  1056. }, dfd);
  1057. return dfd.promise();
  1058. },
  1059. /**
  1060. * @param {String} password .
  1061. * @return {$.Promise} .
  1062. */
  1063. unregister: function(password) {
  1064. var self = this,
  1065. dfd = new $.Deferred();
  1066. monaca.cloud._post('User.unregister', {
  1067. password: password
  1068. }, dfd, {},
  1069. function() {
  1070. self._oid = null;
  1071. monaca.cloud._setSessionId('');
  1072. localStorage.removeItem('monacaCloudLoginToken');
  1073. }
  1074. );
  1075. return dfd.promise();
  1076. },
  1077. /**
  1078. * @param {String} username .
  1079. * @param {String} password .
  1080. * @return {$.Promise} .
  1081. */
  1082. login: function(username, password) {
  1083. var self = this,
  1084. dfd = new $.Deferred();
  1085. monaca.cloud._post('User.login', {
  1086. username: username,
  1087. password: password
  1088. }, dfd, {},
  1089. function(jsonResponse) {
  1090. self._oid = jsonResponse.result.user._id;
  1091. }
  1092. );
  1093. return dfd.promise();
  1094. },
  1095. /**
  1096. * @return {$.Promise} .
  1097. */
  1098. autoLogin: function() {
  1099. var dfd = new $.Deferred();
  1100. var token = localStorage.monacaCloudLoginToken || '';
  1101. var self = this;
  1102. monaca.cloud._post('User.autoLogin', {
  1103. loginToken: token
  1104. }, dfd, {},
  1105. function(jsonResponse) {
  1106. self._oid = jsonResponse.result.user._id;
  1107. }
  1108. );
  1109. return dfd.promise();
  1110. },
  1111. /**
  1112. * @return {$.Promise} .
  1113. */
  1114. logout: function() {
  1115. var self = this,
  1116. dfd = new $.Deferred();
  1117. monaca.cloud._post('User.logout', {}, dfd, {},
  1118. function() {
  1119. self._oid = null;
  1120. monaca.cloud._setSessionId('');
  1121. localStorage.removeItem('monacaCloudLoginToken');
  1122. }
  1123. );
  1124. return dfd.promise();
  1125. },
  1126. /**
  1127. * @param {String} oldPassword .
  1128. * @param {String} newPassword .
  1129. * @return {$.Promise} .
  1130. */
  1131. updatePassword: function(oldPassword, newPassword) {
  1132. var dfd = new $.Deferred();
  1133. monaca.cloud._post('User.updatePassword', {
  1134. oldPassword: oldPassword,
  1135. newPassword: newPassword
  1136. }, dfd);
  1137. return dfd.promise();
  1138. },
  1139. /**
  1140. * @param {String} username .
  1141. * @param {Object} options .
  1142. * @return {$.Promise} .
  1143. */
  1144. sendPasswordResetToken: function(username, options) {
  1145. var dfd = new $.Deferred();
  1146. monaca.cloud._post('User.sendPasswordResetToken', {
  1147. username: username,
  1148. options: options
  1149. }, dfd);
  1150. return dfd.promise();
  1151. },
  1152. /**
  1153. * @param {String} username .
  1154. * @param {String} newPassword .
  1155. * @param {String} token .
  1156. * @return {$.Promise} .
  1157. */
  1158. resetPasswordAndLogin: function(username, newPassword, token) {
  1159. var dfd = new $.Deferred();
  1160. var self = this;
  1161. monaca.cloud._post('User.resetPasswordAndLogin', {
  1162. username: username,
  1163. newPassword: newPassword,
  1164. token: token
  1165. }, dfd, {},
  1166. function(jsonResponse) {
  1167. self._oid = jsonResponse.result.user._id;
  1168. }
  1169. );
  1170. return dfd.promise();
  1171. },
  1172. /**
  1173. * @param {String} name .
  1174. * @return {$.Promise} .
  1175. */
  1176. getProperty: function(name) {
  1177. var dfd = new $.Deferred();
  1178. monaca.cloud._post('User.getProperties', {
  1179. names: [name]
  1180. }, dfd, {},
  1181. function(e, status, xhr, dfd) {
  1182. dfd.resolve(e.result.properties[name]);
  1183. }
  1184. );
  1185. return dfd.promise();
  1186. },
  1187. /**
  1188. * @param {Array} names .
  1189. * @return {$.Promise} .
  1190. */
  1191. getProperties: function(names) {
  1192. var dfd = new $.Deferred();
  1193. monaca.cloud._post('User.getProperties', {
  1194. names: names
  1195. }, dfd, {},
  1196. function(e, status, xhr, dfd) {
  1197. dfd.resolve(e.result.properties);
  1198. }
  1199. );
  1200. return dfd.promise();
  1201. },
  1202. /**
  1203. * @param {String} name .
  1204. * @param {String} value .
  1205. * @return {$.Promise} .
  1206. */
  1207. saveProperty: function(name, value) {
  1208. var dfd = new $.Deferred();
  1209. var param = {};
  1210. if (typeof(name) !== 'undefined') {
  1211. param = {
  1212. properties: {}
  1213. };
  1214. param.properties[name] = value;
  1215. }
  1216. monaca.cloud._post('User.saveProperties', param, dfd);
  1217. return dfd.promise();
  1218. },
  1219. /**
  1220. * @param {Object} properties .
  1221. * @return {$.Promise} .
  1222. */
  1223. saveProperties: function(properties) {
  1224. var dfd = new $.Deferred();
  1225. var param = {};
  1226. if (typeof(properties) !== 'undefined') param.properties = properties;
  1227. monaca.cloud._post('User.saveProperties', param, dfd);
  1228. return dfd.promise();
  1229. }
  1230. };
  1231. })();
  1232. })(window);
  1233. ;
  1234. /*** <End:monaca-core-utils LoadJs:"components/monaca-core-utils/monaca-core-utils.js"> ***/
  1235. /*** <End:monaca-core-utils> ***/