Revision 4b5adcc3 cloudcms/static/cloudcms/js/forms.js

b/cloudcms/static/cloudcms/js/forms.js
3 3
  $.fn.formCheckBoxes = function(options) {
4 4
    
5 5
    return this.each(function() {
6
      // process checkboxes
6 7
      var $this = $(this);
7
      var el = $('<span class="checkbox-widget" />');
8
    
8
      var el = $('<a class="checkbox-widget" href="javascript:void(0)"/>');
9
      var form = $this.closest(".form-row");
10

  
11
      // add class to identify form rows which contain a checkbox
12
      form.addClass("with-checkbox");
13
      
14
      if ($this.prev().length > 0) {
15
        var lbl = $this.prev()[0];
16
        if (lbl.nodeName == "LABEL" || lbl.nodeName == "label") {
17
            $(lbl).addClass("checkbox-label");
18

  
19
            $(lbl).click(function(e){
20
                var src = e.srcElement.nodeName;
21
                if (src == "LABEL" || src == "label") {
22
                    el.toggleClass("checked");
23
                };
24
            })
25
        }
26
      }
9 27
      $this.hide();
10 28
      
11
      if ($this.is("checked")) {
29
      if ($this.attr('checked')) {
12 30
        el.addClass("checked");  
13 31
      }
14 32

  
15 33
      el.click(function() {
16 34
        el.toggleClass("checked");
17 35
        $this.attr('checked', el.hasClass("checked"));
36
      });
37
      
38
      el.keypress(function(e){
39
      	
40
      	if (e.keyCode == 0 || e.keyCode == 32){
41
      		e.preventDefault();
42
      		el.toggleClass("checked");
43
        	$this.attr('checked', el.hasClass("checked"));
44
      	}
18 45
      })
19 46

  
20
      $this.after(el);
47
      $this.prev('label').before(el);
21 48
    });
22 49

  
23 50

  
......
68 95
            marginLeft: marginleft,
69 96
            marginBottom: 5
70 97
        }
71
        el.css(styles);
98
        
99
        if (formel.attr("type") != "checkbox") {
100
            el.css(styles);
101
        } else {
102
            el.css("margin-top", "5px");
103
        }
72 104
    });
73 105

  
74 106
  };
75
})( jQuery );
107
})( jQuery );

Also available in: Unified diff