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,612 @@
|
|
1
|
+
/**
|
2
|
+
* RightJS-UI: Autocompleter
|
3
|
+
* http://rightjs.org/ui/autocompleter
|
4
|
+
*
|
5
|
+
* Copyright (C) 2010 Nikolay Nemshilov
|
6
|
+
*/
|
7
|
+
var Autocompleter = RightJS.Autocompleter = (function(document, RightJS) {
|
8
|
+
/**
|
9
|
+
* This module defines the basic widgets constructor
|
10
|
+
* it creates an abstract proxy with the common functionality
|
11
|
+
* which then we reuse and override in the actual widgets
|
12
|
+
*
|
13
|
+
* Copyright (C) 2010 Nikolay Nemshilov
|
14
|
+
*/
|
15
|
+
|
16
|
+
/**
|
17
|
+
* Autocompleter initializer
|
18
|
+
*
|
19
|
+
* Copyright (C) 2010 Nikolay Nemshilov
|
20
|
+
*/
|
21
|
+
var R = RightJS,
|
22
|
+
$ = RightJS.$,
|
23
|
+
$w = RightJS.$w,
|
24
|
+
$E = RightJS.$E,
|
25
|
+
Xhr = RightJS.Xhr,
|
26
|
+
RegExp = RightJS.RegExp,
|
27
|
+
isArray = RightJS.isArray;
|
28
|
+
|
29
|
+
|
30
|
+
|
31
|
+
|
32
|
+
|
33
|
+
|
34
|
+
|
35
|
+
|
36
|
+
/**
|
37
|
+
* The widget units constructor
|
38
|
+
*
|
39
|
+
* @param String tag-name or Object methods
|
40
|
+
* @param Object methods
|
41
|
+
* @return Widget wrapper
|
42
|
+
*/
|
43
|
+
function Widget(tag_name, methods) {
|
44
|
+
if (!methods) {
|
45
|
+
methods = tag_name;
|
46
|
+
tag_name = 'DIV';
|
47
|
+
}
|
48
|
+
|
49
|
+
/**
|
50
|
+
* An Abstract Widget Unit
|
51
|
+
*
|
52
|
+
* Copyright (C) 2010 Nikolay Nemshilov
|
53
|
+
*/
|
54
|
+
var AbstractWidget = new RightJS.Wrapper(RightJS.Element.Wrappers[tag_name] || RightJS.Element, {
|
55
|
+
/**
|
56
|
+
* The common constructor
|
57
|
+
*
|
58
|
+
* @param Object options
|
59
|
+
* @param String optional tag name
|
60
|
+
* @return void
|
61
|
+
*/
|
62
|
+
initialize: function(key, options) {
|
63
|
+
this.key = key;
|
64
|
+
var args = [{'class': 'rui-' + key}];
|
65
|
+
|
66
|
+
// those two have different constructors
|
67
|
+
if (!(this instanceof RightJS.Input || this instanceof RightJS.Form)) {
|
68
|
+
args.unshift(tag_name);
|
69
|
+
}
|
70
|
+
this.$super.apply(this, args);
|
71
|
+
|
72
|
+
if (RightJS.isString(options)) {
|
73
|
+
options = RightJS.$(options);
|
74
|
+
}
|
75
|
+
|
76
|
+
// if the options is another element then
|
77
|
+
// try to dynamically rewrap it with our widget
|
78
|
+
if (options instanceof RightJS.Element) {
|
79
|
+
this._ = options._;
|
80
|
+
if ('$listeners' in options) {
|
81
|
+
options.$listeners = options.$listeners;
|
82
|
+
}
|
83
|
+
options = {};
|
84
|
+
}
|
85
|
+
this.setOptions(options, this);
|
86
|
+
return this;
|
87
|
+
},
|
88
|
+
|
89
|
+
// protected
|
90
|
+
|
91
|
+
/**
|
92
|
+
* Catches the options
|
93
|
+
*
|
94
|
+
* @param Object user-options
|
95
|
+
* @param Element element with contextual options
|
96
|
+
* @return void
|
97
|
+
*/
|
98
|
+
setOptions: function(options, element) {
|
99
|
+
element = element || this;
|
100
|
+
RightJS.Options.setOptions.call(this,
|
101
|
+
RightJS.Object.merge(options, eval("("+(
|
102
|
+
element.get('data-'+ this.key) || '{}'
|
103
|
+
)+")"))
|
104
|
+
);
|
105
|
+
return this;
|
106
|
+
}
|
107
|
+
});
|
108
|
+
|
109
|
+
/**
|
110
|
+
* Creating the actual widget class
|
111
|
+
*
|
112
|
+
*/
|
113
|
+
var Klass = new RightJS.Wrapper(AbstractWidget, methods);
|
114
|
+
|
115
|
+
// creating the widget related shortcuts
|
116
|
+
RightJS.Observer.createShortcuts(Klass.prototype, Klass.EVENTS || []);
|
117
|
+
|
118
|
+
return Klass;
|
119
|
+
}
|
120
|
+
|
121
|
+
|
122
|
+
/**
|
123
|
+
* A shared module to create textual spinners
|
124
|
+
*
|
125
|
+
* Copyright (C) 2010 Nikolay Nemshilov
|
126
|
+
*/
|
127
|
+
var Spinner = new RightJS.Wrapper(RightJS.Element, {
|
128
|
+
/**
|
129
|
+
* Constructor
|
130
|
+
*
|
131
|
+
* @param Number optional spinner size (4 by default)
|
132
|
+
* @return void
|
133
|
+
*/
|
134
|
+
initialize: function(size) {
|
135
|
+
this.$super('div', {'class': 'rui-spinner'});
|
136
|
+
this.dots = [];
|
137
|
+
|
138
|
+
for (var i=0; i < (size || 4); i++) {
|
139
|
+
this.dots.push(new RightJS.Element('div'));
|
140
|
+
}
|
141
|
+
|
142
|
+
this.dots[0].addClass('glowing');
|
143
|
+
this.insert(this.dots);
|
144
|
+
RightJS(this.shift).bind(this).periodical(300);
|
145
|
+
},
|
146
|
+
|
147
|
+
/**
|
148
|
+
* Shifts the spinner elements
|
149
|
+
*
|
150
|
+
* @return void
|
151
|
+
*/
|
152
|
+
shift: function() {
|
153
|
+
if (this.visible()) {
|
154
|
+
var dot = this.dots.pop();
|
155
|
+
this.dots.unshift(dot);
|
156
|
+
this.insert(dot, 'top');
|
157
|
+
}
|
158
|
+
}
|
159
|
+
});
|
160
|
+
|
161
|
+
/**
|
162
|
+
* A shared module that toggles a widget visibility status
|
163
|
+
* in a uniformed way according to the options settings
|
164
|
+
*
|
165
|
+
* Copyright (C) 2010 Nikolay Nemshilov
|
166
|
+
*/
|
167
|
+
|
168
|
+
/**
|
169
|
+
* The toggler's common functionality
|
170
|
+
*
|
171
|
+
* NOTE: this function getting called in the context
|
172
|
+
* of a widget
|
173
|
+
*
|
174
|
+
* @param Element the element to toggle
|
175
|
+
* @param event String 'show' or 'hide' the event name
|
176
|
+
* @param String an optional fx-name
|
177
|
+
* @param Object an optional fx-options hash
|
178
|
+
* @return void
|
179
|
+
*/
|
180
|
+
function toggler(element, event, fx_name, fx_options) {
|
181
|
+
if (RightJS.Fx) {
|
182
|
+
if (fx_name === undefined) {
|
183
|
+
fx_name = this.options.fxName;
|
184
|
+
|
185
|
+
if (fx_options === undefined) {
|
186
|
+
fx_options = {
|
187
|
+
duration: this.options.fxDuration,
|
188
|
+
onFinish: RightJS(this.fire).bind(this, event)
|
189
|
+
};
|
190
|
+
|
191
|
+
// hide on double time
|
192
|
+
if (event === 'hide') {
|
193
|
+
fx_options.duration = (RightJS.Fx.Durations[fx_options.duration] ||
|
194
|
+
fx_options.duration) / 2;
|
195
|
+
}
|
196
|
+
}
|
197
|
+
}
|
198
|
+
}
|
199
|
+
|
200
|
+
RightJS.Element.prototype[event].call(element, fx_name, fx_options);
|
201
|
+
|
202
|
+
// manually trigger the event if no fx were specified
|
203
|
+
if (!RightJS.Fx || !fx_name) { this.fire(event); }
|
204
|
+
|
205
|
+
return this;
|
206
|
+
}
|
207
|
+
|
208
|
+
/**
|
209
|
+
* Relatively positions the current element
|
210
|
+
* against the specified one
|
211
|
+
*
|
212
|
+
* NOTE: this function is called in a context
|
213
|
+
* of another element
|
214
|
+
*
|
215
|
+
* @param Element the target element
|
216
|
+
* @param String position 'right' or 'bottom'
|
217
|
+
* @param Boolean if `true` then the element size will be adjusted
|
218
|
+
* @return void
|
219
|
+
*/
|
220
|
+
function re_position(element, where, resize) {
|
221
|
+
var anchor = this.reAnchor || (this.reAnchor =
|
222
|
+
new RightJS.Element('div', {'class': 'rui-re-anchor'}))
|
223
|
+
.insert(this),
|
224
|
+
|
225
|
+
pos = anchor.insertTo(element, 'after').position(),
|
226
|
+
dims = element.dimensions(), target = this,
|
227
|
+
|
228
|
+
border_top = parseInt(element.getStyle('borderTopWidth')),
|
229
|
+
border_left = parseInt(element.getStyle('borderLeftWidth')),
|
230
|
+
border_right = parseInt(element.getStyle('borderRightWidth')),
|
231
|
+
border_bottom = parseInt(element.getStyle('borderBottomWidth')),
|
232
|
+
|
233
|
+
top = dims.top - pos.y + border_top,
|
234
|
+
left = dims.left - pos.x + border_left,
|
235
|
+
width = dims.width - border_left - border_right,
|
236
|
+
height = dims.height - border_top - border_bottom;
|
237
|
+
|
238
|
+
// making the element to appear so we could read it's sizes
|
239
|
+
target.setStyle('visibility:hidden').show(null);
|
240
|
+
|
241
|
+
if (where === 'right') {
|
242
|
+
left += width - target.size().x;
|
243
|
+
} else { // bottom
|
244
|
+
top += height;
|
245
|
+
}
|
246
|
+
|
247
|
+
target.moveTo(left, top);
|
248
|
+
|
249
|
+
if (resize) {
|
250
|
+
if (['left', 'right'].include(where)) {
|
251
|
+
target.setHeight(height);
|
252
|
+
} else {
|
253
|
+
target.setWidth(width);
|
254
|
+
}
|
255
|
+
}
|
256
|
+
|
257
|
+
// rolling the invisibility back
|
258
|
+
target.setStyle('visibility:visible').hide(null);
|
259
|
+
}
|
260
|
+
|
261
|
+
/**
|
262
|
+
* The actual shared module to be inserted in the widgets
|
263
|
+
*
|
264
|
+
* Copyright (C) 2010 Nikolay Nemshilov
|
265
|
+
*/
|
266
|
+
var Toggler = {
|
267
|
+
/**
|
268
|
+
* Shows the element
|
269
|
+
*
|
270
|
+
* @param String fx-name
|
271
|
+
* @param Object fx-options
|
272
|
+
* @return Element this
|
273
|
+
*/
|
274
|
+
show: function(fx_name, fx_options) {
|
275
|
+
this.constructor.current = this;
|
276
|
+
return toggler.call(this, this, 'show', fx_name, fx_options);
|
277
|
+
},
|
278
|
+
|
279
|
+
/**
|
280
|
+
* Hides the element
|
281
|
+
*
|
282
|
+
* @param String fx-name
|
283
|
+
* @param Object fx-options
|
284
|
+
* @return Element this
|
285
|
+
*/
|
286
|
+
hide: function(fx_name, fx_options) {
|
287
|
+
this.constructor.current = null;
|
288
|
+
return toggler.call(this, this, 'hide', fx_name, fx_options);
|
289
|
+
},
|
290
|
+
|
291
|
+
/**
|
292
|
+
* Toggles the widget at the given element
|
293
|
+
*
|
294
|
+
* @param Element the related element
|
295
|
+
* @param String position right/bottom (bottom is the default)
|
296
|
+
* @param Boolean marker if the element should be resized to the element size
|
297
|
+
* @return Widget this
|
298
|
+
*/
|
299
|
+
showAt: function(element, where, resize) {
|
300
|
+
this.hide(null).shownAt = element = RightJS.$(element);
|
301
|
+
|
302
|
+
// moves this element at the given one
|
303
|
+
re_position.call(this, element, where, resize);
|
304
|
+
|
305
|
+
return this.show();
|
306
|
+
},
|
307
|
+
|
308
|
+
/**
|
309
|
+
* Toggles the widget at the given element
|
310
|
+
*
|
311
|
+
* @param Element the related element
|
312
|
+
* @param String position top/left/right/bottom (bottom is the default)
|
313
|
+
* @param Boolean marker if the element should be resized to the element size
|
314
|
+
* @return Widget this
|
315
|
+
*/
|
316
|
+
toggleAt: function(element, where, resize) {
|
317
|
+
return this.hidden() ? this.showAt(element, where, resize) : this.hide();
|
318
|
+
}
|
319
|
+
};
|
320
|
+
|
321
|
+
/**
|
322
|
+
* The RightJS UI Autocompleter unit base class
|
323
|
+
*
|
324
|
+
* Copyright (C) 2009-2010 Nikolay Nemshilov
|
325
|
+
*/
|
326
|
+
var Autocompleter = new Widget('UL', {
|
327
|
+
include: Toggler,
|
328
|
+
|
329
|
+
extend: {
|
330
|
+
version: '2.0.0',
|
331
|
+
|
332
|
+
EVENTS: $w('show hide update load select done'),
|
333
|
+
|
334
|
+
Options: {
|
335
|
+
url: document.location.href,
|
336
|
+
param: 'search',
|
337
|
+
method: 'get',
|
338
|
+
|
339
|
+
minLength: 1, // the minimal length when it starts work
|
340
|
+
threshold: 200, // the typing pause threshold
|
341
|
+
|
342
|
+
cache: true, // use the results cache
|
343
|
+
local: null, // an optional local search results list
|
344
|
+
|
345
|
+
fxName: 'slide', // list appearance fx name
|
346
|
+
fxDuration: 'short', // list appearance fx duration
|
347
|
+
|
348
|
+
spinner: 'native', // spinner element reference
|
349
|
+
|
350
|
+
cssRule: 'input[data-autocompleter]' // the auto-initialization css-rule
|
351
|
+
}
|
352
|
+
},
|
353
|
+
|
354
|
+
/**
|
355
|
+
* basic constructor
|
356
|
+
*
|
357
|
+
* @param mixed the input element reference, a string id or the element instance
|
358
|
+
* @param Object options
|
359
|
+
*/
|
360
|
+
initialize: function(input, options) {
|
361
|
+
this.input = $(input); // KEEP IT before the super call
|
362
|
+
|
363
|
+
this
|
364
|
+
.$super('autocompleter', options)
|
365
|
+
.addClass('rui-dd-menu')
|
366
|
+
.onMousedown(this.clicked);
|
367
|
+
|
368
|
+
this.input.autocompleter = this;
|
369
|
+
},
|
370
|
+
|
371
|
+
/**
|
372
|
+
* Destructor
|
373
|
+
*
|
374
|
+
* @return Autocompleter this
|
375
|
+
*/
|
376
|
+
destroy: function() {
|
377
|
+
delete(this.input.autocompleter);
|
378
|
+
return this;
|
379
|
+
},
|
380
|
+
|
381
|
+
/**
|
382
|
+
* picks the next item on the list
|
383
|
+
*
|
384
|
+
* @return Autocompleter this
|
385
|
+
*/
|
386
|
+
prev: function() {
|
387
|
+
return this.pick('prev');
|
388
|
+
},
|
389
|
+
|
390
|
+
/**
|
391
|
+
* picks the next item on the list
|
392
|
+
*
|
393
|
+
* @return Autocompleter this
|
394
|
+
*/
|
395
|
+
next: function() {
|
396
|
+
return this.pick('next');
|
397
|
+
},
|
398
|
+
|
399
|
+
/**
|
400
|
+
* triggers the done event, sets up the value and closes the list
|
401
|
+
*
|
402
|
+
* @return Autocompleter this
|
403
|
+
*/
|
404
|
+
done: function(current) {
|
405
|
+
current = current || this.first('li.current');
|
406
|
+
|
407
|
+
if (current) {
|
408
|
+
this.input.setValue(R(current.html()).stripTags());
|
409
|
+
this.fire('done');
|
410
|
+
}
|
411
|
+
|
412
|
+
return this.hide();
|
413
|
+
},
|
414
|
+
|
415
|
+
// protected
|
416
|
+
|
417
|
+
// preprocessing the urls a bit
|
418
|
+
setOptions: function(options) {
|
419
|
+
this.$super(options, this.input);
|
420
|
+
|
421
|
+
options = this.options;
|
422
|
+
|
423
|
+
// building the correct url template with a placeholder
|
424
|
+
if (!R(options.url).includes('%{search}')) {
|
425
|
+
options.url += (R(options.url).includes('?') ? '&' : '?') + options.param + '=%{search}';
|
426
|
+
}
|
427
|
+
},
|
428
|
+
|
429
|
+
// works with the 'prev' and 'next' methods
|
430
|
+
pick: function(which_one) {
|
431
|
+
var items = this.children(),
|
432
|
+
current = items.first('hasClass', 'current'),
|
433
|
+
index = items.indexOf(current);
|
434
|
+
|
435
|
+
if (which_one == 'prev') {
|
436
|
+
current = index < 1 ? items.last() : items[index < 0 ? 0 : (index-1)];
|
437
|
+
} else if (which_one == 'next') {
|
438
|
+
current = index < 0 || index == (items.length - 1) ?
|
439
|
+
items.first() : items[index + 1];
|
440
|
+
}
|
441
|
+
|
442
|
+
return this.fire('select', current.radioClass('current'));
|
443
|
+
},
|
444
|
+
|
445
|
+
// handles mouse clicks on the list element
|
446
|
+
clicked: function(event) {
|
447
|
+
this.done(event.stop().find('li'));
|
448
|
+
},
|
449
|
+
|
450
|
+
// handles the key-press events
|
451
|
+
keypressed: function(event) {
|
452
|
+
if (this.input.value().length >= this.options.minLength) {
|
453
|
+
if (this.timeout) {
|
454
|
+
this.timeout.cancel();
|
455
|
+
}
|
456
|
+
this.timeout = R(this.trigger).bind(this).delay(this.options.threshold);
|
457
|
+
} else {
|
458
|
+
return this.hide();
|
459
|
+
}
|
460
|
+
},
|
461
|
+
|
462
|
+
// triggers the actual action
|
463
|
+
trigger: function() {
|
464
|
+
this.timeout = null;
|
465
|
+
|
466
|
+
this.cache = this.cache || {};
|
467
|
+
var search = this.input.value(), options = this.options;
|
468
|
+
|
469
|
+
if (search.length < options.minLength) { return this.hide(); }
|
470
|
+
|
471
|
+
if (this.cache[search]) {
|
472
|
+
this.suggest(this.cache[search], search);
|
473
|
+
} else if (isArray(options.local)) {
|
474
|
+
this.suggest(this.findLocal(search), search);
|
475
|
+
} else {
|
476
|
+
this.request = Xhr.load(options.url.replace('%{search}', encodeURIComponent(search)), {
|
477
|
+
method: options.method,
|
478
|
+
spinner: this.getSpinner(),
|
479
|
+
onComplete: R(function(response) {
|
480
|
+
this.fire('load').suggest(response.text, search);
|
481
|
+
}).bind(this)
|
482
|
+
});
|
483
|
+
}
|
484
|
+
},
|
485
|
+
|
486
|
+
// updates the suggestions list
|
487
|
+
suggest: function(result_text, search) {
|
488
|
+
// saving the result in cache
|
489
|
+
if (this.options.cache) {
|
490
|
+
this.cache[search] = result_text;
|
491
|
+
}
|
492
|
+
|
493
|
+
if (!(result_text).blank()) {
|
494
|
+
this.update(result_text.replace(/<ul[^>]*>|<\/ul>/im, ''));
|
495
|
+
this.fire('update').showAt(this.input, 'bottom', 'resize');
|
496
|
+
} else {
|
497
|
+
this.hide();
|
498
|
+
}
|
499
|
+
|
500
|
+
return this;
|
501
|
+
},
|
502
|
+
|
503
|
+
// performs the locals search
|
504
|
+
findLocal: function(search) {
|
505
|
+
var regexp = new RegExp("("+RegExp.escape(search)+")", 'ig');
|
506
|
+
|
507
|
+
return R(this.options.local).map(function(option) {
|
508
|
+
if (option.match(regexp)) {
|
509
|
+
return '<li>'+ option.replace(regexp, '<strong>$1</strong>') +'</li>';
|
510
|
+
}
|
511
|
+
}).compact().join('');
|
512
|
+
},
|
513
|
+
|
514
|
+
// builds a native textual spinner if necessary
|
515
|
+
getSpinner: function() {
|
516
|
+
var options = this.options, spinner = options.spinner;
|
517
|
+
|
518
|
+
if (spinner == 'native') {
|
519
|
+
spinner = options.spinner = new Spinner(3).insertTo(this);
|
520
|
+
spinner.addClass('rui-autocompleter-spinner');
|
521
|
+
}
|
522
|
+
|
523
|
+
// positioning the native spinner
|
524
|
+
if (spinner instanceof Spinner) {
|
525
|
+
re_position.call(spinner, this.input, 'right', 'resize');
|
526
|
+
}
|
527
|
+
|
528
|
+
return spinner;
|
529
|
+
}
|
530
|
+
});
|
531
|
+
|
532
|
+
/**
|
533
|
+
* The document events hooking
|
534
|
+
*
|
535
|
+
* Copyright (C) 2009-2010 Nikolay Nemshilov
|
536
|
+
*/
|
537
|
+
$(document).on({
|
538
|
+
/**
|
539
|
+
* Initializes autocompleters on-focus
|
540
|
+
*
|
541
|
+
* @param Event focus
|
542
|
+
* @return void
|
543
|
+
*/
|
544
|
+
focus: function(event) {
|
545
|
+
var target = event.target;
|
546
|
+
|
547
|
+
if (target && (target instanceof RightJS.Element) && (target.autocompleter || target.match(Autocompleter.Options.cssRule))) {
|
548
|
+
if (!target.autocompleter) {
|
549
|
+
new Autocompleter(target);
|
550
|
+
}
|
551
|
+
}
|
552
|
+
},
|
553
|
+
|
554
|
+
/**
|
555
|
+
* Hides autocompleters on-blur
|
556
|
+
*
|
557
|
+
* @param Event blur
|
558
|
+
* @return void
|
559
|
+
*/
|
560
|
+
blur: function(event) {
|
561
|
+
var autocompleter = event.target ? event.target.autocompleter : null;
|
562
|
+
|
563
|
+
if (autocompleter && autocompleter.visible()) {
|
564
|
+
autocompleter.hide();
|
565
|
+
}
|
566
|
+
},
|
567
|
+
|
568
|
+
/**
|
569
|
+
* Catching the basic keyboard events
|
570
|
+
* to navigate through the autocompletion list
|
571
|
+
*
|
572
|
+
* @param Event keydown
|
573
|
+
* @return void
|
574
|
+
*/
|
575
|
+
keydown: function(event) {
|
576
|
+
var autocompleter = event.target ? event.target.autocompleter : null;
|
577
|
+
|
578
|
+
if (autocompleter && autocompleter.visible()) {
|
579
|
+
var method_name = ({
|
580
|
+
27: 'hide', // Esc
|
581
|
+
38: 'prev', // Up
|
582
|
+
40: 'next', // Down
|
583
|
+
13: 'done' // Enter
|
584
|
+
})[event.keyCode];
|
585
|
+
|
586
|
+
if (method_name) {
|
587
|
+
event.stop();
|
588
|
+
autocompleter[method_name]();
|
589
|
+
}
|
590
|
+
}
|
591
|
+
},
|
592
|
+
|
593
|
+
/**
|
594
|
+
* Catches the input fields keyup events
|
595
|
+
* and tries to make the autocompleter to show some suggestions
|
596
|
+
*
|
597
|
+
* @param Event keyup
|
598
|
+
* @return void
|
599
|
+
*/
|
600
|
+
keyup: function(event) {
|
601
|
+
var autocompleter = event.target ? event.target.autocompleter : null;
|
602
|
+
|
603
|
+
if (autocompleter && !R([9, 27, 37, 38, 39, 40, 13]).include(event.keyCode)) {
|
604
|
+
autocompleter.keypressed(event);
|
605
|
+
}
|
606
|
+
}
|
607
|
+
});
|
608
|
+
|
609
|
+
document.write("<style type=\"text/css\"> *.rui-dd-menu, *.rui-dd-menu li{margin:0;padding:0;border:none;background:none;list-style:none;font-weight:normal;float:none} *.rui-dd-menu{display:none;position:absolute;z-index:9999;background:white;border:1px solid #BBB;border-radius:.2em;-moz-border-radius:.2em;-webkit-border-radius:.2em;box-shadow:#DDD .2em .2em .4em;-moz-box-shadow:#DDD .2em .2em .4em;-webkit-box-shadow:#DDD .2em .2em .4em} *.rui-dd-menu li{padding:.2em .4em;border-top:none;border-bottom:none;cursor:pointer} *.rui-dd-menu li.current{background:#DDD} *.rui-dd-menu li:hover{background:#EEE}dl.rui-dd-menu dt{padding:.3em .5em;cursor:default;font-weight:bold;font-style:italic;color:#444;background:#EEE}dl.rui-dd-menu dd li{padding-left:1.5em}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-re-anchor{margin:0;padding:0;background:none;border:none;float:none;display:inline;position:absolute;z-index:9999}.rui-autocompleter{border-top-color:#DDD !important;border-top-left-radius:0 !important;border-top-rui-radius:0 !important;-moz-border-radius-topleft:0 !important;-moz-border-radius-topright:0 !important;-webkit-border-top-left-radius:0 !important;-webkit-border-top-right-radius:0 !important}.rui-autocompleter-spinner{border:none !important;background:none !important;position:absolute;z-index:9999}.rui-autocompleter-spinner div{margin-top:.2em !important; *margin-top:0.1em !important}</style>");
|
610
|
+
|
611
|
+
return Autocompleter;
|
612
|
+
})(document, RightJS);
|
@@ -0,0 +1,18 @@
|
|
1
|
+
/**
|
2
|
+
* RightJS-UI: Autocompleter
|
3
|
+
* http://rightjs.org/ui/autocompleter
|
4
|
+
*
|
5
|
+
* Copyright (C) 2010 Nikolay Nemshilov
|
6
|
+
*/
|
7
|
+
var Autocompleter=RightJS.Autocompleter=function(j,c){function l(a,b,d,e){if(c.Fx)if(d===undefined){d=this.options.fxName;if(e===undefined){e={duration:this.options.fxDuration,onFinish:c(this.fire).bind(this,b)};if(b==="hide")e.duration=(c.Fx.Durations[e.duration]||e.duration)/2}}c.Element.prototype[b].call(a,d,e);if(!c.Fx||!d)this.fire(b);return this}function m(a,b,d){var e=(this.reAnchor||(this.reAnchor=new c.Element("div",{"class":"rui-re-anchor"})).insert(this)).insertTo(a,"after").position(),
|
8
|
+
f=a.dimensions(),h=parseInt(a.getStyle("borderTopWidth")),i=parseInt(a.getStyle("borderLeftWidth")),q=parseInt(a.getStyle("borderRightWidth")),r=parseInt(a.getStyle("borderBottomWidth"));a=f.top-e.y+h;e=f.left-e.x+i;i=f.width-i-q;f=f.height-h-r;this.setStyle("visibility:hidden").show(null);if(b==="right")e+=i-this.size().x;else a+=f;this.moveTo(e,a);if(d)["left","right"].include(b)?this.setHeight(f):this.setWidth(i);this.setStyle("visibility:visible").hide(null)}var g=c,n=c.$,s=c.$w,t=c.Xhr,o=c.RegExp,
|
9
|
+
u=c.isArray,p=new c.Wrapper(c.Element,{initialize:function(a){this.$super("div",{"class":"rui-spinner"});this.dots=[];for(var b=0;b<(a||4);b++)this.dots.push(new c.Element("div"));this.dots[0].addClass("glowing");this.insert(this.dots);c(this.shift).bind(this).periodical(300)},shift:function(){if(this.visible()){var a=this.dots.pop();this.dots.unshift(a);this.insert(a,"top")}}}),k=new (function(a,b){if(!b){b=a;a="DIV"}var d=new c.Wrapper(c.Element.Wrappers[a]||c.Element,{initialize:function(e,f){this.key=
|
10
|
+
e;var h=[{"class":"rui-"+e}];this instanceof c.Input||this instanceof c.Form||h.unshift(a);this.$super.apply(this,h);if(c.isString(f))f=c.$(f);if(f instanceof c.Element){this._=f._;if("$listeners"in f)f.$listeners=f.$listeners;f={}}this.setOptions(f,this);return this},setOptions:function(e,f){f=f||this;c.Options.setOptions.call(this,c.Object.merge(e,eval("("+(f.get("data-"+this.key)||"{}")+")")));return this}});d=new c.Wrapper(d,b);c.Observer.createShortcuts(d.prototype,d.EVENTS||[]);return d})("UL",
|
11
|
+
{include:{show:function(a,b){this.constructor.current=this;return l.call(this,this,"show",a,b)},hide:function(a,b){this.constructor.current=null;return l.call(this,this,"hide",a,b)},showAt:function(a,b,d){this.hide(null).shownAt=a=c.$(a);m.call(this,a,b,d);return this.show()},toggleAt:function(a,b,d){return this.hidden()?this.showAt(a,b,d):this.hide()}},extend:{version:"2.0.0",EVENTS:s("show hide update load select done"),Options:{url:j.location.href,param:"search",method:"get",minLength:1,threshold:200,
|
12
|
+
cache:true,local:null,fxName:"slide",fxDuration:"short",spinner:"native",cssRule:"input[data-autocompleter]"}},initialize:function(a,b){this.input=n(a);this.$super("autocompleter",b).addClass("rui-dd-menu").onMousedown(this.clicked);this.input.autocompleter=this},destroy:function(){delete this.input.autocompleter;return this},prev:function(){return this.pick("prev")},next:function(){return this.pick("next")},done:function(a){if(a=a||this.first("li.current")){this.input.setValue(g(a.html()).stripTags());
|
13
|
+
this.fire("done")}return this.hide()},setOptions:function(a){this.$super(a,this.input);a=this.options;g(a.url).includes("%{search}")||(a.url+=(g(a.url).includes("?")?"&":"?")+a.param+"=%{search}")},pick:function(a){var b=this.children(),d=b.first("hasClass","current"),e=b.indexOf(d);if(a=="prev")d=e<1?b.last():b[e<0?0:e-1];else if(a=="next")d=e<0||e==b.length-1?b.first():b[e+1];return this.fire("select",d.radioClass("current"))},clicked:function(a){this.done(a.stop().find("li"))},keypressed:function(){if(this.input.value().length>=
|
14
|
+
this.options.minLength){this.timeout&&this.timeout.cancel();this.timeout=g(this.trigger).bind(this).delay(this.options.threshold)}else return this.hide()},trigger:function(){this.timeout=null;this.cache=this.cache||{};var a=this.input.value(),b=this.options;if(a.length<b.minLength)return this.hide();if(this.cache[a])this.suggest(this.cache[a],a);else if(u(b.local))this.suggest(this.findLocal(a),a);else this.request=t.load(b.url.replace("%{search}",encodeURIComponent(a)),{method:b.method,spinner:this.getSpinner(),
|
15
|
+
onComplete:g(function(d){this.fire("load").suggest(d.text,a)}).bind(this)})},suggest:function(a,b){if(this.options.cache)this.cache[b]=a;if(a.blank())this.hide();else{this.update(a.replace(/<ul[^>]*>|<\/ul>/im,""));this.fire("update").showAt(this.input,"bottom","resize")}return this},findLocal:function(a){var b=new o("("+o.escape(a)+")","ig");return g(this.options.local).map(function(d){if(d.match(b))return"<li>"+d.replace(b,"<strong>$1</strong>")+"</li>"}).compact().join("")},getSpinner:function(){var a=
|
16
|
+
this.options,b=a.spinner;if(b=="native"){b=a.spinner=(new p(3)).insertTo(this);b.addClass("rui-autocompleter-spinner")}b instanceof p&&m.call(b,this.input,"right","resize");return b}});n(j).on({focus:function(a){if((a=a.target)&&a instanceof c.Element&&(a.autocompleter||a.match(k.Options.cssRule)))a.autocompleter||new k(a)},blur:function(a){(a=a.target?a.target.autocompleter:null)&&a.visible()&&a.hide()},keydown:function(a){var b=a.target?a.target.autocompleter:null;if(b&&b.visible()){var d={27:"hide",
|
17
|
+
38:"prev",40:"next",13:"done"}[a.keyCode];if(d){a.stop();b[d]()}}},keyup:function(a){var b=a.target?a.target.autocompleter:null;b&&!g([9,27,37,38,39,40,13]).include(a.keyCode)&&b.keypressed(a)}});j.write('<style type="text/css"> *.rui-dd-menu, *.rui-dd-menu li{margin:0;padding:0;border:none;background:none;list-style:none;font-weight:normal;float:none} *.rui-dd-menu{display:none;position:absolute;z-index:9999;background:white;border:1px solid #BBB;border-radius:.2em;-moz-border-radius:.2em;-webkit-border-radius:.2em;box-shadow:#DDD .2em .2em .4em;-moz-box-shadow:#DDD .2em .2em .4em;-webkit-box-shadow:#DDD .2em .2em .4em} *.rui-dd-menu li{padding:.2em .4em;border-top:none;border-bottom:none;cursor:pointer} *.rui-dd-menu li.current{background:#DDD} *.rui-dd-menu li:hover{background:#EEE}dl.rui-dd-menu dt{padding:.3em .5em;cursor:default;font-weight:bold;font-style:italic;color:#444;background:#EEE}dl.rui-dd-menu dd li{padding-left:1.5em}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-re-anchor{margin:0;padding:0;background:none;border:none;float:none;display:inline;position:absolute;z-index:9999}.rui-autocompleter{border-top-color:#DDD !important;border-top-left-radius:0 !important;border-top-rui-radius:0 !important;-moz-border-radius-topleft:0 !important;-moz-border-radius-topright:0 !important;-webkit-border-top-left-radius:0 !important;-webkit-border-top-right-radius:0 !important}.rui-autocompleter-spinner{border:none !important;background:none !important;position:absolute;z-index:9999}.rui-autocompleter-spinner div{margin-top:.2em !important; *margin-top:0.1em !important}</style>');
|
18
|
+
return k}(document,RightJS);
|