| 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 function openSharePopup(url) | 6 function openSharePopup(url) |
| 7 { | 7 { |
| 8 var iframe = document.getElementById("share-popup"); | 8 var iframe = document.getElementById("share-popup"); |
| 9 var glassPane = document.getElementById("glass-pane"); | 9 var glassPane = document.getElementById("glass-pane"); |
| 10 | 10 |
| 11 var popupMessageListener = function(event) | |
| 12 { | |
| 13 if (event.origin !== url) | |
| 14 return; | |
| 15 | |
| 16 console.log(event); | |
|
Wladimir Palant
2012/10/25 13:31:04
Debug code?
| |
| 17 iframe.width = event.data.width; | |
| 18 iframe.height = event.data.height; | |
| 19 window.removeEventListener("message", popupMessageListener); | |
| 20 }; | |
| 21 window.addEventListener("message", popupMessageListener, false); | |
| 22 | |
| 11 var popupLoadListener = function() | 23 var popupLoadListener = function() |
| 12 { | 24 { |
| 13 iframe.className = "visible"; | 25 iframe.className = "visible"; |
| 14 | 26 |
| 15 var popupCloseListener = function() | 27 var popupCloseListener = function() |
| 16 { | 28 { |
| 17 iframe.className = glassPane.className = ""; | 29 iframe.className = glassPane.className = ""; |
| 18 document.removeEventListener("click", popupCloseListener); | 30 document.removeEventListener("click", popupCloseListener); |
| 19 } | 31 }; |
|
Wladimir Palant
2012/10/25 10:45:03
Missing semicolon?
Felix Dahlke
2012/10/25 12:00:51
Yes, ouch.
| |
| 20 document.addEventListener("click", popupCloseListener, false); | 32 document.addEventListener("click", popupCloseListener, false); |
| 21 iframe.removeEventListener("load", popupLoadListener); | 33 iframe.removeEventListener("load", popupLoadListener); |
| 22 }; | 34 }; |
| 35 iframe.addEventListener("load", popupLoadListener, false); | |
| 23 | 36 |
| 24 iframe.addEventListener("load", popupLoadListener, false); | |
| 25 iframe.src = url; | 37 iframe.src = url; |
| 26 glassPane.className = "visible"; | 38 glassPane.className = "visible"; |
|
Wladimir Palant
2012/10/25 10:45:03
Does it still work if you close the popup and then
Felix Dahlke
2012/10/25 12:00:51
Sure.
| |
| 27 } | 39 } |
| 28 | 40 |
| 29 function initSocialLinks(variant) | 41 function initSocialLinks(variant) |
| 30 { | 42 { |
| 31 var networks = ["twitter", "facebook"]; | 43 var networks = ["twitter", "facebook"]; |
| 32 networks.forEach(function(network) | 44 networks.forEach(function(network) |
| 33 { | 45 { |
| 34 var links = document.getElementsByClassName("share-" + network); | 46 var links = document.getElementsByClassName("share-" + network); |
| 35 for (var i = 0; i < links.length; i++) | 47 for (var i = 0; i < links.length; i++) |
|
Wladimir Palant
2012/10/25 10:45:03
I consider it acceptable to omit brackets if the f
Felix Dahlke
2012/10/25 12:00:51
OK, seems appropriate.
| |
| 48 { | |
| 36 links[i].addEventListener("click", function(e) | 49 links[i].addEventListener("click", function(e) |
| 37 { | 50 { |
| 38 e.preventDefault(); | 51 e.preventDefault(); |
| 39 // openSharePopup(getDocLink(network) + "&variant=" + variant); | 52 openSharePopup(getDocLink("share-" + network) + "&variant=" + variant); |
| 40 openSharePopup("http://localhost:8000"); | |
|
Wladimir Palant
2012/10/25 10:45:03
Debug code apparently.
Felix Dahlke
2012/10/25 12:00:51
Double ouch.
| |
| 41 }, false); | 53 }, false); |
| 54 } | |
| 42 }); | 55 }); |
| 43 } | 56 } |
| 44 | 57 |
| 45 function init() | 58 function init() |
| 46 { | 59 { |
| 47 // Choose a share text variant randomly | 60 // Choose a share text variant randomly |
| 48 var variant = Math.floor(Math.random() * 2) + 1; | 61 var variant = Math.floor(Math.random() * 2) + 1; |
| 49 document.documentElement.setAttribute("share-variant", variant); | 62 document.documentElement.setAttribute("share-variant", variant); |
| 50 | 63 |
| 51 // Set up page title | 64 // Set up page title |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 91 } | 104 } |
| 92 } | 105 } |
| 93 } | 106 } |
| 94 | 107 |
| 95 function getDocLink(page, anchor) | 108 function getDocLink(page, anchor) |
| 96 { | 109 { |
| 97 return Prefs.documentation_link | 110 return Prefs.documentation_link |
| 98 .replace(/%LINK%/g, page) | 111 .replace(/%LINK%/g, page) |
| 99 .replace(/%LANG%/g, Utils.appLocale) + (anchor ? "#" + anchor : "" ); | 112 .replace(/%LANG%/g, Utils.appLocale) + (anchor ? "#" + anchor : "" ); |
| 100 } | 113 } |
| LEFT | RIGHT |