jquery_on_rails 0.2.0 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.2.0
1
+ 0.2.1
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{jquery_on_rails}
8
- s.version = "0.2.0"
8
+ s.version = "0.2.1"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Joe Khoobyar"]
@@ -24,7 +24,9 @@ Gem::Specification.new do |s|
24
24
  "jquery_on_rails.gemspec",
25
25
  "lib/jquery_on_rails.rb",
26
26
  "lib/jquery_on_rails/helpers/jquery_helper.rb",
27
+ "lib/jquery_on_rails/helpers/jquery_ui_helper.rb",
27
28
  "lib/jquery_on_rails/railtie.rb",
29
+ "public/javascripts/jquery-ui-effects.js",
28
30
  "public/javascripts/jquery.js",
29
31
  "public/javascripts/rails.js",
30
32
  "spec/dummy/app/controllers/dummy_controller.rb",
@@ -37,6 +39,7 @@ Gem::Specification.new do |s|
37
39
  "spec/dummy/log/test.log",
38
40
  "spec/jquery_helper_spec.rb",
39
41
  "spec/jquery_on_rails_spec.rb",
42
+ "spec/jquery_ui_helper_spec.rb",
40
43
  "spec/spec_helper.rb"
41
44
  ]
42
45
  s.homepage = %q{http://github.com/joekhoobyar/jquery_on_rails}
@@ -55,6 +58,7 @@ Gem::Specification.new do |s|
55
58
  "spec/dummy/config/routes.rb",
56
59
  "spec/jquery_helper_spec.rb",
57
60
  "spec/jquery_on_rails_spec.rb",
61
+ "spec/jquery_ui_helper_spec.rb",
58
62
  "spec/spec_helper.rb"
59
63
  ]
60
64
 
@@ -32,14 +32,16 @@ module JQueryOnRails
32
32
  :jsonp, :jsonpCallback, :password, :processData, :scriptCharset,
33
33
  :timeout, :traditional, :type, :username, :xhr])
34
34
  CONFIRM_FUNCTION = 'confirm'.freeze
35
+ TOGGLE_EFFECTS = Set.new([:toggle_appear, :toggle_slide, :toggle_blind])
36
+ RENAME_EFFECTS = { :appear=>'fadeIn', :fade=>'fadeOut' }
35
37
  end
36
38
 
37
39
  # Returns the JavaScript needed for a remote function.
38
40
  # Takes the same arguments as link_to_remote.
39
41
  #
40
42
  # Example:
41
- # # Generates: <select id="options" onchange="$.ajax({method : 'GET',
42
- # # url : '/testing/update_options', async:true, evalScripts:true,
43
+ # # Generates: <select id="options" onchange="jQuery.ajax({method : 'GET',
44
+ # # url : '/testing/update_options', processData:false, async:true, evalScripts:true,
43
45
  # # complete : function(data,status,request){$('#options').html(request.responseText)}})">
44
46
  # <select id="options" onchange="<%= remote_function(:update => "options",
45
47
  # :url => { :action => :update_options }) %>">
@@ -54,6 +56,22 @@ module JQueryOnRails
54
56
  function = "if (#{confirm_for_javascript(options[:confirm])}) { #{function}; }" if options[:confirm]
55
57
  function
56
58
  end
59
+
60
+ # Basic effects, limited to those supported by core jQuery 1.4
61
+ # Additional effects are supported by jQuery UI.
62
+ def visual_effect(name, element_id = false, js_options = {})
63
+ element = element_id ? ActiveSupport::JSON.encode("##{element_id}") : "element"
64
+ element = "jQuery(#{element})"
65
+ js_options = (options_for_javascript js_options unless js_options.empty?)
66
+ case name = name.to_sym
67
+ when :toggle_slide
68
+ "#{element}.slideToggle(#{js_options});"
69
+ when :toggle_appear
70
+ "(function(state){ return (function() { state=!state; return #{element}['fade'+(state?'In':'Out')](#{js_options}); })(); })(#{element}.css('visiblity')!='hidden');"
71
+ else
72
+ "#{element}.#{RENAME_EFFECTS[name] || name.to_s.camelize(false)}(#{js_options});"
73
+ end
74
+ end
57
75
 
58
76
  # Mostly copied from Rails 3 PrototypeHelper
59
77
  class JavaScriptGenerator #:nodoc:
@@ -162,6 +180,10 @@ module JQueryOnRails
162
180
  yield
163
181
  record "}, #{(seconds * 1000).to_i})"
164
182
  end
183
+
184
+ def visual_effect(name, id = nil, options = {})
185
+ record @context.send(:visual_effect, name, id, options)
186
+ end
165
187
 
166
188
  private
167
189
  def loop_on_multiple_ids(method, ids)
@@ -233,7 +255,7 @@ module JQueryOnRails
233
255
  def update_page_tag(html_options = {}, &block)
234
256
  javascript_tag update_page(&block), html_options
235
257
  end
236
-
258
+
237
259
  protected
238
260
 
239
261
  # Generates a JavaScript confirm() method call.
@@ -0,0 +1,52 @@
1
+ module JQueryOnRails
2
+ module Helpers
3
+ module JQueryUiHelper
4
+ unless const_defined? :FX_OPTIONS
5
+ FX_OPTIONS = {
6
+ 'Up' => {:mode=>:hide,:direction=>:vertical}, 'Down' => {:mode=>:show,:direction=>:vertical},
7
+ 'Left' => {:mode=>:hide,:direction=>:horizontal}, 'Right' => {:mode=>:show,:direction=>:horizontal},
8
+ 'Out' => {:mode=>:hide,:direction=>nil}, 'In' => {:mode=>:show,:direction=>nil},
9
+ :fadeIn => {:mode=>:primitive,:direction=>nil}, :fadeOut => {:mode=>:primitive,:direction=>nil},
10
+ :animate => {:mode=>:primitive,:direction=>nil}, :puff => {:direction=>nil}, :size => {:direction=>nil},
11
+ :toggleAppear => {:direction=>nil,:mode=>"return element[name+(element.is(':hidden')?'In':'Out')](options);"}
12
+ }.with_indifferent_access
13
+
14
+ FX_NAMES = HashWithIndifferentAccess.new{|h,k| k}
15
+ FX_NAMES.update :toggleAppear=>'fade', :appear=>'fadeIn', :fade=>'fadeOut',
16
+ :morph=>'animate', :shrink=>'sizeOut', :grow=>'sizeIn'
17
+ end
18
+
19
+ # Generates jQuery UI effects. This expands upon the core jQuery 1.4 effects
20
+ # that are generated by JQueryHelper#visual_effect
21
+ def visual_effect(name, element_id=false, js_options={})
22
+ element = element_id ? ActiveSupport::JSON.encode("##{element_id}") : "element"
23
+
24
+ fx_opt, name = FX_OPTIONS[name = name.to_s.camelize(:lower)] || {}, FX_NAMES[name]
25
+ fx_opt ||= FX_NAMES[name]
26
+ fx_opt[:mode], name = :toggle, FX_NAMES[name[6,1].downcase+name[7..-1]] if name.start_with? 'toggle'
27
+ fx_opt = FX_OPTIONS[$1].merge fx_opt if ! FX_OPTIONS.include? name and name.sub! /(Up|Down|Left|Right|In|Out)$/, ''
28
+ fx_opt = FX_OPTIONS[name].merge fx_opt if FX_OPTIONS.include? name
29
+ fx_opt.merge! js_options
30
+
31
+ if ! fx_opt.include? :direction then fx_opt[:direction] = "'vertical'"
32
+ elsif fx_opt[:direction].nil? then fx_opt.delete :direction
33
+ else fx_opt[:direction] = "'#{fx_opt[:direction]}'"
34
+ end
35
+
36
+ # [:endcolor, :direction, :startcolor, :scaleMode, :restorecolor]
37
+ fx = "jQuery(#{element})"
38
+ fx = "#{fx}.css('background-color','#{fx_opt.delete :startcolor}')" if fx_opt[:startcolor]
39
+ if name=='animate' then fx_opt[:backgroundColor] ||= fx_opt.delete :endcolor
40
+ elsif fx_opt[:endcolor] then fx = "#{fx}.animate('background-color','#{fx_opt.delete :endcolor}')"
41
+ end
42
+ method, fx_opt = fx_opt.delete(:mode)||:effect, (options_for_javascript fx_opt unless fx_opt.empty?)
43
+
44
+ case method; when :primitive; "#{fx}.#{name}(#{fx_opt});"
45
+ when Symbol; "#{fx}.#{method}('#{name}'#{','+fx_opt if fx_opt.present?});"
46
+ else "(function(element,name,options){ #{method} })(#{fx},'#{name}'#{','+fx_opt if fx_opt.present?});"
47
+ end
48
+ end
49
+
50
+ end
51
+ end
52
+ end
@@ -1,4 +1,14 @@
1
+ require 'active_support'
2
+
1
3
  module JQueryOnRails
2
4
  VERSION = File.read(File.expand_path('../../VERSION', __FILE__)).strip
5
+
6
+ module Helpers
7
+ extend ActiveSupport::Autoload
8
+
9
+ autoload :JQueryHelper, 'jquery_on_rails/helpers/jquery_helper'
10
+ autoload :JQueryUiHelper, 'jquery_on_rails/helpers/jquery_ui_helper'
11
+ end
12
+
3
13
  require 'jquery_on_rails/railtie' if defined? Rails
