Skip to content

Commit 05dbe24

Browse files
author
Clemens Prerovsky
committed
split aloha-ui.js so that the sticky-top implementation is in it's own file
1 parent 31c67d8 commit 05dbe24

2 files changed

Lines changed: 34 additions & 19 deletions

File tree

demo/aloha-ui/aloha-ui-sticky.js

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
(function (aloha) {
2+
'use strict';
3+
4+
var $$ = aloha.editor.ui.$$;
5+
var Dom = aloha.dom;
6+
7+
/*
8+
* make elements with the .aloha-sticky-top class stick to the top when scrolling
9+
*/
10+
$$(window).on('scroll', function (event) {
11+
var stickies = $$('.aloha-sticky-top');
12+
var scrollTop = Dom.scrollTop(document);
13+
stickies.elements.forEach(function (element) {
14+
if (Dom.hasClass(element, 'aloha-sticky-top-active')) {
15+
if (scrollTop <= Dom.getAttr(element, 'data-aloha-sticky-top-pos')) {
16+
Dom.setAttr(element, 'data-aloha-sticky-top-pos', null);
17+
Dom.removeClass(element, 'aloha-sticky-top-active');
18+
}
19+
} else {
20+
if (scrollTop > Dom.absoluteTop(element)) {
21+
Dom.setAttr(element, 'data-aloha-sticky-top-pos', Dom.absoluteTop(element));
22+
Dom.addClass(element, 'aloha-sticky-top-active');
23+
}
24+
}
25+
});
26+
});
27+
})(window.aloha);
Lines changed: 7 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -528,25 +528,6 @@
528528
}
529529
});
530530

531-
// make .aloha-sticky-top items stick to the top when scrolling
532-
$$(window).on('scroll', function (event) {
533-
var stickies = $$('.aloha-sticky-top');
534-
var scrollTop = Dom.scrollTop(document);
535-
stickies.elements.forEach(function (element) {
536-
if (Dom.hasClass(element, 'aloha-sticky-top-active')) {
537-
if (scrollTop <= Dom.getAttr(element, 'data-aloha-sticky-top-pos')) {
538-
Dom.setAttr(element, 'data-aloha-sticky-top-pos', null);
539-
Dom.removeClass(element, 'aloha-sticky-top-active');
540-
}
541-
} else {
542-
if (scrollTop > Dom.absoluteTop(element)) {
543-
Dom.setAttr(element, 'data-aloha-sticky-top-pos', Dom.absoluteTop(element));
544-
Dom.addClass(element, 'aloha-sticky-top-active');
545-
}
546-
}
547-
});
548-
});
549-
550531
var shortcuts = {
551532
'meta+k' : LinksUI.insertLink,
552533
'ctrl+k' : LinksUI.insertLink
@@ -611,4 +592,11 @@
611592
}
612593

613594
aloha.editor.stack.unshift(handleUi);
595+
596+
// exports
597+
aloha.editor.ui = {
598+
'$$' : $$,
599+
shortcuts : shortcuts,
600+
actions : actions
601+
};
614602
}(window.aloha));

0 commit comments

Comments
 (0)