diff --git a/_includes/maps/offshore-regions.html b/_includes/maps/offshore-regions.html index 86b7a3284..83d7b4276 100644 --- a/_includes/maps/offshore-regions.html +++ b/_includes/maps/offshore-regions.html @@ -2,8 +2,9 @@ {% for region in site.offshore_regions %} {% if include.href %}{% endif %} - {{ region.title }} - + {{ state.title }} + {% if include.href %}{% endif %} diff --git a/_includes/maps/state-areas.html b/_includes/maps/state-areas.html index de5f865b9..10a8a8d36 100644 --- a/_includes/maps/state-areas.html +++ b/_includes/maps/state-areas.html @@ -7,9 +7,11 @@ - {{ state.title }}: {{ value }} - + {{ state.title }} + + {% if include.href %}{% endif %} {% endfor %} diff --git a/_includes/state-map.html b/_includes/state-map.html index fb7a9a872..ca2395370 100644 --- a/_includes/state-map.html +++ b/_includes/state-map.html @@ -2,7 +2,7 @@ {% assign states_svg = '/maps/states/all.svg' %} {% assign offshore_svg = '/maps/offshore/all.svg' %} - + {% if include.offshore_regions != false %} diff --git a/_sass/components/_all.scss b/_sass/components/_all.scss index 60ede291f..67d32cf8b 100644 --- a/_sass/components/_all.scss +++ b/_sass/components/_all.scss @@ -21,3 +21,4 @@ @import 'flowchart'; @import 'tabs'; @import 'sticky'; +@import 'tooltip'; diff --git a/_sass/components/_tooltip.scss b/_sass/components/_tooltip.scss new file mode 100644 index 000000000..8c0d9c7d6 --- /dev/null +++ b/_sass/components/_tooltip.scss @@ -0,0 +1,18 @@ +.eiti-tooltip { + background: $white; + border: 2px solid $greenest-land; + max-width: 300px; + padding: $base-padding-lite; + padding-bottom: ($base-padding-lite / 2); + padding-top: 0.23em; // to account for verticality of text + position: absolute; + z-index: 9000; + + p { + @include heading('para-sm'); + + color: $greenest-land; + font-weight: $weight-bold; + margin: 0; + } +} diff --git a/_sass/elements/_maps.scss b/_sass/elements/_maps.scss index 453da3d42..b1d8aeb12 100644 --- a/_sass/elements/_maps.scss +++ b/_sass/elements/_maps.scss @@ -27,10 +27,22 @@ svg.map { .feature.offshore-area use { fill: $greenest-land; + + &:hover, + &:active, + &:focus { + fill: darken($greenest-land, 5%); + } } .feature:not([fill]) use { fill-opacity: 0; + + &:hover, + &:active, + &:focus { + fill-opacity: 0.3; + } } .feature[fill] use { diff --git a/js/components/eiti-tooltip-wrapper.js b/js/components/eiti-tooltip-wrapper.js new file mode 100644 index 000000000..6909a9571 --- /dev/null +++ b/js/components/eiti-tooltip-wrapper.js @@ -0,0 +1,122 @@ +(function(exports) { + + var depixelize = function(value) { + if (value.indexOf('px') > -1) { + return +value.substr(0, value.length - 2); + } else { + return value; + } + }; + + var pixelize = function(value) { + return value + 'px'; + }; + + var hideTooltip = function (tooltip) { + tooltip.attr('aria-hidden', true); + }; + + var attached = function() { + var self = d3.select(this); + var svg = d3.select('svg'); + var svgParent = self; + var titles = self.selectAll('title'); + var tiles = self.selectAll('use'); + + var tooltip, + tooltipText; + + var init = function(initialize) { + tooltip = self.select('.eiti-tooltip'); + + if (tooltip.empty()) { + tooltip = self.append('div') + .classed('eiti-tooltip', true); + } + + tooltip + .attr('aria-hidden', true); + + tooltipText = tooltip.select('p'); + + if (tooltipText.empty()) { + tooltipText = tooltip.append('p'); + } + + // clear text + // if no javascript runs, will serve as the tooltip + // otherwise, clear it so that it doesn't interfere with + // this tooltip + titles.text(''); + }; + + var update = function() { + var event = event || d3.event || window.event; + var elem = event.target || event.srcElement; + + var parentElement = d3.select(elem.parentElement); + var title = parentElement.select('title'); + + init(); + + tooltipText.text(function(){ + return title.attr('desc'); + }); + + tooltip + .attr('aria-hidden', false) + .attr('aria-label', function(){ + return title.attr('alt'); + }) + .style('left', function() { + var tooltipWidth = depixelize(tooltip.style('width')); + var svgWidth = depixelize(svg.style('width')); + + if (svgWidth <= tooltipWidth + event.layerX) { + return pixelize(event.layerX - tooltipWidth); + } else { + return pixelize(event.layerX); + } + }) + .style('top', function() { + var tooltipHeight = depixelize(tooltip.style('height')); + var svgHeight = depixelize(svg.style('height')); + + if (svgHeight <= tooltipHeight + event.layerY) { + return pixelize(event.layerY - tooltipHeight); + } else { + return pixelize(event.layerY); + } + }); + }; + + var hide = function () { + var event = event || window.event; + var elem = event.target || event.srcElement; + if (elem.nodeName === 'svg') { + var tooltip = self.select('.eiti-tooltip'); + hideTooltip(tooltip); + } + }; + + init(this); + + tiles.on('mouseover', update); + svg.on('mouseout', hide); + }; + + var detached = function() { }; + + exports.EITITooltipWrapper = document.registerElement('eiti-tooltip-wrapper', { + extends: 'div', + prototype: Object.create( + HTMLElement.prototype, + { + attachedCallback: {value: attached}, + detachdCallback: {value: detached} + } + ) + }); + +})(this); + diff --git a/js/lib/homepage.min.js b/js/lib/homepage.min.js index 220143a61..100a080d1 100644 --- a/js/lib/homepage.min.js +++ b/js/lib/homepage.min.js @@ -49,6 +49,7 @@ 'use strict'; __webpack_require__(7); + __webpack_require__(41); })(window); @@ -193,6 +194,135 @@ }); +/***/ }, + +/***/ 41: +/***/ function(module, exports) { + + (function(exports) { + + var depixelize = function(value) { + if (value.indexOf('px') > -1) { + return +value.substr(0, value.length - 2); + } else { + return value; + } + }; + + var pixelize = function(value) { + return value + 'px'; + }; + + var hideTooltip = function (tooltip) { + tooltip.attr('aria-hidden', true); + }; + + var attached = function() { + var self = d3.select(this); + var svg = d3.select('svg'); + var svgParent = self; + var titles = self.selectAll('title'); + var tiles = self.selectAll('use'); + + var tooltip, + tooltipText; + + var init = function(initialize) { + tooltip = self.select('.eiti-tooltip'); + + if (tooltip.empty()) { + tooltip = self.append('div') + .classed('eiti-tooltip', true); + } + + tooltip + .attr('aria-hidden', true); + + tooltipText = tooltip.select('p'); + + if (tooltipText.empty()) { + tooltipText = tooltip.append('p'); + } + + // clear text + // if no javascript runs, will serve as the tooltip + // otherwise, clear it so that it doesn't interfere with + // this tooltip + titles.text(''); + }; + + var update = function() { + var event = event || d3.event || window.event; + var elem = event.target || event.srcElement; + + var parentElement = d3.select(elem.parentElement); + var title = parentElement.select('title'); + + init(); + + tooltipText.text(function(){ + return title.attr('desc'); + }); + + tooltip + .attr('aria-hidden', false) + .attr('aria-label', function(){ + return title.attr('alt'); + }) + .style('left', function() { + var tooltipWidth = depixelize(tooltip.style('width')); + var svgWidth = depixelize(svg.style('width')); + + if (svgWidth <= tooltipWidth + event.layerX) { + return pixelize(event.layerX - tooltipWidth); + } else { + return pixelize(event.layerX); + } + }) + .style('top', function() { + var tooltipHeight = depixelize(tooltip.style('height')); + var svgHeight = depixelize(svg.style('height')); + + if (svgHeight <= tooltipHeight + event.layerY) { + return pixelize(event.layerY - tooltipHeight); + } else { + return pixelize(event.layerY); + } + }); + }; + + var hide = function () { + var event = event || window.event; + var elem = event.target || event.srcElement; + if (elem.nodeName === 'svg') { + var tooltip = self.select('.eiti-tooltip'); + hideTooltip(tooltip); + } + }; + + init(this); + + tiles.on('mouseover', update); + svg.on('mouseout', hide); + }; + + var detached = function() { }; + + exports.EITITooltipWrapper = document.registerElement('eiti-tooltip-wrapper', { + extends: 'div', + prototype: Object.create( + HTMLElement.prototype, + { + attachedCallback: {value: attached}, + detachdCallback: {value: detached} + } + ) + }); + + })(this); + + + /***/ } /******/ }); \ No newline at end of file diff --git a/js/lib/main.min.js b/js/lib/main.min.js index bc1402f5b..4b7add00c 100644 --- a/js/lib/main.min.js +++ b/js/lib/main.min.js @@ -50,44 +50,44 @@ 'use strict'; // 3rd party dependencies - var d3 = __webpack_require__(8); + var d3 = __webpack_require__(9); exports.d3 = d3; // Custom map projection - d3.geo.albersCustom = __webpack_require__(9); + d3.geo.albersCustom = __webpack_require__(10); // common 3rd-party dependencies - exports.queue = __webpack_require__(10); - exports.topojson = __webpack_require__(11); - exports.colorbrewer = __webpack_require__(12); - exports.$ = exports.jQuery = __webpack_require__(14); + exports.queue = __webpack_require__(11); + exports.topojson = __webpack_require__(12); + exports.colorbrewer = __webpack_require__(13); + exports.$ = exports.jQuery = __webpack_require__(15); // EITI site-wide common code - exports.eiti = __webpack_require__(15); + exports.eiti = __webpack_require__(16); // custom elements polyfill - __webpack_require__(16); + __webpack_require__(17); - exports.EITIMap = __webpack_require__(17); - exports.EITISlider = __webpack_require__(19); - exports.EITIToggle = __webpack_require__(20); + exports.EITIMap = __webpack_require__(18); + exports.EITISlider = __webpack_require__(20); + exports.EITIToggle = __webpack_require__(21); // FIXME: does this export anything? - __webpack_require__(21); + __webpack_require__(22); // XXX List.js's node module isn't CommonJS compatible, so we have to use a // built version. - exports.List = __webpack_require__(22); + exports.List = __webpack_require__(23); - exports.Glossary = __webpack_require__(23); - exports.Accordion = __webpack_require__(24); + exports.Glossary = __webpack_require__(24); + exports.Accordion = __webpack_require__(25); $(function () { var glossary = new exports.Glossary(), accordion = new exports.Accordion(); }); - var svg4everybody = __webpack_require__(25); + var svg4everybody = __webpack_require__(26); svg4everybody(); })(window); @@ -101,7 +101,8 @@ /* 5 */, /* 6 */, /* 7 */, -/* 8 */ +/* 8 */, +/* 9 */ /***/ function(module, exports, __webpack_require__) { var __WEBPACK_AMD_DEFINE_FACTORY__, __WEBPACK_AMD_DEFINE_RESULT__;!function() { @@ -9660,12 +9661,12 @@ }(); /***/ }, -/* 9 */ +/* 10 */ /***/ function(module, exports, __webpack_require__) { (function(exports) { - var d3 = exports.d3 || __webpack_require__(8); + var d3 = exports.d3 || __webpack_require__(9); var E = 1e-6; @@ -9845,7 +9846,7 @@ /***/ }, -/* 10 */ +/* 11 */ /***/ function(module, exports, __webpack_require__) { (function (global, factory) { @@ -9966,7 +9967,7 @@ })); /***/ }, -/* 11 */ +/* 12 */ /***/ function(module, exports, __webpack_require__) { var __WEBPACK_AMD_DEFINE_FACTORY__, __WEBPACK_AMD_DEFINE_RESULT__;!function() { @@ -10506,14 +10507,14 @@ /***/ }, -/* 12 */ +/* 13 */ /***/ function(module, exports, __webpack_require__) { - module.exports = __webpack_require__(13); + module.exports = __webpack_require__(14); /***/ }, -/* 13 */ +/* 14 */ /***/ function(module, exports, __webpack_require__) { var __WEBPACK_AMD_DEFINE_FACTORY__, __WEBPACK_AMD_DEFINE_RESULT__;// This product includes color specifications and designs developed by Cynthia Brewer (http://colorbrewer.org/). @@ -10834,7 +10835,7 @@ /***/ }, -/* 14 */ +/* 15 */ /***/ function(module, exports, __webpack_require__) { var __WEBPACK_AMD_DEFINE_ARRAY__, __WEBPACK_AMD_DEFINE_RESULT__;/*! @@ -21848,14 +21849,14 @@ /***/ }, -/* 15 */ +/* 16 */ /***/ function(module, exports, __webpack_require__) { (function(exports) { 'use strict'; - var d3 = __webpack_require__(8); - var queue = __webpack_require__(10); + var d3 = __webpack_require__(9); + var queue = __webpack_require__(11); /* * @namespace eiti @@ -22565,21 +22566,21 @@ /***/ }, -/* 16 */ +/* 17 */ /***/ function(module, exports) { /*! (C) WebReflection Mit Style License */ (function(e,t,n,r){"use strict";function rt(e,t){for(var n=0,r=e.length;n>0),s="attached",o="detached",u="extends",a="ADDITION",f="MODIFICATION",l="REMOVAL",c="DOMAttrModified",h="DOMContentLoaded",p="DOMSubtreeModified",d="<",v="=",m=/^[A-Z][A-Z0-9]*(?:-[A-Z0-9]+)+$/,g=["ANNOTATION-XML","COLOR-PROFILE","FONT-FACE","FONT-FACE-SRC","FONT-FACE-URI","FONT-FACE-FORMAT","FONT-FACE-NAME","MISSING-GLYPH"],y=[],b=[],w="",E=t.documentElement,S=y.indexOf||function(e){for(var t=this.length;t--&&this[t]!==e;);return t},x=n.prototype,T=x.hasOwnProperty,N=x.isPrototypeOf,C=n.defineProperty,k=n.getOwnPropertyDescriptor,L=n.getOwnPropertyNames,A=n.getPrototypeOf,O=n.setPrototypeOf,M=!!n.__proto__,_=n.create||function mt(e){return e?(mt.prototype=e,new mt):this},D=O||(M?function(e,t){return e.__proto__=t,e}:L&&k?function(){function e(e,t){for(var n,r=L(t),i=0,s=r.length;i -1) { + return +value.substr(0, value.length - 2); + } else { + return value; + } + }; + + var pixelize = function(value) { + return value + 'px'; + }; + + var hideTooltip = function (tooltip) { + tooltip.attr('aria-hidden', true); + }; + + var attached = function() { + var self = d3.select(this); + var svg = d3.select('svg'); + var svgParent = self; + var titles = self.selectAll('title'); + var tiles = self.selectAll('use'); + + var tooltip, + tooltipText; + + var init = function(initialize) { + tooltip = self.select('.eiti-tooltip'); + + if (tooltip.empty()) { + tooltip = self.append('div') + .classed('eiti-tooltip', true); + } + + tooltip + .attr('aria-hidden', true); + + tooltipText = tooltip.select('p'); + + if (tooltipText.empty()) { + tooltipText = tooltip.append('p'); + } + + // clear text + // if no javascript runs, will serve as the tooltip + // otherwise, clear it so that it doesn't interfere with + // this tooltip + titles.text(''); + }; + + var update = function() { + var event = event || d3.event || window.event; + var elem = event.target || event.srcElement; + + var parentElement = d3.select(elem.parentElement); + var title = parentElement.select('title'); + + init(); + + tooltipText.text(function(){ + return title.attr('desc'); + }); + + tooltip + .attr('aria-hidden', false) + .attr('aria-label', function(){ + return title.attr('alt'); + }) + .style('left', function() { + var tooltipWidth = depixelize(tooltip.style('width')); + var svgWidth = depixelize(svg.style('width')); + + if (svgWidth <= tooltipWidth + event.layerX) { + return pixelize(event.layerX - tooltipWidth); + } else { + return pixelize(event.layerX); + } + }) + .style('top', function() { + var tooltipHeight = depixelize(tooltip.style('height')); + var svgHeight = depixelize(svg.style('height')); + + if (svgHeight <= tooltipHeight + event.layerY) { + return pixelize(event.layerY - tooltipHeight); + } else { + return pixelize(event.layerY); + } + }); + }; + + var hide = function () { + var event = event || window.event; + var elem = event.target || event.srcElement; + if (elem.nodeName === 'svg') { + var tooltip = self.select('.eiti-tooltip'); + hideTooltip(tooltip); + } + }; + + init(this); + + tiles.on('mouseover', update); + svg.on('mouseout', hide); + }; + + var detached = function() { }; + + exports.EITITooltipWrapper = document.registerElement('eiti-tooltip-wrapper', { + extends: 'div', + prototype: Object.create( + HTMLElement.prototype, + { + attachedCallback: {value: attached}, + detachdCallback: {value: detached} + } + ) + }); + + })(this); + + + /***/ } /******/ ]); \ No newline at end of file diff --git a/js/src/homepage.js b/js/src/homepage.js index a27e7aff6..0ec3e632a 100644 --- a/js/src/homepage.js +++ b/js/src/homepage.js @@ -2,6 +2,7 @@ 'use strict'; require('./../components/aria-tabs.js'); + require('./../components/eiti-tooltip-wrapper.js'); })(window); diff --git a/js/src/state-pages.js b/js/src/state-pages.js index f99e9fdcf..00b6f8114 100644 --- a/js/src/state-pages.js +++ b/js/src/state-pages.js @@ -7,6 +7,7 @@ require('./../components/eiti-bar-chart.js'); require('./../components/year-switcher-section.js'); require('./../components/eiti-data-map-table.js'); + require('./../components/eiti-tooltip-wrapper.js'); require('./../components/aria-tabs.js');