right-rails 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/MIT-LICENSE +20 -0
- data/README.textile +50 -0
- data/Rakefile +23 -0
- data/generators/right_rails/right_rails_generator.rb +41 -0
- data/generators/right_rails/templates/iframed.html.erb +10 -0
- data/generators/right_scaffold/right_scaffold_generator.rb +53 -0
- data/generators/right_scaffold/templates/controller.rb +99 -0
- data/generators/right_scaffold/templates/helper.rb +2 -0
- data/generators/right_scaffold/templates/layout.html.erb +18 -0
- data/generators/right_scaffold/templates/style.css +54 -0
- data/generators/right_scaffold/templates/view__form.html.erb +16 -0
- data/generators/right_scaffold/templates/view__item.html.erb +13 -0
- data/generators/right_scaffold/templates/view_edit.html.erb +6 -0
- data/generators/right_scaffold/templates/view_index.html.erb +9 -0
- data/generators/right_scaffold/templates/view_new.html.erb +5 -0
- data/generators/right_scaffold/templates/view_show.html.erb +10 -0
- data/init.rb +12 -0
- data/javascripts/right-autocompleter-src.js +303 -0
- data/javascripts/right-autocompleter.js +9 -0
- data/javascripts/right-behavior-src.js +240 -0
- data/javascripts/right-behavior.js +8 -0
- data/javascripts/right-calendar-src.js +855 -0
- data/javascripts/right-calendar.js +9 -0
- data/javascripts/right-dnd-src.js +555 -0
- data/javascripts/right-dnd.js +9 -0
- data/javascripts/right-effects-src.js +425 -0
- data/javascripts/right-effects.js +6 -0
- data/javascripts/right-events-src.js +369 -0
- data/javascripts/right-events.js +6 -0
- data/javascripts/right-json-src.js +176 -0
- data/javascripts/right-json.js +6 -0
- data/javascripts/right-lightbox-src.js +597 -0
- data/javascripts/right-lightbox.js +9 -0
- data/javascripts/right-rails-src.js +269 -0
- data/javascripts/right-rails.js +9 -0
- data/javascripts/right-rater-src.js +248 -0
- data/javascripts/right-rater.js +9 -0
- data/javascripts/right-selectable-src.js +507 -0
- data/javascripts/right-selectable.js +7 -0
- data/javascripts/right-slider-src.js +291 -0
- data/javascripts/right-slider.js +7 -0
- data/javascripts/right-sortable-src.js +221 -0
- data/javascripts/right-sortable.js +9 -0
- data/javascripts/right-src.js +4939 -0
- data/javascripts/right-tabs-src.js +776 -0
- data/javascripts/right-tabs.js +6 -0
- data/javascripts/right-tooltips-src.js +130 -0
- data/javascripts/right-tooltips.js +9 -0
- data/javascripts/right-ui-i18n-de.js +29 -0
- data/javascripts/right-ui-i18n-en-us.js +11 -0
- data/javascripts/right-ui-i18n-es.js +29 -0
- data/javascripts/right-ui-i18n-fr.js +29 -0
- data/javascripts/right-ui-i18n-jp.js +33 -0
- data/javascripts/right-ui-i18n-ru.js +29 -0
- data/javascripts/right-ui-i18n-uk.js +29 -0
- data/javascripts/right.js +10 -0
- data/lib/right-rails.rb +11 -0
- data/lib/right_rails/controller_extensions.rb +85 -0
- data/lib/right_rails/helpers/basic.rb +111 -0
- data/lib/right_rails/helpers/forms.rb +239 -0
- data/lib/right_rails/helpers/misc.rb +164 -0
- data/lib/right_rails/helpers/rails.rb +166 -0
- data/lib/right_rails/helpers.rb +5 -0
- data/lib/right_rails/java_script_generator.rb +313 -0
- data/lib/right_rails.rb +6 -0
- data/spec/lib/right_rails/controller_extensions_spec.rb +60 -0
- data/spec/lib/right_rails/helpers/basic_spec.rb +74 -0
- data/spec/lib/right_rails/helpers/forms_spec.rb +51 -0
- data/spec/lib/right_rails/helpers/misc_spec.rb +120 -0
- data/spec/lib/right_rails/helpers/rails_spec.rb +149 -0
- data/spec/lib/right_rails/java_script_generator_spec.rb +317 -0
- data/spec/spec.opts +5 -0
- data/spec/spec_helper.rb +15 -0
- metadata +128 -0
@@ -0,0 +1,269 @@
|
|
1
|
+
/**
|
2
|
+
* Ruby On Rails common Ajax operations conventional wrapper
|
3
|
+
* and underscored aliases for core methods
|
4
|
+
*
|
5
|
+
* http://github.com/MadRabbit/right-rails
|
6
|
+
*
|
7
|
+
* Copyright (C) Nikolay V. Nemshilov aka St.
|
8
|
+
*/
|
9
|
+
|
10
|
+
/**
|
11
|
+
* RR is the common ajax operations wrapper for ruby on rails
|
12
|
+
*
|
13
|
+
* Copyright (C) 2009 Nikolay V. Nemshilov aka St.
|
14
|
+
*/
|
15
|
+
;
|
16
|
+
var RR = {
|
17
|
+
/**
|
18
|
+
* Basic options
|
19
|
+
*
|
20
|
+
* NOTE: DO NOT CHANGE this hash right here
|
21
|
+
* Use your application.js file to alter the options
|
22
|
+
*/
|
23
|
+
Options: {
|
24
|
+
format: 'js', // the working format for remote requests over the application
|
25
|
+
|
26
|
+
flashId: 'flashes', // the flashes element id
|
27
|
+
flashHideFx: 'slide', // use null if you don't want any fx in here
|
28
|
+
flashHideDelay: 3200, // use -1 to disable the flash element hidding
|
29
|
+
|
30
|
+
highlightUpdates: true,
|
31
|
+
|
32
|
+
removeFx: 'fade'
|
33
|
+
},
|
34
|
+
|
35
|
+
/**
|
36
|
+
* Updates the flashes block with the source
|
37
|
+
*
|
38
|
+
* @param String new content
|
39
|
+
* @return RR this
|
40
|
+
*/
|
41
|
+
update_flash: function(content) {
|
42
|
+
var element = $(this.Options.flashId);
|
43
|
+
if (element) {
|
44
|
+
this.replace(element, content).hide_flash();
|
45
|
+
}
|
46
|
+
return this;
|
47
|
+
},
|
48
|
+
|
49
|
+
/**
|
50
|
+
* Initializes the delayed flashes hide call
|
51
|
+
*
|
52
|
+
* @return RR this
|
53
|
+
*/
|
54
|
+
hide_flash: function() {
|
55
|
+
if (this.Options.flashHideDelay > -1) {
|
56
|
+
var element = $(this.Options.flashId);
|
57
|
+
if (element && element.visible()) {
|
58
|
+
element.hide.bind(element, this.Options.flashHideFx).delay(this.Options.flashHideDelay);
|
59
|
+
}
|
60
|
+
}
|
61
|
+
return this;
|
62
|
+
},
|
63
|
+
|
64
|
+
/**
|
65
|
+
* Highlights the element according to the options
|
66
|
+
*
|
67
|
+
* @param String element id
|
68
|
+
* @return RR this
|
69
|
+
*/
|
70
|
+
highlight: function(id) {
|
71
|
+
if (this.Options.highlightUpdates) {
|
72
|
+
$(id).highlight();
|
73
|
+
}
|
74
|
+
return this;
|
75
|
+
},
|
76
|
+
|
77
|
+
/**
|
78
|
+
* Inserts the content into the given element
|
79
|
+
*
|
80
|
+
* @param String destination id
|
81
|
+
* @param String content
|
82
|
+
* @return RR this
|
83
|
+
*/
|
84
|
+
insert: function(where, what) {
|
85
|
+
return this.highlight($(where).insert(what).lastChild).rescan();
|
86
|
+
},
|
87
|
+
|
88
|
+
/**
|
89
|
+
* Replaces the given element with a new content
|
90
|
+
*
|
91
|
+
* @param String destination id
|
92
|
+
* @param String content
|
93
|
+
* @return RR this
|
94
|
+
*/
|
95
|
+
replace: function(id, source) {
|
96
|
+
$(id).replace(source);
|
97
|
+
return this.highlight(id).rescan();
|
98
|
+
},
|
99
|
+
|
100
|
+
/**
|
101
|
+
* removes the element by id
|
102
|
+
*
|
103
|
+
* @param String element id
|
104
|
+
* @return RR this
|
105
|
+
*/
|
106
|
+
remove: function(id) {
|
107
|
+
var element = $(id);
|
108
|
+
if (element) {
|
109
|
+
if (this.Options.removeFx) {
|
110
|
+
element.hide(this.Options.removeFx, {
|
111
|
+
onFinish: element.remove.bind(element)
|
112
|
+
});
|
113
|
+
} else {
|
114
|
+
element.remove();
|
115
|
+
}
|
116
|
+
}
|
117
|
+
},
|
118
|
+
|
119
|
+
/**
|
120
|
+
* Makes a remote form out of the form
|
121
|
+
*
|
122
|
+
* @param String form id
|
123
|
+
* @return RR this
|
124
|
+
*/
|
125
|
+
remotize_form: function(id) {
|
126
|
+
var form = $(id);
|
127
|
+
if (form) {
|
128
|
+
form.remotize().enable().action += '.'+this.Options.format;
|
129
|
+
}
|
130
|
+
return this;
|
131
|
+
},
|
132
|
+
|
133
|
+
/**
|
134
|
+
* Replaces the form with new content and makes it remote
|
135
|
+
*
|
136
|
+
* @param String form id
|
137
|
+
* @param String content
|
138
|
+
* @return RR this
|
139
|
+
*/
|
140
|
+
replace_form: function(id, source) {
|
141
|
+
var form = $(id);
|
142
|
+
if (form) {
|
143
|
+
form.replace(source);
|
144
|
+
this.remotize_form(id);
|
145
|
+
}
|
146
|
+
|
147
|
+
return this.rescan();
|
148
|
+
},
|
149
|
+
|
150
|
+
/**
|
151
|
+
* Inserts the form source into the given element
|
152
|
+
*
|
153
|
+
* @param String target id
|
154
|
+
* @param String form source
|
155
|
+
* @return RR this
|
156
|
+
*/
|
157
|
+
show_form_for: function(id, source) {
|
158
|
+
$(id).select('form').each('remove'); // removing old forms
|
159
|
+
$(id).insert(source);
|
160
|
+
|
161
|
+
return this.remotize_form($(id).first('form')).rescan();
|
162
|
+
},
|
163
|
+
|
164
|
+
/**
|
165
|
+
* Hijacks the action links and makes them remote
|
166
|
+
*
|
167
|
+
* @return RR self
|
168
|
+
*/
|
169
|
+
hijack_links: function() {
|
170
|
+
this._links = this._links || [];
|
171
|
+
|
172
|
+
$$('a.edit, a.destroy').each(function(link) {
|
173
|
+
var uid = $uid(link);
|
174
|
+
if (!this._links[uid]) {
|
175
|
+
this._links[uid] = true;
|
176
|
+
|
177
|
+
if (link.hasClass('destroy')) {
|
178
|
+
link.onclick = eval('({f:'+ link.onclick.toString().replace('.submit', '.send')+'})').f;
|
179
|
+
} else if (link.hasClass('edit')) {
|
180
|
+
link.onclick = function(event) { event.stop();
|
181
|
+
Xhr.load(link.href + '.' + this.Options.format);
|
182
|
+
}.bind(this);
|
183
|
+
}
|
184
|
+
}
|
185
|
+
}, this);
|
186
|
+
|
187
|
+
return this;
|
188
|
+
},
|
189
|
+
|
190
|
+
/**
|
191
|
+
* Scans for updated elements
|
192
|
+
*
|
193
|
+
* @return RR this
|
194
|
+
*/
|
195
|
+
rescan: function() {
|
196
|
+
this.hijack_links();
|
197
|
+
|
198
|
+
$w('Lightbox Calendar Autocompleter Draggable Droppable Sortable Tabs Slider Rater Selectable'
|
199
|
+
).each(function(name) {
|
200
|
+
if (self[name]) self[name].rescan();
|
201
|
+
});
|
202
|
+
|
203
|
+
|
204
|
+
return this;
|
205
|
+
}
|
206
|
+
};
|
207
|
+
|
208
|
+
// the document onload hook
|
209
|
+
document.onReady(function() {
|
210
|
+
RR.hide_flash().rescan();
|
211
|
+
});
|
212
|
+
/**
|
213
|
+
* Underscored aliases for Ruby On Rails
|
214
|
+
*
|
215
|
+
* Copyright (C) 2009 Nikolay V. Nemshilov aka St.
|
216
|
+
*/
|
217
|
+
|
218
|
+
// the language and window level aliases
|
219
|
+
[String.prototype, Array.prototype, Function.prototype, Object, Options, Observer, Observer.prototype, window, document].each(function(object) {
|
220
|
+
for (var key in object) {
|
221
|
+
try { // some keys are not accessable
|
222
|
+
|
223
|
+
if (/[A-Z]/.test(key) && typeof(object[key]) == 'function') {
|
224
|
+
var u_key = key.underscored();
|
225
|
+
if (object[u_key] === null || object[u_key] === undefined) {
|
226
|
+
object[u_key] = object[key];
|
227
|
+
}
|
228
|
+
}
|
229
|
+
} catch (e) {}
|
230
|
+
}
|
231
|
+
});
|
232
|
+
|
233
|
+
|
234
|
+
// DOM package aliases
|
235
|
+
[Element, Event, Form, Form.Element].each(function(object) {
|
236
|
+
var aliases = {}, methods = object.Methods;
|
237
|
+
|
238
|
+
for (var key in methods) {
|
239
|
+
if (/[A-Z]/.test(key) && typeof(methods[key]) == 'function') {
|
240
|
+
aliases[key.underscored()] = methods[key];
|
241
|
+
}
|
242
|
+
}
|
243
|
+
|
244
|
+
object.addMethods(aliases);
|
245
|
+
});
|
246
|
+
|
247
|
+
|
248
|
+
// various ruby-like method aliases
|
249
|
+
$alias(String.prototype, {
|
250
|
+
index_of: 'indexOf',
|
251
|
+
last_index_of: 'lastIndexOf',
|
252
|
+
to_f: 'toFloat',
|
253
|
+
to_i: 'toInt',
|
254
|
+
gsub: 'replace',
|
255
|
+
downcase: 'toLowerCase',
|
256
|
+
upcase: 'toUpperCase',
|
257
|
+
index: 'indexOf',
|
258
|
+
rindex: 'lastIndexOf',
|
259
|
+
strip: 'trim'
|
260
|
+
});
|
261
|
+
|
262
|
+
$alias(Array.prototype, {
|
263
|
+
collect: 'map',
|
264
|
+
detect: 'filter',
|
265
|
+
index_of: 'indexOf',
|
266
|
+
last_index_of: 'lastIndexOf',
|
267
|
+
index: 'indexOf',
|
268
|
+
rindex: 'lastIndexOf'
|
269
|
+
});
|
@@ -0,0 +1,9 @@
|
|
1
|
+
/**
|
2
|
+
* Ruby On Rails common Ajax operations conventional wrapper
|
3
|
+
* and underscored aliases for core methods
|
4
|
+
*
|
5
|
+
* http://github.com/MadRabbit/right-rails
|
6
|
+
*
|
7
|
+
* Copyright (C) Nikolay V. Nemshilov aka St.
|
8
|
+
*/
|
9
|
+
eval((function(s,d){for(var i=d.length-1;i>-1;i--)if(d[i])s=s.replace(new RegExp(i,'g'),d[i]);return s})(";13 RR={6:{31:'js',26:'flashes',28:'slide',12:3200,1555:50,19Fx:'fade'},update_flash:4(c){13 e=$(5.6.26);if(e)5.10(e,c).17();7 5},17:4(){if(5.6.12>-1){13 e=$(5.6.26);if(e&&e.visible())e.48.39(e,5.6.28).delay(5.6.12)}7 5},15:4(i){if(5.6.1555)$(i).15();7 5},30:4(a,w){7 5.15($(a).30(w).lastChild).9()},10:4(i,s){$(i).10(s);7 5.15(i).9()},19:4(i){13 e=$(i);if(e){if(5.6.19Fx)e.48(5.6.19Fx,{onFinish:e.19.39(e)});46 e.19()}},14:4(i){13 f=$(i);if(f)f.remotize().enable().action+='.'+5.6.31;7 5},10_52:4(i,s){13 f=$(i);if(f){f.10(s);5.14(i)}7 5.9()},show_52_54:4(i,s){$(i).select('52').25('19');$(i).30(s);7 5.14($(i).first('52')).9()},hijack22:4(){5.22=5.22||[];$$('a.51, a.38').25(4(l){13 u=$uid(l);if(!5.22[u]){5.22[u]=50;if(l.35('38'))l.29=eval('({f:'+l.29.to41().10('.submit','.send')+'})').f;46 if(l.35('51')){l.29=4(e){e.stop();Xhr.load(l.href+'.'+5.6.31)}.39(5)}}},5);7 5},9:4(){5.hijack22();$w('Lightbox Calendar Autocompleter Draggable Droppable Sortable Tabs Slider Rater Selectable').25(4(n){if(53[n])53[n].9()});7 5}};36.onReady(4(){RR.17().9()});[41.8,44.8,Function.8,Object,6,33,33.8,window,36].25(4(o){54(13 k in o)try{if(/[A-Z]/.47(k)&&40(o[k])=='4'){13 u=k.27();if(o[u]===null||o[u]===undefined)o[u]=o[k]}}catch(e){}});[37,Event,49,49.37].25(4(o){13 a={},m=o.56;54(13 k in m)if(/[A-Z]/.47(k)&&40(m[k])=='4')a[k.27()]=m[k];o.add56(a)});43(41.8,{34:'18',21:'11',to_f:'toFloat',to_i:'toInt',gsub:'10',downcase:'toLower57',upcase:'toUpper57',45:'18',42:'11',strip:'trim'});43(44.8,{collect:'map',detect:'filter',34:'18',21:'11',45:'18',42:'11'});",",,,,function,this,Options,return,prototype,rescan,replace,lastIndexOf,flashHideDelay,var,remotize_form,highlight,highlightUpdates,hide_flash,indexOf,remove,,last_index_of,_links,removeFx,hijack_links,each,flashId,underscored,flashHideFx,onclick,insert,format,,Observer,index_of,hasClass,document,Element,destroy,bind,typeof,String,rindex,$alias,Array,index,else,test,hide,Form,true,edit,form,self,for,Updates,Methods,Case".split(",")));
|
@@ -0,0 +1,248 @@
|
|
1
|
+
/**
|
2
|
+
* Simple rating script
|
3
|
+
*
|
4
|
+
* Visit http://rightjs.org/ui/rater for details
|
5
|
+
*
|
6
|
+
* Copyright (C) 2009 Nikolay V. Nemshilov aka St.
|
7
|
+
*/
|
8
|
+
if (!self.RightJS) throw "Gimme RightJS";
|
9
|
+
|
10
|
+
/**
|
11
|
+
* The Rating widget
|
12
|
+
*
|
13
|
+
* Copyright (C) 2009 Nikolay V. Nemshilov aka St.
|
14
|
+
*/
|
15
|
+
var Rater = new Class(Observer, {
|
16
|
+
extend: {
|
17
|
+
EVENTS: $w('change hover send'),
|
18
|
+
|
19
|
+
Options: {
|
20
|
+
size: 5, // number of stars in the line
|
21
|
+
value: null, // default value
|
22
|
+
update: null, // an element to update
|
23
|
+
|
24
|
+
disabled: false, // if it should be disabled
|
25
|
+
disableOnVote: false, // if it should be disabled when user clicks a value
|
26
|
+
|
27
|
+
url: null, // an url to send results with AJAX
|
28
|
+
param: 'rate', // the value param name
|
29
|
+
Xhr: null // additional Xhr options
|
30
|
+
},
|
31
|
+
|
32
|
+
// searches and initializes rating units
|
33
|
+
rescan: function() {
|
34
|
+
$$('div.right-rater').each(function(element) {
|
35
|
+
if (!element._rater) new Rater(element);
|
36
|
+
});
|
37
|
+
}
|
38
|
+
},
|
39
|
+
|
40
|
+
/**
|
41
|
+
* basic constructor
|
42
|
+
*
|
43
|
+
* @param mixed element reference or an options hash
|
44
|
+
* @param Object options hash
|
45
|
+
*/
|
46
|
+
initialize: function() {
|
47
|
+
var args = $A(arguments);
|
48
|
+
|
49
|
+
this.element = (args[0] && !isHash(args[0])) ? $(args[0]) : null;
|
50
|
+
this.$super(isHash(args.last()) ? args.last() : this.element ? eval('('+this.element.get('data-rater-options')+')') : null);
|
51
|
+
|
52
|
+
if (!this.element) this.element = this.build();
|
53
|
+
|
54
|
+
this.element._rater = this.init();
|
55
|
+
},
|
56
|
+
|
57
|
+
/**
|
58
|
+
* Sets the element value
|
59
|
+
*
|
60
|
+
* @param Number or String value
|
61
|
+
* @return Rater this
|
62
|
+
*/
|
63
|
+
setValue: function(value) {
|
64
|
+
if (!this.disabled()) {
|
65
|
+
// converting the type and rounding the value
|
66
|
+
value = isString(value) ? value.toInt() : value;
|
67
|
+
value = isNumber(value) ? value.round() : 0;
|
68
|
+
|
69
|
+
// checking constraints
|
70
|
+
if (value > this.options.size) value = this.options.size;
|
71
|
+
else if (value < 0) value = 0;
|
72
|
+
|
73
|
+
this.highlight(value);
|
74
|
+
|
75
|
+
if (this.value != value) {
|
76
|
+
this.fire('change', this.value = value, this);
|
77
|
+
}
|
78
|
+
}
|
79
|
+
|
80
|
+
return this;
|
81
|
+
},
|
82
|
+
|
83
|
+
/**
|
84
|
+
* Returns the current value of the rater
|
85
|
+
*
|
86
|
+
* @return Number value
|
87
|
+
*/
|
88
|
+
getValue: function() {
|
89
|
+
return this.value;
|
90
|
+
},
|
91
|
+
|
92
|
+
/**
|
93
|
+
* Inserts the rater into the given element
|
94
|
+
*
|
95
|
+
* @param mixed element reference
|
96
|
+
* @param String optional position
|
97
|
+
* @return Rater this
|
98
|
+
*/
|
99
|
+
insertTo: function(element, position) {
|
100
|
+
this.element.insertTo(element, position);
|
101
|
+
return this;
|
102
|
+
},
|
103
|
+
|
104
|
+
/**
|
105
|
+
* Assigns the unit to work with an input element
|
106
|
+
*
|
107
|
+
* @param mixed element reference
|
108
|
+
* @return Rater this
|
109
|
+
*/
|
110
|
+
assignTo: function(element) {
|
111
|
+
var assign = function(element, value) {
|
112
|
+
if (element = $(element)) {
|
113
|
+
if (value === undefined || value === null) value = '';
|
114
|
+
element[element.setValue ? 'setValue' : 'update'](''+value);
|
115
|
+
}
|
116
|
+
}.curry(element);
|
117
|
+
|
118
|
+
var connect = function(element, object) {
|
119
|
+
var element = $(element);
|
120
|
+
if (element && element.onChange) {
|
121
|
+
element.onChange(function() {
|
122
|
+
this.setValue(element.value);
|
123
|
+
}.bind(object));
|
124
|
+
}
|
125
|
+
}.curry(element);
|
126
|
+
|
127
|
+
if ($(element)) {
|
128
|
+
assign(this.value);
|
129
|
+
connect(this);
|
130
|
+
} else {
|
131
|
+
document.onReady(function() {
|
132
|
+
assign(this.value);
|
133
|
+
connect(this);
|
134
|
+
}.bind(this));
|
135
|
+
}
|
136
|
+
|
137
|
+
return this.onChange(assign);
|
138
|
+
},
|
139
|
+
|
140
|
+
/**
|
141
|
+
* Sends an Xhr request with the current value to the options.url address
|
142
|
+
*
|
143
|
+
* @return Rater this
|
144
|
+
*/
|
145
|
+
send: function() {
|
146
|
+
if (this.options.url) {
|
147
|
+
new Xhr(this.options.url, this.options.Xhr).send(this.options.param+"="+this.value);
|
148
|
+
this.fire('send', this.value, this);
|
149
|
+
}
|
150
|
+
return this;
|
151
|
+
},
|
152
|
+
|
153
|
+
/**
|
154
|
+
* Disables the instance
|
155
|
+
*
|
156
|
+
* @return Rater this
|
157
|
+
*/
|
158
|
+
disable: function() {
|
159
|
+
this.element.addClass('right-rater-disabled');
|
160
|
+
return this;
|
161
|
+
},
|
162
|
+
|
163
|
+
/**
|
164
|
+
* Enables this instance
|
165
|
+
*
|
166
|
+
* @return Rater this
|
167
|
+
*/
|
168
|
+
enable: function() {
|
169
|
+
this.element.removeClass('right-rater-disabled');
|
170
|
+
return this;
|
171
|
+
},
|
172
|
+
|
173
|
+
/**
|
174
|
+
* Checks if the instance is disabled
|
175
|
+
*
|
176
|
+
* @return boolean
|
177
|
+
*/
|
178
|
+
disabled: function() {
|
179
|
+
return this.element.hasClass('right-rater-disabled');
|
180
|
+
},
|
181
|
+
|
182
|
+
// protected
|
183
|
+
|
184
|
+
// callback for 'hover' event
|
185
|
+
hovered: function(index) {
|
186
|
+
if (!this.disabled()) {
|
187
|
+
this.highlight(index + 1);
|
188
|
+
this.fire('hover', index + 1, this);
|
189
|
+
}
|
190
|
+
},
|
191
|
+
|
192
|
+
// callback for user-click
|
193
|
+
clicked: function(index) {
|
194
|
+
this.setValue(index + 1);
|
195
|
+
if (this.options.disableOnVote) this.disable();
|
196
|
+
this.send();
|
197
|
+
},
|
198
|
+
|
199
|
+
// callback when user moves the mouse out
|
200
|
+
leaved: function() {
|
201
|
+
this.setValue(this.value);
|
202
|
+
},
|
203
|
+
|
204
|
+
// highlights the stars
|
205
|
+
highlight: function(number) {
|
206
|
+
this.stars.each(function(element, i) {
|
207
|
+
element[number - 1 < i ? 'removeClass' : 'addClass']('right-rater-glow');
|
208
|
+
});
|
209
|
+
},
|
210
|
+
|
211
|
+
// initializes the script
|
212
|
+
init: function() {
|
213
|
+
this.stars = this.element.subNodes();
|
214
|
+
|
215
|
+
this.stars.each(function(element, index) {
|
216
|
+
element.onMouseover(this.hovered.bind(this, index))
|
217
|
+
.onClick(this.clicked.bind(this, index));
|
218
|
+
}, this);
|
219
|
+
|
220
|
+
this.element.onMouseout(this.leaved.bind(this));
|
221
|
+
this.setValue(this.options.value);
|
222
|
+
|
223
|
+
if (this.options.disabled) this.disable();
|
224
|
+
if (this.options.update) this.assignTo(this.options.update);
|
225
|
+
|
226
|
+
return this;
|
227
|
+
},
|
228
|
+
|
229
|
+
// builds the elements structure
|
230
|
+
build: function() {
|
231
|
+
var element = $E('div', {'class': 'right-rater'});
|
232
|
+
|
233
|
+
this.options.size.times(function() {
|
234
|
+
element.insert($E('div', {html: '★'}));
|
235
|
+
});
|
236
|
+
|
237
|
+
return element;
|
238
|
+
}
|
239
|
+
});
|
240
|
+
|
241
|
+
/**
|
242
|
+
* Document on-load trigger for units auto-discovery
|
243
|
+
*
|
244
|
+
* Copyright (C) 2009 Nikolay V. Nemshilov aka St.
|
245
|
+
*/
|
246
|
+
document.onReady(function() { Rater.rescan(); });
|
247
|
+
|
248
|
+
document.write("<style type=\"text/css\">div.right-rater,div.right-rater div{margin:0;padding:0;background:none;border:none;display:inline-block;*display:inline;*zoom:1;font-family:Arial;font-size:110%}div.right-rater{width:6em;vertical-align:middle}div.right-rater div{width:1em;height:1em;line-height:1em;text-align:center;cursor:pointer;color:#888}div.right-rater div.right-rater-glow{color:brown;text-shadow:#666 .05em .05em .15em}div.right-rater-disabled div{cursor:default}</style>");
|
@@ -0,0 +1,9 @@
|
|
1
|
+
/**
|
2
|
+
* Simple rating script
|
3
|
+
*
|
4
|
+
* Visit http://rightjs.org/ui/rater for details
|
5
|
+
*
|
6
|
+
* Copyright (C) 2009 Nikolay V. Nemshilov aka St.
|
7
|
+
*/
|
8
|
+
if (!self.RightJS) throw "Gimme RightJS";
|
9
|
+
eval((function(s,d){for(var i=d.length-1;i>-1;i--)if(d[i])s=s.replace(new RegExp(i,'g'),d[i]);return s})("32 39=59 77(Observer,{extend:{EVENTS:$w('53 55 29'),Options:{28:5,19:22,25:22,16:58,24:58,62:22,61:'rate',60:22},51:4(){$$('21.17-14').44(4(e){if(!e._14)59 39(e)})}},71ialize:4(){32 a=$A(arguments);2.13=(a[0]&&!47(a[0]))?$(a[0]):22;2.$super(47(a.70())?a.70():2.13?eval('('+2.13.get('data-14-12')+')'):22);if(!2.13)2.13=2.63();2.13._14=2.71()},20:4(v){if(!2.16()){v=isString(v)?v.toInt():v;v=isNumber(v)?v.round():0;if(v>2.12.28)v=2.12.28;69 if(v<0)v=0;2.23(v);if(2.19!=v)2.45('53',2.19=v,2)}18 2},getValue:4(){18 2.19},38:4(e,p){2.13.38(e,p);18 2},36:4(b){32 a=4(e,v){if(e=$(e)){if(v===undefined||v===22)v='';e[e.20?'20':'25'](''+v)}}.57(b);32 c=4(e,o){32 e=$(e);if(e&&e.27)e.27(4(){2.20(e.19)}.30(o))}.57(b);if($(b)){a(2.19);c(2)}69 26.41(4(){a(2.19);c(2)}.30(2));18 2.27(a)},29:4(){if(2.12.62){59 60(2.12.62,2.12.60).29(2.12.61+\"=\"+2.19);2.45('29',2.19,2)}18 2},31:4(){2.13.35('17-14-16');18 2},enable:4(){2.13.34('17-14-16');18 2},16:4(){18 2.13.has77('17-14-16')},40:4(i){if(!2.16()){2.23(i+1);2.45('55',i+1,2)}},43:4(i){2.20(i+1);if(2.12.24)2.31();2.29()},54:4(){2.20(2.19)},23:4(n){2.37.44(4(e,a){e[n-1<a?'34':'35']('17-14-74')})},71:4(){2.37=2.13.subNodes();2.37.44(4(e,i){e.onMouseover(2.40.30(2,i)).onClick(2.43.30(2,i))},2);2.13.onMouseout(2.54.30(2));2.20(2.12.19);if(2.12.16)2.31();if(2.12.25)2.36(2.12.25);18 2},63:4(){32 e=$E('21',{'class':'17-14'});2.12.28.times(4(){e.insert($E('21',{html:'★'}))});18 e}});26.41(4(){39.51()});26.write(\"<65 type=\\\"46/css\\\">21.17-14,21.17-14 21{margin:0;padding:0;background:75;border:75;42:52-block;*42:52;*zoom:1;76-family:Arial;76-28:110%}21.17-14{67:6em;vertical-68:middle}21.17-14 21{67:64;48:64;line-48:64;46-68:center;50:pointer;56:#888}21.17-14 21.17-14-74{56:brown;46-shadow:#666 .72 .72 .15em}21.17-14-16 21{50:default}</65>\");",",,this,,function,,,,,,,,options,element,rater,,disabled,right,return,value,setValue,div,null,highlight,disableOnVote,update,document,onChange,size,send,bind,disable,var,,removeClass,addClass,assignTo,stars,insertTo,Rater,hovered,onReady,display,clicked,each,fire,text,isHash,height,_rater,cursor,rescan,inline,change,leaved,hover,color,curry,false,new,Xhr,param,url,build,1em,style,,width,align,else,last,init,05em,,glow,none,font,Class".split(",")));
|