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
@@ -1,288 +0,0 @@
1
- /**
2
- * RightJS UI Slider unit (http://rightjs.org/ui/slider)
3
- *
4
- * Copyright (C) 2009 Nikolay V. Nemshilov
5
- */
6
- if (!self.RightJS || !self.Draggable) throw "Gimme RightJS w/ DnD";
7
- /**
8
- * RightJS UI Slider unit
9
- *
10
- * Copyright (C) 2009 Nikolay V. Nemshilov
11
- */
12
- var Slider = new Class(Observer, {
13
- extend: {
14
- EVENTS: $w('change'),
15
-
16
- Options: {
17
- min: 0, // the min value
18
- max: 100, // the max value
19
- snap: 0, // the values threshold
20
- value: null, // start value, if null then the min value will be used
21
- direction: 'x', // slider direction 'x', 'y'
22
- update: null, // reference to an element to update
23
- round: 0 // the number of symbols after the decimal pointer
24
- },
25
-
26
- rescan: function(scope) {
27
- ($(scope) || document).select('div.right-slider').each(function(element) {
28
- if (!element._slider) {
29
- new Slider(element);
30
- }
31
- });
32
- }
33
- },
34
-
35
- /**
36
- * basic constructor
37
- * USAGE:
38
- * new Slider('element-id'[, {options}]);
39
- * new Slider({options});
40
- *
41
- * @param mixed slider element reference or options
42
- * @param Object options
43
- */
44
- initialize: function() {
45
- var args = $A(arguments);
46
- this.element = (args[0] && !isHash(args[0])) ? $(args.shift()) : this.build();
47
-
48
- this.$super(isHash(args[0]) ? args[0] : eval('('+this.element.get('data-slider-options')+')'));
49
-
50
- if (this.options.update) this.assignTo(this.options.update);
51
-
52
- this.element._slider = this.init();
53
- },
54
-
55
- // basic desctructor
56
- destroy: function() {
57
- this.handle.undoDraggable();
58
- delete(this.element._slider);
59
- return this;
60
- },
61
-
62
- /**
63
- * The value setter
64
- *
65
- * NOTE: will get snapped according to the options
66
- *
67
- * @param mixed string or number value
68
- * @return Slider this
69
- */
70
- setValue: function(value) {
71
- var value = isString(value) ? value.toFloat() : value;
72
-
73
- // rounding the value according to the options
74
- var base = Math.pow(10, this.options.round);
75
- value = (value * base).round() / base;
76
-
77
- // checking the value constraings
78
- if (this.options.snap) {
79
- var snap = this.options.snap;
80
- var diff = value % snap;
81
- value = diff < snap/2 ? value - diff : value - diff + snap;
82
- }
83
- if (value < this.options.min) value = this.options.min;
84
- if (value > this.options.max) value = this.options.max;
85
-
86
- this.moveTo(value);
87
-
88
- if (value !== this.value) {
89
- this.fire('change', this.value = value);
90
- }
91
-
92
- return this;
93
- },
94
-
95
- /**
96
- * Returns the value
97
- *
98
- * @return Float number
99
- */
100
- getValue: function() {
101
- return this.value;
102
- },
103
-
104
- /**
105
- * Sets the minimal value and rebuilds the dimensions cache
106
- *
107
- * @param Number optional value to reset
108
- * @return Slider this
109
- */
110
- reset: function(value) {
111
- return this.precalc().setValue([value, this.options.value, this.options.min].compact()[0]);
112
- },
113
-
114
- /**
115
- * Inserts the widget into the element
116
- *
117
- * @param mixed element reference
118
- * @param String optional position
119
- * @return Slider this
120
- */
121
- insertTo: function(element, position) {
122
- this.element.insertTo(element, position);
123
- return this.reset(this.value);
124
- },
125
-
126
- /**
127
- * Assigns the slider to feed an input element on change
128
- *
129
- * @param mixed an input element reference
130
- * @return Slider this
131
- */
132
- assignTo: function(element) {
133
- var assign = function(element, value) {
134
- if (element = $(element)) {
135
- if (value === undefined || value === null) value = '';
136
- element[element.setValue ? 'setValue' : 'update'](''+value);
137
- }
138
- }.curry(element);
139
-
140
- var connect = function(element, object) {
141
- var element = $(element);
142
- if (element && element.onChange) {
143
- element.onChange(function() {
144
- this.setValue(element.value);
145
- }.bind(object));
146
- }
147
- }.curry(element);
148
-
149
- if ($(element)) {
150
- assign(this.value);
151
- connect(this);
152
- } else {
153
- document.onReady(function() {
154
- assign(this.value);
155
- connect(this);
156
- }.bind(this));
157
- }
158
-
159
- return this.onChange(assign);
160
- },
161
-
162
- // protected
163
-
164
- // inits the slider handle and resets the whole thing
165
- init: function() {
166
- this.handle = this.element.first('div.right-slider-handle')
167
- .makeDraggable({
168
- onBefore: this.prepare.bind(this),
169
- onDrag: this.dragged.bind(this)
170
- });
171
-
172
- // make it jump to the position
173
- this.element.onClick(this.clicked.bind(this));
174
-
175
- if (this.options.direction == 'y') {
176
- this.element.addClass('right-slider-vertical');
177
- } else {
178
- this.options.direction = this.element.hasClass('right-slider-vertical') ? 'y' : 'x';
179
- }
180
-
181
- // fixing the manual position calculations for Konqueror
182
- if (this.konqFix = (RightJS.version < '1.5.0' && !this.handle.getBoundingClientRect)) {
183
- var parent = this.element;
184
- var old_dims = this.handle.dimensions;
185
- this.handle.dimensions = function() {
186
- var dims = old_dims.call(this);
187
- var subset = parent.dimensions();
188
-
189
- dims.top += subset.top;
190
- dims.left += subset.left;
191
-
192
- return dims;
193
- };
194
- }
195
-
196
-
197
- return this.reset();
198
- },
199
-
200
- // builds the slider prorgrammatically
201
- build: function() {
202
- return $E('div', {'class': 'right-slider'}).insert($E('div', {'class': 'right-slider-handle'}));
203
- },
204
-
205
- // callback for the eleemnt on-click event to make the slider to jump there
206
- clicked: function(event) {
207
- event.stop();
208
- this.precalc().moveTo(this.value);
209
-
210
- var position = event.position();
211
- var element = this.dimensions;
212
-
213
- var position = (this.horizontal ? position.x - element.left : position.y - element.top) - this.offset;
214
-
215
- if (position > this.space) position = this.space;
216
- else if (position < 0) position = 0;
217
-
218
- this.setPosition(position);
219
- },
220
-
221
- // callback for the element dragg
222
- dragged: function(draggable, event) {
223
- this.setPosition(draggable.element.style[this.horizontal ? 'left' : 'top'].toFloat());
224
- },
225
-
226
- // callback for the draggable before event
227
- prepare: function(draggable) {
228
- // moving the slider to the beginning position
229
- this.precalc().moveTo(this.value);
230
-
231
- var offset = this.offset;
232
- var element = this.dimensions;
233
- var options = draggable.options;
234
- options.range = {};
235
-
236
- // calculating the ranges
237
- if ((options.axis = this.options.direction) == 'x') {
238
- options.range.x = [element.left + offset, element.left + element.width - offset];
239
- if (this.konqFix) options.range.x[0] -= element.left;
240
- } else {
241
- options.range.y = [element.top + offset, element.top + element.height - offset];
242
- if (this.konqFix) options.range.y[0] -= element.top;
243
- }
244
-
245
- // calculating the snapping range
246
- if (this.options.snap) {
247
- options.snap = this.space / (this.options.max - this.options.min) * this.options.snap;
248
- }
249
- },
250
-
251
- // sets the slider value by the handle position
252
- setPosition: function(position) {
253
- if (!this.horizontal) position = this.space - position;
254
- var value = position / this.space * (this.options.max - this.options.min) + this.options.min;
255
-
256
- this.setValue(value);
257
- },
258
-
259
- // moves the slider to the given position
260
- moveTo: function(value) {
261
- var position = this.space / (this.options.max - this.options.min) * (value - this.options.min);
262
-
263
- if (!this.horizontal) position = this.space - position;
264
-
265
- this.handle.style[this.horizontal ? 'left' : 'top'] = position + 'px';
266
-
267
- return this;
268
- },
269
-
270
- // precalculates dimensions, direction and offset for further use
271
- precalc: function() {
272
- var handle = this.handle.setStyle({left:'0', top:'0'}).dimensions();
273
-
274
- this.dimensions = this.element.dimensions();
275
- this.horizontal = this.options.direction == 'x';
276
- this.offset = this.horizontal ? handle.left - this.dimensions.left : handle.top - this.dimensions.top;
277
- this.space = (this.horizontal ? this.dimensions.width - handle.width : this.dimensions.height - handle.height) - this.offset * 2;
278
-
279
- return this;
280
- }
281
- });
282
-
283
- /**
284
- * Document onReady hook for sliders
285
- *
286
- * Copyright (C) 2009 Nikolay V. Nemshilov
287
- */
288
- document.onReady(function() { Slider.rescan(); });document.write("<style type=\"text/css\">div.right-slider,div.right-slider-handle{margin:0;padding:0;border:none;background:none}div.right-slider{height:0.4em;width:20em;border:1px solid #CCC;background:#EEE;-moz-border-radius:.2em;-webkit-border-radius:.2em;position:relative;margin:.6em 0;display:inline-block;*display:inline;*zoom:1;vertical-align:middle}div.right-slider-handle{position:absolute;left:0;top:0;cursor:pointer;width:4pt;height:1em;margin-top:-0.4em;margin-left:0.1em;background:#CCC;border:1px solid #AAA;-moz-border-radius:.2em;-webkit-border-radius:.2em}div.right-slider-vertical{height:10em;width:0.4em;margin:0 .3em}div.right-slider-vertical div.right-slider-handle{margin:0;margin-left:-0.4em;margin-top:0.1em;height:4pt;width:1em}</style>");
@@ -1,7 +0,0 @@
1
- /**
2
- * RightJS UI Slider unit (http://rightjs.org/ui/slider)
3
- *
4
- * Copyright (C) 2009 Nikolay V. Nemshilov
5
- */
6
- if (!self.RightJS || !self.Draggable) throw "Gimme RightJS w/ DnD";
7
- eval((function(s,d){for(var i=d.length-1;i>-1;i--)if(d[i])s=s.replace(new RegExp(i,'g'),d[i]);return s})("14 50=78 83(Observer,{extend:{EVENTS:$w('69'),Options:{32:0,47:100,38:0,21:65,25:'x',39:65,55:0},67:9(s){($(s)||33).select('30.17-12').each(9(e){if(!e._12)78 50(e)})}},75ialize:9(){14 a=$A(arguments);7.13=(a[0]&&!70(a[0]))?$(a.shift()):7.74();7.$super(70(a[0])?a[0]:eval('('+7.13.get('data-12-8')+')'));if(7.8.39)7.54(7.8.39);7.13._12=7.75()},destroy:9(){7.16.undo82();delete(7.13._12);18 7},24:9(v){14 v=isString(v)?v.64():v;14 b=Math.pow(10,7.8.55);v=(v*b).55()/b;if(7.8.38){14 s=7.8.38;14 d=v % s;v=d<s/2?v-d:v-d+s}if(v<7.8.32)v=7.8.32;if(v>7.8.47)v=7.8.47;7.40(v);if(v!==7.21)7.fire('69',7.21=v);18 7},getValue:9(){18 7.21},53:9(v){18 7.36().24([v,7.8.21,7.8.32].compact()[0])},52:9(e,p){7.13.52(e,p);18 7.53(7.21)},54:9(b){14 a=9(e,v){if(e=$(e)){if(v===undefined||v===65)v='';e[e.24?'24':'39'](''+v)}}.72(b);14 c=9(e,o){14 e=$(e);if(e&&e.43)e.43(9(){7.24(e.21)}.45(o))}.72(b);if($(b)){a(7.21);c(7)}51 33.60(9(){a(7.21);c(7)}.45(7));18 7.43(a)},75:9(){7.16=7.13.first('30.17-12-16').make82({onBefore:7.63.45(7),onDrag:7.59.45(7)});7.13.onClick(7.61.45(7));if(7.8.25=='y')7.13.add83('17-12-29');51 7.8.25=7.13.has83('17-12-29')?'y':'x';if(7.46=(RightJS.version<'1.5.0'&&!7.16.getBoundingClientRect)){14 p=7.13;14 o=7.16.11;7.16.11=9(){14 d=o.call(7);14 s=p.11();d.22+=s.22;d.19+=s.19;18 d}}18 7.53()},74:9(){18 $E('30',{'71':'17-12'}).insert($E('30',{'71':'17-12-16'}))},61:9(a){a.s22();7.36().40(7.21);14 p=a.44();14 e=7.11;14 p=(7.15?p.x-e.19:p.y-e.22)-7.42;if(p>7.28)p=7.28;51 if(p<0)p=0;7.34(p)},59:9(d,e){7.34(d.13.48[7.15?'19':'22'].64())},63:9(d){7.36().40(7.21);14 o=7.42;14 e=7.11;14 a=d.8;a.37={};if((a.axis=7.8.25)=='x'){a.37.x=[e.19+o,e.19+e.31-o];if(7.46)a.37.x[0]-=e.19}51{a.37.y=[e.22+o,e.22+e.27-o];if(7.46)a.37.y[0]-=e.22}if(7.8.38)a.38=7.28/(7.8.47-7.8.32)*7.8.38},34:9(p){if(!7.15)p=7.28-p;14 v=p/7.28*(7.8.47-7.8.32)+7.8.32;7.24(v)},40:9(v){14 p=7.28/(7.8.47-7.8.32)*(v-7.8.32);if(!7.15)p=7.28-p;7.16.48[7.15?'19':'22']=p+'px';18 7},36:9(){14 h=7.16.setStyle({19:'0',22:'0'}).11();7.11=7.13.11();7.15=7.8.25=='x';7.42=7.15?h.19-7.11.19:h.22-7.11.22;7.28=(7.15?7.11.31-h.31:7.11.27-h.27)-7.42*2;18 7}});33.60(9(){50.67()});33.write(\"<48 type=\\\"text/css\\\">30.17-12,30.17-12-16{23:0;padding:0;26:76;35:76}30.17-12{27:0.62;31:20em;26:81 73 #77;35:#EEE;-79-26-41:.56;-66-26-41:.56;44:relative;23:.6em 0;58:68-block;*58:68;*zoom:1;29-align:middle}30.17-12-16{44:absolute;19:0;22:0;cursor:pointer;31:80;27:57;23-22:-0.62;23-19:0.57;35:#77;26:81 73 #AAA;-79-26-41:.56;-66-26-41:.56}30.17-12-29{27:10em;31:0.62;23:0 .3em}30.17-12-29 30.17-12-16{23:0;23-19:-0.62;23-22:0.57;27:80;31:57}</48>\");",",,,,,,,this,options,function,,dimensions,slider,element,var,horizontal,handle,right,return,left,,value,top,margin,setValue,direction,border,height,space,vertical,div,width,min,document,setPosition,background,precalc,range,snap,update,moveTo,radius,offset,onChange,position,bind,konqFix,max,style,_slider,Slider,else,insertTo,reset,assignTo,round,2em,1em,display,dragged,onReady,clicked,4em,prepare,toFloat,null,webkit,rescan,inline,change,isHash,class,curry,solid,build,init,none,CCC,new,moz,4pt,1px,Draggable,Class".split(",")));
@@ -1,225 +0,0 @@
1
- /**
2
- * Sortable feature for RightJS (requires the Drag'n'Drop feature)
3
- *
4
- * See http://rightjs.org/ui/sortable
5
- *
6
- * Copyright (C) 2009-2010 Nikolay V. Nemshilov
7
- */
8
- if (!Draggable) throw "Gimme Draggable";
9
- /**
10
- * The Sortable unit
11
- *
12
- * Copyright (C) 2009-2010 Nikolay V. Nemshilov
13
- */
14
- var Sortable = new Class(Observer, {
15
- extend: {
16
- EVENTS: $w('update'),
17
-
18
- Options: {
19
- direction: 'auto', // 'auto', 'vertical', 'horizontal', 'x', 'y'
20
-
21
- tags: 'li', // the list items tag name
22
-
23
- url: null, // the Xhr requests url address, might contain the '%{id}' placeholder
24
- method: 'put', // the Xhr requests method
25
-
26
- Xhr: {}, // additional Xhr options
27
-
28
- idParam: 'id', // the id value name
29
- posParam: 'position', // the position value name
30
- parseId: true, // if the id attribute should be converted into an integer before sending
31
-
32
- cssRule: '[rel^=sortable]' // css-rule for automatically processable sortables
33
- },
34
-
35
- // DEPRECATED: scans through the page for auto-discoverable sortables
36
- rescan: function(scope) { }
37
- },
38
-
39
- /**
40
- * basic constructor
41
- *
42
- * @param mixed element reference
43
- * @param Object options
44
- */
45
- initialize: function(element, options) {
46
- this.element = $(element);
47
- this.$super(Object.merge(options, eval('('+this.element.get('data-sortable-options')+')')));
48
-
49
- // trying to get the embedded Xhr url address
50
- var rule = this.options.cssRule.split('[').last(),
51
- attr = this.element.get(rule.split('^=').first()) || '',
52
- url = attr.match(/\[(.+?)\]/);
53
-
54
- if (url) this.options.url = url[1];
55
-
56
- this.element._sortable = this.init().onUpdate('tryXhr');
57
- },
58
-
59
- // detaches all the events out of the elemnts
60
- destroy: function() {
61
- this.getItems.each(function(item) {
62
- item.undoDraggable().undoDroppable();
63
- });
64
- delete(this.element._sortable);
65
-
66
- return this;
67
- },
68
-
69
- // callback for the moved elements
70
- moved: function(element) {
71
- var items = this.getItems();
72
- var position = items.indexOf(element);
73
-
74
- if (position > -1 && position != element.current_position) {
75
- this.fire('update', element, position);
76
-
77
- items.each(function(item, index) {
78
- item.current_position = index;
79
- });
80
- }
81
-
82
- // resetting the left/top positions so it didn't jump next time
83
- element.setStyle({left:'auto', top: 'auto'});
84
- },
85
-
86
- // tries to send an Xhr request about the element relocation
87
- tryXhr: function(element, position) {
88
- if (this.options.url) {
89
- var url = this.options.url, params = {};
90
-
91
- // building the Xhr request options
92
- var options = Object.merge({
93
- method: this.options.method,
94
- params: {}
95
- }, this.options.Xhr);
96
-
97
- // grabbing the id
98
- var id = element.id || '';
99
- if (this.options.parseId && id) {
100
- id = id.match(/\d+/) || '';
101
- }
102
-
103
- // assigning the parameters
104
- if (url.include('%{id}')) {
105
- url = url.replace('%{id}', id);
106
- } else {
107
- params[this.options.idParam] = id;
108
- }
109
- params[this.options.posParam] = position;
110
-
111
- // merging the params with possible Xhr params
112
- if (isString(options.params)) options.params += '&'+Object.toQueryString(params);
113
- else options.params = Object.merge(options.params, params);
114
-
115
- // calling the server
116
- Xhr.load(url, options);
117
- }
118
- },
119
-
120
- // protected
121
-
122
- // inits the sortable unit
123
- init: function() {
124
- var items = this.getItems();
125
-
126
- if (items.length) {
127
- var callback = this.moved.bind(this);
128
-
129
- // guessing the direction
130
- var direction = this.options.direction != 'auto' ? this.options.direction :
131
- ['left', 'right'].include(items[0].getStyle('float')) ? 'x' : 'y';
132
-
133
- // the draggable options
134
- var drag_options = {
135
- range: this.element,
136
- axis: direction,
137
- revert: true,
138
- revertDuration: 0,
139
- onStop: function() {
140
- callback(this.element);
141
- }
142
- };
143
-
144
- // the droppable options
145
- var drop_options = {
146
- overlap: direction,
147
- containment: items,
148
- onHover: function(draggable) {
149
- if (items.include(draggable.element)) {
150
- // calculating the swapping direction
151
- var drag_dims = draggable.element.dimensions();
152
- var this_dims = this.element.dimensions();
153
-
154
- var before = draggable.axisY ? (
155
- drag_dims.top > this_dims.top
156
- ) : (
157
- drag_dims.left > this_dims.left
158
- );
159
-
160
- this.element.insert(draggable.clone, before ? 'before' : 'after');
161
- }
162
- }
163
- };
164
-
165
- // processing the items
166
- items.each(function(item, index) {
167
- item.makeDraggable(drag_options).makeDroppable(drop_options).current_position = index;
168
- });
169
- }
170
-
171
- return this;
172
- },
173
-
174
- // returns the list of the items
175
- getItems: function() {
176
- return this.element.subNodes(this.options.tags);
177
- }
178
-
179
-
180
- });
181
-
182
- /**
183
- * Document level hooks for sortables
184
- *
185
- * Copyright (C) 2009-2010 Nikolay V. Nemshilov
186
- */
187
- document.onMousedown(function(event) {
188
- var target = event.target, element = [target].concat(target.parents()).first('match', Sortable.Options.cssRule);
189
-
190
- if (element) {
191
- var sortable = element._srotable || new Sortable(element);
192
-
193
- if (target._draggable) {
194
- target._draggable.dragStart(event);
195
- }
196
- };
197
- });
198
-
199
- /**
200
- * Element level features for the Sortable unit
201
- *
202
- * Copyright (C) 2009-2010 Nikolay V. Nemshilov
203
- */
204
- Element.include({
205
- /**
206
- * Tries to make a sortable unit out of the element
207
- *
208
- * @param Object options
209
- * @return Element this
210
- */
211
- makeSortable: function(options) {
212
- new Sortable(this, options);
213
- return this;
214
- },
215
-
216
- /**
217
- * Destroy the sortable functionality on the element
218
- *
219
- * @return Element this
220
- */
221
- undoSortable: function() {
222
- if (this._sortable) this._sortable.destroy();
223
- return this;
224
- }
225
- });
@@ -1,9 +0,0 @@
1
- /**
2
- * Sortable feature for RightJS (requires the Drag'n'Drop feature)
3
- *
4
- * See http://rightjs.org/ui/sortable
5
- *
6
- * Copyright (C) 2009-2010 Nikolay V. Nemshilov
7
- */
8
- if (!Draggable) throw "Gimme Draggable";
9
- eval((function(s,d){for(var i=d.length-1;i>-1;i--)if(d[i])s=s.replace(new RegExp(i,'g'),d[i]);return s})("6 9=39 Class(Observer,{extend:{EVENTS:$w('32'),27:{14:'21',40:'li',30:null,19:'put',34:{},29:'id',23:'position',28:42,16:'[rel^=24]'},rescan:3(s){}},43ialize:3(e,o){2.5=$(e);2.$super(15.25(o,eval('('+2.5.44('data-24-4')+')')));6 r=2.4.16.38('[').last(),a=2.5.44(r.38('^=').37())||'',u=a.22(/\\[(.+?)\\]/);if(u)2.4.30=u[1];2.5.8=2.43().onUpdate('33')},26:3(){2.10.31(3(i){i.undo45().undo46()});delete(2.5.8);12 2},35:3(e){6 b=2.10();6 p=b.indexOf(e);if(p>-1&&p!=e.7){2.fire('32',e,p);b.31(3(a,i){a.7=i})}e.set48({20:'21',36:'21'})},33:3(e,a){if(2.4.30){6 u=2.4.30,p={};6 o=15.25({19:2.4.19,11:{}},2.4.34);6 i=e.id||'';if(2.4.28&&i)i=i.22(/\\d+/)||'';if(u.13('%{id}'))u=u.replace('%{id}',i);41 p[2.4.29]=i;p[2.4.23]=a;if(is47(o.11))o.11+='&'+15.toQuery47(p);41 o.11=15.25(o.11,p);34.load(u,o)}},43:3(){6 h=2.10();if(h.length){6 c=2.35.bind(2);6 e=2.4.14!='21'?2.4.14:['20','right'].13(h[0].4448('float'))?'x':'y';6 f={range:2.5,axis:e,revert:42,revertDuration:0,onS36:3(){c(2.5)}};6 g={overlap:e,containment:h,onHover:3(a){if(h.13(a.5)){6 d=a.5.17();6 t=2.5.17();6 b=a.axisY?(d.36>t.36):(d.20>t.20);2.5.insert(a.clone,b?'before':'after')}}};h.31(3(a,i){a.make45(f).make46(g).7=i})}12 2},10:3(){12 2.5.subNodes(2.4.40)}});document.onMousedown(3(a){6 t=a.tar44,e=[t].concat(t.parents()).37('22',9.27.16);if(e){6 s=e._srotable||39 9(e);if(t.18)t.18.dragStart(a)}});Element.13({make9:3(o){39 9(2,o);12 2},undo9:3(){if(2.8)2.8.26();12 2}});",",,this,function,options,element,var,current_position,_sortable,Sortable,getItems,params,return,include,direction,Object,cssRule,dimensions,_draggable,method,left,auto,match,posParam,sortable,merge,destroy,Options,parseId,idParam,url,each,update,tryXhr,Xhr,moved,top,first,split,new,tags,else,true,init,get,Draggable,Droppable,String,Style".split(",")));