/** * mui back 5+ * @param {type} $ * @param {type} window * @returns {undefined} */ (function($, window) { if ($.os.plus && $.os.android) { $.addBack({ name: 'mui', index: 5, handle: function() { //后续重新设计此处,将back放到各个空间内部实现 //popover if ($.targets._popover && $.targets._popover.classList.contains($.className('active'))) { $($.targets._popover).popover('hide'); return true; } //offcanvas var offCanvas = document.querySelector($.classSelector('.off-canvas-wrap.active')); if (offCanvas) { $(offCanvas).offCanvas('close'); return true; } var previewImage = $.isFunction($.getPreviewImage) && $.getPreviewImage(); if (previewImage && previewImage.isShown()) { previewImage.close(); return true; } //popup return $.closePopup(); } }); } //首次按下back按键的时间 $.__back__first = null; /** * 5+ back */ $.addBack({ name: '5+', index: 10, handle: function() { if (!window.plus) { return false; } var wobj = plus.webview.currentWebview(); var parent = wobj.parent(); if (parent) { parent.evalJS('mui&&mui.back();'); } else { wobj.canBack(function(e) { //by chb 暂时注释,在碰到类似popover之类的锚点的时候,需多次点击才能返回; if (e.canBack) { //webview history back window.history.back(); } else { //webview close or hide //fixed by fxy 此处不应该用opener判断,因为用户有可能自己close掉当前窗口的opener。这样的话。opener就为空了,导致不能执行close if (wobj.id === plus.runtime.appid) { //首页 //首页不存在opener的情况下,后退实际上应该是退出应用; //首次按键,提示‘再按一次退出应用’ if (!$.__back__first) { $.__back__first = new Date().getTime(); mui.toast('再按一次退出应用'); setTimeout(function() { $.__back__first = null; }, 2000); } else { if (new Date().getTime() - $.__back__first < 2000) { plus.runtime.quit(); } } } else { //其他页面, if (wobj.preload) { wobj.hide("auto"); } else { //关闭页面时,需要将其打开的所有子页面全部关闭; $.closeAll(wobj); } } } }); } return true; } }); $.menu = function() { var menu = document.querySelector($.classSelector('.action-menu')); if (menu) { $.trigger(menu, $.EVENT_START); //临时处理menu无touchstart的话,找不到当前targets的问题 $.trigger(menu, 'tap'); } else { //执行父窗口的menu if (window.plus) { var wobj = $.currentWebview; var parent = wobj.parent(); if (parent) { //又得evalJS parent.evalJS('mui&&mui.menu();'); } } } }; var __back = function() { $.back(); }; var __menu = function() { $.menu(); }; //默认监听 $.plusReady(function() { if ($.options.keyEventBind.backbutton) { plus.key.addEventListener('backbutton', __back, false); } if ($.options.keyEventBind.menubutton) { plus.key.addEventListener('menubutton', __menu, false); } }); //处理按键监听事件 $.addInit({ name: 'keyEventBind', index: 1000, handle: function() { $.plusReady(function() { //如果不为true,则移除默认监听 if (!$.options.keyEventBind.backbutton) { plus.key.removeEventListener('backbutton', __back); } if (!$.options.keyEventBind.menubutton) { plus.key.removeEventListener('menubutton', __menu); } }); } }); })(mui, window);