summaryrefslogtreecommitdiffstats
path: root/HTML/script.js
diff options
context:
space:
mode:
authorMageia SVN-Git Migration <svn-git-migration@mageia.org>2011-02-07 23:18:17 +0000
committerMageia SVN-Git Migration <svn-git-migration@mageia.org>2011-02-07 23:18:17 +0000
commit841b56cd2b970466d68fbc4165f86760759c0169 (patch)
treea548c9131c2e1abedcbfc4b4e2ccf592a41d70ad /HTML/script.js
parent911afa843897cd330622a2e222cff6080a64e590 (diff)
downloadindexhtml-841b56cd2b970466d68fbc4165f86760759c0169.tar
indexhtml-841b56cd2b970466d68fbc4165f86760759c0169.tar.gz
indexhtml-841b56cd2b970466d68fbc4165f86760759c0169.tar.bz2
indexhtml-841b56cd2b970466d68fbc4165f86760759c0169.tar.xz
indexhtml-841b56cd2b970466d68fbc4165f86760759c0169.zip
Synthesized commit during git-svn import combining previous Mandriva history with Mageia.
This commit consitsts of the following subversion commits: ------------------------------------------------------------------------ r485 | dmorgan | 2011-02-07 23:18:17 +0000 (Mon, 07 Feb 2011) | 1 line Import cleaned indexhtml ------------------------------------------------------------------------ In addition to the above commits, the following cleaning work has been recorded: o mails - replacement was done in headers except for Subject in header-ur which does not contain Mandriva... - dropped most mail bodys, except for French & English, rewritten to a minimal version - a good mail should be designed and translated o about - command is about-mandriva, have to look at what uses it - removed MDV graphics from style/css o HTML - a simple page should be placed there, until web team provides something o po - all translations should be dropped, strings updated when the real page is ready o COPYING - added COPYING file (GNU GPL v3). indexhtml.spec file stated "GPL" (should be changed to GPL3+)
Diffstat (limited to 'HTML/script.js')
-rw-r--r--HTML/script.js148
1 files changed, 88 insertions, 60 deletions
diff --git a/HTML/script.js b/HTML/script.js
index 71e40e6..fff1fb8 100644
--- a/HTML/script.js
+++ b/HTML/script.js
@@ -1,67 +1,95 @@
-/* $Id$
+/**
+ * @copyright Copyright (c) 2011 Romain d'Alverny
+ * @license http://www.gnu.org/licenses/gpl-3.0.html GNU GPL v3 and later
*
+ * Redirect browser online IF it is in online mode.
+ * Or stay on offline page and listen to online event.
+ *
+ * Browser targets: Mozilla Firefox 3.6+, Konqueror.
*/
-var remoteweb = 'http://start.mandriva.com/';
-
-String.prototype.rtrim = function() { return this.replace(/\s*$/, ""); };
-String.prototype.ltrim = function() { return this.replace(/^\s*/, ""); };
-String.prototype.trim = function() { return this.rtrim().ltrim(); };
-String.prototype.encodeURI = function() { return this.replace(/\+/g,"%2B"); };
-
-function actOnline() {
- // #1
- var release = '';
- var pack = '';
- var product = '';
- var lang = '';
- try {
- var t = document.getElementsByTagName('meta');
- for( var i=0; i<t.length; i+=1 ) {
- if( t.item(i).getAttribute('name') == 'mdv:release' ) {
- release = t.item(i).getAttribute('content');
- } else if( t.item(i).getAttribute('name') == 'mdv:pack' ) {
- pack = t.item(i).getAttribute('content');
- } else if( t.item(i).getAttribute('name') == 'mdv:product' ) {
- product = t.item(i).getAttribute('content');
- }
- }
- lang = parent.window.document.documentElement.attributes.getNamedItem('lang').value;
- }
- catch( e ) {}
- finally {}
-
- // #2
- var args = '';
- if( release !== '' ) { args = 'r='+release.trim().encodeURI(); }
- if( pack !== '' ) { if( args !== '' ) { args += '&'; } args += 'p='+pack.trim().encodeURI(); }
- if( product !== '' ) { if( args !== '' ) { args += '&'; } args += 'p='+product.trim().encodeURI(); }
- if( lang !== '' ) { if( args !== '' ) { args += '&'; } args += 'l='+lang.trim(); }
- if( args !== '' ) { remoteweb += '?' + args; }
-
- // #3
- parent.location = remoteweb;
- return true;
+function StartPage(url, image) {
+ this.location = url;
+ this.onlinePx = image;
}
-function actOffline() { return true; }
-function imgLoad() { actOnline(); }
-function imgError() { var i = document.getElementById('i'); i.parentNode.removeChild(i); actOffline(); }
-
-window.alert = function() {};
-
-function run() {
- try {
- var i = document.createElement('img');
- i.id = 'i';
- i.onload = imgLoad;
- i.onerror = imgError;
- i.src = 'http://images.mandriva.com/images/donotremove.png';
- document.getElementsByTagName('body').item(0).appendChild(i);
- }
- catch(e) { return false; }
- return true;
+StartPage.prototype.run = function () {
+ if (false && navigator.onLine !== null) {
+ !navigator.onLine ? this.actOnline() : this.actOffline();
+
+ } else { // for khtml-based browsers
+ try {
+ var sp = this,
+ i = document.createElement('img');
+
+ window.alert = function() {};
+
+ i.id = 'i';
+ i.onload = function () { console.log(sp); sp.actOnline(); };
+ i.onerror = function () { sp.actOffline(); };
+ i.src = this.onlinePx + '?' + new Date().getTime();
+ document.getElementsByTagName('body').item(0).appendChild(i);
+ }
+ catch (e) { return false; }
+ }
+
+ return true;
}
-/*
-*/
+StartPage.prototype.actOnline = function () {
+ var productId = '',
+ lang = '',
+ args = new Array;
+
+ if (null !== (product_id = this.getProductId())) {
+ args.push('p=' + product_id);
+ }
+
+ if (null !== (lang = this.getLocale())) {
+ args.push('l=' + lang);
+ }
+
+ if (args.length > 0) {
+ this.location = [this.location, args.join('&')].join('?');
+ }
+ parent.location = this.location;
+
+ return true;
+}
+
+StartPage.prototype.actOffline = function () {
+ var p = this,
+ i = document.getElementById("i");
+
+ if (null !== i) {
+ i.parentNode.removeChild(i);
+ }
+ document.getElementsByTagName("body").item(0).setAttribute("class", "offline");
+ document.body.addEventListener("online", function () { p.actOnline(); }, false);
+
+ return true;
+}
+
+StartPage.prototype.getLocale = function () {
+ var ret = null;
+
+ try {
+ ret = parent.window.document.documentElement.attributes.getNamedItem('lang').value.trim();
+ } catch (e) {}
+
+ return ret;
+}
+
+StartPage.prototype.getProductId = function () {
+ var ret = null,
+ t = document.getElementsByTagName('meta');
+
+ for (var i = 0; i < t.length; i += 1) {
+ if (t.item(i).getAttribute('name') == 'product:id') {
+ ret = t.item(i).getAttribute('content').trim();
+ break;
+ }
+ }
+
+ return ret;
+}