Animated progression bar, better colors.
[platal.git] / htdocs / javascript / xorg.js
index 0e5f5d0..c25725f 100644 (file)
@@ -32,7 +32,7 @@ function getNow() {
     if (yr<1000) yr += 1900;
     hr = dt.getHours();
     mi = dt.getMinutes();
-    
+
     time   = (mi < 10) ? hr +':0'+mi : hr+':'+mi;
     days   = ['Dimanche', 'Lundi', 'Mardi', 'Mercredi', 'Jeudi', 'Vendredi', 'Samedi'];
     months = ['janvier', 'février', 'mars', 'avril', 'mai', 'juin', 'juillet',
@@ -66,7 +66,7 @@ function addSearchEngine()
     try {
         window.external.AddSearchProvider(searchURI);
     } catch(e) {
-        alert("Impossible d'installer la barre de recherche"); 
+        alert("Impossible d'installer la barre de recherche");
     }
   }
 }
@@ -89,7 +89,7 @@ function attachEvent(obj, evt, f, useCapture) {
         return true;
     } else if (obj.attachEvent) {
         return obj.attachEvent("on"+evt, f);
-    } 
+    }
     return false;
 }
 
@@ -165,13 +165,21 @@ function goodiesPopup(node) {
     }
 }
 
+function disableGoodiesPopups() {
+    __goodies_active = false;
+}
+
+var __goodies_active = true;
 var __goodies_ical_sites = [
     {'url_prefix': '',
      'img': 'images/icons/calendar_view_day.gif',
      'title': 'Calendrier iCal'},
     {'url_prefix': 'http://www.google.com/calendar/render?cid=',
      'img': 'images/goodies/add-google-calendar.gif',
-     'title': 'Ajouter à Google Calendar'}
+     'title': 'Ajouter à Google Calendar'},
+    {'url_prefix': 'https://www.google.com/calendar/hosted/polytechnique.org/render?cid=',
+     'img': 'images/goodies/add-google-calendar.gif',
+     'title': 'Ajouter à Google Apps / Calendar'}
 ];
 var __goodies_rss_sites = [
     {'url_prefix': '',
@@ -187,7 +195,11 @@ var __goodies_rss_sites = [
     {'url_prefix': 'http://add.my.yahoo.com/content?.intl=fr&url=',
      'img': 'images/goodies/add-yahoo.gif',
      'alt': 'Add to My Yahoo!',
-     'title': 'Ajouter à My Yahoo!'}
+     'title': 'Ajouter à My Yahoo!'},
+    {'url_prefix': 'http://www.newsgator.com/ngs/subscriber/subext.aspx?url=',
+     'img': 'images/goodies/add-newsgator.gif',
+     'alt': 'Subscribe in NewsGator Online',
+     'title': 'Ajouter à Newsgator'}
 ];
 
 function __goodies_popupText(url, sites) {
@@ -206,9 +218,11 @@ function __goodies_popupText(url, sites) {
 
 function __goodies_popup(node, sites, default_title) {
     var mouseover_cb = function() {
-        var rss_text = __goodies_popupText(node.href, sites);
-        var rss_title = (node.title ? node.title : default_title);
-        return overlib(rss_text, CAPTION, rss_title, CLOSETEXT, 'Fermer', DELAY, 800, STICKY, WIDTH, 150);
+        if (__goodies_active) {
+            var rss_text = __goodies_popupText(node.href, sites);
+            var rss_title = (node.title ? node.title : default_title);
+            return overlib(rss_text, CAPTION, rss_title, CLOSETEXT, 'Fermer', DELAY, 800, STICKY, WIDTH, 150);
+        }
     }
     var mouseout_cb = function() {
         nd();
@@ -266,6 +280,79 @@ function auto_links_nodes(nodes) {
 
 // }}}
 
+
+/***************************************************************************
+ * Password check
+ */
+
+// {{{ function checkPassword
+
+function getType(char) {
+    if (char >= 'a' && char <= 'z') {
+        return 1;
+    } else if (char >= 'A' && char <= 'Z') {
+        return 2;
+    } else if (char >= '0' && char <= '9') {
+        return 3;
+    } else {
+        return 4;
+    }
+}
+
+function checkPassword(box) {
+    var prev = 0;
+    var prop = 0;
+    var pass = box.value;
+    var types = Array(0, 0, 0, 0, 0);
+    for (i = 0 ; i < pass.length ; ++i) {
+        type = getType(pass.charAt(i));
+        if (prev != 0 && prev != type) {
+            prop += 5;
+        }
+        if (i >= 5) {
+            prop += 5;
+        }
+        if (types[type] == 0) {
+            prop += 10;
+        }
+        types[type]++;
+        prev = type;
+    }
+    if (prop > 100) {
+        prop = 100;
+    } else if (prop < 0) {
+        prop = 0;
+    }
+    if (prop >= 60) {
+        if (prop == 100) {
+            color = "#47f";
+        } else {
+            color = "#4f4";
+        }
+        ok = true;
+    } else if (prop >= 40) {
+        color = "#ff4";
+        ok = false;
+    } else {
+        color = "#f20";
+        ok = false;
+    }
+    $("#passwords_measure")
+        .stop()
+        .animate({ width: prop + "%",
+                   backgroundColor: color
+                 }, 750);
+    var submitButton = $(":submit[@name='" + passwordprompt_submit + "']");
+    if (ok) {
+        submitButton.removeAttr("disabled");
+    } else {
+        submitButton.attr("disabled", "disabled");
+    }
+}
+
+// }}}
+
+
 /***************************************************************************
  * The real OnLoad
  */