From 2ffc0d9e6b87a3523f748d763c0e56d5bf46804b Mon Sep 17 00:00:00 2001 From: Kenox Date: Thu, 3 Nov 2022 19:03:20 +0100 Subject: [PATCH] Center scrolled view --- static/application.js | 10 ++++++++++ static/application.min.js | 2 +- static/index.html | 9 --------- 3 files changed, 11 insertions(+), 10 deletions(-) diff --git a/static/application.js b/static/application.js index a764a64..abf4de5 100644 --- a/static/application.js +++ b/static/application.js @@ -185,6 +185,16 @@ haste.prototype.addLineNumbers = function(lineCount) { div.appendChild(text); document.body.appendChild(div) } + + if(window.location.hash) { + const hash = window.location.hash.substring(1); + highlightLine(hash) + console.log("try to get to line" + hash); + document.getElementById("line" + hash)[0].scrollIntoView({ + behavior: 'smooth', + block: 'center' + }); + } }; function highlightLine(line) { diff --git a/static/application.min.js b/static/application.min.js index 5bb9b4a..f3c8d26 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};haste_document.prototype.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){e?(o.$code.html(e.value),o.setTitle(e.key),o.fullKey(),o.$textarea.val("").hide(),o.$box.show().focus(),o.addLineNumbers(e.lineCount)):o.newDocument()},this.lookupTypeByExtension(t[1]))},haste.prototype.duplicateDocument=function(){if(this.doc.locked){var e=this.doc.data;this.newDocument(),this.$textarea.val(e)}},haste.prototype.lockDocument=function(){var e=this;this.doc.save(this.$textarea.val(),function(t,o){if(t)e.showMessage(t.message,"error");else if(o){e.$code.html(o.value),e.setTitle(o.key);var n="/"+o.key;window.history.pushState(null,e.appName+"-"+o.key,n),e.fullKey(),e.$textarea.val("").hide(),e.$box.show().focus(),e.addLineNumbers(o.lineCount)}})},haste.prototype.configureButtons=function(){var e=this;this.buttons=[{$where:$("#box2 .save"),label:"Save",shortcutDescription:"control + s",shortcut:function(e){return e.ctrlKey&&83===e.keyCode},action:function(){""!==e.$textarea.val().replace(/^\s+|\s+$/g,"")&&e.lockDocument()}},{$where:$("#box2 .new"),label:"New",shortcut:function(e){return e.ctrlKey&&78===e.keyCode},shortcutDescription:"control + n",action:function(){e.newDocument(!e.doc.key)}},{$where:$("#box2 .duplicate"),label:"Duplicate & Edit",shortcut:function(t){return e.doc.locked&&t.ctrlKey&&68===t.keyCode},shortcutDescription:"control + d",action:function(){e.duplicateDocument()}},{$where:$("#box2 .raw"),label:"Just Text",shortcut:function(e){return e.ctrlKey&&e.shiftKey&&82===e.keyCode},shortcutDescription:"control + shift + r",action:function(){window.location.href=workersUrl+"raw/"+e.doc.key}}];for(var t=0;t/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){e?(o.$code.html(e.value),o.setTitle(e.key),o.fullKey(),o.$textarea.val("").hide(),o.$box.show().focus(),o.addLineNumbers(e.lineCount)):o.newDocument()},this.lookupTypeByExtension(t[1]))},haste.prototype.duplicateDocument=function(){if(this.doc.locked){var e=this.doc.data;this.newDocument(),this.$textarea.val(e)}},haste.prototype.lockDocument=function(){var e=this;this.doc.save(this.$textarea.val(),function(t,o){if(t)e.showMessage(t.message,"error");else if(o){e.$code.html(o.value),e.setTitle(o.key);var n="/"+o.key;window.history.pushState(null,e.appName+"-"+o.key,n),e.fullKey(),e.$textarea.val("").hide(),e.$box.show().focus(),e.addLineNumbers(o.lineCount)}})},haste.prototype.configureButtons=function(){var e=this;this.buttons=[{$where:$("#box2 .save"),label:"Save",shortcutDescription:"control + s",shortcut:function(e){return e.ctrlKey&&83===e.keyCode},action:function(){""!==e.$textarea.val().replace(/^\s+|\s+$/g,"")&&e.lockDocument()}},{$where:$("#box2 .new"),label:"New",shortcut:function(e){return e.ctrlKey&&78===e.keyCode},shortcutDescription:"control + n",action:function(){e.newDocument(!e.doc.key)}},{$where:$("#box2 .duplicate"),label:"Duplicate & Edit",shortcut:function(t){return e.doc.locked&&t.ctrlKey&&68===t.keyCode},shortcutDescription:"control + d",action:function(){e.duplicateDocument()}},{$where:$("#box2 .raw"),label:"Just Text",shortcut:function(e){return e.ctrlKey&&e.shiftKey&&82===e.keyCode},shortcutDescription:"control + shift + r",action:function(){window.location.href=workersUrl+"raw/"+e.doc.key}}];for(var t=0;t