Merge branch 'toc_hackathon' of github.com:xwiki-labs/cryptpad into toc_hackathon
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;
|
||||
});
|
||||
|
|
|
@ -5,8 +5,9 @@ define([
|
|||
'/common/common-hash.js',
|
||||
'/common/hyperscript.js',
|
||||
'/common/common-interface.js',
|
||||
'/common/common-ui-elements.js',
|
||||
'/customize/messages.js'
|
||||
], function($, Sortify, Util, Hash, h, UI, Messages) {
|
||||
], function($, Sortify, Util, Hash, h, UI, UIElements, Messages) {
|
||||
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) {
|
||||
// Don't redraw if there were no change
|
||||
var str = Sortify(Env.comments || {});
|
||||
|
@ -558,7 +553,7 @@ define([
|
|||
|
||||
// Scroll into view
|
||||
if (!$last.length) { return; }
|
||||
var visible = isVisible($last[0], Env.$inner);
|
||||
var visible = UIElements.isVisible($last[0], Env.$inner);
|
||||
if (!visible) { $last[0].scrollIntoView(); }
|
||||
};
|
||||
|
||||
|
@ -574,7 +569,7 @@ define([
|
|||
|
||||
focusContent();
|
||||
|
||||
var visible = isVisible(div, Env.$container);
|
||||
var visible = UIElements.isVisible(div, Env.$container);
|
||||
if (!visible) { div.scrollIntoView(); }
|
||||
});
|
||||
|
||||
|
|
|
@ -42,6 +42,7 @@ define([
|
|||
'/common/common-hash.js',
|
||||
'/common/common-util.js',
|
||||
'/common/common-interface.js',
|
||||
'/common/common-ui-elements.js',
|
||||
'/common/hyperscript.js',
|
||||
'/bower_components/chainpad/chainpad.dist.js',
|
||||
'/customize/application_config.js',
|
||||
|
@ -69,6 +70,7 @@ define([
|
|||
Hash,
|
||||
Util,
|
||||
UI,
|
||||
UIElements,
|
||||
h,
|
||||
ChainPad,
|
||||
AppConfig,
|
||||
|
@ -609,12 +611,6 @@ define([
|
|||
}, 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 toc = [];
|
||||
$inner.find('h1, h2, h3').each(function (i, el) {
|
||||
|
@ -634,7 +630,7 @@ define([
|
|||
$(a).click(function (e) {
|
||||
e.preventDefault();
|
||||
e.stopPropagation();
|
||||
if (!obj.el || isVisible(obj.el, $inner)) { return; }
|
||||
if (!obj.el || UIElements.isVisible(obj.el, $inner)) { return; }
|
||||
obj.el.scrollIntoView();
|
||||
});
|
||||
a.innerHTML = obj.title;
|
||||
|
|
|
@ -1,19 +1,28 @@
|
|||
define([
|
||||
'jquery',
|
||||
'/common/hyperscript.js',
|
||||
'/common/common-ui-elements.js',
|
||||
'/customize/messages.js'
|
||||
], function ($, h, Messages) {
|
||||
], function ($, h, UIElements, Messages) {
|
||||
|
||||
var onLinkClicked = function (e, inner) {
|
||||
var $target = $(e.target);
|
||||
if (!$target.is('a')) { return; }
|
||||
var href = $target.attr('href');
|
||||
if (!href || href[0] === '#') { return; }
|
||||
if (!href) { return; }
|
||||
var $inner = $(inner);
|
||||
|
||||
e.preventDefault();
|
||||
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 $inner = $(inner);
|
||||
|
||||
var rect = e.target.getBoundingClientRect();
|
||||
var rect0 = inner.getBoundingClientRect();
|
||||
|
|
Loading…
Reference in New Issue