4
14
  end
@@ -0,0 +1,207 @@
1
+ /*
2
+ * jQuery UI Effects 1.8.1
3
+ *
4
+ * Copyright (c) 2010 AUTHORS.txt (http://jqueryui.com/about)
5
+ * Dual licensed under the MIT (MIT-LICENSE.txt)
6
+ * and GPL (GPL-LICENSE.txt) licenses.
7
+ *
8
+ * http://docs.jquery.com/UI/Effects/
9
+ */
10
+ jQuery.effects||function(f){function k(c){var a;if(c&&c.constructor==Array&&c.length==3)return c;if(a=/rgb\(\s*([0-9]{1,3})\s*,\s*([0-9]{1,3})\s*,\s*([0-9]{1,3})\s*\)/.exec(c))return[parseInt(a[1],10),parseInt(a[2],10),parseInt(a[3],10)];if(a=/rgb\(\s*([0-9]+(?:\.[0-9]+)?)\%\s*,\s*([0-9]+(?:\.[0-9]+)?)\%\s*,\s*([0-9]+(?:\.[0-9]+)?)\%\s*\)/.exec(c))return[parseFloat(a[1])*2.55,parseFloat(a[2])*2.55,parseFloat(a[3])*2.55];if(a=/#([a-fA-F0-9]{2})([a-fA-F0-9]{2})([a-fA-F0-9]{2})/.exec(c))return[parseInt(a[1],
11
+ 16),parseInt(a[2],16),parseInt(a[3],16)];if(a=/#([a-fA-F0-9])([a-fA-F0-9])([a-fA-F0-9])/.exec(c))return[parseInt(a[1]+a[1],16),parseInt(a[2]+a[2],16),parseInt(a[3]+a[3],16)];if(/rgba\(0, 0, 0, 0\)/.exec(c))return l.transparent;return l[f.trim(c).toLowerCase()]}function q(c,a){var b;do{b=f.curCSS(c,a);if(b!=""&&b!="transparent"||f.nodeName(c,"body"))break;a="backgroundColor"}while(c=c.parentNode);return k(b)}function m(){var c=document.defaultView?document.defaultView.getComputedStyle(this,null):this.currentStyle,
12
+ a={},b,d;if(c&&c.length&&c[0]&&c[c[0]])for(var e=c.length;e--;){b=c[e];if(typeof c[b]=="string"){d=b.replace(/\-(\w)/g,function(g,h){return h.toUpperCase()});a[d]=c[b]}}else for(b in c)if(typeof c[b]==="string")a[b]=c[b];return a}function n(c){var a,b;for(a in c){b=c[a];if(b==null||f.isFunction(b)||a in r||/scrollbar/.test(a)||!/color/i.test(a)&&isNaN(parseFloat(b)))delete c[a]}return c}function s(c,a){var b={_:0},d;for(d in a)if(c[d]!=a[d])b[d]=a[d];return b}function j(c,a,b,d){if(typeof c=="object"){d=
13
+ a;b=null;a=c;c=a.effect}if(f.isFunction(a)){d=a;b=null;a={}}if(f.isFunction(b)){d=b;b=null}if(typeof a=="number"||f.fx.speeds[a]){d=b;b=a;a={}}a=a||{};b=b||a.duration;b=f.fx.off?0:typeof b=="number"?b:f.fx.speeds[b]||f.fx.speeds._default;d=d||a.complete;return[c,a,b,d]}f.effects={};f.each(["backgroundColor","borderBottomColor","borderLeftColor","borderRightColor","borderTopColor","color","outlineColor"],function(c,a){f.fx.step[a]=function(b){if(!b.colorInit){b.start=q(b.elem,a);b.end=k(b.end);b.colorInit=
14
+ true}b.elem.style[a]="rgb("+Math.max(Math.min(parseInt(b.pos*(b.end[0]-b.start[0])+b.start[0],10),255),0)+","+Math.max(Math.min(parseInt(b.pos*(b.end[1]-b.start[1])+b.start[1],10),255),0)+","+Math.max(Math.min(parseInt(b.pos*(b.end[2]-b.start[2])+b.start[2],10),255),0)+")"}});var l={aqua:[0,255,255],azure:[240,255,255],beige:[245,245,220],black:[0,0,0],blue:[0,0,255],brown:[165,42,42],cyan:[0,255,255],darkblue:[0,0,139],darkcyan:[0,139,139],darkgrey:[169,169,169],darkgreen:[0,100,0],darkkhaki:[189,
15
+ 183,107],darkmagenta:[139,0,139],darkolivegreen:[85,107,47],darkorange:[255,140,0],darkorchid:[153,50,204],darkred:[139,0,0],darksalmon:[233,150,122],darkviolet:[148,0,211],fuchsia:[255,0,255],gold:[255,215,0],green:[0,128,0],indigo:[75,0,130],khaki:[240,230,140],lightblue:[173,216,230],lightcyan:[224,255,255],lightgreen:[144,238,144],lightgrey:[211,211,211],lightpink:[255,182,193],lightyellow:[255,255,224],lime:[0,255,0],magenta:[255,0,255],maroon:[128,0,0],navy:[0,0,128],olive:[128,128,0],orange:[255,
16
+ 165,0],pink:[255,192,203],purple:[128,0,128],violet:[128,0,128],red:[255,0,0],silver:[192,192,192],white:[255,255,255],yellow:[255,255,0],transparent:[255,255,255]},o=["add","remove","toggle"],r={border:1,borderBottom:1,borderColor:1,borderLeft:1,borderRight:1,borderTop:1,borderWidth:1,margin:1,padding:1};f.effects.animateClass=function(c,a,b,d){if(f.isFunction(b)){d=b;b=null}return this.each(function(){var e=f(this),g=e.attr("style")||" ",h=n(m.call(this)),p,t=e.attr("className");f.each(o,function(u,
17
+ i){c[i]&&e[i+"Class"](c[i])});p=n(m.call(this));e.attr("className",t);e.animate(s(h,p),a,b,function(){f.each(o,function(u,i){c[i]&&e[i+"Class"](c[i])});if(typeof e.attr("style")=="object"){e.attr("style").cssText="";e.attr("style").cssText=g}else e.attr("style",g);d&&d.apply(this,arguments)})})};f.fn.extend({_addClass:f.fn.addClass,addClass:function(c,a,b,d){return a?f.effects.animateClass.apply(this,[{add:c},a,b,d]):this._addClass(c)},_removeClass:f.fn.removeClass,removeClass:function(c,a,b,d){return a?
18
+ f.effects.animateClass.apply(this,[{remove:c},a,b,d]):this._removeClass(c)},_toggleClass:f.fn.toggleClass,toggleClass:function(c,a,b,d,e){return typeof a=="boolean"||a===undefined?b?f.effects.animateClass.apply(this,[a?{add:c}:{remove:c},b,d,e]):this._toggleClass(c,a):f.effects.animateClass.apply(this,[{toggle:c},a,b,d])},switchClass:function(c,a,b,d,e){return f.effects.animateClass.apply(this,[{add:a,remove:c},b,d,e])}});f.extend(f.effects,{version:"1.8.1",save:function(c,a){for(var b=0;b<a.length;b++)a[b]!==
19
+ null&&c.data("ec.storage."+a[b],c[0].style[a[b]])},restore:function(c,a){for(var b=0;b<a.length;b++)a[b]!==null&&c.css(a[b],c.data("ec.storage."+a[b]))},setMode:function(c,a){if(a=="toggle")a=c.is(":hidden")?"show":"hide";return a},getBaseline:function(c,a){var b;switch(c[0]){case "top":b=0;break;case "middle":b=0.5;break;case "bottom":b=1;break;default:b=c[0]/a.height}switch(c[1]){case "left":c=0;break;case "center":c=0.5;break;case "right":c=1;break;default:c=c[1]/a.width}return{x:c,y:b}},createWrapper:function(c){if(c.parent().is(".ui-effects-wrapper"))return c.parent();
20
+ var a={width:c.outerWidth(true),height:c.outerHeight(true),"float":c.css("float")},b=f("<div></div>").addClass("ui-effects-wrapper").css({fontSize:"100%",background:"transparent",border:"none",margin:0,padding:0});c.wrap(b);b=c.parent();if(c.css("position")=="static"){b.css({position:"relative"});c.css({position:"relative"})}else{f.extend(a,{position:c.css("position"),zIndex:c.css("z-index")});f.each(["top","left","bottom","right"],function(d,e){a[e]=c.css(e);if(isNaN(parseInt(a[e],10)))a[e]="auto"});
21
+ c.css({position:"relative",top:0,left:0})}return b.css(a).show()},removeWrapper:function(c){if(c.parent().is(".ui-effects-wrapper"))return c.parent().replaceWith(c);return c},setTransition:function(c,a,b,d){d=d||{};f.each(a,function(e,g){unit=c.cssUnit(g);if(unit[0]>0)d[g]=unit[0]*b+unit[1]});return d}});f.fn.extend({effect:function(c){var a=j.apply(this,arguments);a={options:a[1],duration:a[2],callback:a[3]};var b=f.effects[c];return b&&!f.fx.off?b.call(this,a):this},_show:f.fn.show,show:function(c){if(!c||
22
+ typeof c=="number"||f.fx.speeds[c])return this._show.apply(this,arguments);else{var a=j.apply(this,arguments);a[1].mode="show";return this.effect.apply(this,a)}},_hide:f.fn.hide,hide:function(c){if(!c||typeof c=="number"||f.fx.speeds[c])return this._hide.apply(this,arguments);else{var a=j.apply(this,arguments);a[1].mode="hide";return this.effect.apply(this,a)}},__toggle:f.fn.toggle,toggle:function(c){if(!c||typeof c=="number"||f.fx.speeds[c]||typeof c=="boolean"||f.isFunction(c))return this.__toggle.apply(this,
23
+ arguments);else{var a=j.apply(this,arguments);a[1].mode="toggle";return this.effect.apply(this,a)}},cssUnit:function(c){var a=this.css(c),b=[];f.each(["em","px","%","pt"],function(d,e){if(a.indexOf(e)>0)b=[parseFloat(a),e]});return b}});f.easing.jswing=f.easing.swing;f.extend(f.easing,{def:"easeOutQuad",swing:function(c,a,b,d,e){return f.easing[f.easing.def](c,a,b,d,e)},easeInQuad:function(c,a,b,d,e){return d*(a/=e)*a+b},easeOutQuad:function(c,a,b,d,e){return-d*(a/=e)*(a-2)+b},easeInOutQuad:function(c,
24
+ a,b,d,e){if((a/=e/2)<1)return d/2*a*a+b;return-d/2*(--a*(a-2)-1)+b},easeInCubic:function(c,a,b,d,e){return d*(a/=e)*a*a+b},easeOutCubic:function(c,a,b,d,e){return d*((a=a/e-1)*a*a+1)+b},easeInOutCubic:function(c,a,b,d,e){if((a/=e/2)<1)return d/2*a*a*a+b;return d/2*((a-=2)*a*a+2)+b},easeInQuart:function(c,a,b,d,e){return d*(a/=e)*a*a*a+b},easeOutQuart:function(c,a,b,d,e){return-d*((a=a/e-1)*a*a*a-1)+b},easeInOutQuart:function(c,a,b,d,e){if((a/=e/2)<1)return d/2*a*a*a*a+b;return-d/2*((a-=2)*a*a*a-2)+
25
+ b},easeInQuint:function(c,a,b,d,e){return d*(a/=e)*a*a*a*a+b},easeOutQuint:function(c,a,b,d,e){return d*((a=a/e-1)*a*a*a*a+1)+b},easeInOutQuint:function(c,a,b,d,e){if((a/=e/2)<1)return d/2*a*a*a*a*a+b;return d/2*((a-=2)*a*a*a*a+2)+b},easeInSine:function(c,a,b,d,e){return-d*Math.cos(a/e*(Math.PI/2))+d+b},easeOutSine:function(c,a,b,d,e){return d*Math.sin(a/e*(Math.PI/2))+b},easeInOutSine:function(c,a,b,d,e){return-d/2*(Math.cos(Math.PI*a/e)-1)+b},easeInExpo:function(c,a,b,d,e){return a==0?b:d*Math.pow(2,
26
+ 10*(a/e-1))+b},easeOutExpo:function(c,a,b,d,e){return a==e?b+d:d*(-Math.pow(2,-10*a/e)+1)+b},easeInOutExpo:function(c,a,b,d,e){if(a==0)return b;if(a==e)return b+d;if((a/=e/2)<1)return d/2*Math.pow(2,10*(a-1))+b;return d/2*(-Math.pow(2,-10*--a)+2)+b},easeInCirc:function(c,a,b,d,e){return-d*(Math.sqrt(1-(a/=e)*a)-1)+b},easeOutCirc:function(c,a,b,d,e){return d*Math.sqrt(1-(a=a/e-1)*a)+b},easeInOutCirc:function(c,a,b,d,e){if((a/=e/2)<1)return-d/2*(Math.sqrt(1-a*a)-1)+b;return d/2*(Math.sqrt(1-(a-=2)*
27
+ a)+1)+b},easeInElastic:function(c,a,b,d,e){c=1.70158;var g=0,h=d;if(a==0)return b;if((a/=e)==1)return b+d;g||(g=e*0.3);if(h<Math.abs(d)){h=d;c=g/4}else c=g/(2*Math.PI)*Math.asin(d/h);return-(h*Math.pow(2,10*(a-=1))*Math.sin((a*e-c)*2*Math.PI/g))+b},easeOutElastic:function(c,a,b,d,e){c=1.70158;var g=0,h=d;if(a==0)return b;if((a/=e)==1)return b+d;g||(g=e*0.3);if(h<Math.abs(d)){h=d;c=g/4}else c=g/(2*Math.PI)*Math.asin(d/h);return h*Math.pow(2,-10*a)*Math.sin((a*e-c)*2*Math.PI/g)+d+b},easeInOutElastic:function(c,
28
+ a,b,d,e){c=1.70158;var g=0,h=d;if(a==0)return b;if((a/=e/2)==2)return b+d;g||(g=e*0.3*1.5);if(h<Math.abs(d)){h=d;c=g/4}else c=g/(2*Math.PI)*Math.asin(d/h);if(a<1)return-0.5*h*Math.pow(2,10*(a-=1))*Math.sin((a*e-c)*2*Math.PI/g)+b;return h*Math.pow(2,-10*(a-=1))*Math.sin((a*e-c)*2*Math.PI/g)*0.5+d+b},easeInBack:function(c,a,b,d,e,g){if(g==undefined)g=1.70158;return d*(a/=e)*a*((g+1)*a-g)+b},easeOutBack:function(c,a,b,d,e,g){if(g==undefined)g=1.70158;return d*((a=a/e-1)*a*((g+1)*a+g)+1)+b},easeInOutBack:function(c,
29
+ a,b,d,e,g){if(g==undefined)g=1.70158;if((a/=e/2)<1)return d/2*a*a*(((g*=1.525)+1)*a-g)+b;return d/2*((a-=2)*a*(((g*=1.525)+1)*a+g)+2)+b},easeInBounce:function(c,a,b,d,e){return d-f.easing.easeOutBounce(c,e-a,0,d,e)+b},easeOutBounce:function(c,a,b,d,e){return(a/=e)<1/2.75?d*7.5625*a*a+b:a<2/2.75?d*(7.5625*(a-=1.5/2.75)*a+0.75)+b:a<2.5/2.75?d*(7.5625*(a-=2.25/2.75)*a+0.9375)+b:d*(7.5625*(a-=2.625/2.75)*a+0.984375)+b},easeInOutBounce:function(c,a,b,d,e){if(a<e/2)return f.easing.easeInBounce(c,a*2,0,
30
+ d,e)*0.5+b;return f.easing.easeOutBounce(c,a*2-e,0,d,e)*0.5+d*0.5+b}})}(jQuery);
31
+ ;/*
32
+ * jQuery UI Effects Blind 1.8.1
33
+ *
34
+ * Copyright (c) 2010 AUTHORS.txt (http://jqueryui.com/about)
35
+ * Dual licensed under the MIT (MIT-LICENSE.txt)
36
+ * and GPL (GPL-LICENSE.txt) licenses.
37
+ *
38
+ * http://docs.jquery.com/UI/Effects/Blind
39
+ *
40
+ * Depends:
41
+ * jquery.effects.core.js
42
+ */
43
+ (function(b){b.effects.blind=function(c){return this.queue(function(){var a=b(this),g=["position","top","left"],f=b.effects.setMode(a,c.options.mode||"hide"),d=c.options.direction||"vertical";b.effects.save(a,g);a.show();var e=b.effects.createWrapper(a).css({overflow:"hidden"}),h=d=="vertical"?"height":"width";d=d=="vertical"?e.height():e.width();f=="show"&&e.css(h,0);var i={};i[h]=f=="show"?d:0;e.animate(i,c.duration,c.options.easing,function(){f=="hide"&&a.hide();b.effects.restore(a,g);b.effects.removeWrapper(a);
44
+ c.callback&&c.callback.apply(a[0],arguments);a.dequeue()})})}})(jQuery);
45
+ ;/*
46
+ * jQuery UI Effects Bounce 1.8.1
47
+ *
48
+ * Copyright (c) 2010 AUTHORS.txt (http://jqueryui.com/about)
49
+ * Dual licensed under the MIT (MIT-LICENSE.txt)
50
+ * and GPL (GPL-LICENSE.txt) licenses.
51
+ *
52
+ * http://docs.jquery.com/UI/Effects/Bounce
53
+ *
54
+ * Depends:
55
+ * jquery.effects.core.js
56
+ */
57
+ (function(e){e.effects.bounce=function(b){return this.queue(function(){var a=e(this),l=["position","top","left"],h=e.effects.setMode(a,b.options.mode||"effect"),d=b.options.direction||"up",c=b.options.distance||20,m=b.options.times||5,i=b.duration||250;/show|hide/.test(h)&&l.push("opacity");e.effects.save(a,l);a.show();e.effects.createWrapper(a);var f=d=="up"||d=="down"?"top":"left";d=d=="up"||d=="left"?"pos":"neg";c=b.options.distance||(f=="top"?a.outerHeight({margin:true})/3:a.outerWidth({margin:true})/
58
+ 3);if(h=="show")a.css("opacity",0).css(f,d=="pos"?-c:c);if(h=="hide")c/=m*2;h!="hide"&&m--;if(h=="show"){var g={opacity:1};g[f]=(d=="pos"?"+=":"-=")+c;a.animate(g,i/2,b.options.easing);c/=2;m--}for(g=0;g<m;g++){var j={},k={};j[f]=(d=="pos"?"-=":"+=")+c;k[f]=(d=="pos"?"+=":"-=")+c;a.animate(j,i/2,b.options.easing).animate(k,i/2,b.options.easing);c=h=="hide"?c*2:c/2}if(h=="hide"){g={opacity:0};g[f]=(d=="pos"?"-=":"+=")+c;a.animate(g,i/2,b.options.easing,function(){a.hide();e.effects.restore(a,l);e.effects.removeWrapper(a);
59
+ b.callback&&b.callback.apply(this,arguments)})}else{j={};k={};j[f]=(d=="pos"?"-=":"+=")+c;k[f]=(d=="pos"?"+=":"-=")+c;a.animate(j,i/2,b.options.easing).animate(k,i/2,b.options.easing,function(){e.effects.restore(a,l);e.effects.removeWrapper(a);b.callback&&b.callback.apply(this,arguments)})}a.queue("fx",function(){a.dequeue()});a.dequeue()})}})(jQuery);
60
+ ;/*
61
+ * jQuery UI Effects Clip 1.8.1
62
+ *
63
+ * Copyright (c) 2010 AUTHORS.txt (http://jqueryui.com/about)
64
+ * Dual licensed under the MIT (MIT-LICENSE.txt)
65
+ * and GPL (GPL-LICENSE.txt) licenses.
66
+ *
67
+ * http://docs.jquery.com/UI/Effects/Clip
68
+ *
69
+ * Depends:
70
+ * jquery.effects.core.js
71
+ */
72
+ (function(b){b.effects.clip=function(e){return this.queue(function(){var a=b(this),i=["position","top","left","height","width"],f=b.effects.setMode(a,e.options.mode||"hide"),c=e.options.direction||"vertical";b.effects.save(a,i);a.show();var d=b.effects.createWrapper(a).css({overflow:"hidden"});d=a[0].tagName=="IMG"?d:a;var g={size:c=="vertical"?"height":"width",position:c=="vertical"?"top":"left"};c=c=="vertical"?d.height():d.width();if(f=="show"){d.css(g.size,0);d.css(g.position,c/2)}var h={};h[g.size]=
73
+ f=="show"?c:0;h[g.position]=f=="show"?0:c/2;d.animate(h,{queue:false,duration:e.duration,easing:e.options.easing,complete:function(){f=="hide"&&a.hide();b.effects.restore(a,i);b.effects.removeWrapper(a);e.callback&&e.callback.apply(a[0],arguments);a.dequeue()}})})}})(jQuery);
74
+ ;/*
75
+ * jQuery UI Effects Drop 1.8.1
76
+ *
77
+ * Copyright (c) 2010 AUTHORS.txt (http://jqueryui.com/about)
78
+ * Dual licensed under the MIT (MIT-LICENSE.txt)
79
+ * and GPL (GPL-LICENSE.txt) licenses.
80
+ *
81
+ * http://docs.jquery.com/UI/Effects/Drop
82
+ *
83
+ * Depends:
84
+ * jquery.effects.core.js
85
+ */
86
+ (function(c){c.effects.drop=function(d){return this.queue(function(){var a=c(this),h=["position","top","left","opacity"],e=c.effects.setMode(a,d.options.mode||"hide"),b=d.options.direction||"left";c.effects.save(a,h);a.show();c.effects.createWrapper(a);var f=b=="up"||b=="down"?"top":"left";b=b=="up"||b=="left"?"pos":"neg";var g=d.options.distance||(f=="top"?a.outerHeight({margin:true})/2:a.outerWidth({margin:true})/2);if(e=="show")a.css("opacity",0).css(f,b=="pos"?-g:g);var i={opacity:e=="show"?1:
87
+ 0};i[f]=(e=="show"?b=="pos"?"+=":"-=":b=="pos"?"-=":"+=")+g;a.animate(i,{queue:false,duration:d.duration,easing:d.options.easing,complete:function(){e=="hide"&&a.hide();c.effects.restore(a,h);c.effects.removeWrapper(a);d.callback&&d.callback.apply(this,arguments);a.dequeue()}})})}})(jQuery);
88
+ ;/*
89
+ * jQuery UI Effects Explode 1.8.1
90
+ *
91
+ * Copyright (c) 2010 AUTHORS.txt (http://jqueryui.com/about)
92
+ * Dual licensed under the MIT (MIT-LICENSE.txt)
93
+ * and GPL (GPL-LICENSE.txt) licenses.
94
+ *
95
+ * http://docs.jquery.com/UI/Effects/Explode
96
+ *
97
+ * Depends:
98
+ * jquery.effects.core.js
99
+ */
100
+ (function(j){j.effects.explode=function(a){return this.queue(function(){var c=a.options.pieces?Math.round(Math.sqrt(a.options.pieces)):3,d=a.options.pieces?Math.round(Math.sqrt(a.options.pieces)):3;a.options.mode=a.options.mode=="toggle"?j(this).is(":visible")?"hide":"show":a.options.mode;var b=j(this).show().css("visibility","hidden"),g=b.offset();g.top-=parseInt(b.css("marginTop"),10)||0;g.left-=parseInt(b.css("marginLeft"),10)||0;for(var h=b.outerWidth(true),i=b.outerHeight(true),e=0;e<c;e++)for(var f=
101
+ 0;f<d;f++)b.clone().appendTo("body").wrap("<div></div>").css({position:"absolute",visibility:"visible",left:-f*(h/d),top:-e*(i/c)}).parent().addClass("ui-effects-explode").css({position:"absolute",overflow:"hidden",width:h/d,height:i/c,left:g.left+f*(h/d)+(a.options.mode=="show"?(f-Math.floor(d/2))*(h/d):0),top:g.top+e*(i/c)+(a.options.mode=="show"?(e-Math.floor(c/2))*(i/c):0),opacity:a.options.mode=="show"?0:1}).animate({left:g.left+f*(h/d)+(a.options.mode=="show"?0:(f-Math.floor(d/2))*(h/d)),top:g.top+
102
+ e*(i/c)+(a.options.mode=="show"?0:(e-Math.floor(c/2))*(i/c)),opacity:a.options.mode=="show"?1:0},a.duration||500);setTimeout(function(){a.options.mode=="show"?b.css({visibility:"visible"}):b.css({visibility:"visible"}).hide();a.callback&&a.callback.apply(b[0]);b.dequeue();j("div.ui-effects-explode").remove()},a.duration||500)})}})(jQuery);
103
+ ;/*
104
+ * jQuery UI Effects Fold 1.8.1
105
+ *
106
+ * Copyright (c) 2010 AUTHORS.txt (http://jqueryui.com/about)
107
+ * Dual licensed under the MIT (MIT-LICENSE.txt)
108
+ * and GPL (GPL-LICENSE.txt) licenses.
109
+ *
110
+ * http://docs.jquery.com/UI/Effects/Fold
111
+ *
112
+ * Depends:
113
+ * jquery.effects.core.js
114
+ */
115
+ (function(c){c.effects.fold=function(a){return this.queue(function(){var b=c(this),j=["position","top","left"],d=c.effects.setMode(b,a.options.mode||"hide"),g=a.options.size||15,h=!!a.options.horizFirst,k=a.duration?a.duration/2:c.fx.speeds._default/2;c.effects.save(b,j);b.show();var e=c.effects.createWrapper(b).css({overflow:"hidden"}),f=d=="show"!=h,l=f?["width","height"]:["height","width"];f=f?[e.width(),e.height()]:[e.height(),e.width()];var i=/([0-9]+)%/.exec(g);if(i)g=parseInt(i[1],10)/100*
116
+ f[d=="hide"?0:1];if(d=="show")e.css(h?{height:0,width:g}:{height:g,width:0});h={};i={};h[l[0]]=d=="show"?f[0]:g;i[l[1]]=d=="show"?f[1]:0;e.animate(h,k,a.options.easing).animate(i,k,a.options.easing,function(){d=="hide"&&b.hide();c.effects.restore(b,j);c.effects.removeWrapper(b);a.callback&&a.callback.apply(b[0],arguments);b.dequeue()})})}})(jQuery);
117
+ ;/*
118
+ * jQuery UI Effects Highlight 1.8.1
119
+ *
120
+ * Copyright (c) 2010 AUTHORS.txt (http://jqueryui.com/about)
121
+ * Dual licensed under the MIT (MIT-LICENSE.txt)
122
+ * and GPL (GPL-LICENSE.txt) licenses.
123
+ *
124
+ * http://docs.jquery.com/UI/Effects/Highlight
125
+ *
126
+ * Depends:
127
+ * jquery.effects.core.js
128
+ */
129
+ (function(b){b.effects.highlight=function(c){return this.queue(function(){var a=b(this),e=["backgroundImage","backgroundColor","opacity"],d=b.effects.setMode(a,c.options.mode||"show"),f={backgroundColor:a.css("backgroundColor")};if(d=="hide")f.opacity=0;b.effects.save(a,e);a.show().css({backgroundImage:"none",backgroundColor:c.options.color||"#ffff99"}).animate(f,{queue:false,duration:c.duration,easing:c.options.easing,complete:function(){d=="hide"&&a.hide();b.effects.restore(a,e);d=="show"&&!b.support.opacity&&
130
+ this.style.removeAttribute("filter");c.callback&&c.callback.apply(this,arguments);a.dequeue()}})})}})(jQuery);
131
+ ;/*
132
+ * jQuery UI Effects Pulsate 1.8.1
133
+ *
134
+ * Copyright (c) 2010 AUTHORS.txt (http://jqueryui.com/about)
135
+ * Dual licensed under the MIT (MIT-LICENSE.txt)
136
+ * and GPL (GPL-LICENSE.txt) licenses.
137
+ *
138
+ * http://docs.jquery.com/UI/Effects/Pulsate
139
+ *
140
+ * Depends:
141
+ * jquery.effects.core.js
142
+ */
143
+ (function(d){d.effects.pulsate=function(a){return this.queue(function(){var b=d(this),c=d.effects.setMode(b,a.options.mode||"show");times=(a.options.times||5)*2-1;duration=a.duration?a.duration/2:d.fx.speeds._default/2;isVisible=b.is(":visible");animateTo=0;if(!isVisible){b.css("opacity",0).show();animateTo=1}if(c=="hide"&&isVisible||c=="show"&&!isVisible)times--;for(c=0;c<times;c++){b.animate({opacity:animateTo},duration,a.options.easing);animateTo=(animateTo+1)%2}b.animate({opacity:animateTo},duration,
144
+ a.options.easing,function(){animateTo==0&&b.hide();a.callback&&a.callback.apply(this,arguments)});b.queue("fx",function(){b.dequeue()}).dequeue()})}})(jQuery);
145
+ ;/*
146
+ * jQuery UI Effects Scale 1.8.1
147
+ *
148
+ * Copyright (c) 2010 AUTHORS.txt (http://jqueryui.com/about)
149
+ * Dual licensed under the MIT (MIT-LICENSE.txt)
150
+ * and GPL (GPL-LICENSE.txt) licenses.
151
+ *
152
+ * http://docs.jquery.com/UI/Effects/Scale
153
+ *
154
+ * Depends:
155
+ * jquery.effects.core.js
156
+ */
157
+ (function(c){c.effects.puff=function(b){return this.queue(function(){var a=c(this),e=c.effects.setMode(a,b.options.mode||"hide"),g=parseInt(b.options.percent,10)||150,h=g/100,i={height:a.height(),width:a.width()};c.extend(b.options,{fade:true,mode:e,percent:e=="hide"?g:100,from:e=="hide"?i:{height:i.height*h,width:i.width*h}});a.effect("scale",b.options,b.duration,b.callback);a.dequeue()})};c.effects.scale=function(b){return this.queue(function(){var a=c(this),e=c.extend(true,{},b.options),g=c.effects.setMode(a,
158
+ b.options.mode||"effect"),h=parseInt(b.options.percent,10)||(parseInt(b.options.percent,10)==0?0:g=="hide"?0:100),i=b.options.direction||"both",f=b.options.origin;if(g!="effect"){e.origin=f||["middle","center"];e.restore=true}f={height:a.height(),width:a.width()};a.from=b.options.from||(g=="show"?{height:0,width:0}:f);h={y:i!="horizontal"?h/100:1,x:i!="vertical"?h/100:1};a.to={height:f.height*h.y,width:f.width*h.x};if(b.options.fade){if(g=="show"){a.from.opacity=0;a.to.opacity=1}if(g=="hide"){a.from.opacity=
159
+ 1;a.to.opacity=0}}e.from=a.from;e.to=a.to;e.mode=g;a.effect("size",e,b.duration,b.callback);a.dequeue()})};c.effects.size=function(b){return this.queue(function(){var a=c(this),e=["position","top","left","width","height","overflow","opacity"],g=["position","top","left","overflow","opacity"],h=["width","height","overflow"],i=["fontSize"],f=["borderTopWidth","borderBottomWidth","paddingTop","paddingBottom"],k=["borderLeftWidth","borderRightWidth","paddingLeft","paddingRight"],p=c.effects.setMode(a,
160
+ b.options.mode||"effect"),n=b.options.restore||false,m=b.options.scale||"both",l=b.options.origin,j={height:a.height(),width:a.width()};a.from=b.options.from||j;a.to=b.options.to||j;if(l){l=c.effects.getBaseline(l,j);a.from.top=(j.height-a.from.height)*l.y;a.from.left=(j.width-a.from.width)*l.x;a.to.top=(j.height-a.to.height)*l.y;a.to.left=(j.width-a.to.width)*l.x}var d={from:{y:a.from.height/j.height,x:a.from.width/j.width},to:{y:a.to.height/j.height,x:a.to.width/j.width}};if(m=="box"||m=="both"){if(d.from.y!=
161
+ d.to.y){e=e.concat(f);a.from=c.effects.setTransition(a,f,d.from.y,a.from);a.to=c.effects.setTransition(a,f,d.to.y,a.to)}if(d.from.x!=d.to.x){e=e.concat(k);a.from=c.effects.setTransition(a,k,d.from.x,a.from);a.to=c.effects.setTransition(a,k,d.to.x,a.to)}}if(m=="content"||m=="both")if(d.from.y!=d.to.y){e=e.concat(i);a.from=c.effects.setTransition(a,i,d.from.y,a.from);a.to=c.effects.setTransition(a,i,d.to.y,a.to)}c.effects.save(a,n?e:g);a.show();c.effects.createWrapper(a);a.css("overflow","hidden").css(a.from);
162
+ if(m=="content"||m=="both"){f=f.concat(["marginTop","marginBottom"]).concat(i);k=k.concat(["marginLeft","marginRight"]);h=e.concat(f).concat(k);a.find("*[width]").each(function(){child=c(this);n&&c.effects.save(child,h);var o={height:child.height(),width:child.width()};child.from={height:o.height*d.from.y,width:o.width*d.from.x};child.to={height:o.height*d.to.y,width:o.width*d.to.x};if(d.from.y!=d.to.y){child.from=c.effects.setTransition(child,f,d.from.y,child.from);child.to=c.effects.setTransition(child,
163
+ f,d.to.y,child.to)}if(d.from.x!=d.to.x){child.from=c.effects.setTransition(child,k,d.from.x,child.from);child.to=c.effects.setTransition(child,k,d.to.x,child.to)}child.css(child.from);child.animate(child.to,b.duration,b.options.easing,function(){n&&c.effects.restore(child,h)})})}a.animate(a.to,{queue:false,duration:b.duration,easing:b.options.easing,complete:function(){a.to.opacity===0&&a.css("opacity",a.from.opacity);p=="hide"&&a.hide();c.effects.restore(a,n?e:g);c.effects.removeWrapper(a);b.callback&&
164
+ b.callback.apply(this,arguments);a.dequeue()}})})}})(jQuery);
165
+ ;/*
166
+ * jQuery UI Effects Shake 1.8.1
167
+ *
168
+ * Copyright (c) 2010 AUTHORS.txt (http://jqueryui.com/about)
169
+ * Dual licensed under the MIT (MIT-LICENSE.txt)
170
+ * and GPL (GPL-LICENSE.txt) licenses.
171
+ *
172
+ * http://docs.jquery.com/UI/Effects/Shake
173
+ *
174
+ * Depends:
175
+ * jquery.effects.core.js
176
+ */
177
+ (function(d){d.effects.shake=function(a){return this.queue(function(){var b=d(this),j=["position","top","left"];d.effects.setMode(b,a.options.mode||"effect");var c=a.options.direction||"left",e=a.options.distance||20,l=a.options.times||3,f=a.duration||a.options.duration||140;d.effects.save(b,j);b.show();d.effects.createWrapper(b);var g=c=="up"||c=="down"?"top":"left",h=c=="up"||c=="left"?"pos":"neg";c={};var i={},k={};c[g]=(h=="pos"?"-=":"+=")+e;i[g]=(h=="pos"?"+=":"-=")+e*2;k[g]=(h=="pos"?"-=":"+=")+
178
+ e*2;b.animate(c,f,a.options.easing);for(e=1;e<l;e++)b.animate(i,f,a.options.easing).animate(k,f,a.options.easing);b.animate(i,f,a.options.easing).animate(c,f/2,a.options.easing,function(){d.effects.restore(b,j);d.effects.removeWrapper(b);a.callback&&a.callback.apply(this,arguments)});b.queue("fx",function(){b.dequeue()});b.dequeue()})}})(jQuery);
179
+ ;/*
180
+ * jQuery UI Effects Slide 1.8.1
181
+ *
182
+ * Copyright (c) 2010 AUTHORS.txt (http://jqueryui.com/about)
183
+ * Dual licensed under the MIT (MIT-LICENSE.txt)
184
+ * and GPL (GPL-LICENSE.txt) licenses.
185
+ *
186
+ * http://docs.jquery.com/UI/Effects/Slide
187
+ *
188
+ * Depends:
189
+ * jquery.effects.core.js
190
+ */
191
+ (function(c){c.effects.slide=function(d){return this.queue(function(){var a=c(this),h=["position","top","left"],e=c.effects.setMode(a,d.options.mode||"show"),b=d.options.direction||"left";c.effects.save(a,h);a.show();c.effects.createWrapper(a).css({overflow:"hidden"});var f=b=="up"||b=="down"?"top":"left";b=b=="up"||b=="left"?"pos":"neg";var g=d.options.distance||(f=="top"?a.outerHeight({margin:true}):a.outerWidth({margin:true}));if(e=="show")a.css(f,b=="pos"?-g:g);var i={};i[f]=(e=="show"?b=="pos"?
192
+ "+=":"-=":b=="pos"?"-=":"+=")+g;a.animate(i,{queue:false,duration:d.duration,easing:d.options.easing,complete:function(){e=="hide"&&a.hide();c.effects.restore(a,h);c.effects.removeWrapper(a);d.callback&&d.callback.apply(this,arguments);a.dequeue()}})})}})(jQuery);
193
+ ;/*
194
+ * jQuery UI Effects Transfer 1.8.1
195
+ *
196
+ * Copyright (c) 2010 AUTHORS.txt (http://jqueryui.com/about)
197
+ * Dual licensed under the MIT (MIT-LICENSE.txt)
198
+ * and GPL (GPL-LICENSE.txt) licenses.
199
+ *
200
+ * http://docs.jquery.com/UI/Effects/Transfer
201
+ *
202
+ * Depends:
203
+ * jquery.effects.core.js
204
+ */
205
+ (function(e){e.effects.transfer=function(a){return this.queue(function(){var b=e(this),c=e(a.options.to),d=c.offset();c={top:d.top,left:d.left,height:c.innerHeight(),width:c.innerWidth()};d=b.offset();var f=e('<div class="ui-effects-transfer"></div>').appendTo(document.body).addClass(a.options.className).css({top:d.top,left:d.left,height:b.innerHeight(),width:b.innerWidth(),position:"absolute"}).animate(c,a.duration,a.options.easing,function(){f.remove();a.callback&&a.callback.apply(b[0],arguments);
206
+ b.dequeue()})})}})(jQuery);
207
+ ;
@@ -1,5 +1,7 @@
1
1
  require File.expand_path('../boot', __FILE__)
