Merge pull request #123 from tophf/editor-fixes

Editor: fixes
This commit is contained in:
Jason Barnabe 2015-06-09 21:27:54 -05:00
commit 761b5bd7d9
2 changed files with 37 additions and 11 deletions

31
edit.js
View File

@ -3,7 +3,7 @@
var styleId = null;
var dirty = {}; // only the actually dirty items here
var editors = []; // array of all CodeMirror instances
var isSeparateWindow; // used currrently to determine if the window size/pos should be remembered
var saveSizeOnClose;
// direct & reverse mapping of @-moz-document keywords and internal property names
var propertyToCss = {urls: "url", urlPrefixes: "url-prefix", domains: "domain", regexps: "regexp"};
@ -404,13 +404,26 @@ document.addEventListener("wheel", function(event) {
}
});
chrome.tabs.query({currentWindow: true}, function(tabs) {
isSeparateWindow = tabs.length == 1;
});
if (prefs.getPref("openEditInWindow")) {
chrome.tabs.query({currentWindow: true}, function(tabs) {
var windowId = tabs[0].windowId;
if (tabs.length == 1 && window.history.length == 1) {
sessionStorageHash("saveSizeOnClose").set(windowId, true);
saveSizeOnClose = true;
} else {
saveSizeOnClose = sessionStorageHash("saveSizeOnClose").value[windowId];
}
chrome.tabs.onRemoved.addListener(function(tabId, info) {
if (info.windowId == windowId && info.isWindowClosing) {
sessionStorageHash("saveSizeOnClose").unset(windowId);
}
});
});
}
window.onbeforeunload = function() {
if (isSeparateWindow) {
prefs.setPref('windowPosition', {
if (saveSizeOnClose) {
prefs.setPref("windowPosition", {
left: screenLeft,
top: screenTop,
width: outerWidth,
@ -928,11 +941,9 @@ function saveComplete(style) {
// Go from new style URL to edit style URL
if (location.href.indexOf("id=") == -1) {
// give the code above a moment before we kill the page
setTimeout(function() {location.href = "edit.html?id=" + style.id;}, 200);
} else {
updateTitle();
history.replaceState({}, document.title, "edit.html?id=" + style.id);
}
updateTitle();
}
function showMozillaFormat() {

View File

@ -161,6 +161,7 @@ var prefs = {
// defaults
"openEditInWindow": false, // new editor opens in a own browser window
"windowPosition": {}, // detached window position
"show-badge": true, // display text on popup menu icon
"disableAll": false, // boss key
@ -242,3 +243,17 @@ function getCodeMirrorThemes(callback) {
});
});
}
function sessionStorageHash(name) {
var hash = {
value: {},
set: function(k, v) { this.value[k] = v; this.updateStorage(); },
unset: function(k) { delete this.value[k]; this.updateStorage(); },
updateStorage: function() {
sessionStorage[this.name] = JSON.stringify(this.value);
}
};
try { hash.value = JSON.parse(sessionStorage[name]); } catch(e) {}
Object.defineProperty(hash, "name", {value: name});
return hash;
}