right-rails 1.2.2 → 1.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (131) hide show
  1. data/CHANGELOG +7 -0
  2. data/README.rdoc +1 -1
  3. data/Rakefile +1 -1
  4. data/init.rb +1 -0
  5. data/lib/generators/right_rails/right_rails_generator.rb +15 -6
  6. data/lib/right_rails.rb +1 -1
  7. data/lib/right_rails/controller_extensions.rb +28 -15
  8. data/lib/right_rails/helpers/misc.rb +38 -38
  9. data/lib/right_rails/helpers/rails.rb +50 -7
  10. data/lib/rjs_renderer.rb +26 -0
  11. data/spec/lib/right_rails/controller_extensions_spec.rb +25 -14
  12. data/spec/lib/right_rails/helpers/forms_spec.rb +6 -6
  13. data/spec/lib/right_rails/helpers/rails_spec.rb +44 -45
  14. data/vendor/assets/images/rightjs-ui/rte.png +0 -0
  15. data/vendor/assets/javascripts/right-safe-src.js +2 -2
  16. data/vendor/assets/javascripts/right-safe.js +2 -2
  17. data/vendor/assets/javascripts/right-src.js +386 -100
  18. data/vendor/assets/javascripts/right.js +2 -2
  19. data/vendor/assets/javascripts/right/calendar-src.js +19 -3
  20. data/vendor/assets/javascripts/right/calendar.js +2 -2
  21. data/vendor/assets/javascripts/right/colorpicker-src.js +59 -20
  22. data/vendor/assets/javascripts/right/colorpicker.js +2 -2
  23. data/vendor/assets/javascripts/right/i18n/de.js +43 -42
  24. data/vendor/assets/javascripts/right/i18n/es.js +1 -0
  25. data/vendor/assets/javascripts/right/i18n/fi.js +1 -0
  26. data/vendor/assets/javascripts/right/i18n/fr.js +1 -0
  27. data/vendor/assets/javascripts/right/i18n/hu.js +1 -0
  28. data/vendor/assets/javascripts/right/i18n/it.js +1 -0
  29. data/vendor/assets/javascripts/right/i18n/jp.js +1 -0
  30. data/vendor/assets/javascripts/right/i18n/lt.js +96 -0
  31. data/vendor/assets/javascripts/right/i18n/nl.js +1 -0
  32. data/vendor/assets/javascripts/right/i18n/pt-br.js +1 -0
  33. data/vendor/assets/javascripts/right/i18n/ru.js +1 -0
  34. data/vendor/assets/javascripts/right/i18n/ua.js +1 -0
  35. data/vendor/assets/javascripts/right/jquerysh-src.js +4 -4
  36. data/vendor/assets/javascripts/right/jquerysh.js +2 -2
  37. data/vendor/assets/javascripts/right/rails-src.js +51 -15
  38. data/vendor/assets/javascripts/right/rails.js +2 -2
  39. data/vendor/assets/javascripts/right/resizable-src.js +11 -11
  40. data/vendor/assets/javascripts/right/rte-src.js +33 -13
  41. data/vendor/assets/javascripts/right/rte.js +2 -2
  42. data/vendor/assets/javascripts/right/slider-src.js +137 -28
  43. data/vendor/assets/javascripts/right/slider.js +2 -2
  44. metadata +24 -126
  45. data/generators/right_rails/right_rails_generator.rb +0 -46
  46. data/generators/right_rails/templates/iframed.html.erb +0 -10
  47. data/generators/right_scaffold/right_scaffold_generator.rb +0 -53
  48. data/generators/right_scaffold/templates/controller.rb +0 -99
  49. data/generators/right_scaffold/templates/helper.rb +0 -2
  50. data/generators/right_scaffold/templates/layout.html.erb +0 -18
  51. data/generators/right_scaffold/templates/style.css +0 -54
  52. data/generators/right_scaffold/templates/view__form.html.erb +0 -16
  53. data/generators/right_scaffold/templates/view__item.html.erb +0 -13
  54. data/generators/right_scaffold/templates/view_edit.html.erb +0 -6
  55. data/generators/right_scaffold/templates/view_index.html.erb +0 -9
  56. data/generators/right_scaffold/templates/view_new.html.erb +0 -5
  57. data/generators/right_scaffold/templates/view_show.html.erb +0 -10
  58. data/lib/generators/right_rails/templates/iframed.html.erb +0 -10
  59. data/public/images/rightjs-ui/colorpicker.png +0 -0
  60. data/public/images/rightjs-ui/resizable.png +0 -0
  61. data/public/images/rightjs-ui/rte.png +0 -0
  62. data/public/javascripts/right-olds-src.js +0 -652
  63. data/public/javascripts/right-olds.js +0 -9
  64. data/public/javascripts/right-safe-src.js +0 -68
  65. data/public/javascripts/right-safe.js +0 -7
  66. data/public/javascripts/right-src.js +0 -6014
  67. data/public/javascripts/right.js +0 -7
  68. data/public/javascripts/right/autocompleter-src.js +0 -625
  69. data/public/javascripts/right/autocompleter.js +0 -7
  70. data/public/javascripts/right/billboard-src.js +0 -564
  71. data/public/javascripts/right/billboard.js +0 -7
  72. data/public/javascripts/right/calendar-src.js +0 -1464
  73. data/public/javascripts/right/calendar.js +0 -7
  74. data/public/javascripts/right/casting-src.js +0 -183
  75. data/public/javascripts/right/casting.js +0 -7
  76. data/public/javascripts/right/colorpicker-src.js +0 -981
  77. data/public/javascripts/right/colorpicker.js +0 -7
  78. data/public/javascripts/right/dialog-src.js +0 -768
  79. data/public/javascripts/right/dialog.js +0 -7
  80. data/public/javascripts/right/dnd-src.js +0 -591
  81. data/public/javascripts/right/dnd.js +0 -7
  82. data/public/javascripts/right/effects-src.js +0 -508
  83. data/public/javascripts/right/effects.js +0 -7
  84. data/public/javascripts/right/i18n/de.js +0 -95
  85. data/public/javascripts/right/i18n/en-us.js +0 -11
  86. data/public/javascripts/right/i18n/es.js +0 -95
  87. data/public/javascripts/right/i18n/fi.js +0 -96
  88. data/public/javascripts/right/i18n/fr.js +0 -95
  89. data/public/javascripts/right/i18n/hu.js +0 -100
  90. data/public/javascripts/right/i18n/it.js +0 -95
  91. data/public/javascripts/right/i18n/jp.js +0 -99
  92. data/public/javascripts/right/i18n/nl.js +0 -95
  93. data/public/javascripts/right/i18n/pt-br.js +0 -95
  94. data/public/javascripts/right/i18n/ru.js +0 -95
  95. data/public/javascripts/right/i18n/ua.js +0 -99
  96. data/public/javascripts/right/in-edit-src.js +0 -373
  97. data/public/javascripts/right/in-edit.js +0 -7
  98. data/public/javascripts/right/jquerysh-src.js +0 -362
  99. data/public/javascripts/right/jquerysh.js +0 -7
  100. data/public/javascripts/right/json-src.js +0 -147
  101. data/public/javascripts/right/json.js +0 -7
  102. data/public/javascripts/right/keys-src.js +0 -87
  103. data/public/javascripts/right/keys.js +0 -7
  104. data/public/javascripts/right/lightbox-src.js +0 -931
  105. data/public/javascripts/right/lightbox.js +0 -7
  106. data/public/javascripts/right/rails-src.js +0 -402
  107. data/public/javascripts/right/rails.js +0 -7
  108. data/public/javascripts/right/rater-src.js +0 -384
  109. data/public/javascripts/right/rater.js +0 -7
  110. data/public/javascripts/right/resizable-src.js +0 -465
  111. data/public/javascripts/right/resizable.js +0 -7
  112. data/public/javascripts/right/rte-src.js +0 -2685
  113. data/public/javascripts/right/rte.js +0 -7
  114. data/public/javascripts/right/selectable-src.js +0 -725
  115. data/public/javascripts/right/selectable.js +0 -7
  116. data/public/javascripts/right/sizzle-src.js +0 -1132
  117. data/public/javascripts/right/sizzle.js +0 -7
  118. data/public/javascripts/right/slider-src.js +0 -395
  119. data/public/javascripts/right/slider.js +0 -7
  120. data/public/javascripts/right/sortable-src.js +0 -430
  121. data/public/javascripts/right/sortable.js +0 -7
  122. data/public/javascripts/right/table-src.js +0 -176
  123. data/public/javascripts/right/table.js +0 -7
  124. data/public/javascripts/right/tabs-src.js +0 -1157
  125. data/public/javascripts/right/tabs.js +0 -7
  126. data/public/javascripts/right/tags-src.js +0 -745
  127. data/public/javascripts/right/tags.js +0 -7
  128. data/public/javascripts/right/tooltips-src.js +0 -331
  129. data/public/javascripts/right/tooltips.js +0 -7
  130. data/public/javascripts/right/uploader-src.js +0 -302
  131. data/public/javascripts/right/uploader.js +0 -7
