Keine Beschreibung

monaca-core-utils.js 62KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415
  1. /**
  2. * Monaca Core Utility Library
  3. * This library requires cordova.js
  4. *
  5. * @version 2.0.7
  6. * @author Asial Corporation
  7. */
  8. window.monaca = window.monaca || {};
  9. (function() {
  10. /*
  11. * monaca api queue.
  12. */
  13. monaca.apiQueue = monaca.apiQueue || {};
  14. monaca.apiQueue.paramsArray = [];
  15. monaca.apiQueue.exec = function(a,b,c,d,e){
  16. if (!monaca.isDeviceReady) {
  17. monaca.apiQueue.paramsArray.push([a,b,c,d,e]);
  18. } else {
  19. window.cordova.exec(a,b,c,d,e);
  20. }
  21. };
  22. monaca.apiQueue.next = function(){
  23. var params = monaca.apiQueue.paramsArray.shift();
  24. if (params) {
  25. window.cordova.exec(
  26. function(r) {
  27. if (typeof params[0] === 'function') params[0](r);
  28. monaca.apiQueue.next();
  29. },
  30. function(r) {
  31. if (typeof params[1] === 'function') params[1](r);
  32. monaca.apiQueue.next();
  33. },
  34. params[2],
  35. params[3],
  36. params[4]
  37. );
  38. }
  39. };
  40. monaca.isDeviceReady = monaca.isDeviceReady || false;
  41. document.addEventListener('deviceready', function(){
  42. window.monaca.isDeviceReady = true;
  43. monaca.apiQueue.next();
  44. }, false);
  45. /**
  46. * Check User-Agent
  47. */
  48. var isAndroid = !!(navigator.userAgent.match(/Android/i));
  49. var isIOS = !!(navigator.userAgent.match(/iPhone|iPad|iPod/i));
  50. monaca.isAndroid = isAndroid;
  51. monaca.isIOS = isIOS;
  52. /**
  53. * Obtain style property
  54. */
  55. monaca.retrieveUIStyle = function() {
  56. var argsArray = [].slice.apply(arguments);
  57. monaca.apiQueue.exec(arguments[arguments.length-1], null, "mobi.monaca.nativecomponent", "retrieve", argsArray);
  58. };
  59. /**
  60. * Update style property
  61. */
  62. monaca.updateUIStyle = function(id, name, value) {
  63. if (typeof id == "string") {
  64. var argsArray = [].slice.apply(arguments);
  65. monaca.apiQueue.exec(null, null, "mobi.monaca.nativecomponent", "update", argsArray);
  66. } else {
  67. for (var i = 0; i < id.length; i++) {
  68. monaca.apiQueue.exec(null, null, "mobi.monaca.nativecomponent", "update", [id[i], name, value]);
  69. }
  70. }
  71. };
  72. if (isAndroid) {
  73. monaca.retrieveUIStyle = function(id, name, success, failure) {
  74. monaca.apiQueue.exec(
  75. function(style) { success(style[name]); } || function() { },
  76. failure || function() { },
  77. "mobi.monaca.nativecomponent",
  78. "retrieve",
  79. [id]
  80. );
  81. };
  82. monaca.updateUIStyle = function(id, name, value, success, failure) {
  83. var style = {};
  84. style[name] = value;
  85. monaca.apiQueue.exec(
  86. success || function() { },
  87. failure || function() { },
  88. "mobi.monaca.nativecomponent",
  89. "update",
  90. [id, style]
  91. );
  92. };
  93. }
  94. /**
  95. * Spinner handling
  96. */
  97. monaca.showSpinner = function (options) {
  98. options = options || {};
  99. var src = options.src ? options.src : null;
  100. var frames = options.frames != null ? options.frames : null;
  101. var interval = options.interval != null ? options.interval : null;
  102. var backgroundColor = options.backgroundColor ? options.backgroundColor : null;
  103. var backgroundOpacity = options.backgroundOpacity != null ? options.backgroundOpacity : null;
  104. var title = options.title ? options.title : null;
  105. var titleColor = options.titleColor ? options.titleColor : null;
  106. var titleFontScale = options.titleFontScale != null ? options.titleFontScale : null;
  107. monaca.apiQueue.exec(null, null, "mobi.monaca.nativecomponent", 'showSpinner', [ src, frames, interval, backgroundColor, backgroundOpacity, title, titleColor, titleFontScale, null ]);
  108. };
  109. monaca.hideSpinner = function(){
  110. monaca.apiQueue.exec(null, null, "mobi.monaca.nativecomponent", 'hideSpinner', []);
  111. };
  112. monaca.updateSpinnerTitle = function(newTitle){
  113. if (!newTitle) newTitle = "";
  114. monaca.apiQueue.exec(null, null, "mobi.monaca.nativecomponent", 'updateSpinnerTitle', [ newTitle ]);
  115. };
  116. var transitionPluginName = "Transit";
  117. /**
  118. * Open new page.
  119. */
  120. monaca.pushPage = function(path, options, param) {
  121. options = options || {};
  122. var animation = null;
  123. switch (options.animation) {
  124. case "lift":
  125. animation = "modal"; break;
  126. case "slide":
  127. case "slideLeft":
  128. animation = "push"; break;
  129. case "slideRight":
  130. animation = "slideRight"; break;
  131. default:
  132. animation = "push";
  133. }
  134. monaca.apiQueue.exec(null, null, transitionPluginName, animation, [path, options, param]);
  135. };
  136. /**
  137. * Close current page.
  138. */
  139. monaca.popPage = function(options) {
  140. options = options || {};
  141. var name = options.animation == 'lift' ? 'dismiss' : 'pop';
  142. monaca.apiQueue.exec(null, null, transitionPluginName, name, [options]);
  143. };
  144. /**
  145. * Open in browser.
  146. */
  147. monaca.invokeBrowser = function(url) {
  148. monaca.apiQueue.exec(null, null, transitionPluginName, "browse", [url]);
  149. };
  150. /**
  151. * Load in current page.
  152. */
  153. monaca.load = function(path, options, param) {
  154. monaca.apiQueue.exec(null, null, transitionPluginName, "link", [path, options, param]);
  155. };
  156. /**
  157. * return to top page.
  158. */
  159. monaca.home = function(options) {
  160. options = options || {};
  161. monaca.apiQueue.exec(null, null, transitionPluginName, "home", [options]);
  162. };
  163. /**
  164. * Clear stack
  165. */
  166. monaca.clearPageStack = function(clearAll) {
  167. clearAll = clearAll || false;
  168. monaca.apiQueue.exec(null, null, transitionPluginName, "clearPageStack", [clearAll]);
  169. };
  170. /**
  171. * Console API from independent PhoneGap.
  172. */
  173. window.monaca.console = window.monaca.console || {};
  174. /**
  175. * base method for send log.
  176. */
  177. monaca.console.sendLog = function(level, url, line, char, arguments) {
  178. var message;
  179. for (var i=0; i<arguments.length; i++){
  180. if (typeof arguments[i] == "string") {
  181. message = arguments[i];
  182. } else {
  183. message = JSON.stringify(arguments[i]);
  184. }
  185. if (message === undefined) {
  186. message = "undefined";
  187. }
  188. if (isIOS) {
  189. // not checked yet or confirmed MonacaDebugger
  190. if (! monaca.isMonacaDebuggerChecked || monaca.isMonacaDebugger ) {
  191. var head = message.substr(0, 5);
  192. if (window.monaca.isDeviceReady !== true || (head != 'ERROR' && head != 'WARN:')) {
  193. var xhr = new XMLHttpRequest();
  194. var path = "https://monaca-debugger.local/log?level=" + encodeURIComponent(level) + "&message=" + encodeURIComponent(message) + "&at=" + (new Date()).getTime();
  195. xhr.open("GET", path);
  196. xhr.send();
  197. }
  198. }
  199. window.orig_console[level](message);
  200. } else {
  201. window.console[level](message);
  202. }
  203. }
  204. }
  205. /**
  206. * monaca console methods
  207. */
  208. var methods = ["debug", "info", "log", "warn", "error"];
  209. for (var i=0; i<methods.length; i++) {
  210. var method = methods[i];
  211. monaca.console[method] = function(method) {
  212. return function() {
  213. monaca.console.sendLog(method, null, null, null, arguments);
  214. };
  215. }(method);
  216. }
  217. /** Replace window.console if iOS **/
  218. if (isIOS) {
  219. window.orig_console = window.console;
  220. window.console = window.monaca.console;
  221. window.addEventListener( "error" , function (desc, page, line, char) {
  222. monaca.console.sendLog("error", null, null, null, [ { "message" : desc.message , "page" : desc.filename , "line" : desc.lineno , "char" : desc.colno } ]);
  223. } , false );
  224. // window.onerror = function (desc, page, line, char) {
  225. // monaca.console.sendLog("error", page, line, char, [ { "message" : desc , "page" : page , "line" : line, "char" : char } ] );
  226. // };
  227. }
  228. /* Comment out for now
  229. window.onerror = function (desc, page, line, char) {
  230. monaca.console.sendLog("error", page, line, char, [desc]);
  231. };
  232. */
  233. window.monaca.splashScreen = window.monaca.splashScreen || {};
  234. var splashScreenPluginName = "MonacaSplashScreen";
  235. /**
  236. * hide SplashScreen.
  237. */
  238. monaca.splashScreen.hide = function() {
  239. if (isAndroid) {
  240. monaca.apiQueue.exec(null, null, splashScreenPluginName, "hide", []);
  241. } else {
  242. navigator.splashscreen.hide();
  243. }
  244. };
  245. // Set monaca.baseUrl
  246. if (typeof location.href !== "string") {
  247. console.warn("Cannot find base url");
  248. monaca.baseUrl = null;
  249. } else {
  250. monaca.baseUrl = location.href.split("/www/")[0] + "/www/";
  251. }
  252. /**
  253. * Get device ID
  254. */
  255. monaca.getDeviceId = function(callback) {
  256. monaca.apiQueue.exec(function(result) { callback(result.deviceId); }, null, "Monaca", "getRuntimeConfiguration", []);
  257. };
  258. monaca.getRuntimeConfiguration = function(success,failure) {
  259. monaca.apiQueue.exec( success , failure , "Monaca" , "getRuntimeConfiguration" , []);
  260. };
  261. monaca.isMonacaDebuggerChecked = false;
  262. monaca.isMonacaDebugger = null;
  263. monaca.getRuntimeConfiguration( function(result) {
  264. monaca.isMonacaDebuggerChecked = true;
  265. monaca.isMonacaDebugger = !! result.isMonacaDebugger;
  266. });
  267. })();
  268. /**
  269. * iOS Status Bar Plugin
  270. *
  271. * @author Asial Corporation
  272. * @date 2014/1/15
  273. */
  274. window.StatusBar = window.StatusBar || {};
  275. (function() {
  276. /*
  277. hideStatusBar
  278. support : iOS6,iOS7
  279. */
  280. StatusBar.hideStatusBar = function() {
  281. monaca.apiQueue.exec(null, null, "mobi.monaca.nativecomponent", 'hideStatusBar', []);
  282. }
  283. /*
  284. showStatusBar
  285. support : iOS6,iOS7
  286. */
  287. StatusBar.showStatusBar = function() {
  288. monaca.apiQueue.exec(null, null, "mobi.monaca.nativecomponent", 'showStatusBar', []);
  289. }
  290. /*
  291. statusBarStyleDefault
  292. support : iOS6,iOS7
  293. */
  294. StatusBar.statusBarStyleDefault = function() {
  295. monaca.apiQueue.exec(null, null, "mobi.monaca.nativecomponent", 'statusBarStyleDefault', []);
  296. }
  297. /*
  298. statusBarStyleLightContent
  299. support : iOS7
  300. */
  301. StatusBar.statusBarStyleLightContent = function() {
  302. monaca.apiQueue.exec(null, null, "mobi.monaca.nativecomponent", 'statusBarStyleLightContent', []);
  303. }
  304. /*
  305. statusBarStyleBlackOpaque
  306. support : iOS6
  307. */
  308. StatusBar.statusBarStyleBlackOpaque = function() {
  309. monaca.apiQueue.exec(null, null, "mobi.monaca.nativecomponent", 'statusBarStyleBlackOpaque', []);
  310. }
  311. /*
  312. statusBarStyleBlackTranslucent
  313. support : iOS6
  314. */
  315. StatusBar.statusBarStyleBlackTranslucent = function() {
  316. monaca.apiQueue.exec(null, null, "mobi.monaca.nativecomponent", 'statusBarStyleBlackTranslucent', []);
  317. }
  318. })();
  319. /**
  320. * Monaca Cloud Functions
  321. * Version 1.5.0
  322. *
  323. * @author Masahiro TANAKA <info@monaca.mobi>
  324. * @date 2013/03/17
  325. */
  326. window.monaca = window.monaca || {};
  327. window.monaca.cloud = window.monaca.cloud || {};
  328. (function() {
  329. /**
  330. * Push Notification
  331. */
  332. monaca.cloud.Push = {};
  333. monaca.cloud.Push.callback = null;
  334. monaca.cloud.Push.callbackData = null;
  335. monaca.cloud.Push.send = function(data) {
  336. if (typeof monaca.cloud.Push.callback === "function") {
  337. monaca.cloud.Push.callback(data);
  338. } else {
  339. monaca.cloud.Push.callbackData = data;
  340. }
  341. };
  342. monaca.cloud.Push.setHandler = function(fn) {
  343. if (typeof fn !== "function") {
  344. console.warn("Push callback must be a function");
  345. } else {
  346. monaca.cloud.Push.callback = fn;
  347. if (monaca.cloud.Push.callbackData) {
  348. monaca.cloud.Push.callback(monaca.cloud.Push.callbackData);
  349. monaca.cloud.Push.callbackData = null;
  350. }
  351. }
  352. };
  353. })();
  354. /*
  355. * cloud
  356. */
  357. (function(root) {
  358. var original$ = root.$;
  359. var originalZepto = root.Zepto;
  360. /* Zepto 1.1.3 - zepto event ajax deferred callbacks - zeptojs.com/license */
  361. 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);
  362. root.$ = original$;
  363. root.Zepto = originalZepto;
  364. var monaca = root.monaca = root.monaca || {};
  365. monaca.cloud = monaca.cloud || {};
  366. monaca.cloud.timeout = 30000;
  367. monaca.cloud.url = '%%%CLOUD_HOST%%%';
  368. monaca.cloud.backendId = '%%%BACKEND_ID%%%';
  369. monaca.cloud.apiKey = '%%%BACKEND_API_KEY%%%';
  370. monaca.cloud.deviceId = null;
  371. monaca.cloud.postQueue = [];
  372. /**
  373. * @property {jQuery} .
  374. */
  375. monaca.cloud.$ = Zepto;
  376. var MonacaCloudError = (function() {
  377. function MonacaCloudError(code, message, data) {
  378. if (typeof data === "undefined") {
  379. data = {};
  380. }
  381. this.code = code;
  382. this.message = message;
  383. this.data = data;
  384. }
  385. return MonacaCloudError;
  386. })();
  387. /**
  388. * @class
  389. */
  390. monaca.cloud.Error = function(code, message, data) {
  391. return new MonacaCloudError(code, message, data);
  392. };
  393. /**
  394. * @param {Number} msec .
  395. */
  396. monaca.cloud.setTimeout = function(msec) {
  397. this.timeout = msec;
  398. };
  399. // Get device id
  400. document.addEventListener("deviceready", function() {
  401. cordova.exec(function(result) {
  402. monaca.cloud.deviceId = new String(result.deviceId);
  403. monaca.cloud.url = new String(result.url);
  404. monaca.cloud.backendId = new String(result.backendId);
  405. monaca.cloud.apiKey = new String(result.apiKey);
  406. // execute and clear postQueue
  407. for (var i = 0; i < monaca.cloud.postQueue.length; i++) {
  408. monaca.cloud._doPost.apply(monaca.cloud, monaca.cloud.postQueue[i]);
  409. }
  410. monaca.cloud.postQueue = [];
  411. }, function(error) {
  412. console.error(error);
  413. },
  414. "Monaca",
  415. "getRuntimeConfiguration", []
  416. );
  417. }, false);
  418. // Others
  419. monaca.cloud._post = function(method, params, dfd, ajaxOptions, beforeSuccess) {
  420. if (monaca.cloud.deviceId == null) {
  421. monaca.cloud.postQueue.push([method, params, dfd, ajaxOptions, beforeSuccess]);
  422. } else {
  423. monaca.cloud._doPost(method, params, dfd, ajaxOptions, beforeSuccess);
  424. }
  425. };
  426. monaca.cloud._doPost = function(method, params, dfd, ajaxOptions, beforeSuccess) {
  427. var $ = monaca.cloud.$;
  428. if (typeof(ajaxOptions) === 'undefined') ajaxOptions = {};
  429. if ((typeof(method) === 'undefined') && (typeof(params) === 'undefined')) {
  430. throw new Error('Invalid arguments');
  431. }
  432. params['__api_key'] = monaca.cloud.apiKey;
  433. params['__device'] = monaca.cloud.deviceId;
  434. var sid = monaca.cloud._getSessionId();
  435. if (sid.length > 0) {
  436. params['__session'] = sid;
  437. }
  438. var data = JSON.stringify({
  439. jsonrpc: '2.0',
  440. method: method,
  441. params: params,
  442. id: '1'
  443. });
  444. var o = $.extend(true, {
  445. url: this.url + this.backendId,
  446. data: data,
  447. dataType: 'json',
  448. type: 'POST',
  449. timeout: this.timeout,
  450. success: function(jsonResponse, status, xhr) {
  451. var sessionHeader = xhr.getResponseHeader('X-Set-Monaca-Cloud-Session');
  452. if (sessionHeader) {
  453. monaca.cloud._setSessionId(sessionHeader);
  454. }
  455. if (typeof(jsonResponse.error) !== 'undefined') {
  456. // has error code
  457. dfd.reject(jsonResponse.error);
  458. } else {
  459. // success
  460. if (typeof(jsonResponse.result.loginToken) !== 'undefined') {
  461. localStorage.monacaCloudLoginToken = jsonResponse.result.loginToken;
  462. }
  463. if (typeof(beforeSuccess) !== 'undefined') {
  464. beforeSuccess(jsonResponse, status, xhr, dfd);
  465. }
  466. dfd.resolve(jsonResponse.result);
  467. }
  468. },
  469. error: function(xhr, status) {
  470. switch (status) {
  471. case 'timeout':
  472. var err = monaca.cloud.Error(-11, 'Connection timeout');
  473. break;
  474. case 'parsererror':
  475. var err = monaca.cloud.Error(-12, 'Invalid response');
  476. break;
  477. default:
  478. var err = monaca.cloud.Error(-13, 'Invalid status code');
  479. }
  480. dfd.reject(err);
  481. }
  482. }, ajaxOptions);
  483. $.ajax(o);
  484. };
  485. var _sessionId = '';
  486. monaca.cloud._getSessionId = function() {
  487. return _sessionId;
  488. };
  489. monaca.cloud._setSessionId = function(id) {
  490. if (typeof id != 'string') {
  491. id = '';
  492. }
  493. _sessionId = id;
  494. };
  495. })(window);
  496. /*
  497. * CollectionItem
  498. */
  499. (function(root) {
  500. var monaca = root.monaca = root.monaca || {};
  501. monaca.cloud = monaca.cloud || {};
  502. var $ = monaca.cloud.$;
  503. /**
  504. * @class
  505. */
  506. MonacaCloudCollectionItem = (function() {
  507. function MonacaCloudCollectionItem(item, collection) {
  508. /**
  509. * @property {String} .
  510. */
  511. this._id = item._id;
  512. /**
  513. * @property {String} .
  514. */
  515. this._ownerUserOid = item._ownerUserOid;
  516. /**
  517. * @property {Date} .
  518. */
  519. this._createdAt = new Date(item._createdAt);
  520. /**
  521. * @property {Date} .
  522. */
  523. this._updatedAt = new Date(item._updatedAt);
  524. /**
  525. * @property {MonacaCloudCollection} .
  526. */
  527. this._collection = collection;
  528. for (var key in item) {
  529. if (key.substr(0, 1) != '_') {
  530. this[key] = item[key];
  531. }
  532. }
  533. }
  534. MonacaCloudCollectionItem.prototype = {
  535. /**
  536. * @return {$.Promise} .
  537. */
  538. update: function() {
  539. var dfd = new $.Deferred();
  540. var col = this._collection;
  541. var data = {};
  542. for (var key in this) {
  543. if (key.indexOf('_') !== 0) {
  544. data[key] = this[key];
  545. }
  546. }
  547. monaca.cloud._post('Collection.update', {
  548. collectionName: col.name,
  549. itemOid: this._id,
  550. data: data,
  551. }, dfd, {});
  552. return dfd.promise();
  553. },
  554. /**
  555. * @return {$.Promise} .
  556. */
  557. getPermission: function() {
  558. var dfd = new $.Deferred();
  559. var col = this._collection;
  560. monaca.cloud._post('Collection.getPermission', {
  561. collectionName: col.name,
  562. itemOid: this._id
  563. }, dfd, {});
  564. return dfd.promise();
  565. },
  566. /**
  567. * @param {Object} permission .
  568. * @param {Object} [options] .
  569. * @return {$.Promise} .
  570. */
  571. updatePermission: function(permission, options) {
  572. var dfd = new $.Deferred();
  573. var col = this._collection;
  574. if (typeof(options) === 'undefined') {
  575. options = {};
  576. }
  577. monaca.cloud._post('Collection.updatePermission', {
  578. collectionName: col.name,
  579. criteria: '_id == ?',
  580. bindParams: [this._id],
  581. permission: permission,
  582. options: options
  583. }, dfd, {});
  584. return dfd.promise();
  585. },
  586. /**
  587. * @return {$.Promise} .
  588. */
  589. remove: function() {
  590. var dfd = new $.Deferred();
  591. var col = this._collection;
  592. monaca.cloud._post('Collection.delete', {
  593. collectionName: col.name,
  594. itemOid: this._id,
  595. }, dfd, {});
  596. return dfd.promise();
  597. },
  598. 'delete': function() {
  599. return this.remove();
  600. }
  601. };
  602. return MonacaCloudCollectionItem;
  603. })();
  604. monaca.cloud.CollectionItem = function(item, collection) {
  605. return new MonacaCloudCollectionItem(item, collection);
  606. };
  607. })(window);
  608. /*
  609. * Collection
  610. */
  611. (function(root) {
  612. var monaca = root.monaca = root.monaca || {};
  613. monaca.cloud = monaca.cloud || {};
  614. var $ = monaca.cloud.$;
  615. /**
  616. * @class
  617. */
  618. MonacaCloudCollection = (function() {
  619. function MonacaCloudCollection(name) {
  620. this.name = name;
  621. }
  622. MonacaCloudCollection.prototype = {
  623. /**
  624. * @param {Object|Array} items .
  625. * @return {Array} result .
  626. */
  627. _makeCollectionItem: function(items) {
  628. var result = [];
  629. if (items instanceof Array) {
  630. for (var i = 0; i < items.length; i++) {
  631. result[i] = monaca.cloud.CollectionItem(items[i], this);
  632. }
  633. } else {
  634. result = monaca.cloud.CollectionItem(items, this);
  635. }
  636. return result;
  637. },
  638. /**
  639. * @param {Criteria|Array} criteria .
  640. */
  641. _validateCriteria: function(criteria) {
  642. if ((typeof(criteria) === 'undefined') || (typeof(criteria) === 'null')) {
  643. criteria = monaca.cloud.Criteria('');
  644. } else if (typeof(criteria) === 'string') {
  645. criteria = monaca.cloud.Criteria(criteria);
  646. }
  647. return criteria;
  648. },
  649. /**
  650. * @param {Object|Array} orderBy .
  651. * @param {Object} options .
  652. */
  653. _validateOptions: function(orderBy, options) {
  654. //if orderBy is hash, consider it as "options"
  655. if ((typeof(orderBy) === 'object') && (typeof(orderBy.length) === 'undefined')) {
  656. options = orderBy;
  657. if (typeof(options.orderBy) !== 'undefined') {
  658. orderBy = orderBy.orderBy;
  659. } else {
  660. orderBy = null;
  661. }
  662. }
  663. if (orderBy === '') {
  664. orderBy = null;
  665. }
  666. return {
  667. orderBy: orderBy,
  668. options: options
  669. };
  670. },
  671. /**
  672. * @param {Criteria|String} criteria .
  673. * @param {String|Array} [orderBy] .
  674. * @param {Object} [options] .
  675. * @return {$.Promise} .
  676. */
  677. find: function(criteria, orderBy, options) {
  678. var self = this;
  679. var dfd = new $.Deferred();
  680. criteria = self._validateCriteria(criteria);
  681. var o = self._validateOptions(orderBy, options);
  682. monaca.cloud._post('Collection.find', {
  683. collectionName: this.name,
  684. criteria: criteria.query,
  685. bindParams: criteria.bindParams,
  686. orderBy: o.orderBy,
  687. options: o.options
  688. }, dfd, {},
  689. function(e, status, xhr, dfd) {
  690. e.result.items = self._makeCollectionItem(e.result.items);
  691. dfd.resolve(e.result);
  692. });
  693. return dfd.promise();
  694. },
  695. /**
  696. * @param {Criteria|String} criteria .
  697. * @param {String|Array} [orderBy] .
  698. * @param {Object} [options] .
  699. * @return {$.Promise} .
  700. */
  701. findMine: function(criteria, orderBy, options) {
  702. var self = this;
  703. var dfd = new $.Deferred();
  704. criteria = self._validateCriteria(criteria);
  705. var o = self._validateOptions(orderBy, options);
  706. var userOid = monaca.cloud.User._oid;
  707. if (criteria.query != '') {
  708. criteria.query = '(' + criteria.query + ') && ';
  709. }
  710. if (userOid != null) {
  711. criteria.query += '(_ownerUserOid == ?)';
  712. criteria.bindParams.push(userOid);
  713. } else {
  714. criteria.query += '(_ownerDeviceOid == ?)';
  715. criteria.bindParams.push(monaca.cloud.deviceId);
  716. }
  717. monaca.cloud._post('Collection.find', {
  718. collectionName: this.name,
  719. criteria: criteria.query,
  720. bindParams: criteria.bindParams,
  721. orderBy: o.orderBy,
  722. options: o.options
  723. }, dfd, {},
  724. function(e, status, xhr, dfd) {
  725. e.result.items = self._makeCollectionItem(e.result.items);
  726. dfd.resolve(e.result);
  727. });
  728. return dfd.promise();
  729. },
  730. /**
  731. * @param {Criteria|String} criteria .
  732. * @param {String|Array} [orderBy] .
  733. * @param {Object} [options] .
  734. * @return {$.Promise} .
  735. */
  736. findOne: function(criteria, orderBy, options) {
  737. var self = this;
  738. var dfd = new $.Deferred();
  739. criteria = self._validateCriteria(criteria);
  740. var o = self._validateOptions(orderBy, options);
  741. monaca.cloud._post('Collection.find', {
  742. collectionName: this.name,
  743. criteria: criteria.query,
  744. bindParams: criteria.bindParams,
  745. orderBy: o.orderBy,
  746. options: o.options
  747. }, dfd, {},
  748. function(e, status, xhr, dfd) {
  749. var result = (e.result.totalItems > 0) ? self._makeCollectionItem(e.result.items[0]) : null;
  750. dfd.resolve(result);
  751. });
  752. return dfd.promise();
  753. },
  754. /**
  755. * @param {Criteria|String} criteria .
  756. * @param {String|Array} [orderBy] .
  757. * @param {Object} [options] .
  758. * @return {$.Promise} .
  759. */
  760. findOneMine: function(criteria, orderBy, options) {
  761. var self = this;
  762. var dfd = new $.Deferred();
  763. criteria = self._validateCriteria(criteria);
  764. var o = self._validateOptions(orderBy, options);
  765. var userOid = monaca.cloud.User._oid;
  766. if (criteria.query != '') {
  767. criteria.query = '(' + criteria.query + ') && ';
  768. }
  769. if (userOid != null) {
  770. criteria.query += '(_ownerUserOid == ?)';
  771. criteria.bindParams.push(userOid);
  772. } else {
  773. criteria.query += '(_ownerDeviceOid == ?)';
  774. criteria.bindParams.push(monaca.cloud.deviceId);
  775. }
  776. monaca.cloud._post('Collection.find', {
  777. collectionName: this.name,
  778. criteria: criteria.query,
  779. bindParams: criteria.bindParams,
  780. orderBy: o.orderBy,
  781. options: o.options
  782. }, dfd, {},
  783. function(e, status, xhr, dfd) {
  784. var result = (e.result.totalItems > 0) ? self._makeCollectionItem(e.result.items[0]) : null;
  785. dfd.resolve(result);
  786. });
  787. return dfd.promise();
  788. },
  789. /**
  790. * @param {Object} item .
  791. * @param {Object} [permission] .
  792. * @return {$.Promise} .
  793. */
  794. insert: function(item, permission) {
  795. var self = this;
  796. var dfd = new $.Deferred();
  797. if (typeof(permission) === 'undefined') {
  798. permission = {};
  799. }
  800. monaca.cloud._post('Collection.insert', {
  801. collectionName: this.name,
  802. item: item,
  803. permission: permission
  804. }, dfd, {},
  805. function(e, status, xhr, dfd) {
  806. var item = self._makeCollectionItem(e.result.item);
  807. dfd.resolve(item);
  808. });
  809. return dfd.promise();
  810. },
  811. /**
  812. * @param {Criteria|String} criteria .
  813. * @param {Object} permission .
  814. * @param {Object} [options] .
  815. * @return {$.Promise} .
  816. */
  817. updatePermission: function(criteria, permission, options) {
  818. var self = this;
  819. var dfd = new $.Deferred();
  820. criteria = self._validateCriteria(criteria);
  821. monaca.cloud._post('Collection.updatePermission', {
  822. collectionName: this.name,
  823. criteria: criteria.query,
  824. bindParams: criteria.bindParams,
  825. permission: permission,
  826. options: options
  827. }, dfd, {});
  828. return dfd.promise();
  829. }
  830. };
  831. return MonacaCloudCollection;
  832. })();
  833. monaca.cloud.Collection = function(name) {
  834. return new MonacaCloudCollection(name);
  835. };
  836. })(window);
  837. /*
  838. * Criteria
  839. */
  840. (function(root) {
  841. var monaca = root.monaca = root.monaca || {};
  842. monaca.cloud = monaca.cloud || {};
  843. var $ = monaca.cloud.$;
  844. /**
  845. * @class
  846. */
  847. MonacaCloudCriteria = (function() {
  848. function MonacaCloudCriteria(query, bindParams) {
  849. this.query = query;
  850. this.bindParams = (typeof(bindParams) !== 'undefined') ? bindParams : [];
  851. }
  852. return MonacaCloudCriteria;
  853. })();
  854. monaca.cloud.Criteria = function(query, bindParams) {
  855. return new MonacaCloudCriteria(query, bindParams);
  856. };
  857. })(window);
  858. /*
  859. * Device
  860. */
  861. (function(root) {
  862. var monaca = root.monaca = root.monaca || {};
  863. monaca.cloud = monaca.cloud || {};
  864. var $ = monaca.cloud.$;
  865. /**
  866. * @class
  867. */
  868. monaca.cloud.Device = {
  869. /**
  870. * @param {String} name .
  871. * @return {$.Promise} .
  872. */
  873. getProperty: function(name) {
  874. var dfd = new $.Deferred();
  875. monaca.cloud._post('Device.getProperties', {
  876. names: [name]
  877. }, dfd, {},
  878. function(e, status, xhr, dfd) {
  879. dfd.resolve(e.result.properties[name]);
  880. }
  881. );
  882. return dfd.promise();
  883. },
  884. /**
  885. * @param {Array} names .
  886. * @return {$.Promise} .
  887. */
  888. getProperties: function(names) {
  889. var dfd = new $.Deferred();
  890. monaca.cloud._post('Device.getProperties', {
  891. names: names
  892. }, dfd, {},
  893. function(e, status, xhr, dfd) {
  894. dfd.resolve(e.result.properties);
  895. }
  896. );
  897. return dfd.promise();
  898. },
  899. /**
  900. * @param {String} name .
  901. * @param {String} value .
  902. * @return {$.Promise} .
  903. */
  904. saveProperty: function(name, value) {
  905. var dfd = new $.Deferred();
  906. var param = {};
  907. if ((typeof(name) !== 'undefined') && (typeof(value) !== 'undefined')) {
  908. param = {
  909. properties: {}
  910. };
  911. param.properties[name] = value;
  912. }
  913. monaca.cloud._post('Device.saveProperties', param, dfd);
  914. return dfd.promise();
  915. },
  916. /**
  917. * @param {Object} properties .
  918. * @return {$.Promise} .
  919. */
  920. saveProperties: function(properties) {
  921. var dfd = new $.Deferred();
  922. var param = {};
  923. if (typeof(properties) !== 'undefined') param.properties = properties;
  924. monaca.cloud._post('Device.saveProperties', param, dfd);
  925. return dfd.promise();
  926. }
  927. };
  928. })(window);
  929. /*
  930. * Mailer
  931. */
  932. (function(root) {
  933. var monaca = root.monaca = root.monaca || {};
  934. monaca.cloud = monaca.cloud || {};
  935. var $ = monaca.cloud.$;
  936. /**
  937. * @class
  938. */
  939. monaca.cloud.Mailer = {
  940. /**
  941. * @param {String} userOid .
  942. * @param {String} templateName .
  943. * @param {Object} substituteParams .
  944. * @param {Object} [options] .
  945. * @return {$.Promise} .
  946. */
  947. sendMail: function(userOid, templateName, substituteParams, options) {
  948. var dfd = new $.Deferred();
  949. if (typeof(options) === 'undefined') {
  950. options = {};
  951. }
  952. monaca.cloud._post('Mailer.sendMail', {
  953. userOid: userOid,
  954. templateName: templateName,
  955. substituteParams: substituteParams,
  956. options: options
  957. }, dfd);
  958. return dfd.promise();
  959. }
  960. };
  961. })(window);
  962. /*
  963. * User
  964. */
  965. (function(root) {
  966. var monaca = root.monaca = root.monaca || {};
  967. monaca.cloud = monaca.cloud || {};
  968. var $ = monaca.cloud.$;
  969. /**
  970. * @class
  971. */
  972. monaca.cloud.User = (function() {
  973. return {
  974. _oid: null,
  975. /**
  976. * @return {Boolean} .
  977. */
  978. isAuthenticated: function() {
  979. return (this._oid === null) ? false : true;
  980. },
  981. /**
  982. * @param {String} username .
  983. * @param {String} password .
  984. * @param {Object} [properties] .
  985. * @return {$.Promise} .
  986. */
  987. register: function(username, password, properties) {
  988. var dfd = new $.Deferred();
  989. var self = this;
  990. if (typeof(properties) === 'undefined') properties = {};
  991. monaca.cloud._post('User.register', {
  992. username: username,
  993. password: password,
  994. properties: properties
  995. }, dfd, {},
  996. function(jsonResponse) {
  997. self._oid = jsonResponse.result.user._id;
  998. }
  999. );
  1000. return dfd.promise();
  1001. },
  1002. /**
  1003. * @param {String} username .
  1004. * @param {Object} properties .
  1005. * @return {$.Promise} .
  1006. */
  1007. validate: function(username, properties) {
  1008. var dfd = new $.Deferred();
  1009. monaca.cloud._post('User.validate', {
  1010. username: username,
  1011. properties: properties
  1012. }, dfd);
  1013. return dfd.promise();
  1014. },
  1015. /**
  1016. * @param {String} password .
  1017. * @return {$.Promise} .
  1018. */
  1019. unregister: function(password) {
  1020. var self = this,
  1021. dfd = new $.Deferred();
  1022. monaca.cloud._post('User.unregister', {
  1023. password: password
  1024. }, dfd, {},
  1025. function() {
  1026. self._oid = null;
  1027. monaca.cloud._setSessionId('');
  1028. localStorage.removeItem('monacaCloudLoginToken');
  1029. }
  1030. );
  1031. return dfd.promise();
  1032. },
  1033. /**
  1034. * @param {String} username .
  1035. * @param {String} password .
  1036. * @return {$.Promise} .
  1037. */
  1038. login: function(username, password) {
  1039. var self = this,
  1040. dfd = new $.Deferred();
  1041. monaca.cloud._post('User.login', {
  1042. username: username,
  1043. password: password
  1044. }, dfd, {},
  1045. function(jsonResponse) {
  1046. self._oid = jsonResponse.result.user._id;
  1047. }
  1048. );
  1049. return dfd.promise();
  1050. },
  1051. /**
  1052. * @return {$.Promise} .
  1053. */
  1054. autoLogin: function() {
  1055. var dfd = new $.Deferred();
  1056. var token = localStorage.monacaCloudLoginToken || '';
  1057. var self = this;
  1058. monaca.cloud._post('User.autoLogin', {
  1059. loginToken: token
  1060. }, dfd, {},
  1061. function(jsonResponse) {
  1062. self._oid = jsonResponse.result.user._id;
  1063. }
  1064. );
  1065. return dfd.promise();
  1066. },
  1067. /**
  1068. * @return {$.Promise} .
  1069. */
  1070. logout: function() {
  1071. var self = this,
  1072. dfd = new $.Deferred();
  1073. monaca.cloud._post('User.logout', {}, dfd, {},
  1074. function() {
  1075. self._oid = null;
  1076. monaca.cloud._setSessionId('');
  1077. localStorage.removeItem('monacaCloudLoginToken');
  1078. }
  1079. );
  1080. return dfd.promise();
  1081. },
  1082. /**
  1083. * @param {String} oldPassword .
  1084. * @param {String} newPassword .
  1085. * @return {$.Promise} .
  1086. */
  1087. updatePassword: function(oldPassword, newPassword) {
  1088. var dfd = new $.Deferred();
  1089. monaca.cloud._post('User.updatePassword', {
  1090. oldPassword: oldPassword,
  1091. newPassword: newPassword
  1092. }, dfd);
  1093. return dfd.promise();
  1094. },
  1095. /**
  1096. * @param {String} username .
  1097. * @param {Object} options .
  1098. * @return {$.Promise} .
  1099. */
  1100. sendPasswordResetToken: function(username, options) {
  1101. var dfd = new $.Deferred();
  1102. monaca.cloud._post('User.sendPasswordResetToken', {
  1103. username: username,
  1104. options: options
  1105. }, dfd);
  1106. return dfd.promise();
  1107. },
  1108. /**
  1109. * @param {String} username .
  1110. * @param {String} newPassword .
  1111. * @param {String} token .
  1112. * @return {$.Promise} .
  1113. */
  1114. resetPasswordAndLogin: function(username, newPassword, token) {
  1115. var dfd = new $.Deferred();
  1116. var self = this;
  1117. monaca.cloud._post('User.resetPasswordAndLogin', {
  1118. username: username,
  1119. newPassword: newPassword,
  1120. token: token
  1121. }, dfd, {},
  1122. function(jsonResponse) {
  1123. self._oid = jsonResponse.result.user._id;
  1124. }
  1125. );
  1126. return dfd.promise();
  1127. },
  1128. /**
  1129. * @param {String} name .
  1130. * @return {$.Promise} .
  1131. */
  1132. getProperty: function(name) {
  1133. var dfd = new $.Deferred();
  1134. monaca.cloud._post('User.getProperties', {
  1135. names: [name]
  1136. }, dfd, {},
  1137. function(e, status, xhr, dfd) {
  1138. dfd.resolve(e.result.properties[name]);
  1139. }
  1140. );
  1141. return dfd.promise();
  1142. },
  1143. /**
  1144. * @param {Array} names .
  1145. * @return {$.Promise} .
  1146. */
  1147. getProperties: function(names) {
  1148. var dfd = new $.Deferred();
  1149. monaca.cloud._post('User.getProperties', {
  1150. names: names
  1151. }, dfd, {},
  1152. function(e, status, xhr, dfd) {
  1153. dfd.resolve(e.result.properties);
  1154. }
  1155. );
  1156. return dfd.promise();
  1157. },
  1158. /**
  1159. * @param {String} name .
  1160. * @param {String} value .
  1161. * @return {$.Promise} .
  1162. */
  1163. saveProperty: function(name, value) {
  1164. var dfd = new $.Deferred();
  1165. var param = {};
  1166. if (typeof(name) !== 'undefined') {
  1167. param = {
  1168. properties: {}
  1169. };
  1170. param.properties[name] = value;
  1171. }
  1172. monaca.cloud._post('User.saveProperties', param, dfd);
  1173. return dfd.promise();
  1174. },
  1175. /**
  1176. * @param {Object} properties .
  1177. * @return {$.Promise} .
  1178. */
  1179. saveProperties: function(properties) {
  1180. var dfd = new $.Deferred();
  1181. var param = {};
  1182. if (typeof(properties) !== 'undefined') param.properties = properties;
  1183. monaca.cloud._post('User.saveProperties', param, dfd);
  1184. return dfd.promise();
  1185. }
  1186. };
  1187. })();
  1188. })(window);