Difference between revisions of "MediaWiki talk:Common.js"

From Baka-Tsuki
Jump to navigation Jump to search
 
(One intermediate revision by the same user not shown)
Line 1: Line 1:
  +
==Idea==
/** Collapsible tables *********************************************************
 
  +
Umm. Is it possible to install [http://www.mediawiki.org/wiki/Manual:Collapsible_elements#Before_1.17 Collapsiblity]. It will allow mature pages to be made collapsible rather than having to make warning pages separately. Also will become insertable in full text pages. Example:
*
 
  +
----
* Description: Allows tables to be collapsed, showing only the header. See
 
  +
{| class="wikitable collapsible collapsed" width="100%" style="text-align:left; clear:both; font-size:100% background-color:#transparent;"
* http://www.mediawiki.org/wiki/Manual:Collapsible_tables.
 
  +
! style="background:#C0C0C0;" align="center"|This chapter is Mature and is considered for Adults (18+) only.<br>If you are below the age of consent in your respected country, you are advised to not expand this chapter.<br>By continuing, you are agreeing to the terms of our [[Baka-Tsuki:Copyrights|Disclaimer]].
* Maintainers: [[en:User:R. Koot]]
 
  +
|-
*/
 
  +
|Mature reading text written here
 
  +
var autoCollapse = 2;
 
  +
<nowiki>---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------</nowiki>
var collapseCaption = 'hide';
 
  +
var expandCaption = 'show';
 
  +
<nowiki>---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------</nowiki>
 
  +
function collapseTable( tableIndex ) {
 
  +
<nowiki>---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------</nowiki>
var Button = document.getElementById( 'collapseButton' + tableIndex );
 
  +
var Table = document.getElementById( 'collapsibleTable' + tableIndex );
 
  +
<nowiki>---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------</nowiki>
 
  +
|-
if ( !Table || !Button ) {
 
  +
|}
return false;
 
  +
----
}
 
  +
Note the above table should automatically become collapsible once collapsiblity is installed. Background colors can be changed. Basically a hide/show link/button/thingy will appear on the right side of the grey bar. [[User:Zero2001|Zero2001]] - [[User_talk:Zero2001|Talk]] - 14:00, 10 June 2011 (UCT)
 
  +
var Rows = Table.rows;
 
  +
Come on guys. It's not like the current web settings will get messed up if you do append the collapsiblity functions. Plus in website cases the lesser the page loading need to get to the goal the better (famous websites use this, it's even part of website designing in Computer Sciences). Collapsible tables can help hide mature content thus changing the normal path from: "Light Novel Main Page" → "Warning Page" → "Mature Content Page" ''to:'' "Light Novel Main Page" → "Mature Content Page (with content hidden)". See... 3 page loads > 2 page loads therefore 2 page loads one is better, no? [[User:Zero2001|Zero2001]] - [[User_talk:Zero2001|Talk]] - 15:51, 13 June 2011 (UCT)
 
  +
