diff --git a/chrome/content/zotero/zoteroPane.js b/chrome/content/zotero/zoteroPane.js index 876f459fa..904e67c8e 100644 --- a/chrome/content/zotero/zoteroPane.js +++ b/chrome/content/zotero/zoteroPane.js @@ -89,6 +89,7 @@ var ZoteroPane = new function() var self = this; var _loaded = false; + var _onVisibleHandlers = []; var titlebarcolorState, titleState; // Also needs to be changed in collectionTreeView.js @@ -114,6 +115,7 @@ var ZoteroPane = new function() } _loaded = true; + ZoteroPane.restoreSavedState(); Zotero.setFontSize(document.getElementById('zotero-pane')) if (Zotero.isMac) { @@ -311,6 +313,8 @@ var ZoteroPane = new function() return; } + this.saveCurrentState(); + var tagSelector = document.getElementById('zotero-tag-selector'); tagSelector.unregister(); @@ -335,7 +339,7 @@ var ZoteroPane = new function() ps.alert(null, "", msg); return false; } - ZoteroPane.onLoad(); + ZoteroPane.init(); } // If Zotero could not be initialized, display an error message and return @@ -405,6 +409,8 @@ var ZoteroPane = new function() } } + for each(var handler in _onVisibleHandlers) handler(); + return true; } @@ -3414,4 +3420,49 @@ var ZoteroPane = new function() } } + /** + * Saves all attributes labeled as zotero-persist + */ + this.restoreSavedState = function() { + // load all z-persist attributes + var savedData = Zotero.Prefs.get("overlay.persist"); + if(savedData != "") { + savedData = JSON.parse(savedData); + for(var id in savedData) { + var el = document.getElementById(id); + if(el) { + var savedDataEl = savedData[id]; + for(var attr in savedDataEl) { + Zotero.debug(attr+" = "+savedDataEl[attr]); + try { + el.setAttribute(attr, savedDataEl[attr]); + } catch(e) {} + } + } + } + } + } + + /** + * Restores all attributes labeled as zotero-persist + */ + this.saveCurrentState = function() { + var data = {}; + + var zPersists = document.evaluate('//*[@zotero-persist]', document.getElementById('zotero-pane'), null, + XPathResult.ANY_TYPE, null); + var el; + while(el = zPersists.iterateNext()) { + var id = el.getAttribute('id'); + if(id) { + data[id] = {}; + + for each(var attr in el.getAttribute("zotero-persist").split(/[\s,]/)) { + data[id][attr] = el.getAttribute(attr); + } + } + } + + Zotero.Prefs.set("overlay.persist", JSON.stringify(data)); + } } \ No newline at end of file