r78914 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r78913‎ | r78914 | r78915 >
Date:19:25, 23 December 2010
Author:krinkle
Status:ok (Comments)
Tags:
Comment:
adding jQuery.makeCollapsible plugin
Modified paths:
  • /trunk/phase3/resources/Resources.php (modified) (history)
  • /trunk/phase3/resources/jquery/jquery.makeCollapsible.css (added) (history)
  • /trunk/phase3/resources/jquery/jquery.makeCollapsible.js (added) (history)

Diff [purge]

Index: trunk/phase3/resources/jquery/jquery.makeCollapsible.js
@@ -0,0 +1,109 @@
 2+/**
 3+ * make lists, divs, tables etc. toggleable
 4+ *
 5+ * This will enable collapsible-functionality on all passed elements.
 6+ * Will prevent binding twice to the same element.
 7+ * Initial state is expanded by default, this can be overriden by adding class
 8+ * "kr-collapsed" to the "kr-collapsible" element.
 9+ * Elements made collapsible have class "kr-made-collapsible".
 10+ * Except for tables and lists, the inner content is wrapped in "kr-collapsible-content".
 11+ *
 12+ * Copyright 2008-2009 Krinkle <krinklemail@gmail.com>
 13+ *
 14+ * @license CC-BY 2.0 NL <http://creativecommons.org/licenses/by/2.0/nl/deed.en>
 15+ */
 16+
 17+$.fn.makeCollapsible = function() {
 18+
 19+ return this.each(function() {
 20+ var $that = $(this).addClass('kr-collapsible'), // in case $('#myAJAXelement').makeCollapsible() was called
 21+ that = this,
 22+ collapsetext = $(this).attr('data-collapsetext'),
 23+ expandtext = $(this).attr('data-expandtext');
 24+ // Use custom text or default ?
 25+ if( !collapsetext || collapsetext == ''){
 26+ collapsetext = 'Collapse';
 27+ }
 28+ if ( !expandtext || expandtext == ''){
 29+ expandtext = 'Expand';
 30+ }
 31+ // Create toggle link with a space around the brackets (&nbsp)
 32+ $toggleLink = $('<span class="kr-collapsible-toggle kr-collapsible-toggle-hide">&nbsp;[<a href="#">' + collapsetext + '</a>]&nbsp;</span>').click(function(){
 33+ var $that = $(this),
 34+ $collapsible = $that.closest('.kr-collapsible.kr-made-collapsible').toggleClass('kr-collapsed');
 35+ if ($that.hasClass('kr-collapsible-toggle-hide')) {
 36+ // Change link to "Show"
 37+ $that
 38+ .removeClass('kr-collapsible-toggle-hide').addClass('kr-collapsible-toggle-show')
 39+ .find('> a').html(expandtext);
 40+ // Hide the collapsible element
 41+ if ($collapsible.is('table')) {
 42+ // Hide all direct childing table rows of this table, except the row containing the link
 43+ // Slide doens't work, but fade works fine as of jQuery 1.1.3
 44+ // http://stackoverflow.com/questions/467336/jquery-how-to-use-slidedown-or-show-function-on-a-table-row#920480
 45+ // Stop to prevent animaties from stacking up
 46+ $collapsible.find('> tbody > tr').not($that.parent().parent()).stop(true, true).fadeOut();
 47+ } else if ($collapsible.is('ul') || $collapsible.is('ol')) {
 48+ $collapsible.find('> li').not($that.parent()).stop(true, true).slideUp();
 49+ } else { // <div>, <p> etc.
 50+ $collapsible.find('> .kr-collapsible-content').slideUp();
 51+ }
 52+ } else {
 53+ // Change link to "Hide"
 54+ $that
 55+ .removeClass('kr-collapsible-toggle-show').addClass('kr-collapsible-toggle-hide')
 56+ .find('> a').html(collapsetext);
 57+ // Show the collapsible element
 58+ if ($collapsible.is('table')) {
 59+ $collapsible.find('> tbody > tr').not($that.parent().parent()).stop(true, true).fadeIn();
 60+ } else if ($collapsible.is('ul') || $collapsible.is('ol')) {
 61+ $collapsible.find('> li').not($that.parent()).stop(true, true).slideDown();
 62+ } else { // <div>, <p> etc.
 63+ $collapsible.find('> .kr-collapsible-content').slideDown();
 64+ }
 65+ }
 66+ return false;
 67+ });
 68+ // Skip if it has been enabled already.
 69+ if ($that.hasClass('kr-made-collapsible')) {
 70+ return;
 71+ } else {
 72+ $that.addClass('kr-made-collapsible');
 73+ }
 74+ // Elements are treated differently
 75+ if ($that.is('table')) {
 76+ // The toggle-link will be in the last cell (td or th) of the first row
 77+ var $lastCell = $('tr:first th, tr:first td', that).eq(-1);
 78+ if (!$lastCell.find('> .kr-collapsible-toggle').size()) {
 79+ $lastCell.prepend($toggleLink);
 80+ }
 81+
 82+ } else if ($that.is('ul') || $that.is('ol')) {
 83+ if (!$('li:first', $that).find('> .kr-collapsible-toggle').size()) {
 84+ // Make sure the numeral count doesn't get messed up, reset to 1 unless value-attribute is already used
 85+ if ( $('li:first', $that).attr('value') == '' ) {
 86+ $('li:first', $that).attr('value', '1');
 87+ }
 88+ $that.prepend($toggleLink.wrap('<li class="kr-collapsibile-toggle-li">').parent());
 89+ }
 90+ } else { // <div>, <p> etc.
 91+ // Is there an content-wrapper already made ?
 92+ // If a direct child with the class does not exists, create the wrap.
 93+ if (!$that.find('g> .kr-collapsible-content').size()) {
 94+ $that.wrapInner('<div class="kr-collapsible-content">');
 95+ }
 96+
 97+ // Add toggle-link if not present
 98+ if (!$that.find('> .kr-collapsible-toggle').size()) {
 99+ $that.prepend($toggleLink);
 100+ }
 101+ }
 102+ // Initial state
 103+ if ($that.hasClass('kr-collapsed')) {
 104+ $toggleLink.click();
 105+ }
 106+ });
 107+};
 108+$(function(){
 109+ $('.kr-collapsible').makeCollapsible();
 110+});
