Merge branch 'toc_hackathon' of github.com:xwiki-labs/cryptpad into toc_hackathon

pull/1/head
David Benqué 4 years ago
commit aadf097c5d

@ -4104,5 +4104,11 @@ define([
}; };
}; };
UIElements.isVisible = function (el, $container) {
var size = $container.outerHeight();
var pos = el.getBoundingClientRect();
return (pos.bottom < size) && (pos.y > 0);
};
return UIElements; return UIElements;
}); });

@ -5,8 +5,9 @@ define([
'/common/common-hash.js', '/common/common-hash.js',
'/common/hyperscript.js', '/common/hyperscript.js',
'/common/common-interface.js', '/common/common-interface.js',
'/common/common-ui-elements.js',
'/customize/messages.js' '/customize/messages.js'
], function($, Sortify, Util, Hash, h, UI, Messages) { ], function($, Sortify, Util, Hash, h, UI, UIElements, Messages) {
var Comments = {}; var Comments = {};
/* /*
@ -273,12 +274,6 @@ define([
]); ]);
}; };
var isVisible = function(el, $container) {
var size = $container.outerHeight();
var pos = el.getBoundingClientRect();
return (pos.bottom < size) && (pos.y > 0);
};
var redrawComments = function(Env) { var redrawComments = function(Env) {
// Don't redraw if there were no change // Don't redraw if there were no change
var str = Sortify(Env.comments || {}); var str = Sortify(Env.comments || {});
@ -558,7 +553,7 @@ define([
// Scroll into view // Scroll into view
if (!$last.length) { return; } if (!$last.length) { return; }
var visible = isVisible($last[0], Env.$inner); var visible = UIElements.isVisible($last[0], Env.$inner);
if (!visible) { $last[0].scrollIntoView(); } if (!visible) { $last[0].scrollIntoView(); }
}; };
@ -574,7 +569,7 @@ define([
focusContent(); focusContent();
var visible = isVisible(div, Env.$container); var visible = UIElements.isVisible(div, Env.$container);
if (!visible) { div.scrollIntoView(); } if (!visible) { div.scrollIntoView(); }
}); });

@ -42,6 +42,7 @@ define([
'/common/common-hash.js', '/common/common-hash.js',
'/common/common-util.js', '/common/common-util.js',
'/common/common-interface.js', '/common/common-interface.js',
'/common/common-ui-elements.js',
'/common/hyperscript.js', '/common/hyperscript.js',
'/bower_components/chainpad/chainpad.dist.js', '/bower_components/chainpad/chainpad.dist.js',
'/customize/application_config.js', '/customize/application_config.js',
@ -69,6 +70,7 @@ define([
Hash, Hash,
Util, Util,
UI, UI,
UIElements,
h, h,
ChainPad, ChainPad,
AppConfig, AppConfig,
@ -609,12 +611,6 @@ define([
}, 500); // 500ms to make sure it is sent after chainpad sync }, 500); // 500ms to make sure it is sent after chainpad sync
}; };
var isVisible = function(el, $container) {
var size = $container.outerHeight();
var pos = el.getBoundingClientRect();
return (pos.bottom < size) && (pos.y > 0);
};
var updateTOC = function () { var updateTOC = function () {
var toc = []; var toc = [];
$inner.find('h1, h2, h3').each(function (i, el) { $inner.find('h1, h2, h3').each(function (i, el) {
@ -634,7 +630,7 @@ define([
$(a).click(function (e) { $(a).click(function (e) {
e.preventDefault(); e.preventDefault();
e.stopPropagation(); e.stopPropagation();
if (!obj.el || isVisible(obj.el, $inner)) { return; } if (!obj.el || UIElements.isVisible(obj.el, $inner)) { return; }
obj.el.scrollIntoView(); obj.el.scrollIntoView();
}); });
a.innerHTML = obj.title; a.innerHTML = obj.title;

@ -1,19 +1,28 @@
define([ define([
'jquery', 'jquery',
'/common/hyperscript.js', '/common/hyperscript.js',
'/common/common-ui-elements.js',
'/customize/messages.js' '/customize/messages.js'
], function ($, h, Messages) { ], function ($, h, UIElements, Messages) {
var onLinkClicked = function (e, inner) { var onLinkClicked = function (e, inner) {
var $target = $(e.target); var $target = $(e.target);
if (!$target.is('a')) { return; } if (!$target.is('a')) { return; }
var href = $target.attr('href'); var href = $target.attr('href');
if (!href || href[0] === '#') { return; } if (!href) { return; }
var $inner = $(inner);
e.preventDefault(); e.preventDefault();
e.stopPropagation(); e.stopPropagation();
if (href[0] === '#') {
var anchor = $inner.find(href);
if (!anchor.length) { return; }
anchor[0].scrollIntoView();
return;
}
var $iframe = $('html').find('iframe').contents(); var $iframe = $('html').find('iframe').contents();
var $inner = $(inner);
var rect = e.target.getBoundingClientRect(); var rect = e.target.getBoundingClientRect();
var rect0 = inner.getBoundingClientRect(); var rect0 = inner.getBoundingClientRect();

Loading…
Cancel
Save