1 line
5.3 KiB
JSON
1 line
5.3 KiB
JSON
|
{"ast":null,"code":"'use strict';\n\nvar eventUtils = require('./event'),\n JSON3 = require('json3'),\n browser = require('./browser');\n\nvar debug = function debug() {};\n\nif (process.env.NODE_ENV !== 'production') {\n debug = require('debug')('sockjs-client:utils:iframe');\n}\n\nmodule.exports = {\n WPrefix: '_jp',\n currentWindowId: null,\n polluteGlobalNamespace: function polluteGlobalNamespace() {\n if (!(module.exports.WPrefix in global)) {\n global[module.exports.WPrefix] = {};\n }\n },\n postMessage: function postMessage(type, data) {\n if (global.parent !== global) {\n global.parent.postMessage(JSON3.stringify({\n windowId: module.exports.currentWindowId,\n type: type,\n data: data || ''\n }), '*');\n } else {\n debug('Cannot postMessage, no parent window.', type, data);\n }\n },\n createIframe: function createIframe(iframeUrl, errorCallback) {\n var iframe = global.document.createElement('iframe');\n var tref, unloadRef;\n\n var unattach = function unattach() {\n debug('unattach');\n clearTimeout(tref); // Explorer had problems with that.\n\n try {\n iframe.onload = null;\n } catch (x) {// intentionally empty\n }\n\n iframe.onerror = null;\n };\n\n var cleanup = function cleanup() {\n debug('cleanup');\n\n if (iframe) {\n unattach(); // This timeout makes chrome fire onbeforeunload event\n // within iframe. Without the timeout it goes straight to\n // onunload.\n\n setTimeout(function () {\n if (iframe) {\n iframe.parentNode.removeChild(iframe);\n }\n\n iframe = null;\n }, 0);\n eventUtils.unloadDel(unloadRef);\n }\n };\n\n var onerror = function onerror(err) {\n debug('onerror', err);\n\n if (iframe) {\n cleanup();\n errorCallback(err);\n }\n };\n\n var post = function post(msg, origin) {\n debug('post', msg, origin);\n setTimeout(function () {\n try {\n // When the iframe is not loaded, IE raises an exception\n // on 'contentWindow'.\n if (iframe && iframe.contentWindow) {\n iframe.contentWindow.postMessage(msg, origin);\n }\n } catch (x) {// intentionally empty\n }\n }, 0);\n };\n\n iframe.src = iframeUrl;\n iframe.style.display = 'none';\n iframe.style.position = 'absolute';\n\n iframe.onerror = function () {\n onerror('onerror');\n };\n\n iframe.onload = function () {\n debug('onload'); // `onload` is triggered before scripts on the iframe are\n // executed. Give it few seconds to actually load stuff.\n\n clearTimeout(tref);\n tref = setTimeout(function () {\n onerror('onload timeout');\n }, 2000);\n };\n\n global.document.body.appendChild(iframe);\n tref = setTimeout(function () {\n onerror('timeout');\n }, 15000);\n unloadRef = eventUtils.unloadAdd(cleanup);\n return {\n post: post,\n cleanup: cleanup,\n loaded: unattach\n };\n }\n /* eslint no-undef: \"off\", new-cap: \"off\" */\n ,\n createHtmlfile: function createHtmlfile(iframeUrl, errorCallback) {\n var axo = ['Active'].concat('Object').join('X');\n var doc = new global[axo]('htmlfile');\n var tref, unloadRef;\n var iframe;\n\n var unattach = function unattach() {\n clearTimeout(tref);\n iframe.onerror = null;\n };\n\n var cleanup = function cleanup() {\n if (doc) {\n unattach();\n eventUtils.unloadDel(unloadRef);\n iframe.parentNode.removeChild(iframe);\n iframe = doc = null;\n CollectGarbage();\n }\n };\n\n var onerror = function onerror(r) {\n debug('onerror', r);\n\n if (doc) {\n cleanup();\n errorCallback(r);\n }\n };\n\n var post = function post(msg, origin) {\n try {\n // When the iframe is not loaded, IE raises an exception\n // on 'contentWindow'.\n setTimeout(f
|