Author: scottbw
Date: Tue Mar  9 10:58:01 2010
New Revision: 920794

URL: http://svn.apache.org/viewvc?rev=920794&view=rev
Log:
Updated widgets to use the current localization model and removed dependencies 
on shared language helper and util JS in wookie-wrapper.js (see WOOKIE-97). 
This means that there are fewer objects in the global space - just the Widget 
object itself - and that wookie-wrapper.js is much smaller and loads faster.

Added:
    incubator/wookie/trunk/widgets/chat/languageHelper.js
    incubator/wookie/trunk/widgets/chat/widgetUtils.js
    incubator/wookie/trunk/widgets/forum/languageHelper.js
    incubator/wookie/trunk/widgets/forum/widgetUtils.js
    incubator/wookie/trunk/widgets/vote/languageHelper.js
    incubator/wookie/trunk/widgets/vote/widgetUtils.js
Modified:
    incubator/wookie/trunk/WebContent/shared/js/wookie-wrapper.js
    incubator/wookie/trunk/widgets/chat/chat.js
    incubator/wookie/trunk/widgets/chat/index.htm
    incubator/wookie/trunk/widgets/forum/config.xml
    incubator/wookie/trunk/widgets/forum/forumutils.js
    incubator/wookie/trunk/widgets/forum/index.htm
    incubator/wookie/trunk/widgets/vote/index.htm
    incubator/wookie/trunk/widgets/vote/vote.js
    incubator/wookie/trunk/widgets/weather/weather.js

Modified: incubator/wookie/trunk/WebContent/shared/js/wookie-wrapper.js
URL: 
http://svn.apache.org/viewvc/incubator/wookie/trunk/WebContent/shared/js/wookie-wrapper.js?rev=920794&r1=920793&r2=920794&view=diff
==============================================================================
--- incubator/wookie/trunk/WebContent/shared/js/wookie-wrapper.js (original)
+++ incubator/wookie/trunk/WebContent/shared/js/wookie-wrapper.js Tue Mar  9 
10:58:01 2010
@@ -225,326 +225,6 @@ widget = Widget;
 window.widget = Widget;
 
 
