From b256527a2a3500ac4c94e2472c2ebe928377bb37 Mon Sep 17 00:00:00 2001
From: Pierre Spring <pierre.spring@caillou.ch>
Date: Sun, 10 Oct 2010 20:05:45 +0200
Subject: subscriptions.js jQueryfied

---
 lib/scripts/subscriptions.js | 67 ++++++++++++++++++++------------------------
 1 file changed, 31 insertions(+), 36 deletions(-)

(limited to 'lib/scripts')

diff --git a/lib/scripts/subscriptions.js b/lib/scripts/subscriptions.js
index d701f258f..144f31881 100644
--- a/lib/scripts/subscriptions.js
+++ b/lib/scripts/subscriptions.js
@@ -2,45 +2,40 @@
  * Hide list subscription style if target is a page
  *
  * @author Adrian Lang <lang@cosmocode.de>
+ * @author Pierre Spring <pierre.spring@caillou.ch>
  */
+(function ($) {
+    $(function () {
+        var form, list, digest;
+        
+        form = $('#subscribe__form');
 
-addInitEvent(function () {
-    var form = $('subscribe__form');
-    if (!form) {
-        return;
-    }
-
-    var styleradios = {};
-
-    function update_state() {
-        if (!this.checked) {
+        if (0 === form.size()) {
             return;
         }
-        if (this.value.match(/:$/)) {
-            styleradios.list.parentNode.style.display = '';
-        } else {
-            styleradios.list.parentNode.style.display = 'none';
-            if (styleradios.list.checked) {
-                styleradios.digest.checked = 'checked';
-            }
-        }
-    }
+        
+        list = form.find("input[name='sub_style'][value='list']");
+        digest = form.find("input[name='sub_style'][value='digest']");
 
-    var cur_sel = null;
+        form.find("input[name='sub_target']")
+            .click(
+                function () {
+                    var input = $(this);
+                    if (!input.is(':checked')) {
+                        return;
+                    }
 
-    var inputs = form.getElementsByTagName('input');
-    for (var i = 0; i < inputs.length ; ++i) {
-        switch (inputs[i].name) {
-        case 'sub_target':
-            addEvent(inputs[i], 'click', update_state);
-            if (inputs[i].checked) {
-                cur_sel = inputs[i];
-            }
-            break;
-        case 'sub_style':
-            styleradios[inputs[i].value] = inputs[i];
-            break;
-        }
-    }
-    update_state.call(cur_sel);
-});
+                    if (input.val().match(/:$/)) {
+                        list.parent().show();
+                    } else {
+                        list.parent().hide();
+                        if (list.is(':checked')) {
+                            digest.attr('checked', 'checked');
+                        }
+                    }
+                }
+            )
+            .filter(':checked')
+            .click();
+    });
+}(jQuery));
\ No newline at end of file
-- 
cgit v1.2.3