diff --git a/src/static/css/iframe_editor.css b/src/static/css/iframe_editor.css index 7267375a4..42951f486 100644 --- a/src/static/css/iframe_editor.css +++ b/src/static/css/iframe_editor.css @@ -101,6 +101,7 @@ body.mozilla, body.safari { font-size: 9px; padding: 0 14px 0 10px; font-family: monospace; + cursor: pointer; } .plugin-ep_author_neat #sidedivinner.authorColors .line-number { padding-right: 10px; diff --git a/src/static/js/pad_editor.js b/src/static/js/pad_editor.js index e7e723080..aeff98c9e 100644 --- a/src/static/js/pad_editor.js +++ b/src/static/js/pad_editor.js @@ -1,3 +1,4 @@ +'use strict'; /** * This code is mostly from the old Etherpad. Please help us to comment this code. * This helps other people to understand this code better and helps them to improve it. @@ -29,7 +30,7 @@ const padeditor = (function () { let pad = undefined; let settings = undefined; - var self = { + const self = { ace: null, // this is accessed directly from other files viewZoom: 100, @@ -41,6 +42,33 @@ const padeditor = (function () { function aceReady() { $('#editorloadingbox').hide(); if (readyFunc) { + // If a number is in the URI IE #L124 go to that line number + const lineNumber = window.location.hash.substr(1); + if (lineNumber) { + if (lineNumber[0] === 'L') { + const lineNumberInt = parseInt(lineNumber.replace('L', '')); + const $inner = $('iframe[name="ace_outer"]').contents().find('iframe') + .contents().find('#innerdocbody'); + const line = $inner.find(`div:nth-child(${lineNumberInt})`); + if (line.length !== 0) { + let offsetTop = line.offset().top; + const $outerdoc = $('iframe[name="ace_outer"]').contents().find('#outerdocbody'); + offsetTop += parseInt($outerdoc.css('padding-top').replace('px', '')); + offsetTop += parseInt($inner.css('padding-top').replace('px', '')); + const $outerdocHTML = $('iframe[name="ace_outer"]').contents() + .find('#outerdocbody').parent(); + $outerdoc.css({top: `${offsetTop}px`}); // Chrome + $outerdocHTML.animate({scrollTop: offsetTop}); // needed for FF + } + } + } + const $outerdoc = $('iframe[name="ace_outer"]').contents().find('#outerdocbody'); + // Listen for clicks on sidediv items + $outerdoc.find('#sidedivinner').on('click', 'div', function() { + const lineNumber = $(this).index() + 1; + window.location.hash = 'L' + lineNumber; + }) + readyFunc(); } }