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=$('
  • '+e+"
  • ");$("#messages").prepend(o),setTimeout(function(){o.slideUp("fast",function(){$(this).remove()})},3e3)},haste.prototype.lightKey=function(){this.configureKey(["new","save"])},haste.prototype.fullKey=function(){this.configureKey(["new","duplicate","raw"])},haste.prototype.configureKey=function(e){var t,o=0;$("#box2 .function").each(function(){for(t=$(this),o=0;o");e.appendChild(t),document.body.appendChild(e)},haste.prototype.loadDocument=function(e){var t=e.split(".",2),o=this;o.doc=new haste_document,o.doc.load(t[0],function(e){if(e){for(var t=e.value.split(/\r\n|\r|\n/),n=0;n/g,">").replace(/0;)t[0].parentNode.removeChild(t[0])}function highlightNew(e){const t=document.getElementsByTagName("code");let o=0;for(let e=0;eo&&(o=t[e].offsetWidth),t[e].style.removeProperty("background-color");for(let e=0;e'+e+"");$("#messages").prepend(o),setTimeout(function(){o.slideUp("fast",function(){$(this).remove()})},3e3)},haste.prototype.lightKey=function(){this.configureKey(["new","save"])},haste.prototype.fullKey=function(){this.configureKey(["new","duplicate","raw"])},haste.prototype.configureKey=function(e){var t,o=0;$("#box2 .function").each(function(){for(t=$(this),o=0;o");e.appendChild(t),document.body.appendChild(e)},haste.prototype.loadDocument=function(e){var t=e.split(".",2),o=this;o.doc=new haste_document,o.doc.load(t[0],function(e){if(e){for(var t=e.value.split(/\r\n|\r|\n/),n=0;n - +
    
     		
     	
     
    diff --git a/static/solarized_dark.css b/static/solarized_dark.css
    index e9bff14..4145c5c 100644
    --- a/static/solarized_dark.css
    +++ b/static/solarized_dark.css
    @@ -18,8 +18,10 @@ pre.code {
       padding: 0.5em;
       background: #1E1F22;
       color: #78797A;
    -  white-space: pre-wrap;
       margin-left: 8em;
    +  white-space: pre;
    +  word-break: normal;
    +  word-wrap: normal;
     }
     
     pre.code::before {
    @@ -34,13 +36,13 @@ pre.code code {
     }
     
     pre.code code::before {
    -  content: counter(listing) ". ";
    +  content: counter(listing) " ";
       display: inline-block;
       float: left;
    -  height: 3em;
    -  padding-left: auto;
    -  margin-left: auto;
    -  text-align: right;
    +  height: 16px;
    +  padding-left: 0;
    +  margin-left: -28px;
    +  color: #3D3F41;
     }
     
     .hljs-comment,