미디어위키:Common.js: 두 판 사이의 차이
mobile redirect helper 삭제 |
숨기기/펼치기 관련 js 수정 |
||
| 35번째 줄: | 35번째 줄: | ||
* | * | ||
* Description: Allows tables to be collapsed, showing only the header. See | * Description: Allows tables to be collapsed, showing only the header. See | ||
* [[ | * [[Wikipedia:NavFrame]]. | ||
* Maintainers: [[ | * Maintainers: [[User:R. Koot]] | ||
*/ | */ | ||
var autoCollapse = 2; | var autoCollapse = 2; | ||
var collapseCaption = "숨기기"; | var collapseCaption = "숨기기"; | ||
var expandCaption = "보이기"; | var expandCaption = "보이기"; | ||
window.collapseTable = function( tableIndex ){ | |||
function | |||
{ | |||
var Button = document.getElementById( "collapseButton" + tableIndex ); | var Button = document.getElementById( "collapseButton" + tableIndex ); | ||
var Table = document.getElementById( "collapsibleTable" + tableIndex ); | var Table = document.getElementById( "collapsibleTable" + tableIndex ); | ||
if ( !Table || !Button ) { | if ( !Table || !Button ) { | ||
return false; | return false; | ||
} | } | ||
var Rows = Table.rows; | var Rows = Table.rows; | ||
if ( Button.firstChild.data == collapseCaption ) { | if ( Button.firstChild.data == collapseCaption ) { | ||
for ( var i = 1; i < Rows.length; i++ ) { | for ( var i = 1; i < Rows.length; i++ ) { | ||
| 66번째 줄: | 65번째 줄: | ||
} | } | ||
} | } | ||
function createCollapseButtons() | function createCollapseButtons(){ | ||
{ | |||
var tableIndex = 0; | var tableIndex = 0; | ||
var NavigationBoxes = new Object(); | var NavigationBoxes = new Object(); | ||
var Tables = document.getElementsByTagName( "table" ); | var Tables = document.getElementsByTagName( "table" ); | ||
for ( var i = 0; i < Tables.length; i++ ) { | for ( var i = 0; i < Tables.length; i++ ) { | ||
if ( hasClass( Tables[i], "collapsible" ) ) { | if ( hasClass( Tables[i], "collapsible" ) ) { | ||
/* only add button and increment count if there is a header row to work with */ | /* only add button and increment count if there is a header row to work with */ | ||
var HeaderRow = Tables[i].getElementsByTagName( "tr" )[0]; | var HeaderRow = Tables[i].getElementsByTagName( "tr" )[0]; | ||
| 81번째 줄: | 79번째 줄: | ||
var Header = HeaderRow.getElementsByTagName( "th" )[0]; | var Header = HeaderRow.getElementsByTagName( "th" )[0]; | ||
if (!Header) continue; | if (!Header) continue; | ||
NavigationBoxes[ tableIndex ] = Tables[i]; | NavigationBoxes[ tableIndex ] = Tables[i]; | ||
Tables[i].setAttribute( "id", "collapsibleTable" + tableIndex ); | Tables[i].setAttribute( "id", "collapsibleTable" + tableIndex ); | ||
var Button = document.createElement( "span" ); | var Button = document.createElement( "span" ); | ||
var ButtonLink = document.createElement( "a" ); | var ButtonLink = document.createElement( "a" ); | ||
var ButtonText = document.createTextNode( collapseCaption ); | var ButtonText = document.createTextNode( collapseCaption ); | ||
Button.className = "collapseButton"; //Styles are declared in Common.css | Button.className = "collapseButton"; //Styles are declared in Common.css | ||
ButtonLink.style.color = Header.style.color; | ButtonLink.style.color = Header.style.color; | ||
ButtonLink.setAttribute( "id", "collapseButton" + tableIndex ); | ButtonLink.setAttribute( "id", "collapseButton" + tableIndex ); | ||
ButtonLink.setAttribute( "href", " | ButtonLink.setAttribute( "href", "#" ); | ||
addHandler( ButtonLink, "click", new Function( "evt", "collapseTable(" + tableIndex + " ); return killEvt( evt );") ); | |||
ButtonLink.appendChild( ButtonText ); | ButtonLink.appendChild( ButtonText ); | ||
Button.appendChild( document.createTextNode( "[" ) ); | Button.appendChild( document.createTextNode( "[" ) ); | ||
Button.appendChild( ButtonLink ); | Button.appendChild( ButtonLink ); | ||
Button.appendChild( document.createTextNode( "]" ) ); | Button.appendChild( document.createTextNode( "]" ) ); | ||
Header.insertBefore( Button, Header. | Header.insertBefore( Button, Header.firstChild ); | ||
tableIndex++; | tableIndex++; | ||
} | } | ||
} | } | ||
for ( var i = 0; i < tableIndex; i++ ) { | for ( var i = 0; i < tableIndex; i++ ) { | ||
if ( hasClass( NavigationBoxes[i], "collapsed" ) || ( tableIndex >= autoCollapse && hasClass( NavigationBoxes[i], "autocollapse" ) ) ) { | if ( hasClass( NavigationBoxes[i], "collapsed" ) || ( tableIndex >= autoCollapse && hasClass( NavigationBoxes[i], "autocollapse" ) ) ) { | ||
| 120번째 줄: | 119번째 줄: | ||
} | } | ||
} | } | ||
$( createCollapseButtons ); | |||
/* ([[위키백과:관리자 요청/2007년 5월#스크립트 추가 요청]]) */ | /* ([[위키백과:관리자 요청/2007년 5월#스크립트 추가 요청]]) */ | ||
/** Dynamic Navigation Bars (experimental) ************************************* | /** Dynamic Navigation Bars (experimental) ************************************* | ||
* | * | ||
* Description: See [[ | * Description: See [[Wikipedia:NavFrame]]. | ||
* Maintainers: UNMAINTAINED | * Maintainers: UNMAINTAINED | ||
*/ | */ | ||
// set up the words in your language | // set up the words in your language | ||
var NavigationBarHide = '[' + collapseCaption + ']'; | var NavigationBarHide = '[' + collapseCaption + ']'; | ||
var NavigationBarShow = '[' + expandCaption + ']'; | var NavigationBarShow = '[' + expandCaption + ']'; | ||
// shows and hides content and picture (if available) of navigation bars | // shows and hides content and picture (if available) of navigation bars | ||
// Parameters: | // Parameters: | ||
// indexNavigationBar: the index of navigation bar to be toggled | // indexNavigationBar: the index of navigation bar to be toggled | ||
function | window.toggleNavigationBar = function(indexNavigationBar){ | ||
{ | |||
var NavToggle = document.getElementById("NavToggle" + indexNavigationBar); | var NavToggle = document.getElementById("NavToggle" + indexNavigationBar); | ||
var NavFrame = document.getElementById("NavFrame" + indexNavigationBar); | var NavFrame = document.getElementById("NavFrame" + indexNavigationBar); | ||
if (!NavFrame || !NavToggle) { | if (!NavFrame || !NavToggle) { | ||
return false; | return false; | ||
} | } | ||
// if shown now | // if shown now | ||
if (NavToggle.firstChild.data == NavigationBarHide) { | if (NavToggle.firstChild.data == NavigationBarHide) { | ||
| 154번째 줄: | 153번째 줄: | ||
} | } | ||
NavToggle.firstChild.data = NavigationBarShow; | NavToggle.firstChild.data = NavigationBarShow; | ||
// if hidden now | // if hidden now | ||
} else if (NavToggle.firstChild.data == NavigationBarShow) { | } else if (NavToggle.firstChild.data == NavigationBarShow) { | ||
| 165번째 줄: | 164번째 줄: | ||
} | } | ||
} | } | ||
// adds show/hide-button to navigation bars | // adds show/hide-button to navigation bars | ||
function createNavigationBarToggleButton() | function createNavigationBarToggleButton(){ | ||
{ | |||
var indexNavigationBar = 0; | var indexNavigationBar = 0; | ||
// iterate over all < div >-elements | // iterate over all < div >-elements | ||
| 175번째 줄: | 173번째 줄: | ||
// if found a navigation bar | // if found a navigation bar | ||
if (hasClass(NavFrame, "NavFrame")) { | if (hasClass(NavFrame, "NavFrame")) { | ||
indexNavigationBar++; | indexNavigationBar++; | ||
var NavToggle = document.createElement("a"); | var NavToggle = document.createElement("a"); | ||
| 181번째 줄: | 179번째 줄: | ||
NavToggle.setAttribute('id', 'NavToggle' + indexNavigationBar); | NavToggle.setAttribute('id', 'NavToggle' + indexNavigationBar); | ||
NavToggle.setAttribute('href', 'javascript:toggleNavigationBar(' + indexNavigationBar + ');'); | NavToggle.setAttribute('href', 'javascript:toggleNavigationBar(' + indexNavigationBar + ');'); | ||
var isCollapsed = hasClass( NavFrame, "collapsed" ); | var isCollapsed = hasClass( NavFrame, "collapsed" ); | ||
/* | /* | ||
| 206번째 줄: | 204번째 줄: | ||
var NavToggleText = document.createTextNode(isCollapsed ? NavigationBarShow : NavigationBarHide); | var NavToggleText = document.createTextNode(isCollapsed ? NavigationBarShow : NavigationBarHide); | ||
NavToggle.appendChild(NavToggleText); | NavToggle.appendChild(NavToggleText); | ||
// Find the NavHead and attach the toggle link (Must be this complicated because Moz's firstChild handling is borked) | // Find the NavHead and attach the toggle link (Must be this complicated because Moz's firstChild handling is borked) | ||
for(var j=0; j < NavFrame.childNodes.length; j++) { | for(var j=0; j < NavFrame.childNodes.length; j++) { | ||
if (hasClass(NavFrame.childNodes[j], "NavHead")) { | if (hasClass(NavFrame.childNodes[j], "NavHead")) { | ||
NavToggle.style.color = NavFrame.childNodes[j].style.color; | |||
NavFrame.childNodes[j].appendChild(NavToggle); | NavFrame.childNodes[j].appendChild(NavToggle); | ||
} | } | ||
| 217번째 줄: | 216번째 줄: | ||
} | } | ||
} | } | ||
$( createNavigationBarToggleButton ); | |||