Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 17 additions & 3 deletions src/sandbox-console.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,17 @@ var Sandbox = {
}
},

log: function(val) {
var history = this.get('history');
var item = {
command : val,
resultHidden : true
};
history.push(item);
this.set({ history : history}).change();
this.save();
},

// Adds a new item to the history
addHistory: function(item) {
var history = this.get('history');
Expand All @@ -92,6 +103,7 @@ var Sandbox = {
iframeSetup : function() {
this.sandboxFrame = $('<iframe width="0" height="0"/>').css({visibility : 'hidden'}).appendTo('body')[0];
this.sandbox = this.sandboxFrame.contentWindow;
this.sandbox.log = this.log;

// This should help IE run eval inside the iframe.
if (!this.sandbox.eval && this.sandbox.execScript) {
Expand Down Expand Up @@ -128,9 +140,10 @@ var Sandbox = {
return false;

var item = {
command : command
command : command,
resultHidden : false
};

// Evaluate the command and store the eval result, adding some basic classes for syntax-highlighting
try {
item.result = this.get('iframe') ? this.iframeEval(command) : eval.call(window, command);
Expand Down Expand Up @@ -211,7 +224,8 @@ var Sandbox = {
_hidden : command._hidden,
_class : command._class,
command : this.toEscaped(command.command),
result : this.toEscaped(command.result)
result : this.toEscaped(command.result),
resultHidden : command.resultHidden
});
}, "", this)
);
Expand Down
13 changes: 7 additions & 6 deletions src/sandbox.html
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@

<!-- The command/result template (NB whitespace/line breaks matter inside <pre> tag): -->
<script type="text/template" id="tplCommand"><% if (! _hidden) { %><span class="command"><%= command %></span>
<span class="prefix"><%= this.resultPrefix %></span><span class="<%= _class %>"><%= result %></span>
<% } %></script>
<%if (! resultHidden) {%><span class="prefix"><%= this.resultPrefix %></span><span class="<%= _class %>"><%= result %></span>
<% } } %></script>


<!-- Scripts -->
Expand All @@ -47,12 +47,13 @@
<script type="text/javascript">
jQuery(document).ready(function($) {
// Create the sandbox:
var model = new Sandbox.Model({
iframe : true, // evaluate commands inside a hidden iframe (default: false)
fallback : true // use global eval if iframe isn't available (default: true)
});
window.sandbox = new Sandbox.View({
el : $('#sandbox'),
model : new Sandbox.Model({
iframe : true, // evaluate commands inside a hidden iframe (default: false)
fallback : true // use global eval if iframe isn't available (default: true)
})
model : model
});
});
</script>
Expand Down