Create a gist now

Instantly share code, notes, and snippets.

Accordion for SharePoint
$('head').append($('<link rel="stylesheet">').attr('href', ''));
$.getScript('', function() {
$.getScript('', 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());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment