Advertisement
mspotilas

collapse/expand blogger sidebar gadgets

Feb 5th, 2012
2,329
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <script src='http://code.jquery.com/jquery-latest.js' type='text/javascript'></script>
  2. <style type='text/css'>
  3. .cegdicon { position:relative;float:right;height:9px;width:9px;top:3px;margin-top:0px;}
  4. .cegdlink { display:block; }
  5. .cegdclosed { background: url(data:image/gif;base64,R0lGODlhCQAJAKIAAO/v5/fz78TK1/f39wAAAIuRoP///wAAACH5BAAAAAAALAAAAAAJAAkAAAMeKLVcajCaFQkca2gywiwDIYpfEAAWREHpJ0VOwwgJADs=) center center no-repeat;}
  6. .cegdopen { background: url(data:image/gif;base64,R0lGODlhCQAJAKIAAO/v5/fz78TK1/f39wAAAIuRoP///wAAACH5BAAAAAAALAAAAAAJAAkAAAMbKLVcajCaJeFYI+cwyyAg2AUBIFFVl05KswgJADs=) center center no-repeat;}
  7. </style>
  8. <script type='text/javascript'>
  9. //<![CDATA[
  10. // collapse/expand blogger sidebar gadgets
  11. // MS-potilas 2012. See http://yabtb.blogspot.com/2012/02/hack-to-expandcollapse-blogger-sidebar.html
  12. var cegdMargin = 6;
  13. var cegdGroups = {};
  14. function cegdToggle(ee, closeonly) {
  15.   if(!closeonly) closeonly = false;
  16.   var ele = $(ee);
  17.   var ene = ele.find(".widget-content:first");
  18.   if(!ene.length) ene = ele.find(".gadgets-gadget-container:first");
  19.   var h2 = ele.find("h2:first");
  20.   if(closeonly || !ene.is(":hidden")) {
  21.     ene.slideUp("fast");
  22.     h2.find(".cegdicon").addClass("cegdclosed");
  23.     h2.find(".cegdicon").removeClass("cegdopen");
  24.   } else {
  25.     ene.slideDown("fast");
  26.     h2.find(".cegdicon").addClass("cegdopen");
  27.     h2.find(".cegdicon").removeClass("cegdclosed");
  28.   }
  29. }
  30. function cegdClose(ee) { cegdToggle(ee, true); }
  31. function cegdDo(ee) {
  32.   if(cegdGroups["#"+$(ee).attr("id")] && cegdGroups["#"+$(ee).attr("id")] != "") {
  33.     var ccc=cegdGroups["#"+$(ee).attr("id")].split(",");
  34.     for(var i=0; i<ccc.length; i++) cegdClose(ccc[i]);
  35.   }
  36.   cegdToggle(ee);
  37. }  
  38. function cegdInit(ele, closed) {
  39.   var h2 = $(ele).find("h2:first");
  40.   if(h2.length) {
  41.     if(!(h2.parent().is("a")))
  42.       h2.wrap('<a title="Click to show/hide" class="cegdlink" href="javascript:void(0)" onclick="cegdDo(&#39;'+ele+'&#39;);this.blur();"></a>');
  43.     $(ele).css('margin-top', cegdMargin);
  44.     $(ele).css('margin-bottom', cegdMargin);
  45.     if(!(h2.find(".cegdicon").length))
  46.       h2.prepend('<div class="cegdicon cegdopen"></div>');
  47.     if(closed) cegdClose(ele);
  48.   }
  49. }
  50. function cedgID(gdg) {
  51.   if(gdg[0] == '#') return gdg;
  52.   if($(gdg).length == 1) return gdg;
  53.   if(gdg[0] != '#' && $('#'+gdg).length == 1) return '#'+gdg;
  54.   if($(".widget h2:contains('"+gdg+"')").length == 1)
  55.     return '#'+($(".widget h2:contains('"+gdg+"')").parents(".widget").attr("id"));
  56.   return gdg;
  57. }
  58. function cedgAddOpen() {
  59.   if(arguments.length > 1 && cegdGroups[cedgID(arguments[0])]) return;
  60.   for(var i = 0; i < arguments.length; i++) {
  61.     arguments[i] = cedgID(arguments[i]);
  62.     cegdInit(arguments[i]);
  63.     var oth = "";
  64.     for(var j = 0; j < arguments.length; j++) {
  65.       if(i!=j) {
  66.         if(oth!="") oth += ",";
  67.         oth += cedgID(arguments[j]);
  68.       }
  69.     }
  70.     if(oth != "") cegdGroups[arguments[i]] = oth;
  71.     if(i) cegdClose(arguments[i]);
  72.   }
  73. }
  74. function cedgAddClosed(gdgid) {
  75.   cegdInit(cedgID(gdgid), true);
  76. }
  77. $(window).load(function() {
  78.   // call cedgAddOpen / cedgAddClosed for gadgets you want to expand/collapse
  79.   // parameter: gadget ID with # in front of it (CSS/jQuery selector), or gadget title.
  80.   // cedgAddOpen can also create a group, from which only one is open at a time.
  81.  
  82.   // Adds "About Me", initially closed
  83.   cedgAddClosed("#Profile1");
  84.  
  85.   // would add "Subscribe" gadget
  86.   // cedgAddOpen("#Subscribe1");
  87.    
  88.   // This would add all sidebar gadgets, and make them closed initially
  89.   // $(".sidebar .widget").each(function() { cedgAddClosed("#"+$(this).attr("id")); });
  90. });
  91. //]]>
  92. </script>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement