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: Rebased and fixed some issues Created Jan. 15, 2014, 5:10 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 (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 // force the same behavior in Safari, we are going to reload the page of the 5 // force the same behavior in Safari, we are going to reload the page of the
6 // bubble everytime it is shown. 6 // bubble everytime it is shown.
7 safari.application.addEventListener("popover", function() 7 safari.application.addEventListener("popover", function()
8 { 8 {
9 document.documentElement.style.display = "none"; 9 document.documentElement.style.display = "none";
10 document.location.reload(); 10 document.location.reload();
11 }, true); 11 }, true);
12 12
13 13
14 // Safari doesn't adjust the size of the popover automatically to the size 14 // Safari doesn't adjust the size of the popover automatically to the size
15 // of its content, like when the ad counter is expanded/collapsed. So we add 15 // of its content, like when the ad counter is expanded/collapsed. So we add
16 // event listeners to do so. 16 // event listeners to do so.
17 var updateSize = function() 17 var updateSize = function()
18 { 18 {
19 safari.self.width = document.body.offsetWidth; 19 safari.self.width = document.body.offsetWidth;
20 safari.self.height = document.body.offsetHeight; 20 safari.self.height = document.body.offsetHeight;
21 }; 21 };
22 22
23 window.addEventListener("load", function() 23 window.addEventListener("load", function()
24 { 24 {
25 updateSize(); 25 updateSize();
26 26
27 if ("WebKitMutationObserver" in window) 27 var MutationObserver = window.MutationObserver || window.WebKitMutationObser ver;
Wladimir Palant 2014/01/16 07:55:59 We should go for the standardized name first, futu
Sebastian Noack 2014/01/16 11:00:31 Done.
28 new WebKitMutationObserver(updateSize).observe(document, { 28 if (MutationObserver)
29 {
30 new MutationObserver(updateSize).observe(document, {
29 childList: true, attributes: true, 31 childList: true, attributes: true,
30 characterData: true, subtree: true 32 characterData: true, subtree: true
31 }); 33 });
34 }
32 else 35 else
33 document.addEventListener("DOMSubtreeModified", updateSize); 36 document.addEventListener("DOMSubtreeModified", updateSize);
34 }); 37 });
35 38
36 39
37 // import ext into the javascript context of the popover. This code might fail , 40 // import ext into the javascript context of the popover. This code might fail ,
38 // when the background page isn't ready yet. So it is important to put it belo w 41 // when the background page isn't ready yet. So it is important to put it belo w
39 // the reloading code above. 42 // the reloading code above.
40 var backgroundPage = safari.extension.globalPage.contentWindow; 43 var backgroundPage = safari.extension.globalPage.contentWindow;
41 ext = backgroundPage.ext; 44 window.ext = backgroundPage.ext;
42 TabMap = backgroundPage.TabMap; 45 window.TabMap = backgroundPage.TabMap;
43 })(); 46 })();
LEFTRIGHT

Powered by Google App Engine
This is Rietveld