Skip to content

Commit

Permalink
feat: 定制化组件修改与小说阅读器的双向事件监听的方案 #1259
Browse files Browse the repository at this point in the history
  • Loading branch information
Espoir-L committed Oct 11, 2018
1 parent cfc6730 commit fc3e7fd
Showing 1 changed file with 20 additions and 10 deletions.
30 changes: 20 additions & 10 deletions src/mip-custom/mip-custom.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,22 +65,32 @@ define(function () {
dom.addPlaceholder.apply(this);
// 判断是否是MIP2的环境,配合小说shell,由小说shell去控制custom的请求是否发送
if (window.MIP.version && +window.MIP.version === 2) {
// 监听小说shell播放的广告请求的事件
window.addEventListener('showAdvertising', handler);
// 当小说shell优先加载时——向小说shell发送custom已经ready的状态以方便后续事件的执行
var shellWindow = window.MIP.viewer.page.isRootPage ? window : window.parent;
window.MIP.viewer.page.emitCustomEvent(shellWindow, false, {
name: 'customReady',
data: {
customPageId: window.MIP.viewer.page.currentPageId
}
})
var currentWindow = getCurrentWindow();
var isRootPage = currentWindow.MIP.viewer.page.isRootPage;
var rootWindow = isRootPage ? window : window.parent;
if (rootWindow.MIP.mipshellXiaoshuo != null) {
// 监听小说shell播放的广告请求的事件
window.addEventListener('showAdvertising', handler);
}
else {
this.initElement(dom)
}
}
else {
this.initElement(dom)
}
};

/**
* 在MIP2的小说中会涉及不到不同的window,需要获取当前页的window
*
*/
function getCurrentWindow () {
let pageId = window.MIP.viewer.page.currentPageId
let pageInfo = window.MIP.viewer.page.getPageById(pageId)
return pageInfo.targetWindow
}

/**
* 发出请求+渲染页面
*
Expand Down

0 comments on commit fc3e7fd

Please sign in to comment.