@@ -1,7 +0,0 @@
1
- /**
2
- * RightJS-UI Dialog v2.2.0
3
- * http://rightjs.org/ui/dialog
4
- *
5
- * Copyright (C) 2010-2011 Nikolay Nemshilov
6
- */
7
- var Dialog=RightJS.Dialog=function(a){function b(b,c){c||(c=b,b="DIV");var d=new a.Class(a.Element.Wrappers[b]||a.Element,{initialize:function(c,d){this.key=c;var e=[{"class":"rui-"+c}];this instanceof a.Input||this instanceof a.Form||e.unshift(b),this.$super.apply(this,e),a.isString(d)&&(d=a.$(d)),d instanceof a.Element&&(this._=d._,"$listeners"in d&&(d.$listeners=d.$listeners),d={}),this.setOptions(d,this);return a.Wrapper.Cache[a.$uid(this._)]=this},setOptions:function(b,c){c&&(b=a.Object.merge(b,(new Function("return "+(c.get("data-"+this.key)||"{}")))())),b&&a.Options.setOptions.call(this,a.Object.merge(this.options,b));return this}}),e=new a.Class(d,c);a.Observer.createShortcuts(e.prototype,e.EVENTS||a([]));return e}var c=new a.Class(a.Element,{initialize:function(a,b){this.$super("div",b),this._.innerHTML=a,this.addClass("rui-button"),this.on("selectstart","stopEvent")},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}}),d=new a.Class(a.Element,{initialize:function(b){this.$super("div",{"class":"rui-spinner"}),this.dots=[];for(var c=0;c<(b||4);c++)this.dots.push(new a.Element("div"));this.dots[0].addClass("glowing"),this.insert(this.dots),a(this.shift).bind(this).periodical(300)},shift:function(){if(this.visible()){var a=this.dots.pop();this.dots.unshift(a),this.insert(a,"top")}}}),e=a,f=a.$,g=a.$w,h=a.$E,i=a.Class,j=a.Object,k=a.Element,l=new b({extend:{version:"2.2.0",EVENTS:g("ok cancel help expand collapse resize load"),Options:{lockScreen:!0,fxDuration:"short",draggable:!0,closeable:!0,expandable:!1,showHelp:!1,showIcon:null,title:null,html:null,url:null},i18n:{Ok:"Ok",Close:"Close",Cancel:"Cancel",Help:"Help",Expand:"Expand",Collapse:"Collapse",Alert:"Warning!",Confirm:"Confirm",Prompt:"Enter"},current:!1,dragged:!1},initialize:function(a){this.$super("dialog",a).append(this.head=new l.Head(this),this.body=new l.Body(this),this.foot=new l.Foot(this)).onCancel(this.hide),this.locker=h("div",{"class":"rui-screen-locker"}),this.options.title&&this.title(this.options.title),this.options.html&&this.html(this.options.html),this.options.url&&this.load(this.options.url)},show:function(){this.options.lockScreen&&this.locker.insertTo(document.body),this.setStyle("visibility:hidden").insertTo(document.body).resize().setStyle("visibility:visible;opacity:0"),this.options.fxDuration?this.morph({opacity:1},{duration:this.options.fxDuration}):this.setStyle("opacity:1");return l.current=this},hide:function(){this.locker.remove(),this.remove(),l.current=!1;return this},resize:function(){arguments.length&&this.$super.apply(this,arguments);var a=this.size(),b=f(window).size();this.expanded&&(a.x=b.x-20,a.y=b.y-10,this.$super.call(this,a)),this.setStyle({top:(b.y-a.y)/2+f(window).scrolls().y+"px",left:(b.x-a.x-16)/2+"px"});return this.fire("resize")},title:function(a){if(arguments.length){this.head.title.html(a);return this}return this.head.title.html()},update:function(a){this.body.update(a);return this.resize()},html:function(){return arguments.length?this.$super.apply(this,arguments):this.body.html()},load:function(a,b){this.show(),this.body.load(a,b);return this},expand:function(){this.expanded||(this._prevSize=this.size(),this.resize({x:f(window).size().x-20,y:f(window).size().y-10}),this.expanded=!0,this.fire("expand"));return this},collapse:function(){this.expanded&&(this.expanded=!1,this.resize(this._prevSize),this.fire("collapse"));return this}});l.Head=new i(k,{initialize:function(a){this.dialog=a,this.options=a.options,this.$super("div",{"class":"rui-dialog-head"}),this.append(this.icon=h("div",{"class":"icon"}),this.title=h("div",{"class":"title",html:"&nbsp;"}),this.tools=h("div",{"class":"tools"})),this.fsButton=h("div",{"class":"expand",html:"&equiv;",title:l.i18n.Expand}).onClick(function(){a.expanded?(a.collapse(),this.html("&equiv;").set("title",l.i18n.Expand)):(a.expand(),this.html("_").set("title",l.i18n.Collapse))}),this.closeButton=h("div",{"class":"close",html:"&times;",title:l.i18n.Close}).onClick(function(){a.fire("cancel")}),this.options.expandable&&this.tools.insert(this.fsButton),this.options.closeable&&this.tools.insert(this.closeButton),this.on({selectstart:function(a){a.stop()},mousedown:this.dragStart}),this.options.draggable||this.dialog.addClass("rui-dialog-nodrag")},dragStart:function(a){if(this.options.draggable&&!a.find("div.tools div")){var b=this.dialog.dimensions(),c=a.position();this.xDiff=b.left-c.x,this.yDiff=b.top-c.y,this.maxX=f(window).size().x-b.width-20,this.dlgStyle=this.dialog.get("style"),l.dragged=this.dialog,a.stop()}},dragMove:function(a){var b=a.position(),c=b.x+this.xDiff,d=b.y+this.yDiff;c<0?c=0:c>this.maxX&&(c=this.maxX),d<0&&(d=0),this.dlgStyle.top=d+"px",this.dlgStyle.left=c+"px"},dragStop:function(a){l.dragged=!1}}),l.Body=new i(k,{initialize:function(a){this.dialog=a,this.options=a.options,this.$super("div",{"class":"rui-dialog-body"}),this.locker=h("div",{"class":"rui-dialog-body-locker"}).insert(new d)},load:function(a,b){this.insert(this.locker,"top"),this.xhr=(new Xhr(a,j.merge({method:"get"},b))).onComplete(e(function(a){this.update(a.text),this.dialog.resize().fire("load")}).bind(this)).send();return this},update:function(a){this.$super(a),this.options.showIcon&&this.insert('<div class="rui-dialog-body-icon">'+this.options.showIcon+"</div>","top");return this}}),l.Foot=new i(k,{initialize:function(a){this.$super("div",{"class":"rui-dialog-foot"}),this.dialog=a,a.okButton=(new c(l.i18n.Ok,{"class":"ok"})).onClick(function(){a.fire("ok")}),a.helpButton=(new c(l.i18n.Help,{"class":"help"})).onClick(function(){a.fire("help")}),a.cancelButton=(new c(l.i18n.Cancel,{"class":"cancel"})).onClick(function(){a.fire("cancel")}),a.options.showHelp&&this.insert(a.helpButton),a.options.closeable&&this.insert(a.cancelButton),this.insert(a.okButton)}}),l.Alert=new i(l,{initialize:function(a){a=j.merge({showIcon:"!",title:l.i18n.Alert},a),this.$super(a),this.addClass("rui-dialog-alert"),this.on("ok","hide")}}),l.Confirm=new i(l,{initialize:function(a){a=j.merge({showIcon:"?",title:l.i18n.Confirm},a),this.$super(a),this.addClass("rui-dialog-confirm"),this.on("ok","hide")}}),l.Prompt=new i(l,{initialize:function(b){b=j.merge({showIcon:"&#x27A5;",title:l.i18n.Prompt,label:l.i18n.Prompt},b),this.$super(b),this.addClass("rui-dialog-prompt"),this.html([h("label",{html:this.options.label}),this.input=new a.Input(this.options.input||{})]),this.input.get("type")!=="textarea"&&this.input.onKeydown(e(function(a){a.keyCode===13&&this.fire("ok")}).bind(this))},show:function(){this.$super.apply(this,arguments),this.input.select();return this}}),f(document).on({keydown:function(a){a.keyCode===27&&l.current?l.current.options.closeable&&l.current.fire("cancel"):a.keyCode===13&&l.current&&(l.current instanceof l.Prompt||(a.stop(),l.current.fire("ok")))},mousemove:function(a){l.dragged&&l.dragged.head.dragMove(a)},mouseup:function(a){l.dragged&&l.dragged.head.dragStop(a)}}),f(window).onResize(function(){l.current&&l.current.resize()});var m=document.createElement("style"),n=document.createTextNode("*.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-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-screen-locker{position:fixed;top:0;left:0;width:100%;height:100%;margin:0;padding:0;background:#000;opacity:.5;filter:alpha(opacity=50);z-index:99999;cursor:default}div.rui-dialog{position:absolute;z-index:99999;background:white;margin:0;padding:0;padding-top:2.5em;padding-bottom:2.8em;border-radius:.35em;-moz-border-radius:.35em;-webkit-border-radius:.35em;border:1px solid #ccc}div.rui-dialog-body{min-width:20em;min-height:4.5em;margin:0;padding:0 1em;height:100%;overflow:auto;position:relative}div.rui-dialog-body-locker{position:absolute;z-index:9999;left:0;top:0;width:100%;height:100%;text-align:center;opacity:.6;filter:alpha(opacity=60)}div.rui-dialog-body-locker div.rui-spinner{border:none;background:none;font-size:150%;margin-top:8%}div.rui-dialog-body-icon{float:left;background:#eee;font-size:360%;font-family:Arial;border:2px solid gray;border-radius:.1em;-moz-border-radius:.1em;-webkit-border-radius:.1em;width:1em;line-height:1em;text-align:center;margin-right:.2em;margin-top:.05em;cursor:default;user-select:none;-moz-user-select:none;-webkit-user-select:none}div.rui-dialog-head{position:absolute;top:0;left:0;margin:0;padding:0;width:100%;line-height:2em;background:#ccc;border-radius:.35em;-moz-border-radius:.35em;-webkit-border-radius:.35em;border-bottom-left-radius:0;border-bottom-right-radius:0;-moz-border-radius-bottomleft:0;-moz-border-radius-bottomright:0;-webkit-border-bottom-left-radius:0;-webkit-border-bottom-right-radius:0;cursor:move;user-select:none;-moz-user-select:none;-webkit-user-select:none}div.rui-dialog-head div.icon{float:left;height:1.4em;width:1.4em;margin-left:1em;margin-top:.3em;margin-right:.3em;display:none}div.rui-dialog-head div.title{margin-left:1em;color:#444}div.rui-dialog-head div.tools{position:absolute;right:.3em;top:.3em}div.rui-dialog-head div.tools div{float:left;width:1.4em;line-height:1.4em;text-align:center;margin-left:.15em;cursor:pointer;background:#aaa;border-radius:.2em;-moz-border-radius:.2em;-webkit-border-radius:.2em;font-family:Verdana;opacity:.6;filter:alpha(opacity=60)}div.rui-dialog-head div.tools div:hover{opacity:1;filter:alpha(opacity=100);box-shadow:#444 0 0 .1em;-moz-box-shadow:#444 0 0 .1em;-webkit-box-shadow:#444 0 0 .1em}div.rui-dialog-head div.tools div.close:hover{background:#daa}div.rui-dialog-nodrag div.rui-dialog-head{cursor:default}div.rui-dialog-foot{position:absolute;bottom:0;left:0;width:100%;text-align:right}div.rui-dialog-foot div.rui-button{margin:.6em 1em;background:#eee;width:4em}div.rui-dialog-foot div.help{float:left}div.rui-dialog-foot div.cancel{margin-right:-.5em}div.rui-dialog-foot div.ok:hover{background-color:#ded}div.rui-dialog-foot div.cancel:hover{background-color:#ecc}div.rui-dialog-alert div.rui-dialog-foot{text-align:center}div.rui-dialog-alert div.rui-dialog-foot div.cancel{display:none}div.rui-dialog-alert div.rui-dialog-body-icon{color:brown;background:#FEE;border-color:brown}div.rui-dialog-confirm div.rui-dialog-body-icon{color:#44A;background:#EEF;border-color:#44a}div.rui-dialog-prompt div.rui-dialog-body-icon{color:#333}div.rui-dialog-prompt div.rui-dialog-body label{display:block;font-weight:bold;font-size:120%;color:#444;margin-bottom:.5em}div.rui-dialog-prompt div.rui-dialog-body input,div.rui-dialog-prompt div.rui-dialog-body textarea{border:1px solid #aaa;font-size:1em;display:block;width:16em;margin:0;padding:.2em;margin-left:4.7em;border-radius:.2em;-moz-border-radius:.2em;-webkit-border-radius:.2em;outline:none}div.rui-dialog-prompt div.rui-dialog-body textarea{width:24em;height:8em}");m.type="text/css",document.getElementsByTagName("head")[0].appendChild(m),m.styleSheet?m.styleSheet.cssText=n.nodeValue:m.appendChild(n);return l}(RightJS)
@@ -1,591 +0,0 @@
1
- /**
2
- * Drag'n'Drop module v2.2.2
3
- * http://rightjs.org/plugins/drag-n-drop
4
- *
5
- * Copyright (C) 2009-2011 Nikolay Nemshilov
6
- */
7
- (function(window, document, RightJS) {
8
- /**
9
- * The DND module initialization script
10
- *
11
- * Copyright (C) 2010 Nikolay Nemshilov
12
- */
13
- var R = RightJS,
14
- $ = RightJS.$,
15
- $w = RightJS.$w,
16
- Class = RightJS.Class,
17
- isHash = RightJS.isHash,
18
- isArray = RightJS.isArray,
19
- Element = RightJS.Element,
20
- Observer = RightJS.Observer;
21
-
22
-
23
-
24
- /**
25
- * Draggable unit
26
- *
27
- * Copyright (C) 2009-2011 Nikolay Nemshilov
28
- */
29
- var Draggable = new Class(Observer, {
30
- extend: {
31
- version: '2.2.2',
32
-
33
- EVENTS: $w('before start drag stop drop'),
34
-
35
- Options: {
36
- handle: null, // a handle element that will start the drag
37
-
38
- snap: 0, // a number in pixels or [x,y]
39
- axis: null, // null or 'x' or 'y' or 'vertical' or 'horizontal'
40
- range: null, // {x: [min, max], y:[min, max]} or reference to another element
41
-
42
- dragClass: 'dragging', // the in-process class name
43
-
44
- clone: false, // if should keep a clone in place
45
- revert: false, // marker if the object should be moved back on finish
46
- revertDuration: 'normal', // the moving back fx duration
47
-
48
- scroll: true, // if it should automatically scroll
49
- scrollSensitivity: 32, // the scrolling area size in pixels
50
-
51
- zIndex: 10000000, // the element's z-index
52
- moveOut: false, // marker if the draggable should be moved out of it's context (for overflown elements)
53
-
54
- relName: 'draggable' // the audodiscovery feature key
55
- },
56
-
57
- // referenece to the currently active draggable
58
- current: null,
59
-
60
- // scans the document for auto-processed draggables with the rel="draggable" attribute
61
- rescan: function(scope) {
62
- var key = this.Options.relName, ref = this === Draggable ? 'draggable' : 'droppable';
63
-
64
- ($(scope)||$(document)).find('*[rel^="'+key+'"]').each(function(element) {
65
- if (!element[ref]) {
66
- new this(element, new Function('return '+element.get('data-'+key))() || {});
67
- }
68
- }, this);
69
- }
70
- },
71
-
72
- /**
73
- * Basic controller
74
- *
75
- * @param mixed element reference
76
- * @param Object options
77
- */
78
- initialize: function(element, options) {
79
- this.element = $(element);
80
- this.$super(options);
81
-
82
- this._dragStart = R(this.dragStart).bind(this);
83
- this.handle.onMousedown(this._dragStart);
84
-
85
- this.element.draggable = this;
86
- },
87
-
88
- /**
89
- * detaches the mouse observers out of the draggable element
90
- *
91
- * @return this
92
- */
93
- destroy: function() {
94
- this.handle.stopObserving('mousedown', this._dragStart);
95
- delete(this.element.draggable);
96
-
97
- return this;
98
- },
99
-
100
- // additional options processing
101
- setOptions: function(options) {
102
- this.$super(options);
103
-
104
- // checking the handle
105
- this.handle = this.options.handle ? $(this.options.handle) : this.element;
106
-
107
- // checking the spappings
108
- if (isArray(this.options.snap)) {
109
- this.snapX = this.options.snap[0];
110
- this.snapY = this.options.snap[1];
111
- } else {
112
- this.snapX = this.snapY = this.options.snap;
113
- }
114
-
115
- return this;
116
- },
117
-
118
- /**
119
- * Moves the element back to the original position
120
- *
121
- * @return this
122
- */
123
- revert: function() {
124
- var position = this.clone.position();
125
- var end_style = {
126
- top: (position.y + this.ryDiff) + 'px',
127
- left: (position.x + this.rxDiff) + 'px'
128
- };
129
-
130
- if (this.options.revertDuration && this.element.morph) {
131
- this.element.morph(end_style, {
132
- duration: this.options.revertDuration,
133
- onFinish: R(this.swapBack).bind(this)
134
- });
135
- } else {
136
- this.element.setStyle(end_style);
137
- this.swapBack();
138
- }
139
-
140
- return this;
141
- },
142
-
143
- // protected
144
-
145
- // handles the event start
146
- dragStart: function(event) {
147
- if (this._drag) { return false; } else { this._drag = true; }
148
-
149
- this.fire('before', this, event.stop());
150
-
151
- // calculating the positions diff
152
- var position = this.element.position();
153
-
154
- this.xDiff = event.pageX - position.x;
155
- this.yDiff = event.pageY - position.y;
156
-
157
- // grabbing the relative position diffs for nested spaces
158
- this.rxDiff = this.ryDiff = 0;
159
- this.element.parents().reverse().each(function(parent) {
160
- if (parent.getStyle('position') !== 'static') {
161
- parent = parent.position();
162
-
163
- this.rxDiff = - parent.x;
164
- this.ryDiff = - parent.y;
165
- }
166
- }, this);
167
-
168
- // preserving the element sizes
169
- var size = {
170
- x: this.element.getStyle('width'),
171
- y: this.element.getStyle('height')
172
- };
173
-
174
- if (size.x == 'auto') { size.x = this.element._.offsetWidth + 'px'; }
175
- if (size.y == 'auto') { size.y = this.element._.offsetHeight + 'px'; }
176
-
177
- // building a clone element if necessary
178
- if (this.options.clone || this.options.revert) {
179
- this.clone = new Element(this.element._.cloneNode(true)).setStyle({
180
- visibility: this.options.clone ? 'visible' : 'hidden'
181
- }).insertTo(this.element, 'before');
182
- }
183
-
184
- // reinserting the element to the body so it was over all the other elements
185
- this.element.setStyle({
186
- position: 'absolute',
187
- zIndex: Draggable.Options.zIndex++,
188
- top: (position.y + this.ryDiff) + 'px',
189
- left: (position.x + this.rxDiff) + 'px',
190
- width: size.x,
191
- height: size.y
192
- }).addClass(this.options.dragClass);
193
-
194
- if (this.options.moveOut) {
195
- this.element.insertTo(document.body);
196
- }
197
-
198
- // caching the window scrolls
199
- this.winScrolls = $(window).scrolls();
200
- this.winSizes = $(window).size();
201
-
202
- Draggable.current = this.calcConstraints().fire('start', this, event);
203
-
204
- this.style = this.element._.style;
205
- },
206
-
207
- // catches the mouse move event
208
- dragProcess: function(event) {
209
- var page_x = event.pageX, page_y = event.pageY, x = page_x - this.xDiff, y = page_y - this.yDiff;
210
-
211
- // checking the range
212
- if (this.ranged) {
213
- if (this.minX > x) { x = this.minX; }
214
- if (this.maxX < x) { x = this.maxX; }
215
- if (this.minY > y) { y = this.minY; }
216
- if (this.maxY < y) { y = this.maxY; }
217
- }
218
-
219
- // checking the scrolls
220
- if (this.options.scroll) {
221
- var scrolls = {x: this.winScrolls.x, y: this.winScrolls.y},
222
- sensitivity = this.options.scrollSensitivity;
223
-
224
- if ((page_y - scrolls.y) < sensitivity) {
225
- scrolls.y = page_y - sensitivity;
226
- } else if ((scrolls.y + this.winSizes.y - page_y) < sensitivity){
227
- scrolls.y = page_y - this.winSizes.y + sensitivity;
228
- }
229
-
230
- if ((page_x - scrolls.x) < sensitivity) {
231
- scrolls.x = page_x - sensitivity;
232
- } else if ((scrolls.x + this.winSizes.x - page_x) < sensitivity){
233
- scrolls.x = page_x - this.winSizes.x + sensitivity;
234
- }
235
-
236
- if (scrolls.y < 0) { scrolls.y = 0; }
237
- if (scrolls.x < 0) { scrolls.x = 0; }
238
-
239
- if (scrolls.y < this.winScrolls.y || scrolls.y > this.winScrolls.y ||
240
- scrolls.x < this.winScrolls.x || scrolls.x > this.winScrolls.x) {
241
-
242
- $(window).scrollTo(this.winScrolls = scrolls);
243
- }
244
- }
245
-
246
- // checking the snaps
247
- if (this.snapX) { x = x - x % this.snapX; }
248
- if (this.snapY) { y = y - y % this.snapY; }
249
-
250
- // checking the constraints
251
- if (!this.axisY) { this.style.left = (x + this.rxDiff) + 'px'; }
252
- if (!this.axisX) { this.style.top = (y + this.ryDiff) + 'px'; }
253
-
254
- this.fire('drag', this, event);
255
- },
256
-
257
- // handles the event stop
258
- dragStop: function(event) {
259
- this.element.removeClass(this.options.dragClass);
260
-
261
- // notifying the droppables for the drop
262
- Droppable.checkDrop(event, this);
263
-
264
- if (this.options.revert) {
265
- this.revert();
266
- } else {
267
- this._drag = false;
268
- }
269
-
270
- Draggable.current = null;
271
-
272
- this.fire('stop', this, event);
273
- },
274
-
275
- // swaps the clone element to the actual element back
276
- swapBack: function() {
277
- if (this.clone) {
278
- this.clone.replace(
279
- this.element.setStyle({
280
- width: this.clone.getStyle('width'),
281
- height: this.clone.getStyle('height'),
282
- position: this.clone.getStyle('position'),
283
- zIndex: this.clone.getStyle('zIndex') || ''
284
- })
285
- );
286
- }
287
- this._drag = false;
288
- },
289
-
290
- // calculates the constraints
291
- calcConstraints: function() {
292
- var axis = this.options.axis;
293
- this.axisX = R(['x', 'horizontal']).include(axis);
294
- this.axisY = R(['y', 'vertical']).include(axis);
295
-
296
- this.ranged = false;
297
- var range = this.options.range;
298
- if (range) {
299
- this.ranged = true;
300
-
301
- // if the range is defined by another element
302
- var element = $(range);
303
- if (element instanceof Element) {
304
- var dims = element.dimensions();
305
-
306
- range = {
307
- x: [dims.left, dims.left + dims.width],
308
- y: [dims.top, dims.top + dims.height]
309
- };
310
- }
311
-
312
- if (isHash(range)) {
313
- var size = this.element.size();
314
-
315
- if (range.x) {
316
- this.minX = range.x[0];
317
- this.maxX = range.x[1] - size.x;
318
- }
319
- if (range.y) {
320
- this.minY = range.y[0];
321
- this.maxY = range.y[1] - size.y;
322
- }
323
- }
324
- }
325
-
326
- return this;
327
- }
328
- });
329
-
330
- /**
331
- * Droppable unit
332
- *
333
- * Copyright (C) 2009-2010 Nikolay Nemshilov
334
- */
335
- var Droppable = new Class(Observer, {
336
- extend: {
337
- EVENTS: $w('drop hover leave'),
338
-
339
- Options: {
340
- accept: '*',
341
- containment: null, // the list of elements (or ids) that should to be accepted
342
-
343
- overlap: null, // 'x', 'y', 'horizontal', 'vertical', 'both' makes it respond only if the draggable overlaps the droppable
344
- overlapSize: 0.5, // the overlapping level 0 for nothing 1 for the whole thing
345
-
346
- allowClass: 'droppable-allow',
347
- denyClass: 'droppable-deny',
348
-
349
- relName: 'droppable' // automatically discovered feature key
350
- },
351
-
352
- // See the Draggable rescan method, case we're kinda hijacking it in here
353
- rescan: Draggable.rescan,
354
-
355
- /**
356
- * Checks for hoverting draggable
357
- *
358
- * @param Event mouse event
359
- * @param Draggable draggable
360
- */
361
- checkHover: function(event, draggable) {
362
- for (var i=0, length = this.active.length; i < length; i++) {
363
- this.active[i].checkHover(event, draggable);
364
- }
365
- },
366
-
367
- /**
368
- * Checks for a drop
369
- *
370
- * @param Event mouse event
371
- * @param Draggable draggable
372
- */
373
- checkDrop: function(event, draggable) {
374
- for (var i=0, length = this.active.length; i < length; i++) {
375
- this.active[i].checkDrop(event, draggable);
376
- }
377
- },
378
-
379
- active: []
380
- },
381
-
382
- /**
383
- * Basic cosntructor
384
- *
385
- * @param mixed the draggable element reference
386
- * @param Object options
387
- */
388
- initialize: function(element, options) {
389
- this.element = $(element);
390
- this.$super(options);
391
-
392
- Droppable.active.push(this.element._droppable = this);
393
- },
394
-
395
- /**
396
- * Detaches the attached events
397
- *
398
- * @return self
399
- */
400
- destroy: function() {
401
- Droppable.active = Droppable.active.without(this);
402
- delete(this.element.droppable);
403
- return this;
404
- },
405
-
406
- /**
407
- * checks the event for hovering
408
- *
409
- * @param Event mouse event
410
- * @param Draggable the draggable object
411
- */
412
- checkHover: function(event, draggable) {
413
- if (this.hoveredBy(event, draggable)) {
414
- if (!this._hovered) {
415
- this._hovered = true;
416
- this.element.addClass(this.options[this.allows(draggable) ? 'allowClass' : 'denyClass']);
417
- this.fire('hover', draggable, this, event);
418
- }
419
- } else if (this._hovered) {
420
- this._hovered = false;
421
- this.reset().fire('leave', draggable, this, event);
422
- }
423
- },
424
-
425
- /**
426
- * Checks if it should process the drop from draggable
427
- *
428
- * @param Event mouse event
429
- * @param Draggable draggable
430
- */
431
- checkDrop: function(event, draggable) {
432
- this.reset();
433
- if (this.hoveredBy(event, draggable) && this.allows(draggable)) {
434
- draggable.fire('drop', this, draggable, event);
435
- this.fire('drop', draggable, this, event);
436
- }
437
- },
438
-
439
- /**
440
- * resets the element state
441
- *
442
- * @return self
443
- */
444
- reset: function() {
445
- this.element.removeClass(this.options.allowClass).removeClass(this.options.denyClass);
446
- return this;
447
- },
448
-
449
- // protected
450
-
451
- // checks if the element is hovered by the event
452
- hoveredBy: function(event, draggable) {
453
- var dims = this.element.dimensions(),
454
- t_top = dims.top,
455
- t_left = dims.left,
456
- t_right = dims.left + dims.width,
457
- t_bottom = dims.top + dims.height,
458
- event_x = event.pageX,
459
- event_y = event.pageY;
460
-
461
- // checking the overlapping
462
- if (this.options.overlap) {
463
- var drag_dims = draggable.element.dimensions(),
464
- level = this.options.overlapSize,
465
- top = drag_dims.top,
466
- left = drag_dims.left,
467
- right = drag_dims.left + drag_dims.width,
468
- bottom = drag_dims.top + drag_dims.height;
469
-
470
-
471
- switch (this.options.overlap) {
472
- // horizontal overlapping only check
473
- case 'x':
474
- case 'horizontal':
475
- return (
476
- (top > t_top && top < t_bottom) ||
477
- (bottom > t_top && bottom < t_bottom)
478
- ) && (
479
- (left > t_left && left < (t_right - dims.width * level)) ||
480
- (right < t_right && right > (t_left + dims.width * level))
481
- );
482
-
483
- // vertical overlapping only check
484
- case 'y':
485
- case 'vertical':
486
- return (
487
- (left > t_left && left < t_right) ||
488
- (right > t_left && right < t_right)
489
- ) && (
490
- (top > t_top && top < (t_bottom - dims.height * level)) ||
491
- (bottom < t_bottom && bottom > (t_top + dims.height * level))
492
- );
493
-
494
- // both overlaps check
495
- default:
496
- return (
497
- (left > t_left && left < (t_right - dims.width * level)) ||
498
- (right < t_right && right > (t_left + dims.width * level))
499
- ) && (
500
- (top > t_top && top < (t_bottom - dims.height * level)) ||
501
- (bottom < t_bottom && bottom > (t_top + dims.height * level))
502
- );
503
- }
504
-
505
- } else {
506
- // simple check agains the event position
507
- return event_x > t_left && event_x < t_right && event_y > t_top && event_y < t_bottom;
508
- }
509
- },
510
-
511
- // checks if the object accepts the draggable
512
- allows: function(draggable) {
513
- if (this.options.containment && !this._scanned) {
514
- this.options.containment = R(this.options.containment).map($);
515
- this._scanned = true;
516
- }
517
-
518
- // checking the invitations list
519
- var welcomed = this.options.containment ? this.options.containment.includes(draggable.element) : true;
520
-
521
- return welcomed && (this.options.accept == '*' ? true : draggable.element.match(this.options.accept));
522
- }
523
-
524
- });
525
-
526
- /**
527
- * The document events hooker
528
- *
529
- * Copyright (C) 2009-2011 Nikolay Nemshilov
530
- */
531
- $(document).on({
532
- // parocesses the automatically discovered elements
533
- ready: function() {
534
- Draggable.rescan();
535
- Droppable.rescan();
536
- },
537
-
538
- // watch the draggables moving arond
539
- mousemove: function(event) {
540
- if (Draggable.current !== null) {
541
- Draggable.current.dragProcess(event);
542
- Droppable.checkHover(event, Draggable.current);
543
- }
544
- },
545
-
546
- // releases the current draggable on mouse up
547
- mouseup: function(event) {
548
- if (Draggable.current !== null) {
549
- Draggable.current.dragStop(event);
550
- }
551
- }
552
- });
553
-
554
- /**
555
- * Element level hooks for drag'n'drops
556
- *
557
- * Copyright (C) 2009-2010 Nikolay Nemshilov
558
- */
559
- Element.include({
560
-
561
- makeDraggable: function(options) {
562
- new Draggable(this, options);
563
- return this;
564
- },
565
-
566
- undoDraggable: function() {
567
- if ('draggable' in this) {
568
- this.draggable.destroy();
569
- }
570
-
571
- return this;
572
- },
573
-
574
- makeDroppable: function(options) {
575
- new Droppable(this, options);
576
- return this;
577
- },
578
-
579
- undoDroppable: function() {
580
- if ('droppable' in this) {
581
- this.droppable.destroy();
582
- }
583
-
584
- return this;
585
- }
586
-
587
- });
588
-
589
- window.Draggable = RightJS.Draggable = Draggable;
590
- window.Droppable = RightJS.Droppable = Droppable;
591
- })(window, document, RightJS);