Skip to content

Commit

Permalink
feat: 允许独立站禁用 mip-shell (#542)
Browse files Browse the repository at this point in the history
  • Loading branch information
yenshih authored Mar 13, 2019
1 parent f0c7906 commit 0da36d7
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 4 deletions.
3 changes: 2 additions & 1 deletion packages/mip/src/components/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import MipShell from './mip-shell/index'
import MipFixed from './mip-fixed/index'
import MipLayout from './mip-layout'
import registerElement from '../register-element'
import {isMIPShellDisabled} from '../page/util/dom'

export default {

Expand All @@ -34,6 +35,6 @@ export default {
registerElement('mip-fixed', MipFixed)
new MipBind()
registerElement('mip-data', MipData)
registerElement('mip-shell', MipShell)
isMIPShellDisabled() || registerElement('mip-shell', MipShell)
}
}
9 changes: 9 additions & 0 deletions packages/mip/src/page/util/dom.js
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,15 @@ export function ensureMIPShell () {
}
}

/**
* Returns whether mip-shell needs to be disabled.
*
* @returns {boolean}
*/
export function isMIPShellDisabled () {
return !!(window.MIP.standalone && document.querySelector('mip-shell[disabled]'))
}

export function nextFrame (fn) {
raf(() => {
raf(fn)
Expand Down
7 changes: 4 additions & 3 deletions packages/mip/src/viewer.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import EventAction from './util/event-action'
import EventEmitter from './util/event-emitter'
import {fn, makeCacheUrl, parseCacheUrl} from './util'
import {supportsPassive} from './page/util/feature-detect'
import {resolvePath} from './page/util/path'
import viewport from './viewport'
import Page from './page/index'
import {
Expand All @@ -22,6 +21,8 @@ import {
OUTER_MESSAGE_PUSH_STATE,
OUTER_MESSAGE_REPLACE_STATE
} from './page/const'
import {isMIPShellDisabled} from './page/util/dom'
import {resolvePath} from './page/util/path'
import Messager from './messager'
import fixedElement from './fixed-element'
import clientPrerender from './client-prerender'
Expand Down Expand Up @@ -205,9 +206,9 @@ let viewer = {
}

// Jump in top window directly
// 1. Cross origin and NOT in SF
// 1. ( Cross origin or MIP Shell is disabled ) and NOT in SF
// 2. Not MIP page and not only hash change
if ((this._isCrossOrigin(to) && window.MIP.standalone) ||
if (((this._isCrossOrigin(to) || isMIPShellDisabled()) && window.MIP.standalone) ||
(!isMipLink && !isHashInCurrentPage)) {
if (replace) {
window.top.location.replace(to)
Expand Down

0 comments on commit 0da36d7

Please sign in to comment.