From 580cfebbab5f6054b8e87449571f568c4b38e3bc Mon Sep 17 00:00:00 2001 From: Kushagra Gour Date: Mon, 8 May 2017 01:37:58 +0530 Subject: [PATCH] add console exec feature --- src/index.html | 12 ++++++++++-- src/screenlog.js | 11 ++++++++++- src/script.js | 16 ++++++++++++---- src/style.css | 10 +++++----- 4 files changed, 37 insertions(+), 12 deletions(-) diff --git a/src/index.html b/src/index.html index 40947a4..f8d4dc2 100644 --- a/src/index.html +++ b/src/index.html @@ -101,7 +101,7 @@
-
+
Console @@ -117,7 +117,10 @@
- + + + +
@@ -601,6 +604,11 @@ + + + + + diff --git a/src/screenlog.js b/src/screenlog.js index 8a23762..8d9d67a 100644 --- a/src/screenlog.js +++ b/src/screenlog.js @@ -171,4 +171,13 @@ screenLog.init({ proxyCallback: function () { window.parent.onMessageFromConsole.apply(null, arguments); } -}); \ No newline at end of file +}); +window._wmEvaluate = function _wmEvaluate(expr) { + try { + var result = eval(expr); + } catch(e) { + window.parent.onMessageFromConsole.call(null, e); + return; + } + window.parent.onMessageFromConsole.call(null, result); +} \ No newline at end of file diff --git a/src/script.js b/src/script.js index de98319..3841336 100644 --- a/src/script.js +++ b/src/script.js @@ -92,6 +92,7 @@ runBtn, searchInput, consoleEl, consoleLogEl scope.cm = {}; scope.consoleCm; + scope.frame = frame; scope.demoFrameDocument = frame.contentDocument || frame.contentWindow.document; // Check all the code wrap if they are minimized or not @@ -1304,23 +1305,29 @@ runBtn, searchInput, consoleEl, consoleLogEl }; scope.toggleConsole = function () { - consoleEl.classList.toggle('is-open'); + consoleEl.classList.toggle('is-minimized'); }; scope.clearConsole = function () { scope.consoleCm.setValue(''); }; - + scope.evalConsoleExpr = function (e) { + if (e.which === 13) { + window.onMessageFromConsole('> ' + e.target.value); + frame.contentWindow._wmEvaluate(e.target.value); + e.target.value = ''; + } + }; window.onMessageFromConsole = function() { [...arguments].forEach(function(arg) { - if (arg.indexOf && arg.indexOf('filesystem:chrome-extension') !== -1) { + if (arg && arg.indexOf && arg.indexOf('filesystem:chrome-extension') !== -1) { arg = arg.replace(/filesystem:chrome-extension.*\.js:(\d+):(\d+)/g, 'script $1:$2'); } scope.consoleCm.replaceRange('\n' + arg + ((arg + '').match(/\[object \w+\]/) ? JSON.stringify(arg) : '') + ' ', {line: Infinity}); + scope.consoleCm.scrollTo(0, Infinity); }); } function compileNodes() { - function attachListenerForEvent(eventName) { const nodes = $all(`[d-${eventName}]`); nodes.forEach(function (el) { @@ -1332,6 +1339,7 @@ runBtn, searchInput, consoleEl, consoleLogEl attachListenerForEvent('click'); attachListenerForEvent('change'); attachListenerForEvent('input'); + attachListenerForEvent('keypress'); } function init () { diff --git a/src/style.css b/src/style.css index c02108a..393e9ef 100644 --- a/src/style.css +++ b/src/style.css @@ -824,13 +824,13 @@ li.CodeMirror-hint-active { height: 30vh; left: 0; right: 0; - transform: translateY(calc(100% - 30px)); - transition: transform 0.4s cubic-bezier(0.77,-0.1,0.13,0.9); -} -.console.is-open { transform: translateY(0); + transition: transform 0.4s cubic-bezier(0.76, 0.01, 0.13, 0.9); +} +.console.is-minimized { + transform: translateY(calc(100% - 30px)); } .console .Codemirror { height: auto; - max-height: calc(100% - 50px); + max-height: calc(100% - 70px); } \ No newline at end of file