Left: | ||
Right: |
LEFT | RIGHT |
---|---|
1 (function() | 1 (function() |
2 { | 2 { |
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 | |
5 // make the popover show the right state and details, we have to emulate the | |
6 // same behavior as on Chrome, by reloading the popover every time it is shown . | |
7 safari.self.addEventListener("popover", function() | |
8 { | |
9 mayResize = false; | |
10 document.documentElement.style.display = "none"; | |
11 document.location.reload(); | |
12 }); | |
13 | |
14 | |
15 // Safari doesn't adjust the size of the popover automatically to the size | 3 // Safari doesn't adjust the size of the popover automatically to the size |
16 // of its content, like when the ad counter is expanded/collapsed. So we add | 4 // of its content, like when the ad counter is expanded/collapsed. So we add |
17 // event listeners to do so. | 5 // event listeners to do so. |
18 var mayResize = true; | 6 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 | 7 |
20 var updateSize = function() | 8 var updateSize = function() |
21 { | 9 { |
22 if (mayResize) | 10 if (mayResize) |
23 { | 11 { |
24 safari.self.width = document.body.offsetWidth; | 12 safari.self.width = document.body.offsetWidth; |
25 safari.self.height = document.body.offsetHeight; | 13 safari.self.height = document.body.offsetHeight; |
26 } | 14 } |
27 }; | 15 }; |
28 | 16 |
29 window.addEventListener("load", function() | 17 window.addEventListener("load", function() |
30 { | 18 { |
31 updateSize(); | 19 updateSize(); |
32 | 20 |
33 var MutationObserver = window.MutationObserver || window.WebKitMutationObser ver; | 21 var MutationObserver = window.MutationObserver || window.WebKitMutationObser ver; |
34 if (MutationObserver) | 22 if (MutationObserver) |
35 { | 23 { |
36 new MutationObserver(updateSize).observe(document, { | 24 new MutationObserver(updateSize).observe(document, { |
37 childList: true, attributes: true, | 25 childList: true, attributes: true, |
38 characterData: true, subtree: true | 26 characterData: true, subtree: true |
39 }); | 27 }); |
40 } | 28 } |
41 else | 29 else |
42 document.addEventListener("DOMSubtreeModified", updateSize); | 30 document.addEventListener("DOMSubtreeModified", updateSize); |
43 }); | 31 }); |
44 | 32 |
45 | 33 |
34 // Safari will load the popover once, and then show it everytime the icon is | |
35 // clicked. While Chrome loads it everytime you click the icon. So in order to | |
36 // make the popover show the right state and details, we have to emulate the | |
37 // same behavior as on Chrome, by reloading the popover every time it is shown . | |
38 safari.self.addEventListener("popover", function() | |
39 { | |
40 mayResize = false; | |
41 document.documentElement.style.display = "none"; | |
42 document.location.reload(); | |
43 }); | |
44 | |
45 | |
46 // Safari doesn't hide popovers automatically, when we change the active tab | 46 // Safari doesn't hide popovers automatically, when we change the active tab |
47 // programmatically, like when the options link is clicked. So we add an event | 47 // programmatically, like when the options link is clicked. So we add an event |
48 // listener to do so. | 48 // listener to do so. |
49 safari.application.addEventListener("activate", function() | 49 safari.application.addEventListener("activate", function() |
50 { | 50 { |
51 safari.self.hide(); | 51 safari.self.hide(); |
52 }, true); | 52 }, true); |
53 | 53 |
54 | 54 |
55 // 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 , |
56 // 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 |
57 // the reloading code above. | 57 // the reloading code above. |
58 var backgroundPage = safari.extension.globalPage.contentWindow; | 58 var backgroundPage = safari.extension.globalPage.contentWindow; |
59 | 59 |
60 window.ext = { | 60 window.ext = { |
61 __proto__: backgroundPage.ext, | 61 __proto__: backgroundPage.ext, |
62 closePopup: function() | 62 closePopup: function() |
63 { | 63 { |
64 safari.self.hide(); | 64 safari.self.hide(); |
65 } | 65 } |
66 }; | 66 }; |
67 window.TabMap = backgroundPage.TabMap; | 67 window.TabMap = backgroundPage.TabMap; |
68 })(); | 68 })(); |
LEFT | RIGHT |