right-rails 0.6.0 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (118) hide show
  1. data/CHANGELOG +8 -0
  2. data/README.rdoc +71 -0
  3. data/Rakefile +144 -14
  4. data/generators/right_rails/right_rails_generator.rb +18 -21
  5. data/init.rb +11 -32
  6. data/lib/generators/right_rails/right_rails_generator.rb +27 -0
  7. data/lib/generators/right_rails/templates/iframed.html.erb +10 -0
  8. data/lib/right-rails.rb +1 -1
  9. data/lib/right_rails/config.rb +278 -0
  10. data/lib/right_rails/controller_extensions.rb +10 -5
  11. data/lib/right_rails/helpers/basic.rb +10 -66
  12. data/lib/right_rails/helpers/forms.rb +141 -139
  13. data/lib/right_rails/helpers/misc.rb +45 -67
  14. data/lib/right_rails/helpers/rails.rb +40 -105
  15. data/lib/right_rails/helpers.rb +364 -1
  16. data/lib/right_rails/java_script_generator.rb +34 -24
  17. data/lib/right_rails.rb +6 -1
  18. data/{images → public/images}/colorpicker.png +0 -0
  19. data/{images → public/images}/resizable.png +0 -0
  20. data/public/javascripts/right/autocompleter-src.js +612 -0
  21. data/public/javascripts/right/autocompleter.js +18 -0
  22. data/public/javascripts/right/calendar-src.js +1448 -0
  23. data/public/javascripts/right/calendar.js +36 -0
  24. data/public/javascripts/right/colorpicker-src.js +967 -0
  25. data/public/javascripts/right/colorpicker.js +26 -0
  26. data/{javascripts/right-dnd-src.js → public/javascripts/right/dnd-src.js} +86 -52
  27. data/public/javascripts/right/dnd.js +20 -0
  28. data/{javascripts/right-effects-src.js → public/javascripts/right/effects-src.js} +90 -45
  29. data/public/javascripts/right/effects.js +17 -0
  30. data/{javascripts/right-ui-i18n-de.js → public/javascripts/right/i18n/de.js} +7 -7
  31. data/{javascripts/right-ui-i18n-en-us.js → public/javascripts/right/i18n/en-us.js} +1 -1
  32. data/{javascripts/right-ui-i18n-es.js → public/javascripts/right/i18n/es.js} +7 -7
  33. data/{javascripts/right-ui-i18n-fr.js → public/javascripts/right/i18n/fr.js} +7 -7
  34. data/{javascripts/right-ui-i18n-hu.js → public/javascripts/right/i18n/hu.js} +7 -7
  35. data/{javascripts/right-ui-i18n-jp.js → public/javascripts/right/i18n/jp.js} +7 -7
  36. data/{javascripts/right-ui-i18n-nl.js → public/javascripts/right/i18n/nl.js} +7 -7
  37. data/{javascripts/right-ui-i18n-pt-br.js → public/javascripts/right/i18n/pt-br.js} +7 -7
  38. data/{javascripts/right-ui-i18n-ru.js → public/javascripts/right/i18n/ru.js} +7 -7
  39. data/{javascripts/right-ui-i18n-ua.js → public/javascripts/right/i18n/ua.js} +17 -12
  40. data/public/javascripts/right/in-edit-src.js +352 -0
  41. data/public/javascripts/right/in-edit.js +13 -0
  42. data/public/javascripts/right/json-src.js +160 -0
  43. data/public/javascripts/right/json.js +10 -0
  44. data/public/javascripts/right/lightbox-src.js +881 -0
  45. data/public/javascripts/right/lightbox.js +24 -0
  46. data/{javascripts/right-rails-src.js → public/javascripts/right/rails-src.js} +195 -171
  47. data/public/javascripts/right/rails.js +14 -0
  48. data/public/javascripts/right/rater-src.js +366 -0
  49. data/public/javascripts/right/rater.js +13 -0
  50. data/public/javascripts/right/resizable-src.js +420 -0
  51. data/public/javascripts/right/resizable.js +15 -0
  52. data/public/javascripts/right/selectable-src.js +687 -0
  53. data/public/javascripts/right/selectable.js +22 -0
  54. data/public/javascripts/right/slider-src.js +377 -0
  55. data/public/javascripts/right/slider.js +14 -0
  56. data/public/javascripts/right/sortable-src.js +392 -0
  57. data/public/javascripts/right/sortable.js +16 -0
  58. data/public/javascripts/right/tabs-src.js +1123 -0
  59. data/public/javascripts/right/tabs.js +29 -0
  60. data/public/javascripts/right/tooltip-src.js +307 -0
  61. data/public/javascripts/right/tooltip.js +12 -0
  62. data/public/javascripts/right/uploader-src.js +283 -0
  63. data/public/javascripts/right/uploader.js +13 -0
  64. data/{javascripts → public/javascripts}/right-olds-src.js +134 -186
  65. data/public/javascripts/right-olds.js +18 -0
  66. data/public/javascripts/right-safe-src.js +161 -0
  67. data/public/javascripts/right-safe.js +8 -0
  68. data/{javascripts → public/javascripts}/right-src.js +2558 -1750
  69. data/public/javascripts/right.js +92 -0
  70. data/spec/lib/right_rails/config_spec.rb +133 -0
  71. data/spec/lib/right_rails/controller_extensions_spec.rb +1 -1
  72. data/spec/lib/right_rails/helpers/basic_spec.rb +77 -66
  73. data/spec/lib/right_rails/helpers/forms_spec.rb +231 -33
  74. data/spec/lib/right_rails/helpers/misc_spec.rb +94 -26
  75. data/spec/lib/right_rails/helpers/rails_spec.rb +42 -7
  76. data/spec/lib/right_rails/helpers_spec.rb +125 -0
  77. data/spec/lib/right_rails/java_script_generator_spec.rb +30 -0
  78. data/spec/rcov.opts +3 -0
  79. data/spec/spec_helper.rb +12 -7
  80. metadata +70 -61
  81. data/README.textile +0 -69
  82. data/javascripts/right-autocompleter-src.js +0 -318
  83. data/javascripts/right-autocompleter.js +0 -9
  84. data/javascripts/right-behavior-src.js +0 -261
  85. data/javascripts/right-behavior.js +0 -8
  86. data/javascripts/right-calendar-src.js +0 -946
  87. data/javascripts/right-calendar.js +0 -9
  88. data/javascripts/right-colorpicker-src.js +0 -635
  89. data/javascripts/right-colorpicker.js +0 -9
  90. data/javascripts/right-dnd.js +0 -9
  91. data/javascripts/right-effects.js +0 -6
  92. data/javascripts/right-events-src.js +0 -321
  93. data/javascripts/right-events.js +0 -6
  94. data/javascripts/right-in-edit-src.js +0 -194
  95. data/javascripts/right-in-edit.js +0 -6
  96. data/javascripts/right-json-src.js +0 -141
  97. data/javascripts/right-json.js +0 -6
  98. data/javascripts/right-lightbox-src.js +0 -651
  99. data/javascripts/right-lightbox.js +0 -9
  100. data/javascripts/right-olds.js +0 -9
  101. data/javascripts/right-rails.js +0 -9
  102. data/javascripts/right-rater-src.js +0 -253
  103. data/javascripts/right-rater.js +0 -9
  104. data/javascripts/right-resizable-src.js +0 -336
  105. data/javascripts/right-resizable.js +0 -9
  106. data/javascripts/right-selectable-src.js +0 -565
  107. data/javascripts/right-selectable.js +0 -7
  108. data/javascripts/right-slider-src.js +0 -288
  109. data/javascripts/right-slider.js +0 -7
  110. data/javascripts/right-sortable-src.js +0 -225
  111. data/javascripts/right-sortable.js +0 -9
  112. data/javascripts/right-tabs-src.js +0 -937
  113. data/javascripts/right-tabs.js +0 -6
  114. data/javascripts/right-tooltips-src.js +0 -195
  115. data/javascripts/right-tooltips.js +0 -9
  116. data/javascripts/right-uploader-src.js +0 -167
  117. data/javascripts/right-uploader.js +0 -9
  118. data/javascripts/right.js +0 -7
