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/wiki/Release_Page"; 
 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/wiki/Document_Page",
 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(forceLoad)
 63     {
 64        if(this.initialized && !forceLoad)
 65           return;
 66 
 67        this.refreshMenu(); 
 68 
 69        // check new releases
 70        this.checkNewRelease(); 
 71 
 72        this.initialized = true; 
 73     },
 74 
 75     refreshMenu: function()
 76     {
 77        // get default language first 
 78        var defaultLanguage = fireinputPrefGetDefault("interfaceLanguage");
 79        // update UI 
 80        for(var i =0; i<helpUI.length; i++)
 81        {
 82           var id = helpUI[i].id;
 83           var handle = document.getElementById(id);
 84           if(!handle)
 85              continue;
 86 
 87           var strKey = helpUI[i].strKey;
 88           var attr = helpUI[i].attribute;
 89 
 90           var value = FireinputUtils.getLocaleString(strKey + defaultLanguage);
 91           // to check whether the shortcut keystring exists 
 92           var found =value.match(/%(.+)%/i);
 93           if(found)
 94           {
 95              var keystring = FireinputKeyBinding.getKeyString(found[1]);
 96              value = value.replace(found[0], keystring);
 97           }
 98 
 99           handle.setAttribute(attr, value);
100        }
101     }, 
102 
103 
104     showSite: function(site)
105     {
106        var url = helpSite[site]; 
107        if (url)
108           FireinputUtils.loadURI(url); 
109     },
110 
111     openEditor: function()
112     {
113        FireinputUtils.loadURI("chrome://fireinput/content/editor.html"); 
114     },
115     
116     showAbout: function()
117     {
118        FireinputUtils.loadURI("chrome://fireinput/content/about.html"); 
119     }, 
120 
121     checkNewRelease: function()
122     {
123        var ajax = new Ajax();
124        if(!ajax)
125           return;
126 
127        var self = this;
128 
129        ajax.setOptions(
130           {
131              method: 'get',
132              onSuccess: function(p) { self.displayNewReleaseMenuItem(p); }
133           });
134 
135        ajax.request(RELEASE_NEW);
136     },
137 
138     displayNewReleaseMenuItem: function(p)
139     {
140        if(!p)
141           return;
142        if(p.responseText.length <= 0)
143           return;
144 
145        var version = p.responseText.match(/latestrelease_[\d\.]+/g)[0];
146        if(!version)
147           return; 
148 
149        version = version.replace("latestrelease_", ""); 
150        if(!version || version.length <= 0)
151           return; 
152 
153        var newVersionArray = version.split('.'); 
154        var curVersionArray = FIREINPUT_VERSION.split('.'); 
155 
156        if(curVersionArray.length <= 1) 
157           return; 
158 
159        var curVersionMinor = curVersionArray[1]; 
160        curVersionMinor = curVersionMinor.replace(/\D+/, ""); 
161 
162        // major version 
163        if(newVersionArray[0] < curVersionArray[0])
164           return;         
165 
166        // minor version 
167        if(newVersionArray[1] < parseInt(curVersionMinor))
168           return; 
169 
170        if(newVersionArray[1] > parseInt(curVersionMinor))
171        {
172           this.showNewRelease(version); 
173           return; 
174        }
175 
176        if(newVersionArray.length <= 2) 
177           return; 
178 
179        // development version 
180        if(newVersionArray.length > curVersionArray.length)
181        {
182           this.showNewRelease(version); 
183           return; 
184        }
185        else if(newVersionArray.length == curVersionArray.length)
186        {
187           var devNewVersion = newVersionArray[newVersionArray.length -1];   
188           var devCurVersion = curVersionArray[curVersionArray.length -1];   
189           if(parseInt(devNewVersion) > parseInt(devCurVersion))
190           {
191              this.showNewRelease(version); 
192              return; 
193           }
194        } 
195     }, 
196    
197     showNewRelease: function(version)
198     {   
199        var element = document.getElementById("helpNewRelease"); 
200        element.style.display = ""; 
201        element.style.color = "red"; 
202        element.setAttribute("label", element.getAttribute("label") + " " + version);
203 
204        element = document.getElementById("fireinputHelp"); 
205        element.style.color = "red"; 
206 
207        var defaultLanguage = fireinputPrefGetDefault("interfaceLanguage");
208 
209        element = document.getElementById("fireinputNewVersion");
210        var msg = FireinputUtils.getLocaleString("fireinput.help.newrelease.text" + defaultLanguage);
211        msg = msg.replace(/%VERSION%/, version); 
212        element.setAttribute("label", msg); 
213 
214        
215        element = document.getElementById("fireinputNewVersionPanel");
216        element.style.display = "";
217     }
218 }; 


syntax highlighted by Code2HTML, v. 0.9.1