Use MutationObserver instead of DOMAttrModified
This commit is contained in:
parent
78259db2f0
commit
99411eab63
@ -584,46 +584,60 @@ TreeStyleTabWindowHelper.overrideExtensionsDelayed = function TSTWH_overrideExte
|
|||||||
TreeStyleTabUtils.getTreePref('compatibility.PersonalTitlebar')) {
|
TreeStyleTabUtils.getTreePref('compatibility.PersonalTitlebar')) {
|
||||||
let titlebar = document.getElementById('titlebar');
|
let titlebar = document.getElementById('titlebar');
|
||||||
let personalTitlebar = document.getElementById('personal-titlebar');
|
let personalTitlebar = document.getElementById('personal-titlebar');
|
||||||
|
let MutationObserver = window.MutationObserver || window.MozMutationObserver;
|
||||||
let listener = {
|
let listener = {
|
||||||
handleEvent : function(aEvent)
|
handleEvent : function(aEvent)
|
||||||
{
|
{
|
||||||
switch (aEvent.type)
|
switch (aEvent.type)
|
||||||
{
|
{
|
||||||
case 'beforecustomization':
|
case 'beforecustomization':
|
||||||
titlebar.removeEventListener('DOMAttrModified', this, true);
|
this.handleMutation = false;
|
||||||
gBrowser.treeStyleTab.destroyTabStrip(personalTitlebar);
|
gBrowser.treeStyleTab.destroyTabStrip(personalTitlebar);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'aftercustomization':
|
case 'aftercustomization':
|
||||||
titlebar.addEventListener('DOMAttrModified', this, true);
|
this.handleMutation = true;
|
||||||
break;
|
|
||||||
|
|
||||||
case 'DOMAttrModified':
|
|
||||||
if (
|
|
||||||
aEvent.attrName == 'hidden' &&
|
|
||||||
gBrowser.tabContainer.parentNode.id == (aEvent.newValue == 'true' ? 'toolbar-menubar' : 'personal-titlebar' )
|
|
||||||
) {
|
|
||||||
gBrowser.treeStyleTab.destroyTabbar()
|
|
||||||
.then(function() {
|
|
||||||
gBrowser.treeStyleTab.reinitTabbar();
|
|
||||||
});
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'unload':
|
case 'unload':
|
||||||
titlebar.removeEventListener('DOMAttrModified', this, true);
|
observer.disconnect();
|
||||||
|
observer = null;
|
||||||
document.removeEventListener('beforecustomization', this, false);
|
document.removeEventListener('beforecustomization', this, false);
|
||||||
document.removeEventListener('aftercustomization', this, false);
|
document.removeEventListener('aftercustomization', this, false);
|
||||||
document.removeEventListener('unload', this, false);
|
document.removeEventListener('unload', this, false);
|
||||||
personalTitlebar = null;
|
personalTitlebar = null;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
handleMutation : true,
|
||||||
|
onMutation : function(aMutations, aObserver)
|
||||||
|
{
|
||||||
|
if (!this.handleMutation)
|
||||||
|
return;
|
||||||
|
|
||||||
|
aMutations.forEach(function(aMutation) {
|
||||||
|
var newValue = aMutation.target.getAttribute('hidden');
|
||||||
|
var expectedParent = newValue == 'true' ? 'toolbar-menubar' : 'personal-titlebar' ;
|
||||||
|
if (gBrowser.tabContainer.parentNode.id == expectedParent)
|
||||||
|
gBrowser.treeStyleTab.destroyTabbar()
|
||||||
|
.then(function() {
|
||||||
|
gBrowser.treeStyleTab.reinitTabbar();
|
||||||
|
});
|
||||||
|
}, this);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
let observer = new MutationObserver((function(aMutations, aObserver) {
|
||||||
|
listener.onMutation(aMutations, aObserver);
|
||||||
|
}).bind(this));
|
||||||
|
observer.observe(titlebar, {
|
||||||
|
attributes : true,
|
||||||
|
attributeFilter : [
|
||||||
|
'hidden'
|
||||||
|
]
|
||||||
|
});
|
||||||
document.addEventListener('beforecustomization', listener, false);
|
document.addEventListener('beforecustomization', listener, false);
|
||||||
document.addEventListener('aftercustomization', listener, false);
|
document.addEventListener('aftercustomization', listener, false);
|
||||||
document.addEventListener('unload', listener, false);
|
document.addEventListener('unload', listener, false);
|
||||||
titlebar.addEventListener('DOMAttrModified', listener, true);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Tab Control
|
// Tab Control
|
||||||
|
Loading…
Reference in New Issue
Block a user