By Wolfflow on
Hi I found a solution to implement collapsible block with JQuery. I found the tip at Here the Author defined from the site is keven.squad5.
Well I did implement the code and is ok! the only bug is that it hide automatic any block settled on left or right sidebar, With Firebug you can deactivate the inserted css tag element style {display:none;} and show the block again.
What happen is that there is no Show/Hide (Block Title) link for switching from hide/show. Below the code:
1. Blocks.toggle.js
function toggle_block(id, target_id){
$("#"+id).click(function() {if($.cookie(target_id) != 'shown'){
$("#"+target_id).show('slow');
$.cookie(target_id, 'shown');
}else{
$("#"+target_id).hide('slow');
$.cookie(target_id, 'hidden');
}
});
if($.cookie(target_id) != 'shown'){
$('#'+target_id).hide();
}
}
2. block.tpl.php:
<?php // $Id: block.tpl.php,v 1.3 2007/08/07 08:39:36 goba Exp $
drupal_add_js(path_to_theme() . '/js/jquery.cookie.js');
drupal_add_js(path_to_theme() . '/js/blocks.toggle.js');
$js = '$(document).ready(function(){' . ' toggle_block(\'toggle-' . $block->module .'-'. $block->delta . '\', \'block-' . $block->module .'-'. $block->delta . '\');' .'});';
drupal_add_js($js,'inline');
?>
<div id="block-<?php print $block->module .'-'. $block->delta; ?>" class="clear-block block block-<?php print $block->module ?>">
<?php if (!empty($block->subject)): ?>
<h2><a href="#" id="toggle-<?php print $block->module .'-'. $block->delta ?>"><?php print $block->subject ?></a></h2>
<?php endif;?>
<div class="block-content" id="block-<?php print $block->module .'-'. $block->delta; ?>"><?php print $block->content ?>
</div>
</div>
Any help is very much appreciate I'm not a coder :-) Thanks
Comments
=-=
may want to try, http://drupal.org/project/collapsiblock
Thanks @VM I know that
Thanks @VM I know that module, just building a solution for only one page.tpl.php as not to have to much modules installed.
Contact me for drupal projects in English, German, Italian, Drupal Hosting Support.
preprocess_block: <?php
preprocess_block:
blocks.toggle.js:
@seutje : will give it a
@seutje : will give it a go, thanks meanwhile!!
Contact me for drupal projects in English, German, Italian, Drupal Hosting Support.
@seutje done this: function
@seutje
done this:
function garland_preprocess_block(&$vars) {but unclear for this:
(/* condition for activating, e.g. $block->module == 'foo' or by path or something */)I would like to have it activated for every block when user have permission to hide/diplay blocks
Should I put the _preprocess_ function in the garland template.php or only in my block.tpl.php?
Contact me for drupal projects in English, German, Italian, Drupal Hosting Support.
preprocess implementations go
preprocess implementations go in template.php
if (user_access('hide/display blocks'))I suppose, assuming this permission is defined by something in a hook_perm implementationSuccess! Really many thanks
Success! Really many thanks @seutje , appreciate and thankful for the time you dedicate to drive me in the right direction.
I spent really many times to look for a simple implementation, that can very easy be customize now.
One note on my code, that you missed also in your preprocess_block: suggestion, there was a small bug:
should be like this:
IMHO: With this small solution every one wants avoid to install collapsiblock and required Javascript Tools will have more choice for installing other very usefully contributed modules.
Again thanks I own you a beer!!
Regards
Contact me for drupal projects in English, German, Italian, Drupal Hosting Support.
Hi @sutje, just as additional
Hi @sutje, just as additional information, could you please direct me where should the hook_permission be inserted?
A. After the function in the theme template.php file
B. By building a small module suppose it should go in the collapsyblockcookie.module
C. or in a collapsyblockcookie.admin.inc
Regards
Contact me for drupal projects in English, German, Italian, Drupal Hosting Support.
hmm, yea sry, I never
hmm, yea sry, I never actually tested it, I just wrote that as an example or startingpoint
unfortunately, themes can't implement hook_permission in Drupal 6 (they can in 7 so then you can just drop it in template.php), so you'll have to make it into a module and then you might as well move the js and preprocess_block implementation to that same module
Update
Required code for implementing:
/jsfolderNote: The code works but still have some buggy behave:
1. After some testing Show/Hide Block , the block/s disappear. it look that a settings conflict exist.
Contact me for drupal projects in English, German, Italian, Drupal Hosting Support.
Permission and collaboration
FYI:
For correctness I post here the email text:
sent to http://keven.squad5.net/ with sites contact form 07.07.2010 10:30
Contact me for drupal projects in English, German, Italian, Drupal Hosting Support.
amazing!
This is Keven Ages here. You absolutely have my persmission and blessing to do whatever you'd like with this code Wolfflow. I'm glad you find it useful!
Eventually for collapsicookie.module
Work in progress:
Contact me for drupal projects in English, German, Italian, Drupal Hosting Support.
block.tpl.php is incorrect
Here is the correct way to implement block.tpl.php
FYI Demonstration Site: For
FYI Demonstration Site:
For those that would like to see how this small project works at actual development stage you can visit Drupal 6.17 Sandbox Site,
please use --- user: demo and password: demo --- to log in.
Contact me for drupal projects in English, German, Italian, Drupal Hosting Support.
So assuming the code above
So assuming the code above isn't working. I tried to get it working with rootcandy theme and faced the same bug as discribed by Wolfflow - after show/hide link clicked, this block disappeared for ever.
Any ideas how to fix it?
Hi @volocuga. I am trying to
Hi @volocuga. I am trying to build a small module for this but as I'm not a php proof it will take me some time to figue this out. Stay tuned.
Regards
Contact me for drupal projects in English, German, Italian, Drupal Hosting Support.
What does your block.tpl.php
What does your block.tpl.php code look like?
Hi, Keven, glad to get your
Hi, Keven, glad to get your support and thanks for granted permission in name of me and others who may find this useful.
So the code of block.tpl.php is as follow:
Kind Regards
Note: I just re-paste here the code edited at #Update comment above.
Contact me for drupal projects in English, German, Italian, Drupal Hosting Support.
Replace that code with this
Replace your current block.tpl.php code with the following:
@blueflowers - nope.
@blueflowers - nope.
(unstable) - last used from me:
I think the problems lies that we need a substitute/replace "hide"-link that may call the javascript toggle for status=visible
and then when clicked for set status=invisible the javascript call a substitute/routine for showing the "display"-link.
I will try to separate/divide the toggle js code, 1. for hiding, 2. for displaying
...to be continued
Contact me for drupal projects in English, German, Italian, Drupal Hosting Support.
Studing jQuery Toggle
references:
1. jQuery toggle & cookies
Contact me for drupal projects in English, German, Italian, Drupal Hosting Support.
I think we should find
I think we should find another approach with JQuery Collapsible Block with Cookies
I did a bit of searching and with your help we should be better off with
JQuery Toggle-block with Cookies
So I have found some help (here) Simple Toggle with CSS & jQuery
The code parts that should be modified for working in Drupal with Jquery are:
themename_preprocess_functionin the template.php fileThis is a development tryout, so it does not work now, I'm just guessing.
Authors of relative codes are being contacted
Contact me for drupal projects in English, German, Italian, Drupal Hosting Support.
collapsiblock module
I'm the maintainer of http://drupal.org/project/collapsiblock. I sugest if you want the same feature as collapsiblock but not want to use a module you should check the JS inside. It was tested by thousands of poeple without major problem.
But if I was you I will just grab the module.... is very light and works out-of-the-box.
https://interface-network.com - Interface Network is an action and research technology governance agency.