Koha/koha-tmpl/intranet-tmpl/prog/en/lib/jquery/plugins/jquery.fixFloat.js
Owen Leonard edd8e5767d Bug 7135 - in addbiblio, make save button floating to have it on always on screen
Follow-up fix corrects z-index of toolbar so that "More" menu
is not hidden behind it.

Signed-off-by: Paul Poulain <paul.poulain@biblibre.com>
2011-12-14 15:52:55 +01:00

68 lines
No EOL
2 KiB
JavaScript

/* Source: http://www.webspeaks.in/2011/07/new-gmail-like-floating-toolbar-jquery.html
Revision: http://jsfiddle.net/pasmalin/AyjeZ/
*/
(function($){
$.fn.fixFloat = function(options){
var defaults = {
enabled: true
};
var options = $.extend(defaults, options);
var offsetTop; /**Distance of the element from the top of window**/
var s; /**Scrolled distance from the top of window through which we have moved**/
var fixMe = true;
var repositionMe = true;
var tbh = $(this);
var originalOffset = tbh.position().top; /**Get the actual distance of the element from the top mychange:change to position better work**/
if (tbh.css('position')!='absolute') {
var tbhBis = $("<div></div>");
tbhBis.css({"display":tbh.css("display"),"visibility":"hidden"});
tbhBis.width(tbh.outerWidth(true));
tbhBis.height(tbh.outerHeight(true));
tbh.after(tbhBis);
tbh.width(tbh.width());
tbh.css({'position':'absolute'});
}
if(options.enabled){
$(window).scroll(function(){
var offsetTop = tbh.offset().top; /**Get the current distance of the element from the top **/
var s = parseInt($(window).scrollTop(), 10); /**Get the from the top of wondow through which we have scrolled**/
var fixMe = true;
if(s > offsetTop){
fixMe = true;
}else{
fixMe = false;
}
if(s < originalOffset){
repositionMe = true;
}else{
repositionMe = false;
}
if(fixMe){
var cssObj = {
'position' : 'fixed',
'top' : '0px',
'z-index' : '1000'
}
tbh.css(cssObj);
tbh.addClass("floating");
}
if(repositionMe){
var cssObj = {
'position' : 'absolute',
'top' : originalOffset,
'z-index' : '1'
}
tbh.css(cssObj);
tbh.removeClass("floating");
}
});
}
};
})(jQuery);