mirror of
https://github.com/seejohnrun/haste-server
synced 2025-08-21 07:33:12 -07:00
change hash
This commit is contained in:
parent
d0158c23de
commit
02c82acf8c
3 changed files with 105 additions and 90 deletions
|
@ -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 {
|
||||||
|
|
|
@ -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() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
});
|
});
|
|
@ -1,22 +1,22 @@
|
||||||
<html>
|
<html>
|
||||||
|
|
||||||
<head>
|
<head>
|
||||||
|
|
||||||
<title>hastebin</title>
|
<title>hastebin</title>
|
||||||
<meta charset="utf-8" />
|
<meta charset="utf-8" />
|
||||||
<link rel="stylesheet" type="text/css" href="solarized_dark.css"/>
|
<link rel="stylesheet" type="text/css" href="solarized_dark.css" />
|
||||||
<link rel="stylesheet" type="text/css" href="application.css"/>
|
<link rel="stylesheet" type="text/css" href="application.css" />
|
||||||
|
|
||||||
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
|
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
|
||||||
<script type="text/javascript" src="highlight.min.js"></script>
|
<script type="text/javascript" src="highlight.min.js"></script>
|
||||||
<script type="text/javascript" src="application.min.js"></script>
|
<script type="text/javascript" src="application.min.js"></script>
|
||||||
|
|
||||||
<meta name="robots" content="noindex,nofollow"/>
|
<meta name="robots" content="noindex,nofollow" />
|
||||||
|
|
||||||
<script type="text/javascript">
|
<script type="text/javascript">
|
||||||
var app = null;
|
var app = null;
|
||||||
// Handle pops
|
// Handle pops
|
||||||
var handlePop = function(evt) {
|
var handlePop = function (evt) {
|
||||||
var path = evt.target.location.href;
|
var path = evt.target.location.href;
|
||||||
if (path === app.baseUrl) { app.newDocument(true); }
|
if (path === app.baseUrl) { app.newDocument(true); }
|
||||||
else { app.loadDocument(path.split('#')[0].split('/').slice(-1)[0]); }
|
else { app.loadDocument(path.split('#')[0].split('/').slice(-1)[0]); }
|
||||||
|
@ -24,9 +24,9 @@
|
||||||
// Set up the pop state to handle loads, skipping the first load
|
// Set up the pop state to handle loads, skipping the first load
|
||||||
// to make chrome behave like others:
|
// to make chrome behave like others:
|
||||||
// http://code.google.com/p/chromium/issues/detail?id=63040
|
// http://code.google.com/p/chromium/issues/detail?id=63040
|
||||||
setTimeout(function() {
|
setTimeout(function () {
|
||||||
window.onpopstate = function(evt) {
|
window.onpopstate = function (evt) {
|
||||||
try { handlePop(evt); } catch(err) { /* not loaded yet */ }
|
try { handlePop(evt); } catch (err) { /* not loaded yet */ }
|
||||||
};
|
};
|
||||||
}, 1000);
|
}, 1000);
|
||||||
|
|
||||||
|
@ -57,20 +57,25 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
// Construct app and load initial path
|
// Construct app and load initial path
|
||||||
$(function() {
|
$(function () {
|
||||||
var baseUrl = window.location.href.split('#')[0].split('/');
|
var baseUrl = window.location.href.split('#')[0].split('/');
|
||||||
baseUrl = baseUrl.slice(0, baseUrl.length - 1).join('/') + '/';
|
baseUrl = baseUrl.slice(0, baseUrl.length - 1).join('/') + '/';
|
||||||
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>
|
||||||
|
|
||||||
<body>
|
<body>
|
||||||
<ul id="messages"></ul>
|
<ul id="messages"></ul>
|
||||||
|
|
||||||
<div id="key">
|
<div id="key">
|
||||||
|
@ -95,6 +100,6 @@
|
||||||
<pre id="box" style="display:none;" class="hljs" tabindex="0"><code></code></pre>
|
<pre id="box" style="display:none;" class="hljs" tabindex="0"><code></code></pre>
|
||||||
<textarea spellcheck="false" style="display:none;"></textarea>
|
<textarea spellcheck="false" style="display:none;"></textarea>
|
||||||
|
|
||||||
</body>
|
</body>
|
||||||
|
|
||||||
</html>
|
</html>
|
Loading…
Add table
Add a link
Reference in a new issue