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.
Files changed (118) hide show
  1. data/CHANGELOG +8 -0
  2. data/README.rdoc +71 -0
  3. data/Rakefile +144 -14
  4. data/generators/right_rails/right_rails_generator.rb +18 -21
  5. data/init.rb +11 -32
  6. data/lib/generators/right_rails/right_rails_generator.rb +27 -0
  7. data/lib/generators/right_rails/templates/iframed.html.erb +10 -0
  8. data/lib/right-rails.rb +1 -1
  9. data/lib/right_rails/config.rb +278 -0
  10. data/lib/right_rails/controller_extensions.rb +10 -5
  11. data/lib/right_rails/helpers/basic.rb +10 -66
  12. data/lib/right_rails/helpers/forms.rb +141 -139
  13. data/lib/right_rails/helpers/misc.rb +45 -67
  14. data/lib/right_rails/helpers/rails.rb +40 -105
  15. data/lib/right_rails/helpers.rb +364 -1
  16. data/lib/right_rails/java_script_generator.rb +34 -24
  17. data/lib/right_rails.rb +6 -1
  18. data/{images → public/images}/colorpicker.png +0 -0
  19. data/{images → public/images}/resizable.png +0 -0
  20. data/public/javascripts/right/autocompleter-src.js +612 -0
  21. data/public/javascripts/right/autocompleter.js +18 -0
  22. data/public/javascripts/right/calendar-src.js +1448 -0
  23. data/public/javascripts/right/calendar.js +36 -0
  24. data/public/javascripts/right/colorpicker-src.js +967 -0
  25. data/public/javascripts/right/colorpicker.js +26 -0
  26. data/{javascripts/right-dnd-src.js → public/javascripts/right/dnd-src.js} +86 -52
  27. data/public/javascripts/right/dnd.js +20 -0
  28. data/{javascripts/right-effects-src.js → public/javascripts/right/effects-src.js} +90 -45
  29. data/public/javascripts/right/effects.js +17 -0
  30. data/{javascripts/right-ui-i18n-de.js → public/javascripts/right/i18n/de.js} +7 -7
  31. data/{javascripts/right-ui-i18n-en-us.js → public/javascripts/right/i18n/en-us.js} +1 -1
  32. data/{javascripts/right-ui-i18n-es.js → public/javascripts/right/i18n/es.js} +7 -7
  33. data/{javascripts/right-ui-i18n-fr.js → public/javascripts/right/i18n/fr.js} +7 -7
  34. data/{javascripts/right-ui-i18n-hu.js → public/javascripts/right/i18n/hu.js} +7 -7
  35. data/{javascripts/right-ui-i18n-jp.js → public/javascripts/right/i18n/jp.js} +7 -7
  36. data/{javascripts/right-ui-i18n-nl.js → public/javascripts/right/i18n/nl.js} +7 -7
  37. data/{javascripts/right-ui-i18n-pt-br.js → public/javascripts/right/i18n/pt-br.js} +7 -7
  38. data/{javascripts/right-ui-i18n-ru.js → public/javascripts/right/i18n/ru.js} +7 -7
  39. data/{javascripts/right-ui-i18n-ua.js → public/javascripts/right/i18n/ua.js} +17 -12
  40. data/public/javascripts/right/in-edit-src.js +352 -0
  41. data/public/javascripts/right/in-edit.js +13 -0
  42. data/public/javascripts/right/json-src.js +160 -0
  43. data/public/javascripts/right/json.js +10 -0
  44. data/public/javascripts/right/lightbox-src.js +881 -0
  45. data/public/javascripts/right/lightbox.js +24 -0
  46. data/{javascripts/right-rails-src.js → public/javascripts/right/rails-src.js} +195 -171
  47. data/public/javascripts/right/rails.js +14 -0
  48. data/public/javascripts/right/rater-src.js +366 -0
  49. data/public/javascripts/right/rater.js +13 -0
  50. data/public/javascripts/right/resizable-src.js +420 -0
  51. data/public/javascripts/right/resizable.js +15 -0
  52. data/public/javascripts/right/selectable-src.js +687 -0
  53. data/public/javascripts/right/selectable.js +22 -0
  54. data/public/javascripts/right/slider-src.js +377 -0
  55. data/public/javascripts/right/slider.js +14 -0
  56. data/public/javascripts/right/sortable-src.js +392 -0
  57. data/public/javascripts/right/sortable.js +16 -0
  58. data/public/javascripts/right/tabs-src.js +1123 -0
  59. data/public/javascripts/right/tabs.js +29 -0
  60. data/public/javascripts/right/tooltip-src.js +307 -0
  61. data/public/javascripts/right/tooltip.js +12 -0
  62. data/public/javascripts/right/uploader-src.js +283 -0
  63. data/public/javascripts/right/uploader.js +13 -0
  64. data/{javascripts → public/javascripts}/right-olds-src.js +134 -186
  65. data/public/javascripts/right-olds.js +18 -0
  66. data/public/javascripts/right-safe-src.js +161 -0
  67. data/public/javascripts/right-safe.js +8 -0
  68. data/{javascripts → public/javascripts}/right-src.js +2558 -1750
  69. data/public/javascripts/right.js +92 -0
  70. data/spec/lib/right_rails/config_spec.rb +133 -0
  71. data/spec/lib/right_rails/controller_extensions_spec.rb +1 -1
  72. data/spec/lib/right_rails/helpers/basic_spec.rb +77 -66
  73. data/spec/lib/right_rails/helpers/forms_spec.rb +231 -33
  74. data/spec/lib/right_rails/helpers/misc_spec.rb +94 -26
  75. data/spec/lib/right_rails/helpers/rails_spec.rb +42 -7
  76. data/spec/lib/right_rails/helpers_spec.rb +125 -0
  77. data/spec/lib/right_rails/java_script_generator_spec.rb +30 -0
  78. data/spec/rcov.opts +3 -0
  79. data/spec/spec_helper.rb +12 -7
  80. metadata +70 -61
  81. data/README.textile +0 -69
  82. data/javascripts/right-autocompleter-src.js +0 -318
  83. data/javascripts/right-autocompleter.js +0 -9
  84. data/javascripts/right-behavior-src.js +0 -261
  85. data/javascripts/right-behavior.js +0 -8
  86. data/javascripts/right-calendar-src.js +0 -946
  87. data/javascripts/right-calendar.js +0 -9
  88. data/javascripts/right-colorpicker-src.js +0 -635
  89. data/javascripts/right-colorpicker.js +0 -9
  90. data/javascripts/right-dnd.js +0 -9
  91. data/javascripts/right-effects.js +0 -6
  92. data/javascripts/right-events-src.js +0 -321
  93. data/javascripts/right-events.js +0 -6
  94. data/javascripts/right-in-edit-src.js +0 -194
  95. data/javascripts/right-in-edit.js +0 -6
  96. data/javascripts/right-json-src.js +0 -141
  97. data/javascripts/right-json.js +0 -6
  98. data/javascripts/right-lightbox-src.js +0 -651
  99. data/javascripts/right-lightbox.js +0 -9
  100. data/javascripts/right-olds.js +0 -9
  101. data/javascripts/right-rails.js +0 -9
  102. data/javascripts/right-rater-src.js +0 -253
  103. data/javascripts/right-rater.js +0 -9
  104. data/javascripts/right-resizable-src.js +0 -336
  105. data/javascripts/right-resizable.js +0 -9
  106. data/javascripts/right-selectable-src.js +0 -565
  107. data/javascripts/right-selectable.js +0 -7
  108. data/javascripts/right-slider-src.js +0 -288
  109. data/javascripts/right-slider.js +0 -7
  110. data/javascripts/right-sortable-src.js +0 -225
  111. data/javascripts/right-sortable.js +0 -9
  112. data/javascripts/right-tabs-src.js +0 -937
  113. data/javascripts/right-tabs.js +0 -6
  114. data/javascripts/right-tooltips-src.js +0 -195
  115. data/javascripts/right-tooltips.js +0 -9
  116. data/javascripts/right-uploader-src.js +0 -167
  117. data/javascripts/right-uploader.js +0 -9
  118. data/javascripts/right.js +0 -7
