Skip to content
Snippets Groups Projects
Commit f85f8c94 authored by Alex Pott's avatar Alex Pott
Browse files

Initial commit of the floating block module

parents
No related branches found
Tags 7.x-2.11
No related merge requests found
$Id$
-- SUMMARY --
The Floating block module allows you to keep html blocks, selected using
jquery selectors in a fixed position on the page similar to the way that
tableheader.js works in core Drupal.
For a full description of the module, visit the project page
http://drupal.org/project/floating_block
To submit bug reports and feature suggestions, or to track changes
http://drupal.org/project/issues/floating_block
-- REQUIREMENTS --
None.
-- INSTALLATION --
Install as usual, see http://drupal.org/node/70151 for further information.
-- CONFIGURATION --
Configure which htmls blocks to apply the effect to in
Administer > Settings > Floating Block
Customize the menu settings in Administer Site configuration
Administration menu.
To prevent administrative menu items from appearing twice, you may hide the
Navigation menu block, or move the Administer menu items into a separate
menu.
-- CUSTOMIZATION --
-- TROUBLESHOOTING --
-- FAQ --
-- CONTACT --
Current maintainers
Alex Pott (alexpott) - http://drupal.org/user/157725
; $Id:
name = Floating Block
description = Allows regions of the site to float
;package = Development
core = 6.x
// $Id$
/**
* Provides the ability to fix a html block to a position on the page when the
* browser is scroled.
*
* This code is based on tableheader.js
*/
Drupal.blockFloatDoScroll = function() {
if (typeof(Drupal.blockFloatOnScroll)=='function') {
Drupal.blockFloatOnScroll();
}
};
/**
* Attaches the floating_block behavior.
*/
Drupal.behaviors.blockFloat = function (context) {
// This breaks in anything less than IE 7. Prevent it from running.
if (jQuery.browser.msie && parseInt(jQuery.browser.version, 10) < 7) {
return;
}
// Keep track of all cloned blocks.
var blocks = [];
$(Drupal.settings.floating_block).each(function (i, selector) {
$(selector.toString() +':not(.blockFloat-processed)', context).each(function (j, block) {
// Clone thead so it inherits original jQuery properties.
var blockClone = $(block).clone(true).insertBefore(block).addClass('sticky-block').css({
position: 'fixed',
top: '0px',
width: $(this).width(),
height: $(this).height(),
visibility: 'hidden'
});
if ($(block).attr('id').length > 0) {
$(blockClone).attr('id',$(block).attr('id') + '-clone');
}
blockClone = $(blockClone)[0];
blockClone.original_position = $(block).offset();
blocks.push(blockClone);
// Finish initialzing header positioning.
tracker(blockClone);
//Maybe need to attach soemthing to parent div?
//$(table).addClass('sticky-table');
$(block).addClass('blockFloat-processed');
});
});
// Define the anchor holding var.
var prevAnchor = '';
// Track positioning and visibility.
function tracker(e) {
// Save positioning data.
var viewHeight = document.documentElement.scrollHeight || document.body.scrollHeight;
if (e.viewHeight != viewHeight) {
e.viewHeight = viewHeight;
e.docHeight = $(document).height();
e.vPosition = e.original_position.top;
e.hPosition = e.original_position.left;
e.vLength = e.clientHeight;
}
var current_position = $(e).offset();
// Track horizontal positioning relative to the viewport and set visibility.
var hScroll = document.documentElement.scrollLeft || document.body.scrollLeft;
var vOffset = (document.documentElement.scrollTop || document.body.scrollTop) - e.vPosition;
var topPosition = 0;
if (vOffset > 0) {
visState = 'visible';
$('#sidebar-left-inner').css({visibility: 'hidden'});
//Don't let the bottom of the block go beneath the document height
if ((current_position.top + e.vLength) > e.docHeight) {
topPosition = e.docHeight - current_position.top - e.vLength;
}
}
else {
visState = 'hidden';
$('#sidebar-left-inner').css({visibility: 'visible'});
}
$(e).css({left: -hScroll + e.hPosition +'px', visibility: visState, top: topPosition +'px'});
}
// Only attach to scrollbars once, even if Drupal.attachBehaviors is called
// multiple times.
if (!$('body').hasClass('blockFloat-processed')) {
$('body').addClass('blockFloat-processed');
$(window).scroll(Drupal.blockFloatDoScroll);
$(document.documentElement).scroll(Drupal.blockFloatDoScroll);
}
// Track scrolling.
Drupal.blockFloatOnScroll = function() {
$(blocks).each(function () {
tracker(this);
});
};
// Track resizing.
var time = null;
var resize = function () {
// Ensure minimum time between adjustments.
if (time) {
return;
}
time = setTimeout(function () {
$('.sticky-block').each(function () {
this.viewHeight = 0;
tracker(this);
});
// Reset timer
time = null;
}, 250);
};
$(window).resize(resize);
};
<?php
// $Id$
/**
* @file
* Allows regions of the site to float.
*/
/**
* Implementation of hook_init().
*/
function floating_block_init() {
$selectors = preg_split("/(\r\n|\n)/", variable_get('floating_block_to_apply', ''));
if (count($selectors)) {
drupal_add_js(array('floating_block' => $selectors, ), 'setting');
$path = drupal_get_path('module', 'floating_block');
drupal_add_js($path . '/floating_block.js');
}
}
/**
* Implementation of hook_menu().
*/
function floating_block_menu() {
$items = array();
$items['admin/settings/floating_block'] = array(
'title' => 'Floating block',
'description' => 'Configure floating block.',
'access arguments' => array('administer site configuration'),
'page callback' => 'drupal_get_form',
'page arguments' => array('floating_block_admin')
);
return $items;
}
/**
* Form to config floating block settings.
*/
function floating_block_admin() {
$form = array();
$form['floating_block_to_apply'] = array(
'#type' => 'textarea',
'#title' => t('CSS Classes/Selectors to <em>Include</em>'),
'#default_value' => variable_get('floating_block_to_apply', ''),
'#description' => t('CSS selectors including id or class where to apply the floating block to. For example use <code>#sidebar-left</code> for ID, <code>.sidebar-left</code> for classes, and/or <code>#floating-block .floating_block</code> for combination. One selector per line.'),
);
return system_settings_form($form);
}
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment