1
0
Fork 0
mirror of https://github.com/seejohnrun/haste-server.git synced 2024-11-01 03:21:21 +00:00

Working line number support - just waiting on a final color from @bridawson

[#5]
This commit is contained in:
John Crepezzi 2011-12-15 21:26:57 -05:00
parent 49bb449141
commit 3a6b36ebaa
4 changed files with 41 additions and 4 deletions

View file

@ -1,6 +1,6 @@
body { body {
background: #002B36; background: #002B36;
padding: 20px; padding: 20px 50px;
margin: 0px; margin: 0px;
} }
@ -19,6 +19,20 @@ textarea {
font-size: 13px; font-size: 13px;
} }
/* the line numbers */
#linenos {
color: #003366;
z-index: -1000;
position: absolute;
top: 20px;
left: 0px;
width: 30px; /* 30 to get 20 away from box */
font-size: 13px;
font-family: monospace;
text-align: right;
}
/* code box when locked */ /* code box when locked */
#box { #box {
@ -27,6 +41,7 @@ textarea {
width: 100%; width: 100%;
border: 0px; border: 0px;
outline: none; outline: none;
font-size: 13px;
} }
#box code { #box code {

View file

@ -32,7 +32,8 @@ haste_document.prototype.load = function(key, callback, lang) {
callback({ callback({
value: high.value, value: high.value,
key: key, key: key,
language: high.language || lang language: high.language || lang,
lineCount: res.data.split("\n").length
}); });
}, },
error: function(err) { error: function(err) {
@ -59,7 +60,8 @@ haste_document.prototype.save = function(data, callback) {
callback({ callback({
value: high.value, value: high.value,
key: res.key, key: res.key,
language: high.language language: high.language,
lineCount: data.split("\n").length
}); });
} }
}); });
@ -73,6 +75,7 @@ var haste = function(appName, options) {
this.$textarea = $('textarea'); this.$textarea = $('textarea');
this.$box = $('#box'); this.$box = $('#box');
this.$code = $('#box code'); this.$code = $('#box code');
this.$linenos = $('#linenos');
this.options = options; this.options = options;
this.configureShortcuts(); this.configureShortcuts();
this.configureButtons(); this.configureButtons();
@ -126,6 +129,7 @@ haste.prototype.newDocument = function(hideHistory) {
this.$textarea.val('').show('fast', function() { this.$textarea.val('').show('fast', function() {
this.focus(); this.focus();
}); });
this.removeLineNumbers();
}; };
// Map of common extensions // Map of common extensions
@ -156,6 +160,21 @@ haste.prototype.lookupTypeByExtension = function(ext) {
return haste.extensionMap[ext] || ext; return haste.extensionMap[ext] || ext;
}; };
// Add line numbers to the document
// For the specified number of lines
haste.prototype.addLineNumbers = function(lineCount) {
var h = '';
for (var i = 0; i < lineCount; i++) {
h += (i + 1).toString() + '<br/>';
}
$('#linenos').html(h);
};
// Remove the line numbers
haste.prototype.removeLineNumbers = function() {
$('#linenos').html('&gt;');
};
// Load a document and show it // Load a document and show it
haste.prototype.loadDocument = function(key) { haste.prototype.loadDocument = function(key) {
// Split the key up // Split the key up
@ -170,6 +189,7 @@ haste.prototype.loadDocument = function(key) {
_this.fullKey(); _this.fullKey();
_this.$textarea.val('').hide(); _this.$textarea.val('').hide();
_this.$box.show().focus(); _this.$box.show().focus();
_this.addLineNumbers(ret.lineCount);
} }
else { else {
_this.newDocument(); _this.newDocument();
@ -201,6 +221,7 @@ haste.prototype.lockDocument = function() {
_this.fullKey(); _this.fullKey();
_this.$textarea.val('').hide(); _this.$textarea.val('').hide();
_this.$box.show().focus(); _this.$box.show().focus();
_this.addLineNumbers(ret.lineCount);
} }
}); });
}; };

File diff suppressed because one or more lines are too long

View file

@ -57,6 +57,7 @@
</div> </div>
</div> </div>
<div id="linenos"></div>
<pre id="box" style="display:none;" tabindex="0"><code></code></pre> <pre id="box" style="display:none;" tabindex="0"><code></code></pre>
<textarea spellcheck="false" style="display:none;"></textarea> <textarea spellcheck="false" style="display:none;"></textarea>