public
Created

Accordion for SharePoint

  • Download Gist
sp-accordion.js
JavaScript
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
$('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();
});
});

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.