summaryrefslogtreecommitdiff
path: root/lib/scripts/subscriptions.js
diff options
context:
space:
mode:
Diffstat (limited to 'lib/scripts/subscriptions.js')
-rw-r--r--lib/scripts/subscriptions.js65
1 files changed, 30 insertions, 35 deletions
diff --git a/lib/scripts/subscriptions.js b/lib/scripts/subscriptions.js
index d701f258f..79b1caf1a 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;
-addInitEvent(function () {
- var form = $('subscribe__form');
- if (!form) {
- return;
- }
+ form = $('#subscribe__form');
- 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';
- }
- }
- }
- var cur_sel = null;
+ list = form.find("input[name='sub_style'][value='list']");
+ digest = form.find("input[name='sub_style'][value='digest']");
- 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);
-});
+ form.find("input[name='sub_target']")
+ .click(
+ function () {
+ var input = $(this);
+ if (!input.is(':checked')) {
+ return;
+ }
+
+ if (input.val().match(/:$/)) {
+ list.parent().show();
+ } else {
+ list.parent().hide();
+ if (list.is(':checked')) {
+ digest.attr('checked', 'checked');
+ }
+ }
+ }
+ )
+ .filter(':checked')
+ .click();
+ });
+}(jQuery));