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; user-select: none;
} }
.line {
/* display: block;*/
}
.line:hover {
background-color: #cbd387;
}
.lineHighlight {
background-color: yellow;
}
/* code box when locked */ /* code box when locked */
#box { #box {

View file

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

View file

@ -63,9 +63,14 @@
console.log(baseUrl); console.log(baseUrl);
const selectedLines = getSelectedLinesFromURL(); const selectedLines = getSelectedLinesFromURL();
console.log(selectedLines); 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 }); handlePop({ target: window });
}); });
function handleLineClick(lineId) {
/* TODO */
window.location.hash = "#L" + (lineId + 1);
}
</script> </script>
</head> </head>