mirror of
https://github.com/seejohnrun/haste-server
synced 2025-08-21 05:13:08 -07:00
cleanup
This commit is contained in:
parent
bfaa4af363
commit
bc62766bef
3 changed files with 567 additions and 564 deletions
|
@ -36,14 +36,6 @@ textarea {
|
|||
user-select: none;
|
||||
}
|
||||
|
||||
.line {
|
||||
/* display: block;*/
|
||||
}
|
||||
|
||||
/*.line:hover {
|
||||
background-color: #cbd387;
|
||||
}*/
|
||||
|
||||
.lineHighlight {
|
||||
background-color: yellow;
|
||||
}
|
||||
|
|
|
@ -28,7 +28,7 @@ haste_document.prototype.load = function(key, callback, lang) {
|
|||
_this.key = key;
|
||||
_this.data = res.data;
|
||||
try {
|
||||
var high = { value: "" };
|
||||
var high = { value: "", language: null};
|
||||
var lines = res.data.split("\n");
|
||||
for (var i = 0; i < lines.length; i++) {
|
||||
if (lang === "txt") {
|
||||
|
@ -56,7 +56,7 @@ haste_document.prototype.load = function(key, callback, lang) {
|
|||
setTimeout(function() {
|
||||
// show current line and the one before it
|
||||
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 {
|
||||
// if lines 1-2, go to top of file
|
||||
document.body.scrollTo(0, 0);
|
||||
|
@ -218,11 +218,26 @@ haste.prototype.lookupTypeByExtension = function(ext) {
|
|||
};
|
||||
|
||||
// Add line numbers to the document
|
||||
// For the specified number of lines, each with a class and id
|
||||
// For the specified number of lines
|
||||
haste.prototype.addLineNumbers = function(lineCount) {
|
||||
var h = '';
|
||||
for (var i = 0; i < lineCount; i++) {
|
||||
h += '<span onclick="handleLineClick(' + i.toString() + ')" onmouseenter="handleMouseEnter(' + i.toString() + ')" onmouseleave="handleMouseLeave(' + i.toString() + ')" onmousedown="handleMouseDown(' + i.toString() + ')" onmouseup="handleMouseUp(' + i.toString() + ')" id="line-number-' + (i + 1) + '">' + (i + 1) + '</span><br/>';
|
||||
h +=
|
||||
'<span onclick="handleLineClick(' +
|
||||
i.toString() +
|
||||
')" onmouseenter="handleMouseEnter(' +
|
||||
i.toString() +
|
||||
')" onmouseleave="handleMouseLeave(' +
|
||||
i.toString() +
|
||||
')" onmousedown="handleMouseDown(' +
|
||||
i.toString() +
|
||||
')" onmouseup="handleMouseUp(' +
|
||||
i.toString() +
|
||||
')" id="line-number-' +
|
||||
(i + 1) +
|
||||
'">' +
|
||||
(i + 1) +
|
||||
"</span><br/>";
|
||||
}
|
||||
$('#linenos').html(h);
|
||||
};
|
||||
|
@ -284,7 +299,6 @@ haste.prototype.lockDocument = function() {
|
|||
_this.addLineNumbers(ret.lineCount);
|
||||
// Load Document Again
|
||||
var path = window.location.href;
|
||||
console.log(path);
|
||||
_this.loadDocument(path.split('#')[0].split('/').slice(-1)[0]);
|
||||
}
|
||||
});
|
||||
|
@ -427,4 +441,5 @@ $(function() {
|
|||
}
|
||||
}
|
||||
});
|
||||
|
||||
});
|
|
@ -38,7 +38,6 @@
|
|||
};
|
||||
}, 1000);
|
||||
|
||||
|
||||
/**
|
||||
* Function to parse the URL fragment and extract line numbers
|
||||
* @returns {Object} Object with parsed startLine, endLine
|
||||
|
@ -68,27 +67,21 @@
|
|||
$(function() {
|
||||
var baseUrl = window.location.href.split('#')[0].split('/');
|
||||
baseUrl = baseUrl.slice(0, baseUrl.length - 1).join('/') + '/';
|
||||
console.log(baseUrl);
|
||||
const selectedLines = getSelectedLinesFromURL();
|
||||
console.log(selectedLines);
|
||||
app = new haste('hastebin', { twitter: false, baseUrl: baseUrl, selectedLines: selectedLines });
|
||||
app = new haste('hastebin', { twitter: true, baseUrl: baseUrl, selectedLines: selectedLines });
|
||||
handlePop({ target: window });
|
||||
});
|
||||
|
||||
$(window).on('hashchange', function() {
|
||||
isHashChange = true;
|
||||
});
|
||||
|
||||
// Update the window hash with the selected lines
|
||||
function updateWindowLineHash(lineId){
|
||||
console.log('updateWindowLineHash', lineId, app.selectedLines.startLine, app.selectedLines.endLine);
|
||||
app.selectedLines.startLine = Math.min(lineId,app.selectedLines.startLine);
|
||||
app.selectedLines.endLine = Math.max(lineId,app.selectedLines.endLine);
|
||||
window.location.hash = "#L" + (app.selectedLines.startLine) + "-L" + (app.selectedLines.endLine);
|
||||
}
|
||||
|
||||
// Handle mouse enter
|
||||
function handleMouseEnter(lineId) {
|
||||
lineId = lineId + 1;
|
||||
console.log('lineId', lineId);
|
||||
$('#line-number-' + lineId).css('background-color', '#cbd387');
|
||||
$('#line-' + lineId).css('background-color', '#cbd387');
|
||||
if(isDragging){
|
||||
|
@ -97,12 +90,14 @@
|
|||
}
|
||||
}
|
||||
|
||||
// Handle mouse leave
|
||||
function handleMouseLeave(lineId) {
|
||||
lineId = lineId + 1;
|
||||
$('#line-number-' + lineId).css('background-color', '');
|
||||
$('#line-' + lineId).css('background-color', '');
|
||||
}
|
||||
|
||||
// Handle mouse down, unhighlight current lines first
|
||||
function unHighlightCurrent(){
|
||||
startLine = app.selectedLines.startLine;
|
||||
endLine = app.selectedLines.endLine;
|
||||
|
@ -120,6 +115,7 @@
|
|||
updateWindowLineHash(lineId);
|
||||
}
|
||||
|
||||
// Handle mouse up
|
||||
function handleMouseUp(lineId) {
|
||||
if(!isDragging){
|
||||
return;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue