| 1 | function initInnerShare() { |
| 2 | if (window.isTerminal) return |
| 3 | |
| 4 | var fullUrl = "//www.bloomberg.com/graphics/2015-paul-ford-what-is-code/"; |
| 5 | |
| 6 | var moduleByName = d3.nest() |
| 7 | .key(function(d){ return d.name }) |
| 8 | .map(modules); |
| 9 | |
| 10 | function track(label) { |
| 11 | if(typeof tracker == 'function') { |
| 12 | tracker('share', label) |
| 13 | } |
| 14 | } |
| 15 | |
| 16 | var that = { |
| 17 | |
| 18 | assignButtons: function() { |
| 19 | |
| 20 | Array.prototype.forEach.call(document.querySelectorAll('.innershare .innertw'), function(el){ |
| 21 | el.addEventListener('click', that.postToTwitter) |
| 22 | }); |
| 23 | |
| 24 | |
| 25 | }, |
| 26 | |
| 27 | centerPopup: function(width, height) { |
| 28 | var wLeft = window.screenLeft ? window.screenLeft : window.screenX; |
| 29 | var wTop = window.screenTop ? window.screenTop : window.screenY; |
| 30 | var left = wLeft + (window.innerWidth / 2) - (width / 2); |
| 31 | var top = wTop + (window.innerHeight / 2) - (height / 2); |
| 32 | return 'width=' + width + ',height=' + height + ',top=' + top + ',left=' + left; |
| 33 | }, |
| 34 | |
| 35 | postToTwitter: function(event) { |
| 36 | event.preventDefault() |
| 37 | var data = moduleByName[d3.select(this).attr('data-mname')][0]; |
| 38 | // var data = shareData(); |
| 39 | var tweetUrl = "//twitter.com/share?url=" + encodeURIComponent(fullUrl+"#"+data.name) + "&text=" + encodeURIComponent(data.tweet); |
| 40 | var opts = that.centerPopup(820, 440) + "scrollbars=1"; |
| 41 | track("Twitter"); |
| 42 | window.open(tweetUrl, 'twitter', opts); |
| 43 | } |
| 44 | }; |
| 45 | |
| 46 | that.assignButtons() |
| 47 | } |
| 48 | |
| 49 | // ---------------------------------------------------------------------------- |
| 50 | // Copyright (C) 2015 Bloomberg Finance L.P. |