| Left: | ||
| Right: |
| LEFT | RIGHT |
|---|---|
| 1 var backgroundPage = chrome.extension.getBackgroundPage(); | 1 var backgroundPage = chrome.extension.getBackgroundPage(); |
| 2 var require = backgroundPage.require; | 2 var require = backgroundPage.require; |
| 3 var Prefs = require("prefs").Prefs; | 3 var Prefs = require("prefs").Prefs; |
| 4 var Utils = require("utils").Utils; | 4 var Utils = require("utils").Utils; |
| 5 | 5 |
| 6 jQuery.fn.center = function() | |
| 7 { | |
| 8 return this.css({ | |
| 9 position: "absolute", | |
| 10 top: Math.max(0, (($(window).height() - this.outerHeight()) / 2) | |
| 11 + $(window).scrollTop()), | |
| 12 left: Math.max(0, (($(window).width() - this.outerWidth()) / 2) | |
| 13 + $(window).scrollLeft()) | |
| 14 }); | |
| 15 }; | |
| 16 | |
| 17 function openSharePopup(url) | 6 function openSharePopup(url) |
| 18 { | 7 { |
| 19 var glassPane = $("<div/>").addClass("share-popup-glass-pane"); | 8 var iframe = document.getElementById("share-popup"); |
| 9 var glassPane = document.getElementById("glass-pane"); | |
| 20 | 10 |
| 21 var iframe = $("<iframe/>") | 11 var popupMessageListener = function(event) |
| 22 .addClass("share-popup") | 12 { |
| 23 .attr({ | 13 if (event.origin !== url) |
| 24 src: url, | 14 return; |
| 25 scrolling: "no" | |
| 26 }) | |
| 27 .on("load", function() | |
| 28 { | |
| 29 iframe.center().fadeIn(150); | |
| 30 $(document).click(function() | |
| 31 { | |
| 32 iframe.fadeOut(100, iframe.remove); | |
| 33 glassPane.fadeOut(200, glassPane.remove); | |
|
Wladimir Palant
2012/10/25 07:12:00
I think that using CSS transitions for fade-in/fad
| |
| 34 }); | |
| 35 }); | |
|
Wladimir Palant
2012/10/25 07:12:00
Generally I'm trying to avoid creating non-trivial
| |
| 36 | 15 |
| 37 var body = $(document.body); | 16 console.log(event); |
|
Wladimir Palant
2012/10/25 13:31:04
Debug code?
| |
| 38 body.append(glassPane); | 17 iframe.width = event.data.width; |
| 39 glassPane.fadeIn(200, function() | 18 iframe.height = event.data.height; |
|
Felix Dahlke
2012/10/24 14:57:33
I would have loved to use Function.bind here, but
Wladimir Palant
2012/10/25 07:12:00
I agree - bind() is good for the obvious cases, th
| |
| 19 window.removeEventListener("message", popupMessageListener); | |
| 20 }; | |
| 21 window.addEventListener("message", popupMessageListener, false); | |
| 22 | |
| 23 var popupLoadListener = function() | |
| 40 { | 24 { |
| 41 body.append(iframe); | 25 iframe.className = "visible"; |
| 42 }); | 26 |
| 27 var popupCloseListener = function() | |
| 28 { | |
| 29 iframe.className = glassPane.className = ""; | |
| 30 document.removeEventListener("click", popupCloseListener); | |
| 31 }; | |
| 32 document.addEventListener("click", popupCloseListener, false); | |
| 33 iframe.removeEventListener("load", popupLoadListener); | |
| 34 }; | |
| 35 iframe.addEventListener("load", popupLoadListener, false); | |
| 36 | |
| 37 iframe.src = url; | |
| 38 glassPane.className = "visible"; | |
| 43 } | 39 } |
| 44 | 40 |
| 45 function initSocialLinks(variant) | 41 function initSocialLinks(variant) |
| 46 { | 42 { |
| 47 var networks = ["twitter", "facebook"]; | 43 var networks = ["twitter", "facebook"]; |
| 48 networks.forEach(function(network) | 44 networks.forEach(function(network) |
| 49 { | 45 { |
| 50 var links = document.getElementsByClassName("share-" + network); | 46 var links = document.getElementsByClassName("share-" + network); |
| 51 for (var i = 0; i < links.length; i++) | 47 for (var i = 0; i < links.length; i++) |
| 52 $(links[i]) | 48 { |
| 53 .attr("href", "#") | 49 links[i].addEventListener("click", function(e) |
|
Wladimir Palant
2012/10/25 07:12:00
Why does this attribute need to be defined dynamic
| |
| 54 .click(function(e) | 50 { |
| 55 { | 51 e.preventDefault(); |
| 56 e.preventDefault(); | 52 openSharePopup(getDocLink("share-" + network) + "&variant=" + variant); |
| 57 openSharePopup(getDocLink(network) + "&variant=" + variant); | 53 }, false); |
| 58 }); | 54 } |
| 59 }); | 55 }); |
| 60 } | 56 } |
| 61 | 57 |
| 62 function init() | 58 function init() |
| 63 { | 59 { |
| 64 // Choose a share text variant randomly | 60 // Choose a share text variant randomly |
| 65 var variant = Math.floor(Math.random() * 2) + 1; | 61 var variant = Math.floor(Math.random() * 2) + 1; |
| 66 document.documentElement.setAttribute("share-variant", variant); | 62 document.documentElement.setAttribute("share-variant", variant); |
| 67 | 63 |
| 68 // Set up page title | 64 // Set up page title |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 108 } | 104 } |
| 109 } | 105 } |
| 110 } | 106 } |
| 111 | 107 |
| 112 function getDocLink(page, anchor) | 108 function getDocLink(page, anchor) |
| 113 { | 109 { |
| 114 return Prefs.documentation_link | 110 return Prefs.documentation_link |
| 115 .replace(/%LINK%/g, page) | 111 .replace(/%LINK%/g, page) |
| 116 .replace(/%LANG%/g, Utils.appLocale) + (anchor ? "#" + anchor : "" ); | 112 .replace(/%LANG%/g, Utils.appLocale) + (anchor ? "#" + anchor : "" ); |
| 117 } | 113 } |
| LEFT | RIGHT |