mirror of
https://github.com/chinchang/web-maker.git
synced 2025-08-02 19:37:29 +02:00
Fix call to clearCOnsole in case of detached window. fixes #222
This commit is contained in:
@@ -1,3 +1,6 @@
|
|||||||
|
var mainWindow = window.parent.onMessageFromConsole
|
||||||
|
? window.parent
|
||||||
|
: window.parent.opener;
|
||||||
(function() {
|
(function() {
|
||||||
var logEl,
|
var logEl,
|
||||||
isInitialized = false,
|
isInitialized = false,
|
||||||
@@ -37,18 +40,27 @@
|
|||||||
if (_options.proxyCallback) {
|
if (_options.proxyCallback) {
|
||||||
_options.proxyCallback.apply(null, arguments);
|
_options.proxyCallback.apply(null, arguments);
|
||||||
}
|
}
|
||||||
if (_options.noUi) { return; }
|
if (_options.noUi) {
|
||||||
var el = createElement('div', 'line-height:18px;min-height:18px;background:' +
|
return;
|
||||||
(logEl.children.length % 2 ? 'rgba(255,255,255,0.1)' : '') + ';color:' + color); // zebra lines
|
}
|
||||||
|
var el = createElement(
|
||||||
|
'div',
|
||||||
|
'line-height:18px;min-height:18px;background:' +
|
||||||
|
(logEl.children.length % 2 ? 'rgba(255,255,255,0.1)' : '') +
|
||||||
|
';color:' +
|
||||||
|
color
|
||||||
|
); // zebra lines
|
||||||
var val = [].slice.call(arguments).reduce(function(prev, arg) {
|
var val = [].slice.call(arguments).reduce(function(prev, arg) {
|
||||||
return prev + ' ' + (typeof arg === "object" ? JSON.stringify(arg) : arg);
|
return (
|
||||||
|
prev + ' ' + (typeof arg === 'object' ? JSON.stringify(arg) : arg)
|
||||||
|
);
|
||||||
}, '');
|
}, '');
|
||||||
el.textContent = val;
|
el.textContent = val;
|
||||||
|
|
||||||
logEl.appendChild(el);
|
logEl.appendChild(el);
|
||||||
|
|
||||||
// Scroll to last element, if autoScroll option is set.
|
// Scroll to last element, if autoScroll option is set.
|
||||||
if(_options.autoScroll) {
|
if (_options.autoScroll) {
|
||||||
logEl.scrollTop = logEl.scrollHeight - logEl.clientHeight;
|
logEl.scrollTop = logEl.scrollHeight - logEl.clientHeight;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@@ -56,7 +68,7 @@
|
|||||||
|
|
||||||
function clear() {
|
function clear() {
|
||||||
if (_options.noUi) {
|
if (_options.noUi) {
|
||||||
window.parent.clearConsole();
|
mainWindow.clearConsole();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
logEl.innerHTML = '';
|
logEl.innerHTML = '';
|
||||||
@@ -79,18 +91,20 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
function setOptions(options) {
|
function setOptions(options) {
|
||||||
for(var i in options)
|
for (var i in options)
|
||||||
if(options.hasOwnProperty(i) && _options.hasOwnProperty(i)) {
|
if (options.hasOwnProperty(i) && _options.hasOwnProperty(i)) {
|
||||||
_options[i] = options[i];
|
_options[i] = options[i];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function init(options) {
|
function init(options) {
|
||||||
if (isInitialized) { return; }
|
if (isInitialized) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
isInitialized = true;
|
isInitialized = true;
|
||||||
|
|
||||||
if(options) {
|
if (options) {
|
||||||
setOptions(options);
|
setOptions(options);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -175,19 +189,18 @@
|
|||||||
destroy: checkInitDecorator(destroy)
|
destroy: checkInitDecorator(destroy)
|
||||||
};
|
};
|
||||||
})();
|
})();
|
||||||
var mainWindow = window.parent.onMessageFromConsole ? window.parent : window.parent.opener;
|
|
||||||
screenLog.init({
|
screenLog.init({
|
||||||
noUi: true,
|
noUi: true,
|
||||||
proxyCallback: function () {
|
proxyCallback: function() {
|
||||||
mainWindow.onMessageFromConsole.apply(null, arguments);
|
mainWindow.onMessageFromConsole.apply(null, arguments);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
window._wmEvaluate = function _wmEvaluate(expr) {
|
window._wmEvaluate = function _wmEvaluate(expr) {
|
||||||
try {
|
try {
|
||||||
var result = eval(expr);
|
var result = eval(expr);
|
||||||
} catch(e) {
|
} catch (e) {
|
||||||
mainWindow.onMessageFromConsole.call(null, e);
|
mainWindow.onMessageFromConsole.call(null, e);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
mainWindow.onMessageFromConsole.call(null, result);
|
mainWindow.onMessageFromConsole.call(null, result);
|
||||||
}
|
};
|
||||||
|
Reference in New Issue
Block a user