MediaWiki:Common.js: Difference between revisions
collapsible elements Tag: Reverted |
fix maybe |
||
(One intermediate revision by the same user not shown) | |||
Line 4: | Line 4: | ||
// I wasn't totally satisfied with MediaWiki's built-in way to make collapsible elements, so here is an alternative implementation I made. | // I wasn't totally satisfied with MediaWiki's built-in way to make collapsible elements, so here is an alternative implementation I made. | ||
function customcollapseShow(jQueryObj) { | function customcollapseShow(jQueryObj) { | ||
var container = $(jQueryObj).parents(".customcollapse"); | |||
container.find(".customcollapse-content").show(); | container.find(".customcollapse-content").show(); | ||
container.find(".customcollapse-show").hide().removeAttr("aria-expanded"); | container.find(".customcollapse-show").hide().removeAttr("aria-expanded"); | ||
Line 15: | Line 15: | ||
function customcollapseHide(jQueryObj) { | function customcollapseHide(jQueryObj) { | ||
var container = $(jQueryObj).parents(".customcollapse"); | |||
container.find(".customcollapse-content").hide(); | container.find(".customcollapse-content").hide(); | ||
container.find(".customcollapse-hide").hide().removeAttr("aria-expanded"); | container.find(".customcollapse-hide").hide().removeAttr("aria-expanded"); | ||
Line 46: | Line 46: | ||
// For toggles, changing the element to a <button>. This necessitates removing the element and adding it back again | // For toggles, changing the element to a <button>. This necessitates removing the element and adding it back again | ||
$(this).addClass("plainbutton"); | $(this).addClass("plainbutton"); | ||
var innerHtml = this.innerHTML; | |||
var attributes = this.attributes; | |||
var btn = document.createElement("button"); | |||
btn.innerHTML = innerHtml; | btn.innerHTML = innerHtml; | ||
for ( | for (var i = 0; i < attributes.length; i++) { | ||
btn.attributes.setNamedItem( | btn.attributes.setNamedItem(attributes[i].cloneNode()); | ||
} | } | ||
$(this).replaceWith(btn); | $(this).replaceWith(btn); |