-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsummernote-sticky-toolbar.js
80 lines (66 loc) · 2.18 KB
/
summernote-sticky-toolbar.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
/**
* Summernote Sticky Toolbar
*
* This is a plugin for Summernote (www.summernote.org) WYSIWYG editor.
* It will keep the toolbar sticky to the top of the screen as you scroll.
*
* @author İlyas Özkurt <[email protected]>
*
*/
(function (factory) {
/* Global define */
if (typeof define === 'function' && define.amd) {
// AMD. Register as an anonymous module.
define(['jquery'], factory);
} else if (typeof module === 'object' && module.exports) {
// Node/CommonJS
module.exports = factory(require('jquery'));
} else {
// Browser globals
factory(window.jQuery);
}
}(function ($) {
$.extend($.summernote.options, {
enabled: false,
offset: 0,
zIndex: 9999
})
$.extend($.summernote.plugins, {
/**
* @param {Object} context - context object has status of editor.
*/
'stickyToolbar': function (context) {
let $editor = context.layoutInfo.editor,
$toolbar = context.layoutInfo.toolbar,
options = context.options.stickyToolbar;
this.initialize = function () {
if (options.enabled) {
$(window).scroll(this.repositionToolbar);
this.repositionToolbar();
}
};
this.repositionToolbar = function () {
var windowTop = $(window).scrollTop() + options.offset,
editorTop = $editor.offset().top,
editorBottom = editorTop + $editor.height();
if (
windowTop > editorTop &&
windowTop < editorBottom
) {
$toolbar
.css({
'position': 'sticky',
'top': options.offset,
'z-index': options.zIndex,
});
} else {
$toolbar
.css({
'position': 'static',
'top': 0,
});
}
}
}
});
}));