Browse Source

this fixes #49

pull/2/head
gorhill 10 years ago
parent
commit
5d90401f54
  1. 6
      src/js/popup.js
  2. 42
      src/js/udom.js

6
src/js/popup.js

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

42
src/js/udom.js

@ -570,8 +570,11 @@ DOMList.prototype.text = function(text) {
/******************************************************************************/ /******************************************************************************/
var toggleClass = function(node, className, targetState) { 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; var newState = targetState;
if ( newState === undefined ) { if ( newState === undefined ) {
newState = !currentState; newState = !currentState;
@ -579,24 +582,20 @@ var toggleClass = function(node, className, targetState) {
if ( newState === currentState ) { if ( newState === currentState ) {
return; 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 ) { if ( !this.nodes.length ) {
return false; 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) { DOMList.prototype.addClass = function(className) {
return this.toggleClass(className, true); return this.toggleClass(className, true);
@ -616,14 +615,27 @@ DOMList.prototype.removeClass = function(className) {
/******************************************************************************/ /******************************************************************************/
DOMList.prototype.toggleClass = function(className, targetState) { 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 i = this.nodes.length;
var node, j; var node, j;
while ( i-- ) { while ( i-- ) {
node = this.nodes[i]; node = this.nodes[i];
j = classNames.length;
j = tokens.length;
while ( j-- ) { while ( j-- ) {
toggleClass(node, classNames[j], targetState);
toggleClass(node, tokens[j], targetState);
} }
} }
return this; return this;

Loading…
Cancel
Save