this fixes #49

pull/2/head
gorhill 10 years ago
parent 65918c5c26
commit 5d90401f54

@ -296,7 +296,7 @@ function toggleCollapseState(elem) {
function toggleMainCollapseState(uelem) {
var matHead = uelem.ancestors('#matHead.collapsible').toggleClass('collapsed');
var collapsed = matHead.hasClassName('collapsed');
var collapsed = matHead.hasClass('collapsed');
uDom('#matList .matSection.collapsible').toggleClass('collapsed', collapsed);
setUserSetting('popupCollapseDomains', collapsed);
@ -318,7 +318,7 @@ function toggleSpecificCollapseState(uelem) {
// from main collapse switch.
var section = uelem.ancestors('.matSection.collapsible').toggleClass('collapsed');
var domain = section.prop('domain');
var collapsed = section.hasClassName('collapsed');
var collapsed = section.hasClass('collapsed');
var mainCollapseState = getUserSetting('popupCollapseDomains');
var specificCollapseStates = getUserSetting('popupCollapseSpecificDomains') || {};
if ( collapsed !== mainCollapseState ) {
@ -1232,7 +1232,7 @@ uDom.onLoad(function() {
uDom('#matList').on('click', '.g4Meta', function() {
var collapsed = uDom(this)
.toggleClass('g4Collapsed')
.hasClassName('g4Collapsed');
.hasClass('g4Collapsed');
setUserSetting('popupHideBlacklisted', collapsed);
});
});

@ -570,8 +570,11 @@ DOMList.prototype.text = function(text) {
/******************************************************************************/
var toggleClass = function(node, className, targetState) {
var re = new RegExp('(^| )' + className + '( |$)');
var currentState = re.test(node.className);
var tokenList = node.classList;
if ( tokenList instanceof DOMTokenList === false ) {
return;
}
var currentState = tokenList.contains(className);
var newState = targetState;
if ( newState === undefined ) {
newState = !currentState;
@ -579,24 +582,20 @@ var toggleClass = function(node, className, targetState) {
if ( newState === currentState ) {
return;
}
var newClassName = node.className;
if ( newState ) {
newClassName += ' ' + className;
} else {
newClassName = newClassName.replace(re, ' ');
}
node.className = newClassName.trim();
tokenList.toggle(className, newState)
};
/******************************************************************************/
DOMList.prototype.hasClassName = function(className) {
DOMList.prototype.hasClass = function(className) {
if ( !this.nodes.length ) {
return false;
}
var re = new RegExp('(^| )' + className + '( |$)');
return re.test(this.nodes[0].className);
var tokenList = this.nodes[0].classList;
return tokenList instanceof DOMTokenList &&
tokenList.contains(className);
};
DOMList.prototype.hasClassName = DOMList.prototype.hasClass;
DOMList.prototype.addClass = function(className) {
return this.toggleClass(className, true);
@ -616,14 +615,27 @@ DOMList.prototype.removeClass = function(className) {
/******************************************************************************/
DOMList.prototype.toggleClass = function(className, targetState) {
var classNames = className.split(/\s+/);
if ( className.indexOf(' ') !== -1 ) {
return this.toggleClasses(className, true);
}
var i = this.nodes.length;
while ( i-- ) {
toggleClass(this.nodes[i], className, targetState);
}
return this;
};
/******************************************************************************/
DOMList.prototype.toggleClasses = function(classNames, targetState) {
var tokens = classNames.split(/\s+/);
var i = this.nodes.length;
var node, j;
while ( i-- ) {
node = this.nodes[i];
j = classNames.length;
j = tokens.length;
while ( j-- ) {
toggleClass(node, classNames[j], targetState);
toggleClass(node, tokens[j], targetState);
}
}
return this;

Loading…
Cancel
Save