Skip to content

Instantly share code, notes, and snippets.

@rajnisheu
Created February 12, 2017 14:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rajnisheu/471aa8e68cdfcf55dcd42dd5342ce640 to your computer and use it in GitHub Desktop.
Save rajnisheu/471aa8e68cdfcf55dcd42dd5342ce640 to your computer and use it in GitHub Desktop.
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