Module: ActionView::Helpers::JqueryUiHelper
- Defined in:
- lib/action_view/helpers/jquery_ui_helper.rb
Constant Summary collapse
- JQUERY_VAR =
::JRails::JQUERY_VAR
- SCRIPTACULOUS_EFFECTS =
{ appear: {method: 'fadeIn'}, blind_down: {method: 'blind', mode: 'show', options: {direction: 'vertical'}}, blind_up: {method: 'blind', mode: 'hide', options: {direction: 'vertical'}}, blind_right: {method: 'blind', mode: 'show', options: {direction: 'horizontal'}}, blind_left: {method: 'blind', mode: 'hide', options: {direction: 'horizontal'}}, bounce_in: {method: 'bounce', mode: 'show', options: {direction: 'up'}}, bounce_out: {method: 'bounce', mode: 'hide', options: {direction: 'up'}}, drop_in: {method: 'drop', mode: 'show', options: {direction: 'up'}}, drop_out: {method: 'drop', mode: 'hide', options: {direction: 'down'}}, fade: {method: 'fadeOut'}, fold_in: {method: 'fold', mode: 'hide'}, fold_out: {method: 'fold', mode: 'show'}, grow: {method: 'scale', mode: 'show'}, shrink: {method: 'scale', mode: 'hide'}, slide_down: {method: 'slide', mode: 'show', options: {direction: 'up'}}, slide_up: {method: 'slide', mode: 'hide', options: {direction: 'up'}}, slide_right: {method: 'slide', mode: 'show', options: {direction: 'left'}}, slide_left: {method: 'slide', mode: 'hide', options: {direction: 'left'}}, squish: {method: 'scale', mode: 'hide', options: {origin: "['top','left']"}}, switch_on: {method: 'clip', mode: 'show', options: {direction: 'vertical'}}, switch_off: {method: 'clip', mode: 'hide', options: {direction: 'vertical'}}, toggle_appear: {method: 'fadeToggle'}, toggle_slide: {method: 'slide', mode: 'toggle', options: {direction: 'up'}}, toggle_blind: {method: 'blind', mode: 'toggle', options: {direction: 'vertical'}}, }
Instance Method Summary collapse
- #array_or_string_for_javascript(option) ⇒ Object
- #draggable_element(element_id, options = {}) ⇒ Object
- #draggable_element_js(element_id, options = {}) ⇒ Object
- #drop_receiving_element(element_id, options = {}) ⇒ Object
- #drop_receiving_element_js(element_id, options = {}) ⇒ Object
- #sortable_element(element_id, options = {}) ⇒ Object
-
#sortable_element_js(element_id, options = {}) ⇒ Object
:nodoc:.
- #visual_effect(name, element_id = false, js_options = {}) ⇒ Object
Instance Method Details
#array_or_string_for_javascript(option) ⇒ Object
153 154 155 156 157 158 159 |
# File 'lib/action_view/helpers/jquery_ui_helper.rb', line 153 def array_or_string_for_javascript(option) if option.kind_of?(Array) "['#{option.join('\',\'')}']" elsif !option.nil? "'#{option}'" end end |
#draggable_element(element_id, options = {}) ⇒ Object
121 122 123 |
# File 'lib/action_view/helpers/jquery_ui_helper.rb', line 121 def draggable_element(element_id, = {}) javascript_tag(draggable_element_js(element_id, ).chop!) end |
#draggable_element_js(element_id, options = {}) ⇒ Object
125 126 127 |
# File 'lib/action_view/helpers/jquery_ui_helper.rb', line 125 def draggable_element_js(element_id, = {}) %(#{JQUERY_VAR}("#{jquery_id(element_id)}").draggable(#{options_for_javascript(options)});) end |
#drop_receiving_element(element_id, options = {}) ⇒ Object
129 130 131 |
# File 'lib/action_view/helpers/jquery_ui_helper.rb', line 129 def drop_receiving_element(element_id, = {}) javascript_tag(drop_receiving_element_js(element_id, ).chop!) end |
#drop_receiving_element_js(element_id, options = {}) ⇒ Object
133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 |
# File 'lib/action_view/helpers/jquery_ui_helper.rb', line 133 def drop_receiving_element_js(element_id, = {}) #convert similar options [:hoverClass] = .delete(:hoverclass) if [:hoverclass] [:drop] = .delete(:onDrop) if [:onDrop] if [:drop] || [:url] [:with] ||= "'id=' + encodeURIComponent(#{JQUERY_VAR}(ui.draggable).attr('id'))" [:drop] ||= "function(ev, ui){" + remote_function() + "}" end .delete_if { |key, value| JqueryHelper::AJAX_OPTIONS.include?(key) } [:accept] = array_or_string_for_javascript([:accept]) if [:accept] [:activeClass, :hoverClass, :tolerance].each do |option| [option] = "'#{options[option]}'" if [option] end %(#{JQUERY_VAR}('#{jquery_id(element_id)}').droppable(#{options_for_javascript(options)});) end |
#sortable_element(element_id, options = {}) ⇒ Object
68 69 70 |
# File 'lib/action_view/helpers/jquery_ui_helper.rb', line 68 def sortable_element(element_id, = {}) javascript_tag(sortable_element_js(element_id, ).chop!) end |
#sortable_element_js(element_id, options = {}) ⇒ Object
:nodoc:
72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 |
# File 'lib/action_view/helpers/jquery_ui_helper.rb', line 72 def sortable_element_js(element_id, = {}) #:nodoc: #convert similar attributes [:handle] = ".#{options[:handle]}" if [:handle] if [:tag] || [:only] [:items] = "> " [:items] << .delete(:tag) if [:tag] [:items] << ".#{options.delete(:only)}" if [:only] end [:connectWith] = .delete(:containment).map {|x| "##{x}"} if [:containment] [:containment] = .delete(:container) if [:container] [:dropOnEmpty] = false unless [:dropOnEmpty] [:helper] = "'clone'" if [:ghosting] == true [:axis] = case .delete(:constraint) when "vertical", :vertical "y" when "horizontal", :horizontal "x" when false nil when nil "y" end .delete(:axis) if [:axis].nil? .delete(:overlap) .delete(:ghosting) if [:onUpdate] || [:url] if [:format] [:with] ||= "#{JQUERY_VAR}(this).sortable('serialize',{key:'#{element_id}[]', expression:#{options[:format]}})" .delete(:format) else [:with] ||= "#{JQUERY_VAR}(this).sortable('serialize',{key:'#{element_id}[]'})" end [:onUpdate] ||= "function(){" + remote_function() + "}" end .delete_if { |key, value| JqueryHelper::AJAX_OPTIONS.include?(key) } [:update] = .delete(:onUpdate) if [:onUpdate] [:axis, :cancel, :containment, :cursor, :handle, :tolerance, :items, :placeholder].each do |option| [option] = "'#{options[option]}'" if [option] end [:connectWith] = array_or_string_for_javascript([:connectWith]) if [:connectWith] %(#{JQUERY_VAR}('#{jquery_id(element_id)}').sortable(#{options_for_javascript(options)});) end |
#visual_effect(name, element_id = false, js_options = {}) ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/action_view/helpers/jquery_ui_helper.rb', line 36 def visual_effect(name, element_id = false, = {}) if SCRIPTACULOUS_EFFECTS.has_key? name.to_sym effect = SCRIPTACULOUS_EFFECTS[name.to_sym] name = effect[:method] mode = effect[:mode] = .merge(effect[:options]) if effect[:options] end [:color, :direction, :startcolor, :endcolor].each do |option| [option] = "'#{js_options[option]}'" if [option] end if .has_key? :duration speed = .delete :duration speed = (speed * 1000).to_i unless speed.nil? else speed = .delete :speed end if %w[fadeIn fadeOut fadeToggle].include? name javascript = "#{JQUERY_VAR}(\"#{jquery_id(element_id)}\").#{name}(" javascript << "#{speed}" unless speed.nil? javascript << ");" else javascript = "#{JQUERY_VAR}(\"#{jquery_id(element_id)}\").#{mode || 'effect'}('#{name}'" javascript << ",#{options_for_javascript(js_options)}" unless speed.nil? && .empty? javascript << ",#{speed}" unless speed.nil? javascript << ");" end end |