right-rails 0.6.0 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +8 -0
- data/README.rdoc +71 -0
- data/Rakefile +144 -14
- data/generators/right_rails/right_rails_generator.rb +18 -21
- data/init.rb +11 -32
- data/lib/generators/right_rails/right_rails_generator.rb +27 -0
- data/lib/generators/right_rails/templates/iframed.html.erb +10 -0
- data/lib/right-rails.rb +1 -1
- data/lib/right_rails/config.rb +278 -0
- data/lib/right_rails/controller_extensions.rb +10 -5
- data/lib/right_rails/helpers/basic.rb +10 -66
- data/lib/right_rails/helpers/forms.rb +141 -139
- data/lib/right_rails/helpers/misc.rb +45 -67
- data/lib/right_rails/helpers/rails.rb +40 -105
- data/lib/right_rails/helpers.rb +364 -1
- data/lib/right_rails/java_script_generator.rb +34 -24
- data/lib/right_rails.rb +6 -1
- data/{images → public/images}/colorpicker.png +0 -0
- data/{images → public/images}/resizable.png +0 -0
- data/public/javascripts/right/autocompleter-src.js +612 -0
- data/public/javascripts/right/autocompleter.js +18 -0
- data/public/javascripts/right/calendar-src.js +1448 -0
- data/public/javascripts/right/calendar.js +36 -0
- data/public/javascripts/right/colorpicker-src.js +967 -0
- data/public/javascripts/right/colorpicker.js +26 -0
- data/{javascripts/right-dnd-src.js → public/javascripts/right/dnd-src.js} +86 -52
- data/public/javascripts/right/dnd.js +20 -0
- data/{javascripts/right-effects-src.js → public/javascripts/right/effects-src.js} +90 -45
- data/public/javascripts/right/effects.js +17 -0
- data/{javascripts/right-ui-i18n-de.js → public/javascripts/right/i18n/de.js} +7 -7
- data/{javascripts/right-ui-i18n-en-us.js → public/javascripts/right/i18n/en-us.js} +1 -1
- data/{javascripts/right-ui-i18n-es.js → public/javascripts/right/i18n/es.js} +7 -7
- data/{javascripts/right-ui-i18n-fr.js → public/javascripts/right/i18n/fr.js} +7 -7
- data/{javascripts/right-ui-i18n-hu.js → public/javascripts/right/i18n/hu.js} +7 -7
- data/{javascripts/right-ui-i18n-jp.js → public/javascripts/right/i18n/jp.js} +7 -7
- data/{javascripts/right-ui-i18n-nl.js → public/javascripts/right/i18n/nl.js} +7 -7
- data/{javascripts/right-ui-i18n-pt-br.js → public/javascripts/right/i18n/pt-br.js} +7 -7
- data/{javascripts/right-ui-i18n-ru.js → public/javascripts/right/i18n/ru.js} +7 -7
- data/{javascripts/right-ui-i18n-ua.js → public/javascripts/right/i18n/ua.js} +17 -12
- data/public/javascripts/right/in-edit-src.js +352 -0
- data/public/javascripts/right/in-edit.js +13 -0
- data/public/javascripts/right/json-src.js +160 -0
- data/public/javascripts/right/json.js +10 -0
- data/public/javascripts/right/lightbox-src.js +881 -0
- data/public/javascripts/right/lightbox.js +24 -0
- data/{javascripts/right-rails-src.js → public/javascripts/right/rails-src.js} +195 -171
- data/public/javascripts/right/rails.js +14 -0
- data/public/javascripts/right/rater-src.js +366 -0
- data/public/javascripts/right/rater.js +13 -0
- data/public/javascripts/right/resizable-src.js +420 -0
- data/public/javascripts/right/resizable.js +15 -0
- data/public/javascripts/right/selectable-src.js +687 -0
- data/public/javascripts/right/selectable.js +22 -0
- data/public/javascripts/right/slider-src.js +377 -0
- data/public/javascripts/right/slider.js +14 -0
- data/public/javascripts/right/sortable-src.js +392 -0
- data/public/javascripts/right/sortable.js +16 -0
- data/public/javascripts/right/tabs-src.js +1123 -0
- data/public/javascripts/right/tabs.js +29 -0
- data/public/javascripts/right/tooltip-src.js +307 -0
- data/public/javascripts/right/tooltip.js +12 -0
- data/public/javascripts/right/uploader-src.js +283 -0
- data/public/javascripts/right/uploader.js +13 -0
- data/{javascripts → public/javascripts}/right-olds-src.js +134 -186
- data/public/javascripts/right-olds.js +18 -0
- data/public/javascripts/right-safe-src.js +161 -0
- data/public/javascripts/right-safe.js +8 -0
- data/{javascripts → public/javascripts}/right-src.js +2558 -1750
- data/public/javascripts/right.js +92 -0
- data/spec/lib/right_rails/config_spec.rb +133 -0
- data/spec/lib/right_rails/controller_extensions_spec.rb +1 -1
- data/spec/lib/right_rails/helpers/basic_spec.rb +77 -66
- data/spec/lib/right_rails/helpers/forms_spec.rb +231 -33
- data/spec/lib/right_rails/helpers/misc_spec.rb +94 -26
- data/spec/lib/right_rails/helpers/rails_spec.rb +42 -7
- data/spec/lib/right_rails/helpers_spec.rb +125 -0
- data/spec/lib/right_rails/java_script_generator_spec.rb +30 -0
- data/spec/rcov.opts +3 -0
- data/spec/spec_helper.rb +12 -7
- metadata +70 -61
- data/README.textile +0 -69
- data/javascripts/right-autocompleter-src.js +0 -318
- data/javascripts/right-autocompleter.js +0 -9
- data/javascripts/right-behavior-src.js +0 -261
- data/javascripts/right-behavior.js +0 -8
- data/javascripts/right-calendar-src.js +0 -946
- data/javascripts/right-calendar.js +0 -9
- data/javascripts/right-colorpicker-src.js +0 -635
- data/javascripts/right-colorpicker.js +0 -9
- data/javascripts/right-dnd.js +0 -9
- data/javascripts/right-effects.js +0 -6
- data/javascripts/right-events-src.js +0 -321
- data/javascripts/right-events.js +0 -6
- data/javascripts/right-in-edit-src.js +0 -194
- data/javascripts/right-in-edit.js +0 -6
- data/javascripts/right-json-src.js +0 -141
- data/javascripts/right-json.js +0 -6
- data/javascripts/right-lightbox-src.js +0 -651
- data/javascripts/right-lightbox.js +0 -9
- data/javascripts/right-olds.js +0 -9
- data/javascripts/right-rails.js +0 -9
- data/javascripts/right-rater-src.js +0 -253
- data/javascripts/right-rater.js +0 -9
- data/javascripts/right-resizable-src.js +0 -336
- data/javascripts/right-resizable.js +0 -9
- data/javascripts/right-selectable-src.js +0 -565
- data/javascripts/right-selectable.js +0 -7
- data/javascripts/right-slider-src.js +0 -288
- data/javascripts/right-slider.js +0 -7
- data/javascripts/right-sortable-src.js +0 -225
- data/javascripts/right-sortable.js +0 -9
- data/javascripts/right-tabs-src.js +0 -937
- data/javascripts/right-tabs.js +0 -6
- data/javascripts/right-tooltips-src.js +0 -195
- data/javascripts/right-tooltips.js +0 -9
- data/javascripts/right-uploader-src.js +0 -167
- data/javascripts/right-uploader.js +0 -9
- data/javascripts/right.js +0 -7
@@ -0,0 +1,24 @@
|
|
1
|
+
/**
|
2
|
+
* Lightbox feature for RightJS
|
3
|
+
* http://rightjs.org/ui/lightbox
|
4
|
+
*
|
5
|
+
* Copyright (C) 2009-2010 Nikolay Nemshilov
|
6
|
+
*/
|
7
|
+
var Lightbox=RightJS.Lightbox=function(p,d){var q=d.$,r=d.$$,u=d.$w,h=d.$E,v=d.$ext,w=d.Xhr,x=d.Class,y=d.Object,s=d.Wrapper,j=d.Element,i=d.Browser;i.IE6=i.OLD&&navigator.userAgent.indexOf("MSIE 6")>0;var z=new d.Wrapper(d.Element,{initialize:function(a){this.$super("div",{"class":"rui-spinner"});this.dots=[];for(var b=0;b<(a||4);b++)this.dots.push(new d.Element("div"));this.dots[0].addClass("glowing");this.insert(this.dots);d(this.shift).bind(this).periodical(300)},shift:function(){if(this.visible()){var a=
|
8
|
+
this.dots.pop();this.dots.unshift(a);this.insert(a,"top")}}}),f=new (function(a,b){if(!b){b=a;a="DIV"}var c=new d.Wrapper(d.Element.Wrappers[a]||d.Element,{initialize:function(e,g){this.key=e;var k=[{"class":"rui-"+e}];this instanceof d.Input||this instanceof d.Form||k.unshift(a);this.$super.apply(this,k);if(d.isString(g))g=d.$(g);if(g instanceof d.Element){this._=g._;if("$listeners"in g)g.$listeners=g.$listeners;g={}}this.setOptions(g,this);return this},setOptions:function(e,g){g=g||this;d.Options.setOptions.call(this,
|
9
|
+
d.Object.merge(e,eval("("+(g.get("data-"+this.key)||"{}")+")")));return this}});c=new d.Wrapper(c,b);d.Observer.createShortcuts(c.prototype,c.EVENTS||[]);return c})({extend:{version:"2.0.0",EVENTS:u("show hide load"),Options:{fxName:"fade",fxDuration:100,group:null,hideOnEsc:true,hideOnOutClick:true,showCloseButton:true,cssRule:"a[data-lightbox]",mediaWidth:425,mediaHeight:350},i18n:{Close:"Close",Prev:"Previous Image",Next:"Next Image"},Images:/\.(jpg|jpeg|gif|png|bmp)/,Medias:[[/(http:\/\/.*?youtube\.[a-z]+)\/watch\?v=([^&]+)/,
|
10
|
+
"$1/v/$2","swf"],[/(http:\/\/video.google.com)\/videoplay\?docid=([^&]+)/,"$1/googleplayer.swf?docId=$2","swf"],[/(http:\/\/vimeo\.[a-z]+)\/([0-9]+).*?/,"$1/moogaloop.swf?clip_id=$2","swf"]]},initialize:function(a,b){this.$super("lightbox",{}).setOptions(a,b).insert([this.locker=new A(this.options),this.dialog=new B(this.options)]).on({close:this._close,next:this._next,prev:this._prev})},setOptions:function(a,b){this.$super(a,b);if(b){var c=b.get("rel");if(c&&(c=c.match(/lightbox\[(.+?)\]/)))this.options.group=
|
11
|
+
c[1]}return this},setTitle:function(a){this.dialog.setTitle(a);return this},show:function(a){return this._showAnd(function(){this.dialog.show(a,!a)})},hide:function(){f.current=null;return this.$super(this.options.fxName,{duration:this.options.fxDuration/3,onFinish:d(function(){this.fire("hide");this.remove()}).bind(this)})},load:function(a,b){return this._showAnd(function(){this.dialog.load(a,b)})},resize:function(a){this.dialog.resize(a);return this},_close:function(a){a.stop();this.hide()},_prev:function(a){a.stop();
|
12
|
+
l.prev()},_next:function(a){a.stop();l.next()},_showAnd:function(a){if(f.current!==this){f.current=this;r("div.rui-lightbox").each("remove");this.insertTo(p.body);this.dialog.show("",true);if(i.OLD){this.reposition();j.prototype.show.call(this);a.call(this)}else{this.setStyle("display:none");j.prototype.show.call(this,this.options.fxName,{duration:this.options.fxDuration/2,onFinish:d(function(){a.call(this);this.fire("show")}).bind(this)})}}else a.call(this);return this},reposition:function(){if(i.IE6){var a=
|
13
|
+
q(window);this.setStyle({top:a.scrolls().y+"px",width:a.size().x+"px",height:a.size().y+"px",position:"absolute"})}}});f.extend({hide:function(){f.current&&f.current.hide()},show:function(){return this.inst("show",arguments)},load:function(){return this.inst("load",arguments)},inst:function(a,b){var c=new f;return c[a].apply(c,b)}});var A=new s(j,{initialize:function(a){this.$super("div",{"class":"rui-lightbox-locker"});a.hideOnOutClick&&this.onClick("fire","close")}}),B=new s(j,{initialize:function(a){var b=
|
14
|
+
f.i18n;this.options=a;this.$super("div",{"class":"rui-lightbox-dialog"});this.insert([this.title=h("div",{"class":"rui-lightbox-title"}),h("div",{"class":"rui-lightbox-body"}).insert(h("div",{"class":"rui-lightbox-body-inner"}).insert([this.locker=h("div",{"class":"rui-lightbox-body-locker"}).insert(new z(4)),this.scroller=h("div",{"class":"rui-lightbox-scroller"}).insert(this.content=h("div",{"class":"rui-lightbox-content"}))])),h("div",{"class":"rui-lightbox-navigation"}).insert([this.closeButton=
|
15
|
+
h("div",{"class":"close",html:"×",title:b.Close}).onClick("fire","close"),this.prevLink=h("div",{"class":"prev",html:"←",title:b.Prev}).onClick("fire","prev"),this.nextLink=h("div",{"class":"next",html:"→",title:b.Next}).onClick("fire","next")])]);this.prevLink.hide();this.nextLink.hide();a.showCloseButton||this.closeButton.hide()},setTitle:function(a){this.title.update(a||"")},resize:function(a,b){var c=this.parent().size(),e=this.scroller.size(),g=(c.y-this.size().y)/2,k=this.size().x-
|
16
|
+
e.x;if(a){a=this.scroller.setStyle(a).size();this.scroller.setStyle({width:e.x+"px",height:e.y+"px"})}else a=this.content.size();if(a.x+100>c.x)a.x=c.x-100;if(a.y+100>c.y)a.y=c.y-100;var t=(g*2+e.y-a.y)/2,m=this._.style,n=this.scroller._.style;if(d.Fx&&b&&(a.x!=e.x||a.y!=e.y))v(new d.Fx(this,{duration:this.options.fxDuration,transition:"Lin"}),{render:function(o){n.width=e.x+(a.x-e.x)*o+"px";n.height=e.y+(a.y-e.y)*o+"px";m.top=g+(t-g)*o+"px";if(i.IE6)m.width=k+e.y+(a.y-e.y)*o+"px"}}).onFinish(d(this.unlock).bind(this)).start();
|
17
|
+
else{n.width=a.x+"px";n.height=a.y+"px";m.top=t+"px";if(i.IE6)m.width=k+a.x+"px";this.request||this.unlock()}return this},show:function(a,b){this.content.update(a||"");this.resize(null,!b)},load:function(a,b){if(a instanceof j){this.setTitle(a.get("title"));a=a.get("href")}l.show(this,a);this.lock().cancel();this.request=new C(a,b,d(function(c,e){this.request=null;this.show(c,e)}).bind(this));return this.resize()},cancel:function(){this.request&&this.request.cancel();return this},lock:function(){this.locker.setStyle("opacity:1");
|
18
|
+
return this},unlock:function(){this.locker.morph({opacity:0},{duration:this.options.fxDuration*2/3});return this}}),C=new x({initialize:function(a,b,c){if(this.isImage(a,c))f.current.addClass("rui-lightbox-image");else if(this.isMedia(a,c))f.current.addClass("rui-lightbox-media");else this.xhr=(new w(a,y.merge({method:"get"},b))).onComplete(function(){c(this.text)}).send()},cancel:function(){if(this.xhr)this.xhr.cancel();else if(this.img)this.img.onload=function(){}},isImage:function(a,b){if(a.match(f.Images)){var c=
|
19
|
+
this.img=h("img")._;c.onload=function(){b(c)};c.src=a;return true}},isMedia:function(a,b){var c=d(f.Medias).map(function(e){return a.match(e[0])?this.buildEmbed(a.replace(e[0],e[1]),e[2]):null},this).compact()[0];if(c){b(c,true);return true}},buildEmbed:function(a,b){var c={swf:["D27CDB6E-AE6D-11cf-96B8-444553540000","http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0","application/x-shockwave-flash"]},e=f.current?f.current.options:f.Options;e=' width="'+e.mediaWidth+
|
20
|
+
'" height="'+e.mediaHeight+'"';return'<object classid="clsid:'+c[b][0]+'" codebase="'+c[b][1]+'"'+e+'><param name="src" value="'+a+'" /><embed src="'+a+'" type="'+c[b][2]+'"'+e+" /></object>"}}),l={show:function(a,b){if(a.options.group){this.dialog=a;this.links=this.find(a.options.group);this.link=this.links.first(function(g){return g.get("href")===b});var c=this.links.indexOf(this.link),e=this.links.length;a.prevLink[e&&c>0?"show":"hide"]();a.nextLink[e&&c<e-1?"show":"hide"]()}else this.dialog=null},
|
21
|
+
prev:function(){if(this.dialog&&!this.timer){var a=this.links[this.links.indexOf(this.link)-1];if(a){this.dialog.load(a);this.timeout()}}},next:function(){if(this.dialog&&!this.timer){var a=this.links[this.links.indexOf(this.link)+1];if(a){this.dialog.load(a);this.timeout()}}},find:function(a){return r("a").filter(function(b){var c=b.get("data-lightbox");b=b.get("rel");return c&&eval("("+c+")").group===a||b&&b.indexOf("lightbox["+a+"]")>-1})},timeout:function(){this.timer=d(function(){l.timer=null}).delay(300)}};
|
22
|
+
q(p).on({click:function(a){var b=a.find(f.Options.cssRule)||a.find("a[rel^=lightbox]");if(b){a.stop();(new f({},b)).load(b)}},mousewheel:function(a){if(f.current){a.stop();f.current.fire((a._.detail||-a._.wheelDelta)<0?"prev":"next")}},keydown:function(a){var b=f.current,c={27:"close",33:"prev",37:"prev",38:"prev",39:"next",40:"next",34:"next"}[a.keyCode];if(b&&c)if(c!=="close"||b.options.hideOnEsc){a.stop();b.fire(c)}}});q(window).on({resize:function(){if(f.current){f.current.reposition();f.current.dialog.resize()}},
|
23
|
+
scroll:function(){f.current&&i.IE6&&f.current.reposition()}});p.write('<style type="text/css">div.rui-spinner,div.rui-spinner div{margin:0;padding:0;border:none;background:none;list-style:none;font-weight:normal;float:none;display:inline-block; *display:inline; *zoom:1;border-radius:.12em;-moz-border-radius:.12em;-webkit-border-radius:.12em}div.rui-spinner{text-align:center;white-space:nowrap;background:#EEE;border:1px solid #DDD;height:1.2em;padding:0 .2em}div.rui-spinner div{width:.4em;height:70%;background:#BBB;margin-left:1px}div.rui-spinner div:first-child{margin-left:0}div.rui-spinner div.glowing{background:#777}div.rui-lightbox{position:fixed;top:0;left:0;z-index:9999;float:none;width:100%;height:100%;margin:0;padding:0;background:none;border:none;text-align:center}div.rui-lightbox-locker{position:absolute;top:0px;left:0px;width:100%;height:100%;background-color:#000;opacity:0.8;filter:alpha(opacity=80);cursor:default}div.rui-lightbox-dialog{display:inline-block; *display:inline; *zoom:1;position:relative;text-align:left}div.rui-lightbox-title{height:1.2em;margin-bottom:.1em;white-space:nowrap;color:#DDD;font-weight:bold;font-size:1.6em;font-family:Helvetica;text-shadow:#000 .05em .1em .2em}div.rui-lightbox-body{background-color:white;padding:1em;border-radius:.5em;-moz-border-radius:.5em;-webkit-border-radius:.5em;box-shadow:#000 .1em .2em 1.5em;-moz-box-shadow:#000 .1em .2em 1.5em;-webkit-box-shadow:#000 .1em .2em 1.5em}div.rui-lightbox-body-inner{position:relative}div.rui-lightbox-scroller{overflow:hidden}div.rui-lightbox-content{display:inline-block; *display:inline; *zoom:1;min-height:10em;min-width:10em;_height:10em;_width:10em}div.rui-lightbox-body-locker{background-color:white;position:absolute;left:0px;top:0px;width:100%;height:100%;z-index:999;opacity:0;filter:alpha(opacity=0)}div.rui-lightbox-body-locker div.rui-spinner{position:absolute;right:0;bottom:0;border:none;background:none;font-size:150%}div.rui-lightbox-navigation{color:#888;font-size:150%;font-family:Arial;height:1em;user-select:none;-moz-user-select:none;-webkit-user-select:none}div.rui-lightbox-navigation div{cursor:pointer;position:absolute}div.rui-lightbox-navigation div:hover{color:white}div.rui-lightbox-navigation div.next{left:2em}div.rui-lightbox-navigation div.close{right:0}div.rui-lightbox-image div.rui-lightbox-body,div.rui-lightbox-media div.rui-lightbox-body{padding:0;border:1px solid #777;border-radius:0px;-moz-border-radius:0px;-webkit-border-radius:0px}div.rui-lightbox-image div.rui-lightbox-content,div.rui-lightbox-media div.rui-lightbox-content{min-height:12em;min-width:12em;_height:12em;_width:12em}div.rui-lightbox-image div.rui-lightbox-content img{vertical-align:middle}div.rui-lightbox-image div.rui-lightbox-body,div.rui-lightbox-image div.rui-lightbox-body-locker,div.rui-lightbox-media div.rui-lightbox-body,div.rui-lightbox-media div.rui-lightbox-body-locker{background-color:#DDD}div.rui-lightbox-image div.rui-lightbox-body-locker div.rui-spinner,div.rui-lightbox-media div.rui-lightbox-body-locker div.rui-spinner{bottom:.5em;right:.5em}</style>');
|
24
|
+
return f}(document,RightJS);
|
@@ -1,16 +1,177 @@
|
|
1
1
|
/**
|
2
|
-
* Ruby On Rails
|
3
|
-
*
|
2
|
+
* The Ruby On Rails plugin for RightJS
|
3
|
+
* http://github.com/MadRabbit/right-rails
|
4
4
|
*
|
5
|
-
*
|
5
|
+
* Copyright (C) 2009-2010 Nikolay Nemshilov
|
6
|
+
*/
|
7
|
+
(function(window, document, RightJS) {
|
8
|
+
/**
|
9
|
+
* Underscored aliases for Ruby On Rails
|
10
|
+
*
|
11
|
+
* Copyright (C) 2009-2010 Nikolay Nemshilov
|
12
|
+
*/
|
13
|
+
|
14
|
+
/**
|
15
|
+
* The Rails plugin initialization script
|
16
|
+
*
|
17
|
+
* Copyright (C) 2010 Nikolay Nemshilov
|
18
|
+
*/
|
19
|
+
|
20
|
+
var R = RightJS,
|
21
|
+
$ = RightJS.$,
|
22
|
+
$$ = RightJS.$$,
|
23
|
+
$E = RightJS.$E,
|
24
|
+
Xhr = RightJS.Xhr,
|
25
|
+
Object = RightJS.Object;
|
26
|
+
|
27
|
+
|
28
|
+
|
29
|
+
// the language and window level aliases
|
30
|
+
R([
|
31
|
+
RightJS.String.prototype,
|
32
|
+
RightJS.Array.prototype,
|
33
|
+
RightJS.Function.prototype,
|
34
|
+
RightJS.Object,
|
35
|
+
RightJS.Options,
|
36
|
+
RightJS.Observer,
|
37
|
+
RightJS.Observer.prototype,
|
38
|
+
window,
|
39
|
+
document
|
40
|
+
]).each(function(object) {
|
41
|
+
for (var key in object) {
|
42
|
+
try { // some keys are not accessable
|
43
|
+
|
44
|
+
if (/[A-Z]/.test(key) && typeof(object[key]) === 'function') {
|
45
|
+
var u_key = R(key).underscored();
|
46
|
+
if (object[u_key] === null || object[u_key] === undefined) {
|
47
|
+
object[u_key] = object[key];
|
48
|
+
}
|
49
|
+
}
|
50
|
+
} catch (e) {}
|
51
|
+
}
|
52
|
+
});
|
53
|
+
|
54
|
+
|
55
|
+
// DOM package aliases
|
56
|
+
R([
|
57
|
+
RightJS.Element,
|
58
|
+
RightJS.Event,
|
59
|
+
RightJS.Form,
|
60
|
+
RightJS.Input
|
61
|
+
]).each(function(object) {
|
62
|
+
if (!object) { return; }
|
63
|
+
|
64
|
+
var aliases = {}, methods = object.prototype;
|
65
|
+
|
66
|
+
for (var key in methods) {
|
67
|
+
if (/[A-Z]/.test(key) && typeof(methods[key]) === 'function') {
|
68
|
+
object.prototype[R(key).underscored()] = methods[key];
|
69
|
+
}
|
70
|
+
}
|
71
|
+
});
|
72
|
+
|
73
|
+
// various ruby-like method aliases
|
74
|
+
RightJS.$alias(RightJS.String.prototype, {
|
75
|
+
index_of: 'indexOf',
|
76
|
+
last_index_of: 'lastIndexOf',
|
77
|
+
to_f: 'toFloat',
|
78
|
+
to_i: 'toInt',
|
79
|
+
gsub: 'replace',
|
80
|
+
downcase: 'toLowerCase',
|
81
|
+
upcase: 'toUpperCase',
|
82
|
+
index: 'indexOf',
|
83
|
+
rindex: 'lastIndexOf',
|
84
|
+
strip: 'trim'
|
85
|
+
});
|
86
|
+
|
87
|
+
RightJS.$alias(RightJS.Array.prototype, {
|
88
|
+
collect: 'map',
|
89
|
+
detect: 'filter',
|
90
|
+
index_of: 'indexOf',
|
91
|
+
last_index_of: 'lastIndexOf',
|
92
|
+
index: 'indexOf',
|
93
|
+
rindex: 'lastIndexOf'
|
94
|
+
});
|
95
|
+
|
96
|
+
/**
|
97
|
+
* Rails 3 UJS support module
|
6
98
|
*
|
7
|
-
* Copyright (C)
|
99
|
+
* Copyright (C) 2010 Nikolay Nemshilov
|
8
100
|
*/
|
101
|
+
(function() {
|
102
|
+
// tries to cancel the event via confirmation
|
103
|
+
var user_cancels = function(event, element) {
|
104
|
+
var message = element.get('data-confirm');
|
105
|
+
if (message && !confirm(message)) {
|
106
|
+
event.stop();
|
107
|
+
return true;
|
108
|
+
}
|
109
|
+
};
|
110
|
+
|
111
|
+
// adds XHR events to the element
|
112
|
+
var add_xhr_events = function(element, options) {
|
113
|
+
return Object.merge({
|
114
|
+
onCreate: function() { element.fire('ajax:loading', this); },
|
115
|
+
onComplete: function() { element.fire('ajax:complete', this); },
|
116
|
+
onSuccess: function() { element.fire('ajax:success', this); },
|
117
|
+
onFailure: function() { element.fire('ajax:failure', this); }
|
118
|
+
}, options);
|
119
|
+
};
|
120
|
+
|
121
|
+
// processes link clicks
|
122
|
+
var try_link_submit = function(event) {
|
123
|
+
var link = event.target,
|
124
|
+
method = link.get('data-method'),
|
125
|
+
remote = link.get('data-remote'),
|
126
|
+
url = link.get('href');
|
127
|
+
|
128
|
+
if (user_cancels(event, link)) { return; }
|
129
|
+
if (method || remote) { event.stop(); }
|
130
|
+
|
131
|
+
if (remote) {
|
132
|
+
Xhr.load(url, add_xhr_events(link, {
|
133
|
+
method: method || 'get',
|
134
|
+
spinner: link.get('data-spinner')
|
135
|
+
}));
|
136
|
+
|
137
|
+
} else if (method) {
|
138
|
+
var param = $$('meta[name=csrf-param]')[0],
|
139
|
+
token = $$('meta[name=csrf-token]')[0],
|
140
|
+
form = $E('form', {action: url, method: 'post'});
|
141
|
+
|
142
|
+
if (param && token) {
|
143
|
+
form.insert('<input type="hidden" name="'+param.get('content')+'" value="'+token.get('content')+'" />');
|
144
|
+
}
|
145
|
+
|
146
|
+
form.insert('<input type="hidden" name="_method" value="'+method+'"/>')
|
147
|
+
.insertTo(document.body).submit();
|
148
|
+
}
|
149
|
+
};
|
150
|
+
|
151
|
+
// global events listeners
|
152
|
+
$(document).on({
|
153
|
+
click: function(event) {
|
154
|
+
var tag = event.target._.tagName;
|
155
|
+
if (tag === 'A' || tag === 'BUTTON') {
|
156
|
+
try_link_submit(event);
|
157
|
+
}
|
158
|
+
},
|
159
|
+
|
160
|
+
submit: function(event) {
|
161
|
+
var form = event.target;
|
162
|
+
if (form.has('data-remote') && !user_cancels(event, form)) {
|
163
|
+
event.stop();
|
164
|
+
form.send(add_xhr_events(form));
|
165
|
+
}
|
166
|
+
}
|
167
|
+
});
|
168
|
+
})();
|
169
|
+
|
9
170
|
|
10
171
|
/**
|
11
172
|
* RR is the common ajax operations wrapper for ruby on rails
|
12
173
|
*
|
13
|
-
* Copyright (C) 2009-2010 Nikolay
|
174
|
+
* Copyright (C) 2009-2010 Nikolay Nemshilov
|
14
175
|
*/
|
15
176
|
var RR = {
|
16
177
|
/**
|
@@ -84,9 +245,9 @@ var RR = {
|
|
84
245
|
/**
|
85
246
|
* Inserts the content into the given element
|
86
247
|
*
|
87
|
-
* @param String destination id
|
88
|
-
* @param String content
|
89
|
-
* @param String position
|
248
|
+
* @param destination String destination id
|
249
|
+
* @param content String content
|
250
|
+
* @param position String position
|
90
251
|
* @return RR this
|
91
252
|
*/
|
92
253
|
insert: function(where, what, in_position) {
|
@@ -95,7 +256,7 @@ var RR = {
|
|
95
256
|
|
96
257
|
// trying to find the new block
|
97
258
|
switch (position) {
|
98
|
-
case 'bottom': new_element = container.
|
259
|
+
case 'bottom': new_element = container.children().last(); break;
|
99
260
|
case 'top': new_element = container.first(); break;
|
100
261
|
case 'before': new_element = container.prev(); break;
|
101
262
|
case 'after': new_element = container.next(); break;
|
@@ -116,8 +277,8 @@ var RR = {
|
|
116
277
|
/**
|
117
278
|
* Replaces the given element with a new content
|
118
279
|
*
|
119
|
-
* @param String destination id
|
120
|
-
* @param String content
|
280
|
+
* @param destination String destination id
|
281
|
+
* @param content String content
|
121
282
|
* @return RR this
|
122
283
|
*/
|
123
284
|
replace: function(id, source) {
|
@@ -132,15 +293,8 @@ var RR = {
|
|
132
293
|
* @return RR this
|
133
294
|
*/
|
134
295
|
remove: function(id) {
|
135
|
-
|
136
|
-
|
137
|
-
var remove_element = element.remove.bind(element);
|
138
|
-
|
139
|
-
if (this.Options.removeFx) {
|
140
|
-
element.hide(this.Options.removeFx, {onFinish: remove_element});
|
141
|
-
} else {
|
142
|
-
remove_element();
|
143
|
-
}
|
296
|
+
if ($(id)) {
|
297
|
+
$(id).remove(this.Options.removeFx);
|
144
298
|
}
|
145
299
|
},
|
146
300
|
|
@@ -153,7 +307,7 @@ var RR = {
|
|
153
307
|
remotize_form: function(id) {
|
154
308
|
var form = $(id);
|
155
309
|
if (form) {
|
156
|
-
form.remotize().enable().action += '.'+this.Options.format;
|
310
|
+
form.remotize().enable()._.action += '.'+this.Options.format;
|
157
311
|
}
|
158
312
|
return this;
|
159
313
|
},
|
@@ -161,8 +315,8 @@ var RR = {
|
|
161
315
|
/**
|
162
316
|
* Replaces the form with new content and makes it remote
|
163
317
|
*
|
164
|
-
* @param String form id
|
165
|
-
* @param String content
|
318
|
+
* @param form id String form id
|
319
|
+
* @param content String content
|
166
320
|
* @return RR this
|
167
321
|
*/
|
168
322
|
replace_form: function(id, source) {
|
@@ -178,8 +332,8 @@ var RR = {
|
|
178
332
|
/**
|
179
333
|
* Inserts the form source into the given element
|
180
334
|
*
|
181
|
-
* @param String target id
|
182
|
-
* @param String form source
|
335
|
+
* @param target id String target id
|
336
|
+
* @param source String form source
|
183
337
|
* @return RR this
|
184
338
|
*/
|
185
339
|
show_form_for: function(id, source) {
|
@@ -195,17 +349,14 @@ var RR = {
|
|
195
349
|
* @param Event event
|
196
350
|
*/
|
197
351
|
process_click: function(event) {
|
198
|
-
var
|
352
|
+
var link;
|
199
353
|
|
200
|
-
if (link) {
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
event.stop();
|
207
|
-
eval('({f:'+ link.onclick.toString().replace('.submit', '.send')+'})').f.call(link);
|
208
|
-
}
|
354
|
+
if ((link = event.find('a'+ this.Options.linkToAjaxEdit))) {
|
355
|
+
event.stop();
|
356
|
+
Xhr.load(link.get('href') + '.' + this.Options.format);
|
357
|
+
} else if ((link = event.find('a'+ this.Options.linkToAjaxDelete)) && link.has('onclick')) {
|
358
|
+
event.stop();
|
359
|
+
eval('({f:'+ link.onclick.toString().replace('.submit', '.send')+'})').f.call(link);
|
209
360
|
}
|
210
361
|
},
|
211
362
|
|
@@ -216,7 +367,9 @@ var RR = {
|
|
216
367
|
*/
|
217
368
|
rescan: function(scope) {
|
218
369
|
$w('Draggable Droppable Tabs Slider Selectable').each(function(name) {
|
219
|
-
if (name in
|
370
|
+
if (name in window) {
|
371
|
+
window[name].rescan(this.Options.rescanWithScopes ? scope : null);
|
372
|
+
}
|
220
373
|
}, this);
|
221
374
|
|
222
375
|
|
@@ -224,87 +377,13 @@ var RR = {
|
|
224
377
|
}
|
225
378
|
};
|
226
379
|
|
380
|
+
|
227
381
|
/**
|
228
|
-
*
|
382
|
+
* the document onload hooks
|
229
383
|
*
|
230
|
-
* Copyright (C) 2010 Nikolay
|
384
|
+
* Copyright (C) 2010 Nikolay Nemshilov
|
231
385
|
*/
|
232
|
-
(
|
233
|
-
// tries to cancel the event via confirmation
|
234
|
-
var user_cancels = function(event, element) {
|
235
|
-
var message = element.get('data-confirm');
|
236
|
-
if (message && !confirm(message)) {
|
237
|
-
event.stop();
|
238
|
-
return true;
|
239
|
-
}
|
240
|
-
};
|
241
|
-
|
242
|
-
// adds XHR events to the element
|
243
|
-
var add_xhr_events = function(element, options) {
|
244
|
-
return Object.merge({
|
245
|
-
onCreate: function() { element.fire('ajax:loading', this) },
|
246
|
-
onComplete: function() { element.fire('ajax:complete', this) },
|
247
|
-
onSuccess: function() { element.fire('ajax:success', this) },
|
248
|
-
onFailure: function() { element.fire('ajax:failure', this) }
|
249
|
-
}, options);
|
250
|
-
};
|
251
|
-
|
252
|
-
// processes link clicks
|
253
|
-
var try_link_submit = function(event, link) {
|
254
|
-
var method = link.get('data-method'), remote = link.get('data-remote');
|
255
|
-
|
256
|
-
if (user_cancels(event, link)) return;
|
257
|
-
if (method || remote) event.stop();
|
258
|
-
|
259
|
-
if (remote)
|
260
|
-
Xhr.load(link.href, add_xhr_events(link, {
|
261
|
-
method: method || 'get',
|
262
|
-
spinner: link.get('data-spinner')
|
263
|
-
}));
|
264
|
-
|
265
|
-
else if (method) {
|
266
|
-
var param = $$('meta[name=csrf-param]')[0],
|
267
|
-
token = $$('meta[name=csrf-token]')[0],
|
268
|
-
form = $E('form', {action: link.href, method: 'post'});
|
269
|
-
|
270
|
-
if (param && token)
|
271
|
-
form.insert('<input type="hidden" name="'+param.get('content')+'" value="'+token.get('content')+'" />');
|
272
|
-
form.insert('<input type="hidden" name="_method" value="'+method+'"/>')
|
273
|
-
.insertTo(document.body).submit();
|
274
|
-
}
|
275
|
-
};
|
276
|
-
|
277
|
-
// processes form submits
|
278
|
-
var try_form_submit = function(event, button) {
|
279
|
-
if (!user_cancels(event, button) && $(button.form).has('data-remote')) {
|
280
|
-
event.stop();
|
281
|
-
button.form.send(add_xhr_events(button.form));
|
282
|
-
}
|
283
|
-
};
|
284
|
-
|
285
|
-
// global events listeners
|
286
|
-
document.on({
|
287
|
-
click: function (event) {
|
288
|
-
var target = event.target, form = target.form,
|
289
|
-
link = [target].concat(target.parents()).first('match', 'a');
|
290
|
-
|
291
|
-
if (form && ['submit', 'image'].include(target.type))
|
292
|
-
try_form_submit(event, target);
|
293
|
-
else if (link)
|
294
|
-
try_link_submit(event, link);
|
295
|
-
},
|
296
|
-
|
297
|
-
keydown: function(event) {
|
298
|
-
var target = event.target, form = target.form;
|
299
|
-
if (form && target.tagName === 'INPUT' && event.keyCode == 13) {
|
300
|
-
try_form_submit(event, target);
|
301
|
-
}
|
302
|
-
}
|
303
|
-
});
|
304
|
-
})();
|
305
|
-
|
306
|
-
// the document onload hook
|
307
|
-
document.on({
|
386
|
+
$(document).on({
|
308
387
|
ready: function() {
|
309
388
|
RR.hide_flash();
|
310
389
|
},
|
@@ -313,61 +392,6 @@ document.on({
|
|
313
392
|
RR.process_click(event);
|
314
393
|
}
|
315
394
|
});
|
316
|
-
/**
|
317
|
-
* Underscored aliases for Ruby On Rails
|
318
|
-
*
|
319
|
-
* Copyright (C) 2009-2010 Nikolay V. Nemshilov
|
320
|
-
*/
|
321
|
-
|
322
|
-
// the language and window level aliases
|
323
|
-
[String.prototype, Array.prototype, Function.prototype, Object, Options, Observer, Observer.prototype, window, document].each(function(object) {
|
324
|
-
for (var key in object) {
|
325
|
-
try { // some keys are not accessable
|
326
|
-
|
327
|
-
if (/[A-Z]/.test(key) && typeof(object[key]) === 'function') {
|
328
|
-
var u_key = key.underscored();
|
329
|
-
if (object[u_key] === null || object[u_key] === undefined) {
|
330
|
-
object[u_key] = object[key];
|
331
|
-
}
|
332
|
-
}
|
333
|
-
} catch (e) {}
|
334
|
-
}
|
335
|
-
});
|
336
|
-
|
337
|
-
|
338
|
-
// DOM package aliases
|
339
|
-
[Element, Event, Form, Form.Element].each(function(object) {
|
340
|
-
var aliases = {}, methods = object.Methods;
|
341
|
-
|
342
|
-
for (var key in methods) {
|
343
|
-
if (/[A-Z]/.test(key) && typeof(methods[key]) === 'function') {
|
344
|
-
aliases[key.underscored()] = methods[key];
|
345
|
-
}
|
346
|
-
}
|
347
395
|
|
348
|
-
|
349
|
-
});
|
350
|
-
|
351
|
-
|
352
|
-
// various ruby-like method aliases
|
353
|
-
$alias(String.prototype, {
|
354
|
-
index_of: 'indexOf',
|
355
|
-
last_index_of: 'lastIndexOf',
|
356
|
-
to_f: 'toFloat',
|
357
|
-
to_i: 'toInt',
|
358
|
-
gsub: 'replace',
|
359
|
-
downcase: 'toLowerCase',
|
360
|
-
upcase: 'toUpperCase',
|
361
|
-
index: 'indexOf',
|
362
|
-
rindex: 'lastIndexOf',
|
363
|
-
strip: 'trim'
|
364
|
-
});
|
365
|
-
|
366
|
-
$alias(Array.prototype, {
|
367
|
-
collect: 'map',
|
368
|
-
detect: 'filter',
|
369
|
-
index_of: 'indexOf',
|
370
|
-
last_index_of: 'lastIndexOf',
|
371
|
-
index: 'indexOf',
|
372
|
-
rindex: 'lastIndexOf'
|
373
|
-
});
|
396
|
+
window.RR = RR;
|
397
|
+
})(window, document, RightJS);
|
@@ -0,0 +1,14 @@
|
|
1
|
+
/**
|
2
|
+
* The Ruby On Rails plugin for RightJS
|
3
|
+
* http://github.com/MadRabbit/right-rails
|
4
|
+
*
|
5
|
+
* Copyright (C) 2009-2010 Nikolay Nemshilov
|
6
|
+
*/
|
7
|
+
(function(i,j,e){var f=e.$,l=e.$$,o=e.$E,m=e.Xhr,p=e.Object;e([e.String.prototype,e.Array.prototype,e.Function.prototype,e.Object,e.Options,e.Observer,e.Observer.prototype,i,j]).each(function(a){for(var b in a)try{if(/[A-Z]/.test(b)&&typeof a[b]==="function"){var c=e(b).underscored();if(a[c]===null||a[c]===undefined)a[c]=a[b]}}catch(d){}});e([e.Element,e.Event,e.Form,e.Input]).each(function(a){if(a){var b=a.prototype;for(var c in b)if(/[A-Z]/.test(c)&&typeof b[c]==="function")a.prototype[e(c).underscored()]=
|
8
|
+
b[c]}});e.$alias(e.String.prototype,{index_of:"indexOf",last_index_of:"lastIndexOf",to_f:"toFloat",to_i:"toInt",gsub:"replace",downcase:"toLowerCase",upcase:"toUpperCase",index:"indexOf",rindex:"lastIndexOf",strip:"trim"});e.$alias(e.Array.prototype,{collect:"map",detect:"filter",index_of:"indexOf",last_index_of:"lastIndexOf",index:"indexOf",rindex:"lastIndexOf"});(function(){var a=function(c,d){var g=d.get("data-confirm");if(g&&!confirm(g)){c.stop();return true}},b=function(c,d){return p.merge({onCreate:function(){c.fire("ajax:loading",
|
9
|
+
this)},onComplete:function(){c.fire("ajax:complete",this)},onSuccess:function(){c.fire("ajax:success",this)},onFailure:function(){c.fire("ajax:failure",this)}},d)};f(j).on({click:function(c){var d=c.target._.tagName;if(d==="A"||d==="BUTTON"){var g=c.target;d=g.get("data-method");var n=g.get("data-remote"),h=g.get("href");if(!a(c,g)){if(d||n)c.stop();if(n)m.load(h,b(g,{method:d||"get",spinner:g.get("data-spinner")}));else if(d){c=l("meta[name=csrf-param]")[0];g=l("meta[name=csrf-token]")[0];h=o("form",
|
10
|
+
{action:h,method:"post"});c&&g&&h.insert('<input type="hidden" name="'+c.get("content")+'" value="'+g.get("content")+'" />');h.insert('<input type="hidden" name="_method" value="'+d+'"/>').insertTo(j.body).submit()}}}},submit:function(c){var d=c.target;if(d.has("data-remote")&&!a(c,d)){c.stop();d.send(b(d))}}})})();var k={Options:{format:"js",flashId:"flashes",flashHideFx:"slide",flashHideDelay:3200,highlightUpdates:true,removeFx:"fade",insertFx:"fade",insertPosition:"bottom",linkToAjaxEdit:".ajax_edit",
|
11
|
+
linkToAjaxDelete:".ajax_delete",rescanWithScopes:true},update_flash:function(a){var b=f(this.Options.flashId);b&&this.replace(b,a).hide_flash();return this},hide_flash:function(){if(this.Options.flashHideDelay>-1){var a=f(this.Options.flashId);a&&a.visible()&&a.hide.bind(a,this.Options.flashHideFx).delay(this.Options.flashHideDelay)}return this},highlight:function(a){f(a)&&this.Options.highlightUpdates&&f(a).highlight();return this},insert:function(a,b,c){c=c||this.Options.insertPosition;var d;b=
|
12
|
+
f(a).insert(b,c);switch(c){case "bottom":d=b.children().last();break;case "top":d=b.first();break;case "before":d=b.prev();break;case "after":d=b.next();break}d&&this.Options.insertFx?d.hide().show(this.Options.insertFx,{onFinish:this.highlight.bind(this,d)}):this.highlight(d);return this.rescan(a)},replace:function(a,b){f(a).replace(b);return this.highlight(a).rescan(a)},remove:function(a){f(a)&&f(a).remove(this.Options.removeFx)},remotize_form:function(a){if(a=f(a))a.remotize().enable()._.action+=
|
13
|
+
"."+this.Options.format;return this},replace_form:function(a,b){var c=f(a);if(c){c.replace(b);this.remotize_form(a)}return this.rescan(a)},show_form_for:function(a,b){f(a).select("form").each("remove");f(a).insert(b);return this.remotize_form(f(a).first("form")).rescan(a)},process_click:function(a){var b;if(b=a.find("a"+this.Options.linkToAjaxEdit)){a.stop();m.load(b.get("href")+"."+this.Options.format)}else if((b=a.find("a"+this.Options.linkToAjaxDelete))&&b.has("onclick")){a.stop();eval("({f:"+
|
14
|
+
b.onclick.toString().replace(".submit",".send")+"})").f.call(b)}},rescan:function(a){$w("Draggable Droppable Tabs Slider Selectable").each(function(b){if(b in i)i[b].rescan(this.Options.rescanWithScopes?a:null)},this);return this}};f(j).on({ready:function(){k.hide_flash()},click:function(a){k.process_click(a)}});i.RR=k})(window,document,RightJS);
|