\ No newline at end of file
Property changes on: trunk/phase3/resources/jquery/jquery.makeCollapsible.js
___________________________________________________________________
Added: svn:eol-style
1111 + native
Index: trunk/phase3/resources/jquery/jquery.makeCollapsible.css
@@ -0,0 +1,12 @@
 2+/* See also jQuery.makeCollapsible.js */
 3+.kr-collapsible-toggle {
 4+ float:right;
 5+}
 6+/* list-items go as wide as their parent element, don't float them inside list items */
 7+li .kr-collapsible-toggle {
 8+ float:none;
 9+}
 10+/* the added list item should have no list-style */
 11+.kr-collapsibile-toggle-li {
 12+ list-style:none;
 13+}
\ No newline at end of file
Property changes on: trunk/phase3/resources/jquery/jquery.makeCollapsible.css
___________________________________________________________________
Added: svn:eol-style
114 + native
Index: trunk/phase3/resources/Resources.php
@@ -78,6 +78,10 @@
7979 'jquery.localize' => array(
8080 'scripts' => 'resources/jquery/jquery.localize.js'
8181 ),
 82+ 'jquery.makeCollapsible' => array(
 83+ 'scripts' => 'resources/jquery/jquery.makeCollapsible.js',
 84+ 'styles' => 'resources/jquery/jquery.makeCollapsible.css',
 85+ ),
8286 'jquery.suggestions' => array(
8387 'scripts' => 'resources/jquery/jquery.suggestions.js',
8488 'styles' => 'resources/jquery/jquery.suggestions.css',
@@ -345,7 +349,7 @@
346350 ),
347351 'mediawiki.util' => array(
348352 'scripts' => 'resources/mediawiki.util/mediawiki.util.js',
349 - 'dependencies' => array( 'jquery.checkboxShiftClick', 'jquery.client', 'jquery.placeholder' ),
 353+ 'dependencies' => array( 'jquery.checkboxShiftClick', 'jquery.client', 'jquery.placeholder', 'jquery.makeCollapsible' ),
350354 'debugScripts' => 'resources/mediawiki.util/mediawiki.util.test.js',
351355 ),
352356 'mediawiki.action.history' => array(

Sign-offs

UserFlagDate
Hasharinspected12:10, 7 March 2011

Follow-up revisions

RevisionCommit summaryAuthorDate
r78915whitespace according to mw conventions + using mw.msg instead of english hard...krinkle19:26, 23 December 2010

Comments

#Comment by Aaron Schulz (talk | contribs)   20:31, 14 June 2011

+ Slide doens't work

Weee :)

Not sure I'm a fan of the "kr-" prefix. Meh.

#Comment by Krinkle (talk | contribs)   20:44, 14 June 2011

As you move forward in the commits related to this you'll encounter the commit that dropped this in favour of mw

I wrote this plugin originally for myself in 2008, initial check-in still had "kr" (krinkle) prefix.

#Comment by He7d3r (talk | contribs)   12:48, 28 June 2011

Does anyone know in which MW version this plugin is going to be available? Some people seems to be confused by the current information on Manual:Collapsible elements. I think some information should be added to the release notes and maybe the wikipage should be tagged with {{MW 1.18|r=78914}} (or the appropriated tag).

#Comment by P858snake (talk | contribs)   12:53, 28 June 2011

I'm pretty sure it falls within the 1.18 branching.

Status & tagging log