Editor: use history back for Back-To-Manage when appropriate
This commit is contained in:
parent
9cfa214d19
commit
67fe43e9a9
31
edit.js
31
edit.js
|
@ -4,6 +4,7 @@ var styleId = null;
|
||||||
var dirty = {}; // only the actually dirty items here
|
var dirty = {}; // only the actually dirty items here
|
||||||
var editors = []; // array of all CodeMirror instances
|
var editors = []; // array of all CodeMirror instances
|
||||||
var saveSizeOnClose;
|
var saveSizeOnClose;
|
||||||
|
var useHistoryBack; // use browser history back when "back to manage" is clicked
|
||||||
|
|
||||||
// direct & reverse mapping of @-moz-document keywords and internal property names
|
// direct & reverse mapping of @-moz-document keywords and internal property names
|
||||||
var propertyToCss = {urls: "url", urlPrefixes: "url-prefix", domains: "domain", regexps: "regexp"};
|
var propertyToCss = {urls: "url", urlPrefixes: "url-prefix", domains: "domain", regexps: "regexp"};
|
||||||
|
@ -404,21 +405,34 @@ document.addEventListener("wheel", function(event) {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
if (prefs.getPref("openEditInWindow")) {
|
chrome.tabs.query({currentWindow: true}, function(tabs) {
|
||||||
chrome.tabs.query({currentWindow: true}, function(tabs) {
|
var windowId = tabs[0].windowId;
|
||||||
var windowId = tabs[0].windowId;
|
if (prefs.getPref("openEditInWindow")) {
|
||||||
if (tabs.length == 1 && window.history.length == 1) {
|
if (tabs.length == 1 && window.history.length == 1) {
|
||||||
sessionStorageHash("saveSizeOnClose").set(windowId, true);
|
sessionStorageHash("saveSizeOnClose").set(windowId, true);
|
||||||
saveSizeOnClose = true;
|
saveSizeOnClose = true;
|
||||||
} else {
|
} else {
|
||||||
saveSizeOnClose = sessionStorageHash("saveSizeOnClose").value[windowId];
|
saveSizeOnClose = sessionStorageHash("saveSizeOnClose").value[windowId];
|
||||||
}
|
}
|
||||||
chrome.tabs.onRemoved.addListener(function(tabId, info) {
|
}
|
||||||
if (info.windowId == windowId && info.isWindowClosing) {
|
chrome.tabs.onRemoved.addListener(function(tabId, info) {
|
||||||
sessionStorageHash("saveSizeOnClose").unset(windowId);
|
sessionStorageHash("manageStylesHistory").unset(tabId);
|
||||||
}
|
if (info.windowId == windowId && info.isWindowClosing) {
|
||||||
});
|
sessionStorageHash("saveSizeOnClose").unset(windowId);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
getActiveTab(function(tab) {
|
||||||
|
useHistoryBack = sessionStorageHash("manageStylesHistory").value[tab.id] == location.href;
|
||||||
|
});
|
||||||
|
|
||||||
|
function goBackToManage(event) {
|
||||||
|
if (useHistoryBack) {
|
||||||
|
event.stopPropagation();
|
||||||
|
event.preventDefault();
|
||||||
|
history.back();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
window.onbeforeunload = function() {
|
window.onbeforeunload = function() {
|
||||||
|
@ -791,6 +805,7 @@ function initHooks() {
|
||||||
document.getElementById("save-button").addEventListener("click", save, false);
|
document.getElementById("save-button").addEventListener("click", save, false);
|
||||||
document.getElementById("sections-help").addEventListener("click", showSectionHelp, false);
|
document.getElementById("sections-help").addEventListener("click", showSectionHelp, false);
|
||||||
document.getElementById("keyMap-help").addEventListener("click", showKeyMapHelp, false);
|
document.getElementById("keyMap-help").addEventListener("click", showKeyMapHelp, false);
|
||||||
|
document.getElementById("cancel-button").addEventListener("click", goBackToManage);
|
||||||
|
|
||||||
setupGlobalSearch();
|
setupGlobalSearch();
|
||||||
setCleanGlobal();
|
setCleanGlobal();
|
||||||
|
|
10
manage.js
10
manage.js
|
@ -121,10 +121,10 @@ function createStyleElement(style) {
|
||||||
var openWindow = left && shift && !ctrl;
|
var openWindow = left && shift && !ctrl;
|
||||||
var openBackgroundTab = (middle && !shift) || (left && ctrl && !shift);
|
var openBackgroundTab = (middle && !shift) || (left && ctrl && !shift);
|
||||||
var openForegroundTab = (middle && shift) || (left && ctrl && shift);
|
var openForegroundTab = (middle && shift) || (left && ctrl && shift);
|
||||||
|
var url = event.target.href || event.target.parentNode.href;
|
||||||
|
event.preventDefault();
|
||||||
|
event.stopPropagation();
|
||||||
if (openWindow || openBackgroundTab || openForegroundTab) {
|
if (openWindow || openBackgroundTab || openForegroundTab) {
|
||||||
event.preventDefault();
|
|
||||||
event.stopPropagation();
|
|
||||||
var url = event.target.href || event.target.parentNode.href;
|
|
||||||
if (openWindow) {
|
if (openWindow) {
|
||||||
var options = prefs.getPref('windowPosition', {});
|
var options = prefs.getPref('windowPosition', {});
|
||||||
options.url = url;
|
options.url = url;
|
||||||
|
@ -138,6 +138,10 @@ function createStyleElement(style) {
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
history.replaceState({scrollY: window.scrollY}, document.title);
|
history.replaceState({scrollY: window.scrollY}, document.title);
|
||||||
|
getActiveTab(function(tab) {
|
||||||
|
sessionStorageHash("manageStylesHistory").set(tab.id, url);
|
||||||
|
location.href = url;
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue
Block a user