diff --git a/static/application.js b/static/application.js
index 16ab0ad..b87106b 100644
--- a/static/application.js
+++ b/static/application.js
@@ -194,9 +194,10 @@ haste.prototype.goToLine = function(lineNum) {
// If there was a line before, remove the highlight from it
if (typeof this.line != 'undefined') {
this.line.removeClass("highlight");
+ $(".line[rel='L"+ lineNum +"']").removeClass("highlight");
}
// Scroll to the line and add a highlight to it
- this.line = $("#linenos span[rel='#L"+ lineNum +"']").addClass("highlight");
+ this.line = $("#linenos span[rel='#L"+ lineNum +"'], .line[rel='L"+ lineNum +"']").addClass("highlight");
window.scrollTo(0, this.line.offset().top);
};
@@ -226,6 +227,16 @@ haste.prototype.removeLineNumbers = function() {
$('#linenos').html('>');
};
+// Injects code with line spans in to the code box
+haste.prototype.setCode = function(code) {
+ var lines = new Array();
+ $.each(code.split("\n"), function (index, value) {
+ var index = index + 1; // Because line numbers aren't 0 based :)
+ lines[index] = "" + value + "\n";
+ });
+ this.$code.html(lines.join(""));
+}
+
// Load a document and show it
haste.prototype.loadDocument = function(key) {
// Split the key up
@@ -235,7 +246,7 @@ haste.prototype.loadDocument = function(key) {
_this.doc = new haste_document();
_this.doc.load(parts[0], function(ret) {
if (ret) {
- _this.$code.html(ret.value);
+ _this.setCode(ret.value);
_this.setTitle(ret.key);
_this.fullKey();
_this.$textarea.val('').hide();
@@ -268,7 +279,7 @@ haste.prototype.lockDocument = function() {
_this.showMessage(err.message, 'error');
}
else if (ret) {
- _this.$code.html(ret.value);
+ _this.setCode(ret.value);
_this.setTitle(ret.key);
var file = '/' + ret.key;
if (ret.language) {
diff --git a/static/application.min.js b/static/application.min.js
index fa7e0d1..fb0299a 100644
--- a/static/application.min.js
+++ b/static/application.min.js
@@ -1 +1 @@
-var haste_document=function(){this.locked=!1};haste_document.prototype.htmlEscape=function(e){return e.replace(/&/g,"&").replace(/>/g,">").replace(/'+e+"");$("#messages").prepend(n),setTimeout(function(){n.slideUp("fast",function(){$(this).remove()})},3e3)},haste.prototype.lightKey=function(){this.configureKey(["new","save"])},haste.prototype.fullKey=function(){this.configureKey(["new","duplicate","twitter","raw"])},haste.prototype.configureKey=function(e){var t,n=0;$("#box2 .function").each(function(){t=$(this);for(n=0;n'+num+"
";var r=this;listener=function(e){e.preventDefault(),r.ignoreLast=!0,window.location.hash=$(this).attr("rel"),r.goToLine($(this).attr("rel").substring(2))},$("#linenos").html(t),$("#linenos span").click(listener)},haste.prototype.removeLineNumbers=function(){$("#linenos").html(">")},haste.prototype.loadDocument=function(e){var t=e.split(".",2),n=this;n.doc=new haste_document,n.doc.load(t[0],function(e){e?(n.$code.html(e.value),n.setTitle(e.key),n.fullKey(),n.$textarea.val("").hide(),n.$box.show().focus(),n.addLineNumbers(e.lineCount),typeof window.location.hash!="undefined"&&window.location.hash!=""&&n.goToLine()):n.newDocument()},this.lookupTypeByExtension(t[1]))},haste.prototype.duplicateDocument=function(){if(this.doc.locked){var e=this.doc.data;this.newDocument(),this.$textarea.val(e)}},haste.prototype.lockDocument=function(){var e=this;this.doc.save(this.$textarea.val(),function(t,n){if(t)e.showMessage(t.message,"error");else if(n){e.$code.html(n.value),e.setTitle(n.key);var r="/"+n.key;n.language&&(r+="."+e.lookupExtensionByType(n.language)),window.history.pushState(null,e.appName+"-"+n.key,r),e.fullKey(),e.$textarea.val("").hide(),e.$box.show().focus(),e.addLineNumbers(n.lineCount)}})},haste.prototype.configureButtons=function(){var e=this;this.buttons=[{$where:$("#box2 .save"),label:"Save",shortcutDescription:"control + s",shortcut:function(e){return e.ctrlKey&&e.keyCode===83},action:function(){e.$textarea.val().replace(/^\s+|\s+$/g,"")!==""&&e.lockDocument()}},{$where:$("#box2 .new"),label:"New",shortcut:function(e){return e.ctrlKey&&e.keyCode===78},shortcutDescription:"control + n",action:function(){e.newDocument(!e.doc.key)}},{$where:$("#box2 .duplicate"),label:"Duplicate & Edit",shortcut:function(t){return e.doc.locked&&t.ctrlKey&&t.keyCode===68},shortcutDescription:"control + d",action:function(){e.duplicateDocument()}},{$where:$("#box2 .raw"),label:"Just Text",shortcut:function(e){return e.ctrlKey&&e.shiftKey&&e.keyCode===82},shortcutDescription:"control + shift + r",action:function(){window.location.href="/raw/"+e.doc.key}},{$where:$("#box2 .twitter"),label:"Twitter",shortcut:function(t){return e.options.twitter&&e.doc.locked&&t.shiftKey&&t.ctrlKey&&t.keyCode==84},shortcutDescription:"control + shift + t",action:function(){window.open("https://twitter.com/share?url="+encodeURI(window.location.href))}}];for(var t=0;t/g,">").replace(/'+e+"");$("#messages").prepend(n),setTimeout(function(){n.slideUp("fast",function(){$(this).remove()})},3e3)},haste.prototype.lightKey=function(){this.configureKey(["new","save"])},haste.prototype.fullKey=function(){this.configureKey(["new","duplicate","twitter","raw"])},haste.prototype.configureKey=function(e){var t,n=0;$("#box2 .function").each(function(){t=$(this);for(n=0;n'+num+"
";var r=this;listener=function(e){e.preventDefault(),r.ignoreLast=!0,window.location.hash=$(this).attr("rel"),r.goToLine($(this).attr("rel").substring(2))},$("#linenos").html(t),$("#linenos span").click(listener)},haste.prototype.removeLineNumbers=function(){$("#linenos").html(">")},haste.prototype.setCode=function(e){var t=new Array;$.each(e.split("\n"),function(e,n){var e=e+1;t[e]=""+n+"\n"}),this.$code.html(t.join(""))},haste.prototype.loadDocument=function(e){var t=e.split(".",2),n=this;n.doc=new haste_document,n.doc.load(t[0],function(e){e?(n.setCode(e.value),n.setTitle(e.key),n.fullKey(),n.$textarea.val("").hide(),n.$box.show().focus(),n.addLineNumbers(e.lineCount),typeof window.location.hash!="undefined"&&window.location.hash!=""&&n.goToLine()):n.newDocument()},this.lookupTypeByExtension(t[1]))},haste.prototype.duplicateDocument=function(){if(this.doc.locked){var e=this.doc.data;this.newDocument(),this.$textarea.val(e)}},haste.prototype.lockDocument=function(){var e=this;this.doc.save(this.$textarea.val(),function(t,n){if(t)e.showMessage(t.message,"error");else if(n){e.setCode(n.value),e.setTitle(n.key);var r="/"+n.key;n.language&&(r+="."+e.lookupExtensionByType(n.language)),window.history.pushState(null,e.appName+"-"+n.key,r),e.fullKey(),e.$textarea.val("").hide(),e.$box.show().focus(),e.addLineNumbers(n.lineCount)}})},haste.prototype.configureButtons=function(){var e=this;this.buttons=[{$where:$("#box2 .save"),label:"Save",shortcutDescription:"control + s",shortcut:function(e){return e.ctrlKey&&e.keyCode===83},action:function(){e.$textarea.val().replace(/^\s+|\s+$/g,"")!==""&&e.lockDocument()}},{$where:$("#box2 .new"),label:"New",shortcut:function(e){return e.ctrlKey&&e.keyCode===78},shortcutDescription:"control + n",action:function(){e.newDocument(!e.doc.key)}},{$where:$("#box2 .duplicate"),label:"Duplicate & Edit",shortcut:function(t){return e.doc.locked&&t.ctrlKey&&t.keyCode===68},shortcutDescription:"control + d",action:function(){e.duplicateDocument()}},{$where:$("#box2 .raw"),label:"Just Text",shortcut:function(e){return e.ctrlKey&&e.shiftKey&&e.keyCode===82},shortcutDescription:"control + shift + r",action:function(){window.location.href="/raw/"+e.doc.key}},{$where:$("#box2 .twitter"),label:"Twitter",shortcut:function(t){return e.options.twitter&&e.doc.locked&&t.shiftKey&&t.ctrlKey&&t.keyCode==84},shortcutDescription:"control + shift + t",action:function(){window.open("https://twitter.com/share?url="+encodeURI(window.location.href))}}];for(var t=0;t