puffer 0.0.5 → 0.0.6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (105) hide show
  1. data/.rspec +1 -0
  2. data/Gemfile +2 -1
  3. data/Gemfile.lock +12 -0
  4. data/VERSION +1 -1
  5. data/app/cells/puffer/base/additional.html.erb +17 -0
  6. data/app/cells/puffer/base_cell.rb +25 -0
  7. data/app/controllers/admin/dashboard_controller.rb +12 -0
  8. data/app/views/admin/dashboard/index.html.erb +1 -0
  9. data/app/views/layouts/puffer.html.erb +41 -23
  10. data/app/views/puffer/_form.html.erb +3 -11
  11. data/app/views/puffer/edit.html.erb +6 -4
  12. data/app/views/puffer/index.html.erb +11 -38
  13. data/app/views/puffer/new.html.erb +5 -2
  14. data/app/views/puffer/show.html.erb +4 -4
  15. data/config/routes.rb +7 -0
  16. data/lib/generators/puffer/controller/controller_generator.rb +1 -1
  17. data/lib/generators/puffer/install/templates/puffer/javascripts/rails-src.js +399 -0
  18. data/lib/generators/puffer/install/templates/puffer/javascripts/rails.js +14 -175
  19. data/lib/generators/puffer/install/templates/puffer/javascripts/right-calendar-src.js +1461 -0
  20. data/lib/generators/puffer/install/templates/puffer/javascripts/right-calendar.js +36 -0
  21. data/lib/generators/puffer/install/templates/puffer/javascripts/right-calendar.js.gz +0 -0
  22. data/lib/generators/puffer/install/templates/puffer/javascripts/right-in-edit-src.js +369 -0
  23. data/lib/generators/puffer/install/templates/puffer/javascripts/right-in-edit.js +13 -0
  24. data/lib/generators/puffer/install/templates/puffer/javascripts/right-in-edit.js.gz +0 -0
  25. data/lib/generators/puffer/install/templates/puffer/javascripts/right-lightbox-src.js +905 -0
  26. data/lib/generators/puffer/install/templates/puffer/javascripts/right-lightbox.js +24 -0
  27. data/lib/generators/puffer/install/templates/puffer/javascripts/right-lightbox.js.gz +0 -0
  28. data/lib/generators/puffer/install/templates/puffer/javascripts/right-sortable-src.js +428 -0
  29. data/lib/generators/puffer/install/templates/puffer/javascripts/right-sortable.js +17 -0
  30. data/lib/generators/puffer/install/templates/puffer/javascripts/right-sortable.js.gz +0 -0
  31. data/lib/generators/puffer/install/templates/puffer/javascripts/right-src.js +5892 -0
  32. data/lib/generators/puffer/install/templates/puffer/javascripts/right-tabs-src.js +1145 -0
  33. data/lib/generators/puffer/install/templates/puffer/javascripts/right-tabs.js +29 -0
  34. data/lib/generators/puffer/install/templates/puffer/javascripts/right-tabs.js.gz +0 -0
  35. data/lib/generators/puffer/install/templates/puffer/javascripts/right.js +95 -0
  36. data/lib/generators/puffer/install/templates/puffer/javascripts/right.js.gz +0 -0
  37. data/lib/generators/puffer/install/templates/puffer/stylesheets/puffer.css +168 -0
  38. data/lib/generators/puffer/install/templates/puffer/stylesheets/reset.css +60 -0
  39. data/lib/puffer.rb +2 -1
  40. data/lib/puffer/base.rb +15 -14
  41. data/lib/puffer/controller/config.rb +52 -16
  42. data/lib/puffer/controller/dsl.rb +27 -29
  43. data/lib/puffer/controller/helpers.rb +54 -9
  44. data/lib/puffer/controller/mutate.rb +4 -22
  45. data/lib/puffer/engine.rb +9 -0
  46. data/lib/puffer/extensions/controller.rb +5 -3
  47. data/lib/puffer/extensions/form.rb +14 -0
  48. data/lib/puffer/extensions/mapper.rb +36 -0
  49. data/lib/puffer/fields.rb +21 -0
  50. data/lib/puffer/fields/field.rb +8 -3
  51. data/lib/puffer/inputs.rb +23 -0
  52. data/lib/puffer/inputs/association.rb +11 -0
  53. data/lib/puffer/inputs/base.rb +39 -0
  54. data/lib/puffer/inputs/boolean.rb +19 -0
  55. data/lib/puffer/inputs/collection_association.rb +11 -0
  56. data/lib/puffer/inputs/date_time.rb +16 -0
  57. data/lib/puffer/inputs/file.rb +11 -0
  58. data/lib/puffer/inputs/password.rb +11 -0
  59. data/lib/puffer/inputs/select.rb +11 -0
  60. data/lib/puffer/inputs/text.rb +11 -0
  61. data/lib/puffer/path_set.rb +17 -0
  62. data/lib/puffer/resource.rb +14 -14
  63. data/puffer.gemspec +75 -8
  64. data/spec/dummy/app/controllers/admin/categories_controller.rb +4 -0
  65. data/spec/dummy/app/controllers/admin/posts_controller.rb +4 -0
  66. data/spec/dummy/app/controllers/admin/profiles_controller.rb +5 -0
  67. data/spec/dummy/app/controllers/admin/users_controller.rb +4 -0
  68. data/spec/dummy/app/models/friendship.rb +4 -0
  69. data/spec/dummy/app/models/profile.rb +2 -0
  70. data/spec/dummy/app/models/user.rb +7 -0
  71. data/spec/dummy/app/views/admin/users/index.html.erb +1 -0
  72. data/spec/dummy/config/puffer.rb +0 -0
  73. data/spec/dummy/db/migrate/20110107082706_create_friendships.rb +15 -0
  74. data/spec/dummy/db/schema.rb +9 -1
  75. data/spec/dummy/public/puffer/javascripts/rails-src.js +399 -0
  76. data/spec/dummy/public/puffer/javascripts/rails.js +14 -0
  77. data/spec/dummy/public/puffer/javascripts/right-calendar-src.js +1461 -0
  78. data/spec/dummy/public/puffer/javascripts/right-calendar.js +36 -0
  79. data/spec/dummy/public/puffer/javascripts/right-calendar.js.gz +0 -0
  80. data/spec/dummy/public/puffer/javascripts/right-in-edit-src.js +369 -0
  81. data/spec/dummy/public/puffer/javascripts/right-in-edit.js +13 -0
  82. data/spec/dummy/public/puffer/javascripts/right-in-edit.js.gz +0 -0
  83. data/spec/dummy/public/puffer/javascripts/right-lightbox-src.js +905 -0
  84. data/spec/dummy/public/puffer/javascripts/right-lightbox.js +24 -0
  85. data/spec/dummy/public/puffer/javascripts/right-lightbox.js.gz +0 -0
  86. data/spec/dummy/public/puffer/javascripts/right-sortable-src.js +428 -0
  87. data/spec/dummy/public/puffer/javascripts/right-sortable.js +17 -0
  88. data/spec/dummy/public/puffer/javascripts/right-sortable.js.gz +0 -0
  89. data/spec/dummy/public/puffer/javascripts/right-src.js +5892 -0
  90. data/spec/dummy/public/puffer/javascripts/right-tabs-src.js +1145 -0
  91. data/spec/dummy/public/puffer/javascripts/right-tabs.js +29 -0
  92. data/spec/dummy/public/puffer/javascripts/right-tabs.js.gz +0 -0
  93. data/spec/dummy/public/puffer/javascripts/right.js +95 -0
  94. data/spec/dummy/public/puffer/javascripts/right.js.gz +0 -0
  95. data/spec/dummy/public/puffer/stylesheets/puffer.css +168 -0
  96. data/spec/dummy/public/puffer/stylesheets/reset.css +60 -0
  97. data/spec/lib/fields_spec.rb +2 -0
  98. data/spec/lib/params_spec.rb +55 -54
  99. metadata +114 -23
  100. data/lib/generators/puffer/install/templates/puffer/javascripts/application.js +0 -2
  101. data/lib/generators/puffer/install/templates/puffer/javascripts/controls.js +0 -965
  102. data/lib/generators/puffer/install/templates/puffer/javascripts/dragdrop.js +0 -974
  103. data/lib/generators/puffer/install/templates/puffer/javascripts/effects.js +0 -1123
  104. data/lib/generators/puffer/install/templates/puffer/javascripts/prototype.js +0 -6001
  105. data/lib/puffer/railtie.rb +0 -5