2
2
 
3
+ require "active_support/railtie"
4
+ require "active_model/railtie"
3
5
  require "action_dispatch/railtie"
4
6
  require "action_controller/railtie"
5
7
  require "action_view/railtie"
@@ -1,9 +1,6 @@
1
1
  require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
2
 
3
3
  require 'dummy_controller'
4
- require 'active_model'
5
- require 'active_model/naming'
6
- require 'active_model/conversion'
7
4
 
8
5
  class Ovechkin < Struct.new(:Ovechkin, :id)
9
6
  extend ActiveModel::Naming
@@ -12,23 +9,25 @@ class Ovechkin < Struct.new(:Ovechkin, :id)
12
9
  end
13
10
 
14
11
  describe JQueryOnRails::Helpers::JQueryHelper do
15
- before(:all) do
16
- ActiveSupport::JSON::Encoding.escape_html_entities_in_json = true
17
- end
18
12
  before(:each) do
19
13
  @t = DummyController.new.tap do |c|
20
14
  c.request = ActionDispatch::Request.new Rack::MockRequest.env_for('/dummy')
21
15
  end.view_context
22
16
  end
17
+
18
+ def create_generator
19
+ block = Proc.new{|*args| yield *args if block_given?}
20
+ @t.class::JavaScriptGenerator.new @t, &block
21
+ end
23
22
 