@@ -0,0 +1,366 @@
1
+ /**
2
+ * Rating widget for RightJS
3
+ * http://rightjs.org/ui/rater
4
+ *
5
+ * Copyright (C) 2009-2010 Nikolay Nemshilov
6
+ */
7
+ var Rater = RightJS.Rater = (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 init script for Rater
18
+ *
19
+ * Copyright (C) 2010 Nikolay Nemshilov
20
+ */
21
+ var R = RightJS,
22
+ $ = RightJS.$,
23
+ $w = RightJS.$w,
24
+ Xhr = RightJS.Xhr,
25
+ isString = RightJS.isString,
26
+ isNumber = RightJS.isNumber;
27
+
28
+
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
+ * Same as the assignable, only it doesn't work with popups
121
+ * instead it simply updates the assigned unit value/content
122
+ *
123
+ * Copyright (C) 2010 Nikolay Nemshilov
124
+ */
125
+ var Updater = {
126
+
127
+ /**
128
+ * Assigns the unit to work with an input element
129
+ *
130
+ * @param mixed element reference
131
+ * @return Rater this
132
+ */
133
+ assignTo: function(element) {
134
+ var assign = R(function(element, event) {
135
+ if ((element = $(element))) {
136
+ element[element.setValue ? 'setValue' : 'update'](event.target.getValue());
137
+ }
138
+ }).curry(element);
139
+
140
+ var connect = R(function(element, object) {
141
+ element = $(element);
142
+ if (element && element.onChange) {
143
+ element.onChange(R(function() {
144
+ this.setValue(element.value());
145
+ }).bind(object));
146
+ }
147
+ }).curry(element);
148
+
149
+ if ($(element)) {
150
+ assign({target: this});
151
+ connect(this);
152
+ } else {
153
+ $(document).onReady(R(function() {
154
+ assign({target: this});
155
+ connect(this);
156
+ }.bind(this)));
157
+ }
158
+
159
+ return this.onChange(assign);
160
+ }
161
+ };
162
+
163
+
164
+ /**
165
+ * The Rating widget
166
+ *
167
+ * Copyright (C) 2009-2010 Nikolay Nemshilov
168
+ */
169
+ var Rater = new Widget({
170
+ include: Updater,
171
+
172
+ extend: {
173
+ version: '2.0.0',
174
+
175
+ EVENTS: $w('change hover send'),
176
+
177
+ Options: {
178
+ html: '★', // the dot html code
179
+
180
+ size: 5, // number of stars in the line
181
+ value: null, // default value
182
+ update: null, // an element to update
183
+
184
+ disabled: false, // if it should be disabled
185
+ disableOnVote: false, // if it should be disabled when user clicks a value
186
+
187
+ url: null, // an url to send results with AJAX
188
+ param: 'rate', // the value param name
189
+ Xhr: null // additional Xhr options
190
+ }
191
+ },
192
+
193
+ /**
194
+ * basic constructor
195
+ *
196
+ * @param mixed element reference or an options hash
197
+ * @param Object options hash
198
+ */
199
+ initialize: function(options) {
200
+ this
201
+ .$super('rater', options)
202
+ .on({
203
+ click: this._clicked,
204
+ mouseover: this._hovered,
205
+ mouseout: this._left
206
+ });
207
+
208
+ if (this.empty()) {
209
+ for (var i=0; i < this.options.size; i++) {
210
+ this.insert('<div>'+ this.options.html + '</div>');
211
+ }
212
+ }
213
+
214
+ options = this.options;
215
+
216
+ if (options.value === null) {
217
+ options.value = this.find('.active').length;
218
+ }
219
+
220
+ this.setValue(options.value);
221
+
222
+ if (options.disabled) {
223
+ this.disable();
224
+ }
225
+
226
+ if (options.update) {
227
+ this.assignTo(options.update);
228
+ }
229
+ },
230
+
231
+ /**
232
+ * Sets the element value
233
+ *
234
+ * @param Number or String value
235
+ * @return Rater this
236
+ */
237
+ setValue: function(value) {
238
+ if (!this.disabled()) {
239
+ // converting the type and rounding the value
240
+ value = isString(value) ? R(value).toInt() : value;
241
+ value = isNumber(value) ? R(value).round() : 0;
242
+
243
+ // checking constraints
244
+ value = R(value).max(this.options.size);
245
+ value = R(value).min(0);
246
+
247
+ // highlighting the value
248
+ this.highlight(value);
249
+
250
+ if (this.value != value) {
251
+ this.fire('change', this.value = value, this);
252
+ }
253
+ }
254
+
255
+ return this;
256
+ },
257
+
258
+ /**
259
+ * Returns the current value of the rater
260
+ *
261
+ * @return Number value
262
+ */
263
+ getValue: function() {
264
+ return this.value;
265
+ },
266
+
267
+ /**
268
+ * Sends an Xhr request with the current value to the options.url address
269
+ *
270
+ * @return Rater this
271
+ */
272
+ send: function() {
273
+ if (this.options.url) {
274
+ this.request = new Xhr(this.options.url, this.options.Xhr)
275
+ .send(this.options.param+"="+this.value);
276
+ this.fire('send', this.value, this);
277
+ }
278
+ return this;
279
+ },
280
+
281
+ /**
282
+ * Disables the instance
283
+ *
284
+ * @return Rater this
285
+ */
286
+ disable: function() {
287
+ return this.addClass('rui-rater-disabled');
288
+ },
289
+
290
+ /**
291
+ * Enables this instance
292
+ *
293
+ * @return Rater this
294
+ */
295
+ enable: function() {
296
+ return this.removeClass('rui-rater-disabled');
297
+ },
298
+
299
+ /**
300
+ * Checks if the instance is disabled
301
+ *
302
+ * @return boolean
303
+ */
304
+ disabled: function() {
305
+ return this.hasClass('rui-rater-disabled');
306
+ },
307
+
308
+ // protected
309
+
310
+ // callback for 'hover' event
311
+ _hovered: function(event) {
312
+ var index = this.children().indexOf(event.target);
313
+ if (!this.disabled() && index > -1) {
314
+ this.highlight(index + 1);
315
+ this.fire('hover', index + 1, this);
316
+ }
317
+ },
318
+
319
+ // callback for user-click
320
+ _clicked: function(event) {
321
+ var index = this.children().indexOf(event.target);
322
+ if (!this.disabled() && index > -1) {
323
+ this.setValue(index + 1);
324
+ if (this.options.disableOnVote) {
325
+ this.disable();
326
+ }
327
+ this.send();
328
+ }
329
+ },
330
+
331
+ // callback when user moves the mouse out
332
+ _left: function() {
333
+ this.setValue(this.value);
334
+ },
335
+
336
+ // visually highlights the value
337
+ highlight: function(value) {
338
+ this.children().each(function(element, i) {
339
+ element[value - 1 < i ? 'removeClass' : 'addClass']('active');
340
+ });
341
+ }
342
+ });
343
+
344
+ /**
345
+ * Document level on-demand auto-initialization
346
+ *
347
+ * Copyright (C) 2009-2010 Nikolay Nemshilov
348
+ */
349
+ $(document).onMouseover(function(event) {
350
+ var target = event.target, element = event.find('.rui-rater');
351
+
352
+ if (element) {
353
+ if (!(element instanceof Rater)) {
354
+ element = new Rater(element);
355
+
356
+ if (target.parent() === element) {
357
+ target.fire('mouseover');
358
+ }
359
+ }
360
+ }
361
+ });
362
+
363
+ document.write("<style type=\"text/css\">div.rui-rater,div.rui-rater div{margin:0;padding:0;background:none;border:none;display:inline-block; *display:inline; *zoom:1;font-family:Arial;font-size:110%}div.rui-rater{width:6em;height:1em;vertical-align:middle}div.rui-rater div{float:left;width:1em;height:1em;line-height:1em;text-align:center;cursor:pointer;color:#888}div.rui-rater div.active{color:brown;text-shadow:#666 .05em .05em .15em}div.rui-rater-disabled div{cursor:default}</style>");
364
+
365
+ return Rater;
366
+ })(document, RightJS);
@@ -0,0 +1,13 @@
1
+ /**
2
+ * Rating widget for RightJS
3
+ * http://rightjs.org/ui/rater
4
+ *
5
+ * Copyright (C) 2009-2010 Nikolay Nemshilov
6
+ */
7
+ var Rater=RightJS.Rater=function(h,b){var g=b.$,k=b.$w,l=b.Xhr,m=b.isString,n=b.isNumber,i=new (function(a,e){if(!e){e=a;a="DIV"}var f=new b.Wrapper(b.Element.Wrappers[a]||b.Element,{initialize:function(d,c){this.key=d;var j=[{"class":"rui-"+d}];this instanceof b.Input||this instanceof b.Form||j.unshift(a);this.$super.apply(this,j);if(b.isString(c))c=b.$(c);if(c instanceof b.Element){this._=c._;if("$listeners"in c)c.$listeners=c.$listeners;c={}}this.setOptions(c,this);return this},setOptions:function(d,
8
+ c){c=c||this;b.Options.setOptions.call(this,b.Object.merge(d,eval("("+(c.get("data-"+this.key)||"{}")+")")));return this}});f=new b.Wrapper(f,e);b.Observer.createShortcuts(f.prototype,f.EVENTS||[]);return f})({include:{assignTo:function(a){var e=b(function(d,c){if(d=g(d))d[d.setValue?"setValue":"update"](c.target.getValue())}).curry(a),f=b(function(d,c){(d=g(d))&&d.onChange&&d.onChange(b(function(){this.setValue(d.value())}).bind(c))}).curry(a);if(g(a)){e({target:this});f(this)}else g(h).onReady(b(function(){e({target:this});
9
+ f(this)}.bind(this)));return this.onChange(e)}},extend:{version:"2.0.0",EVENTS:k("change hover send"),Options:{html:"&#9733;",size:5,value:null,update:null,disabled:false,disableOnVote:false,url:null,param:"rate",Xhr:null}},initialize:function(a){this.$super("rater",a).on({click:this._clicked,mouseover:this._hovered,mouseout:this._left});if(this.empty())for(a=0;a<this.options.size;a++)this.insert("<div>"+this.options.html+"</div>");a=this.options;if(a.value===null)a.value=this.find(".active").length;
10
+ this.setValue(a.value);a.disabled&&this.disable();a.update&&this.assignTo(a.update)},setValue:function(a){if(!this.disabled()){a=m(a)?b(a).toInt():a;a=n(a)?b(a).round():0;a=b(a).max(this.options.size);a=b(a).min(0);this.highlight(a);if(this.value!=a)this.fire("change",this.value=a,this)}return this},getValue:function(){return this.value},send:function(){if(this.options.url){this.request=(new l(this.options.url,this.options.Xhr)).send(this.options.param+"="+this.value);this.fire("send",this.value,
11
+ this)}return this},disable:function(){return this.addClass("rui-rater-disabled")},enable:function(){return this.removeClass("rui-rater-disabled")},disabled:function(){return this.hasClass("rui-rater-disabled")},_hovered:function(a){a=this.children().indexOf(a.target);if(!this.disabled()&&a>-1){this.highlight(a+1);this.fire("hover",a+1,this)}},_clicked:function(a){a=this.children().indexOf(a.target);if(!this.disabled()&&a>-1){this.setValue(a+1);this.options.disableOnVote&&this.disable();this.send()}},
12
+ _left:function(){this.setValue(this.value)},highlight:function(a){this.children().each(function(e,f){e[a-1<f?"removeClass":"addClass"]("active")})}});g(h).onMouseover(function(a){var e=a.target;if(a=a.find(".rui-rater"))if(!(a instanceof i)){a=new i(a);e.parent()===a&&e.fire("mouseover")}});h.write('<style type="text/css">div.rui-rater,div.rui-rater div{margin:0;padding:0;background:none;border:none;display:inline-block; *display:inline; *zoom:1;font-family:Arial;font-size:110%}div.rui-rater{width:6em;height:1em;vertical-align:middle}div.rui-rater div{float:left;width:1em;height:1em;line-height:1em;text-align:center;cursor:pointer;color:#888}div.rui-rater div.active{color:brown;text-shadow:#666 .05em .05em .15em}div.rui-rater-disabled div{cursor:default}</style>');
13
+ return i}(document,RightJS);