Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
summernote-ext-fixedtoolbar.js
/**
* Summernote Fixed Toolbar
*
* This is a plugin for Summernote (www.summernote.org) WYSIWYG editor.
* It will keep the toolbar fixed to the top of the screen as you scroll.
*
* @originalauthor Jason Byrne, FloSports <jason.byrne@flosports.tv>
* https://gist.github.com/jasonbyrne/
*
* @modifiedauthor rajnisheu https://gist.github.com/rajnisheu/
* modified to work with summernote 0.8 (and should work with 0.7)
*
*/
(function (factory) {
if (typeof define === 'function' && define.amd) {
define(['jquery'], factory);
} else if (typeof module === 'object' && module.exports) {
module.exports = factory(require('jquery'));
} else {
factory(window.jQuery);
}
}(function ($) {
$.extend($.summernote.plugins, {
'fixedToolbar': function(context) {
// Find editor
var $editor = context.layoutInfo.editor;
var options = context.options;
var lang = options.langInfo;
$toolbar = $editor.find('.note-toolbar');
// Scrolling event
var repositionToolbar = function() {
var windowTop = $(window).scrollTop(),
editorTop = $editor.offset().top,
editorBottom = editorTop + $editor.height();
if (windowTop > editorTop && windowTop < editorBottom) {
$toolbar.css('position', 'fixed');
$toolbar.css('top', '0px');
$toolbar.css('width', $editor.width() + 'px');
$toolbar.css('z-index', '999');
$editor.css('padding-top', '42px');
}
else {
$toolbar.css('position', 'static');
$editor.css('padding-top', '0px');
}
};
// Move it
$(window).scroll(repositionToolbar);
repositionToolbar();
}
});
}));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.