right-rails 0.6.0 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +8 -0
- data/README.rdoc +71 -0
- data/Rakefile +144 -14
- data/generators/right_rails/right_rails_generator.rb +18 -21
- data/init.rb +11 -32
- data/lib/generators/right_rails/right_rails_generator.rb +27 -0
- data/lib/generators/right_rails/templates/iframed.html.erb +10 -0
- data/lib/right-rails.rb +1 -1
- data/lib/right_rails/config.rb +278 -0
- data/lib/right_rails/controller_extensions.rb +10 -5
- data/lib/right_rails/helpers/basic.rb +10 -66
- data/lib/right_rails/helpers/forms.rb +141 -139
- data/lib/right_rails/helpers/misc.rb +45 -67
- data/lib/right_rails/helpers/rails.rb +40 -105
- data/lib/right_rails/helpers.rb +364 -1
- data/lib/right_rails/java_script_generator.rb +34 -24
- data/lib/right_rails.rb +6 -1
- data/{images → public/images}/colorpicker.png +0 -0
- data/{images → public/images}/resizable.png +0 -0
- data/public/javascripts/right/autocompleter-src.js +612 -0
- data/public/javascripts/right/autocompleter.js +18 -0
- data/public/javascripts/right/calendar-src.js +1448 -0
- data/public/javascripts/right/calendar.js +36 -0
- data/public/javascripts/right/colorpicker-src.js +967 -0
- data/public/javascripts/right/colorpicker.js +26 -0
- data/{javascripts/right-dnd-src.js → public/javascripts/right/dnd-src.js} +86 -52
- data/public/javascripts/right/dnd.js +20 -0
- data/{javascripts/right-effects-src.js → public/javascripts/right/effects-src.js} +90 -45
- data/public/javascripts/right/effects.js +17 -0
- data/{javascripts/right-ui-i18n-de.js → public/javascripts/right/i18n/de.js} +7 -7
- data/{javascripts/right-ui-i18n-en-us.js → public/javascripts/right/i18n/en-us.js} +1 -1
- data/{javascripts/right-ui-i18n-es.js → public/javascripts/right/i18n/es.js} +7 -7
- data/{javascripts/right-ui-i18n-fr.js → public/javascripts/right/i18n/fr.js} +7 -7
- data/{javascripts/right-ui-i18n-hu.js → public/javascripts/right/i18n/hu.js} +7 -7
- data/{javascripts/right-ui-i18n-jp.js → public/javascripts/right/i18n/jp.js} +7 -7
- data/{javascripts/right-ui-i18n-nl.js → public/javascripts/right/i18n/nl.js} +7 -7
- data/{javascripts/right-ui-i18n-pt-br.js → public/javascripts/right/i18n/pt-br.js} +7 -7
- data/{javascripts/right-ui-i18n-ru.js → public/javascripts/right/i18n/ru.js} +7 -7
- data/{javascripts/right-ui-i18n-ua.js → public/javascripts/right/i18n/ua.js} +17 -12
- data/public/javascripts/right/in-edit-src.js +352 -0
- data/public/javascripts/right/in-edit.js +13 -0
- data/public/javascripts/right/json-src.js +160 -0
- data/public/javascripts/right/json.js +10 -0
- data/public/javascripts/right/lightbox-src.js +881 -0
- data/public/javascripts/right/lightbox.js +24 -0
- data/{javascripts/right-rails-src.js → public/javascripts/right/rails-src.js} +195 -171
- data/public/javascripts/right/rails.js +14 -0
- data/public/javascripts/right/rater-src.js +366 -0
- data/public/javascripts/right/rater.js +13 -0
- data/public/javascripts/right/resizable-src.js +420 -0
- data/public/javascripts/right/resizable.js +15 -0
- data/public/javascripts/right/selectable-src.js +687 -0
- data/public/javascripts/right/selectable.js +22 -0
- data/public/javascripts/right/slider-src.js +377 -0
- data/public/javascripts/right/slider.js +14 -0
- data/public/javascripts/right/sortable-src.js +392 -0
- data/public/javascripts/right/sortable.js +16 -0
- data/public/javascripts/right/tabs-src.js +1123 -0
- data/public/javascripts/right/tabs.js +29 -0
- data/public/javascripts/right/tooltip-src.js +307 -0
- data/public/javascripts/right/tooltip.js +12 -0
- data/public/javascripts/right/uploader-src.js +283 -0
- data/public/javascripts/right/uploader.js +13 -0
- data/{javascripts → public/javascripts}/right-olds-src.js +134 -186
- data/public/javascripts/right-olds.js +18 -0
- data/public/javascripts/right-safe-src.js +161 -0
- data/public/javascripts/right-safe.js +8 -0
- data/{javascripts → public/javascripts}/right-src.js +2558 -1750
- data/public/javascripts/right.js +92 -0
- data/spec/lib/right_rails/config_spec.rb +133 -0
- data/spec/lib/right_rails/controller_extensions_spec.rb +1 -1
- data/spec/lib/right_rails/helpers/basic_spec.rb +77 -66
- data/spec/lib/right_rails/helpers/forms_spec.rb +231 -33
- data/spec/lib/right_rails/helpers/misc_spec.rb +94 -26
- data/spec/lib/right_rails/helpers/rails_spec.rb +42 -7
- data/spec/lib/right_rails/helpers_spec.rb +125 -0
- data/spec/lib/right_rails/java_script_generator_spec.rb +30 -0
- data/spec/rcov.opts +3 -0
- data/spec/spec_helper.rb +12 -7
- metadata +70 -61
- data/README.textile +0 -69
- data/javascripts/right-autocompleter-src.js +0 -318
- data/javascripts/right-autocompleter.js +0 -9
- data/javascripts/right-behavior-src.js +0 -261
- data/javascripts/right-behavior.js +0 -8
- data/javascripts/right-calendar-src.js +0 -946
- data/javascripts/right-calendar.js +0 -9
- data/javascripts/right-colorpicker-src.js +0 -635
- data/javascripts/right-colorpicker.js +0 -9
- data/javascripts/right-dnd.js +0 -9
- data/javascripts/right-effects.js +0 -6
- data/javascripts/right-events-src.js +0 -321
- data/javascripts/right-events.js +0 -6
- data/javascripts/right-in-edit-src.js +0 -194
- data/javascripts/right-in-edit.js +0 -6
- data/javascripts/right-json-src.js +0 -141
- data/javascripts/right-json.js +0 -6
- data/javascripts/right-lightbox-src.js +0 -651
- data/javascripts/right-lightbox.js +0 -9
- data/javascripts/right-olds.js +0 -9
- data/javascripts/right-rails.js +0 -9
- data/javascripts/right-rater-src.js +0 -253
- data/javascripts/right-rater.js +0 -9
- data/javascripts/right-resizable-src.js +0 -336
- data/javascripts/right-resizable.js +0 -9
- data/javascripts/right-selectable-src.js +0 -565
- data/javascripts/right-selectable.js +0 -7
- data/javascripts/right-slider-src.js +0 -288
- data/javascripts/right-slider.js +0 -7
- data/javascripts/right-sortable-src.js +0 -225
- data/javascripts/right-sortable.js +0 -9
- data/javascripts/right-tabs-src.js +0 -937
- data/javascripts/right-tabs.js +0 -6
- data/javascripts/right-tooltips-src.js +0 -195
- data/javascripts/right-tooltips.js +0 -9
- data/javascripts/right-uploader-src.js +0 -167
- data/javascripts/right-uploader.js +0 -9
- data/javascripts/right.js +0 -7
@@ -0,0 +1,392 @@
|
|
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 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.Wrapper(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
|
+
return this;
|
84
|
+
},
|
85
|
+
|
86
|
+
// protected
|
87
|
+
|
88
|
+
/**
|
89
|
+
* Catches the options
|
90
|
+
*
|
91
|
+
* @param Object user-options
|
92
|
+
* @param Element element with contextual options
|
93
|
+
* @return void
|
94
|
+
*/
|
95
|
+
setOptions: function(options, element) {
|
96
|
+
element = element || this;
|
97
|
+
RightJS.Options.setOptions.call(this,
|
98
|
+
RightJS.Object.merge(options, eval("("+(
|
99
|
+
element.get('data-'+ this.key) || '{}'
|
100
|
+
)+")"))
|
101
|
+
);
|
102
|
+
return this;
|
103
|
+
}
|
104
|
+
});
|
105
|
+
|
106
|
+
/**
|
107
|
+
* Creating the actual widget class
|
108
|
+
*
|
109
|
+
*/
|
110
|
+
var Klass = new RightJS.Wrapper(AbstractWidget, methods);
|
111
|
+
|
112
|
+
// creating the widget related shortcuts
|
113
|
+
RightJS.Observer.createShortcuts(Klass.prototype, Klass.EVENTS || []);
|
114
|
+
|
115
|
+
return Klass;
|
116
|
+
}
|
117
|
+
|
118
|
+
|
119
|
+
/**
|
120
|
+
* The Sortable unit
|
121
|
+
*
|
122
|
+
* Copyright (C) 2009-2010 Nikolay Nemshilov
|
123
|
+
*/
|
124
|
+
var Sortable = new Widget('UL', {
|
125
|
+
extend: {
|
126
|
+
version: '2.0.0',
|
127
|
+
|
128
|
+
EVENTS: $w('change'),
|
129
|
+
|
130
|
+
Options: {
|
131
|
+
url: null, // the Xhr requests url address, might contain the '%{id}' placeholder
|
132
|
+
method: 'put', // the Xhr requests method
|
133
|
+
|
134
|
+
Xhr: {}, // additional Xhr options
|
135
|
+
|
136
|
+
idParam: 'id', // the id value name
|
137
|
+
posParam: 'position', // the position value name
|
138
|
+
parseId: true, // if the id attribute should be converted into an integer before sending
|
139
|
+
|
140
|
+
dragClass: 'dragging', // the in-process class name
|
141
|
+
accept: null, // a reference or a list of references to the other sortables between which you can drag the items
|
142
|
+
minLength: 1, // minimum number of items on the list when the feature works
|
143
|
+
|
144
|
+
cssRule: '*[data-sortable]' // css-rule for automatically initializable sortables
|
145
|
+
},
|
146
|
+
|
147
|
+
current: false // a reference to the currently active sortable
|
148
|
+
},
|
149
|
+
|
150
|
+
/**
|
151
|
+
* basic constructor
|
152
|
+
*
|
153
|
+
* @param mixed element reference
|
154
|
+
* @param Object options
|
155
|
+
* @return void
|
156
|
+
*/
|
157
|
+
initialize: function(element, options) {
|
158
|
+
this.$super('sortable', element)
|
159
|
+
.setOptions(options)
|
160
|
+
.addClass('rui-sortable')
|
161
|
+
.on('change', this._tryXhr)
|
162
|
+
.on('selectstart', 'stopEvent'); // disable select under IE
|
163
|
+
},
|
164
|
+
|
165
|
+
/**
|
166
|
+
* some additional options processing
|
167
|
+
*
|
168
|
+
* @param Object options
|
169
|
+
* @param Element optional context
|
170
|
+
* @return Sortable this
|
171
|
+
*/
|
172
|
+
setOptions: function(options, context) {
|
173
|
+
this.$super(options, context);
|
174
|
+
|
175
|
+
options = this.options;
|
176
|
+
|
177
|
+
// Preprocessing the acceptance list
|
178
|
+
var list = options.accept || [];
|
179
|
+
if (!isArray(list)) { list = [list]; }
|
180
|
+
|
181
|
+
options.accept = R([this].concat(list)).map($).uniq();
|
182
|
+
|
183
|
+
return this;
|
184
|
+
},
|
185
|
+
|
186
|
+
// protected
|
187
|
+
|
188
|
+
// starts the drag
|
189
|
+
startDrag: function(event) {
|
190
|
+
// don't let to drag out the last item
|
191
|
+
if (this.children().length <= this.options.minLength) { return; }
|
192
|
+
|
193
|
+
// trying to find the list-item upon which the user pressed the mouse
|
194
|
+
var target = event.target, targets = R([target].concat(target.parents())),
|
195
|
+
item = targets[targets.indexOf(this) - 1], event_pos = event.position();
|
196
|
+
|
197
|
+
if (item) {
|
198
|
+
this._initDrag(item, event_pos);
|
199
|
+
Sortable.current = this;
|
200
|
+
}
|
201
|
+
},
|
202
|
+
|
203
|
+
// moves the item
|
204
|
+
moveItem: function(event) {
|
205
|
+
var event_pos = event.position(),
|
206
|
+
item = this.itemClone._.style,
|
207
|
+
top = event_pos.y - this.yRDiff,
|
208
|
+
left = event_pos.x - this.xRDiff,
|
209
|
+
right = left + this.cloneWidth,
|
210
|
+
bottom = top + this.cloneHeight;
|
211
|
+
|
212
|
+
// moving the clone
|
213
|
+
item.top = (event_pos.y - this.yDiff) + 'px';
|
214
|
+
item.left = (event_pos.x - this.xDiff) + 'px';
|
215
|
+
|
216
|
+
// checking for an overlaping item
|
217
|
+
var over_item = this.suspects.first(function(suspect) {
|
218
|
+
return (
|
219
|
+
(top > suspect.top && top < suspect.topHalf) ||
|
220
|
+
(bottom < suspect.bottom && bottom > suspect.topHalf)
|
221
|
+
) && (
|
222
|
+
(left > suspect.left && left < suspect.leftHalf) ||
|
223
|
+
(right < suspect.right && right > suspect.leftHalf)
|
224
|
+
);
|
225
|
+
});
|
226
|
+
|
227
|
+
if (over_item) {
|
228
|
+
item = over_item.item;
|
229
|
+
item.insert(this.item, item.prevSiblings().include(this.item) ? 'after' : 'before');
|
230
|
+
this._findSuspects();
|
231
|
+
|
232
|
+
// sending the event
|
233
|
+
var list = item.parent();
|
234
|
+
|
235
|
+
if (!(list instanceof Sortable)) {
|
236
|
+
list = new Sortable(list);
|
237
|
+
}
|
238
|
+
|
239
|
+
this.fire('change', {
|
240
|
+
list: list,
|
241
|
+
item: this.item,
|
242
|
+
index: list.children().indexOf(this.item)
|
243
|
+
});
|
244
|
+
}
|
245
|
+
},
|
246
|
+
|
247
|
+
// finalizes the drag
|
248
|
+
finishDrag: function() {
|
249
|
+
if (this.itemClone) {
|
250
|
+
this.itemClone.remove();
|
251
|
+
this.item.setStyle('visibility:visible');
|
252
|
+
}
|
253
|
+
Sortable.current = false;
|
254
|
+
},
|
255
|
+
|
256
|
+
_initDrag: function(item, event_pos) {
|
257
|
+
var dims = this.dimensions(), item_dims = item.dimensions();
|
258
|
+
|
259
|
+
// creating the draggable clone
|
260
|
+
var clone = item.clone().setStyle({
|
261
|
+
margin: 0,
|
262
|
+
zIndex: 9999,
|
263
|
+
position: 'absolute',
|
264
|
+
top: '0px',
|
265
|
+
left: '0px'
|
266
|
+
})
|
267
|
+
.addClass(this.options.dragClass).insertTo(this)
|
268
|
+
.setHeight(this.cloneHeight = item_dims.height)
|
269
|
+
.setWidth(this.cloneWidth = item_dims.width);
|
270
|
+
|
271
|
+
// adjusting the clone position to compensate relative fields and margins
|
272
|
+
var clone_pos = clone.position(),
|
273
|
+
real_x = item_dims.left - clone_pos.x,
|
274
|
+
real_y = item_dims.top - clone_pos.y;
|
275
|
+
|
276
|
+
clone.moveTo(real_x, real_y);
|
277
|
+
|
278
|
+
this.item = item.setStyle('visibility:hidden');
|
279
|
+
this.itemClone = clone;
|
280
|
+
|
281
|
+
// mouse event-position diffs
|
282
|
+
this.xDiff = event_pos.x - real_x;
|
283
|
+
this.yDiff = event_pos.y - real_y;
|
284
|
+
this.xRDiff = event_pos.x - clone.position().x;
|
285
|
+
this.yRDiff = event_pos.y - clone.position().y;
|
286
|
+
|
287
|
+
// collecting the list of interchangable items with their positions
|
288
|
+
this._findSuspects();
|
289
|
+
},
|
290
|
+
|
291
|
+
// collects the precached list of suspects
|
292
|
+
_findSuspects: function() {
|
293
|
+
var suspects = this.suspects = R([]), item = this.item, clone = this.itemClone;
|
294
|
+
this.options.accept.each(function(list) {
|
295
|
+
list.children().each(function(element) {
|
296
|
+
if (element !== item && element !== clone) {
|
297
|
+
var dims = element.dimensions();
|
298
|
+
|
299
|
+
// caching the sizes
|
300
|
+
suspects.push({
|
301
|
+
item: element,
|
302
|
+
top: dims.top,
|
303
|
+
left: dims.left,
|
304
|
+
right: dims.left + dims.width,
|
305
|
+
bottom: dims.top + dims.height,
|
306
|
+
topHalf: dims.top + dims.height/2,
|
307
|
+
leftHalf: dims.left + dims.width/2
|
308
|
+
});
|
309
|
+
}
|
310
|
+
});
|
311
|
+
});
|
312
|
+
},
|
313
|
+
|
314
|
+
// tries to send an Xhr request about the element relocation
|
315
|
+
_tryXhr: function(event) {
|
316
|
+
if (this.options.url) {
|
317
|
+
var url = R(this.options.url), params = {}, item = event.item, position = event.index + 1;
|
318
|
+
|
319
|
+
// building the Xhr request options
|
320
|
+
var options = Object.merge({
|
321
|
+
method: this.options.method,
|
322
|
+
params: {}
|
323
|
+
}, this.options.Xhr);
|
324
|
+
|
325
|
+
// grabbing the id
|
326
|
+
var id = item.get('id') || '';
|
327
|
+
if (this.options.parseId && id) {
|
328
|
+
id = (id.match(/\d+/) || [''])[0];
|
329
|
+
}
|
330
|
+
|
331
|
+
// assigning the parameters
|
332
|
+
if (url.include('%{id}')) {
|
333
|
+
url = url.replace('%{id}', id);
|
334
|
+
} else {
|
335
|
+
params[this.options.idParam] = id;
|
336
|
+
}
|
337
|
+
params[this.options.posParam] = position;
|
338
|
+
|
339
|
+
// merging the params with possible Xhr params
|
340
|
+
if (isString(options.params)) {
|
341
|
+
options.params += '&'+Object.toQueryString(params);
|
342
|
+
} else {
|
343
|
+
options.params = Object.merge(options.params, params);
|
344
|
+
}
|
345
|
+
|
346
|
+
// calling the server
|
347
|
+
RightJS.Xhr.load(url, options);
|
348
|
+
}
|
349
|
+
}
|
350
|
+
});
|
351
|
+
|
352
|
+
/**
|
353
|
+
* Document level hooks for sortables
|
354
|
+
*
|
355
|
+
* Copyright (C) 2009-2010 Nikolay Nemshilov
|
356
|
+
*/
|
357
|
+
$(document).on({
|
358
|
+
mousedown: function(event) {
|
359
|
+
var element = event.find(Sortable.Options.cssRule);
|
360
|
+
|
361
|
+
if (element) {
|
362
|
+
if (!(element instanceof Sortable)) {
|
363
|
+
element = new Sortable(element);
|
364
|
+
}
|
365
|
+
|
366
|
+
element.startDrag(event);
|
367
|
+
}
|
368
|
+
},
|
369
|
+
|
370
|
+
mousemove: function(event) {
|
371
|
+
if (Sortable.current) {
|
372
|
+
Sortable.current.moveItem(event);
|
373
|
+
}
|
374
|
+
},
|
375
|
+
|
376
|
+
mouseup: function() {
|
377
|
+
if (Sortable.current) {
|
378
|
+
Sortable.current.finishDrag();
|
379
|
+
}
|
380
|
+
}
|
381
|
+
});
|
382
|
+
|
383
|
+
$(window).onBlur(function() {
|
384
|
+
if (Sortable.current) {
|
385
|
+
Sortable.current.finishDrag();
|
386
|
+
}
|
387
|
+
});
|
388
|
+
|
389
|
+
document.write("<style type=\"text/css\">.rui-sortable{user-select:none;-moz-user-select:none;-webkit-user-select:none}</style>");
|
390
|
+
|
391
|
+
return Sortable;
|
392
|
+
})(document, RightJS);
|
@@ -0,0 +1,16 @@
|
|
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(l,f){var j=f.$,m=f.$w,n=f.isString,o=f.isArray,k=f.Object,h=new (function(a,b){if(!b){b=a;a="DIV"}var d=new f.Wrapper(f.Element.Wrappers[a]||f.Element,{initialize:function(e,c){this.key=e;var g=[{"class":"rui-"+e}];this instanceof f.Input||this instanceof f.Form||g.unshift(a);this.$super.apply(this,g);if(f.isString(c))c=f.$(c);if(c instanceof f.Element){this._=c._;if("$listeners"in c)c.$listeners=c.$listeners;c={}}this.setOptions(c,this);return this},setOptions:function(e,
|
10
|
+
c){c=c||this;f.Options.setOptions.call(this,f.Object.merge(e,eval("("+(c.get("data-"+this.key)||"{}")+")")));return this}});d=new f.Wrapper(d,b);f.Observer.createShortcuts(d.prototype,d.EVENTS||[]);return d})("UL",{extend:{version:"2.0.0",EVENTS:m("change"),Options:{url:null,method:"put",Xhr:{},idParam:"id",posParam:"position",parseId:true,dragClass:"dragging",accept:null,minLength:1,cssRule:"*[data-sortable]"},current:false},initialize:function(a,b){this.$super("sortable",a).setOptions(b).addClass("rui-sortable").on("change",
|
11
|
+
this._tryXhr).on("selectstart","stopEvent")},setOptions:function(a,b){this.$super(a,b);a=this.options;var d=a.accept||[];o(d)||(d=[d]);a.accept=f([this].concat(d)).map(j).uniq();return this},startDrag:function(a){if(!(this.children().length<=this.options.minLength)){var b=a.target;b=f([b].concat(b.parents()));b=b[b.indexOf(this)-1];a=a.position();if(b){this._initDrag(b,a);h.current=this}}},moveItem:function(a){a=a.position();var b=this.itemClone._.style,d=a.y-this.yRDiff,e=a.x-this.xRDiff,c=e+this.cloneWidth,
|
12
|
+
g=d+this.cloneHeight;b.top=a.y-this.yDiff+"px";b.left=a.x-this.xDiff+"px";if(a=this.suspects.first(function(i){return(d>i.top&&d<i.topHalf||g<i.bottom&&g>i.topHalf)&&(e>i.left&&e<i.leftHalf||c<i.right&&c>i.leftHalf)})){b=a.item;b.insert(this.item,b.prevSiblings().include(this.item)?"after":"before");this._findSuspects();a=b.parent();a instanceof h||(a=new h(a));this.fire("change",{list:a,item:this.item,index:a.children().indexOf(this.item)})}},finishDrag:function(){if(this.itemClone){this.itemClone.remove();
|
13
|
+
this.item.setStyle("visibility:visible")}h.current=false},_initDrag:function(a,b){this.dimensions();var d=a.dimensions(),e=a.clone().setStyle({margin:0,zIndex:9999,position:"absolute",top:"0px",left:"0px"}).addClass(this.options.dragClass).insertTo(this).setHeight(this.cloneHeight=d.height).setWidth(this.cloneWidth=d.width),c=e.position(),g=d.left-c.x;d=d.top-c.y;e.moveTo(g,d);this.item=a.setStyle("visibility:hidden");this.itemClone=e;this.xDiff=b.x-g;this.yDiff=b.y-d;this.xRDiff=b.x-e.position().x;
|
14
|
+
this.yRDiff=b.y-e.position().y;this._findSuspects()},_findSuspects:function(){var a=this.suspects=f([]),b=this.item,d=this.itemClone;this.options.accept.each(function(e){e.children().each(function(c){if(c!==b&&c!==d){var g=c.dimensions();a.push({item:c,top:g.top,left:g.left,right:g.left+g.width,bottom:g.top+g.height,topHalf:g.top+g.height/2,leftHalf:g.left+g.width/2})}})})},_tryXhr:function(a){if(this.options.url){var b=f(this.options.url),d={},e=a.item;a=a.index+1;var c=k.merge({method:this.options.method,
|
15
|
+
params:{}},this.options.Xhr);e=e.get("id")||"";if(this.options.parseId&&e)e=(e.match(/\d+/)||[""])[0];if(b.include("%{id}"))b=b.replace("%{id}",e);else d[this.options.idParam]=e;d[this.options.posParam]=a;if(n(c.params))c.params+="&"+k.toQueryString(d);else c.params=k.merge(c.params,d);f.Xhr.load(b,c)}}});j(l).on({mousedown:function(a){var b=a.find(h.Options.cssRule);if(b){b instanceof h||(b=new h(b));b.startDrag(a)}},mousemove:function(a){h.current&&h.current.moveItem(a)},mouseup:function(){h.current&&
|
16
|
+
h.current.finishDrag()}});j(window).onBlur(function(){h.current&&h.current.finishDrag()});l.write('<style type="text/css">.rui-sortable{user-select:none;-moz-user-select:none;-webkit-user-select:none}</style>');return h}(document,RightJS);
|