Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge branch 'master' of github.com:remy/jsbin

  • Loading branch information...
commit 649fd056c10be02979f18b0c0d7e0a232a37bf7c 2 parents 3d6c22e + 60a4be9
@remy remy authored
View
6 public/js/chrome/navigation.js
@@ -166,7 +166,11 @@ $('#jsbinurl').click(function (e) {
});
$('#runwithalerts').click(function () {
- renderLivePreview(true);
+ if (editors.console.visible) {
+ editors.console.render(true);
+ } else {
+ renderLivePreview(true);
+ }
return false;
});
View
14 public/js/editors/editors.js
@@ -315,8 +315,9 @@ var panelInit = {
function hide() {
// detroy the iframe if we hide the panel
// note: $live is defined in live.js
+ // Commented out so that the live iframe is never destroyed
if (panels.panels.console.visible === false) {
- $live.find('iframe').remove();
+ // $live.find('iframe').remove();
}
}
@@ -441,11 +442,12 @@ var editorsReady = setInterval(function () {
// panels.distribute();
// if live is visible, render it
- if (panels.panels.live.visible) {
- panels.panels.live.render(true);
- } else if (panels.panels.console.visible) {
- renderLivePreview(true);
- }
+ // if (panels.panels.live.visible) {
+ // panels.panels.live.render(true);
+ // } else if (panels.panels.console.visible) {
+ // renderLivePreview(true);
+ // }
+ $('#runconsole').trigger('click');
$(window).resize(function () {
clearTimeout(resizeTimer);
View
3  public/js/editors/libraries.js
@@ -245,8 +245,7 @@ var libraries = [
},
{
"url": [
- "http://traceur-compiler.googlecode.com/git/src/traceur.js",
- "http://traceur-compiler.googlecode.com/git/src/bootstrap.js"
+ jsbin.static + "/js/vendor/traceur.js"
],
"label": "Traceur"
},
View
137 public/js/processors/processor.js
@@ -1,46 +1,13 @@
-var render = function() {
- if (jsbin.panels.panels.live.visible && jsbin.panels.ready) {
- jsbin.panels.panels.live.render();
- }
-};
-
-var $processorSelectors = $('div.processorSelector').each(function () {
- var panelId = this.getAttribute('data-type'),
- $el = $(this),
- $label = $el.closest('.label').find('strong a'),
- originalLabel = $label.text();
-
- $el.find('a').click(function (e) {
- var panel = jsbin.panels.panels[panelId];
-
- e.preventDefault();
- var target = this.hash.substring(1),
- label = $(this).text(),
- code;
- if (target !== 'convert') {
- $label.text(label);
- if (target === panelId) {
- jsbin.processors.reset(panelId);
- render();
- } else {
- jsbin.processors.set(panelId, target, render);
- }
- } else {
- $label.text(originalLabel);
- panel.setCode(panel.render());
- jsbin.processors.reset(panelId);
- }
- }).bind('select', function (event, value) {
- if (value === this.hash.substring(1)) {
- $label.text($(this).text());
- }
- });
-});
-
-
var Processor = function (url, init, handler) {
var failed = false;
+ // Overwritten when the script loads
+ var callback = function () {
+ window.console && window.console.warn('Processor is not ready yet - trying again');
+ failed = true;
+ return '';
+ };
+
if (typeof handler === 'undefined') {
handler = init;
init = null;
@@ -49,11 +16,13 @@ var Processor = function (url, init, handler) {
var script = document.createElement('script');
script.src = url;
+ // Script has loaded.
+ // Run any init code, and swap the callback. If we failed, try again.
var scriptCB = function () {
if (init) init();
callback = handler;
if (failed) {
- renderLivePreview();
+ editors.console.render();
}
};
@@ -68,12 +37,6 @@ var Processor = function (url, init, handler) {
document.body.appendChild(script);
- var callback = function () {
- window.console && window.console.warn('Processor is not ready yet - trying again');
- failed = true;
- return '';
- };
-
return function () {
return callback.apply(this, arguments);
};
@@ -207,16 +170,84 @@ var processors = jsbin.processors = {
return css;
});
},
- traceur: function () {
- jsbin.panels.panels.javascript.type = 'traceur';
+ traceur: function (ready) {
+ var SourceMapConsumer,
+ SourceMapGenerator,
+ ProjectWriter,
+ ErrorReporter,
+ hasError;
+ return new Processor(jsbin.static + '/js/vendor/traceur.js', function () {
+ // Only create these once, when the processor is loaded
+ $('#library').val( $('#library').find(':contains("Traceur")').val() ).trigger('change');
+ SourceMapConsumer = traceur.outputgeneration.SourceMapConsumer;
+ SourceMapGenerator = traceur.outputgeneration.SourceMapGenerator;
+ ProjectWriter = traceur.outputgeneration.ProjectWriter;
+ ErrorReporter = traceur.util.ErrorReporter;
+ ready();
+ }, function (source) {
+ hasError = false;
+
+ var reporter = new ErrorReporter();
+ reporter.reportMessageInternal = function(location, kind, format, args) {
+ window.console.error(ErrorReporter.format(location, format, args));
+ };
+
+ var url = location.href;
+ var project = new traceur.semantics.symbols.Project(url);
+ var name = 'jsbin';
+
+ var sourceFile = new traceur.syntax.SourceFile(name, source);
+ project.addFile(sourceFile);
+ var res = traceur.codegeneration.Compiler.compile(reporter, project, false);
+
+ var msg = '/*\nIf you\'ve just translated to JS, make sure traceur is in the HTML panel.\nThis is terrible, sorry, but the only way we could get around race conditions. Eat me.\nHugs & kisses,\nDave xox\n*/\ntry{window.traceur = top.traceur;}catch(e){}\n';
+ return msg + ProjectWriter.write(res);
+ });
+ }
+};
+
- // force select the traceur in the client HTML
- $('#library').val( $('#library').find(':contains("Traceur")').val() ).trigger('change');
- ready();
- return function (source) { return source; };
+var render = function() {
+ if (jsbin.panels.ready) {
+ editors.console.render();
}
};
+var $processorSelectors = $('div.processorSelector').each(function () {
+ var panelId = this.getAttribute('data-type'),
+ $el = $(this),
+ $label = $el.closest('.label').find('strong a'),
+ originalLabel = $label.text();
+
+ $el.find('a').click(function (e) {
+ var panel = jsbin.panels.panels[panelId];
+
+ e.preventDefault();
+ var target = this.hash.substring(1),
+ label = $(this).text(),
+ code;
+ if (target !== 'convert') {
+ $label.text(label);
+ if (target === panelId) {
+ jsbin.processors.reset(panelId);
+ render();
+ } else {
+ jsbin.processors.set(panelId, target, render);
+ }
+ } else {
+ $label.text(originalLabel);
+ panel.setCode(panel.render());
+ jsbin.processors.reset(panelId);
+ }
+ }).bind('select', function (event, value) {
+ if (value === this.hash.substring(1)) {
+ $label.text($(this).text());
+ }
+ });
+});
+
+
+
processors.set = function (panelId, preprocessor, callback) {
var panel = jsbin.panels.panels[panelId];
View
108 public/js/render/console.js
@@ -7,6 +7,10 @@ function sortci(a, b) {
return a.toLowerCase() < b.toLowerCase() ? -1 : 1;
}
+function htmlEntities(str) {
+ return String(str).replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;').replace(/"/g, '&quot;');
+}
+
// custom because I want to be able to introspect native browser objects *and* functions
function stringify(o, simple, visited) {
var json = '', i, vi, type = '', parts = [], names = [], circular = false;
@@ -27,9 +31,12 @@ function stringify(o, simple, visited) {
}
if (circular) {
- json = '[circular]';
+ json = '[circular ' + type.slice(1);
+ if (o.outerHTML) {
+ json += ":\n" + htmlEntities(o.outerHTML);
+ }
} else if (type == '[object String]') {
- json = '"' + o.replace(/"/g, '\\"') + '"';
+ json = '"' + htmlEntities(o.replace(/"/g, '\\"')) + '"';
} else if (type == '[object Array]') {
visited.push(o);
@@ -80,8 +87,9 @@ function stringify(o, simple, visited) {
}
json += parts.join(',\n') + '\n}';
} else {
+ visited.push(o);
try {
- json = stringify(o, true)+''; // should look like an object
+ json = stringify(o, true, visited)+''; // should look like an object
} catch (e) {
}
@@ -101,7 +109,6 @@ function run(cmd) {
return ['info', internalCmd];
} else {
try {
- // if ('CoffeeScript' in sandboxframe.contentWindow) cmd = sandboxframe.contentWindow.CoffeeScript.compile(cmd, {bare:true});
rawoutput = sandboxframe.contentWindow.eval(cmd);
} catch (e) {
rawoutput = e.message;
@@ -133,34 +140,56 @@ function post(cmd, blind, response /* passed in when echoing from remote console
span = document.createElement('span'),
parent = output.parentNode;
- response = response || run(cmd);
-
- if (response !== undefined) {
- el.className = 'response';
- span.innerHTML = response[1];
+ if (!internalCommand(cmd)) {
- if (response[0] != 'info') prettyPrint([span]);
- el.appendChild(span);
+ // Compile the command according the the processor
+ cmd = editors.javascript.processor(cmd);
- li.className = response[0];
- li.innerHTML = '<span class="gutter"></span>';
- li.appendChild(el);
-
- appendLog(li);
-
- exec.value = '';
- if (enableCC) {
- try {
- // document.getElementsByTagName('a')[0].focus();
- if (jsbin.panels.focused.id === 'console') {
- cursor.focus();
- document.execCommand('selectAll', false, null);
- document.execCommand('delete', false, null);
- }
- } catch (e) {}
+ // Fix console not having iframe
+ if (!(sandboxframe && sandboxframe.contentWindow)) {
+ // Boo. There must be a nice way to do this.
+ sandboxframe = $live.find('iframe')[0];
+ // Only force it to render if there's no live iframe
+ if (!(sandboxframe && sandboxframe.contentWindow)) {
+ renderLivePreview(false);
+ sandboxframe = $live.find('iframe')[0];
+ }
+ jsconsole.setSandbox(sandboxframe);
}
}
- pos = history.length;
+
+ // In a setTimeout so that renderLivePreview has time for the iframe to load
+ setTimeout(function () {
+ response = response || run(cmd);
+
+ if (response !== undefined) {
+ el.className = 'response';
+ span.innerHTML = response[1];
+
+ if (response[0] != 'info') prettyPrint([span]);
+ el.appendChild(span);
+
+ li.className = response[0];
+ li.innerHTML = '<span class="gutter"></span>';
+ li.appendChild(el);
+
+ appendLog(li);
+
+ exec.value = '';
+ if (enableCC) {
+ try {
+ // document.getElementsByTagName('a')[0].focus();
+ if (jsbin.panels.focused.id === 'console') {
+ cursor.focus();
+ document.execCommand('selectAll', false, null);
+ document.execCommand('delete', false, null);
+ }
+ } catch (e) {}
+ }
+ }
+ pos = history.length;
+ }, 0);
+
}
function log(msg, className) {
@@ -318,22 +347,26 @@ window._console = {
for (; i < l; i++) {
log(stringify(arguments[i], true));
}
+ window.console.log.apply(window.console, arguments);
},
dir: function () {
var l = arguments.length, i = 0;
for (; i < l; i++) {
log(stringify(arguments[i]));
}
+ window.console.dir.apply(window.console, arguments);
},
props: function (obj) {
var props = [], realObj;
try {
for (var p in obj) props.push(p);
} catch (e) {}
+ window.console.props.apply(window.console, arguments);
return props;
},
error: function (err) {
log(err.message, 'error');
+ window.console.error.apply(window.console, arguments);
}
};
@@ -998,14 +1031,14 @@ function upgradeConsolePanel(console) {
console.reset = function () {
jsconsole.reset();
};
- console.settings.render = function () {
-
- // TODO decide whether we should also grab all the JS in the HTML panel
- var code = editors.javascript.render().trim();
- jsconsole.setSandbox($live.find('iframe')[0]);
- jsconsole.onload(function () {
+ console.settings.render = function (withAlerts) {
+ var html = editors.html.render().trim();
+ if (html === "") {
+ var code = editors.javascript.render().trim();
jsconsole.run(code);
- });
+ } else {
+ renderLivePreview(withAlerts || false);
+ }
};
console.settings.show = function () {
jsconsole.clear();
@@ -1017,9 +1050,10 @@ function upgradeConsolePanel(console) {
}, 0);
};
console.settings.hide = function () {
+ // Removal code is commented out so that the
+ // output iframe is never removed
if (!editors.live.visible) {
- // renderLivePreview();
- $live.find('iframe').remove();
+ // $live.find('iframe').remove();
}
};
// jsconsole.ready = true;
View
8 public/js/render/live.js
@@ -91,7 +91,7 @@ function two(s) {
}
function renderLivePreview(withalerts) {
- var source = getPreparedCode(jsbin.panels.panels.console.visible),
+ var source = getPreparedCode(), //jsbin.panels.panels.console.visible),
remove = $live.find('iframe').length > 0,
$frame = $live.prepend('<iframe class="stretch" frameBorder="0"></iframe>').find('iframe:first'),
frame = $frame[0],
@@ -214,9 +214,9 @@ function renderLivePreview(withalerts) {
$live.find('iframe:last').remove();
}
- if (jsbin.panels.panels.console.visible) {
- jsbin.panels.panels.console.render(); // now run the JS
- }
+ // if (jsbin.panels.panels.console.visible) {
+ // jsbin.panels.panels.console.render(); // now run the JS
+ // }
};
// WebKit requires a wait time before actually writing to the iframe
View
13,534 public/js/vendor/traceur.js
13,534 additions, 0 deletions not shown
Please sign in to comment.
Something went wrong with that request. Please try again.