for #11 and #12: Show/Hide container UI & implementation (#24)

* Adding in hide/show API for containers
* fix #12: [un]hide icons in the pop-up UI
This commit is contained in:
luke crouch 2016-12-29 08:37:49 -06:00 committed by Jonathan Kingston
parent 38a4eb68ec
commit 3c06f76ab3
7 changed files with 1455 additions and 10 deletions

View file

@ -1,4 +1,8 @@
module.exports = {
"extends": "nightmare-mode",
"installedESLint": true
"installedESLint": true,
"rules": {
// Consider moving to this as is FF default
// "quotes": ["error", "double"]
}
};

1
.gitignore vendored
View file

@ -2,3 +2,4 @@
node_modules
README.html
*.xpi
*.swp

File diff suppressed because it is too large Load diff

View file

@ -25,8 +25,34 @@
"parameters": [
{
"type": "string",
"name": "cookieStoreId",
"description": "The ID of the contextual identity cookie store. "
"name": "cookiestoreid",
"description": "the id of the contextual identity cookie store. "
}
]
},
{
"name": "hide",
"type": "function",
"description": "hides all of a contextual identity.",
"async": true,
"parameters": [
{
"type": "string",
"name": "cookiestoreid",
"description": "the id of the contextual identity cookie store. "
}
]
},
{
"name": "show",
"type": "function",
"description": "unhides all of a contextual identity.",
"async": true,
"parameters": [
{
"type": "string",
"name": "cookiestoreid",
"description": "the id of the contextual identity cookie store. "
}
]
},

View file

@ -39,6 +39,12 @@ table.unstriped tbody tr {
height: 32px;
}
.hideorshow-icon {
max-width: 16px;
height: 16px;
margin: 4px;
}
.edit-identities {
background: #DCDBDC;
}

View file

@ -1,21 +1,69 @@
/* global browser, window, document */
const identityState = {
};
function hideContainer(containerId) {
const hideorshowIcon = document.querySelector(`#${containerId}-hideorshow-icon`);
hideorshowIcon.src = '/img/container-unhide.svg';
browser.contextualIdentities.hide(containerId);
}
function showContainer(containerId) {
const hideorshowIcon = document.querySelector(`#${containerId}-hideorshow-icon`);
hideorshowIcon.src = '/img/container-hide.svg';
browser.contextualIdentities.show(containerId);
}
browser.contextualIdentities.query({}).then(identites=> {
let customContainerStyles = '';
const identitiesListElement = document.querySelector('.identities-list');
identites.forEach(identity=> {
const identityRow = `
<tr>
<tr data-identity-cookie-store-id="${identity.cookieStoreId}" >
<td><div class="userContext-icon"
data-identity-icon="${identity.icon}"
data-identity-color="${identity.color}"
></div></td>
<td>${identity.name}</td>
<td class="hideorshow" >
<img
data-identity-cookie-store-id="${identity.cookieStoreId}"
id="${identity.cookieStoreId}-hideorshow-icon"
class="hideorshow-icon"
src="/img/container-hide.svg"
/>
</td>
<td>&gt;</td>
</tr>`;
identitiesListElement.innerHTML += identityRow;
});
const rows = identitiesListElement.querySelectorAll('tr');
rows.forEach(row=> {
row.addEventListener('click', e=> {
if (e.target.matches('.hideorshow-icon')) {
const containerId = e.target.dataset.identityCookieStoreId;
if (!(containerId in identityState)) {
identityState[containerId] = true;
}
if (identityState[containerId]) {
hideContainer(containerId);
identityState[containerId] = false;
} else {
showContainer(containerId);
identityState[containerId] = true;
}
}
});
});
});
document.querySelector('#edit-containers-link').addEventListener('click', ()=> {
browser.runtime.sendMessage('open-containers-preferences').then(()=> {

View file

@ -20,6 +20,7 @@
"homepage_url": "https://testpilot.firefox.com/",
"permissions": [
"cookies",
"experiments.contextualidentities",
"contextualidentities"
],