24
23
  it "is automatically mixed into the template class" do
25
24
  @t.class.included_modules.should be_include(JQueryOnRails::Helpers::JQueryHelper)
26
25
  end
27
- it "overrides all instance methods ActionView::Helpers::PrototypeHelper" do
26
+ it "overrides all instance methods from ActionView::Helpers::PrototypeHelper" do
28
27
  (ActionView::Helpers::PrototypeHelper.instance_methods -
29
28
  JQueryOnRails::Helpers::JQueryHelper.instance_methods).should == []
30
29
  end
31
- it "overrides all instance methods ActionView::Helpers::ScriptaculousHelper" do
30
+ it "overrides all instance methods from ActionView::Helpers::ScriptaculousHelper" do
32
31
  return pending("not yet implemented")
33
32
  (ActionView::Helpers::ScriptaculousHelper.instance_methods -
34
33
  JQueryOnRails::Helpers::JQueryHelper.instance_methods).should == []
@@ -94,184 +93,197 @@ describe JQueryOnRails::Helpers::JQueryHelper do
94
93
  end
95
94
  end
96
95
 
97
- describe "javascript generation" do
96
+ describe '#visual_effect' do
97
+ it "renames effects" do
98
+ @t.visual_effect(:fade,'blah').should == %(jQuery("#blah").fadeOut();)
99
+ @t.visual_effect(:appear,'blah').should == %(jQuery("#blah").fadeIn();)
100
+ end
101
+ it "renames toggle effects" do
102
+ @t.visual_effect(:toggle_slide,'blah').should == %(jQuery("#blah").slideToggle();)
103
+ end
104
+ it "rewrites :toggle_appear" do
105
+ @t.visual_effect(:toggle_appear,'blah').should ==
106
+ "(function(state){ return (function() { state=!state; return jQuery(\"#blah\")['fade'+(state?'In':'Out')](); })(); })(jQuery(\"#blah\").css('visiblity')!='hidden');"
107
+ end
108
+ end
109
+
110
+ describe '#update_page' do
111
+ it 'matches output from #create_generator' do
112
+ @block = proc{|page| page.replace_html 'foo', 'bar'}
113
+ @t.update_page(&@block).should == create_generator(&@block).to_s
114
+ end
115
+ end
116
+
117
+ describe '#update_page_tag' do
98
118
  before(:each) do
