mirror of
https://github.com/seejohnrun/haste-server
synced 2025-08-21 04:23:09 -07:00
Use hash as line indicator
This commit is contained in:
parent
5014d7a088
commit
aea2329049
2 changed files with 17 additions and 8 deletions
|
@ -178,6 +178,15 @@ haste.prototype.addLineNumbers = function(lineCount) {
|
||||||
let line = i + 1;
|
let line = i + 1;
|
||||||
div.href = '#' + line;
|
div.href = '#' + line;
|
||||||
div.onclick = function() {
|
div.onclick = function() {
|
||||||
|
highlightLine(line);
|
||||||
|
}
|
||||||
|
let text = document.createTextNode(line.toString());
|
||||||
|
div.appendChild(text);
|
||||||
|
document.body.appendChild(div)
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
function highlightLine(line) {
|
||||||
var box = document.getElementById("box");
|
var box = document.getElementById("box");
|
||||||
// create highlight div
|
// create highlight div
|
||||||
removeElementsByClass('highlight');
|
removeElementsByClass('highlight');
|
||||||
|
@ -185,12 +194,7 @@ haste.prototype.addLineNumbers = function(lineCount) {
|
||||||
highlight.classList.add('highlight');
|
highlight.classList.add('highlight');
|
||||||
highlight.style.marginTop = ((line - 1) * 16) + 'px';
|
highlight.style.marginTop = ((line - 1) * 16) + 'px';
|
||||||
box.insertBefore(highlight, box.firstChild);
|
box.insertBefore(highlight, box.firstChild);
|
||||||
}
|
}
|
||||||
let text = document.createTextNode(line.toString());
|
|
||||||
div.appendChild(text);
|
|
||||||
document.body.appendChild(div)
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
function removeElementsByClass(className){
|
function removeElementsByClass(className){
|
||||||
const elements = document.getElementsByClassName(className);
|
const elements = document.getElementsByClassName(className);
|
||||||
|
@ -225,6 +229,11 @@ haste.prototype.loadDocument = function(key) {
|
||||||
_this.$textarea.val('').hide();
|
_this.$textarea.val('').hide();
|
||||||
_this.$box.show().focus();
|
_this.$box.show().focus();
|
||||||
_this.addLineNumbers(ret.lineCount);
|
_this.addLineNumbers(ret.lineCount);
|
||||||
|
|
||||||
|
if(window.location.hash) {
|
||||||
|
const hash = window.location.hash.substring(1);
|
||||||
|
highlightLine(hash)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
_this.newDocument();
|
_this.newDocument();
|
||||||
|
|
2
static/application.min.js
vendored
2
static/application.min.js
vendored
File diff suppressed because one or more lines are too long
Loading…
Add table
Add a link
Reference in a new issue