Index: lams_build/conf/etherpad/etherpad-lite/node_modules/ep_resize/static/js/index.js =================================================================== diff -u -r6c35e7bbcc3c98e9e3a1c31a367c44cb87bdf987 -rfca1236ef2e9dec8281230a456cb13d0cdaa9b56 --- lams_build/conf/etherpad/etherpad-lite/node_modules/ep_resize/static/js/index.js (.../index.js) (revision 6c35e7bbcc3c98e9e3a1c31a367c44cb87bdf987) +++ lams_build/conf/etherpad/etherpad-lite/node_modules/ep_resize/static/js/index.js (.../index.js) (revision fca1236ef2e9dec8281230a456cb13d0cdaa9b56) @@ -1,70 +1,132 @@ 'use strict'; -var lastHeight; -var lastWidth; -var returnchildHeights = function (children) { - var maxHeight = 0; - if (children.length) { - maxHeight = 0; - children.each(function (key, child) { - if ($(child).is(':visible')) { - var childtop = ($(child).offset().top + $(child).outerHeight()); - if (childtop > maxHeight) { - maxHeight = childtop; - } - } - }); - } +let lastHeight; +let lastWidth; - return maxHeight; +exports.aceEditorCSS = () => ['ep_resize/static/css/styles.css']; + +// SRC: http://youmightnotneedjquery.com/ +const matches = (el, selector) => { + const func = el.matches || + el.matchesSelector || + el.msMatchesSelector || + el.mozMatchesSelector || + el.webkitMatchesSelector || + el.oMatchesSelector; + + func.call(el, selector); }; -exports.aceEditEvent = function (event, args, callback) { - var editbar = $('#editbar'); +// JQuery implementation of "outerHeight()" +const elOuterHeight = (el) => Math.max(el.scrollHeight, el.offsetHeight, el.clientHeight); - var elem = $('iframe[name=ace_outer]').contents().find('iframe[name=ace_inner]'); - var newHeight = elem.outerHeight() + (editbar.length ? editbar.outerHeight() : 0); - var newWidth = elem.outerWidth(); +// JQuery implementation of "outerWidth()" +const elOuterWidth = (el) => Math.max(el.scrollWidth, el.offsetWidth, el.clientWidth); - var maxChild = returnchildHeights($('iframe[name=ace_outer]').contents().find('body').children()); - var maxChildBody = returnchildHeights($('body').children()); - if (maxChildBody > maxChild) { - maxChild = maxChildBody - } +const returnChildHeights = (children, offsetTop) => { + offsetTop = offsetTop + 10 || 10; // Some extra padding for possible shadows etc. - if (maxChild > newHeight) { - newHeight = maxChild; + let maxHeight = 0; + + if (children.length) { + maxHeight = 0; + + for (let i = 0; i < children.length; i++) { + const child = children[i]; + const cid = child.getAttribute('id'); + const isIframe = matches(child, 'iframe'); + const isVisible = child.offsetWidth > 0 || child.offsetHeight > 0; + const validElem = ['editorcontainerbox', 'editbar'].indexOf(cid) === -1; + const hasHeight = child.offsetHeight > 0; + + // Avoid infinit increasing + if (isVisible && validElem && !isIframe && hasHeight) { + const childtop = (child.getBoundingClientRect().top + child.offsetHeight) + offsetTop; + if (childtop > maxHeight) { + maxHeight = childtop; + } + } } - if (!lastHeight || !lastWidth || lastHeight !== newHeight || lastWidth !== newWidth) { - sendResizeMessage(newWidth, newHeight, window.document.location.href); - } - + } + + return maxHeight; }; -exports.goToRevisionEvent = function (hook_name, context, cb) { - - var editbar = $('#timeslider-top') - var elem = $('#padeditor'); +const sendResizeMessage = (width, height, location) => { + lastHeight = height; + lastWidth = width; - var newHeight = elem.outerHeight() + (editbar.length ? editbar.outerHeight() : 0); - var newWidth = elem.outerWidth(); + window.parent.postMessage({ + name: 'ep_resize', + data: { + width, + height, + location : location + }, + }, '*'); +}; - if (!lastHeight || !lastWidth || lastHeight !== newHeight || lastWidth !== newWidth) { - sendResizeMessage(newWidth, newHeight, window.document.location.href); +exports.aceEditEvent = (event, context) => { + const padOuter = document.querySelector('iframe[name="ace_outer"]'); + const padInner = padOuter.contentWindow.document.querySelector('iframe[name="ace_inner"]'); + const popups = document.getElementsByClassName('popup-show'); + const menuRight = document.getElementsByClassName('menu_right')[0]; + const menuLeft = document.getElementsByClassName('menu_left')[0]; + + const aceOuterTop = padOuter.getBoundingClientRect().top; + const aceInnerTop = padInner.getBoundingClientRect().top; + + const finalLine = (context.rep.lines.atIndex(context.rep.lines.length() - 1)).lineNode; + const finalLineOuterHeight = elOuterHeight(finalLine); + let menuBottomOffset = 0; + + if (menuLeft.getBoundingClientRect().top !== menuRight.getBoundingClientRect().top) { + menuBottomOffset = menuRight.offsetHeight; + } + let newHeight = finalLine.getBoundingClientRect().top; + newHeight += finalLineOuterHeight; + newHeight += menuBottomOffset + 10; + if (aceInnerTop > 0) { + newHeight += aceInnerTop; + } + if (aceOuterTop > 0) { + newHeight += aceOuterTop; + } + const newWidth = elOuterWidth(padInner); + + const maxChild = returnChildHeights( + padOuter.contentWindow.document.querySelector('body').children, + aceOuterTop + ); // #outerdocbody + const maxChildBody = returnChildHeights(document.querySelector('body').children); + const maxPopups = returnChildHeights(popups) + menuBottomOffset; + + if (maxChildBody > maxChild) { + newHeight = maxChildBody; + } + + if (maxChild > newHeight) { + newHeight = maxChild; + } + + if (maxPopups > newHeight) { + newHeight = maxPopups; + } + + if (!lastHeight || !lastWidth || lastHeight !== newHeight || lastWidth !== newWidth) { + if (newHeight - lastHeight !== 20 && newHeight - lastHeight !== -5) { + sendResizeMessage(newWidth, newHeight, window.document.location.href); } + } }; -var sendResizeMessage = function (width, height, location) { - lastHeight = height; - lastWidth = width; - +exports.goToRevisionEvent = (hook, context) => { + const editbar = document.getElementById('editbar'); + const elem = document.getElementById('outerdocbody'); + const newHeight = elOuterHeight(elem) + (editbar ? elOuterHeight(editbar) : 0); + const newWidth = elOuterWidth(elem); - window.parent.postMessage({ - name: 'ep_resize', - data: { - width: width, - height: height, - location : location - } - }, '*'); -} + if (!lastHeight || !lastWidth || lastHeight !== newHeight || lastWidth !== newWidth) { + sendResizeMessage(newWidth, newHeight, window.document.location.href); + } +};