Remember position of edit window #7

This commit is contained in:
Jason Barnabe 2015-01-30 12:35:37 -06:00
parent e5d50b02e7
commit 01329b7835
2 changed files with 23 additions and 2 deletions

View File

@ -297,3 +297,16 @@ function saveFromJSONStyleReloaded(updateType, style, callback) {
// Get the DB so that any first run actions will be performed immediately when the background page loads.
getDatabase(function() {}, reportError);
// When an edit page gets attached or detached, remember its state so we can do the same to the next one to open.
var editFullUrl = chrome.extension.getURL("edit.html");
chrome.tabs.onAttached.addListener(function(tabId, data) {
chrome.tabs.get(tabId, function(tabData) {
if (tabData.url.indexOf(editFullUrl) == 0) {
chrome.windows.get(tabData.windowId, {populate: true}, function(win) {
// If there's only one tab in this window, it's been dragged to new window
localStorage['openEditInWindow'] = win.tabs.length == 1 ? "true" : "false";
});
}
});
});

View File

@ -46,7 +46,7 @@ chrome.tabs.getSelected(null, function(tab) {
if (index > 0) {
writeStyle.appendChild(document.createTextNode(" "));
}
link.addEventListener("click", openLink, false);
link.addEventListener("click", openLinkInTabOrWindow, false);
writeStyle.appendChild(link);
});
});
@ -117,10 +117,18 @@ function getId(event) {
return null;
}
function openLinkInTabOrWindow(event) {
event.preventDefault();
if (localStorage['openEditInWindow'] == 'true') {
chrome.windows.create({url: event.target.href});
} else {
chrome.tabs.create({url: event.target.href});
}
}
function openLink(event) {
event.preventDefault();
chrome.tabs.create({url: event.target.href});
//return false;
}
function handleUpdate(style) {