99
119
  @block = proc{|page| page.replace_html 'foo', 'bar'}
100
120
  end
101
-
102
- def create_generator
103
- block = Proc.new{|*args| yield *args if block_given?}
104
- @t.class::JavaScriptGenerator.new @t, &block
121
+ it 'matches output from #create_generator wrapped in a script tag' do
122
+ @t.update_page_tag(&@block).should == @t.javascript_tag(create_generator(&@block).to_s)
105
123
  end
106
-
107
- describe 'JavaScriptGenerator' do
108
- before(:each) do
109
- @g = create_generator
110
- end
111
- it "replaces the PrototypeHelper's generator" do
124
+ it 'outputs html attributes' do
125
+ @t.update_page_tag(:defer=>true, &@block).should == @t.javascript_tag(create_generator(&@block).to_s, :defer=>true)
126
+ end
127
+ end
128
+
129
+ describe 'JavaScriptGenerator' do
130
+ before(:each) do
131
+ @g = create_generator
132
+ end
133
+ it "replaces the PrototypeHelper's generator" do
112
134
  @t.class::JavaScriptGenerator.should == JQueryOnRails::Helpers::JQueryHelper::JavaScriptGenerator
113
135
  JQueryOnRails::Helpers::JQueryHelper::JavaScriptGenerator.should === @g
