Merge pull request #124 from tophf/manage-scroll-save
Manage: remember scroll position, initialize styles earlier
This commit is contained in:
commit
c61b715e2f
21
edit.js
21
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,38 @@ 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) {
|
||||||
|
chrome.windows.getAll(function(windows) {
|
||||||
|
if (windows.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) {
|
chrome.tabs.onRemoved.addListener(function(tabId, info) {
|
||||||
|
sessionStorageHash("manageStylesHistory").unset(tabId);
|
||||||
if (info.windowId == windowId && info.isWindowClosing) {
|
if (info.windowId == windowId && info.isWindowClosing) {
|
||||||
sessionStorageHash("saveSizeOnClose").unset(windowId);
|
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 +809,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();
|
||||||
|
|
|
@ -134,6 +134,7 @@
|
||||||
<script src="storage.js"></script>
|
<script src="storage.js"></script>
|
||||||
<script src="messaging.js"></script>
|
<script src="messaging.js"></script>
|
||||||
<script src="apply.js"></script>
|
<script src="apply.js"></script>
|
||||||
|
<script src="manage.js"></script>
|
||||||
</head>
|
</head>
|
||||||
<body id="stylish-manage">
|
<body id="stylish-manage">
|
||||||
<div id="header">
|
<div id="header">
|
||||||
|
@ -158,7 +159,5 @@
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div id="installed"></div>
|
<div id="installed"></div>
|
||||||
|
|
||||||
<script src="manage.js"></script>
|
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|
53
manage.js
53
manage.js
|
@ -15,28 +15,32 @@ var styleTemplate = tHTML('\
|
||||||
');
|
');
|
||||||
|
|
||||||
var lastUpdatedStyleId = null;
|
var lastUpdatedStyleId = null;
|
||||||
var installed = document.getElementById("installed");
|
var installed;
|
||||||
|
|
||||||
var appliesToExtraTemplate = document.createElement("span");
|
var appliesToExtraTemplate = document.createElement("span");
|
||||||
appliesToExtraTemplate.className = "applies-to-extra";
|
appliesToExtraTemplate.className = "applies-to-extra";
|
||||||
appliesToExtraTemplate.innerHTML = " " + t('appliesDisplayTruncatedSuffix');
|
appliesToExtraTemplate.innerHTML = " " + t('appliesDisplayTruncatedSuffix');
|
||||||
|
|
||||||
chrome.extension.sendMessage({method: "getStyles"}, showStyles);
|
chrome.extension.sendMessage({method: "getStyles"}, showStyles);
|
||||||
loadPrefs({
|
|
||||||
"manage.onlyEnabled": false,
|
|
||||||
"manage.onlyEdited": false,
|
|
||||||
"show-badge": true
|
|
||||||
});
|
|
||||||
|
|
||||||
function showStyles(styles) {
|
function showStyles(styles) {
|
||||||
if (!styles) { // Chrome is starting up
|
if (!styles) { // Chrome is starting up
|
||||||
chrome.extension.sendMessage({method: "getStyles"}, showStyles);
|
chrome.extension.sendMessage({method: "getStyles"}, showStyles);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
if (!installed) {
|
||||||
|
// "getStyles" message callback is invoked before document is loaded,
|
||||||
|
// postpone the action until DOMContentLoaded is fired
|
||||||
|
document.stylishStyles = styles;
|
||||||
|
return;
|
||||||
|
}
|
||||||
styles.sort(function(a, b) { return a.name.localeCompare(b.name)});
|
styles.sort(function(a, b) { return a.name.localeCompare(b.name)});
|
||||||
styles.map(createStyleElement).forEach(function(e) {
|
styles.map(createStyleElement).forEach(function(e) {
|
||||||
installed.appendChild(e);
|
installed.appendChild(e);
|
||||||
});
|
});
|
||||||
|
if (history.state) {
|
||||||
|
window.scrollTo(0, history.state.scrollY);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function createStyleElement(style) {
|
function createStyleElement(style) {
|
||||||
|
@ -117,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);
|
||||||
if (openWindow || openBackgroundTab || openForegroundTab) {
|
var url = event.target.href || event.target.parentNode.href;
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
event.stopPropagation();
|
event.stopPropagation();
|
||||||
var url = event.target.href || event.target.parentNode.href;
|
if (openWindow || openBackgroundTab || openForegroundTab) {
|
||||||
if (openWindow) {
|
if (openWindow) {
|
||||||
var options = prefs.getPref('windowPosition', {});
|
var options = prefs.getPref('windowPosition', {});
|
||||||
options.url = url;
|
options.url = url;
|
||||||
|
@ -132,6 +136,12 @@ function createStyleElement(style) {
|
||||||
active: openForegroundTab
|
active: openForegroundTab
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
history.replaceState({scrollY: window.scrollY}, document.title);
|
||||||
|
getActiveTab(function(tab) {
|
||||||
|
sessionStorageHash("manageStylesHistory").set(tab.id, url);
|
||||||
|
location.href = url;
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -468,11 +478,6 @@ function searchStyles(immediately) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
document.getElementById("check-all-updates").addEventListener("click", checkUpdateAll, false);
|
|
||||||
document.getElementById("apply-all-updates").addEventListener("click", applyUpdateAll, false);
|
|
||||||
document.getElementById("search").addEventListener("input", searchStyles);
|
|
||||||
searchStyles(true); // re-apply filtering on history Back
|
|
||||||
|
|
||||||
function onFilterChange (className, event) {
|
function onFilterChange (className, event) {
|
||||||
installed.classList.toggle(className, event.target.checked);
|
installed.classList.toggle(className, event.target.checked);
|
||||||
}
|
}
|
||||||
|
@ -480,7 +485,25 @@ function initFilter(className, node) {
|
||||||
node.addEventListener("change", onFilterChange.bind(undefined, className), false);
|
node.addEventListener("change", onFilterChange.bind(undefined, className), false);
|
||||||
onFilterChange(className, {target: node});
|
onFilterChange(className, {target: node});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
document.addEventListener("DOMContentLoaded", function() {
|
||||||
|
installed = document.getElementById("installed");
|
||||||
|
if (document.stylishStyles) {
|
||||||
|
showStyles(document.stylishStyles);
|
||||||
|
delete document.stylishStyles;
|
||||||
|
}
|
||||||
|
|
||||||
|
document.getElementById("check-all-updates").addEventListener("click", checkUpdateAll);
|
||||||
|
document.getElementById("apply-all-updates").addEventListener("click", applyUpdateAll);
|
||||||
|
document.getElementById("search").addEventListener("input", searchStyles);
|
||||||
|
searchStyles(true); // re-apply filtering on history Back
|
||||||
|
|
||||||
|
loadPrefs({
|
||||||
|
"manage.onlyEnabled": false,
|
||||||
|
"manage.onlyEdited": false,
|
||||||
|
"show-badge": true,
|
||||||
|
"popup.stylesFirst": true
|
||||||
|
});
|
||||||
initFilter("enabled-only", document.getElementById("manage.onlyEnabled"));
|
initFilter("enabled-only", document.getElementById("manage.onlyEnabled"));
|
||||||
initFilter("edited-only", document.getElementById("manage.onlyEdited"));
|
initFilter("edited-only", document.getElementById("manage.onlyEdited"));
|
||||||
|
});
|
||||||
loadPrefs({"popup.stylesFirst": true});
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user