Left: | ||
Right: |
OLD | NEW |
---|---|
1 (function() | 1 (function() |
2 { | 2 { |
3 // Safari will load the popover once, and then show it everytime the icon is | 3 // Safari will load the popover once, and then show it everytime the icon is |
4 // clicked. While Chrome loads it everytime you click the icon. So in order to | 4 // clicked. While Chrome loads it everytime you click the icon. So in order to |
5 // make the popover show the right state and details we have to reload it | 5 // make the popover show the right state and details, we have to emulate the |
6 // everytime it is shown for a different tab. Also we have to reload the | 6 // same behavior as on Chrome, by reloading the popover every time it is shown . |
7 // popover when the background page wasn't ready yet, since we have to access | |
8 // the background page in the popover. | |
9 var backgroundPage = safari.extension.globalPage.contentWindow; | |
10 var valid = backgroundPage.document.readyState == "complete"; | |
11 var activeTab = safari.application.activeBrowserWindow.activeTab; | |
12 var mayResize = true; | |
13 | |
14 safari.self.addEventListener("popover", function() | 7 safari.self.addEventListener("popover", function() |
15 { | 8 { |
16 if (!valid || activeTab != safari.application.activeBrowserWindow.activeTab) | 9 mayResize = false; |
17 { | 10 document.documentElement.style.display = "none"; |
18 mayResize = false; | 11 document.location.reload(); |
19 document.documentElement.style.display = "none"; | |
20 document.location.reload(); | |
21 } | |
22 }); | 12 }); |
23 | 13 |
24 | 14 |
25 // Safari doesn't adjust the size of the popover automatically to the size | 15 // Safari doesn't adjust the size of the popover automatically to the size |
26 // of its content, like when the ad counter is expanded/collapsed. So we add | 16 // of its content, like when the ad counter is expanded/collapsed. So we add |
27 // event listeners to do so. | 17 // event listeners to do so. |
18 var mayResize = true; | |
Wladimir Palant
2014/01/23 13:40:54
Nit: I don't really like this variable being used
Sebastian Noack
2014/01/23 14:00:34
Done.
| |
19 | |
28 var updateSize = function() | 20 var updateSize = function() |
29 { | 21 { |
30 if (mayResize) | 22 if (mayResize) |
31 { | 23 { |
32 safari.self.width = document.body.offsetWidth; | 24 safari.self.width = document.body.offsetWidth; |
33 safari.self.height = document.body.offsetHeight; | 25 safari.self.height = document.body.offsetHeight; |
34 } | 26 } |
35 }; | 27 }; |
36 | 28 |
37 window.addEventListener("load", function() | 29 window.addEventListener("load", function() |
(...skipping 18 matching lines...) Expand all Loading... | |
56 // listener to do so. | 48 // listener to do so. |
57 safari.application.addEventListener("activate", function() | 49 safari.application.addEventListener("activate", function() |
58 { | 50 { |
59 safari.self.hide(); | 51 safari.self.hide(); |
60 }, true); | 52 }, true); |
61 | 53 |
62 | 54 |
63 // import ext into the javascript context of the popover. This code might fail , | 55 // import ext into the javascript context of the popover. This code might fail , |
64 // when the background page isn't ready yet. So it is important to put it belo w | 56 // when the background page isn't ready yet. So it is important to put it belo w |
65 // the reloading code above. | 57 // the reloading code above. |
58 var backgroundPage = safari.extension.globalPage.contentWindow; | |
59 | |
66 window.ext = { | 60 window.ext = { |
67 __proto__: backgroundPage.ext, | 61 __proto__: backgroundPage.ext, |
68 closePopup: function() | 62 closePopup: function() |
69 { | 63 { |
70 safari.self.hide(); | 64 safari.self.hide(); |
71 valid = false; | |
72 } | 65 } |
73 }; | 66 }; |
74 window.TabMap = backgroundPage.TabMap; | 67 window.TabMap = backgroundPage.TabMap; |
75 })(); | 68 })(); |
OLD | NEW |