@@ -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(j,d){var q=d.$,s=d.$$,u=d.$w,h=d.$E,v=d.$ext,w=d.Xhr,r=d.Class,x=d.Object,k=d.Element,i=d.Browser;i.IE6=i.OLD&&navigator.userAgent.indexOf("MSIE 6")>0;var y=new d.Class(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=this.dots.pop();
8
+ this.dots.unshift(a);this.insert(a,"top")}}}),f=new (function(a,b){if(!b){b=a;a="DIV"}var c=new d.Class(d.Element.Wrappers[a]||d.Element,{initialize:function(e,g){this.key=e;var l=[{"class":"rui-"+e}];this instanceof d.Input||this instanceof d.Form||l.unshift(a);this.$super.apply(this,l);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 d.Wrapper.Cache[d.$uid(this._)]=this},setOptions:function(e,g){g=g||
9
+ this;d.Options.setOptions.call(this,d.Object.merge(e,eval("("+(g.get("data-"+this.key)||"{}")+")")));return this}});c=new d.Class(c,b);d.Observer.createShortcuts(c.prototype,c.EVENTS||[]);return c})({extend:{version:"2.2.0",EVENTS:u("show hide load"),Options:{fxName:"fade",fxDuration:300,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)/,
10
+ Medias:[[/(http:\/\/.*?youtube\.[a-z]+)\/watch\?v=([^&]+)/,"$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 z(this.options),this.dialog=new A(this.options)]).on({close:this._close,next:this._next,prev:this._prev})},setOptions:function(a,b){this.$super(a,b);if(b){var c=
11
+ b.get("rel");if(c&&(c=c.match(/lightbox\[(.+?)\]/)))this.options.group=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);
12
+ return this},_close:function(a){a.stop();this.hide()},_prev:function(a){a.stop();m.prev()},_next:function(a){a.stop();m.next()},_showAnd:function(a){if(f.current!==this){f.current=this;s("div.rui-lightbox").each("remove");this.insertTo(j.body);this.dialog.show("",true);if(i.OLD){this.reposition();k.prototype.show.call(this);a.call(this)}else{this.setStyle("display:none");k.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);
13
+ return this},reposition:function(){if(i.IE6){var a=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 z=new r(k,{initialize:function(a){this.$super("div",{"class":"rui-lightbox-locker"});a.hideOnOutClick&&this.onClick("fire",
14
+ "close")}}),A=new r(k,{initialize:function(a){var b=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 y(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:"&times;",title:b.Close}).onClick("fire","close"),this.prevLink=h("div",{"class":"prev",html:"&larr;",title:b.Prev}).onClick("fire","prev"),this.nextLink=h("div",{"class":"next",html:"&rarr;",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,l=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,n=this._.style,o=this.scroller._.style;if(d.Fx&&b&&(a.x!=e.x||a.y!=e.y))v(new d.Fx(this,{duration:this.options.fxDuration}),{render:function(p){o.width=e.x+(a.x-e.x)*p+"px";o.height=e.y+(a.y-e.y)*p+"px";n.top=g+(t-g)*p+"px";if(i.IE6)n.width=l+e.y+(a.y-e.y)*p+"px"}}).onFinish(d(this.unlock).bind(this)).start();
17
+ else{o.width=a.x+"px";o.height=a.y+"px";n.top=t+"px";if(i.IE6)n.width=l+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 k){this.setTitle(a.get("title"));a=a.get("href")}m.show(this,a);this.lock().cancel();this.request=new B(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;display:block").insertTo(this.scroller,
18
+ "before");return this},unlock:function(){this.locker.remove(d(this.content.html()).blank()?null:"fade",{duration:this.options.fxDuration*2/3});return this}}),B=new r({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,x.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(){}},
19
+ isImage:function(a,b){if(a.match(f.Images)){var c=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?
20
+ f.current.options:f.Options;e=' width="'+e.mediaWidth+'" 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>"}}),m={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&&
21
+ c<e-1?"show":"hide"]()}else this.dialog=null},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 s("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=
22
+ d(function(){m.timer=null}).delay(300)}};q(j).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){var b=a.target;if(!b.parent("div.rui-lightbox-content")||b.getStyle("overflow")==="visible")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!==
23
+ "close"||b.options.hideOnEsc){a.stop();b.fire(c)}}});q(window).on({resize:function(){if(f.current){f.current.reposition();f.current.dialog.resize()}},scroll:function(){f.current&&i.IE6&&f.current.reposition()}});(function(){var a=j.createElement("style"),b=j.createTextNode("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;float:none;width:100%;height:100%;margin:0;padding:0;background:none;border:none;text-align:center;z-index:9999;z-index/*\\**/:auto\\9;}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;z-index/*\\**/:9990\\9;}div.rui-lightbox-dialog{display:inline-block; *display:inline; *zoom:1;position:relative;text-align:left;z-index/*\\**/:9999\\9;}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}div.rui-lightbox-body{background-color:#FFF;padding:1em;border-radius:.5em;-moz-border-radius:.5em;-webkit-border-radius:.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%;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:160%;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:#D8D8D8}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}");
24
+ a.type="text/css";if(a.styleSheet)a.styleSheet.cssText=b.nodeValue;else a.appendChild(b);j.getElementsByTagName("head")[0].appendChild(a)})();return f}(document,RightJS);
@@ -0,0 +1,428 @@
1
+ /**
2
+ * Sortable feature for RightJS
3
+ * See http://rightjs.org/ui/sortable
4
+ *
5
+ * NOTE: requires the dnd-plugin
6
+ *
7
+ * Copyright (C) 2009-2010 Nikolay Nemshilov
8
+ */
9
+ var Sortable = RightJS.Sortable = (function(document, RightJS) {
10
+ /**
11
+ * This module defines the basic widgets constructor
12
+ * it creates an abstract proxy with the common functionality
13
+ * which then we reuse and override in the actual widgets
14
+ *
15
+ * Copyright (C) 2010-2011 Nikolay Nemshilov
16
+ */
17
+
18
+ /**
19
+ * Sortable initialization script
20
+ *
21
+ * Copyright (C) 2010 Nikolay Nemshilov
22
+ */
23
+ var R = RightJS,
24
+ $ = RightJS.$,
25
+ $w = RightJS.$w,
26
+ isString = RightJS.isString,
27
+ isArray = RightJS.isArray,
28
+ Object = RightJS.Object;
29
+
30
+
31
+
32
+
33
+ /**
34
+ * The widget units constructor
35
+ *
36
+ * @param String tag-name or Object methods
37
+ * @param Object methods
38
+ * @return Widget wrapper
39
+ */
40
+ function Widget(tag_name, methods) {
41
+ if (!methods) {
42
+ methods = tag_name;
43
+ tag_name = 'DIV';
44
+ }
45
+
46
+ /**
47
+ * An Abstract Widget Unit
48
+ *
49
+ * Copyright (C) 2010 Nikolay Nemshilov
50
+ */
51
+ var AbstractWidget = new RightJS.Class(RightJS.Element.Wrappers[tag_name] || RightJS.Element, {
52
+ /**
53
+ * The common constructor
54
+ *
55
+ * @param Object options
56
+ * @param String optional tag name
57
+ * @return void
58
+ */
59
+ initialize: function(key, options) {
60
+ this.key = key;
61
+ var args = [{'class': 'rui-' + key}];
62
+
63
+ // those two have different constructors
64
+ if (!(this instanceof RightJS.Input || this instanceof RightJS.Form)) {
65
+ args.unshift(tag_name);
66
+ }
67
+ this.$super.apply(this, args);
68
+
69
+ if (RightJS.isString(options)) {
70
+ options = RightJS.$(options);
71
+ }
72
+
73
+ // if the options is another element then
74
+ // try to dynamically rewrap it with our widget
75
+ if (options instanceof RightJS.Element) {
76
+ this._ = options._;
77
+ if ('$listeners' in options) {
78
+ options.$listeners = options.$listeners;
79
+ }
80
+ options = {};
81
+ }
82
+ this.setOptions(options, this);
83
+
84
+ return (RightJS.Wrapper.Cache[RightJS.$uid(this._)] = this);
85
+ },
86
+
87
+ // protected
88
+
89
+ /**
90
+ * Catches the options
91
+ *
92
+ * @param Object user-options
93
+ * @param Element element with contextual options
94
+ * @return void
95
+ */
96
+ setOptions: function(options, element) {
97
+ element = element || this;
98
+ RightJS.Options.setOptions.call(this,
99
+ RightJS.Object.merge(options, eval("("+(
100
+ element.get('data-'+ this.key) || '{}'
101
+ )+")"))
102
+ );
103
+ return this;
104
+ }
105
+ });
106
+
107
+ /**
108
+ * Creating the actual widget class
109
+ *
110
+ */
111
+ var Klass = new RightJS.Class(AbstractWidget, methods);
112
+
113
+ // creating the widget related shortcuts
114
+ RightJS.Observer.createShortcuts(Klass.prototype, Klass.EVENTS || []);
115
+
116
+ return Klass;
117
+ }
118
+
119
+
120
+ /**
121
+ * The Sortable unit
122
+ *
123
+ * Copyright (C) 2009-2011 Nikolay Nemshilov
124
+ */
125
+ var Sortable = new Widget('UL', {
126
+ extend: {
127
+ version: '2.2.0',
128
+
129
+ EVENTS: $w('start change finish'),
130
+
131
+ Options: {
132
+ url: null, // the Xhr requests url address, might contain the '%{id}' placeholder
133
+ method: 'put', // the Xhr requests method
134
+
135
+ Xhr: {}, // additional Xhr options
136
+
137
+ idParam: 'id', // the id value name
138
+ posParam: 'position', // the position value name
139
+ parseId: true, // if the id attribute should be converted into an integer before sending
140
+
141
+ dragClass: 'dragging', // the in-process class name
142
+ accept: null, // a reference or a list of references to the other sortables between which you can drag the items
143
+ minLength: 1, // minimum number of items on the list when the feature works
144
+
145
+ itemCss: 'li', // the draggable item's css rule
146
+ handleCss: 'li', // the draggables handle element css rule
147
+
148
+ cssRule: '*[data-sortable]' // css-rule for automatically initializable sortables
149
+ },
150
+
151
+ current: false, // a reference to the currently active sortable
152
+
153
+ /**
154
+ * Typecasting the list element for Sortable
155
+ *
156
+ * @param Element list
157
+ * @return Sortable list
158
+ */
159
+ cast: function(element) {
160
+ element = $(element._);
161
+ if (!(element instanceof Sortable)) {
162
+ element = new Sortable(element);
163
+ }
164
+ return element;
165
+ }
166
+ },
167
+
168
+ /**
169
+ * basic constructor
170
+ *
171
+ * @param mixed element reference
172
+ * @param Object options
173
+ * @return void
174
+ */
175
+ initialize: function(element, options) {
176
+ this.$super('sortable', element)
177
+ .setOptions(options)
178
+ .addClass('rui-sortable')
179
+ .on('finish', this._tryXhr)
180
+ .on('selectstart', 'stopEvent'); // disable select under IE
181
+ },
182
+
183
+ /**
184
+ * some additional options processing
185
+ *
186
+ * @param Object options
187
+ * @param Element optional context
188
+ * @return Sortable this
189
+ */
190
+ setOptions: function(options, context) {
191
+ this.$super(options, context);
192
+
193
+ options = this.options;
194
+
195
+ // Preprocessing the acceptance list
196
+ var list = options.accept || [];
197
+ if (!isArray(list)) { list = [list]; }
198
+
199
+ options.accept = R([this].concat(list)).map($).uniq();
200
+
201
+ return this;
202
+ },
203
+
204
+ // returns a list of draggable items
205
+ items: function() {
206
+ return this.children(this.options.itemCss);
207
+ },
208
+
209
+ // protected
210
+
211
+ // starts the drag
212
+ startDrag: function(event) {
213
+ // don't let to drag out the last item
214
+ if (this.items().length <= this.options.minLength) { return; }
215
+
216
+ // trying to find the list-item upon which the user pressed the mouse
217
+ var item = event.find(this.options.itemCss),
218
+ handle = event.find(this.options.handleCss);
219
+
220
+ if (item && handle) {
221
+ this._initDrag(item, event.position());
222
+ Sortable.current = this;
223
+ this.fire('start', this._evOpts(event));
224
+ }
225
+ },
226
+
227
+ // moves the item
228
+ moveItem: function(event) {
229
+ var event_pos = event.position(),
230
+ item = this.itemClone._.style,
231
+ top = event_pos.y - this.yRDiff,
232
+ left = event_pos.x - this.xRDiff,
233
+ right = left + this.cloneWidth,
234
+ bottom = top + this.cloneHeight;
235
+
236
+ // moving the clone
237
+ item.top = (event_pos.y - this.yDiff) + 'px';
238
+ item.left = (event_pos.x - this.xDiff) + 'px';
239
+
240
+ // checking for an overlaping item
241
+ var over_item = this.suspects.first(function(suspect) {
242
+ return (
243
+ (top > suspect.top && top < suspect.topHalf) ||
244
+ (bottom < suspect.bottom && bottom > suspect.topHalf)
245
+ ) && (
246
+ (left > suspect.left && left < suspect.leftHalf) ||
247
+ (right < suspect.right && right > suspect.leftHalf)
248
+ );
249
+ });
250
+
251
+ if (over_item) {
252
+ item = over_item.item;
253
+ item.insert(this.item, item.prevSiblings().include(this.item) ? 'after' : 'before');
254
+ this._findSuspects();
255
+
256
+ this.fire('change', this._evOpts(event, item));
257
+ }
258
+ },
259
+
260
+ // finalizes the drag
261
+ finishDrag: function(event) {
262
+ if (this.itemClone) {
263
+ this.itemClone.remove();
264
+ this.item.setStyle('visibility:visible');
265
+ }
266
+ Sortable.current = false;
267
+ this.fire('finish', this._evOpts(event));
268
+ },
269
+
270
+ // returns the event options
271
+ _evOpts: function(event, item) {
272
+ item = item || this.item;
273
+ var list = Sortable.cast(item.parent());
274
+
275
+ return {
276
+ list: list,
277
+ item: item,
278
+ event: event,
279
+ index: list.items().indexOf(item)
280
+ };
281
+ },
282
+
283
+ _initDrag: function(item, event_pos) {
284
+ var dims = this.dimensions(), item_dims = item.dimensions();
285
+
286
+ // creating the draggable clone
287
+ var clone = item.clone().setStyle({
288
+ margin: 0,
289
+ zIndex: 9999,
290
+ position: 'absolute',
291
+ top: '0px',
292
+ left: '0px'
293
+ })
294
+ .addClass(this.options.dragClass).insertTo(this)
295
+ .setHeight(this.cloneHeight = item_dims.height)
296
+ .setWidth(this.cloneWidth = item_dims.width);
297
+
298
+ // adjusting the clone position to compensate relative fields and margins
299
+ var clone_pos = clone.position(),
300
+ real_x = item_dims.left - clone_pos.x,
301
+ real_y = item_dims.top - clone_pos.y;
302
+
303
+ clone.moveTo(real_x, real_y);
304
+
305
+ this.item = item.setStyle('visibility:hidden');
306
+ this.itemClone = clone;
307
+
308
+ // mouse event-position diffs
309
+ this.xDiff = event_pos.x - real_x;
310
+ this.yDiff = event_pos.y - real_y;
311
+ this.xRDiff = event_pos.x - clone.position().x;
312
+ this.yRDiff = event_pos.y - clone.position().y;
313
+
314
+ // collecting the list of interchangable items with their positions
315
+ this._findSuspects();
316
+ },
317
+
318
+ // collects the precached list of suspects
319
+ _findSuspects: function() {
320
+ var suspects = this.suspects = R([]), item = this.item, clone = this.itemClone;
321
+ this.options.accept.each(function(list) {
322
+ Sortable.cast(list).items().each(function(element) {
323
+ if (element !== item && element !== clone) {
324
+ var dims = element.dimensions();
325
+
326
+ // caching the sizes
327
+ suspects.push({
328
+ item: element,
329
+ top: dims.top,
330
+ left: dims.left,
331
+ right: dims.left + dims.width,
332
+ bottom: dims.top + dims.height,
333
+ topHalf: dims.top + dims.height/2,
334
+ leftHalf: dims.left + dims.width/2
335
+ });
336
+ }
337
+ });
338
+ });
339
+ },
340
+
341
+ // tries to send an Xhr request about the element relocation
342
+ _tryXhr: function(event) {
343
+ if (this.options.url) {
344
+ var url = R(this.options.url), params = {}, item = event.item, position = event.index + 1;
345
+
346
+ // building the Xhr request options
347
+ var options = Object.merge({
348
+ method: this.options.method,
349
+ params: {}
350
+ }, this.options.Xhr);
351
+
352
+ // grabbing the id
353
+ var id = item.get('id') || '';
354
+ if (this.options.parseId && id) {
355
+ id = (id.match(/\d+/) || [''])[0];
356
+ }
357
+
358
+ // assigning the parameters
359
+ if (url.include('%{id}')) {
360
+ url = url.replace('%{id}', id);
361
+ } else {
362
+ params[this.options.idParam] = id;
363
+ }
364
+ params[this.options.posParam] = position;
365
+
366
+ // merging the params with possible Xhr params
367
+ if (isString(options.params)) {
368
+ options.params += '&'+Object.toQueryString(params);
369
+ } else {
370
+ options.params = Object.merge(options.params, params);
371
+ }
372
+
373
+ // calling the server
374
+ RightJS.Xhr.load(url, options);
375
+ }
376
+ }
377
+ });
378
+
379
+
380
+ /**
381
+ * Document level hooks for sortables
382
+ *
383
+ * Copyright (C) 2009-2010 Nikolay Nemshilov
384
+ */
385
+ $(document).on({
386
+ mousedown: function(event) {
387
+ var element = event.find(Sortable.Options.cssRule+",*.rui-sortable");
388
+
389
+ if (element) {
390
+ Sortable.cast(element).startDrag(event);
391
+ }
392
+ },
393
+
394
+ mousemove: function(event) {
395
+ if (Sortable.current) {
396
+ Sortable.current.moveItem(event);
397
+ }
398
+ },
399
+
400
+ mouseup: function(event) {
401
+ if (Sortable.current) {
402
+ Sortable.current.finishDrag(event);
403
+ }
404
+ }
405
+ });
406
+
407
+ $(window).onBlur(function() {
408
+ if (Sortable.current) {
409
+ Sortable.current.finishDrag();
410
+ }
411
+ });
412
+ (function() {
413
+ var style = document.createElement('style'),
414
+ rules = document.createTextNode(".rui-sortable{user-select:none;-moz-user-select:none;-webkit-user-select:none}");
415
+
416
+ style.type = 'text/css';
417
+
418
+ if(style.styleSheet) {
419
+ style.styleSheet.cssText = rules.nodeValue;
420
+ } else {
421
+ style.appendChild(rules);
422
+ }
423
+
424
+ document.getElementsByTagName('head')[0].appendChild(style);
425
+ })();
426
+
427
+ return Sortable;
428
+ })(document, RightJS);