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,881 @@
|
|
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(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
|
+
* The filenames to include
|
18
|
+
*
|
19
|
+
* Copyright (C) 2010 Nikolay Nemshilov
|
20
|
+
*/
|
21
|
+
var R = RightJS,
|
22
|
+
$ = RightJS.$,
|
23
|
+
$$ = RightJS.$$,
|
24
|
+
$w = RightJS.$w,
|
25
|
+
$E = RightJS.$E,
|
26
|
+
$ext = RightJS.$ext,
|
27
|
+
Xhr = RightJS.Xhr,
|
28
|
+
Class = RightJS.Class,
|
29
|
+
Object = RightJS.Object,
|
30
|
+
Wrapper = RightJS.Wrapper,
|
31
|
+
Element = RightJS.Element,
|
32
|
+
Browser = RightJS.Browser;
|
33
|
+
|
34
|
+
// IE6 doesn't support position:fixed so it needs a crunch
|
35
|
+
Browser.IE6 = Browser.OLD && navigator.userAgent.indexOf("MSIE 6") > 0;
|
36
|
+
|
37
|
+
|
38
|
+
|
39
|
+
|
40
|
+
|
41
|
+
|
42
|
+
|
43
|
+
/**
|
44
|
+
* The widget units constructor
|
45
|
+
*
|
46
|
+
* @param String tag-name or Object methods
|
47
|
+
* @param Object methods
|
48
|
+
* @return Widget wrapper
|
49
|
+
*/
|
50
|
+
function Widget(tag_name, methods) {
|
51
|
+
if (!methods) {
|
52
|
+
methods = tag_name;
|
53
|
+
tag_name = 'DIV';
|
54
|
+
}
|
55
|
+
|
56
|
+
/**
|
57
|
+
* An Abstract Widget Unit
|
58
|
+
*
|
59
|
+
* Copyright (C) 2010 Nikolay Nemshilov
|
60
|
+
*/
|
61
|
+
var AbstractWidget = new RightJS.Wrapper(RightJS.Element.Wrappers[tag_name] || RightJS.Element, {
|
62
|
+
/**
|
63
|
+
* The common constructor
|
64
|
+
*
|
65
|
+
* @param Object options
|
66
|
+
* @param String optional tag name
|
67
|
+
* @return void
|
68
|
+
*/
|
69
|
+
initialize: function(key, options) {
|
70
|
+
this.key = key;
|
71
|
+
var args = [{'class': 'rui-' + key}];
|
72
|
+
|
73
|
+
// those two have different constructors
|
74
|
+
if (!(this instanceof RightJS.Input || this instanceof RightJS.Form)) {
|
75
|
+
args.unshift(tag_name);
|
76
|
+
}
|
77
|
+
this.$super.apply(this, args);
|
78
|
+
|
79
|
+
if (RightJS.isString(options)) {
|
80
|
+
options = RightJS.$(options);
|
81
|
+
}
|
82
|
+
|
83
|
+
// if the options is another element then
|
84
|
+
// try to dynamically rewrap it with our widget
|
85
|
+
if (options instanceof RightJS.Element) {
|
86
|
+
this._ = options._;
|
87
|
+
if ('$listeners' in options) {
|
88
|
+
options.$listeners = options.$listeners;
|
89
|
+
}
|
90
|
+
options = {};
|
91
|
+
}
|
92
|
+
this.setOptions(options, this);
|
93
|
+
return this;
|
94
|
+
},
|
95
|
+
|
96
|
+
// protected
|
97
|
+
|
98
|
+
/**
|
99
|
+
* Catches the options
|
100
|
+
*
|
101
|
+
* @param Object user-options
|
102
|
+
* @param Element element with contextual options
|
103
|
+
* @return void
|
104
|
+
*/
|
105
|
+
setOptions: function(options, element) {
|
106
|
+
element = element || this;
|
107
|
+
RightJS.Options.setOptions.call(this,
|
108
|
+
RightJS.Object.merge(options, eval("("+(
|
109
|
+
element.get('data-'+ this.key) || '{}'
|
110
|
+
)+")"))
|
111
|
+
);
|
112
|
+
return this;
|
113
|
+
}
|
114
|
+
});
|
115
|
+
|
116
|
+
/**
|
117
|
+
* Creating the actual widget class
|
118
|
+
*
|
119
|
+
*/
|
120
|
+
var Klass = new RightJS.Wrapper(AbstractWidget, methods);
|
121
|
+
|
122
|
+
// creating the widget related shortcuts
|
123
|
+
RightJS.Observer.createShortcuts(Klass.prototype, Klass.EVENTS || []);
|
124
|
+
|
125
|
+
return Klass;
|
126
|
+
}
|
127
|
+
|
128
|
+
|
129
|
+
/**
|
130
|
+
* A shared module to create textual spinners
|
131
|
+
*
|
132
|
+
* Copyright (C) 2010 Nikolay Nemshilov
|
133
|
+
*/
|
134
|
+
var Spinner = new RightJS.Wrapper(RightJS.Element, {
|
135
|
+
/**
|
136
|
+
* Constructor
|
137
|
+
*
|
138
|
+
* @param Number optional spinner size (4 by default)
|
139
|
+
* @return void
|
140
|
+
*/
|
141
|
+
initialize: function(size) {
|
142
|
+
this.$super('div', {'class': 'rui-spinner'});
|
143
|
+
this.dots = [];
|
144
|
+
|
145
|
+
for (var i=0; i < (size || 4); i++) {
|
146
|
+
this.dots.push(new RightJS.Element('div'));
|
147
|
+
}
|
148
|
+
|
149
|
+
this.dots[0].addClass('glowing');
|
150
|
+
this.insert(this.dots);
|
151
|
+
RightJS(this.shift).bind(this).periodical(300);
|
152
|
+
},
|
153
|
+
|
154
|
+
/**
|
155
|
+
* Shifts the spinner elements
|
156
|
+
*
|
157
|
+
* @return void
|
158
|
+
*/
|
159
|
+
shift: function() {
|
160
|
+
if (this.visible()) {
|
161
|
+
var dot = this.dots.pop();
|
162
|
+
this.dots.unshift(dot);
|
163
|
+
this.insert(dot, 'top');
|
164
|
+
}
|
165
|
+
}
|
166
|
+
});
|
167
|
+
|
168
|
+
/**
|
169
|
+
* The lightbox widget
|
170
|
+
*
|
171
|
+
* Copyright (C) 2009-2010 Nikolay Nemshilov
|
172
|
+
*/
|
173
|
+
var Lightbox = new Widget({
|
174
|
+
|
175
|
+
extend: {
|
176
|
+
version: '2.0.0',
|
177
|
+
|
178
|
+
EVENTS: $w('show hide load'),
|
179
|
+
|
180
|
+
Options: {
|
181
|
+
fxName: 'fade',
|
182
|
+
fxDuration: 100,
|
183
|
+
|
184
|
+
group: null, // a group marker
|
185
|
+
|
186
|
+
hideOnEsc: true,
|
187
|
+
hideOnOutClick: true,
|
188
|
+
showCloseButton: true,
|
189
|
+
|
190
|
+
cssRule: "a[data-lightbox]", // all lightbox links css-rule
|
191
|
+
|
192
|
+
// video links default size
|
193
|
+
mediaWidth: 425,
|
194
|
+
mediaHeight: 350
|
195
|
+
},
|
196
|
+
|
197
|
+
i18n: {
|
198
|
+
Close: 'Close',
|
199
|
+
Prev: 'Previous Image',
|
200
|
+
Next: 'Next Image'
|
201
|
+
},
|
202
|
+
|
203
|
+
// the supported image-urls regexp
|
204
|
+
Images: /\.(jpg|jpeg|gif|png|bmp)/,
|
205
|
+
|
206
|
+
// media content sources
|
207
|
+
Medias: [
|
208
|
+
[/(http:\/\/.*?youtube\.[a-z]+)\/watch\?v=([^&]+)/, '$1/v/$2', 'swf'],
|
209
|
+
[/(http:\/\/video.google.com)\/videoplay\?docid=([^&]+)/, '$1/googleplayer.swf?docId=$2', 'swf'],
|
210
|
+
[/(http:\/\/vimeo\.[a-z]+)\/([0-9]+).*?/, '$1/moogaloop.swf?clip_id=$2', 'swf']
|
211
|
+
]
|
212
|
+
},
|
213
|
+
|
214
|
+
/**
|
215
|
+
* basic constructor
|
216
|
+
*
|
217
|
+
* @param Object options override
|
218
|
+
* @param Element optional options holder
|
219
|
+
* @return void
|
220
|
+
*/
|
221
|
+
initialize: function(options, context) {
|
222
|
+
this
|
223
|
+
.$super('lightbox', {})
|
224
|
+
.setOptions(options, context)
|
225
|
+
.insert([
|
226
|
+
this.locker = new Locker(this.options),
|
227
|
+
this.dialog = new Dialog(this.options)
|
228
|
+
])
|
229
|
+
.on({
|
230
|
+
close: this._close,
|
231
|
+
next: this._next,
|
232
|
+
prev: this._prev
|
233
|
+
});
|
234
|
+
},
|
235
|
+
|
236
|
+
/**
|
237
|
+
* Extracting the rel="lightboux[groupname]" attributes
|
238
|
+
*
|
239
|
+
* @param Object options
|
240
|
+
* @param Element link with options
|
241
|
+
* @return Dialog this
|
242
|
+
*/
|
243
|
+
setOptions: function(options, context) {
|
244
|
+
this.$super(options, context);
|
245
|
+
|
246
|
+
if (context) {
|
247
|
+
var rel = context.get('rel');
|
248
|
+
if (rel && (rel = rel.match(/lightbox\[(.+?)\]/))) {
|
249
|
+
this.options.group = rel[1];
|
250
|
+
}
|
251
|
+
}
|
252
|
+
|
253
|
+
return this;
|
254
|
+
},
|
255
|
+
|
256
|
+
/**
|
257
|
+
* Sets the popup's title
|
258
|
+
*
|
259
|
+
* @param mixed string or element or somethin'
|
260
|
+
* @return Lighbox self
|
261
|
+
*/
|
262
|
+
setTitle: function(text) {
|
263
|
+
this.dialog.setTitle(text);
|
264
|
+
|
265
|
+
return this;
|
266
|
+
},
|
267
|
+
|
268
|
+
/**
|
269
|
+
* Shows the lightbox
|
270
|
+
*
|
271
|
+
* @param String/Array... content
|
272
|
+
* @return Lightbox this
|
273
|
+
*/
|
274
|
+
show: function(content) {
|
275
|
+
return this._showAnd(function() {
|
276
|
+
this.dialog.show(content, !content);
|
277
|
+
});
|
278
|
+
},
|
279
|
+
|
280
|
+
/**
|
281
|
+
* Hides the lightbox
|
282
|
+
*
|
283
|
+
* @return Lightbox this
|
284
|
+
*/
|
285
|
+
hide: function() {
|
286
|
+
Lightbox.current = null;
|
287
|
+
|
288
|
+
return this.$super(this.options.fxName, {
|
289
|
+
duration: this.options.fxDuration/3,
|
290
|
+
onFinish: R(function() {
|
291
|
+
this.fire('hide');
|
292
|
+
this.remove();
|
293
|
+
}).bind(this)
|
294
|
+
});
|
295
|
+
},
|
296
|
+
|
297
|
+
/**
|
298
|
+
* Loads up the data from url or a link
|
299
|
+
*
|
300
|
+
* @param String address or a link element
|
301
|
+
* @param Object Xhr options
|
302
|
+
* @return Lightbox this
|
303
|
+
*/
|
304
|
+
load: function(link, options) {
|
305
|
+
return this._showAnd(function() {
|
306
|
+
this.dialog.load(link, options);
|
307
|
+
});
|
308
|
+
},
|
309
|
+
|
310
|
+
/**
|
311
|
+
* Resizes the content block to the given size
|
312
|
+
*
|
313
|
+
* @param Hash size
|
314
|
+
* @return Lightbox this
|
315
|
+
*/
|
316
|
+
resize: function(size) {
|
317
|
+
this.dialog.resize(size);
|
318
|
+
return this;
|
319
|
+
},
|
320
|
+
|
321
|
+
// protected
|
322
|
+
|
323
|
+
// handles the 'close' event
|
324
|
+
_close: function(event) {
|
325
|
+
event.stop();
|
326
|
+
this.hide();
|
327
|
+
},
|
328
|
+
|
329
|
+
// handles the 'prev' event
|
330
|
+
_prev: function(event) {
|
331
|
+
event.stop();
|
332
|
+
Pager.prev();
|
333
|
+
},
|
334
|
+
|
335
|
+
// handles the 'next' event
|
336
|
+
_next: function(event) {
|
337
|
+
event.stop();
|
338
|
+
Pager.next();
|
339
|
+
},
|
340
|
+
|
341
|
+
// shows the lightbox element and then calls back
|
342
|
+
_showAnd: function(callback) {
|
343
|
+
if (Lightbox.current !== this) {
|
344
|
+
Lightbox.current = this;
|
345
|
+
|
346
|
+
// hidding all the hanging around lightboxes
|
347
|
+
$$('div.rui-lightbox').each('remove');
|
348
|
+
|
349
|
+
this.insertTo(document.body);
|
350
|
+
this.dialog.show('', true);
|
351
|
+
|
352
|
+
if (Browser.OLD) { // IE's get screwed by the transparency tricks
|
353
|
+
this.reposition();
|
354
|
+
Element.prototype.show.call(this);
|
355
|
+
callback.call(this);
|
356
|
+
} else {
|
357
|
+
this.setStyle('display:none');
|
358
|
+
Element.prototype.show.call(this, this.options.fxName, {
|
359
|
+
duration: this.options.fxDuration/2,
|
360
|
+
onFinish: R(function() {
|
361
|
+
callback.call(this);
|
362
|
+
this.fire('show');
|
363
|
+
}).bind(this)
|
364
|
+
});
|
365
|
+
}
|
366
|
+
} else {
|
367
|
+
callback.call(this);
|
368
|
+
}
|
369
|
+
|
370
|
+
return this;
|
371
|
+
},
|
372
|
+
|
373
|
+
// manually repositioning under IE6 browser
|
374
|
+
reposition: function() {
|
375
|
+
if (Browser.IE6) {
|
376
|
+
var win = $(window);
|
377
|
+
|
378
|
+
this.setStyle({
|
379
|
+
top: win.scrolls().y + 'px',
|
380
|
+
width: win.size().x + 'px',
|
381
|
+
height: win.size().y + 'px',
|
382
|
+
position: "absolute"
|
383
|
+
});
|
384
|
+
}
|
385
|
+
}
|
386
|
+
});
|
387
|
+
|
388
|
+
|
389
|
+
/**
|
390
|
+
* The class level interface
|
391
|
+
*
|
392
|
+
* @copyright (C) 2009 Nikolay Nemshilov
|
393
|
+
*/
|
394
|
+
Lightbox.extend({
|
395
|
+
hide: function() {
|
396
|
+
if (Lightbox.current) {
|
397
|
+
Lightbox.current.hide();
|
398
|
+
}
|
399
|
+
},
|
400
|
+
|
401
|
+
show: function() {
|
402
|
+
return this.inst('show', arguments);
|
403
|
+
},
|
404
|
+
|
405
|
+
load: function() {
|
406
|
+
return this.inst('load', arguments);
|
407
|
+
},
|
408
|
+
|
409
|
+
// private
|
410
|
+
|
411
|
+
inst: function(name, args) {
|
412
|
+
var inst = new Lightbox();
|
413
|
+
return inst[name].apply(inst, args);
|
414
|
+
}
|
415
|
+
});
|
416
|
+
|
417
|
+
/**
|
418
|
+
* Lightbox background locker element
|
419
|
+
*
|
420
|
+
* Copyright (C) 2010 Nikolay Nemshilov
|
421
|
+
*/
|
422
|
+
var Locker = new Wrapper(Element, {
|
423
|
+
initialize: function(options) {
|
424
|
+
this.$super('div', {'class': 'rui-lightbox-locker'});
|
425
|
+
|
426
|
+
if (options.hideOnOutClick) {
|
427
|
+
this.onClick('fire', 'close');
|
428
|
+
}
|
429
|
+
}
|
430
|
+
});
|
431
|
+
|
432
|
+
/**
|
433
|
+
* The dialog element wrapper
|
434
|
+
*
|
435
|
+
* Copyright (C) 2010 Nikolay Nemshilov
|
436
|
+
*/
|
437
|
+
var Dialog = new Wrapper(Element, {
|
438
|
+
/**
|
439
|
+
* Constructor
|
440
|
+
*
|
441
|
+
* @param Object options
|
442
|
+
* @return void
|
443
|
+
*/
|
444
|
+
initialize: function(options) {
|
445
|
+
var i18n = Lightbox.i18n;
|
446
|
+
|
447
|
+
this.options = options;
|
448
|
+
this.$super('div', {'class': 'rui-lightbox-dialog'});
|
449
|
+
|
450
|
+
// building up the
|
451
|
+
this.insert([
|
452
|
+
this.title = $E('div', {'class': 'rui-lightbox-title'}),
|
453
|
+
|
454
|
+
$E('div', {'class': 'rui-lightbox-body'}).insert(
|
455
|
+
$E('div', {'class': 'rui-lightbox-body-inner'}).insert([
|
456
|
+
this.locker = $E('div', {'class': 'rui-lightbox-body-locker'}).insert(new Spinner(4)),
|
457
|
+
this.scroller = $E('div', {'class': 'rui-lightbox-scroller'}).insert(
|
458
|
+
this.content = $E('div', {'class': 'rui-lightbox-content'})
|
459
|
+
)
|
460
|
+
])
|
461
|
+
),
|
462
|
+
|
463
|
+
$E('div', {'class': 'rui-lightbox-navigation'}).insert([
|
464
|
+
this.closeButton = $E('div', {'class': 'close', html: '×', title: i18n.Close}).onClick('fire', 'close'),
|
465
|
+
this.prevLink = $E('div', {'class': 'prev', html: '←', title: i18n.Prev}).onClick('fire', 'prev'),
|
466
|
+
this.nextLink = $E('div', {'class': 'next', html: '→', title: i18n.Next}).onClick('fire', 'next')
|
467
|
+
])
|
468
|
+
]);
|
469
|
+
|
470
|
+
// presetting the navigation state
|
471
|
+
this.prevLink.hide();
|
472
|
+
this.nextLink.hide();
|
473
|
+
|
474
|
+
if (!options.showCloseButton) {
|
475
|
+
this.closeButton.hide();
|
476
|
+
}
|
477
|
+
},
|
478
|
+
|
479
|
+
/**
|
480
|
+
* Sets the dialogue caption
|
481
|
+
*
|
482
|
+
* @param String title
|
483
|
+
* @return Dialog this
|
484
|
+
*/
|
485
|
+
setTitle: function(title) {
|
486
|
+
this.title.update(title||'');
|
487
|
+
},
|
488
|
+
|
489
|
+
/**
|
490
|
+
* Nicely resize the dialog box
|
491
|
+
*
|
492
|
+
* @param Object the end size
|
493
|
+
* @param Boolean use fx (false by default)
|
494
|
+
* @return Dialog this
|
495
|
+
*/
|
496
|
+
resize: function(end_size, with_fx) {
|
497
|
+
var win_size = this.parent().size(),
|
498
|
+
cur_size = this.scroller.size(),
|
499
|
+
cur_top = (win_size.y - this.size().y)/2,
|
500
|
+
dlg_diff = this.size().x - cur_size.x; // <- use for IE6 fixes
|
501
|
+
|
502
|
+
if (end_size) {
|
503
|
+
// getting the actual end-size
|
504
|
+
end_size = this.scroller.setStyle(end_size).size();
|
505
|
+
|
506
|
+
this.scroller.setStyle({
|
507
|
+
width: cur_size.x + 'px',
|
508
|
+
height: cur_size.y + 'px'
|
509
|
+
});
|
510
|
+
} else {
|
511
|
+
// using the content block size
|
512
|
+
end_size = this.content.size();
|
513
|
+
}
|
514
|
+
|
515
|
+
// checking the constraints
|
516
|
+
var threshold = 100; // px
|
517
|
+
if ((end_size.x + threshold) > win_size.x) { end_size.x = win_size.x - threshold; }
|
518
|
+
if ((end_size.y + threshold) > win_size.y) { end_size.y = win_size.y - threshold; }
|
519
|
+
|
520
|
+
// the actual resize and reposition
|
521
|
+
var end_top = (cur_top * 2 + cur_size.y - end_size.y) / 2;
|
522
|
+
var dialog = this._.style, content = this.scroller._.style;
|
523
|
+
|
524
|
+
if (RightJS.Fx && with_fx && (end_size.x != cur_size.x || end_size.y != cur_size.y)) {
|
525
|
+
|
526
|
+
$ext(new RightJS.Fx(this, {duration: this.options.fxDuration, transition: 'Lin'}), {
|
527
|
+
render: function(delta) {
|
528
|
+
content.width = (cur_size.x + (end_size.x - cur_size.x) * delta) + 'px';
|
529
|
+
content.height = (cur_size.y + (end_size.y - cur_size.y) * delta) + 'px';
|
530
|
+
dialog.top = (cur_top + (end_top - cur_top) * delta) + 'px';
|
531
|
+
|
532
|
+
if (Browser.IE6) {
|
533
|
+
dialog.width = (dlg_diff + cur_size.y + (end_size.y - cur_size.y) * delta) + 'px';
|
534
|
+
}
|
535
|
+
}
|
536
|
+
}).onFinish(R(this.unlock).bind(this)).start();
|
537
|
+
|
538
|
+
} else {
|
539
|
+
// no-fx direct assignment
|
540
|
+
content.width = end_size.x + 'px';
|
541
|
+
content.height = end_size.y + 'px';
|
542
|
+
dialog.top = end_top + 'px';
|
543
|
+
|
544
|
+
if (Browser.IE6) {
|
545
|
+
dialog.width = (dlg_diff + end_size.x) + 'px';
|
546
|
+
}
|
547
|
+
|
548
|
+
if (!this.request) { this.unlock(); }
|
549
|
+
}
|
550
|
+
|
551
|
+
return this;
|
552
|
+
},
|
553
|
+
|
554
|
+
/**
|
555
|
+
* Shows the content
|
556
|
+
*
|
557
|
+
* @param mixed content String/Element/Array and so one
|
558
|
+
* @return Dialog this
|
559
|
+
*/
|
560
|
+
show: function(content, no_fx) {
|
561
|
+
this.content.update(content || '');
|
562
|
+
this.resize(null, !no_fx);
|
563
|
+
},
|
564
|
+
|
565
|
+
/**
|
566
|
+
* Loads up the data from the link
|
567
|
+
*
|
568
|
+
* @param mixed String url address or a link element
|
569
|
+
* @param Object xhr-options
|
570
|
+
* @return void
|
571
|
+
*/
|
572
|
+
load: function(url, options) {
|
573
|
+
if (url instanceof Element) {
|
574
|
+
this.setTitle(url.get('title'));
|
575
|
+
url = url.get('href');
|
576
|
+
}
|
577
|
+
|
578
|
+
Pager.show(this, url);
|
579
|
+
this.lock().cancel();
|
580
|
+
|
581
|
+
// defined in the loader.js file
|
582
|
+
this.request = new Loader(url, options, R(function(content, no_fx) {
|
583
|
+
this.request = null;
|
584
|
+
this.show(content, no_fx);
|
585
|
+
}).bind(this));
|
586
|
+
|
587
|
+
return this.resize(); // the look might be changed for a media-type
|
588
|
+
},
|
589
|
+
|
590
|
+
/**
|
591
|
+
* Cancels a currently loading request
|
592
|
+
*
|
593
|
+
* @return Dialog this
|
594
|
+
*/
|
595
|
+
cancel: function() {
|
596
|
+
if (this.request) {
|
597
|
+
this.request.cancel();
|
598
|
+
}
|
599
|
+
|
600
|
+
return this;
|
601
|
+
},
|
602
|
+
|
603
|
+
/**
|
604
|
+
* Shows the loading lock
|
605
|
+
*
|
606
|
+
* @return Dialog this
|
607
|
+
*/
|
608
|
+
lock: function() {
|
609
|
+
this.locker.setStyle('opacity:1');
|
610
|
+
return this;
|
611
|
+
},
|
612
|
+
|
613
|
+
/**
|
614
|
+
* Hides the loading lock
|
615
|
+
*
|
616
|
+
* @return Dialog this
|
617
|
+
*/
|
618
|
+
unlock: function() {
|
619
|
+
this.locker.morph({opacity: 0}, {
|
620
|
+
duration: this.options.fxDuration * 2/3
|
621
|
+
});
|
622
|
+
|
623
|
+
return this;
|
624
|
+
}
|
625
|
+
});
|
626
|
+
|
627
|
+
/**
|
628
|
+
* Xhr/images/medias loading module
|
629
|
+
*
|
630
|
+
* Copyright (C) 2009-2010 Nikolay Nemshilov
|
631
|
+
*/
|
632
|
+
var Loader = new Class({
|
633
|
+
/**
|
634
|
+
* Constructor
|
635
|
+
*
|
636
|
+
* @param String url address
|
637
|
+
* @param Object Xhr options
|
638
|
+
* @param Function on-finish callback
|
639
|
+
*/
|
640
|
+
initialize: function(url, options, on_finish) {
|
641
|
+
// adjusting the dialog look for different media-types
|
642
|
+
if (this.isImage(url, on_finish)) {
|
643
|
+
Lightbox.current.addClass('rui-lightbox-image');
|
644
|
+
} else if (this.isMedia(url, on_finish)) {
|
645
|
+
Lightbox.current.addClass('rui-lightbox-media');
|
646
|
+
} else {
|
647
|
+
this.xhr = new Xhr(url,
|
648
|
+
Object.merge({method: 'get'}, options)
|
649
|
+
).onComplete(function() {
|
650
|
+
on_finish(this.text);
|
651
|
+
}).send();
|
652
|
+
}
|
653
|
+
},
|
654
|
+
|
655
|
+
/**
|
656
|
+
* Cancels the request
|
657
|
+
*
|
658
|
+
* @return Loader this
|
659
|
+
*/
|
660
|
+
cancel: function() {
|
661
|
+
if (this.xhr) {
|
662
|
+
this.xhr.cancel();
|
663
|
+
} else if (this.img) {
|
664
|
+
this.img.onload = function() {};
|
665
|
+
}
|
666
|
+
},
|
667
|
+
|
668
|
+
// protected
|
669
|
+
|
670
|
+
// tries to initialize it as an image loading
|
671
|
+
isImage: function(url, on_finish) {
|
672
|
+
if (url.match(Lightbox.Images)) {
|
673
|
+
var img = this.img = $E('img')._;
|
674
|
+
img.onload = function() {
|
675
|
+
on_finish(img);
|
676
|
+
};
|
677
|
+
img.src = url;
|
678
|
+
return true;
|
679
|
+
}
|
680
|
+
},
|
681
|
+
|
682
|
+
// tries to initialize it as a flash-element
|
683
|
+
isMedia: function(url, on_finish) {
|
684
|
+
var media = R(Lightbox.Medias).map(function(desc) {
|
685
|
+
return url.match(desc[0]) ? this.buildEmbed(
|
686
|
+
url.replace(desc[0], desc[1]), desc[2]) : null;
|
687
|
+
}, this).compact()[0];
|
688
|
+
|
689
|
+
if (media) {
|
690
|
+
on_finish(media, true);
|
691
|
+
return true;
|
692
|
+
}
|
693
|
+
},
|
694
|
+
|
695
|
+
// builds an embedded media block
|
696
|
+
buildEmbed: function(url, type) {
|
697
|
+
var media_types = {
|
698
|
+
swf: [
|
699
|
+
'D27CDB6E-AE6D-11cf-96B8-444553540000',
|
700
|
+
'http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0',
|
701
|
+
'application/x-shockwave-flash'
|
702
|
+
]
|
703
|
+
},
|
704
|
+
options = Lightbox.current ? Lightbox.current.options : Lightbox.Options,
|
705
|
+
sizes = ' width="'+ options.mediaWidth + '" height="'+ options.mediaHeight + '"';
|
706
|
+
|
707
|
+
return '<object classid="clsid:' + media_types[type][0] +
|
708
|
+
'" codebase="' + media_types[type][1] + '"'+ sizes + '>' +
|
709
|
+
'<param name="src" value="'+ url +'" />'+
|
710
|
+
'<embed src="'+ url +'" type="'+ media_types[type][2]+'"'+ sizes + ' />' +
|
711
|
+
'</object>';
|
712
|
+
}
|
713
|
+
|
714
|
+
});
|
715
|
+
|
716
|
+
/**
|
717
|
+
* Processes the link-groups showing things in a single Lightbox
|
718
|
+
*
|
719
|
+
* Copyright (C) 2010 Nikolay Nemshilov
|
720
|
+
*/
|
721
|
+
var Pager = {
|
722
|
+
/**
|
723
|
+
* Checks and shows the pager links on the dialog
|
724
|
+
*
|
725
|
+
* @param Dialog dialog
|
726
|
+
* @param String url-address
|
727
|
+
* @return void
|
728
|
+
*/
|
729
|
+
show: function(dialog, url) {
|
730
|
+
if (dialog.options.group) {
|
731
|
+
this.dialog = dialog;
|
732
|
+
this.links = this.find(dialog.options.group);
|
733
|
+
this.link = this.links.first(function(link) {
|
734
|
+
return link.get('href') === url;
|
735
|
+
});
|
736
|
+
|
737
|
+
var index = this.links.indexOf(this.link), size = this.links.length;
|
738
|
+
|
739
|
+
dialog.prevLink[size && index > 0 ? 'show' : 'hide']();
|
740
|
+
dialog.nextLink[size && index < size - 1 ? 'show' : 'hide']();
|
741
|
+
} else {
|
742
|
+
this.dialog = null;
|
743
|
+
}
|
744
|
+
},
|
745
|
+
|
746
|
+
/**
|
747
|
+
* Shows the prev link
|
748
|
+
*
|
749
|
+
* @return void
|
750
|
+
*/
|
751
|
+
prev: function() {
|
752
|
+
if (this.dialog && !this.timer) {
|
753
|
+
var id = this.links.indexOf(this.link),
|
754
|
+
link = this.links[id - 1];
|
755
|
+
|
756
|
+
if (link) {
|
757
|
+
this.dialog.load(link);
|
758
|
+
this.timeout();
|
759
|
+
}
|
760
|
+
}
|
761
|
+
},
|
762
|
+
|
763
|
+
/**
|
764
|
+
* Shows the next link
|
765
|
+
*
|
766
|
+
* @return void
|
767
|
+
*/
|
768
|
+
next: function() {
|
769
|
+
if (this.dialog && !this.timer) {
|
770
|
+
var id = this.links.indexOf(this.link),
|
771
|
+
link = this.links[id + 1];
|
772
|
+
|
773
|
+
if (link) {
|
774
|
+
this.dialog.load(link);
|
775
|
+
this.timeout();
|
776
|
+
}
|
777
|
+
}
|
778
|
+
},
|
779
|
+
|
780
|
+
// private
|
781
|
+
|
782
|
+
// finding the links list
|
783
|
+
find: function(group) {
|
784
|
+
return $$('a').filter(function(link) {
|
785
|
+
var data = link.get('data-lightbox');
|
786
|
+
var rel = link.get('rel');
|
787
|
+
|
788
|
+
return (data && eval("("+ data + ")").group === group) ||
|
789
|
+
(rel && rel.indexOf('lightbox['+ group + ']') > -1);
|
790
|
+
});
|
791
|
+
},
|
792
|
+
|
793
|
+
// having a little nap to prevent ugly quick scrolling
|
794
|
+
timeout: function() {
|
795
|
+
this.timer = R(function() {
|
796
|
+
Pager.timer = null;
|
797
|
+
}).delay(300);
|
798
|
+
}
|
799
|
+
};
|
800
|
+
|
801
|
+
/**
|
802
|
+
* document level hooks
|
803
|
+
*
|
804
|
+
* Copyright (C) 2009-2010 Nikolay Nemshilov
|
805
|
+
*/
|
806
|
+
|
807
|
+
$(document).on({
|
808
|
+
/**
|
809
|
+
* Catches clicks on the target links
|
810
|
+
*
|
811
|
+
* @param Event click
|
812
|
+
* @return void
|
813
|
+
*/
|
814
|
+
click: function(event) {
|
815
|
+
var target = event.find(Lightbox.Options.cssRule) || event.find('a[rel^=lightbox]');
|
816
|
+
|
817
|
+
if (target) {
|
818
|
+
event.stop();
|
819
|
+
new Lightbox({}, target).load(target);
|
820
|
+
}
|
821
|
+
},
|
822
|
+
|
823
|
+
/**
|
824
|
+
* Catches the mousewheel event and tries to scroll
|
825
|
+
* the list of objects on the lightbox
|
826
|
+
*
|
827
|
+
* @param Event mousewheel
|
828
|
+
* @return void
|
829
|
+
*/
|
830
|
+
mousewheel: function(event) {
|
831
|
+
if (Lightbox.current) {
|
832
|
+
event.stop();
|
833
|
+
Lightbox.current.fire((event._.detail || -event._.wheelDelta) < 0 ? 'prev' : 'next');
|
834
|
+
}
|
835
|
+
},
|
836
|
+
|
837
|
+
/**
|
838
|
+
* Handles the navigation form a keyboard
|
839
|
+
*
|
840
|
+
* @param Event keydown
|
841
|
+
* @return void
|
842
|
+
*/
|
843
|
+
keydown: function(event) {
|
844
|
+
var lightbox = Lightbox.current, name = ({
|
845
|
+
27: 'close', // Esc
|
846
|
+
33: 'prev', // PageUp
|
847
|
+
37: 'prev', // Left
|
848
|
+
38: 'prev', // Up
|
849
|
+
39: 'next', // Right
|
850
|
+
40: 'next', // Down
|
851
|
+
34: 'next' // PageDown
|
852
|
+
})[event.keyCode];
|
853
|
+
|
854
|
+
if (lightbox && name) {
|
855
|
+
if (name !== 'close' || lightbox.options.hideOnEsc) {
|
856
|
+
event.stop();
|
857
|
+
lightbox.fire(name);
|
858
|
+
}
|
859
|
+
}
|
860
|
+
}
|
861
|
+
});
|
862
|
+
|
863
|
+
$(window).on({
|
864
|
+
resize: function() {
|
865
|
+
if (Lightbox.current) {
|
866
|
+
Lightbox.current.reposition();
|
867
|
+
Lightbox.current.dialog.resize();
|
868
|
+
}
|
869
|
+
},
|
870
|
+
|
871
|
+
scroll: function(event) {
|
872
|
+
if (Lightbox.current && Browser.IE6) {
|
873
|
+
Lightbox.current.reposition();
|
874
|
+
}
|
875
|
+
}
|
876
|
+
});
|
877
|
+
|
878
|
+
document.write("<style type=\"text/css\">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;z-index:9999;float:none;width:100%;height:100%;margin:0;padding:0;background:none;border:none;text-align:center}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}div.rui-lightbox-dialog{display:inline-block; *display:inline; *zoom:1;position:relative;text-align:left}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;text-shadow:#000 .05em .1em .2em}div.rui-lightbox-body{background-color:white;padding:1em;border-radius:.5em;-moz-border-radius:.5em;-webkit-border-radius:.5em;box-shadow:#000 .1em .2em 1.5em;-moz-box-shadow:#000 .1em .2em 1.5em;-webkit-box-shadow:#000 .1em .2em 1.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%;z-index:999;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:150%;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:#DDD}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}</style>");
|
879
|
+
|
880
|
+
return Lightbox;
|
881
|
+
})(document, RightJS);
|