Editor: remember size/pos only for detached windows

This commit is contained in:
tophf 2015-03-14 01:26:26 +03:00
parent 0e391f928f
commit 374244fceb

21
edit.js
View File

@ -3,6 +3,7 @@
var styleId = null; var styleId = null;
var dirty = false; var dirty = false;
var lockScroll; // ensure the section doesn't jump when clicking selected text var lockScroll; // ensure the section doesn't jump when clicking selected text
var isSeparateWindow;
var appliesToTemplate = document.createElement("li"); var appliesToTemplate = document.createElement("li");
appliesToTemplate.innerHTML = '<select name="applies-type" class="applies-type"><option value="url">' + t("appliesUrlOption") + '</option><option value="url-prefix">' + t("appliesUrlPrefixOption") + '</option><option value="domain">' + t("appliesDomainOption") + '</option><option value="regexp">' + t("appliesRegexpOption") + '</option></select><input name="applies-value" class="applies-value"><button class="remove-applies-to">' + t("appliesRemove") + '</button><button class="add-applies-to">' + t("appliesAdd") + '</button>'; appliesToTemplate.innerHTML = '<select name="applies-type" class="applies-type"><option value="url">' + t("appliesUrlOption") + '</option><option value="url-prefix">' + t("appliesUrlPrefixOption") + '</option><option value="domain">' + t("appliesDomainOption") + '</option><option value="regexp">' + t("appliesRegexpOption") + '</option></select><input name="applies-value" class="applies-value"><button class="remove-applies-to">' + t("appliesRemove") + '</button><button class="add-applies-to">' + t("appliesAdd") + '</button>';
@ -218,13 +219,19 @@ document.addEventListener("keydown", function(e) {
} }
}); });
chrome.tabs.query({currentWindow: true}, function(tabs) {
isSeparateWindow = tabs.length == 1;
});
window.onbeforeunload = function() { window.onbeforeunload = function() {
prefs.setPref('windowPosition', { if (isSeparateWindow) {
left: screenLeft, prefs.setPref('windowPosition', {
top: screenTop, left: screenLeft,
width: outerWidth, top: screenTop,
height: outerHeight width: outerWidth,
}); height: outerHeight
});
}
document.activeElement.blur(); document.activeElement.blur();
return !isCleanGlobal() ? t('styleChangesNotSaved') : null; return !isCleanGlobal() ? t('styleChangesNotSaved') : null;
} }
@ -308,7 +315,7 @@ function addSection(event, section) {
setupCodeMirror(div.querySelector('.code')); setupCodeMirror(div.querySelector('.code'));
if (section) { if (section) {
var index = Array.prototype.indexOf.call(sections.children, section); var index = Array.prototype.indexOf.call(sections.children, section);
var cm = editors.pop(); var cm = editors.pop();
editors.splice(index, 0, cm); editors.splice(index, 0, cm);
cm.focus(); cm.focus();
} }