Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Delta Between Two Patch Sets: safari/ext/popup.js

Issue 6476185965953024: Adjust the size of the bubble to the size of its content in Safari (Closed)
Left Patch Set: Created Dec. 24, 2013, 12:42 p.m.
Right Patch Set: Adressed comments Created Jan. 16, 2014, 10:59 a.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « metadata.safari ('k') | no next file » | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
1 with (safari.extension.globalPage.contentWindow) 1 (function()
2 { 2 {
3 this.ext = ext; 3 // Safari will load the popover once, and then show it everytime the icon is
4 this.TabMap = TabMap; 4 // clicked. While Chrome loads it everytime you click the icon. So in order to
5 } 5 // force the same behavior in Safari, we are going to reload the page of the
6 // bubble everytime it is shown.
7 safari.application.addEventListener("popover", function()
8 {
9 document.documentElement.style.display = "none";
10 document.location.reload();
11 }, true);
6 12
7 // Safari will load the popover once, and then show it everytime the icon is
8 // clicked. While Chrome loads it everytime you click the icon. So in order to
9 // force the same behavior in Safari, we are going to reload the page of the
10 // bubble everytime it is shown.
11 safari.application.addEventListener("popover", function()
12 {
13 document.documentElement.style.display = "none";
14 document.location.reload();
15 }, true);
16 13
17 // Safari doesn't hide popovers automatically, when we change the active tab 14 // Safari doesn't adjust the size of the popover automatically to the size
18 // programmatically, like when the options link is clicked. So we add an event 15 // of its content, like when the ad counter is expanded/collapsed. So we add
19 // listener to do so. 16 // event listeners to do so.
20 safari.application.addEventListener("activate", function() 17 var updateSize = function()
21 { 18 {
22 safari.self.hide(); 19 safari.self.width = document.body.offsetWidth;
23 }, true); 20 safari.self.height = document.body.offsetHeight;
21 };
24 22
25 // Safari doesn't adjust the size of the popover automatically to the size of 23 window.addEventListener("load", function()
26 // its content, like when the ad counter is expanded/collapsed. So we add an 24 {
27 // event listener to do so. 25 updateSize();
28 document.addEventListener("DOMSubtreeModified", function() 26
29 { 27 var MutationObserver = window.MutationObserver || window.WebKitMutationObser ver;
30 safari.self.width = document.body.offsetWidth; 28 if (MutationObserver)
31 safari.self.height = document.body.offsetHeight; 29 {
Wladimir Palant 2014/01/15 15:47:13 What about document.documentElement.offsetWidth/He
Sebastian Noack 2014/01/15 17:21:52 No, it doesn't has the right value (sometimes?). D
32 }); 30 new MutationObserver(updateSize).observe(document, {
31 childList: true, attributes: true,
32 characterData: true, subtree: true
33 });
34 }
35 else
36 document.addEventListener("DOMSubtreeModified", updateSize);
37 });
38
39
40 // import ext into the javascript context of the popover. This code might fail ,
41 // when the background page isn't ready yet. So it is important to put it belo w
42 // the reloading code above.
43 var backgroundPage = safari.extension.globalPage.contentWindow;
44 window.ext = backgroundPage.ext;
45 window.TabMap = backgroundPage.TabMap;
46 })();
LEFTRIGHT

Powered by Google App Engine
This is Rietveld