-/*
- * Language helper object
- */
-var LanguageHelper = {
-
-       currentLanguage : "en",
-       supportedLanguages : new Array("bu","en","fr","nl"),
-       lCallbackFunctName : null, // This is a callback function to be called 
once the language is changed in a widget
-       
-       
-       init : function(){
-               Widget.preferenceForKey("locale", 
this.setDefaultLanguageFromPrefs);
-       },
-       
-       setDefaultLanguageFromPrefs : function(res){
-               if(res != "null"){
-                               this.currentLanguage = res;
-               }
-       },
-
-       getLangOpts : function(callbackFunct) {
-               var langOptionStr = "<select name=\"select_lang\" 
id=\"select_lang\" 
onchange=\"LanguageHelper.doLanguageUpdate(this.options[this.selectedIndex].value);\">"
 ;
-               var optStr; 
-               for (alang in this.supportedLanguages){
-                       if(this.supportedLanguages[alang] == 
this.currentLanguage){
-                               optStr = "<option value=\"" + 
this.supportedLanguages[alang] + "\" selected>" + 
this.supportedLanguages[alang] + "</option>";
-                       }
-                       else{
-                               optStr = "<option value=\"" + 
this.supportedLanguages[alang] + "\">" + this.supportedLanguages[alang] + 
"</option>";
-                       }
-                       langOptionStr += optStr;
-               }
-               langOptionStr += "</select>";
-               lCallbackFunctName = callbackFunct;
-               return langOptionStr;
-       },
-
-       getLocalizedString : function(key) {
-               try {
-                       var evalString = this.currentLanguage + "_" + 
"localizedStrings['"+key+"'];";           
-                       var ret = eval(evalString);
-                       if (ret === undefined)
-                               ret = key;
-                       return ret;
-               }
-               catch (ex) {
-               }
-               return key;
-       },
-
-       doLanguageUpdate : function(la){
-               this.currentLanguage = la;
-               Widget.setPreferenceForKey("locale", this.currentLanguage);
-               lCallbackFunctName();
-       }
-
-}
-LanguageHelper.init();
-
-/*
- *  Browser sniffer
- */
-var BrowserDetect = {
-               init: function () {
-                       this.browser = this.searchString(this.dataBrowser) || 
"An unknown browser";
-                       this.version = this.searchVersion(navigator.userAgent)
-                               || this.searchVersion(navigator.appVersion)
-                               || "an unknown version";
-                       this.OS = this.searchString(this.dataOS) || "an unknown 
OS";            
-               },
-               isBrowser: function (bName) {
-                       if(this.browser==bName){
-                               return true;
-                       }
-                       else{
-                               return false;
-                       }
-               },
-               searchString: function (data) {
-                       for (var i=0;i<data.length;i++) {
-                               var dataString = data[i].string;
-                               var dataProp = data[i].prop;
-                               this.versionSearchString = 
data[i].versionSearch || data[i].identity;
-                               if (dataString) {
-                                       if 
(dataString.indexOf(data[i].subString) != -1)
-                                               return data[i].identity;
-                               }
-                               else if (dataProp)
-                                       return data[i].identity;
-                       }
-               },
-               searchVersion: function (dataString) {
-                       var index = 
dataString.indexOf(this.versionSearchString);
-                       if (index == -1) return;
-                       return 
parseFloat(dataString.substring(index+this.versionSearchString.length+1));
-               },
-               dataBrowser: [
-                       {       string: navigator.userAgent,
-                               subString: "OmniWeb",
-                               versionSearch: "OmniWeb/",
-                               identity: "OmniWeb"
-                       },
-                       {
-                               string: navigator.vendor,
-                               subString: "Apple",
-                               identity: "Safari"
-                       },
-                       {
-                               prop: window.opera,
-                               identity: "Opera"
-                       },
-                       {
-                               string: navigator.vendor,
-                               subString: "iCab",
-                               identity: "iCab"
-                       },
-                       {
-                               string: navigator.vendor,
-                               subString: "KDE",
-                               identity: "Konqueror"
-                       },
-                       {
-                               string: navigator.userAgent,
-                               subString: "Firefox",
-                               identity: "Firefox"
-                       },
-                       {
-                               string: navigator.vendor,
-                               subString: "Camino",
-                               identity: "Camino"
-                       },
-                       {               // for newer Netscapes (6+)
-                               string: navigator.userAgent,
-                               subString: "Netscape",
-                               identity: "Netscape"
-                       },
-                       {
-                               string: navigator.userAgent,
-                               subString: "MSIE",
-                               identity: "Explorer",
-                               versionSearch: "MSIE"
-                       },
-                       {
-                               string: navigator.userAgent,
-                               subString: "Gecko",
-                               identity: "Mozilla",
-                               versionSearch: "rv"
-                       },
-                       {               // for older Netscapes (4-)
-                               string: navigator.userAgent,
-                               subString: "Mozilla",
-                               identity: "Netscape",
-                               versionSearch: "Mozilla"
-                       }
-               ],
-               dataOS : [
-                       {
-                               string: navigator.platform,
-                               subString: "Win",
-                               identity: "Windows"
-                       },
-                       {
-                               string: navigator.platform,
-                               subString: "Mac",
-                               identity: "Mac"
-                       },
-                       {
-                               string: navigator.platform,
-                               subString: "Linux",
-                               identity: "Linux"
-                       }
-               ]
-
-       };
-BrowserDetect.init();
-
-
-/*
- * Replace text function - overloaded on strings
- */
- String.prototype.replaceAll = function(strTarget, strSubString){
-       var strText = this;
-       var intIndexOfMatch = strText.indexOf( strTarget );
-  
-       // Keep looping while an instance of the target string
-       // still exists in the string.
-       while (intIndexOfMatch != -1){
-               // Relace out the current instance.
-               strText = strText.replace( strTarget, strSubString )
-               // Get the index of any next matching substring.
-               intIndexOfMatch = strText.indexOf( strTarget );
-       }
-  
-       // Return the updated string with ALL the target strings
-       // replaced out with the new substring.
-       return( strText );
- }
-
- 
- /*
-  * Utility class
-  */
- var WidgetUtil = {
-                
-        generate3DigitRandomNumber : function(){
-               return Math.floor((Math.random() * 900) + 100);
-        },
-                
-        generateRandomHexColor : function(){
-                               colors = new Array(14)
-                               colors[0]="0"
-                               colors[1]="1"
-                               colors[2]="2"
-                               colors[3]="3"
-                               colors[4]="4"
-                               colors[5]="5"
-                               colors[5]="6"
-                               colors[6]="7"
-                               colors[7]="8"
-                               colors[8]="9"
-                               colors[9]="a"
-                               colors[10]="b"
-                               colors[11]="c"
-                               colors[12]="d"
-                               colors[13]="e"
-                               colors[14]="f"
-
-                               digit = new Array(5)
-                               color=""
-                               for (i=0;i<6;i++){
-                                       
digit[i]=colors[Math.round(Math.random()*14)]
-                                       color = color+digit[i]
-                               }
-                               return color;
-                       },
-                       
-                       findObj : function (n, d) {
-                               var p,i,x; if(!d) d=document;
-                               if((p=n.indexOf("?"))>0&&parent.frames.length) {
-                                       
d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);
-                               }
-                               if(!(x=d[n])&&d.all) x=d.all[n]; for 
(i=0;!x&&i<d.forms.length;i++)
-                                       x=d.forms[i][n];
-                                       
for(i=0;!x&&d.layers&&i<d.layers.length;i++)
-                                               
x=findObj(n,d.layers[i].document);
-                                       if(!x && document.getElementById) 
x=document.getElementById(n); return x;
-                       },
-                       
-                       roundNumber : function (num, dec) {
-                               var result = 
Math.round(num*Math.pow(10,dec))/Math.pow(10,dec);
-                               return result;
-                       },
-                       
-                       onReturn : function(event, sendMessage){
-                               dwr.util.onReturn(event, sendMessage)
-                       },
-                       
-                       getValue : function(fName){                             
-                               return dwr.util.getValue(fName);
-                       },
-               
-                       setValue : function(fName, fValue, options){            
                
-                               dwr.util.setValue(fName, fValue, options);
-                       },
-               
-                       escapeHtml : function(text){
-                               return dwr.util.escapeHtml(text);
-                       },
-                       
-                       byId : function(id){
-                               return dwr.util.byId(id);
-                       }
- }
- 
-/*
- * simple debug window
- */
-var DebugHelper = {
-               
-       winLength : 800,
-       winHeight : 200,
-       debugLog : "",
-       
-       debug : function(p){
-               result = this.cleanInput(p);
-               this.debugLog+="<tr><td>";
-               this.debugLog+=result;
-               this.debugLog+="<hr/></td></tr>";
-               this.writeConsole(this.debugLog);       
-       },
-
-       cleanInput : function(p){
-               removedOpenBracket = p.replaceAll( "<", "&lt;" )
-               removedClosedBracket = removedOpenBracket.replaceAll( ">", 
"&gt;" )
-               result = removedClosedBracket;
-               return result;
-       },
-
-       writeConsole : function(content) {
-                consoleRef=window.open('','myconsole',
-                 'width=' + this.winLength + ',height=' + this.winHeight
-                  +',menubar=0'
-                  +',toolbar=1'
-                  +',status=0'
-                  +',scrollbars=1'
-                  +',resizable=1')     
-                  
-                consoleRef.document.writeln(
-                 '<html><head>'                                  
-                +'<title>Debug</title></head>'
-                +'<body bgcolor=white><table width=' + this.winLength + '>'
-                +content+'<table><a name="bottom"></a></body></html>'
-                )
-                consoleRef.onLoad = consoleRef.scrollTo(0,999999);
-                consoleRef.document.close()
-       }
-
-}
-
-
 
 
 