114
- end
115
- it "#insert_html" do
116
- @g.insert_html(:top, 'element', '<p>This is a test</p>').should ==
117
- 'jQuery("#element").prepend("\\u003Cp\\u003EThis is a test\\u003C/p\\u003E");'
118
- @g.insert_html(:bottom, 'element', '<p>This is a test</p>').should ==
119
- 'jQuery("#element").append("\\u003Cp\\u003EThis is a test\\u003C/p\\u003E");'
120
- @g.insert_html(:before, 'element', '<p>This is a test</p>').should ==
121
- 'jQuery("#element").before("\\u003Cp\\u003EThis is a test\\u003C/p\\u003E");'
122
- @g.insert_html(:after, 'element', '<p>This is a test</p>').should ==
123
- 'jQuery("#element").after("\\u003Cp\\u003EThis is a test\\u003C/p\\u003E");'
124
- end
125
- it "#replace_html" do
126
- @g.replace_html('element', '<p>This is a test</p>').should ==
127
- 'jQuery("#element").html("\\u003Cp\\u003EThis is a test\\u003C/p\\u003E");'
128
- end
129
- it "#replace" do
130
- @g.replace('element', '<div id="element"><p>This is a test</p></div>').should ==
131
- 'jQuery("#element").replaceWith("\\u003Cdiv id=\"element\"\\u003E\\u003Cp\\u003EThis is a test\\u003C/p\\u003E\\u003C/div\\u003E");'
132
- end
133
- it "#remove" do
134
- @g.remove('foo').should == 'jQuery("#foo").remove();'
135
- @g.remove('foo', 'bar', 'baz').should == 'jQuery("#foo, #bar, #baz").remove();'
136
- end
137
- it "#show" do
138
- @g.show('foo').should == 'jQuery("#foo").show();'
139
- @g.show('foo', 'bar', 'baz').should == 'jQuery("#foo, #bar, #baz").show();'
140
- end
141
- it "#hide" do
142
- @g.hide('foo').should == 'jQuery("#foo").hide();'
143
- @g.hide('foo', 'bar', 'baz').should == 'jQuery("#foo, #bar, #baz").hide();'
144
- end
145
- it "#toggle" do
146
- @g.toggle('foo').should == 'jQuery("#foo").toggle();'
147
- @g.toggle('foo', 'bar', 'baz').should == 'jQuery("#foo, #bar, #baz").toggle();'
148
- end
149
- it "#alert" do
150
- @g.alert('hello').should == 'alert("hello");'
151
- end
152
- it "#redirect_to" do
153
- @g.redirect_to(:controller=>'dummy', :action=>'index').should ==
154
- 'window.location.href = "/dummy";'
155
- @g.redirect_to("http://www.example.com/welcome?a=b&c=d").should ==
156
- 'window.location.href = "http://www.example.com/welcome?a=b&c=d";'
157
- end
158
- it "#reload" do
159
- @g.reload.should == 'window.location.reload();'
160
- end
161
- it "#delay" do
162
- @g.delay(20){@g.hide('foo')}
163
- @g.to_s.should == "setTimeout(function(){\n;\njQuery(\"#foo\").hide();\n}, 20000);"
164
- end
165
- it "#to_s" do
166
- @g.insert_html(:top, 'element', '<p>This is a test</p>')
167
- @g.insert_html(:bottom, 'element', '<p>This is a test</p>')
168
- @g.remove('foo', 'bar')
169
- @g.replace_html('baz', '<p>This is a test</p>')
170
-
171
- @g.to_s.should == <<-EOS.chomp
136
+ end
137
+ it "#insert_html" do
138
+ @g.insert_html(:top, 'element', '<p>This is a test</p>').should ==
139
+ 'jQuery("#element").prepend("\\u003Cp\\u003EThis is a test\\u003C/p\\u003E");'
140
+ @g.insert_html(:bottom, 'element', '<p>This is a test</p>').should ==
141
+ 'jQuery("#element").append("\\u003Cp\\u003EThis is a test\\u003C/p\\u003E");'
142
+ @g.insert_html(:before, 'element', '<p>This is a test</p>').should ==
143
+ 'jQuery("#element").before("\\u003Cp\\u003EThis is a test\\u003C/p\\u003E");'
144
+ @g.insert_html(:after, 'element', '<p>This is a test</p>').should ==
145
+ 'jQuery("#element").after("\\u003Cp\\u003EThis is a test\\u003C/p\\u003E");'
146
+ end
147
+ it "#replace_html" do
148
+ @g.replace_html('element', '<p>This is a test</p>').should ==
149
+ 'jQuery("#element").html("\\u003Cp\\u003EThis is a test\\u003C/p\\u003E");'
150
+ end
151
+ it "#replace" do
152
+ @g.replace('element', '<div id="element"><p>This is a test</p></div>').should ==
153
+ 'jQuery("#element").replaceWith("\\u003Cdiv id=\"element\"\\u003E\\u003Cp\\u003EThis is a test\\u003C/p\\u003E\\u003C/div\\u003E");'
154
+ end
155
+ it "#remove" do
156
+ @g.remove('foo').should == 'jQuery("#foo").remove();'
157
+ @g.remove('foo', 'bar', 'baz').should == 'jQuery("#foo, #bar, #baz").remove();'
158
+ end
159
+ it "#show" do
160
+ @g.show('foo').should == 'jQuery("#foo").show();'
161
+ @g.show('foo', 'bar', 'baz').should == 'jQuery("#foo, #bar, #baz").show();'
162
+ end
163
+ it "#hide" do
164
+ @g.hide('foo').should == 'jQuery("#foo").hide();'
165
+ @g.hide('foo', 'bar', 'baz').should == 'jQuery("#foo, #bar, #baz").hide();'
166
+ end
167
+ it "#toggle" do
168
+ @g.toggle('foo').should == 'jQuery("#foo").toggle();'
169
+ @g.toggle('foo', 'bar', 'baz').should == 'jQuery("#foo, #bar, #baz").toggle();'
170
+ end
171
+ it "#alert" do
172
+ @g.alert('hello').should == 'alert("hello");'
173
+ end
174
+ it "#redirect_to" do
175
+ @g.redirect_to(:controller=>'dummy', :action=>'index').should ==
176
+ 'window.location.href = "/dummy";'
177
+ @g.redirect_to("http://www.example.com/welcome?a=b&c=d").should ==
178
+ 'window.location.href = "http://www.example.com/welcome?a=b&c=d";'
179
+ end
180
+ it "#reload" do
181
+ @g.reload.should == 'window.location.reload();'
182
+ end
183
+ it "#delay" do
184
+ @g.delay(20){@g.hide('foo')}
185
+ @g.to_s.should == "setTimeout(function(){\n;\njQuery(\"#foo\").hide();\n}, 20000);"
186
+ end
187
+ it "#to_s" do
188
+ @g.insert_html(:top, 'element', '<p>This is a test</p>')
189
+ @g.insert_html(:bottom, 'element', '<p>This is a test</p>')
190
+ @g.remove('foo', 'bar')
191
+ @g.replace_html('baz', '<p>This is a test</p>')
192
+
193
+ @g.to_s.should == <<-EOS.chomp
172
194
  jQuery("#element").prepend("\\u003Cp\\u003EThis is a test\\u003C/p\\u003E");
