Move to static, rewrite client-JS

This commit is contained in:
John Crepezzi 2011-11-18 10:17:41 -05:00
parent 5b874e3456
commit c5a551f770
7 changed files with 181 additions and 65 deletions

115
static/application.js Normal file
View file

@ -0,0 +1,115 @@
var heist_document = function() {
this.locked = false;
};
heist_document.prototype.save = function(data, callback) {
if (this.locked) {
return false;
}
var high = hljs.highlightAuto(data);
var pack = {
language: high.language,
data: data
};
pack.value = high.value;
pack.uuid = '123456';
this.locked = true;
callback(pack);
};
var heist = function(appName) {
this.appName = appName;
this.setTitle();
this.$textarea = $('textarea');
this.$box = $('#box');
this.$code = $('#box code');
this.configureShortcuts();
};
// Set the page title - include the appName
heist.prototype.setTitle = function(ext) {
var title = ext ? this.appName + ' - ' + ext : this.appName;
document.title = title;
};
// Remove the current document (if there is one)
// and set up for a new one
heist.prototype.newDocument = function(ext) {
this.doc = new heist_document();
this.$box.hide();
this.$textarea.val('').show().focus();
}
// Lock the current document
heist.prototype.lockDocument = function() {
var _this = this;
this.doc.save(this.$textarea.val(), function(ret) {
if (ret) {
_this.$code.html(ret.value);
_this.setTitle(ret.language);
_this.$textarea.val('').hide();
_this.$box.show();
}
});
};
// Configure keyboard shortcuts for the textarea
heist.prototype.configureShortcuts = function() {
var _this = this;
this.$textarea.keyup(function(evt) {
// ^L for lock
if (evt.ctrlKey && evt.which === 76) {
_this.lockDocument();
}
});
};
// TODO refuse to lock empty documents
// TODO support for browsers without pushstate
// TODO support for push state navigation
// TODO ctrl-n for new
// TODO ctrl-d for duplicate
$(function() {
$('textarea').focus();
$('textarea').keydown(function(evt) {
if (evt.keyCode === 9) {
evt.preventDefault();
var myValue = ' ';
// http://stackoverflow.com/questions/946534/insert-text-into-textarea-with-jquery
// For browsers like Internet Explorer
if (document.selection) {
this.focus();
sel = document.selection.createRange();
sel.text = myValue;
this.focus();
}
// Mozilla and Webkit
else if (this.selectionStart || this.selectionStart == '0') {
var startPos = this.selectionStart;
var endPos = this.selectionEnd;
var scrollTop = this.scrollTop;
this.value = this.value.substring(0, startPos) + myValue +
this.value.substring(endPos,this.value.length);
this.focus();
this.selectionStart = startPos + myValue.length;
this.selectionEnd = startPos + myValue.length;
this.scrollTop = scrollTop;
}
else {
this.value += myValue;
this.focus();
}
}
});
});

1
static/highlight.min.js vendored Normal file

File diff suppressed because one or more lines are too long

56
static/index.html Normal file
View file

@ -0,0 +1,56 @@
<html>
<head>
<title>heist</title>
<link rel="stylesheet" type="text/css" href="solarized_dark.css"/>
<style type="text/css">
body {
background: #002B36;
padding: 0px;
margin: 0px;
}
textarea {
background: transparent;
border: 0px;
color: #fff;
padding: 20px;
width: 100%;
height: 100%;
font-family: monospace;
outline: none;
resize: none;
font-size: 13px;
}
#box {
padding: 0px;
width: 100%;
height: 100%;
}
#box code {
padding: 20px;
}
</style>
<script type="text/javascript" src="jquery-1.7.min.js"></script>
<script type="text/javascript" src="highlight.min.js"></script>
<script type="text/javascript" src="application.js"></script>
<script type="text/javascript">
$(function() {
var app = new heist('heist');
app.newDocument();
});
</script>
</head>
<body>
<pre id="box" style="display:none;"><code></code></pre>
<textarea spellcheck="false" style="display:none;"></textarea>
</body>
</html>

4
static/jquery-1.7.min.js vendored Normal file

File diff suppressed because one or more lines are too long

96
static/solarized_dark.css Normal file
View file

@ -0,0 +1,96 @@
/*
Orginal Style from ethanschoonover.com/solarized (c) Jeremy Hull <sourdrums@gmail.com>
*/
pre code {
display: block; padding: 0.5em;
background: #002b36; color: #839496;
}
pre .comment,
pre .template_comment,
pre .diff .header,
pre .doctype,
pre .lisp .string,
pre .javadoc {
color: #586e75;
font-style: italic;
}
pre .keyword,
pre .css .rule .keyword,
pre .winutils,
pre .javascript .title,
pre .method,
pre .addition,
pre .css .tag,
pre .lisp .title {
color: #859900;
}
pre .number,
pre .command,
pre .string,
pre .tag .value,
pre .phpdoc,
pre .tex .formula,
pre .regexp,
pre .hexcolor {
color: #2aa198;
}
pre .title,
pre .localvars,
pre .function .title,
pre .chunk,
pre .decorator,
pre .builtin,
pre .built_in,
pre .lisp .title,
pre .identifier,
pre .title .keymethods,
pre .id {
color: #268bd2;
}
pre .tag .title,
pre .rules .property,
pre .django .tag .keyword {
font-weight: bold;
}
pre .attribute,
pre .variable,
pre .instancevar,
pre .lisp .body,
pre .smalltalk .number,
pre .constant,
pre .class .title,
pre .parent,
pre .haskell .label {
color: #b58900;
}
pre .preprocessor,
pre .pi,
pre .shebang,
pre .symbol,
pre .diff .change,
pre .special,
pre .keymethods,
pre .attr_selector,
pre .important,
pre .subst,
pre .cdata {
color: #cb4b16;
}
pre .deletion {
color: #dc322f;
}
pre .tex .formula {
background: #073642;
}