Skip to content

Commit

Permalink
[#111] Redefine Tooltips using only CSS
Browse files Browse the repository at this point in the history
We just removed 30 KB from the generated script...
  • Loading branch information
cyChop committed Nov 23, 2016
1 parent 08ff541 commit 005e75f
Show file tree
Hide file tree
Showing 13 changed files with 138 additions and 58 deletions.
2 changes: 1 addition & 1 deletion .eslintrc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ rules:
- never
quote-props: # require quotes around object literal property names
- 2
- consistent-as-needed
- as-needed
quotes: # enforce the consistent use of either backticks, double, or single quotes
- 2
- single
Expand Down
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
"bootstrap": "4.0.0-alpha.5",
"rivets": "0.9.6",
"rivets-backbone-adapter": "2.2.0",
"tether": "1.3.7",
"underscore": "1.8.3"
},
"devDependencies": {
Expand Down
6 changes: 3 additions & 3 deletions src/js/model/beverage/beverages.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ export const BEVERAGE_ORDER = {
'tea-oolong': 1,
'tea-white': 2,
'tea-rooibos': 3,
'infusion': 4,
'coffee': 5,
'cocoa': 6
infusion: 4,
coffee: 5,
cocoa: 6
};

export default Collection.extend(
Expand Down
40 changes: 20 additions & 20 deletions src/js/template/beverages.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
<div class="cart-controls">
<small>{beverages._shown}/{beverages.models | length}</small>
<div class="btn-group btn-group-sm">
<button type="button" class="btn btn-primary-outline btn-pick-random"
data-toggle="tooltip" data-placement="bottom" rv-title="i18n.orders.random"
<button type="button" class="btn btn-primary-outline btn-pick-random tooltip"
rv-data-tooltip="i18n.orders.random"
rv-disabled="beverages._shown | eq 0">
<i class="icon icon-random"></i>
</button>
Expand Down Expand Up @@ -50,16 +50,16 @@ <h6 rv-if="orders:total | eq 0" class="dropdown-header">{i18n.orders.none}</h6>
<div class="filters">
<div class="btn-group btn-group-sm" data-toggle="buttons">
<label rv-each-basis="filters:bases"
class="btn btn-secondary" rv-class-active="basis:active"
data-toggle="tooltip" data-placement="bottom" rv-title="basis:key | map i18n.basis">
class="btn btn-secondary tooltip" rv-class-active="basis:active"
rv-data-tooltip="basis:key | map i18n.basis">
<input type="checkbox" rv-checked="basis:active" autocomplete="off"/>
<i class="bev-icon" rv-addclass="basis:key"></i>
</label>
</div>
<div class="btn-group btn-group-sm" data-toggle="buttons">
<label rv-each-moment="filters:moments"
class="btn btn-secondary" rv-class-active="moment:active"
data-toggle="tooltip" data-placement="bottom" rv-title="moment:key | map i18n.moment">
class="btn btn-secondary tooltip" rv-class-active="moment:active"
rv-data-tooltip="moment:key | map i18n.moment">
<input type="checkbox" rv-checked="moment:active" autocomplete="off"/>
<i class="moment-icon" rv-addclass="moment:key"></i>
</label>
Expand Down Expand Up @@ -91,27 +91,27 @@ <h6 rv-if="orders:total | eq 0" class="dropdown-header">{i18n.orders.none}</h6>
<div class="moment">
<ul>
<li rv-class-invisible="b:time.morning | defined | not | or b:time.morning | not"
rv-class-text-muted="b:time.morning | not">
<i class="moment-icon morning" data-toggle="tooltip"
data-placement="bottom"
rv-title="b:time.morning | defined | if i18n.moment.morning i18n.moment.unknown"></i>
rv-class-text-muted="b:time.morning | not"
rv-data-tooltip="b:time.morning | defined | if i18n.moment.morning i18n.moment.unknown"
class="tooltip">
<i class="moment-icon morning"></i>
</li>
<li rv-class-invisible="b:time.daytime | defined | not | or b:time.daytime | not"
rv-class-text-muted="b:time.daytime | not">
<i class="moment-icon daytime" data-toggle="tooltip"
data-placement="bottom"
rv-title="b:time.daytime | defined | if i18n.moment.daytime i18n.moment.unknown"></i>
rv-class-text-muted="b:time.daytime | not"
rv-data-tooltip="b:time.daytime | defined | if i18n.moment.daytime i18n.moment.unknown"
class="tooltip">
<i class="moment-icon daytime"></i>
</li>
<li rv-class-invisible="b:time.evening | defined | not | or b:time.evening | not"
rv-class-text-muted="b:time.evening | not">
<i class="moment-icon evening" data-toggle="tooltip"
data-placement="bottom"
rv-title="b:time.evening | defined | if i18n.moment.evening i18n.moment.unknown"></i>
rv-class-text-muted="b:time.evening | not"
rv-data-tooltip="b:time.evening | defined | if i18n.moment.evening i18n.moment.unknown"
class="tooltip">
<i class="moment-icon evening"></i>
</li>
</ul>
</div>
<div class="theine-level"
data-toggle="tooltip" data-placement="bottom" rv-title="b:theine | map i18n.theine">
<div class="theine-level tooltip"
rv-data-tooltip="b:theine | map i18n.theine">
<div class="icon-bars" rv-addclass="b:theine">
<div class="bar bar-1"></div>
<div class="bar bar-2"></div>
Expand Down
14 changes: 0 additions & 14 deletions src/js/view/beverages.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import Orders from '../model/order/order-summary';
import i18n from 'i18n';

const template = require('../template/beverages.html');
require('bootstrap/js/tooltip');
require('bootstrap/js/dropdown');
require('../../scss/beverages.scss');

Expand Down Expand Up @@ -133,9 +132,6 @@ export default View.extend(
this.context.filters = this.filters;
this.rview = rivets.bind(this.$el.html(template), this.context);

// init tooltips
this._tooltip();

// done, return the result
return this;
},
Expand Down Expand Up @@ -165,7 +161,6 @@ export default View.extend(
.on('sync', () => {
this._filterBeverages();
this.context.ready = true;
this._tooltip();
}, this)
.fetch({
error: () => {
Expand All @@ -181,15 +176,6 @@ export default View.extend(
}, 0);
},

/**
* Initializes the tooltips and popovers of the rendered page. This is set only on existing elements:
* the method should be called again any time a new tooltip trigger element is added to the page.
* @private
*/
_tooltip () {
this.$('[data-toggle="tooltip"]').tooltip();
},

_toggleDetail (event) {
const clicked = this._getClickedBeverage(event);
clicked._detailed = !clicked._detailed;
Expand Down
2 changes: 1 addition & 1 deletion src/scss/_bootstrap.scss
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@

// Components w/ JavaScript
//@import "node_modules/bootstrap/scss/modal";
@import "node_modules/bootstrap/scss/tooltip";
//@import "node_modules/bootstrap/scss/tooltip";
//@import "node_modules/bootstrap/scss/popover";
//@import "node_modules/bootstrap/scss/carousel";

Expand Down
6 changes: 3 additions & 3 deletions src/scss/_variables.scss
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
@import "font-variables";
@import "styles/_font-variables";

$bev-variants: (
tea-white: (
icon: $icon-leaf,
color: #ddd
), tea-green: (
icon: $icon-leaf,
color: #7f7
color: #0b5
), tea-oolong: (
icon: $icon-leaf,
color: #7bd
Expand All @@ -18,7 +18,7 @@ $bev-variants: (
color: #f55
), infusion: (
icon: $icon-pagelines,
color: #bfb
color: #7f7
), coffee: (
icon: $icon-cup,
color: #000
Expand Down
14 changes: 12 additions & 2 deletions src/scss/beverages.scss
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,21 @@
@import "bootstrap";

.beverages-container {
box-sizing: border-box;

*,
*:before,
*:after {
box-sizing: inherit;
}

@extend .container-fluid;
padding: 7px;

@import "icons";
@import "styles/icons";

//* Animation */
@import "animations";
@import "styles/animations";

//* The real styling for the app */
.header {
Expand Down Expand Up @@ -287,6 +295,8 @@
}

//* Utility classes */
@import "styles/tooltips";

.tag {
@each $bev-variant, $icon-map in $bev-variants {
&.#{$bev-variant} {
Expand Down
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion src/scss/_icons.scss → src/scss/styles/_icons.scss
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
@import "variables";
@import "../_variables";

//* The basics of icons */
.icon, .bev-icon, .moment-icon {
Expand Down
77 changes: 77 additions & 0 deletions src/scss/styles/_tooltips.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
// Inspired from https://chrisbracco.com/a-simple-css-tooltip/

//* Base styles for the element that has a tooltip */
//[data-tooltip],
.tooltip {
position: relative;
cursor: pointer;

//* Base styles for the entire tooltip */
&:before, &:after {
position: absolute;
visibility: hidden;
filter: progid:DXImageTransform.Microsoft.Alpha(Opacity=0);
opacity: 0;
transition: opacity 0.2s ease-in-out,
visibility 0.2s ease-in-out,
transform 0.2s cubic-bezier(0.71, 1.7, 0.77, 1.24);
transform: translate3d(0, 0, 0);
pointer-events: none;
}

//* Show the entire tooltip on hover and focus */
&:hover, &:focus {
&:before, &:after {
visibility: visible;
filter: progid:DXImageTransform.Microsoft.Alpha(Opacity=100);
opacity: 1;
}
}

//* Base styles for the tooltip's directional arrow */
&:before {
z-index: 1001;
border: 6px solid transparent;
background: transparent;
content: "";
}

//* Base styles for the tooltip's content area */
&:after {
z-index: 1000;
padding: 8px;
width: 160px;
background-color: #000;
background-color: hsla(0, 0%, 20%, 0.9);
color: #fff;
content: attr(data-tooltip);
font-size: 14px;
line-height: 1.2;
}

//* Bottom tooltips only */
&:before, &:after {
top: 100%;
bottom: auto;
left: 50%;
}

&:before {
margin-top: -12px;
margin-bottom: 0;
border-top-color: transparent;
border-bottom-color: #000;
border-bottom-color: hsla(0, 0%, 20%, 0.9);
}

&:focus, &:hover {
&:before, &:after {
transform: translateY(12px);
}
}

// Horizontally align top/bottom tooltips
&:after {
margin-left: -80px;
}
}
32 changes: 20 additions & 12 deletions webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,29 @@ module.exports = function (lg) {
]
},

{test: /bootstrap[\/\\]js/, loaders: ['imports-loader?jQuery=jquery']},
{
test: /bootstrap[\/\\]js/,
loaders: ['imports-loader?jQuery=jquery']
},

{
test: /\.js$/,
exclude: /node_modules/,
loaders: ['babel-loader']
},
{test: /\.html?$/, loaders: ['raw-loader']},
{test: /\.json$/, loaders: ['json-loader']},
{
test: /\.html?$/,
loaders: ['raw-loader']
},
{
test: /\.json$/,
loaders: ['json-loader']
},

{test: /\.([ot]tf|woff2?|eot|svg)(\?.+)?$/, loaders: ['file-loader']},
{
test: /\.([ot]tf|woff2?|eot|svg)(\?.+)?$/,
loaders: ['file-loader']
},

{
test: /\.scss$/,
Expand All @@ -43,13 +55,11 @@ module.exports = function (lg) {
})
}
],
noParse: /[\/\\]sinon[\/\\]pkg[\/\\]sinon.js$/
noParse: /[/\\]sinon[/\\]pkg[/\\]sinon\.js$/
},

// Resolution configuration
externals: {
'jquery': 'jQuery'
},
externals: {jquery: 'jQuery'},
resolve: {
alias: {
// Shortcuts
Expand All @@ -69,10 +79,8 @@ module.exports = function (lg) {
// Plugins
plugins: [
new webpack.ProvidePlugin({
// Requirements for Bootstrap, popover and tooltip
'window.Tether': 'tether',
'Tether': 'tether',
'Util': 'exports-loader?Util!bootstrap/js/util'
// Util is used by bootstrap/js/dropdown
Util: 'exports-loader?Util!bootstrap/js/util'
}),
new ExtractTextPlugin('[name].css')
]
Expand Down

0 comments on commit 005e75f

Please sign in to comment.