if ( Button.firstChild.data == collapseCaption ) {
 
  +
Another advantage would be the creation of collapsible navigation templates for the series that will allow people to jump between chapters much more smoothly, especially when the chapters in question are non-successive. (It might seem stupid but there are many people who jump between non-successive chapters to confirm a previous event/fact) [[User:Zero2001|Zero2001]] - [[User_talk:Zero2001|Talk]] - 15:16, 28 June 2011 (UCT)
for ( var i = 1; i < Rows.length; i++ ) {
 
  +
Rows[i].style.display = 'none';
 
  +
Huuum...Zero, do you know in which specific case should we use it? I've not seen anywhere that you could use that... [[User:Kira0802|Kira]] 17:35, 28 June 2011 (UCT)
}
 
  +
Button.firstChild.data = expandCaption;
 
  +
Chapter 16.5 of Sword Art Online and other H-scenes in the Visual Novels. Also some prototype nav templates I am making. [[User:Zero2001/Sandbox|Wanna see?]]. But it's still in the building phase. I intend to make the same for many series. [[User:Zero2001|Zero2001]] - [[User_talk:Zero2001|Talk]] - 19:48, 28 June 2011 (UCT)
} else {
 
  +
for ( var i = 1; i < Rows.length; i++ ) {
 
  +
Just passed through quickly chapter 16.5. I understand a bit now. Well, I think it's OK in my opinion. [[User:Kira0802|Kira]] 20:55, 28 June 2011 (UCT)
Rows[i].style.display = Rows[0].style.display;
 
  +
}
 
  +
[http://www.baka-tsuki.org/forums/viewtopic.php?f=16&t=4458 Forum thread]. [[User:Zero2001|Zero2001]] - [[User_talk:Zero2001|Talk]] - 16:32, 2 July 2011 (UCT)
Button.firstChild.data = collapseCaption;
 
  +
}
 
  +
{| class="wikitable collapsible"
}
 
  +
|A normal cell in the header row
 
  +
! colspan="2"| Header cell spans two cols
function createCollapseButtons() {
 
  +
|-
var tableIndex = 0;
 
  +
| colspan="2" | Lorem ipsum dolor sit amet
var NavigationBoxes = new Object();
 
  +
| Separate body cell
var Tables = document.getElementsByTagName( 'table' );
 
+
|}
for ( var i = 0; i < Tables.length; i++ ) {
 
if ( hasClass( Tables[i], 'collapsible' ) ) {
 
 
/* only add button and increment count if there is a header row to work with */
 
var HeaderRow = Tables[i].getElementsByTagName( 'tr' )[0];
 
if ( !HeaderRow ) {
 
continue;
 
}
 
var Header = HeaderRow.getElementsByTagName( 'th' )[0];
 
if ( !Header ) {
 
continue;
 
}
 
 
NavigationBoxes[tableIndex] = Tables[i];
 
Tables[i].setAttribute( 'id', 'collapsibleTable' + tableIndex );
 
 
var Button = document.createElement( 'span' );
 
var ButtonLink = document.createElement( 'a' );
 
var ButtonText = document.createTextNode( collapseCaption );
 
 
Button.className = 'collapseButton'; // Styles are declared in [[MediaWiki:Common.css]]
 
 
ButtonLink.style.color = Header.style.color;
 
ButtonLink.setAttribute( 'id', 'collapseButton' + tableIndex );
 
ButtonLink.setAttribute( 'href', "javascript:collapseTable(" + tableIndex + ");" );
 
ButtonLink.appendChild( ButtonText );
 
 
Button.appendChild( document.createTextNode( '[' ) );
 
Button.appendChild( ButtonLink );
 
Button.appendChild( document.createTextNode( ']' ) );
 
 
Header.insertBefore( Button, Header.childNodes[0] );
 
tableIndex++;
 
}
 
}
 
 
for ( var i = 0; i < tableIndex; i++ ) {
 
if ( hasClass( NavigationBoxes[i], 'collapsed' ) || ( tableIndex >= autoCollapse && hasClass( NavigationBoxes[i], 'autocollapse' ) ) ) {
 
collapseTable( i );
 
} else if ( hasClass( NavigationBoxes[i], 'innercollapse' ) ) {
 
var element = NavigationBoxes[i];
 
while ( element = element.parentNode ) {
 
if ( hasClass( element, 'outercollapse' ) ) {
 
collapseTable( i );
 
break;
 
}
 
}
 
}
 
}
 
}
 
 
addOnloadHook( createCollapseButtons );
 
 
/** Test if an element has a certain class **************************************
 
*
 
* Description: Uses regular expressions and caching for better performance.
 
* Maintainers: [[User:Mike Dillon]], [[User:R. Koot]], [[User:SG]]
 
*/
 
 
var hasClass = ( function() {
 
var reCache = {};
 
return function( element, className ) {
 
return ( reCache[className] ? reCache[className] : ( reCache[className] = new RegExp( "(?:\\s|^)" + className + "(?:\\s|$)" ) ) ).test( element.className );
 
};
 
})();
 

Latest revision as of 22:02, 23 July 2011

Idea[edit]

Umm. Is it possible to install Collapsiblity. It will allow mature pages to be made collapsible rather than having to make warning pages separately. Also will become insertable in full text pages. Example:



Note the above table should automatically become collapsible once collapsiblity is installed. Background colors can be changed. Basically a hide/show link/button/thingy will appear on the right side of the grey bar. Zero2001 - Talk - 14:00, 10 June 2011 (UCT)

Come on guys. It's not like the current web settings will get messed up if you do append the collapsiblity functions. Plus in website cases the lesser the page loading need to get to the goal the better (famous websites use this, it's even part of website designing in Computer Sciences). Collapsible tables can help hide mature content thus changing the normal path from: "Light Novel Main Page" → "Warning Page" → "Mature Content Page" to: "Light Novel Main Page" → "Mature Content Page (with content hidden)". See... 3 page loads > 2 page loads therefore 2 page loads one is better, no? Zero2001 - Talk - 15:51, 13 June 2011 (UCT)

Another advantage would be the creation of collapsible navigation templates for the series that will allow people to jump between chapters much more smoothly, especially when the chapters in question are non-successive. (It might seem stupid but there are many people who jump between non-successive chapters to confirm a previous event/fact) Zero2001 - Talk - 15:16, 28 June 2011 (UCT)

Huuum...Zero, do you know in which specific case should we use it? I've not seen anywhere that you could use that... Kira 17:35, 28 June 2011 (UCT)

Chapter 16.5 of Sword Art Online and other H-scenes in the Visual Novels. Also some prototype nav templates I am making. Wanna see?. But it's still in the building phase. I intend to make the same for many series. Zero2001 - Talk - 19:48, 28 June 2011 (UCT)

Just passed through quickly chapter 16.5. I understand a bit now. Well, I think it's OK in my opinion. Kira 20:55, 28 June 2011 (UCT)

Forum thread. Zero2001 - Talk - 16:32, 2 July 2011 (UCT)

A normal cell in the header row Header cell spans two cols
Lorem ipsum dolor sit amet Separate body cell