1 /* ***** BEGIN LICENSE BLOCK *****
  2  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
  3  *
  4  * The contents of this file are subject to the Mozilla Public License Version
  5  * 1.1 (the "License"); you may not use this file except in compliance with
  6  * the License. You may obtain a copy of the License at
  7  * http://www.mozilla.org/MPL/
  8  *
  9  * Software distributed under the License is distributed on an "AS IS" basis,
 10  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
 11  * for the specific language governing rights and limitations under the
 12  * License.
 13  *
 14  * The Initial Developer of the Original Code is Fireinput Inc.
 15  *
 16  * Portions created by the Initial Developer are Copyright (C) 2007
 17  * the Initial Developer. All Rights Reserved.
 18  *
 19  * Contributor(s):
 20  *     Olly Ja <ollyja@gmail.com>
 21  *
 22  * Alternatively, the contents of this file may be used under the terms of
 23  * either the GNU General Public License Version 2 or later (the "GPL"), or
 24  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
 25  * in which case the provisions of the GPL or the LGPL are applicable instead
 26  * of those above. If you wish to allow use of your version of this file only
 27  * under the terms of either the GPL or the LGPL, and not to allow others to
 28  * use your version of this file under the terms of the MPL, indicate your
 29  * decision by deleting the provisions above and replace them with the notice
 30  * and other provisions required by the GPL or the LGPL. If you do not delete
 31  * the provisions above, a recipient may use your version of this file under
 32  * the terms of any one of the MPL, the GPL or the LGPL.
 33  *
 34  * ***** END LICENSE BLOCK ***** 
 35  */
 36 
 37 const RELEASE_NEW = "http://www.fireinput.com/releases/releases.html"; 
 38 
 39 const helpUI = [
 40     {id: "helpMenuHome", strKey: "fireinput.help.home", attribute: "label"},
 41     {id: "helpMenuDoc", strKey: "fireinput.help.document", attribute: "label"},
 42     {id: "helpMenuKey", strKey: "fireinput.help.shortkey", attribute: "label"},
 43     {id: "helpMenuEditor", strKey: "fireinput.help.editor", attribute: "label"},
 44     {id: "helpNewRelease", strKey: "fireinput.help.newrelease", attribute: "label"},
 45     {id: "helpMenuAbout", strKey: "fireinput.help.about", attribute: "label"},
 46     {id: "helpMenuDonate", strKey: "fireinput.help.donate", attribute: "label"}
 47 ]; 
 48 
 49 const helpSite = {
 50     home: "http://www.fireinput.com",
 51     release: RELEASE_NEW, 
 52     docs: "http://www.fireinput.com/document/index.html",
 53     shortkey: "chrome://fireinput/content/shortkey.html",
 54     contribute: "http://www.fireinput.com/contribute.html"
 55 }; 
 56 
 57 
 58 var FireinputHelp = 
 59 {
 60     initialized: false,
 61 
 62     load: function()
 63     {
 64        if(this.initialized)
 65           return;
 66 
 67        // get default language first 
 68        var defaultLanguage = FireinputPrefDefault.getInterfaceLanguage();
 69        // update UI 
 70        for(var i =0; i<helpUI.length; i++)
 71        {
 72           var id = helpUI[i].id;
 73           var strKey = helpUI[i].strKey;
 74           var attr = helpUI[i].attribute;
 75 
 76           var value = FireinputUtils.getLocaleString(strKey + defaultLanguage);
 77           var handle = document.getElementById(id);
 78           if(!handle)
 79              continue;
 80           handle.setAttribute(attr, value);
 81        }
 82 
 83        // check new releases
 84        this.checkNewRelease(); 
 85        this.initialized = true; 
 86     },
 87 
 88     showSite: function(site)
 89     {
 90        var url = helpSite[site]; 
 91        if (url)
 92           gBrowser.selectedTab = gBrowser.addTab(url);
 93     },
 94 
 95     openEditor: function()
 96     {
 97        gBrowser.selectedTab = gBrowser.addTab("chrome://fireinput/content/editor.html"); 
 98     },
 99     
100     showAbout: function()
101     {
102        gBrowser.selectedTab = gBrowser.addTab("chrome://fireinput/content/about.html"); 
103     }, 
104 
105     checkNewRelease: function()
106     {
107        var ajax = new Ajax();
108        if(!ajax)
109           return;
110 
111        var self = this;
112 
113        ajax.setOptions(
114           {
115              method: 'get',
116              onSuccess: function(p) { self.displayNewReleaseMenuItem(p); }
117           });
118 
119        ajax.request(RELEASE_NEW);
120     },
121 
122     displayNewReleaseMenuItem: function(p)
123     {
124        if(!p)
125           return;
126        if(p.responseText.length <= 0)
127           return;
128 
129        var version = p.responseText.match(/latestrelease_[\d\.]+/g)[0];
130        if(!version)
131           return; 
132 
133        version = version.replace("latestrelease_", ""); 
134        if(!version || version.length <= 0)
135           return; 
136 
137        var newVersionArray = version.split('.'); 
138        var curVersionArray = FIREINPUT_VERSION.split('.'); 
139 
140        if(curVersionArray.length <= 1) 
141           return; 
142 
143        var curVersionMinor = curVersionArray[1]; 
144        curVersionMinor = curVersionMinor.replace(/\D+/, ""); 
145 
146        // major version 
147        if(newVersionArray[0] < curVersionArray[0])
148           return;         
149 
150        // minor version 
151        if(newVersionArray[1] < parseInt(curVersionMinor))
152           return; 
153 
154        if(newVersionArray[1] > parseInt(curVersionMinor))
155        {
156           this.showNewRelease(); 
157           return; 
158        }
159 
160        if(newVersionArray.length <= 2) 
161           return; 
162 
163        // development version 
164        if(newVersionArray.length > curVersionArray.length)
165        {
166           this.showNewRelease(); 
167           return; 
168        }
169        else if(newVersionArray.length == curVersionArray.length)
170        {
171           var devNewVersion = newVersionArray[newVersionArray.length -1];   
172           var devCurVersion = curVersionArray[curVersionArray.length -1];   
173           if(parseInt(devNewVersion) > parseInt(devCurVersion))
174           {
175              this.showNewRelease(); 
176              return; 
177           }
178        } 
179     }, 
180    
181     showNewRelease: function()
182     {   
183        var element = document.getElementById("helpNewRelease"); 
184        element.style.display = ""; 
185        element.style.color = "red"; 
186        
187        element = document.getElementById("fireinputHelp"); 
188        element.style.color = "red"; 
189     }   
190 }; 


syntax highlighted by Code2HTML, v. 0.9.1