Commits

chaals committed a75d49b

Bump version to 1.4 - clean up the popup sizing to make it nicer

Comments (0)

Files changed (4)

 <?xml version="1.0" encoding="utf-8"?>
-<widget xmlns="http://www.w3.org/ns/widgets" version="1.3"
+<widget xmlns="http://www.w3.org/ns/widgets" version="1.4"
   defaultlocale="en">
   <name>Swaplang</name>
   <author href="http://my.opera.com/chaals">Chaals</author>

includes/swaplang-userjs.js

       tempObj[i] = {};
       tempObj[i].href = languageChoices[i].href;
       linksList.push(languageChoices[i].href);
-      if (languageChoices[i].tagName == "LINK")
+      if (languageChoices[i].title)
         tempObj[i].title = languageChoices[i].title;
       else
         tempObj[i].title = languageChoices[i].innerText;
-      longString = (longString.length > tempObj[i].title.length) ? longString : tempObj[i].title;
+      longString = (longString.length > tempObj[i].title.length) ? longString : tempObj[i].title;
+opera.postError('long string: '+longString)
       tempObj[i].hreflang = languageChoices[i].hreflang;
     }
     for (i in tempObj)
     if (listLength) {
       theInfo = {
 	"languagesAvailable"	: listLength,
-	"longestString"		: longString.length
+	"longestString"		: longString
       }
       opera.extension.postMessage(JSON.stringify(theInfo));
     } else
 <head>
 <meta name="Content-Type" content="text/html; charset = UTF-8">
 <title>Swaplang background page</title>
-<style>
+<style>
+  body {width:1000px}
   :link {text-decoration:none}
   a:hover {background: #ddd;}
-  * {margin: 0px ; padding: 0px}
+  * {margin: 0px ; padding: 0px; line-height:1em}
   p { line-height: 1.4em}
-  li { font-family: sans; margin-left: 1.5em; }
+  li { font-family: sans-serif; margin-left: 16px; line-height:1.1em}
 </style>
 </head>
 <body>
 <ul><li id="item">dummy</li></ul>
 
 <script>
-
-  var theSize = document.getElementById("item").currentStyle["fontSize"];
-  var fsize = parseInt(theSize.substring(0,theSize.indexOf('px')));
 
   var UIItemProperties = {
     disabled: true,
   
   //------------------------------------
   opera.extension.onmessage = function( event ){
-    // Messages are received by the background only from the userJS, and only when language selectors are found.
-    // If there are languages enable the button, set the height.
-    // Set the popup width to a size based on the longest string
-    // @@TODO: That should really be the offsetWidth from popup
     if (event.data == "none") 
       disableButton();
     else if (event.data == "ready") 
       requestChoices();
     else {
+    // The current tab is sending a menu to the popup.
+    // Use the info given to set the popup size and enable the button.
       var theInfo = JSON.parse(event.data);
-      theButton.popup.height = (theInfo.languagesAvailable * 1.2 + 2) * fsize;
-      theButton.popup.width = (theInfo.longestString + 2) * fsize / 2;
+      var theSpan = document.createElement('span');
+      theSpan.innerText = theInfo.longestString;
+      document.getElementById('item').appendChild(theSpan);
+      var baseWidth = theSpan.offsetWidth;
+      var theSize = theSpan.currentStyle["fontSize"];
+      var baseHeight = parseInt(theSize.substring(0,theSize.indexOf('px')));
+
+      theButton.popup.height = ((1.15 * theInfo.languagesAvailable + 1.5) * baseHeight);
+      theButton.popup.width = baseWidth + 16;
       enableButton();
     }
   }
 
-  //If a popup connects, and there is a focused active tab,
-  // forward a port to get the menu
+  //If a popup connects, forward a port to current tab for the menu
   opera.extension.onconnect = function( event ){
     var currentTab = opera.extension.tabs.getFocused();
     if (currentTab && event.origin.indexOf("popup.html") > -1 && event.origin.indexOf('widget://') > -1) {
 <style>
   :link {text-decoration:none}
   a:hover {background: #ddd;}
-  * {margin: 0px ; padding: 0px}
+  * {margin: 0px ; padding: 0px; line-height:1em}
   p { line-height: 1.4em}
-  li { font-family: sans-serif; margin-left: 1.5em; }
+  li { font-family: sans-serif; margin-left: 16px; line-height:1.1em}
 </style>
 <script src="strings.js"></script>
 </head>
       var languageChoices = JSON.parse(event.data);
       var theList = document.getElementById('list');
       for (i in languageChoices) {
-opera.postError(("processing item " + i));
       //JSON data has a length and item attribute, which has to be ignored.
         if(i == "length" || i == "item") continue;
       
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.