173
195
  jQuery("#element").append("\\u003Cp\\u003EThis is a test\\u003C/p\\u003E");
174
196
  jQuery("#foo, #bar").remove();
175
197
  jQuery("#baz").html("\\u003Cp\\u003EThis is a test\\u003C/p\\u003E");
176
198
  EOS
177
- end
178
- it "#literal" do
179
- ActiveSupport::JSON.encode(@g.literal("function() {}")).should == "function() {}"
180
- @g.to_s.should == ""
181
- end
182
- it "proxies to class methods" do
183
- @g.form.focus('my_field')
184
- @g.to_s.should == "Form.focus(\"my_field\");"
185
- end
186
- it "proxies to class methods with blocks" do
187
- @g.my_object.my_method do |p|
188
- p[:one].show
189
- p[:two].hide
190
- end
191
- @g.to_s.should == "MyObject.myMethod(function() { jQuery(\"#one\").show();\njQuery(\"#two\").hide(); });"
192
- end
193
- it "calls with or without blocks" do
194
- @g.call(:before)
195
- @g.call(:my_method) do |p|
196
- p[:one].show
197
- p[:two].hide
198
- end
199
- @g.call(:in_between)
200
- @g.call(:my_method_with_arguments, true, "hello") do |p|
201
- p[:three].toggle
202
- end
203
- @g.to_s.should == "before();\nmy_method(function() { jQuery(\"#one\").show();\njQuery(\"#two\").hide(); });\nin_between();\nmy_method_with_arguments(true, \"hello\", function() { jQuery(\"#three\").toggle(); });"
204
- end
205
-
206
- describe "element proxy compatibility" do
207
- before(:each) do
208
- @g.extend @g.class::CompatibilityMethods
209
- end
210
- it "gets properties" do
211
- @g['hello']['style']
212
- @g.to_s.should == 'jQuery("#hello")[0].style;'
213
- end
214
- it "gets nested properties" do
215
- @g['hello']['style']['color']
216
- @g.to_s.should == 'jQuery("#hello")[0].style.color;'
217
- end
218
- it "sets properties" do
219
- @g['hello'].width = 400;
220
- @g.to_s.should == 'jQuery("#hello")[0].width = 400;'
221
- end
222
- it "sets nested properties" do
223
- @g['hello']['style']['color'] = 'red';
224
- @g.to_s.should == 'jQuery("#hello")[0].style.color = "red";'
225
- end
226
- end
227
- describe "element proxy" do
228
- it "refers by element ID" do
229
- @g['hello'].should == 'jQuery("#hello");'
230
- end
231
- it "refers via ActiveModel::Naming" do
232
- @g[Ovechkin.new(:id=>5)].should == 'jQuery("#bunny_5");'
233
- @g[Ovechkin.new].should == 'jQuery("#new_bunny");'
234
- end
235
- it "refers indirectly" do
236
- @g['hello'].hide('first').show
237
- @g.to_s.should == 'jQuery("#hello").hide("first").show();'
238
- end
239
- it "calls methods" do
240
- @g['hello'].hide
241
- @g.to_s.should == 'jQuery("#hello").hide();'
242
- end
243
- it "gets properties" do
244
- @g['hello'][0]['style']
245
- @g.to_s.should == 'jQuery("#hello")[0].style;'
246
- end
247
- it "gets nested properties" do
248
- @g['hello'][0]['style']['color']
249
- @g.to_s.should == 'jQuery("#hello")[0].style.color;'
250
- end
251
- it "sets properties" do
252
- @g['hello'][0].width = 400;
253
- @g.to_s.should == 'jQuery("#hello")[0].width = 400;'
254
- end
255
- it "sets nested properties" do
256
- @g['hello'][0]['style']['color'] = 'red';
257
- @g.to_s.should == 'jQuery("#hello")[0].style.color = "red";'
258
- end
259
- end
260
- end
261
-
262
- describe '#update_page' do
263
- it 'matches output from #create_generator' do
264
- @t.update_page(&@block).should == create_generator(&@block).to_s
199
+ end
200
+ it "#literal" do
201
+ ActiveSupport::JSON.encode(@g.literal("function() {}")).should == "function() {}"
202
+ @g.to_s.should == ""
203
+ end
204
+ it "proxies to class methods" do
205
+ @g.form.focus('my_field')
206
+ @g.to_s.should == "Form.focus(\"my_field\");"
207
+ end
208
+ it "proxies to class methods with blocks" do
209
+ @g.my_object.my_method do |p|
210
+ p[:one].show
211
+ p[:two].hide
265
212
  end
213
+ @g.to_s.should == "MyObject.myMethod(function() { jQuery(\"#one\").show();\njQuery(\"#two\").hide(); });"
266
214
  end
