Browse files

added generate snippet url to editor.html

  • Loading branch information...
1 parent 49143b1 commit 40dbe4e370481086e8d686d5631fb8ee81bd5d02 @leafo committed Jul 24, 2012
Showing with 78 additions and 20 deletions.
  1. +8 −4 editor.html
  2. +19 −4 index.coffee
  3. +1 −1 templates/web.html
  4. +1 −1 www/.gitignore
  5. +36 −9 www/index.js
  6. +13 −1 www/style/style.css
View
12 editor.html
@@ -1,6 +1,11 @@
link_to_home: true
--
+<div class="save-snippet">
+ <input type="text" id="snippet-url" />
+ <button id="snippet-button">Generate Snippet URL</button>
+</div>
+
<h2>Online Compiler</h2>
<div class="full-editor">
@@ -12,15 +17,14 @@
<button id="clear-button">Clear</button>
</div>
-<pre id="demo-out" class="full-output"><em>CSS comes here...</em></pre>
+<strong>Output:</strong>
+<pre id="demo-out" class="full-output"><em>Type some LESS and click Compile!</em></pre>
-<script type="text/javascript" src="$root/index.js"></script>
+<script type="text/javascript" src="$root/index.js?$generate_date"></script>
<script type="text/javascript">
setup_editor(false);
window.onload = function() {
editor.focus()
}
</script>
-
-
View
23 index.coffee
@@ -175,7 +175,7 @@ window.setup_editor = (show_example=true)->
output_node = $ "demo-out"
- $("compile-button").onclick = ->
+ compile = ->
output_node.innerHTML = "Processing..."
css = encodeURIComponent editor.getValue()
send "go.php", "css=#{css}", (req) ->
@@ -184,8 +184,24 @@ window.setup_editor = (show_example=true)->
else
req.responseText
- $("clear-button").onclick = ->
- editor.setValue ""
+ $("compile-button").onclick = compile
+ $("clear-button").onclick = -> editor.setValue ""
+
+ # snippet button
+ if snippet_button = $("snippet-button")
+ snippet_url = $("snippet-url")
+ snippet_button.onclick = ->
+ base = window.location.href.match(/^([^#]*)/)
+ snippet_url.value = base + "#" + encodeURIComponent(editor.getValue())
+ snippet_url.focus()
+ snippet_url.select()
+
+ # loading a snippet in the url?
+ unless show_example
+ hash = window.location.hash.substr(1)
+ if hash.length > 0
+ editor.setValue decodeURIComponent hash
+ compile()
## commit callback
window.github_commit_callback = (out) ->
@@ -236,7 +252,6 @@ window.load_github_commits = ->
document.body.appendChild script
-
window.leafo = {
track_event: (cat, action, label, value=0, interactive=true) ->
try
View
2 templates/web.html
@@ -5,7 +5,7 @@
<title>lessphp - $title</title>
<link rel="stylesheet" href="$root/style/normalize.css" />
<link rel="stylesheet" href="$root/style/960.css" />
- <link rel="stylesheet" href="$root/style/style.css?1" />
+ <link rel="stylesheet" href="$root/style/style.css?$generate_date" />
<link rel="stylesheet" href="$root/codemirror2/lib/codemirror.css" />
<link rel="stylesheet" href="$root/codemirror2/theme/default.css" />
View
2 www/.gitignore
@@ -1,5 +1,5 @@
docs/index.html
editor.html
-changelog.html
index.html
+changelog.html
feed.xml
View
45 www/index.js
@@ -1,3 +1,4 @@
+// Generated by CoffeeScript 1.3.1
(function() {
var $, div, editor, examples, format_date, send;
@@ -73,29 +74,51 @@
editor = null;
window.setup_editor = function(show_example) {
- var output_node;
- if (show_example == null) show_example = true;
+ var compile, hash, output_node, snippet_button, snippet_url;
+ if (show_example == null) {
+ show_example = true;
+ }
window.editor = editor = CodeMirror.fromTextArea($("editor-code"), {
tabMode: "shift",
lineNumbers: true
});
- if (show_example) editor.setValue(examples["default"]);
+ if (show_example) {
+ editor.setValue(examples["default"]);
+ }
output_node = $("demo-out");
- $("compile-button").onclick = function() {
+ compile = function() {
var css;
output_node.innerHTML = "Processing...";
css = encodeURIComponent(editor.getValue());
return send("go.php", "css=" + css, function(req) {
return output_node.innerHTML = req.responseText === "" ? '<i class="hint">no output</i>' : req.responseText;
});
};
- return $("clear-button").onclick = function() {
+ $("compile-button").onclick = compile;
+ $("clear-button").onclick = function() {
return editor.setValue("");
};
+ if (snippet_button = $("snippet-button")) {
+ snippet_url = $("snippet-url");
+ snippet_button.onclick = function() {
+ var base;
+ base = window.location.href.match(/^([^#]*)/);
+ snippet_url.value = base + "#" + encodeURIComponent(editor.getValue());
+ snippet_url.focus();
+ return snippet_url.select();
+ };
+ if (!show_example) {
+ hash = window.location.hash.substr(1);
+ if (hash.length > 0) {
+ editor.setValue(decodeURIComponent(hash));
+ return compile();
+ }
+ }
+ }
};
window.github_commit_callback = function(out) {
- var commits, container, i, max, more, repo_url, _fn;
+ var commits, container, i, max, more, repo_url, _fn, _i;
commits = out.commits;
container = $("commit-list");
while (container.firstChild) {
@@ -119,7 +142,7 @@
};
return container.appendChild(node);
};
- for (i = 0; 0 <= max ? i < max : i > max; 0 <= max ? i++ : i--) {
+ for (i = _i = 0; 0 <= max ? _i < max : _i > max; i = 0 <= max ? ++_i : --_i) {
_fn(i);
}
repo_url = "http://github.com/leafo/lessphp/commits/master";
@@ -164,8 +187,12 @@
window.leafo = {
track_event: function(cat, action, label, value, interactive) {
- if (value == null) value = 0;
- if (interactive == null) interactive = true;
+ if (value == null) {
+ value = 0;
+ }
+ if (interactive == null) {
+ interactive = true;
+ }
try {
return _gaq.push(['_trackEvent', cat, action, label, value, interactive]);
} catch (e) {
View
14 www/style/style.css
@@ -7,7 +7,7 @@
border: 1px solid #EBEBAA;
}
-.new strong {
+strong {
color: #59502B;
}
@@ -367,3 +367,15 @@ td {
padding: 4px 12px;
}
+
+.save-snippet {
+ margin-top: 15px;
+ float: right;
+}
+
+.save-snippet input {
+ border: 1px solid silver;
+ border-radius: 2px;
+}
+
+

0 comments on commit 40dbe4e

Please sign in to comment.