kopia lustrzana https://github.com/c9/core
do not create browser evaluator iframe at startup
rodzic
8b0453bdc5
commit
27caac758d
|
@ -1,5 +1,5 @@
|
||||||
define(function(require, exports, module) {
|
define(function(require, exports, module) {
|
||||||
main.consumes = ["immediate", "settings", "Evaluator", "ui"];
|
main.consumes = ["Evaluator", "ui"];
|
||||||
main.provides = ["immediate.browserjs"];
|
main.provides = ["immediate.browserjs"];
|
||||||
return main;
|
return main;
|
||||||
|
|
||||||
|
@ -19,8 +19,6 @@ define(function(require, exports, module) {
|
||||||
|
|
||||||
function main(options, imports, register) {
|
function main(options, imports, register) {
|
||||||
var Evaluator = imports.Evaluator;
|
var Evaluator = imports.Evaluator;
|
||||||
var settings = imports.settings;
|
|
||||||
var immediate = imports.immediate;
|
|
||||||
var ui = imports.ui;
|
var ui = imports.ui;
|
||||||
|
|
||||||
/***** Initialization *****/
|
/***** Initialization *****/
|
||||||
|
@ -36,13 +34,11 @@ define(function(require, exports, module) {
|
||||||
});
|
});
|
||||||
// var emit = plugin.getEmitter();
|
// var emit = plugin.getEmitter();
|
||||||
|
|
||||||
var iframe, win;
|
var iframe;
|
||||||
|
var win;
|
||||||
var loaded;
|
|
||||||
function load() {
|
|
||||||
if (loaded) return;
|
|
||||||
loaded = true;
|
|
||||||
|
|
||||||
|
function createIframe() {
|
||||||
|
if (iframe) return;
|
||||||
iframe = document.body.appendChild(document.createElement("iframe"));
|
iframe = document.body.appendChild(document.createElement("iframe"));
|
||||||
iframe.setAttribute("nwdisable", "nwdisable");
|
iframe.setAttribute("nwdisable", "nwdisable");
|
||||||
|
|
||||||
|
@ -411,6 +407,7 @@ define(function(require, exports, module) {
|
||||||
}
|
}
|
||||||
|
|
||||||
function evaluate(expression, cell, cb) {
|
function evaluate(expression, cell, cb) {
|
||||||
|
if (!iframe) createIframe();
|
||||||
// Ignore heroku command if typed
|
// Ignore heroku command if typed
|
||||||
// str = str.replace(/^heroku\s+/, "");
|
// str = str.replace(/^heroku\s+/, "");
|
||||||
|
|
||||||
|
@ -445,6 +442,7 @@ define(function(require, exports, module) {
|
||||||
}
|
}
|
||||||
|
|
||||||
function evaluateHeadless(expression) {
|
function evaluateHeadless(expression) {
|
||||||
|
if (!iframe) createIframe();
|
||||||
try {
|
try {
|
||||||
win.thrown = false;
|
win.thrown = false;
|
||||||
win.result = win.eval(expression);
|
win.result = win.eval(expression);
|
||||||
|
@ -485,7 +483,6 @@ define(function(require, exports, module) {
|
||||||
/***** Lifecycle *****/
|
/***** Lifecycle *****/
|
||||||
|
|
||||||
plugin.on("load", function() {
|
plugin.on("load", function() {
|
||||||
load();
|
|
||||||
});
|
});
|
||||||
plugin.on("canEvaluate", function(e) {
|
plugin.on("canEvaluate", function(e) {
|
||||||
return canEvaluate(e.expression);
|
return canEvaluate(e.expression);
|
||||||
|
@ -500,7 +497,8 @@ define(function(require, exports, module) {
|
||||||
|
|
||||||
});
|
});
|
||||||
plugin.on("unload", function() {
|
plugin.on("unload", function() {
|
||||||
loaded = false;
|
iframe && iframe.remove();
|
||||||
|
win = iframe = null;
|
||||||
});
|
});
|
||||||
|
|
||||||
/***** Register and define API *****/
|
/***** Register and define API *****/
|
||||||
|
|
Ładowanie…
Reference in New Issue