267
-
268
- describe '#update_page_tag' do
269
- it 'matches output from #create_generator wrapped in a script tag' do
270
- @t.update_page_tag(&@block).should == @t.javascript_tag(create_generator(&@block).to_s)
215
+ it "calls with or without blocks" do
216
+ @g.call(:before)
217
+ @g.call(:my_method) do |p|
218
+ p[:one].show
219
+ p[:two].hide
271
220
  end
272
- it 'outputs html attributes' do
273
- @t.update_page_tag(:defer=>true, &@block).should == @t.javascript_tag(create_generator(&@block).to_s, :defer=>true)
221
+ @g.call(:in_between)
222
+ @g.call(:my_method_with_arguments, true, "hello") do |p|
223
+ p[:three].toggle
274
224
  end
225
+ @g.to_s.should == "before();\nmy_method(function() { jQuery(\"#one\").show();\njQuery(\"#two\").hide(); });\nin_between();\nmy_method_with_arguments(true, \"hello\", function() { jQuery(\"#three\").toggle(); });"
275
226
  end
227
+ it '#visual_effect matches helper method output' do
228
+ @g.visual_effect(:toggle_slide,'blah')
229
+ @g.to_s.should == @t.visual_effect(:toggle_slide,'blah')
230
+ end
231
+
232
+ describe "element proxy compatibility" do
233
+ before(:each) do
234
+ @g.extend @g.class::CompatibilityMethods
235
+ end
236
+ it "gets properties" do
237
+ @g['hello']['style']
238
+ @g.to_s.should == 'jQuery("#hello")[0].style;'
239
+ end
240
+ it "gets nested properties" do
241
+ @g['hello']['style']['color']
242
+ @g.to_s.should == 'jQuery("#hello")[0].style.color;'
243
+ end
244
+ it "sets properties" do
245
+ @g['hello'].width = 400;
246
+ @g.to_s.should == 'jQuery("#hello")[0].width = 400;'
247
+ end
248
+ it "sets nested properties" do
249
+ @g['hello']['style']['color'] = 'red';
250
+ @g.to_s.should == 'jQuery("#hello")[0].style.color = "red";'
251
+ end
252
+ end
253
+ describe "element proxy" do
254
+ it "refers by element ID" do
255
+ @g['hello']
256
+ @g.to_s.should == 'jQuery("#hello")'
257
+ end
258
+ it "refers by element ID, using ActiveModel::Naming" do
259
+ @g[Ovechkin.new]
260
+ @g.to_s.should == 'jQuery("#new_ovechkin")'
261
+ end
262
+ it "refers indirectly" do
263
+ @g['hello'].hide('first').show
264
+ @g.to_s.should == 'jQuery("#hello").hide("first").show();'
265
+ end
266
+ it "calls methods" do
267
+ @g['hello'].hide
268
+ @g.to_s.should == 'jQuery("#hello").hide();'
269
+ end
270
+ it "gets properties" do
271
+ @g['hello'][0]['style']
272
+ @g.to_s.should == 'jQuery("#hello")[0].style;'
273
+ end
274
+ it "gets nested properties" do
275
+ @g['hello'][0]['style']['color']
276
+ @g.to_s.should == 'jQuery("#hello")[0].style.color;'
277
+ end
278
+ it "sets properties" do
279
+ @g['hello'][0].width = 400;
280
+ @g.to_s.should == 'jQuery("#hello")[0].width = 400;'
281
+ end
282
+ it "sets nested properties" do
283
+ @g['hello'][0]['style']['color'] = 'red';
284
+ @g.to_s.should == 'jQuery("#hello")[0].style.color = "red";'
285
+ end
286
+ end
287
+
276
288
  end
277
289
  end
@@ -0,0 +1,55 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+
3
+ require 'dummy_controller'
4
+
5
+ describe JQueryOnRails::Helpers::JQueryUiHelper do
6
+ before(:each) do
7
+ @t = DummyController.new.tap do |c|
8
+ c.request = ActionDispatch::Request.new Rack::MockRequest.env_for('/dummy')
9
+ end.view_context
10
+ @t.extend JQueryOnRails::Helpers::JQueryUiHelper
11
+ end
12
+ describe '#visual_effect' do
13
+ it "calls core jQuery effects primitives" do
14
+ @t.visual_effect(:fade,'blah').should == %(jQuery("#blah").fadeOut();)
15
+ @t.visual_effect(:appear,'blah').should == %(jQuery("#blah").fadeIn();)
16
+ end
17
+ it "calls hide() or show() based on the effect name" do
18
+ @t.visual_effect(:shrink,'blah').should == %(jQuery("#blah").hide('size');)
19
+ @t.visual_effect(:grow,'blah').should == %(jQuery("#blah").show('size');)
20
+ @t.visual_effect(:puff_in,'blah').should == %(jQuery("#blah").show('puff');)
21
+ @t.visual_effect(:puff_out,'blah').should == %(jQuery("#blah").hide('puff');)
22
+ end
23
+ it "calls effect() by default" do
24
+ @t.visual_effect(:puff,'blah').should == %(jQuery("#blah").effect('puff');)
25
+ end
26
+ it "uses default options for :direction" do
27
+ @t.visual_effect(:blind_down,'blah').should ==
28
+ %(jQuery("#blah").show('blind',{direction:'vertical'});)
29
+ @t.visual_effect(:blind_up,'blah').should ==
30
+ %(jQuery("#blah").hide('blind',{direction:'vertical'});)
31
+ @t.visual_effect(:blind_right,'blah').should ==
32
+ %(jQuery("#blah").show('blind',{direction:'horizontal'});)
33
+ @t.visual_effect(:blind_left,'blah').should ==
34
+ %(jQuery("#blah").hide('blind',{direction:'horizontal'});)
35
+ @t.visual_effect(:blind_up,'blah',:direction=>:horizontal).should ==
36
+ %(jQuery("#blah").hide('blind',{direction:'horizontal'});)
37
+ @t.visual_effect(:blind_right,'blah',:direction=>:vertical).should ==
38
+ %(jQuery("#blah").show('blind',{direction:'vertical'});)
39
+ end
40
+ it "uses jQuery UI toggle effects" do
41
+ @t.visual_effect(:toggle_slide,'blah').should == %(jQuery("#blah").toggle('slide',{direction:'vertical'});)
42
+ @t.visual_effect(:toggle_blind,'blah').should == %(jQuery("#blah").toggle('blind',{direction:'vertical'});)
43
+ @t.visual_effect(:toggle_blind,'blah',:direction=>:horizontal).should ==
44
+ %(jQuery("#blah").toggle('blind',{direction:'horizontal'});)
45
+ @t.visual_effect(:toggle_shrink,'blah').should == %(jQuery("#blah").toggle('size');)
46
+ @t.visual_effect(:toggle_grow,'blah').should == %(jQuery("#blah").toggle('size');)
47
+ @t.visual_effect(:toggle_puff,'blah').should == %(jQuery("#blah").toggle('puff');)
48
+ end
49
+ it "implements :toggle_appear with inline JavaScript" do
50
+ body = JQueryOnRails::Helpers::JQueryUiHelper::FX_OPTIONS[:toggleAppear][:mode]
51
+ @t.visual_effect(:toggle_appear,'blah').should ==
52
+ "(function(element,name,options){ #{body} })(jQuery(\"#blah\"),'fade');"
53
+ end
54
+ end
55
+ end
data/spec/spec_helper.rb CHANGED
@@ -12,6 +12,7 @@ require "rspec"
12
12
  #require "rspec/rails"
13
13
 
14
14
  Rails.backtrace_cleaner.remove_silencers!
15
+ ActiveSupport::JSON::Encoding.escape_html_entities_in_json = true
15
16
 
16
17
  Rspec.configure do |config|
17
18
  require 'rspec/expectations'
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 2
8
- - 0
9
- version: 0.2.0
8
+ - 1
9
+ version: 0.2.1
10
10
  platform: ruby
11
11
  authors:
12
12
  - Joe Khoobyar
@@ -65,7 +65,9 @@ files:
65
65
  - jquery_on_rails.gemspec
66
66
  - lib/jquery_on_rails.rb
67
67
  - lib/jquery_on_rails/helpers/jquery_helper.rb
68
+ - lib/jquery_on_rails/helpers/jquery_ui_helper.rb
68
69
  - lib/jquery_on_rails/railtie.rb
70
+ - public/javascripts/jquery-ui-effects.js
69
71
  - public/javascripts/jquery.js
70
72
  - public/javascripts/rails.js
71
73
  - spec/dummy/app/controllers/dummy_controller.rb
@@ -78,6 +80,7 @@ files:
78
80
  - spec/dummy/log/test.log
79
81
  - spec/jquery_helper_spec.rb
80
82
  - spec/jquery_on_rails_spec.rb
83
+ - spec/jquery_ui_helper_spec.rb
81
84
  - spec/spec_helper.rb
82
85
  has_rdoc: true
83
86
  homepage: http://github.com/joekhoobyar/jquery_on_rails
@@ -119,4 +122,5 @@ test_files:
119
122
  - spec/dummy/config/routes.rb
120
123
  - spec/jquery_helper_spec.rb
121
124
  - spec/jquery_on_rails_spec.rb
125
+ - spec/jquery_ui_helper_spec.rb
122
126
  - spec/spec_helper.rb