Skip to content

Instantly share code, notes, and snippets.

@jasonbyrne
Created October 15, 2015 21:39
Show Gist options
  • Save jasonbyrne/52042156292b71c2e084 to your computer and use it in GitHub Desktop.
Save jasonbyrne/52042156292b71c2e084 to your computer and use it in GitHub Desktop.
Plugin for Summernote to keep the toolbar fixed to the top of the screen as you scroll.
/**
* 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.
*
* @author Jason Byrne, FloSports <jason.byrne@flosports.tv>
*
*/
(function(factory) {
/* global define */
if (typeof define === 'function' && define.amd) {
// AMD. Register as an anonymous module.
define(['jquery'], factory);
}
else {
// Browser globals: jQuery
factory(window.jQuery);
}
}(function($) {
$.summernote.addPlugin({
name: 'fixedToolbar',
init: function(layoutInfo) {
// Find editor
var $editor = layoutInfo.holder().siblings('.note-editor'),
$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', '99999');
$editor.css('padding-top', '42px');
}
else {
$toolbar.css('position', 'static');
$editor.css('padding-top', '0px');
}
};
// Move it
$(window).scroll(repositionToolbar);
repositionToolbar();
}
});
}));
@ilyasozkurt
Copy link

Hello guys,

Here's the updated version:

https://github.com/ilyasozkurt/summernote-sticky-toolbar

Thank you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment