Commit 5dbb61cb53f9ea5cef4de2389019ea5fc063b83b

Authored by Julien Verneuil
1 parent faef3f48

allow radio buttons to act as checkbox by pressing the shift key

Showing 1 changed file with 45 additions and 19 deletions   Show diff stats
web/jQuery/CXM_jq_radio.anubis
... ... @@ -43,29 +43,42 @@ define String
43 43 "radio.addClass('unchecked');".
44 44  
45 45 define String
  46 + multi_select_script
  47 + (
  48 + Bool multi_select_with_shift,
  49 + String script
  50 + ) =
  51 + if multi_select_with_shift then
  52 + "if (!e.shiftKey) {" + script + "} else { window.getSelection().removeAllRanges(); radio.toggleClass('checked').toggleClass('unchecked'); }"
  53 + else
  54 + script.
  55 +
  56 +define String
46 57 radio_onclick_script
47 58 (
48 59 String radio_id,
49 60 RadioGroup radio_group,
  61 + Bool multi_select_with_shift,
50 62 String on_script
51 63 ) =
52 64 "
53 65 var radio = $('#" + radio_id + "');
54   - if (radio.hasClass('checked')) return;
55 66 " +
  67 + multi_select_script(multi_select_with_shift,
  68 + " if (radio.hasClass('checked')) return;" +
56 69  
57   - if radio_group is
58   - {
59   - group(name) then
60   - with jq_selector = "$('.radio-group-" + name + ":not(#" + radio_id + ")')",
61   - jq_selector + ".addClass('unchecked').removeClass('checked');",
  70 + if radio_group is
  71 + {
  72 + group(name) then
  73 + with jq_selector = "$('.radio-group-" + name + ":not(#" + radio_id + ")')",
  74 + jq_selector + ".addClass('unchecked').removeClass('checked');",
62 75  
63   - none then
64   - ""
65   - } +
  76 + none then
  77 + ""
  78 + } +
66 79  
67   - "radio.removeClass('unchecked');
68   - radio.addClass('checked');" + on_script.
  80 + "radio.removeClass('unchecked').addClass('checked');"
  81 + ) + on_script.
69 82  
70 83 public define HTML_Partial_Content
71 84 jq_img_radio
... ... @@ -73,18 +86,31 @@ public define HTML_Partial_Content
73 86 String radio_id,
74 87 RadioGroup radio_group,
75 88 Bool initial_state,
76   -//Bool multi_select_with_shift,
  89 + Bool multi_select_with_shift,
77 90 String image_url,
78 91 String checkbox_label,
79 92 String on_script,
80 93 Icon_orientation orientation
81 94 ) =
82   - partial_content(
83   - [
84   - js_inline(jquery_ready(radio_init_script(radio_id, radio_group, initial_state)))
85   - ],
86   - jquery_button(jquery_img_button(image_url, checkbox_label, radio_id, jQuery_actioner(same, jqscript, radio_onclick_script(radio_id, radio_group, on_script)), orientation))
87   - ).
  95 + partial_content(
  96 + [
  97 + js_inline(jquery_ready(radio_init_script(radio_id, radio_group, initial_state)))
  98 + ],
  99 + jquery_button(jquery_img_button(image_url, checkbox_label, radio_id, jQuery_actioner(same, jqscript, radio_onclick_script(radio_id, radio_group, multi_select_with_shift, on_script)), orientation))
  100 + ).
  101 +
  102 +public define HTML_Partial_Content
  103 + jq_img_radio
  104 + (
  105 + String radio_id,
  106 + RadioGroup radio_group,
  107 + Bool initial_state,
  108 + String image_url,
  109 + String checkbox_label,
  110 + String script,
  111 + Icon_orientation orientation
  112 + ) =
  113 + jq_img_radio(radio_id, none, initial_state, false, image_url, checkbox_label, script, orientation).
88 114  
89 115 public define HTML_Partial_Content
90 116 jq_img_radio
... ... @@ -96,4 +122,4 @@ public define HTML_Partial_Content
96 122 String script,
97 123 Icon_orientation orientation
98 124 ) =
99   - jq_img_radio(radio_id, none, initial_state, image_url, checkbox_label, script, orientation).
  125 + jq_img_radio(radio_id, none, initial_state, false, image_url, checkbox_label, script, orientation).
... ...