Skip to content

Commit

Permalink
feat(active): Removing use of :active in favor of .active for more co…
Browse files Browse the repository at this point in the history
…ntrol of active state

Using the :active pseudo works fine for desktop, but mobile is a
completely different beast, especially with the quirks of each
platform. By intentionally not using any :active selectors and manually
adding/removing a .active class, it gives us a precise control on how
the active state works for ALL platforms. Additionally, this places
less selectors in the css, and reduces the possibility of unnecessary
repaints. Currently this method of using .active instead of :active is
being applied to .button and .item elements.
  • Loading branch information
adamdbradley committed Mar 15, 2014
1 parent a3ea027 commit baa04cd
Show file tree
Hide file tree
Showing 10 changed files with 31 additions and 20 deletions.
23 changes: 23 additions & 0 deletions js/utils/tap.js
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,13 @@
var tap = isRecentTap(e);
if(tap) delete tapCoordinates[tap.id];
}, REMOVE_PREVENT_DELAY);

setTimeout(function(){
for(var hitKey in hitElements) {
hitElements[hitKey] && hitElements[hitKey].classList.remove('active');
delete hitElements[hitKey];
}
}, 150);
}

function stopEvent(e){
Expand All @@ -197,13 +204,29 @@

function recordStartCoordinates(e) {
startCoordinates = getCoordinates(e);

var x, ele = e.target;
for(x=0; x<5; x++) {
if(!ele || ele.tagName === 'LABEL') break;
if( ele.classList.contains('item') || ele.classList.contains('button') ) {
hitElements[hitCounts] = ele;
hitCounts = (hitCounts > 24 ? 0 : hitCounts + 1);
ionic.requestAnimationFrame(function(){
ele.classList.add('active');
});
break;
}
ele = ele.parentElement;
}
}

var tapCoordinates = {}; // used to remember coordinates to ignore if they happen again quickly
var startCoordinates = {}; // used to remember where the coordinates of the start of the tap
var CLICK_PREVENT_DURATION = 1500; // max milliseconds ghostclicks in the same area should be prevented
var REMOVE_PREVENT_DELAY = 375; // delay after a touchend/mouseup before removing the ghostclick prevent
var HIT_RADIUS = 15;
var hitElements = {};
var hitCounts = 0;

// set global click handler and check if the event should stop or not
document.addEventListener('click', preventGhostClick, true);
Expand Down
2 changes: 1 addition & 1 deletion scss/_action-sheet.scss
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@
border-width: 1px 0px 0px 0px;
border-radius: 0;

&.active, &:active {
&.active {
background-color: transparent;
color: inherit;
}
Expand Down
1 change: 0 additions & 1 deletion scss/_bar.scss
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,6 @@
}
}

&.back-button:active,
&.back-button.active {
opacity: 1;
}
Expand Down
3 changes: 1 addition & 2 deletions scss/_button.scss
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,6 @@
border-color: transparent;
background: none;

&.button:active,
&.button.active {
border-color: transparent;
background: none;
Expand All @@ -187,7 +186,7 @@
background: none;
box-shadow: none;

&:active, &.active {
&.active {
opacity: 0.3;
}
}
Expand Down
3 changes: 1 addition & 2 deletions scss/_checkbox.scss
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,7 @@
.item-checkbox {
padding-left: ($item-padding * 2) + $checkbox-width;

&.active,
&:active {
&.active {
box-shadow: none;
}
}
Expand Down
6 changes: 0 additions & 6 deletions scss/_form.scss
Original file line number Diff line number Diff line change
Expand Up @@ -68,12 +68,6 @@ textarea {
font-size: 16px;
}

&.item.active,
.ionic-pseudo &.item:active {
border-color: $item-default-border;
background-color: transparent;
}

.button-bar {
@include border-radius(0);
@include flex(1, 0, 220px);
Expand Down
3 changes: 1 addition & 2 deletions scss/_items.scss
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,7 @@
}

// Link and Button Active States
.item.active:not(.item-divider):not(.item-input-inset),
.item:active:not(.item-divider):not(.item-input-inset),
.item.active:not(.item-divider):not(.item-input):not(.item-input-inset),
.item-complex.active .item-content {
@include item-active-style($item-default-active-bg, $item-default-active-border);

Expand Down
4 changes: 2 additions & 2 deletions scss/_mixins.scss
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
color: $color;
text-decoration: none;
}
&.active, &:active {
&.active {
background-color: $active-bg-color;
box-shadow: inset 0px 1px 3px rgba(0,0,0,0.15);
border-color: $active-border-color;
Expand Down Expand Up @@ -44,7 +44,7 @@
$text-color: $color;
}
color: $text-color;
&.active, &:active {
&.active {
background-color: $color;
color: #fff;
box-shadow: none;
Expand Down
3 changes: 1 addition & 2 deletions scss/_tabs.scss
Original file line number Diff line number Diff line change
Expand Up @@ -168,8 +168,7 @@
/* Navigational tab */

/* Active state for tab */
.tab-item.active,
.tab-item:active {
.tab-item.active {
opacity: 1;

&.tab-item-light {
Expand Down
3 changes: 1 addition & 2 deletions scss/_toggle.scss
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,7 @@
.item-toggle {
padding-right: ($item-padding * 3) + $toggle-width;

&.active,
&:active {
&.active {
box-shadow: none;
}
}
Expand Down

0 comments on commit baa04cd

Please sign in to comment.