diff --git a/static/application.css b/static/application.css index 063e63a..8698c59 100644 --- a/static/application.css +++ b/static/application.css @@ -71,7 +71,7 @@ textarea { #box code { padding: 0px; - background: transparent !important; /* don't hide hastebox */ + /*background: transparent !important; /* don't hide hastebox */ } /* key */ diff --git a/static/application.js b/static/application.js index 63c7850..ff1ad4f 100644 --- a/static/application.js +++ b/static/application.js @@ -171,6 +171,16 @@ haste.prototype.lookupTypeByExtension = function(ext) { // For the specified number of lines haste.prototype.addLineNumbers = function(lineCount) { removeElementsByClass('linenumber'); + + if(window.location.hash) { + const hash = window.location.hash.substring(1); + highlightNew(getLineElement(hash)); + + /*document.getElementById('line' + hash).scrollIntoView({ + behavior: 'smooth', + block: 'center' + });*/ + } /*for (var i = 0; i < lineCount; i++) { let div = document.createElement('a'); div.classList.add('linenumber'); @@ -272,7 +282,19 @@ haste.prototype.lockDocument = function() { _this.showMessage(err.message, 'error'); } else if (ret) { - _this.$code.html(htmlEscape(ret.value)); + //_this.$code.html(htmlEscape(ret.value)); + var lines = ret.value.split(/\r\n|\r|\n/); + for (var i = 0; i < lines.length; i++) { + let code = document.createElement('code'); + code.innerHTML = lines[i]; + let pre = document.getElementById("box"); + pre.appendChild(code); + + code.onclick = function() { + highlightNew(code); + } + } + _this.setTitle(ret.key); var file = '/' + ret.key; window.history.pushState(null, _this.appName + '-' + ret.key, file); @@ -285,6 +307,25 @@ haste.prototype.lockDocument = function() { }); }; +function highlightNew(code) { + const codes = document.getElementsByTagName("code"); + let maxWidth = 0; + for (let i = 0; i < codes.length; i++) { + if (codes[i].offsetWidth > maxWidth) { + maxWidth = codes[i].offsetWidth; + } + codes[i].style.removeProperty("background-color"); + } + for (let i = 0; i < codes.length; i++) { + codes[i].style.width = maxWidth + 'px'; + } + code.style.backgroundColor = "rgba(187, 128, 9, 0.25)"; +} + +function getLineElement(line) { + return document.getElementsByTagName("code")[line - 1]; +} + haste.prototype.configureButtons = function() { var _this = this; this.buttons = [ diff --git a/static/application.min.js b/static/application.min.js index 49f7f58..1f18e91 100644 --- a/static/application.min.js +++ b/static/application.min.js @@ -1 +1 @@ -const workersUrl="https://api.knx.cool/";var haste_document=function(){this.locked=!1};htmlEscape=function(e){return e.replace(/&/g,"&").replace(/>/g,">").replace(/0;)t[0].parentNode.removeChild(t[0])}haste.prototype.setTitle=function(e){var t=e?this.appName+" - "+e:this.appName;document.title=t},haste.prototype.showMessage=function(e,t){var o=$('