@@ -0,0 +1,26 @@
1
+ /**
2
+ * RightJS UI Colorpicker widget
3
+ *
4
+ * See http://rightjs.org/ui/colorpicker
5
+ *
6
+ * Copyright (C) 2010 Nikolay Nemshilov
7
+ */
8
+ var Colorpicker=RightJS.Colorpicker=function(p,q,i,e){function r(a,b,c,d){if(e.Fx)if(c===undefined){c=this.options.fxName;if(d===undefined){d={duration:this.options.fxDuration,onFinish:e(this.fire).bind(this,b)};if(b==="hide")d.duration=(e.Fx.Durations[d.duration]||d.duration)/2}}e.Element.prototype[b].call(a,c,d);if(!e.Fx||!c)this.fire(b);return this}var j=e,n=e.$,u=e.$w,v=e.$$,h=e.$E,s=e.$A,w=e.isArray,o=e.Wrapper,m=e.Element,t=e.Input,x=new e.Wrapper(e.Element,{initialize:function(a,b){this.$super("div",
9
+ b);this._.innerHTML=a;this.addClass("rui-button")},disable:function(){return this.addClass("rui-button-disabled")},enable:function(){return this.removeClass("rui-button-disabled")},disabled:function(){return this.hasClass("rui-button-disabled")},enabled:function(){return!this.disabled()},fire:function(){this.enabled()&&this.$super.apply(this,arguments);return this}}),g=new (function(a,b){if(!b){b=a;a="DIV"}var c=new e.Wrapper(e.Element.Wrappers[a]||e.Element,{initialize:function(d,f){this.key=d;var k=
10
+ [{"class":"rui-"+d}];this instanceof e.Input||this instanceof e.Form||k.unshift(a);this.$super.apply(this,k);if(e.isString(f))f=e.$(f);if(f instanceof e.Element){this._=f._;if("$listeners"in f)f.$listeners=f.$listeners;f={}}this.setOptions(f,this);return this},setOptions:function(d,f){f=f||this;e.Options.setOptions.call(this,e.Object.merge(d,eval("("+(f.get("data-"+this.key)||"{}")+")")));return this}});c=new e.Wrapper(c,b);e.Observer.createShortcuts(c.prototype,c.EVENTS||[]);return c})({include:[{show:function(a,
11
+ b){this.constructor.current=this;return r.call(this,this,"show",a,b)},hide:function(a,b){this.constructor.current=null;return r.call(this,this,"hide",a,b)},showAt:function(a,b,c){var d=this.hide(null).shownAt=a=e.$(a),f=(this.reAnchor||(this.reAnchor=new e.Element("div",{"class":"rui-re-anchor"})).insert(this)).insertTo(d,"after").position();a=d.dimensions();var k=i(d.getStyle("borderTopWidth")),l=i(d.getStyle("borderLeftWidth")),y=i(d.getStyle("borderRightWidth")),z=i(d.getStyle("borderBottomWidth"));
12
+ d=a.top-f.y+k;f=a.left-f.x+l;l=a.width-l-y;a=a.height-k-z;this.setStyle("visibility:hidden").show(null);if(b==="right")f+=l-this.size().x;else d+=a;this.moveTo(f,d);if(c)["left","right"].include(b)?this.setHeight(a):this.setWidth(l);this.setStyle("visibility:visible").hide(null);return this.show()},toggleAt:function(a,b,c){return this.hidden()?this.showAt(a,b,c):this.hide()}},{assignTo:function(a,b){a=e.$(a);if(b=e.$(b)){b[this.key]=this;b.assignedInput=a}else a[this.key]=this;var c=e(function(){if(this.visible()&&
13
+ (!this.showAt||this.shownAt===a))this.setValue(a.value())}).bind(this);a.on({keyup:c,change:c});this.onChange(function(){if(!this.showAt||this.shownAt===a)a.setValue(this.getValue())});return this}}],extend:{version:"2.0.0",EVENTS:u("change show hide done"),Options:{format:"hex",update:null,updateBg:null,trigger:null,fxName:"fade",fxDuration:"short",cssRule:"*[data-colorpicker]"},i18n:{Done:"Done"},hideAll:function(){v("div.rui-colorpicker").each(function(a){a instanceof g&&!a.inlined()&&a.hide()})}},
14
+ initialize:function(a){this.$super("colorpicker",a).addClass("rui-panel").insert([this.field=new A,this.colors=new B,this.controls=new C]).on({mousedown:this.startTrack,keyup:this.recalc,blur:this.update,focus:this.cancelTimer,done:this.done});this.options.update&&this.assignTo(this.options.update,this.options.trigger);this.options.updateBg&&this.updateBg(this.options.updateBg);this.tint=j([1,0,0]);this.satur=0;this.bright=1;this.color=j([255,255,255]);this.recalc().update()},setValue:function(a){if((a=
15
+ w(a)?a:this.toColor(a))&&a.length===3){this.color=a=a.map(function(b){return this.bound(i(""+b),0,255)},this);this.color2tint().update();this.colors.size().y||this.update.bind(this).delay(20)}return this},getValue:function(a){return a?this.color:this[this.options.format==="rgb"?"toRgb":"toHex"]()},updateBg:function(a){var b=n(a);b&&this.onChange(j(function(){b._.style.backgroundColor=this.toRgb()}).bind(this));return this},insertTo:function(a,b){return this.$super(a,b).addClass("rui-colorpicker-inline")},
16
+ inlined:function(){return this.hasClass("rui-colorpicker-inline")},done:function(){this.inlined()||this.hide();return this},setOptions:function(a){a=a||{};this.$super(a,n(a.trigger||a.update))},update:function(){this.field._.style.backgroundColor="rgb("+this.tint.map(function(d){return q.round(d*255)})+")";var a=this.color,b=this.controls;b.preview._.style.backgroundColor=b.display._.value=this.toHex();b.rDisplay._.value=a[0];b.gDisplay._.value=a[1];b.bDisplay._.value=a[2];b=this.field.pointer._.style;
17
+ a=this.field.size();var c=this.satur*a.x-2;b.top=this.bound(a.y-this.bright*a.y-2,0,a.y-5)+"px";b.left=this.bound(c,0,a.x-5)+"px";b=this.tint;a=this.colors.size();b=b[1]==0?b[0]==1?b[2]:2-b[0]:b[0]==0?2+(b[2]==1?b[1]:2-b[2]):4+(b[1]==1?b[0]:2-b[1]);b=b/6*a.y;this.colors.pointer._.style.top=this.bound(b,0,a.y-4)+"px";if(this.prevColor!==""+this.color){this.fire("change",this.color);this.prevColor=""+this.color}return this},recalc:function(a){if(a){a=a.target;var b=a._.value,c=s(this.color),d=false;
18
+ if(a===this.controls.display&&/#\w{6}/.test(b))d=c=this.toColor(b);else if(/^\d+$/.test(b)){c[a._.cIndex]=b;d=true}d&&this.setValue(c)}else this.tint2color();return this},startTrack:function(a){this.stopTrack();this.cancelTimer();if(a.target===this.field.pointer)a.target=this.field;else if(a.target===this.colors.pointer)a.target=this.colors;if(a.target===this.field||a.target===this.colors){a.stop();g.tracking=this;a.target.tracking=true;this.trackMove(a)}},stopTrack:function(){g.tracking=false;this.field.tracking=
19
+ false;this.colors.tracking=false},trackMove:function(a){var b,c=a.position();if(this.field.tracking)b=this.field.dimensions();else if(this.colors.tracking)b=this.colors.dimensions();if(b){a=this.bound(c.y-b.top,0,b.height);c=this.bound(c.x-b.left,0,b.width);if(this.field.tracking){this.satur=c/b.width;this.bright=1-a/b.height}else if(this.colors.tracking){if(a==b.height)a=b.height-0.1;b=b.height/6;c=this.tint=[0,0,0];var d=a%b/b,f=1-d;if(a<b){c[0]=1;c[2]=d}else if(a<b*2){c[0]=f;c[2]=1}else if(a<b*
20
+ 3){c[2]=1;c[1]=d}else if(a<b*4){c[2]=f;c[1]=1}else if(a<b*5){c[1]=1;c[0]=d}else{c[1]=f;c[0]=1}}this.recalc().update()}},cancelTimer:function(){j(function(){if(this._hide_delay){this._hide_delay.cancel();this._hide_delay=null}}).bind(this).delay(10)}}),A=new o(m,{initialize:function(){this.$super("div",{"class":"field"});this.insert(this.pointer=h("div",{"class":"pointer"}))}}),B=new o(m,{initialize:function(){this.$super("div",{"class":"colors"});this.insert(this.pointer=h("div",{"class":"pointer"}))}}),
21
+ C=new o(m,{initialize:function(){this.$super("div",{"class":"controls"});this.insert([this.preview=h("div",{"class":"preview",html:"&nbsp;"}),this.display=h("input",{type:"text","class":"display",maxlength:7}),h("div",{"class":"rgb-display"}).insert([h("div").insert([h("label",{html:"R:"}),this.rDisplay=h("input",{maxlength:3,cIndex:0})]),h("div").insert([h("label",{html:"G:"}),this.gDisplay=h("input",{maxlength:3,cIndex:1})]),h("div").insert([h("label",{html:"B:"}),this.bDisplay=h("input",{maxlength:3,
22
+ cIndex:2})])]),this.button=(new x(g.i18n.Done)).onClick("fire","done")])}});g.include({toRgb:function(){return"rgb("+this.color.join(",")+")"},toHex:function(){return"#"+this.color.map(function(a){return(a<16?"0":"")+a.toString(16)}).join("")},toColor:function(a){a=a.toLowerCase();var b;if(b=/rgb\((\d+),(\d+),(\d+)\)/.exec(a))return[b[1],b[2],b[3]].map(i);else if(/#[\da-f]+/.test(a)){if(b=/^#([\da-f])([\da-f])([\da-f])$/.exec(a))a="#"+b[1]+b[1]+b[2]+b[2]+b[3]+b[3];if(b=/#([\da-f]{2})([\da-f]{2})([\da-f]{2})/.exec(a))return[b[1],
23
+ b[2],b[3]].map(function(c){return i(c,16)})}},color2tint:function(){var a=s(this.color).sort(function(d,f){return d-f}),b=a[0],c=a[2];this.bright=c/255;this.satur=1-b/(c||1);this.tint.each(function(d,f){this.tint[f]=!b&&!c||b==c?f==0?1:0:(this.color[f]-b)/(c-b);return this.tint[f]},this);return this},tint2color:function(){for(var a=this.tint,b=this.color,c=0;c<3;c++){b[c]=1+this.satur*(a[c]-1);b[c]=q.round(255*b[c]*this.bright)}return this},bound:function(a,b,c){a=a;if(b<c)a=a<b?b:a>c?c:a;else{if(a>
24
+ c)a=c;if(a<b)a=b}return a}});n(p).on({mouseup:function(){g.tracking&&g.tracking.stopTrack()},mousemove:function(a){g.tracking&&g.tracking.trackMove(a)},focus:function(a){a=a.target instanceof t?a.target:null;g.hideAll();if(a&&(a.colorpicker||a.match(g.Options.cssRule)))(a.colorpicker||new g({update:a})).setValue(a.value()).showAt(a)},blur:function(a){var b=a.target.colorpicker;if(b)b._hide_delay=j(function(){b.hide()}).delay(200)},click:function(a){var b=a.target instanceof m?a.target:null;if(b&&
25
+ (b.colorpicker||b.match(g.Options.cssRule))){if(!(b instanceof t)){a.stop();(b.colorpicker||new g({trigger:b})).hide(null).toggleAt(b.assignedInput)}}else a.find("div.rui-colorpicker")||g.hideAll()},keydown:function(a){var b=g.current,c={27:"hide",13:"done"}[a.keyCode];if(c&&b&&b.visible()){a.stop();b[c]()}}});p.write('<style type="text/css"> *.rui-button{display:inline-block; *display:inline; *zoom:1;height:1em;line-height:1em;margin:0;padding:.2em .5em;text-align:center;border:1px solid #CCC;border-radius:.2em;-moz-border-radius:.2em;-webkit-border-radius:.2em;cursor:pointer;color:#333;background-color:#FFF;user-select:none;-moz-user-select:none;-webkit-user-select:none} *.rui-button:hover{color:#111;border-color:#999;background-color:#DDD;box-shadow:#888 0 0 .1em;-moz-box-shadow:#888 0 0 .1em;-webkit-box-shadow:#888 0 0 .1em} *.rui-button:active{color:#000;border-color:#777;text-indent:1px;box-shadow:none;-moz-box-shadow:none;-webkit-box-shadow:none} *.rui-button-disabled, *.rui-button-disabled:hover, *.rui-button-disabled:active{color:#888;background:#DDD;border-color:#CCC;cursor:default;text-indent:0;box-shadow:none;-moz-box-shadow:none;-webkit-box-shadow:none}div.rui-re-anchor{margin:0;padding:0;background:none;border:none;float:none;display:inline;position:absolute;z-index:9999}.rui-panel{margin:0;padding:.5em;position:relative;background-color:#EEE;border:1px solid #BBB;border-radius:.3em;-moz-border-radius:.3em;-webkit-border-radius:.3em;box-shadow:.15em .3em .5em #BBB;-moz-box-shadow:.15em .3em .5em #BBB;-webkit-box-shadow:.15em .3em .5em #BBB;cursor:default}div.rui-colorpicker .field,div.rui-colorpicker .field *,div.rui-colorpicker .colors,div.rui-colorpicker .colors *{border:none;background:none;width:auto;height:auto;position:static;float:none;top:none;left:none;right:none;bottom:none;margin:0;padding:0;display:block;font-weight:normal;vertical-align:center}div.rui-colorpicker div.field,div.rui-colorpicker div.field div.pointer,div.rui-colorpicker div.colors,div.rui-colorpicker div.colors div.pointer{background:url(/images/rightjs-ui/colorpicker.png) no-repeat 0 0}div.rui-colorpicker div.field,div.rui-colorpicker div.colors,div.rui-colorpicker div.controls{display:inline-block; *display:inline; *zoom:1;position:relative;vertical-align:top;height:150px}div.rui-colorpicker div.field div.pointer,div.rui-colorpicker div.colors div.pointer{position:absolute;top:0px;left:0;width:9px;height:9px}div.rui-colorpicker input.display,div.rui-colorpicker div.preview,div.rui-colorpicker div.rgb-display,div.rui-colorpicker input.rui-ui-button{font-size:100%;display:block;width:auto;padding:0 .2em}div.rui-colorpicker input.display,div.rui-colorpicker div.preview,div.rui-colorpicker div.rgb-display input,div.rui-colorpicker input.rui-ui-button{border:1px solid #AAA;-moz-border-radius:.2em;-webkit-border-radius:.2em}div.rui-colorpicker div.field{width:150px;background-color:red;cursor:crosshair;margin-right:1.2em}div.rui-colorpicker div.field div.pointer{background-position:-170px 0;margin-left:-2px;margin-top:-2px}div.rui-colorpicker div.colors{width:16px;background-position:-150px 0;border-color:#EEE;cursor:pointer;margin-right:.6em}div.rui-colorpicker div.colors div.pointer{cursor:default;background-position:-170px -20px;margin-left:-8px;margin-top:-3px}div.rui-colorpicker div.controls{width:5em}div.rui-colorpicker div.preview{height:2em;background:white;border-color:#BBB}div.rui-colorpicker input.display{margin-top:.5em;background:#FFF;width:4.5em}div.rui-colorpicker div.rgb-display{padding:0;text-align:right;margin-top:.5em}div.rui-colorpicker div.rgb-display label{display:inline}div.rui-colorpicker div.rgb-display label:after{content:none}div.rui-colorpicker div.rgb-display input{vertical-align:top;font-size:100%;width:2em;text-align:right;margin-left:.2em;padding:0 .2em;background:#FFF;margin-bottom:1px;display:inline}div.rui-colorpicker div.rui-button{cursor:pointer;position:absolute;bottom:0;right:0;width:4em}div.rui-colorpicker-inline{display:inline-block; *display:inline; *zoom:1;position:relative;box-shadow:none;-moz-box-shadow:none;-webkit-box-shadow:none;z-index:auto}</style>');
26
+ return g}(document,Math,parseInt,RightJS);
@@ -1,17 +1,31 @@
1
1
  /**
2
2
  * Drag'n'Drop module for RightJS
3
+ * http://rightjs.org/plugins/drag-n-drop
3
4
  *
4
- * See http://rightjs.org/goods/drag-n-drop
5
+ * Copyright (C) 2009-2010 Nikolay Nemshilov
6
+ */
7
+ (function(window, document, RightJS) {
8
+ /**
9
+ * Draggable unit
5
10
  *
6
- * Copyright (C) 2009-2010 Nikolay V. Nemshilov
11
+ * Copyright (C) 2009-2010 Nikolay Nemshilov
7
12
  */
8
- if (!RightJS) throw "Gimme RightJS";
9
13
 
10
14
  /**
11
- * Draggable unit
15
+ * The DND module initialization script
12
16
  *
13
- * Copyright (C) 2009-2010 Nikolay V. Nemshilov
17
+ * Copyright (C) 2010 Nikolay Nemshilov
14
18
  */
19
+ var R = RightJS,
20
+ $ = RightJS.$,
21
+ $w = RightJS.$w,
22
+ Class = RightJS.Class,
23
+ isHash = RightJS.isHash,
24
+ isArray = RightJS.isArray,
25
+ Element = RightJS.Element,
26
+ Observer = RightJS.Observer;
27
+
28
+
15
29
  var Draggable = new Class(Observer, {
16
30
  extend: {
17
31
  EVENTS: $w('before start drag stop drop'),
@@ -45,8 +59,8 @@ var Draggable = new Class(Observer, {
45
59
  rescan: function(scope) {
46
60
  var key = this.Options.relName;
47
61
 
48
- ($(scope)||document).select('*[rel^="'+key+'"]').each(function(element) {
49
- if (!element._draggable) {
62
+ ($(scope)||$(document)).select('*[rel^="'+key+'"]').each(function(element) {
63
+ if (!element.draggable) {
50
64
  var data = element.get('data-'+key+'-options');
51
65
  new this(element, eval('('+data+')') || {});
52
66
  }
@@ -64,7 +78,7 @@ var Draggable = new Class(Observer, {
64
78
  this.element = $(element);
65
79
  this.$super(options);
66
80
 
67
- this.element._draggable = this.init();
81
+ this.element.draggable = this.init();
68
82
  },
69
83
 
70
84
  /**
@@ -74,7 +88,7 @@ var Draggable = new Class(Observer, {
74
88
  */
75
89
  destroy: function() {
76
90
  this.handle.stopObserving('mousedown', this._dragStart);
77
- delete(this.element._draggable);
91
+ delete(this.element.draggable);
78
92
 
79
93
  return this;
80
94
  },
@@ -112,7 +126,7 @@ var Draggable = new Class(Observer, {
112
126
  if (this.options.revertDuration && this.element.morph) {
113
127
  this.element.morph(end_style, {
114
128
  duration: this.options.revertDuration,
115
- onFinish: this.swapBack.bind(this)
129
+ onFinish: R(this.swapBack).bind(this)
116
130
  });
117
131
  } else {
118
132
  this.element.setStyle(end_style);
@@ -126,7 +140,7 @@ var Draggable = new Class(Observer, {
126
140
 
127
141
  init: function() {
128
142
  // caching the callback so that we could detach it later
129
- this._dragStart = this.dragStart.bind(this);
143
+ this._dragStart = R(this.dragStart).bind(this);
130
144
 
131
145
  this.handle.onMousedown(this._dragStart);
132
146
 
@@ -138,15 +152,15 @@ var Draggable = new Class(Observer, {
138
152
  this.fire('before', this, event.stop());
139
153
 
140
154
  // calculating the positions diff
141
- var position = position = this.element.position();
155
+ var position = this.element.position();
142
156
 
143
157
  this.xDiff = event.pageX - position.x;
144
158
  this.yDiff = event.pageY - position.y;
145
159
 
146
160
  // grabbing the relative position diffs
147
161
  var relative_position = {
148
- y: this.element.getStyle('top').toFloat(),
149
- x: this.element.getStyle('left').toFloat()
162
+ y: R(this.element.getStyle('top')).toFloat(),
163
+ x: R(this.element.getStyle('left')).toFloat()
150
164
  };
151
165
 
152
166
  this.rxDiff = isNaN(relative_position.x) ? 0 : (relative_position.x - position.x);
@@ -158,12 +172,12 @@ var Draggable = new Class(Observer, {
158
172
  y: this.element.getStyle('height')
159
173
  };
160
174
 
161
- if (size.x == 'auto') size.x = this.element.offsetWidth + 'px';
162
- if (size.y == 'auto') size.y = this.element.offsetHeight + 'px';
175
+ if (size.x == 'auto') { size.x = this.element._.offsetWidth + 'px'; }
176
+ if (size.y == 'auto') { size.y = this.element._.offsetHeight + 'px'; }
163
177
 
164
178
  // building a clone element if necessary
165
179
  if (this.options.clone || this.options.revert) {
166
- this.clone = $(this.element.cloneNode(true)).setStyle({
180
+ this.clone = new Element(this.element._.cloneNode(true)).setStyle({
167
181
  visibility: this.options.clone ? 'visible' : 'hidden'
168
182
  }).insertTo(this.element, 'before');
169
183
  }
@@ -178,14 +192,18 @@ var Draggable = new Class(Observer, {
178
192
  height: size.y
179
193
  }).addClass(this.options.dragClass);
180
194
 
181
- if (this.options.moveOut) this.element.insertTo(document.body);
195
+ if (this.options.moveOut) {
196
+ this.element.insertTo(document.body);
197
+ }
182
198
 
183
199
 
184
200
  // caching the window scrolls
185
- this.winScrolls = window.scrolls();
186
- this.winSizes = window.sizes();
201
+ this.winScrolls = $(window).scrolls();
202
+ this.winSizes = $(window).size();
187
203
 
188
204
  Draggable.current = this.calcConstraints().fire('start', this, event);
205
+
206
+ this.style = this.element._.style;
189
207
  },
190
208
 
191
209
  // catches the mouse move event
@@ -194,10 +212,10 @@ var Draggable = new Class(Observer, {
194
212
 
195
213
  // checking the range
196
214
  if (this.ranged) {
197
- if (this.minX > x) x = this.minX;
198
- if (this.maxX < x) x = this.maxX;
199
- if (this.minY > y) y = this.minY;
200
- if (this.maxY < y) y = this.maxY;
215
+ if (this.minX > x) { x = this.minX; }
216
+ if (this.maxX < x) { x = this.maxX; }
217
+ if (this.minY > y) { y = this.minY; }
218
+ if (this.maxY < y) { y = this.maxY; }
201
219
  }
202
220
 
203
221
  // checking the scrolls
@@ -217,23 +235,23 @@ var Draggable = new Class(Observer, {
217
235
  scrolls.x = page_x - this.winSizes.x + sensitivity;
218
236
  }
219
237
 
220
- if (scrolls.y < 0) scrolls.y = 0;
221
- if (scrolls.x < 0) scrolls.x = 0;
238
+ if (scrolls.y < 0) { scrolls.y = 0; }
239
+ if (scrolls.x < 0) { scrolls.x = 0; }
222
240
 
223
241
  if (scrolls.y < this.winScrolls.y || scrolls.y > this.winScrolls.y ||
224
242
  scrolls.x < this.winScrolls.x || scrolls.x > this.winScrolls.x) {
225
243
 
226
- window.scrollTo(this.winScrolls = scrolls);
244
+ $(window).scrollTo(this.winScrolls = scrolls);
227
245
  }
228
246
  }
229
247
 
230
248
  // checking the snaps
231
- if (this.snapX) x = x - x % this.snapX;
232
- if (this.snapY) y = y - y % this.snapY;
249
+ if (this.snapX) { x = x - x % this.snapX; }
250
+ if (this.snapY) { y = y - y % this.snapY; }
233
251
 
234
252
  // checking the constraints
235
- if (!this.axisY) this.element.style.left = (x + this.rxDiff) + 'px';
236
- if (!this.axisX) this.element.style.top = (y + this.ryDiff) + 'px';
253
+ if (!this.axisY) { this.style.left = (x + this.rxDiff) + 'px'; }
254
+ if (!this.axisX) { this.style.top = (y + this.ryDiff) + 'px'; }
237
255
 
238
256
  this.fire('drag', this, event);
239
257
  },
@@ -257,22 +275,22 @@ var Draggable = new Class(Observer, {
257
275
  // swaps the clone element to the actual element back
258
276
  swapBack: function() {
259
277
  if (this.clone) {
260
- this.clone.insert(
278
+ this.clone.replace(
261
279
  this.element.setStyle({
262
280
  width: this.clone.getStyle('width'),
263
281
  height: this.clone.getStyle('height'),
264
282
  position: this.clone.getStyle('position'),
265
283
  zIndex: this.clone.getStyle('zIndex') || ''
266
- }), 'before'
267
- ).remove();
284
+ })
285
+ );
268
286
  }
269
287
  },
270
288
 
271
289
  // calculates the constraints
272
290
  calcConstraints: function() {
273
291
  var axis = this.options.axis;
274
- this.axisX = ['x', 'horizontal'].include(axis);
275
- this.axisY = ['y', 'vertical'].include(axis);
292
+ this.axisX = R(['x', 'horizontal']).include(axis);
293
+ this.axisY = R(['y', 'vertical']).include(axis);
276
294
 
277
295
  this.ranged = false;
278
296
  var range = this.options.range;
@@ -281,7 +299,7 @@ var Draggable = new Class(Observer, {
281
299
 
282
300
  // if the range is defined by another element
283
301
  var element = $(range);
284
- if (isElement(element)) {
302
+ if (element instanceof Element) {
285
303
  var dims = element.dimensions();
286
304
 
287
305
  range = {
@@ -291,7 +309,7 @@ var Draggable = new Class(Observer, {
291
309
  }
292
310
 
293
311
  if (isHash(range)) {
294
- var size = this.element.sizes();
312
+ var size = this.element.size();
295
313
 
296
314
  if (range.x) {
297
315
  this.minX = range.x[0];
@@ -307,10 +325,11 @@ var Draggable = new Class(Observer, {
307
325
  return this;
308
326
  }
309
327
  });
328
+
310
329
  /**
311
330
  * Droppable unit
312
331
  *
313
- * Copyright (C) 2009-2010 Nikolay V. Nemshilov
332
+ * Copyright (C) 2009-2010 Nikolay Nemshilov
314
333
  */
315
334
  var Droppable = new Class(Observer, {
316
335
  extend: {
@@ -330,7 +349,7 @@ var Droppable = new Class(Observer, {
330
349
  },
331
350
 
332
351
  // See the Draggable rescan method, case we're kinda hijacking it in here
333
- rescan: eval('({f:'+Draggable.rescan.toString().replace(/\._draggable/g, '._droppable')+'})').f,
352
+ rescan: eval('['+Draggable.rescan.toString().replace(/\.draggable/g, '.droppable')+']')[0],
334
353
 
335
354
  /**
336
355
  * Checks for hoverting draggable
@@ -339,8 +358,9 @@ var Droppable = new Class(Observer, {
339
358
  * @param Draggable draggable
340
359
  */
341
360
  checkHover: function(event, draggable) {
342
- for (var i=0, length = this.active.length; i < length; i++)
361
+ for (var i=0, length = this.active.length; i < length; i++) {
343
362
  this.active[i].checkHover(event, draggable);
363
+ }
344
364
  },
345
365
 
346
366
  /**
@@ -350,8 +370,9 @@ var Droppable = new Class(Observer, {
350
370
  * @param Draggable draggable
351
371
  */
352
372
  checkDrop: function(event, draggable) {
353
- for (var i=0, length = this.active.length; i < length; i++)
373
+ for (var i=0, length = this.active.length; i < length; i++) {
354
374
  this.active[i].checkDrop(event, draggable);
375
+ }
355
376
  },
356
377
 
357
378
  active: []
@@ -377,7 +398,7 @@ var Droppable = new Class(Observer, {
377
398
  */
378
399
  destroy: function() {
379
400
  Droppable.active = Droppable.active.without(this);
380
- delete(this.element._droppable);
401
+ delete(this.element.droppable);
381
402
  return this;
382
403
  },
383
404
 
@@ -489,7 +510,7 @@ var Droppable = new Class(Observer, {
489
510
  // checks if the object accepts the draggable
490
511
  allows: function(draggable) {
491
512
  if (this.options.containment && !this._scanned) {
492
- this.options.containment.walk($);
513
+ this.options.containment = R(this.options.containment).map($);
493
514
  this._scanned = true;
494
515
  }
495
516
 
@@ -500,12 +521,13 @@ var Droppable = new Class(Observer, {
500
521
  }
501
522
 
502
523
  });
524
+
503
525
  /**
504
526
  * The document events hooker
505
527
  *
506
- * Copyright (C) 2009-2010 Nikolay V. Nemshilov
528
+ * Copyright (C) 2009-2010 Nikolay Nemshilov
507
529
  */
508
- document.on({
530
+ $(document).on({
509
531
  // parocesses the automatically discovered elements
510
532
  ready: function() {
511
533
  Draggable.rescan();
@@ -514,7 +536,7 @@ document.on({
514
536
 
515
537
  // watch the draggables moving arond
516
538
  mousemove: function(event) {
517
- if (Draggable.current) {
539
+ if (Draggable.current !== null) {
518
540
  Draggable.current.dragProcess(event);
519
541
  Droppable.checkHover(event, Draggable.current);
520
542
  }
@@ -522,15 +544,16 @@ document.on({
522
544
 
523
545
  // releases the current draggable on mouse up
524
546
  mouseup: function(event) {
525
- if (Draggable.current) {
547
+ if (Draggable.current !== null) {
526
548
  Draggable.current.dragStop(event);
527
549
  }
528
550
  }
529
551
  });
552
+
530
553
  /**
531
554
  * Element level hooks for drag'n'drops
532
555
  *
533
- * Copyright (C) 2009-2010 Nikolay V. Nemshilov
556
+ * Copyright (C) 2009-2010 Nikolay Nemshilov
534
557
  */
535
558
  Element.include({
536
559
 
@@ -540,7 +563,10 @@ Element.include({
540
563
  },
541
564
 
542
565
  undoDraggable: function() {
543
- if (this._draggable) this._draggable.destroy();
566
+ if ('draggable' in this) {
567
+ this.draggable.destroy();
568
+ }
569
+
544
570
  return this;
545
571
  },
546
572
 
@@ -550,7 +576,15 @@ Element.include({
550
576
  },
551
577
 
552
578
  undoDroppable: function() {
553
- if (this._droppable) this._droppable.destroy();
579
+ if ('droppable' in this) {
580
+ this.droppable.destroy();
581
+ }
582
+
554
583
  return this;
555
584
  }
556
- });
585
+
586
+ });
587
+
588
+ window.Draggable = RightJS.Draggable = Draggable;
589
+ window.Droppable = RightJS.Droppable = Droppable;
590
+ })(window, document, RightJS);
@@ -0,0 +1,20 @@
1
+ /**
2
+ * Drag'n'Drop module for RightJS
3
+ * http://rightjs.org/plugins/drag-n-drop
4
+ *
5
+ * Copyright (C) 2009-2010 Nikolay Nemshilov
6
+ */
7
+ (function(q,r,f){var k=f.$,t=f.$w,u=f.Class,w=f.isHash,x=f.isArray,s=f.Element,v=f.Observer,j=new u(v,{extend:{EVENTS:t("before start drag stop drop"),Options:{handle:null,snap:0,axis:null,range:null,dragClass:"dragging",clone:false,revert:false,revertDuration:"normal",scroll:true,scrollSensitivity:32,zIndex:1E7,moveOut:false,relName:"draggable"},current:null,rescan:function(a){var c=this.Options.relName;(k(a)||k(r)).select('*[rel^="'+c+'"]').each(function(b){if(!b.draggable){var e=b.get("data-"+
8
+ c+"-options");new this(b,eval("("+e+")")||{})}},this)}},initialize:function(a,c){this.element=k(a);this.$super(c);this.element.draggable=this.init()},destroy:function(){this.handle.stopObserving("mousedown",this._dragStart);delete this.element.draggable;return this},setOptions:function(a){this.$super(a);this.handle=this.options.handle?k(this.options.handle):this.element;if(x(this.options.snap)){this.snapX=this.options.snap[0];this.snapY=this.options.snap[1]}else this.snapX=this.snapY=this.options.snap;
9
+ return this},revert:function(){var a=this.clone.position();a={top:a.y+this.ryDiff+"px",left:a.x+this.rxDiff+"px"};if(this.options.revertDuration&&this.element.morph)this.element.morph(a,{duration:this.options.revertDuration,onFinish:f(this.swapBack).bind(this)});else{this.element.setStyle(a);this.swapBack()}return this},init:function(){this._dragStart=f(this.dragStart).bind(this);this.handle.onMousedown(this._dragStart);return this},dragStart:function(a){this.fire("before",this,a.stop());var c=this.element.position();
10
+ this.xDiff=a.pageX-c.x;this.yDiff=a.pageY-c.y;var b={y:f(this.element.getStyle("top")).toFloat(),x:f(this.element.getStyle("left")).toFloat()};this.rxDiff=isNaN(b.x)?0:b.x-c.x;this.ryDiff=isNaN(b.y)?0:b.y-c.y;b={x:this.element.getStyle("width"),y:this.element.getStyle("height")};if(b.x=="auto")b.x=this.element._.offsetWidth+"px";if(b.y=="auto")b.y=this.element._.offsetHeight+"px";if(this.options.clone||this.options.revert)this.clone=(new s(this.element._.cloneNode(true))).setStyle({visibility:this.options.clone?
11
+ "visible":"hidden"}).insertTo(this.element,"before");this.element.setStyle({position:"absolute",zIndex:j.Options.zIndex++,top:c.y+this.ryDiff+"px",left:c.x+this.rxDiff+"px",width:b.x,height:b.y}).addClass(this.options.dragClass);this.options.moveOut&&this.element.insertTo(r.body);this.winScrolls=k(q).scrolls();this.winSizes=k(q).size();j.current=this.calcConstraints().fire("start",this,a);this.style=this.element._.style},dragProcess:function(a){var c=a.pageX,b=a.pageY,e=c-this.xDiff,h=b-this.yDiff;
12
+ if(this.ranged){if(this.minX>e)e=this.minX;if(this.maxX<e)e=this.maxX;if(this.minY>h)h=this.minY;if(this.maxY<h)h=this.maxY}if(this.options.scroll){var d={x:this.winScrolls.x,y:this.winScrolls.y},g=this.options.scrollSensitivity;if(b-d.y<g)d.y=b-g;else if(d.y+this.winSizes.y-b<g)d.y=b-this.winSizes.y+g;if(c-d.x<g)d.x=c-g;else if(d.x+this.winSizes.x-c<g)d.x=c-this.winSizes.x+g;if(d.y<0)d.y=0;if(d.x<0)d.x=0;if(d.y<this.winScrolls.y||d.y>this.winScrolls.y||d.x<this.winScrolls.x||d.x>this.winScrolls.x)k(q).scrollTo(this.winScrolls=
13
+ d)}if(this.snapX)e-=e%this.snapX;if(this.snapY)h-=h%this.snapY;if(!this.axisY)this.style.left=e+this.rxDiff+"px";if(!this.axisX)this.style.top=h+this.ryDiff+"px";this.fire("drag",this,a)},dragStop:function(a){this.element.removeClass(this.options.dragClass);n.checkDrop(a,this);this.options.revert&&this.revert();j.current=null;this.fire("stop",this,a)},swapBack:function(){if(this.clone)this.clone.replace(this.element.setStyle({width:this.clone.getStyle("width"),height:this.clone.getStyle("height"),
14
+ position:this.clone.getStyle("position"),zIndex:this.clone.getStyle("zIndex")||""}))},calcConstraints:function(){var a=this.options.axis;this.axisX=f(["x","horizontal"]).include(a);this.axisY=f(["y","vertical"]).include(a);this.ranged=false;if(a=this.options.range){this.ranged=true;var c=k(a);if(c instanceof s){a=c.dimensions();a={x:[a.left,a.left+a.width],y:[a.top,a.top+a.height]}}if(w(a)){c=this.element.size();if(a.x){this.minX=a.x[0];this.maxX=a.x[1]-c.x}if(a.y){this.minY=a.y[0];this.maxY=a.y[1]-
15
+ c.y}}}return this}}),n=new u(v,{extend:{EVENTS:t("drop hover leave"),Options:{accept:"*",containment:null,overlap:null,overlapSize:0.5,allowClass:"droppable-allow",denyClass:"droppable-deny",relName:"droppable"},rescan:eval("["+j.rescan.toString().replace(/\.draggable/g,".droppable")+"]")[0],checkHover:function(a,c){for(var b=0,e=this.active.length;b<e;b++)this.active[b].checkHover(a,c)},checkDrop:function(a,c){for(var b=0,e=this.active.length;b<e;b++)this.active[b].checkDrop(a,c)},active:[]},initialize:function(a,
16
+ c){this.element=k(a);this.$super(c);n.active.push(this.element._droppable=this)},destroy:function(){n.active=n.active.without(this);delete this.element.droppable;return this},checkHover:function(a,c){if(this.hoveredBy(a,c)){if(!this._hovered){this._hovered=true;this.element.addClass(this.options[this.allows(c)?"allowClass":"denyClass"]);this.fire("hover",c,this,a)}}else if(this._hovered){this._hovered=false;this.reset().fire("leave",c,this,a)}},checkDrop:function(a,c){this.reset();if(this.hoveredBy(a,
17
+ c)&&this.allows(c)){c.fire("drop",this,c,a);this.fire("drop",c,this,a)}},reset:function(){this.element.removeClass(this.options.allowClass).removeClass(this.options.denyClass);return this},hoveredBy:function(a,c){var b=this.element.dimensions(),e=b.top,h=b.left,d=b.left+b.width,g=b.top+b.height,l=a.pageX,m=a.pageY;if(this.options.overlap){var i=c.element.dimensions();l=this.options.overlapSize;m=i.top;var o=i.left,p=i.left+i.width;i=i.top+i.height;switch(this.options.overlap){case "x":case "horizontal":return(m>
18
+ e&&m<g||i>e&&i<g)&&(o>h&&o<d-b.width*l||p<d&&p>h+b.width*l);case "y":case "vertical":return(o>h&&o<d||p>h&&p<d)&&(m>e&&m<g-b.height*l||i<g&&i>e+b.height*l);default:return(o>h&&o<d-b.width*l||p<d&&p>h+b.width*l)&&(m>e&&m<g-b.height*l||i<g&&i>e+b.height*l)}}else return l>h&&l<d&&m>e&&m<g},allows:function(a){if(this.options.containment&&!this._scanned){this.options.containment=f(this.options.containment).map(k);this._scanned=true}return(this.options.containment?this.options.containment.includes(a.element):
19
+ true)&&(this.options.accept=="*"?true:a.element.match(this.options.accept))}});k(r).on({ready:function(){j.rescan();n.rescan()},mousemove:function(a){if(j.current!==null){j.current.dragProcess(a);n.checkHover(a,j.current)}},mouseup:function(a){j.current!==null&&j.current.dragStop(a)}});s.include({makeDraggable:function(a){new j(this,a);return this},undoDraggable:function(){"draggable"in this&&this.draggable.destroy();return this},makeDroppable:function(a){new n(this,a);return this},undoDroppable:function(){"droppable"in
20
+ this&&this.droppable.destroy();return this}});q.Draggable=f.Draggable=j;q.Droppable=f.Droppable=n})(window,document,RightJS);