UNPKG

nyx_server

Version:

Node内容发布

69 lines (56 loc) 2.34 kB
(function ($, lib) { 'use strict'; var win = window; var postMessage = { init: function () { win.addEventListener('message', onMessageHandler, false); } }; // @todo 以下代码需要在实际环境中进行调整。 var disposeAction = function (action, data, options) { switch (action) { case 'close': // 调用相应对象的弹出框关闭方法 eval('0,' + options.scope + '.dialog.closeIt()'); break; case 'preview': // 调用相应对象的预览方法 eval('0,' + options.scope + '.preview.call(' + options.scope + ', "' + encodeURIComponent(JSON.stringify(data)) + '", "' + encodeURIComponent(JSON.stringify(options.data)) + '")'); break; case 'unPreview': // 调用相应对象的取消预览的方法 eval('0,' + options.scope + '.unPreview.call(' + options.scope + ', "' + encodeURIComponent(JSON.stringify(data)) + '", "' + encodeURIComponent(JSON.stringify(options.data)) + '")'); break; case 'resize': eval('0,' + options.scope + '.dialog.resizeSize.call(' + options.scope + '.dialog, ' + data.params + ')'); if (typeof data.title !== 'undefined') { eval('0,' + options.scope + '.dialog.changeTitle.call(' + options.scope + '.dialog, "' + data.title + '")'); } break; } }; // 对与窗口的postmessage通讯进行管理。 // 现在通讯这一块的模式还没有确定下来,需要跟动态碎片合完才能知道最终是什么样子。 var onMessageHandler = function (e) { var data = JSON.parse(e.data); var action = data.data.action; var options = data.options; if (typeof options === 'string') { options = JSON.parse(decodeURIComponent(options)); } if (typeof action !== 'undefined' && action !== 'save') { disposeAction(action, data.data, options); return; } var handler = options.handler; var scope = options.scope; eval('0,' + scope + '.' + handler + '.call(' + scope + ', "' + encodeURIComponent(JSON.stringify(data.data)) + '", "' + encodeURIComponent(JSON.stringify(options.data)) + '")'); }; lib.ns('topic').postMessage = postMessage; }(topicJquery, topic.utils));