From: Florent Bruneau Date: Sun, 23 Jan 2011 15:11:45 +0000 (+0100) Subject: Much cleaner coding style. X-Git-Tag: xorg/1.1.0~176 X-Git-Url: http://git.polytechnique.org/?a=commitdiff_plain;h=048c44a3cb471d42622e393c714efbe3f78018d8;p=platal.git Much cleaner coding style. Signed-off-by: Florent Bruneau --- diff --git a/htdocs/javascript/xorg.js b/htdocs/javascript/xorg.js index 178c39e..ed71ba5 100644 --- a/htdocs/javascript/xorg.js +++ b/htdocs/javascript/xorg.js @@ -84,72 +84,71 @@ function addSearchEngine() // {{{ function goodiesPopup() -var __goodies_active = true; - -var __goodies_ical = { - default_title: 'Calendrier 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'}, - {'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 = { - default_title: 'Fils RSS', - sites: [ - {'url_prefix': '', - 'img': 'images/icons/feed.gif', - 'title': 'Fil rss'}, - {'url_prefix': 'http://fusion.google.com/add?feedurl=', - 'img': 'images/goodies/add-google.gif', - 'alt': 'Add to Google', - 'title': 'Ajouter à iGoogle/Google Reader'}, - {'url_prefix': 'http://www.netvibes.com/subscribe.php?url=', - 'img': 'images/goodies/add-netvibes.gif', - 'title': 'Ajouter à Netvibes'}, - {'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!'} - ] -}; - -function disableGoodiesPopups() { - __goodies_active = false; -} - -function goodiesPopup(node, goodies) { - var text = '
'; - for (var site in goodies.sites) { - var entry = goodies.sites[site]; - var s_alt = entry["alt"] ? entry["alt"] : ""; - var s_img = entry["img"]; - var s_title = entry["title"] ? entry["title"] : ""; - var s_url = entry["url_prefix"].length > 0 ? entry["url_prefix"] + escape(this.href) : this.href; - - text += '' + s_alt + '
'; - } - text += 'Plus de bonus ...
'; +(function($) { + var goodies = { + ical: { + default_title: 'Calendrier 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'}, + {url_prefix: 'https://www.google.com/calendar/hosted/polytechnique.org/render?cid=', + img: 'images/goodies/add-google-calendar.gif', + title: 'Ajouter à Google Apps / Calendar'} + ] + }, + + rss: { + default_title: 'Fils RSS', + sites: [ + {url_prefix: '', + img: 'images/icons/feed.gif', + title: 'Fil rss'}, + {url_prefix: 'http://fusion.google.com/add?feedurl=', + img: 'images/goodies/add-google.gif', + alt: 'Add to Google', + title: 'Ajouter à iGoogle/Google Reader'}, + {url_prefix: 'http://www.netvibes.com/subscribe.php?url=', + img: 'images/goodies/add-netvibes.gif', + title: 'Ajouter à Netvibes'}, + {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!'} + ] + } + }; + + $.fn.extend({ + goodiesPopup: function goodiesPopup(type) { + var text = '
'; + for (var site in goodies[type].sites) { + var entry = goodies[type].sites[site]; + var s_alt = entry.alt || ""; + var s_img = entry.img; + var s_title = entry.title || ""; + var s_url = entry.url_prefix.length > 0 ? entry.url_prefix + escape(this.href) : this.href; + + text += '' + s_alt + '
'; + } + text += 'Plus de bonus ...
'; - var title = node.title ? node.title : goodies.default_title; + var title = this.attr('title') || goodies.default_title; - $(node) - .mouseover( - function() { - if (__goodies_active) { - return overlib(text, CAPTION, title, CLOSETEXT, 'Fermer', DELAY, 800, STICKY, WIDTH, 150); - } - } - ) - .mouseout(nd); -} + return this.overlib({ + text: text, + caption: title, + close_text: 'Fermer', + delay: 800, + sticky: true, + width: 150 + }); + } + }); +}(jQuery)); // }}} // {{{ function auto_links() @@ -190,9 +189,9 @@ function auto_links() { } if (this.nodeName.toLowerCase() == 'a' && !resource_page) { if (rss && !href.contains('prefs/rss') && (href.contains('xml') || href.contains('hash'))) { - goodiesPopup(this, __goodies_rss); + node.goodiesPopup('rss'); } else if (ical) { - goodiesPopup(this, __goodies_ical); + node.goodiesPopup('ical'); } } if(matches = (/^popup_([0-9]*)x([0-9]*)$/).exec(this.className)) { @@ -651,6 +650,57 @@ function sendTestEmail(token, hruid) /*************************************************************************** + * Overlib made simple + */ + +(function($) { + $.fn.extend({ + overlib: function(text, width, height) { + var args = [ ]; + if (typeof text == 'string') { + args.push(text); + width && args.push(width); + height && args.push(height); + } else { + for (var key in text) { + switch (key) { + case 'text': + args.unshift(text[key]); + break; + case 'caption': + args.push(CAPTION, text[key]); + break; + case 'close_text': + args.push(CLOSETEXT, text[key]); + break; + case 'delay': + args.push(DELAY, text[key]); + break; + case 'sticky': + if (text[key]) { + args.push(STICKY); + } + break; + case 'width': + args.push(WIDTH, text[key]); + break; + case 'height': + args.push(HEIGHT, text[key]); + break; + } + } + } + return this + .mouseover(function () { + return overlib.apply(null, args); + }) + .mouseout(nd); + } + }); +}(jQuery)); + + +/*************************************************************************** * The real OnLoad */