Last active
December 14, 2015 10:49
-
-
Save superhighway/5074620 to your computer and use it in GitHub Desktop.
Menyiapkan editor Ace dengan fallback jaga-jaga kalau library Ace tidak loaded.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<script type="text/javascript" src="http://cdnjs.cloudflare.com/ajax/libs/prefixfree/1.0.7/prefixfree.min.js"></script> | |
<link rel="stylesheet" href="main.css" /> | |
</head> | |
<body> | |
<div id='snippet-runner'> | |
<div id='snippet-runner-code-content' class='snippet-runner-code-content'>puts "Halo Ruby!"</div> | |
<div class='snippet-runner-code-actions'> | |
<a href='javascript:void(0);' class='snippet-runner-code-action snippet-runner-code-action-run'>Jalankan</a> | |
</div> | |
<div class='snippet-runner-output-container'> | |
<h3>Output</h3> | |
<pre class='snippet-runner-output'></pre> | |
</div> | |
</div> | |
<script src="http://code.jquery.com/jquery-1.9.1.min.js"></script> | |
<script src="http://d1n0x3qji82z53.cloudfront.net/src-min-noconflict/ace.js" type="text/javascript" charset="utf-8"></script> | |
<script src="./main.js" type="text/javascript"></script> | |
</body> | |
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
* { margin: 0; padding: 0; } | |
a { color: #4183C4; text-decoration: none; } | |
#snippet-runner { | |
font-family: Helvetica, Arial, sans-serif; | |
text-align: center; | |
position: fixed; | |
margin: 0; | |
top: 0; | |
right: 0; | |
left: 0; | |
bottom: 0; | |
background-color: #eee; | |
background-image: linear-gradient(top, #eee, #ddd, #888); | |
padding: 0 2%; | |
overflow: auto; | |
} | |
#snippet-runner-code-content { | |
text-shadow: 0 0 0 #fff; | |
margin: 0; | |
text-align: left; | |
max-width: 650px; | |
position: absolute; | |
left: 0; | |
bottom: 50px; | |
right: 20%; | |
top: 0; | |
overflow: auto; | |
} | |
.snippet-runner-code-actions { | |
position: absolute; | |
bottom: 0; | |
left: 0; | |
right: 20%; | |
max-width: 650px; | |
margin: 0; | |
} | |
.snippet-runner-output-container { | |
position: absolute; | |
margin: 0; | |
padding: 10px; | |
text-align: left; | |
left: 80%; | |
top: 0; | |
} | |
@media only screen and (min-width: 813px) { | |
.snippet-runner-output-container { | |
left: 650px; | |
} | |
} | |
.snippet-runner-code-action-run { | |
display: block; | |
padding: 15px; | |
background-image: linear-gradient(top, #ccc, #bbb, #aaa); | |
border: #777 1px solid; | |
font-weight: bold; | |
text-shadow: 0 1px 0 #fff; | |
} | |
.snippet-runner-code-action-run:active { | |
background-image: linear-gradient(bottom, #ccc, #bbb, #aaa); | |
box-shadow: inset 0 0 8px #888; | |
} | |
.snippet-runner-output-container pre { | |
padding: 10px; | |
background: #fff; | |
border-radius: 3px; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(function() { | |
var editor = null; | |
if (window.ace) { | |
editor = ace.edit("snippet-runner-code-content"); | |
editor.setTheme("ace/theme/twilight"); | |
editor.getSession().setMode("ace/mode/ruby"); | |
} | |
function setEditorValue(snippet) { | |
if (window.ace && editor != null) { | |
editor.getSession().setValue(snippet); | |
} else { | |
$("#snippet-runner-code-content").html('<pre>' + snippet + '</pre>'); | |
} | |
} | |
function getEditorValue() { | |
if (window.ace && editor != null) { | |
return editor.getSession().getValue(); | |
} else { | |
return $("#snippet-runner-code-content").text(); | |
} | |
} | |
var evalURL = 'http://nama-app-kamu.herokuapp.com'; | |
$('.snippet-runner-code-action-run').click(function() { | |
var $outputTarget = $runner.find('.snippet-runner-output'), | |
snippet = getEditorValue(); | |
$.post(evalURL, { snippet: snippet }, function(data, textStatus, xhr) { | |
$outputTarget.text(data); | |
}).fail(function() { | |
$outputTarget.html(snippetRequestError); | |
}); | |
}); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment