change hash

This commit is contained in:
Alysa Meng 2024-07-23 10:00:01 -07:00
commit 02c82acf8c
3 changed files with 105 additions and 90 deletions

View file

@ -36,6 +36,18 @@ textarea {
user-select: none;
}
.line {
/* display: block;*/
}
.line:hover {
background-color: #cbd387;
}
.lineHighlight {
background-color: yellow;
}
/* code box when locked */
#box {

View file

@ -47,20 +47,19 @@ haste_document.prototype.load = function(key, callback, lang) {
currentLine <= selectedLines.endLine
) {
highlighted =
'<span style="background-color: yellow;">' + highlighted + "</span>";
"<span class='lineHighlight'>" + highlighted + "</span>";
}
highlighted = "<span id='line-" + i + "'>" + highlighted + "</span>";
highlighted = "<span onclick='handleLineClick(" + i + ")' class='line' id='line-" + i + "'>" + highlighted + "</span>";
high.value += highlighted + "\n";
}
// scroll to position in document after ensuring components have had time to render
// scroll to position in document after ensuring components h"ve had time to render
setTimeout(function() {
// show current line and the one before it
if (selectedLines.startLine >= 3) {
document.body.scrollTo(0, $("#line-" + (selectedLines.startLine - 2)).offset().top)
} else {
// if lines 1-2, go to top of file
document.body.scrollTop(0);
document.body.scrollTo(0, 0);
}
}, 0);
} catch (err) {
@ -423,5 +422,4 @@ $(function() {
}
}
});
});

View file

@ -63,9 +63,14 @@
console.log(baseUrl);
const selectedLines = getSelectedLinesFromURL();
console.log(selectedLines);
app = new haste('hastebin', { twitter: true, baseUrl: baseUrl, selectedLines: selectedLines });
app = new haste('hastebin', { twitter: false, baseUrl: baseUrl, selectedLines: selectedLines });
handlePop({ target: window });
});
function handleLineClick(lineId) {
/* TODO */
window.location.hash = "#L" + (lineId + 1);
}
</script>
</head>