Skip to content
This repository has been archived by the owner on Nov 15, 2017. It is now read-only.

Commit

Permalink
fixed more kinks re collapsing rows
Browse files Browse the repository at this point in the history
  • Loading branch information
gorhill committed Nov 23, 2013
1 parent eee7662 commit 2137e77
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 14 deletions.
45 changes: 34 additions & 11 deletions js/popup.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ function getPageStats() {
var userSettingsCached = {
};

function getUserSetting(setting) {
if ( userSettingsCached[setting] === undefined ) {
function getUserSetting(setting, bypassCache) {
if ( bypassCache || userSettingsCached[setting] === undefined ) {
userSettingsCached[setting] = getHTTPSB().userSettings[setting];
}
return userSettingsCached[setting];
Expand Down Expand Up @@ -514,6 +514,21 @@ function getNextAction(hostname, type, leaning) {

/******************************************************************************/

// This is required for when we update the matrix while it is open:
// the user might have collapsed/expanded one or more domains, and we don't
// want to lose all his hardwork.

var explicitlyToggledDomains = {};

function getCollapseState(domain) {
if ( explicitlyToggledDomains[domain] !== undefined ) {
return explicitlyToggledDomains[domain];
}
return getUserSetting('popupCollapseDomains');
}

/******************************************************************************/

// Update visual of matrix cells(s)

function updateMatrixCells() {
Expand All @@ -532,15 +547,16 @@ function updateMatrixCells() {
// Update behavior of matrix:
// - Whether a section is collapsible or not. It is collapsible if:
// - It has at least one subdomain AND
// - There is no explicit rule anywhere in the subdomain cells
// - There is no explicit rule anywhere in the subdomain cells AND
// - It is not part of group 3 (blacklisted hostnames)

function updateMatrixBehavior() {
var sections = $('.matSection', HTTPSBPopup.matrixList);
var i = sections.length;
var section, subdomainRows;
while ( i-- ) {
section = $(sections[i]);
subdomainRows = section.children('.l2');
subdomainRows = section.children('.l2:not(.g3)');
section.toggleClass('collapsible', subdomainRows.length > 0 && subdomainRows.children('.gdt,.rdt').length === 0);
}
}
Expand Down Expand Up @@ -810,7 +826,8 @@ function makeMatrixGroup0Section(hostnames) {
var domain = hostnames[0];
var domainDiv = $('<div>')
.addClass('matSection')
.toggleClass('collapsed', getUserSetting('popupCollapseDomains'));
.toggleClass('collapsed', getCollapseState(domain))
.prop('domain', domain);
if ( hostnames.length > 1 ) {
makeMatrixGroup0SectionMetaDomain(hostnames)
.appendTo(domainDiv);
Expand Down Expand Up @@ -865,7 +882,8 @@ function makeMatrixGroup1Section(hostnames) {
var domain = hostnames[0];
var domainDiv = $('<div>')
.addClass('matSection')
.toggleClass('collapsed', getUserSetting('popupCollapseDomains'));
.toggleClass('collapsed', getCollapseState(domain))
.prop('domain', domain);
if ( hostnames.length > 1 ) {
makeMatrixGroup1SectionMetaDomain(hostnames)
.appendTo(domainDiv);
Expand Down Expand Up @@ -920,7 +938,8 @@ function makeMatrixGroup2Section(hostnames) {
var domain = hostnames[0];
var domainDiv = $('<div>')
.addClass('matSection')
.toggleClass('collapsed', getUserSetting('popupCollapseDomains'));
.toggleClass('collapsed', getCollapseState(domain))
.prop('domain', domain);
if ( hostnames.length > 1 ) {
makeMatrixGroup2SectionMetaDomain(hostnames)
.appendTo(domainDiv);
Expand Down Expand Up @@ -964,7 +983,8 @@ function makeMatrixGroup3SectionSubomain(domain, subdomain) {
function makeMatrixGroup3Section(hostnames) {
var domain = hostnames[0];
var domainDiv = $('<div>')
.addClass('matSection');
.addClass('matSection')
.prop('domain', domain);
makeMatrixGroup3SectionDomain(domain)
.appendTo(domainDiv);
for ( var i = 1; i < hostnames.length; i++ ) {
Expand All @@ -981,7 +1001,7 @@ function makeMatrixGroup3(group) {
.addClass('matGroup g3');
$('<div>')
.addClass('matSection g3Meta')
.toggleClass('g3Collapsed', !!getUserSetting('popupHideBlacklisted'))
.toggleClass('g3Collapsed', !!getUserSetting('popupHideBlacklisted', true))
.appendTo(groupDiv);
makeMatrixMetaRow(computeMatrixGroupMetaStats(group), 'g3')
.appendTo(groupDiv);
Expand Down Expand Up @@ -1284,8 +1304,11 @@ function initAll() {
});
$('#domainOnly', popup.matrixCellHotspots)
.on('click', function() {
var section = $(this).parents('.matSection.collapsible');
section.toggleClass('collapsed');
var section = $(this)
.parents('.matSection.collapsible')
.toggleClass('collapsed');
explicitlyToggledDomains[section.prop('domain')] =
section.hasClass('collapsed');
return false;
});

Expand Down
6 changes: 3 additions & 3 deletions popup.html
Original file line number Diff line number Diff line change
Expand Up @@ -374,13 +374,13 @@
border: 0;
padding: 0;
position: absolute;
left: 10%;
bottom: -3px;
left: calc(50% - 6px);
bottom: -4px;
width: 13px;
height: 13px;
visibility: hidden;
background: transparent url('img/domain-collapse.png') no-repeat;
opacity: 0.25;
opacity: 0.2;
z-index: 10000;
}
.matSection.collapsed #domainOnly {
Expand Down

0 comments on commit 2137e77

Please sign in to comment.