Skip to content

Instantly share code, notes, and snippets.

@eirikb
Created September 19, 2012 06:22
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save eirikb/3747997 to your computer and use it in GitHub Desktop.
Save eirikb/3747997 to your computer and use it in GitHub Desktop.
Accordion for SharePoint
$('head').append($('<link rel="stylesheet">').attr('href', 'http://twitter.github.com/bootstrap/assets/css/bootstrap.css'));
$.getScript('http://twitter.github.com/bootstrap/assets/js/bootstrap-transition.js', function() {
$.getScript('http://twitter.github.com/bootstrap/assets/js/bootstrap-collapse.js', function() {
var $collapse = $('<div class="accordion">');
var $tplHead = $('<div class="accordion-heading"><a class="accordion-toggle" data-toggle="collapse">');
var $tplBody = $('<div class="accordion-body collapse"><div class="accordion-inner">');
$('.s4-ba .s4-wpTopTable:has([webpartid])').each(function(i) {
var $wp = $(this);
var $content = $wp.find('[webpartid]');
var $head = $tplHead.clone();
var $body = $tplBody.clone();
if (i === 0) $body.addClass('in');
var $group = $('<div class="accordion-group">').append($head).append($body);
$head.find('a').text($wp.find('tr:first').text().trim()).attr('href', '#collapse' + i);
$body.attr('id', 'collapse' + i).find('div:last').append($content.clone());
$collapse.append($group);
}).first().before($collapse);
$collapse.collapse();
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment