Ruby on Rails | Screencasts | Download | Documentation | Weblog | Community | Source

Ticket #3323: effect.toggle.helper.patch

File effect.toggle.helper.patch, 2.2 kB (added by rails@advany.com, 3 years ago)

diff patch

  • C:/Rails/actionpack/test/template/scriptaculous_helper_test.rb

    old new  
    5858    assert_dom_equal %(<script type=\"text/javascript\">\n//<![CDATA[\nDroppables.add('droptarget1', {accept:['tshirts','mugs'], onDrop:function(element){new Ajax.Updater('infobox', 'http://www.example.com/', {asynchronous:true, evalScripts:true, parameters:'id=' + encodeURIComponent(element.id)})}})\n//]]>\n</script>), 
    5959      drop_receiving_element('droptarget1', :accept => ['tshirts','mugs'], :update => 'infobox') 
    6060  end 
     61   
     62  def test_toggle_effect 
     63    assert_equal "Effect.Toggle('posts')", toggle_visual_effect("posts") 
     64    assert_equal "Effect.Toggle('posts','slide')", toggle_visual_effect("posts", "slide") 
     65    assert_equal "Effect.Toggle('posts','bind')", toggle_visual_effect("posts", "bind") 
     66    assert_equal "Effect.Toggle('posts','appear')", toggle_visual_effect("posts", "appear") 
     67  end 
    6168end 
  • C:/Rails/actionpack/lib/action_view/helpers/scriptaculous_helper.rb

    old new  
    100100   
    101101        javascript_tag("Droppables.add('#{element_id}', #{options_for_javascript(options)})") 
    102102      end 
     103       
     104      # Makes the element with the DOM ID specified by +element_id+ toggable 
     105      # with the effect specified (default appear). 
     106      # 
     107      # Example: 
     108      #   <%= link_to_function "Show/Hide", 
     109      #            toggle_visual_effect( 'div', 'slide' ) %> 
     110      # 
     111      # see http://script.aculo.us for more documentation. 
     112      def toggle_visual_effect(element_id, effect='')            
     113        if( effect == 'slide' || effect == 'bind' || effect == 'appear' ) 
     114          "Effect.Toggle('#{element_id}','#{effect}')" 
     115        else 
     116          "Effect.Toggle('#{element_id}')" 
     117        end 
     118      end 
    103119    end 
    104120  end 
    105121end