Modified: incubator/wookie/trunk/widgets/chat/chat.js
URL: 
http://svn.apache.org/viewvc/incubator/wookie/trunk/widgets/chat/chat.js?rev=920794&r1=920793&r2=920794&view=diff
==============================================================================
--- incubator/wookie/trunk/widgets/chat/chat.js (original)
+++ incubator/wookie/trunk/widgets/chat/chat.js Tue Mar  9 10:58:01 2010
@@ -94,7 +94,7 @@ function getInputInactiveDiv() {
 }
 
 function getInputActiveDiv(){
-       var inputactivediv = LanguageHelper.getLangOpts(updateLanguage) + 
"<input id=\"text\" size=\"30\" onkeypress=\"WidgetUtil.onReturn(event, 
sendMessage)\"/>";
+       var inputactivediv = "<input id=\"text\" size=\"30\" 
onkeypress=\"WidgetUtil.onReturn(event, sendMessage)\"/>";
        inputactivediv += "<input type=\"button\" value=\"" + 
LanguageHelper.getLocalizedString('Send') + "\" 
onclick=\"sendMessage()\"/>&nbsp;";
        if(isAdminUser()){
                inputactivediv += getAdminLockText();
@@ -102,21 +102,6 @@ function getInputActiveDiv(){
        return inputactivediv;
 }
 
-function updateLanguage(){
-       WidgetUtil.setValue("memberslegend", 
LanguageHelper.getLocalizedString('online users'),  { escapeHtml:false });
-       // check to see if we are locked or not first and call callback function
-       Widget.sharedDataForKey("isLocked", updateLanguageLockedOrNot);
-}
-
-function updateLanguageLockedOrNot(isLockedValue){
-       if(isLockedValue!="true"){      
-               WidgetUtil.setValue("joined", getInputActiveDiv(),  { 
escapeHtml:false });
-       }
-       else{
-               WidgetUtil.setValue("joined", getInputInactiveDiv(), { 
escapeHtml:false });
-       }               
-}
-
 function confirmClearChat(){
        var confirmText = LanguageHelper.getLocalizedString('Are you sure you 
want to clear the chat log?');
        confirmText += "\n\n";
@@ -154,9 +139,6 @@ function cleanup() {
                var removed = userList.replace(currentUser,"");
                Widget.setSharedDataForKey("defaultChatPresence",removed);      
                Widget.appendSharedDataForKey("defaultChatLog", chatSeparator + 
"<" + username + " " + LanguageHelper.getLocalizedString('has left the 
chatroom') + ">" + chatSeparator);
-               if(!BrowserDetect.isBrowser('Firefox')){
-                       alert(LanguageHelper.getLocalizedString('You have now 
logged out'));
-               }
                if (isDebug) DebugHelper.debug("<function cleanup> end");       
                                                                                
                                                                                
                
        }
 }

Modified: incubator/wookie/trunk/widgets/chat/index.htm
URL: 
http://svn.apache.org/viewvc/incubator/wookie/trunk/widgets/chat/index.htm?rev=920794&r1=920793&r2=920794&view=diff
==============================================================================
--- incubator/wookie/trunk/widgets/chat/index.htm (original)
+++ incubator/wookie/trunk/widgets/chat/index.htm Tue Mar  9 10:58:01 2010
@@ -5,8 +5,9 @@
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
        <title>Chat Widget</title> 
        <script type='text/javascript' src='chat.js'> </script>    
-       <script type='text/javascript' src='locales/en/localizedStrings.js'> 
</script>
-       <script type='text/javascript' src='locales/bu/localizedStrings.js'> 
</script>
+       <script type='text/javascript' src='languageHelper.js'> </script>
+       <script type='text/javascript' src='localizedStrings.js'> </script>
+       <script type='text/javascript' src='widgetUtils.js'> </script>
        <link rel="stylesheet" href="chat.css" type="text/css"/>   
 </head>
 <body onload="init()"> 

Added: incubator/wookie/trunk/widgets/chat/languageHelper.js
URL: 
http://svn.apache.org/viewvc/incubator/wookie/trunk/widgets/chat/languageHelper.js?rev=920794&view=auto
==============================================================================
--- incubator/wookie/trunk/widgets/chat/languageHelper.js (added)
+++ incubator/wookie/trunk/widgets/chat/languageHelper.js Tue Mar  9 10:58:01 
2010
@@ -0,0 +1,18 @@
+/*
+ * Language helper object
+ */
+var LanguageHelper = {
+
+       getLocalizedString : function(key) {
+               try {
+                       var evalString = "localizedStrings['"+key+"'];";        
        
+                       var ret = eval(evalString);
+                       if (ret === undefined)
+                               ret = key;
+                       return ret;
+               }
+               catch (ex) {
+               }
+               return key;
+       }
+}
\ No newline at end of file

Added: incubator/wookie/trunk/widgets/chat/widgetUtils.js
URL: 
http://svn.apache.org/viewvc/incubator/wookie/trunk/widgets/chat/widgetUtils.js?rev=920794&view=auto
==============================================================================
--- incubator/wookie/trunk/widgets/chat/widgetUtils.js (added)
+++ incubator/wookie/trunk/widgets/chat/widgetUtils.js Tue Mar  9 10:58:01 2010
@@ -0,0 +1,141 @@
+/*
+ * Replace text function - overloaded on strings
+ */
+ String.prototype.replaceAll = function(strTarget, strSubString){
+       var strText = this;
+       var intIndexOfMatch = strText.indexOf( strTarget );
+  
+       // Keep looping while an instance of the target string
+       // still exists in the string.
+       while (intIndexOfMatch != -1){
+               // Relace out the current instance.
+               strText = strText.replace( strTarget, strSubString )
+               // Get the index of any next matching substring.
+               intIndexOfMatch = strText.indexOf( strTarget );
+       }
+  
+       // Return the updated string with ALL the target strings
+       // replaced out with the new substring.
+       return( strText );
+ }
+
+ 
+ /*
+  * Utility class
+  */
+ var WidgetUtil = {
+                
+        generate3DigitRandomNumber : function(){
+               return Math.floor((Math.random() * 900) + 100);
+        },
+                
+        generateRandomHexColor : function(){
+                               colors = new Array(14)
+                               colors[0]="0"
+                               colors[1]="1"
+                               colors[2]="2"
+                               colors[3]="3"
+                               colors[4]="4"
+                               colors[5]="5"
+                               colors[5]="6"
+                               colors[6]="7"
+                               colors[7]="8"
+                               colors[8]="9"
+                               colors[9]="a"
+                               colors[10]="b"
+                               colors[11]="c"
+                               colors[12]="d"
+                               colors[13]="e"
+                               colors[14]="f"
+
+                               digit = new Array(5)
+                               color=""
+                               for (i=0;i<6;i++){
+                                       
digit[i]=colors[Math.round(Math.random()*14)]
+                                       color = color+digit[i]
+                               }
+                               return color;
+                       },
+                       
+                       findObj : function (n, d) {
+                               var p,i,x; if(!d) d=document;
+                               if((p=n.indexOf("?"))>0&&parent.frames.length) {
+                                       
d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);
+                               }
+                               if(!(x=d[n])&&d.all) x=d.all[n]; for 
(i=0;!x&&i<d.forms.length;i++)
+                                       x=d.forms[i][n];
+                                       
for(i=0;!x&&d.layers&&i<d.layers.length;i++)
+                                               
x=findObj(n,d.layers[i].document);
+                                       if(!x && document.getElementById) 
x=document.getElementById(n); return x;
+                       },
+                       
+                       roundNumber : function (num, dec) {
+                               var result = 
Math.round(num*Math.pow(10,dec))/Math.pow(10,dec);
+                               return result;
+                       },
+                       
+                       onReturn : function(event, sendMessage){
+                               dwr.util.onReturn(event, sendMessage)
+                       },
+                       
+                       getValue : function(fName){                             
+                               return dwr.util.getValue(fName);
+                       },
+               
+                       setValue : function(fName, fValue, options){            
                
+                               dwr.util.setValue(fName, fValue, options);
+                       },
+               
+                       escapeHtml : function(text){
+                               return dwr.util.escapeHtml(text);
+                       },
+                       
+                       byId : function(id){
+                               return dwr.util.byId(id);
+                       }
+ }
+ 
+/*
+ * simple debug window
+ */
+var DebugHelper = {
+               
+       winLength : 800,
+       winHeight : 200,
+       debugLog : "",
+       
+       debug : function(p){
+               result = this.cleanInput(p);
+               this.debugLog+="<tr><td>";
+               this.debugLog+=result;
+               this.debugLog+="<hr/></td></tr>";
+               this.writeConsole(this.debugLog);       
+       },
+
+       cleanInput : function(p){
+               removedOpenBracket = p.replaceAll( "<", "&lt;" )
+               removedClosedBracket = removedOpenBracket.replaceAll( ">", 
"&gt;" )
+               result = removedClosedBracket;
+               return result;
+       },
+
+       writeConsole : function(content) {
+                consoleRef=window.open('','myconsole',
+                 'width=' + this.winLength + ',height=' + this.winHeight
+                  +',menubar=0'
+                  +',toolbar=1'
+                  +',status=0'
+                  +',scrollbars=1'
+                  +',resizable=1')     
+                  
+                consoleRef.document.writeln(
+                 '<html><head>'                                  
+                +'<title>Debug</title></head>'
+                +'<body bgcolor=white><table width=' + this.winLength + '>'
+                +content+'<table><a name="bottom"></a></body></html>'
+                )
+                consoleRef.onLoad = consoleRef.scrollTo(0,999999);
+                consoleRef.document.close()
+       }
+
+}
\ No newline at end of file

Modified: incubator/wookie/trunk/widgets/forum/config.xml
URL: 
http://svn.apache.org/viewvc/incubator/wookie/trunk/widgets/forum/config.xml?rev=920794&r1=920793&r2=920794&view=diff
==============================================================================
--- incubator/wookie/trunk/widgets/forum/config.xml (original)
+++ incubator/wookie/trunk/widgets/forum/config.xml Tue Mar  9 10:58:01 2010
@@ -1,5 +1,5 @@
 <?xml version="1.0" encoding="utf-8"?>
-<widget xmlns="http://www.w3.org/ns/widgets"; 
id="http://www.getwookie.org/widgets/chat"; height="350" width="520">
+<widget xmlns="http://www.w3.org/ns/widgets"; 
id="http://www.getwookie.org/widgets/forum"; height="350" width="520">
        <name>Forum</name>
        <description>basic forum widget</description>
        <icon src="icon.png"/>

Modified: incubator/wookie/trunk/widgets/forum/forumutils.js
URL: 
http://svn.apache.org/viewvc/incubator/wookie/trunk/widgets/forum/forumutils.js?rev=920794&r1=920793&r2=920794&view=diff
==============================================================================
--- incubator/wookie/trunk/widgets/forum/forumutils.js (original)
+++ incubator/wookie/trunk/widgets/forum/forumutils.js Tue Mar  9 10:58:01 2010
@@ -88,7 +88,7 @@ function getInactiveToolsStr(){
 }
 
 function getActiveToolsStr(){
-       var activeToolsStr = "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;" + 
LanguageHelper.getLangOpts(getActiveToolsStrUpdated);
+       var activeToolsStr = "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";
        activeToolsStr += "<a href=\"#\" onclick=\"postNewTopic(-1)\"><img 
border=\"0\" src=\"/wookie/shared/images/plus.gif\">&nbsp;" + 
LanguageHelper.getLocalizedString('Post new topic') + "</a>";
        activeToolsStr += "&nbsp;&nbsp;<a href=\"#\" 
onclick=\"forum.getNodeTree('"+instanceid_key+"', getTreeData);\"><img 
border=\"0\" src=\"/wookie/shared/images/refresh.gif\">&nbsp;" + 
LanguageHelper.getLocalizedString('Refresh') + "</a>";
        if(isAdminUser()){

Modified: incubator/wookie/trunk/widgets/forum/index.htm
URL: 
http://svn.apache.org/viewvc/incubator/wookie/trunk/widgets/forum/index.htm?rev=920794&r1=920793&r2=920794&view=diff
==============================================================================
--- incubator/wookie/trunk/widgets/forum/index.htm (original)
+++ incubator/wookie/trunk/widgets/forum/index.htm Tue Mar  9 10:58:01 2010
@@ -5,8 +5,9 @@
   <title>Default Forum Widget</title>
   <script type='text/javascript' src='/wookie/dwr/interface/forum.js'> 
</script>
   <script type='text/javascript' src='forumutils.js'> </script>  
-  <script type='text/javascript' src='locales/en/localizedStrings.js'> 
</script>
-  <script type='text/javascript' src='locales/bu/localizedStrings.js'> 
</script>
+  <script type='text/javascript' src='localizedStrings.js'> </script>
+  <script type='text/javascript' src='languageHelper.js'> </script>
+  <script type='text/javascript' src='widgetUtils.js'> </script>
   <link rel="stylesheet" href="forum.css" type="text/css"/>   
 </head>
 <body onload="init()"> 

Added: incubator/wookie/trunk/widgets/forum/languageHelper.js
URL: 
http://svn.apache.org/viewvc/incubator/wookie/trunk/widgets/forum/languageHelper.js?rev=920794&view=auto
==============================================================================
--- incubator/wookie/trunk/widgets/forum/languageHelper.js (added)
+++ incubator/wookie/trunk/widgets/forum/languageHelper.js Tue Mar  9 10:58:01 
2010
@@ -0,0 +1,18 @@
+/*
+ * Language helper object
+ */
+var LanguageHelper = {
+
+       getLocalizedString : function(key) {
+               try {
+                       var evalString = "localizedStrings['"+key+"'];";        
        
+                       var ret = eval(evalString);
+                       if (ret === undefined)
+                               ret = key;
+                       return ret;
+               }
+               catch (ex) {
+               }
+               return key;
+       }
+}
\ No newline at end of file

Added: incubator/wookie/trunk/widgets/forum/widgetUtils.js
URL: 
http://svn.apache.org/viewvc/incubator/wookie/trunk/widgets/forum/widgetUtils.js?rev=920794&view=auto
==============================================================================
--- incubator/wookie/trunk/widgets/forum/widgetUtils.js (added)
+++ incubator/wookie/trunk/widgets/forum/widgetUtils.js Tue Mar  9 10:58:01 2010
@@ -0,0 +1,141 @@
+/*
+ * Replace text function - overloaded on strings
+ */
+ String.prototype.replaceAll = function(strTarget, strSubString){
+       var strText = this;
+       var intIndexOfMatch = strText.indexOf( strTarget );
+  
+       // Keep looping while an instance of the target string
+       // still exists in the string.
+       while (intIndexOfMatch != -1){
+               // Relace out the current instance.
+               strText = strText.replace( strTarget, strSubString )
+               // Get the index of any next matching substring.
+               intIndexOfMatch = strText.indexOf( strTarget );
+       }
+  
+       // Return the updated string with ALL the target strings
+       // replaced out with the new substring.
+       return( strText );
+ }
+
+ 
+ /*
+  * Utility class
+  */
+ var WidgetUtil = {
+                
+        generate3DigitRandomNumber : function(){
+               return Math.floor((Math.random() * 900) + 100);
+        },
+                
+        generateRandomHexColor : function(){
+                               colors = new Array(14)
+                               colors[0]="0"
+                               colors[1]="1"
+                               colors[2]="2"
+                               colors[3]="3"
+                               colors[4]="4"
+                               colors[5]="5"
+                               colors[5]="6"
+                               colors[6]="7"
+                               colors[7]="8"
+                               colors[8]="9"
+                               colors[9]="a"
+                               colors[10]="b"
+                               colors[11]="c"
+                               colors[12]="d"
+                               colors[13]="e"
+                               colors[14]="f"
+
+                               digit = new Array(5)
+                               color=""
+                               for (i=0;i<6;i++){
+                                       
digit[i]=colors[Math.round(Math.random()*14)]
+                                       color = color+digit[i]
+                               }
+                               return color;
+                       },
+                       
+                       findObj : function (n, d) {
+                               var p,i,x; if(!d) d=document;
+                               if((p=n.indexOf("?"))>0&&parent.frames.length) {
+                                       
d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);
+                               }
+                               if(!(x=d[n])&&d.all) x=d.all[n]; for 
(i=0;!x&&i<d.forms.length;i++)
+                                       x=d.forms[i][n];
+                                       
for(i=0;!x&&d.layers&&i<d.layers.length;i++)
+                                               
x=findObj(n,d.layers[i].document);
+                                       if(!x && document.getElementById) 
x=document.getElementById(n); return x;
+                       },
+                       
+                       roundNumber : function (num, dec) {
+                               var result = 
Math.round(num*Math.pow(10,dec))/Math.pow(10,dec);
+                               return result;
+                       },
+                       
+                       onReturn : function(event, sendMessage){
+                               dwr.util.onReturn(event, sendMessage)
+                       },
+                       
+                       getValue : function(fName){                             
+                               return dwr.util.getValue(fName);
+                       },
+               
+                       setValue : function(fName, fValue, options){            
                
+                               dwr.util.setValue(fName, fValue, options);
+                       },
+               
+                       escapeHtml : function(text){
+                               return dwr.util.escapeHtml(text);
+                       },
+                       
+                       byId : function(id){
+                               return dwr.util.byId(id);
+                       }
+ }
+ 
+/*
+ * simple debug window
+ */
+var DebugHelper = {
+               
+       winLength : 800,
+       winHeight : 200,
+       debugLog : "",
+       
+       debug : function(p){
+               result = this.cleanInput(p);
+               this.debugLog+="<tr><td>";
+               this.debugLog+=result;
+               this.debugLog+="<hr/></td></tr>";
+               this.writeConsole(this.debugLog);       
+       },
+
+       cleanInput : function(p){
+               removedOpenBracket = p.replaceAll( "<", "&lt;" )
+               removedClosedBracket = removedOpenBracket.replaceAll( ">", 
"&gt;" )
+               result = removedClosedBracket;
+               return result;
+       },
+
+       writeConsole : function(content) {
+                consoleRef=window.open('','myconsole',
+                 'width=' + this.winLength + ',height=' + this.winHeight
+                  +',menubar=0'
+                  +',toolbar=1'
+                  +',status=0'
+                  +',scrollbars=1'
+                  +',resizable=1')     
+                  
+                consoleRef.document.writeln(
+                 '<html><head>'                                  
+                +'<title>Debug</title></head>'
+                +'<body bgcolor=white><table width=' + this.winLength + '>'
+                +content+'<table><a name="bottom"></a></body></html>'
+                )
+                consoleRef.onLoad = consoleRef.scrollTo(0,999999);
+                consoleRef.document.close()
+       }
+
+}
\ No newline at end of file

Modified: incubator/wookie/trunk/widgets/vote/index.htm
URL: 
http://svn.apache.org/viewvc/incubator/wookie/trunk/widgets/vote/index.htm?rev=920794&r1=920793&r2=920794&view=diff
==============================================================================
--- incubator/wookie/trunk/widgets/vote/index.htm (original)
+++ incubator/wookie/trunk/widgets/vote/index.htm Tue Mar  9 10:58:01 2010
@@ -5,8 +5,9 @@
   <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
   <title>Default Vote Widget</title>
   <script type='text/javascript' src='vote.js'> </script>  
-  <script type='text/javascript' src='locales/en/localizedStrings.js'> 
</script>
-  <script type='text/javascript' src='locales/bu/localizedStrings.js'> 
</script>
+  <script type='text/javascript' src='languageHelper.js'> </script>
+  <script type='text/javascript' src='localizedStrings.js'> </script>
+  <script type='text/javascript' src='widgetUtils.js'> </script>
   <link rel="stylesheet" href="vote.css" type="text/css"/>
 </head>
 <body onload="init()"> 

Added: incubator/wookie/trunk/widgets/vote/languageHelper.js
URL: 
http://svn.apache.org/viewvc/incubator/wookie/trunk/widgets/vote/languageHelper.js?rev=920794&view=auto
==============================================================================
--- incubator/wookie/trunk/widgets/vote/languageHelper.js (added)
+++ incubator/wookie/trunk/widgets/vote/languageHelper.js Tue Mar  9 10:58:01 
2010
@@ -0,0 +1,18 @@
+/*
+ * Language helper object
+ */
+var LanguageHelper = {
+
+       getLocalizedString : function(key) {
+               try {
+                       var evalString = "localizedStrings['"+key+"'];";        
        
+                       var ret = eval(evalString);
+                       if (ret === undefined)
+                               ret = key;
+                       return ret;
+               }
+               catch (ex) {
+               }
+               return key;
+       }
+}
\ No newline at end of file

Modified: incubator/wookie/trunk/widgets/vote/vote.js
URL: 
http://svn.apache.org/viewvc/incubator/wookie/trunk/widgets/vote/vote.js?rev=920794&r1=920793&r2=920794&view=diff
==============================================================================
--- incubator/wookie/trunk/widgets/vote/vote.js (original)
+++ incubator/wookie/trunk/widgets/vote/vote.js Tue Mar  9 10:58:01 2010
@@ -143,7 +143,7 @@ function doValidation(){
 function showNotReadyYet(){
        var notReadytext = "<div id='legendDiv'>" + 
LanguageHelper.getLocalizedString('This vote instance has not yet been 
initialised') + "</div>";
        notReadytext += "<div id='responseDivFull'></div>";
-       notReadytext += "<div id='submitDiv'><div align=\"left\" 
id=\"lang_opts\">" + LanguageHelper.getLangOpts(showNotReadyYetLangChanged) + 
"</div></div>";
+       notReadytext += "<div id='submitDiv'></div>";
        dwr.util.setValue("maincanvas", notReadytext, { escapeHtml:false });
 }
 
@@ -155,7 +155,7 @@ function createQuestions(){
        var authorVoteText = "<div id='legendDiv'>" + 
LanguageHelper.getLocalizedString('Setup vote widget') + "</div>";
        authorVoteText += "<div id='questionDiv'>" + 
LanguageHelper.getLocalizedString('Step One: Enter the question here') + 
":&nbsp;<input type='text' size='50' maxlength='100' id='questionfield'></div>";
        authorVoteText += "<div id='responseDiv'>" + 
LanguageHelper.getLocalizedString('Step Two: Create the responses') + 
":&nbsp;(<a href='#' onClick='createNewInput()'>" + 
LanguageHelper.getLocalizedString('Click here to add more response fields') + 
"</a>)<div id='dynForm'></div></div>";
-       authorVoteText += "<div id='submitDiv'><div align=\"left\" 
id=\"lang_opts\">" + LanguageHelper.getLangOpts(createQuestionsLangChanged) + 
"&nbsp;</div><a href='#' onClick='doValidation()'>" + 
LanguageHelper.getLocalizedString('Step Three: Click here to check and finish') 
+ "</a></div>";
+       authorVoteText += "<div id='submitDiv'><a href='#' 
onClick='doValidation()'>" + LanguageHelper.getLocalizedString('Step Three: 
Click here to check and finish') + "</a></div>";
        dwr.util.setValue("maincanvas", authorVoteText, { escapeHtml:false });
 }
 
@@ -187,7 +187,7 @@ function setupVoteDisplayStageThree(pAns
        }
     }
     answerText += "</form></div>";    
-    var submitText= questionText+ answerText + "<div id='submitDiv'><div 
align=\"left\" id=\"lang_opts\">" + 
LanguageHelper.getLangOpts(setupVoteDisplayStageOne) + "&nbsp;</div><a href='#' 
onClick='doVote()'>" + LanguageHelper.getLocalizedString('Click here to vote') 
+ "</a></div>";            
+    var submitText= questionText+ answerText + "<div id='submitDiv'><a 
href='#' onClick='doVote()'>" + LanguageHelper.getLocalizedString('Click here 
to vote') + "</a></div>";         
        dwr.util.setValue("maincanvas", submitText, { escapeHtml:false });
        var respDiv = dwr.util.byId('responseDiv');
        respDiv.style.height = "200px"; 
@@ -262,7 +262,7 @@ function showVoteDisplayStageThree(pAnsw
        }
     }
     answerText += "</table></form></div>";  
-    submitDiv = "<div id='submitDiv'><div align=\"left\" id=\"lang_opts\">" + 
LanguageHelper.getLangOpts(showVoteDisplayStageOne) + "&nbsp;</div><a href='#' 
onClick='showVoteDisplayStageOne()'><img border=\"0\" 
src=\"/wookie/shared/images/refresh.gif\">&nbsp;" + 
LanguageHelper.getLocalizedString('Refresh') + "</a></div>";
+    submitDiv = "<div id='submitDiv'><a href='#' 
onClick='showVoteDisplayStageOne()'><img border=\"0\" 
src=\"/wookie/shared/images/refresh.gif\">&nbsp;" + 
LanguageHelper.getLocalizedString('Refresh') + "</a></div>";
       
     var endText= questionText+ answerText + submitDiv;         
        dwr.util.setValue("maincanvas", endText, { escapeHtml:false });

Added: incubator/wookie/trunk/widgets/vote/widgetUtils.js
URL: 
http://svn.apache.org/viewvc/incubator/wookie/trunk/widgets/vote/widgetUtils.js?rev=920794&view=auto
==============================================================================
--- incubator/wookie/trunk/widgets/vote/widgetUtils.js (added)
+++ incubator/wookie/trunk/widgets/vote/widgetUtils.js Tue Mar  9 10:58:01 2010
@@ -0,0 +1,141 @@
+/*
+ * Replace text function - overloaded on strings
+ */
+ String.prototype.replaceAll = function(strTarget, strSubString){
+       var strText = this;
+       var intIndexOfMatch = strText.indexOf( strTarget );
+  
+       // Keep looping while an instance of the target string
+       // still exists in the string.
+       while (intIndexOfMatch != -1){
+               // Relace out the current instance.
+               strText = strText.replace( strTarget, strSubString )
+               // Get the index of any next matching substring.
+               intIndexOfMatch = strText.indexOf( strTarget );
+       }
+  
+       // Return the updated string with ALL the target strings
+       // replaced out with the new substring.
+       return( strText );
+ }
+
+ 
+ /*
+  * Utility class
+  */
+ var WidgetUtil = {
+                
+        generate3DigitRandomNumber : function(){
+               return Math.floor((Math.random() * 900) + 100);
+        },
+                
+        generateRandomHexColor : function(){
+                               colors = new Array(14)
+                               colors[0]="0"
+                               colors[1]="1"
+                               colors[2]="2"
+                               colors[3]="3"
+                               colors[4]="4"
+                               colors[5]="5"
+                               colors[5]="6"
+                               colors[6]="7"
+                               colors[7]="8"
+                               colors[8]="9"
+                               colors[9]="a"
+                               colors[10]="b"
+                               colors[11]="c"
+                               colors[12]="d"
+                               colors[13]="e"
+                               colors[14]="f"
+
+                               digit = new Array(5)
+                               color=""
+                               for (i=0;i<6;i++){
+                                       
digit[i]=colors[Math.round(Math.random()*14)]
+                                       color = color+digit[i]
+                               }
+                               return color;
+                       },
+                       
+                       findObj : function (n, d) {
+                               var p,i,x; if(!d) d=document;
+                               if((p=n.indexOf("?"))>0&&parent.frames.length) {
+                                       
d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);
+                               }
+                               if(!(x=d[n])&&d.all) x=d.all[n]; for 
(i=0;!x&&i<d.forms.length;i++)
+                                       x=d.forms[i][n];
+                                       
for(i=0;!x&&d.layers&&i<d.layers.length;i++)
+                                               
x=findObj(n,d.layers[i].document);
+                                       if(!x && document.getElementById) 
x=document.getElementById(n); return x;
+                       },
+                       
+                       roundNumber : function (num, dec) {
+                               var result = 
Math.round(num*Math.pow(10,dec))/Math.pow(10,dec);
+                               return result;
+                       },
+                       
+                       onReturn : function(event, sendMessage){
+                               dwr.util.onReturn(event, sendMessage)
+                       },
+                       
+                       getValue : function(fName){                             
+                               return dwr.util.getValue(fName);
+                       },
+               
+                       setValue : function(fName, fValue, options){            
                
+                               dwr.util.setValue(fName, fValue, options);
+                       },
+               
+                       escapeHtml : function(text){
+                               return dwr.util.escapeHtml(text);
+                       },
+                       
+                       byId : function(id){
+                               return dwr.util.byId(id);
+                       }
+ }
+ 
+/*
+ * simple debug window
+ */
+var DebugHelper = {
+               
+       winLength : 800,
+       winHeight : 200,
+       debugLog : "",
+       
+       debug : function(p){
+               result = this.cleanInput(p);
+               this.debugLog+="<tr><td>";
+               this.debugLog+=result;
+               this.debugLog+="<hr/></td></tr>";
+               this.writeConsole(this.debugLog);       
+       },
+
+       cleanInput : function(p){
+               removedOpenBracket = p.replaceAll( "<", "&lt;" )
+               removedClosedBracket = removedOpenBracket.replaceAll( ">", 
"&gt;" )
+               result = removedClosedBracket;
+               return result;
+       },
+
+       writeConsole : function(content) {
+                consoleRef=window.open('','myconsole',
+                 'width=' + this.winLength + ',height=' + this.winHeight
+                  +',menubar=0'
+                  +',toolbar=1'
+                  +',status=0'
+                  +',scrollbars=1'
+                  +',resizable=1')     
+                  
+                consoleRef.document.writeln(
+                 '<html><head>'                                  
+                +'<title>Debug</title></head>'
+                +'<body bgcolor=white><table width=' + this.winLength + '>'
+                +content+'<table><a name="bottom"></a></body></html>'
+                )
+                consoleRef.onLoad = consoleRef.scrollTo(0,999999);
+                consoleRef.document.close()
+       }
+
+}
\ No newline at end of file

Modified: incubator/wookie/trunk/widgets/weather/weather.js
URL: 
http://svn.apache.org/viewvc/incubator/wookie/trunk/widgets/weather/weather.js?rev=920794&r1=920793&r2=920794&view=diff
==============================================================================
--- incubator/wookie/trunk/widgets/weather/weather.js (original)
+++ incubator/wookie/trunk/widgets/weather/weather.js Tue Mar  9 10:58:01 2010
@@ -8,6 +8,7 @@ iconTable['sunny'] = 'images/sunny.png';
 iconTable['sunnyintervals'] = 'images/sunny.png';
 iconTable['rainy'] = 'images/rainy.png';
 iconTable['drizzle'] = 'images/rainy.png';
+iconTable['sleet'] = 'images/rainy.png';
 iconTable['lightrain'] = 'images/rainy.png';
 iconTable['heavyrain'] = 'images/rainy.png';
 iconTable['lightshowers'] = 'images/rainy.png';
@@ -80,7 +81,8 @@ function showBack(event)
        var back = document.getElementById("back");
        front.style.display="none";
        back.style.display="block";     
-       WidgetUtil.setValue("controls", getDropDownList(),  { escapeHtml:false 
});
+       document.getElementById("controls").innerHTML = getDropDownList();
+       //WidgetUtil.setValue("controls", getDropDownList(),  { 
escapeHtml:false });
 }
 
 function showFront(event)


Reply via email to