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

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

Issue 5183241912844288: Issue 380 - Fixed width of bubble in Safari with long translated texts (Closed)
Left Patch Set: Created April 26, 2014, 1:34 p.m.
Right Patch Set: Addressed comments Created April 30, 2014, 3:37 p.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 | « popup.html ('k') | skin/popup.css » ('j') | 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 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
4 // 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
5 // event listeners to do so. 5 // event listeners to do so.
6 var mayResize = true; 6 var mayResize = true;
7 var resizingScheduled = false; 7 var resizingScheduled = false;
8 8
9 var updateSize = function() 9 var updateSize = function()
10 { 10 {
11 if (mayResize && !resizingScheduled) 11 if (mayResize && !resizingScheduled)
12 { 12 {
13 setTimeout(function() 13 setTimeout(function()
14 { 14 {
15 safari.self.width = document.body.scrollWidth; 15 safari.self.width = document.body.scrollWidth;
Sebastian Noack 2014/04/26 13:39:37 Safari doesn't count overflowing text caused by "w
16 safari.self.height = document.body.offsetHeight; 16 safari.self.height = document.body.offsetHeight;
17 17
18 resizingScheduled = false; 18 resizingScheduled = false;
19 }, 0); 19 }, 0);
20 20
21 resizingScheduled = true; 21 resizingScheduled = true;
22 } 22 }
23 }; 23 };
24 24
25 window.addEventListener("load", function() 25 window.addEventListener("load", function()
26 { 26 {
27 updateSize(); 27 updateSize();
28 28
29 var MutationObserver = window.MutationObserver || window.WebKitMutationObser ver; 29 var MutationObserver = window.MutationObserver || window.WebKitMutationObser ver;
30 if (MutationObserver) 30 if (MutationObserver)
31 { 31 {
32 new MutationObserver(updateSize).observe(document, { 32 new MutationObserver(updateSize).observe(document, {
33 childList: true, attributes: true, 33 childList: true, attributes: true,
34 characterData: true, subtree: true 34 characterData: true, subtree: true
35 }); 35 });
36 } 36 }
37 else 37 else
38 document.addEventListener("DOMSubtreeModified", updateSize); 38 document.addEventListener("DOMSubtreeModified", updateSize);
39 }); 39 });
40 40
41 // when using "white-space: nowrap", the overflown text overlaps the padding
42 // and neither clientWidth nor scrollWidth, we rely on when adjusting the size
43 // of the popover, inlcudes the overlapped area. So we have to use additional
44 // placeholders, in order to preserve padding. Since the dimensions of the
45 // popover are automatically correctly adjusted on Chrome, those placeholders
46 // would add extra empty space and therefore must only be rendered on Safari.
47 var style = document.createElement("style");
48 style.textContent = ".safari-inline-block { display: inline-block; }";
49 document.head.appendChild(style);
50
41 51
42 // Safari will load the popover once, and then show it everytime the icon is 52 // Safari will load the popover once, and then show it everytime the icon is
43 // clicked. While Chrome loads it everytime you click the icon. So in order to 53 // clicked. While Chrome loads it everytime you click the icon. So in order to
44 // make the popover show the right state and details, we have to emulate the 54 // make the popover show the right state and details, we have to emulate the
45 // same behavior as on Chrome, by reloading the popover every time it is shown . 55 // same behavior as on Chrome, by reloading the popover every time it is shown .
46 safari.self.addEventListener("popover", function() 56 safari.self.addEventListener("popover", function()
47 { 57 {
48 mayResize = false; 58 mayResize = false;
49 document.documentElement.style.display = "none"; 59 document.documentElement.style.display = "none";
50 document.location.reload(); 60 document.location.reload();
(...skipping 14 matching lines...) Expand all
65 // the reloading code above. 75 // the reloading code above.
66 window.ext = { 76 window.ext = {
67 __proto__: safari.extension.globalPage.contentWindow.ext, 77 __proto__: safari.extension.globalPage.contentWindow.ext,
68 78
69 closePopup: function() 79 closePopup: function()
70 { 80 {
71 safari.self.hide(); 81 safari.self.hide();
72 } 82 }
73 }; 83 };
74 })(); 84 })();
LEFTRIGHT

Powered by Google App Engine
This is Rietveld