/* * Moye 0.0.2 * Moye 应用框架设计宗旨是告诉开发者如何在 cyclone 系统上开发应用,包括规范应用生 命周期,支持多语言以及开发 Service 服务等。 * xuanyong (yujie.pyj@alibaba-inc.com) - http://tv.alibaba.net/_site/index.html * * Copyright 2016, Alibaba Group * Released under the MIT license. */ ! function(e) { function t(i) { if (n[i]) return n[i].exports; var o = n[i] = { exports: {}, id: i, loaded: !1 }; return e[i].call(o.exports, o, o.exports, t), o.loaded = !0, o.exports; } var n = {}; return t.m = e, t.c = n, t.p = '', t(0); }([function(e, t, n) { function i(e) { return e && e.__esModule ? e : { 'default': e }; } function o(e, t) { if (!(e instanceof t)) throw new TypeError('Cannot call a class as a function'); } var s = 'function' == typeof Symbol && 'symbol' == typeof Symbol.iterator ? function(e) { return typeof e; } : function(e) { return e && 'function' == typeof Symbol && e.constructor === Symbol ? 'symbol' : typeof e; }, r = Object.assign || function(e) { for (var t = 1; t < arguments.length; t++) { var n = arguments[t]; for (var i in n) Object.prototype.hasOwnProperty.call(n, i) && (e[i] = n[i]); } return e; }, u = function() { function e(e, t) { for (var n = 0; n < t.length; n++) { var i = t[n]; i.enumerable = i.enumerable || !1, i.configurable = !0, 'value' in i && (i.writable = !0), Object.defineProperty(e, i.key, i); } } return function(t, n, i) { return n && e(t.prototype, n), i && e(t, i), t; }; }(), a = n(1), c = i(a), l = n(2), f = i(l), h = n(3), y = i(h), d = n(4), v = i(d), g = n(5), p = i(g), m = function() { function e() { o(this, e), this.utils = c['default'], this.global = new p['default'], this.sceneList = [], this.focusList = [], this.action = {}, this.root = null, this.curScene = null, this.isAtv = !1, this.isTplDebug = !1, this.animate = !1, this.keyCodes = { ENTER: 13, LEFT: 37, UP: 38, RIGHT: 39, DOWN: 40, BACK: 27, MEMU: 18, SOURCE: 690, RECORD: 685, NUM_0: 48, NUM_1: 49, NUM_2: 50, NUM_3: 51, NUM_4: 52, NUM_5: 53, NUM_6: 54, NUM_7: 55, NUM_8: 56, NUM_9: 57, SOUND_UP: 536, SOUND_DOWN: 537, M: 36 }; } return u(e, [{ key: 'init', value: function() { var e = arguments.length <= 0 || void 0 === arguments[0] ? {} : arguments[0]; if ('[object Object]' !== this.utils.getType(e)) throw new Error('[Moye] init\u4f20\u5165\u53c2\u6570\u7c7b\u578b\u9519\u8bef\uff0c\u53ea\u63a5\u53d7\u4f20\u5165\u5bf9\u8c61\u3002'); e = r({ tplmode: 0, packagename: 'com.yunos.moye.demo', isAtv: !0, animate: !1, scene: {} }, e), this.launcher = e.launcher, this.isTplDebug = e.isTplDebug, this.isAtv = e.isAtv, this.animate = e.animate, this.tplmode = e.tplmode, e['default'] && e['default'].lang && '[object Object]' === this.utils.getType(e['default'].lang) ? this.lang = e['default'].lang : this.lang = null, this.scene = e.scene, this.resource = new f['default'](e.packagename, this.lang, this.isTplDebug), this.registerStageListener(), this.isAtv || this.onkeyListener(); } }, { key: 'showScene', value: function(e) { var t = this, n = arguments.length <= 1 || void 0 === arguments[1] ? {} : arguments[1]; if (this.curScene && this.curScene.onPause(), '[object Object]' !== this.utils.getType(n)) throw new Error('[Moye] showScene\u4f20\u5165\u53c2\u6570(data)\u7c7b\u578b\u9519\u8bef\uff0c\u53ea\u63a5\u53d7\u4f20\u5165\u5bf9\u8c61\u3002'); if (this.curScene = new e(this), this.sceneList.push(this.curScene), this.updateDefaultKeyStatus(), this.sceneList.length <= 1 && this.utils.isBlitz()) { var i = blitz.load('base'); i.getPageData({}, function(e) { t.curScene.onCreate(r({}, n, { pageData: e })); }, function(e) { t.curScene.onCreate(n); }); } else this.curScene.onCreate(n); } }, { key: 'registerStageListener', value: function() { var e = this, t = blitz.load('base'); this.isAtv || this.onkeyListener(), this.utils.isBlitz() && (t.addListener({ name: 'page_show' }, function(t) { e.curScene && e.curScene.onResume(); for (var n = 0, i = e.sceneList.length; i > n; n++) e.sceneList[n].onStageShow && e.sceneList[n].onStageShow(); }, function(e) { throw new Error('[ Moye ] page_show\u51fa\u9519\u3002'); }), t.addListener({ name: 'page_hide' }, function(t) { e.curScene && e.curScene.onPause(); for (var n = 0, i = e.sceneList.length; i > n; n++) e.sceneList[n].onStageHide && e.sceneList[n].onStageHide(); }, function(e) { throw new Error('[ Moye ] page_hide\u51fa\u9519\u3002'); }), t.addListener({ name: 'page_stop' }, function(t) { e.curScene && e.curScene.onDestroy(); }, function(e) { throw new Error('[ Moye ] page_stop\u51fa\u9519\u3002'); }), t.addListener({ name: 'stage_resume' }, function(t) { e.curScene.onActive(); }, function(e) { throw new Error('[ Moye ] stage_resume\u51fa\u9519\u3002'); }), t.addListener({ name: 'stage_pause' }, function(t) { e.curScene.onInactive(); }, function(e) { throw new Error('[ Moye ] stage_pause\u51fa\u9519\u3002'); })); } }, { key: 'onkeyListener', value: function() { var e = this; this.isAtv ? (this.root.on('keydown', function(t) { e.curScene.onKeydown(t); }), this.root.on('ok', function(t) { e.curScene.onOK(t); }), this.root.on('click', function(t) { e.curScene.onClick(t); }), this.root.on('keyup', function(t) { switch (t.keyCode) { case e.keyCodes.BACK: e.hideScene(); break; default: e.curScene.onKeyup(t); } })) : (document.body.addEventListener('keydown', function(t) { e.curScene.onKeydown(t); }), document.body.addEventListener('keyup', function(t) { switch (t.keyCode) { case e.keyCodes.BACK: e.hideScene(); break; case e.keyCodes.ENTER: e.curScene.onOK(t); break; default: e.curScene.onKeyup(t); } })); } }, { key: 'hideScene', value: function(e, t) { t ? this.showSceneById(e, t) : this.hideCurScene(e); } }, { key: 'showSceneById', value: function(e, t) { var n = this.focusList.indexOf(t); if (-1 == n) throw new Error('[ Moye ] \u672a\u53d1\u73b0\u5bf9\u5e94ID\u7684Scene\u3002'); this.curScene.onPause(), this.curScene.onDestroy(), this.curScene = null, this.sceneList.length = n + 1; for (var i = this.focusList.length, o = i - 1; o > n; o--) { var s = this.focusList[o], r = document.getElementById(s); r.parentNode.removeChild(r); } this.focusList.length = n + 1, this.render(), this.isAtv && (this.root.getWidgetById(t).enable(), this.atvFocus(t)), this.curScene = this.sceneList[n], this.curScene.onResume(e), this.updateDefaultKeyStatus(); } }, { key: 'hideCurScene', value: function(e) { var t = this, n = this.sceneList; this.curScene = n[n.length - 1]; var i = this.curScene.onBack && this.curScene.onBack(); if (1 !== n.length) { if (!i) { this.curScene.onPause(), this.curScene.onDestroy(), this.isAtv && ! function() { var e = t.focusList.pop(), n = document.getElementById(e); t.animate ? (n.style.transform = 'scale(1)', n.style.opacity = 1, n.addEventListener('transitionend', function() { n.parentNode.removeChild(n), e = null, t.render(); }), n.style.transition = 'all 0.2s ease-in-out', n.style.transform = 'scale(.95)', n.style.opacity = 0) : (n.parentNode.removeChild(n), e = null, t.render()); }(); var o = n.pop(); if (o = null, n.length >= 1) { if (this.curScene = n[n.length - 1], this.isAtv) { var s = this.focusList[this.focusList.length - 1]; this.root.getWidgetById(s).enable(), this.atvFocus(s); } this.curScene.onResume(e); } } this.updateDefaultKeyStatus(); } } }, { key: 'reload', value: function() { var e = this.sceneList, t = this.focusList; this.resource.lang = null, this.resource.getResourceValue(); for (var n = 0, i = t.length; i > n; n++) { var o = document.getElementById(t[n]); o.parentNode.removeChild(o); } t.length = 0, e.length = 1, this.curScene = e[0], this.updateDefaultKeyStatus(), this.curScene.onCreate(); } }, { key: 'updateDefaultKeyStatus', value: function() { this.sceneList.length > 1 || this.launcher ? this.utils.setDefaultKeyEvent(!0) : this.utils.setDefaultKeyEvent(!1); } }, { key: 'getResource', value: function() { return this.resource; } }, { key: 'setContentView', value: function(e, t, n, i) { var o = this, r = arguments.length <= 4 || void 0 === arguments[4] ? function() {} : arguments[4], u = i && i.containerId ? i.containerId : null, a = i && i.isParentShow ? i.isParentShow : !1, c = i && i.focusId ? i.focusId : n, l = i && i.isFront ? i.isFront : !1, f = u ? document.getElementById(u) : document.body, h = function(e, t) { o.animate && (f.style.transform = 'scale(0.95)', setTimeout(function() { f.style.transition = 'all 0.2s ease-in-out', f.style.transform = 'scale(1)'; }, 300)); var i = o.utils.parseToDOM(e); if (i.id || (i.id = n), l ? f.insertBefore(i, f.childNodes[0]) : f.appendChild(i), o.isAtv && (o.render(), o.atvFocus(c), o.focusList.push(n), o.focusList.length > 1)) { var s = o.focusList[o.focusList.length - 2]; o.root.getWidgetById(s).disable(), document.getElementById(s).style.visibility = a ? 'visible' : 'hidden'; } t(); }; this.resource.getResourceValue(function(n) { if (t.lang = n, '[object Function]' === o.utils.getType(e)) h(e(t), r); else { if ('[object String]' !== o.utils.getType(e)) throw new Error('[Moye] setContentView\u4f20\u5165\u53c2\u6570(tpl)\u9519\u8bef\uff0c\u4e0d\u63a5\u53d7String & Function\u4ee5\u5916\u7c7b\u578b\u3002'); console.log('[Moye] \u901a\u8fc7\u6587\u4ef6\u540d\u83b7\u53d6\u6a21\u677f\u7684\u65b9\u5f0f\u5df2\u4e0d\u5efa\u8bae\u4f7f\u7528,\u8bf7\u76f4\u63a5require\u6a21\u677f\u6587\u4ef6\u3002'), o.resource.getTpl(e, function(e, n) { if (!e) throw new Error('[Moye] \u83b7\u53d6\u6a21\u677f\u6587\u4ef6\u51fa\u9519\u3002'); ('object' !== ('undefined' == typeof t ? 'undefined' : s(t)) || null == t) && (t = {}); var i = o.tplReplace(n, t); h(i, r); }); } }); } }, { key: 'render', value: function() { return this.root ? this.root.reRender() : (this.root = window.ATV ? ATV.UI.render() : FocusEngine.render(), this.onkeyListener()), this.root; } }, { key: 'assetData', value: function(e, t) { return 'object' !== ('undefined' == typeof t ? 'undefined' : s(t)) && (t = {}), t.lang = this.resource.getLang(), this.tplReplace(e, t); } }, { key: 'atvFocus', value: function(e) { this.root.getWidgetById(e).focus(), document.getElementById(e).style.visibility = 'visible'; } }, { key: 'getServiceClient', value: function() { return new y['default']; } }, { key: 'tplReplace', value: function(e, t) { return 0 == this.tplmode ? this.utils.regexView(e, t) : juicer(e, t); } }, { key: 'getSystemLang', value: function(e) { var t = blitz.load('property'); t.getSystemProperty({ key: 'persist.sys.language' }, function(t) { var n = t.result; e(n); }, function(e) {}); } }]), e; }(); void 0 !== ('undefined' == typeof window ? 'undefined' : s(window)) ? (window.moye = new m, window.scene = v['default']) : e.exports = moye = new m; }, function(module, exports) { Object.defineProperty(exports, '__esModule', { value: !0 }); var MoyeUtils = { isBlitz: function() { return 'undefined' != typeof yunos; }, parseToDOM: function(e) { var t = void 0, n = document.createElement('div'), i = document.createDocumentFragment(); for (n.innerHTML = e; t = n.firstChild;) i.appendChild(t); return i; }, setDefaultKeyEvent: function(e) { this.isBlitz() && yunos.context.preventDefaultKeyEvent(e); }, hasClass: function(e, t) { return e.className.match(new RegExp('(\\s|^)' + t + '(\\s|$)')); }, addClass: function(e, t) { this.hasClass(e, t) || (e.className += ' ' + t); }, removeClass: function(e, t) { if (this.hasClass(e, t)) { var n = new RegExp('(\\s|^)' + t + '(\\s|$)'); e.className = e.className.replace(n, ' '); } }, writeFile: function(e, t, n) { var i = blitz.load('file'); i.openFile({ filename: e.filename, mode: e.mode }, function(o) { console.log('open file success: ' + JSON.stringify(o)), i.write({ filename: e.filename, data: e.data }, function(o) { console.log('write file success: ' + JSON.stringify(o)), t && t(o), i.closeFile({ filename: e.filename }, function(e) { console.log('close file success: ' + JSON.stringify(e)); }, function(e) { console.log('close file fail: ' + JSON.stringify(e)), n && n(e); }); }, function(e) { console.log('write file fail: ' + JSON.stringify(e)), n && n(e); }); }, function(e) { console.log('open file fail: ' + JSON.stringify(e)), n && n(e); }); }, getType: function(e) { var t = {}.toString; return t.call(e); }, regexView: function regexView(htmlContent, arr) { var result = htmlContent.replace(/\$\{(.*?)\}/g, function() { try { var s = arguments[1].toString(), m = eval('arr.' + s); return void 0 == m ? '' : m; } catch (e) {} }); return result.toString(); } }; window.MoyeUtils = MoyeUtils, exports['default'] = MoyeUtils; }, function(e, t, n) { function i(e) { return e && e.__esModule ? e : { 'default': e }; } function o(e, t) { if (!(e instanceof t)) throw new TypeError('Cannot call a class as a function'); } Object.defineProperty(t, '__esModule', { value: !0 }); var s = function() { function e(e, t) { for (var n = 0; n < t.length; n++) { var i = t[n]; i.enumerable = i.enumerable || !1, i.configurable = !0, 'value' in i && (i.writable = !0), Object.defineProperty(e, i.key, i); } } return function(t, n, i) { return n && e(t.prototype, n), i && e(t, i), t; }; }(), r = n(1), u = i(r), a = function() { function e(t, n, i) { o(this, e), this.respath = '/data/app/' + t + '/res/', this.utils = u['default'], this.lang = null === n ? {} : n, this.file = blitz.load('file'), this.isTplDebug = i, this.tpl = {}, console.log(this.lang); } return s(e, [{ key: 'getLang', value: function() { return this.lang; } }, { key: 'getString', value: function(e) { return this.lang.data[e]; } }, { key: 'getResourceValue', value: function(e) { var t = this; if (this.utils.isBlitz()) { var n = blitz.load('property'); n.getSystemProperty({ key: 'persist.sys.language' }, function(n) { var i = n.result; if (i === t.lang.type) e && e(t.lang.data); else try { var o = 'value_' + i + '.json'; t.lang.data = window.require('../../res/values/' + o), t.lang.type = i, e && e(t.lang.data); } catch (n) { var s = 'value.json'; t.lang.data = window.require('../../res/values/' + s), t.lang.type = i, e && e(t.lang.data); } }, function(n) { e && e(t.lang.data); }); } else this.lang.type && this.lang.data ? e && e(this.lang.data) : this.sendAjaxRequest('../../res/values/value.json', function(n, i) { t.lang.type = 'zh', t.lang.data = JSON.parse(i), e && e(t.lang.data); }); } }, { key: 'sendAjaxRequest', value: function(e, t) { var n = new XMLHttpRequest; n.open('GET', e, !0), n.onreadystatechange = function() { if (4 == n.readyState && 200 == n.status) { var e = n.responseText; t(!0, e); } }, n.send(null); } }, { key: 'getTpl', value: function(e, t) { var n = this; void 0 != this.tpl[e] || this.utils.isBlitz() && !this.isTplDebug ? ! function() { var i = { filename: n.respath + 'tpl/' + e }; n.file.openFile(i, function(o) { n.file.read(i, function(o) { n.tpl[e] = o.data, n.file.closeFile(i, function(e) {}, function(e) { throw new Error('[ Moye ] \u5173\u95ed\u6587\u4ef6(' + i.filename + ')\u51fa\u9519\u3002'); }), t(!0, o.data); }, function(e) { t(!1); }); }, function(e) { t(!1); }); }() : this.sendAjaxRequest('../../res/tpl/' + e, t); } }]), e; }(); t['default'] = a; }, function(e, t, n) { function i(e) { return e && e.__esModule ? e : { 'default': e }; } function o(e, t) { if (!(e instanceof t)) throw new TypeError('Cannot call a class as a function'); } Object.defineProperty(t, '__esModule', { value: !0 }); var s = 'function' == typeof Symbol && 'symbol' == typeof Symbol.iterator ? function(e) { return typeof e; } : function(e) { return e && 'function' == typeof Symbol && e.constructor === Symbol ? 'symbol' : typeof e; }, r = function() { function e(e, t) { for (var n = 0; n < t.length; n++) { var i = t[n]; i.enumerable = i.enumerable || !1, i.configurable = !0, 'value' in i && (i.writable = !0), Object.defineProperty(e, i.key, i); } } return function(t, n, i) { return n && e(t.prototype, n), i && e(t, i), t; }; }(), u = n(1), a = i(u), c = function() { function e() { if (o(this, e), void 0 !== ('undefined' == typeof window ? 'undefined' : s(window))) { var t = a['default']; t.isBlitz() ? this.serivceClient = new BlitzServiceClient : this.serivceClient = null; } } return r(e, [{ key: 'bindService', value: function(e, t) { this.serivceClient.getService(e, function(e) { t(e); }); } }, { key: 'unbindService', value: function(e) { this.serivceClient.release(e); } }, { key: 'startService', value: function(e, t) { this.serivceClient.startService(e, t); } }, { key: 'stopService', value: function(e) { this.serivceClient.stopService(e); } }]), e; }(); t['default'] = c; }, function(e, t) { function n(e, t) { if (!(e instanceof t)) throw new TypeError('Cannot call a class as a function'); } Object.defineProperty(t, '__esModule', { value: !0 }); var i = function() { function e(e, t) { for (var n = 0; n < t.length; n++) { var i = t[n]; i.enumerable = i.enumerable || !1, i.configurable = !0, 'value' in i && (i.writable = !0), Object.defineProperty(e, i.key, i); } } return function(t, n, i) { return n && e(t.prototype, n), i && e(t, i), t; }; }(), o = function() { function e(t) { n(this, e), this.moye = t, this.global = t.global; } return i(e, [{ key: 'onCreate', value: function(e) {} }, { key: 'onResume', value: function(e) {} }, { key: 'onPause', value: function() {} }, { key: 'onStageShow', value: function(e) {} }, { key: 'onStageHide', value: function() {} }, { key: 'onDestroy', value: function() {} }, { key: 'onActive', value: function() {} }, { key: 'onInactive', value: function() {} }, { key: 'onKeydown', value: function(e) {} }, { key: 'onKeyup', value: function(e) {} }, { key: 'onOK', value: function(e) {} }, { key: 'onBack', value: function() {} }, { key: 'onClick', value: function(e) {} }, { key: 'showScene', value: function(e, t) { return this.moye.showScene(e, t); } }, { key: 'hideScene', value: function(e, t) { return this.moye.hideScene(e, t); } }, { key: 'setContentView', value: function(e, t, n, i, o) { this.moye.setContentView(e, t, n, i, o); } }, { key: 'getResource', value: function() { return this.moye.getResource(); } }, { key: 'getAlertDialog', value: function() { return window.require('/system/res/alert-dialog.js'); } }, { key: 'getKeyCodes', value: function() { return this.moye.keyCodes; } }, { key: 'getMoye', value: function() { return this.moye; } }, { key: 'getAtvRoot', value: function() { return this.moye.root; } }, { key: 'atvFocus', value: function(e) { this.moye.atvFocus(e); } }, { key: 'atvRender', value: function() { return this.moye.render(); } }, { key: 'reload', value: function() { return this.moye.reload(); } }, { key: 'isBlitz', value: function() { return this.moye.utils.isBlitz(); } }]), e; }(); t['default'] = o; }, function(e, t) { function n(e, t) { if (!(e instanceof t)) throw new TypeError('Cannot call a class as a function'); } var i = function() { function e(e, t) { for (var n = 0; n < t.length; n++) { var i = t[n]; i.enumerable = i.enumerable || !1, i.configurable = !0, 'value' in i && (i.writable = !0), Object.defineProperty(e, i.key, i); } } return function(t, n, i) { return n && e(t.prototype, n), i && e(t, i), t; }; }(), o = function() { function e() { n(this, e), this.map = {}; } return i(e, [{ key: 'get', value: function(e) { return this.map[e]; } }, { key: 'set', value: function(e, t) { this.map[e] = t; } }, { key: 'each', value: function() { var e = arguments.length <= 0 || void 0 === arguments[0] ? function(e) {} : arguments[0]; for (var t in this.map) e(t); } }]), e; }(); e.exports = o; }]);