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,22 @@
|
|
1
|
+
/**
|
2
|
+
* Selectable unit for RightJS
|
3
|
+
* http://rightjs.org/ui/selectable
|
4
|
+
*
|
5
|
+
* Copyright (C) 2009-2010 Nikolay Nemshilov
|
6
|
+
*/
|
7
|
+
var Selectable=RightJS.Selectable=function(h,e){var g=e.$,p=e.$$,q=e.$w,i=e.$E,o=e.$A,r=e.isHash,l=e.isArray,m=e.isString,s=e.isNumber,t=e.defined,u=e.Input,n=e.Element,k=new (function(a,b){if(!b){b=a;a="DIV"}var d=new e.Wrapper(e.Element.Wrappers[a]||e.Element,{initialize:function(c,f){this.key=c;var j=[{"class":"rui-"+c}];this instanceof e.Input||this instanceof e.Form||j.unshift(a);this.$super.apply(this,j);if(e.isString(f))f=e.$(f);if(f instanceof e.Element){this._=f._;if("$listeners"in f)f.$listeners=
|
8
|
+
f.$listeners;f={}}this.setOptions(f,this);return this},setOptions:function(c,f){f=f||this;e.Options.setOptions.call(this,e.Object.merge(c,eval("("+(f.get("data-"+this.key)||"{}")+")")));return this}});d=new e.Wrapper(d,b);e.Observer.createShortcuts(d.prototype,d.EVENTS||[]);return d})("UL",{include:{assignTo:function(a){var b=e(function(c,f){if(c=g(c))c[c.setValue?"setValue":"update"](f.target.getValue())}).curry(a),d=e(function(c,f){(c=g(c))&&c.onChange&&c.onChange(e(function(){this.setValue(c.value())}).bind(f))}).curry(a);
|
9
|
+
if(g(a)){b({target:this});d(this)}else g(h).onReady(e(function(){b({target:this});d(this)}.bind(this)));return this.onChange(b)}},extend:{version:"2.0.0",EVENTS:q("change select unselect disable enable hover leave show hide"),Options:{options:null,selected:null,disabled:null,multiple:true,fxName:"slide",fxDuration:"short",update:null,parseIds:false,limit:null,hCont:"•"},rescan:function(a){g(a||h).find(".rui-selectable").each(function(b){b instanceof k||new k(b)})}},initialize:function(){var a=
|
10
|
+
o(arguments).compact(),b=a.pop();a=a.pop();var d;if(!r(b)||b instanceof n){a=g(a||b);b={}}if(a&&a instanceof u)a=b=this.harvestOptions(d=a);this.$super("selectable",a).setOptions(b).on({mousedown:this._mousedown,mouseover:this._mouseover,mouseout:this._mouseout,mouseup:this._mouseup,click:this._click,select:this._change,unselect:this._change});this.empty()&&this.build();b=this.options;if(!b.multiple||this.hasClass("rui-selectable-single")){this.isSingle=true;this.addClass("rui-selectable-single");
|
11
|
+
this.buildSingle();b.selected===null&&this.select(this.items()[0])}b.disabled&&this.disable(b.disabled);b.selected&&this.select(b.selected);b.update&&this.assignTo(b.update);if(d){this.assignTo(d).insertTo(d,"before");d.wrap(i("div",{style:"position:absolute;z-index:-1;visibility:hidden;width:0;height:0;overflow:hidden"}))}},setValue:function(a){if(m(a))a=a.split(",").map("trim").filter(function(b){return!b.blank()});this.items().each("removeClass","rui-selectable-selected");return this.select(a)},
|
12
|
+
getValue:function(){if(this.isSingle){var a=this.items().first("hasClass","rui-selectable-selected");return a?this.itemValue(a):null}else return this.items().filter("hasClass","rui-selectable-selected").map(function(b){return this.itemValue(b)},this)},disable:function(a){this.mapOrAll(a).each(function(b){this.fire("disable",b.addClass("rui-selectable-disabled"))},this);return this},enable:function(a){this.mapOrAll(a).each(function(b){this.fire("enable",b.removeClass("rui-selectable-disabled"))},this);
|
13
|
+
return this},disabled:function(a){return this.mapOrAll(a).every("hasClass","rui-selectable-disabled")},select:function(a){a=this.mapEnabled(a);if(this.isSingle&&a){this.items().each("removeClass","rui-selectable-selected");a=e([a[0]])}if(!this.isSingle&&this.options.limit){for(var b=this.items().filter("hasClass","rui-selectable-selected"),d=[];a.length&&b.length+d.length<this.options.limit;){var c=a.shift();b.include(c)||d.push(c)}a=d}a.each(function(f){this.fire("select",f.addClass("rui-selectable-selected"))},
|
14
|
+
this);return this},unselect:function(a){this.getValue();this.mapEnabled(a).each(function(b){this.fire("unselect",b.removeClass("rui-selectable-selected"))},this);return this},selected:function(a){return this.mapEnabled(a).every("hasClass","rui-selectable-selected")},insertTo:function(a,b){n.prototype.insertTo.call(this.isSingle?this.container:this,a,b);return this},fire:function(a,b){b&&b instanceof n?this.$super(a,{item:b,index:this.items().indexOf(b)}):this.$super.apply(this,arguments);return this},
|
15
|
+
itemValue:function(a){var b=a.get("id")||a.get("val");return b?this.options.parseIds?b.match(/\d+/):b:this.items().indexOf(a)},items:function(){return this.find("li")},mapOrAll:function(a){var b=this.items();if(t(a)){l(a)||(a=[a]);b=e(a).map(function(d){var c=m(d)&&/^\d+$/.test(d)?parseInt(d,10):d,f=d;if(s(c))f=b[c];else if(m(d))f=b.first(function(j){return j.id==d||j.val==d});return f},this).compact()}return b},mapEnabled:function(a){return this.mapOrAll(a).filter(function(b){return!b.hasClass("rui-selectable-disabled")},
|
16
|
+
this)},_mousedown:function(a){a.stop();var b=a.target,d=this.items();if(!this.disabled(b)){if(this.isSingle)this.select(b);else if(this.selected(b)){this.unselect(b);this._massRemove=true}else{this.select(b);this._massSelect=true}if((a.shiftKey||a.metaKey)&&this._prevItem){var c=d.indexOf(this._prevItem);a=d.indexOf(b);if(c!=a){if(c>a)a=c=a;for(c=c;c<a;c++)this[this._prevItem.hasClass("rui-selectable-selected")?"select":"unselect"](d[c])}}this._prevItem=b}},_mouseup:function(a){a.stop();this._massRemove=
|
17
|
+
this._massSelect=false},_mouseover:function(a){a=a.target;this.fire("hover",a);if(!this.isSingle)if(this._massSelect)this.select(a);else this._massRemove&&this.unselect(a)},_mouseout:function(a){this.fire("leave",a.target)},_click:function(a){a.stop()},_change:function(){if(""+this.value!=""+this.getValue()){this.value=this.getValue();this.fire("change")}},build:function(){var a=this.options.options,b=e([]);if(l(a))a.each(function(c){b.push(l(c)?c:[c,c])});else for(var d in a)b.push([a[d],d]);b.each(function(c){this.insert(i("li",
|
18
|
+
{val:c[1],html:c[0]}))},this);return this},buildSingle:function(){this.container=i("div",{"class":"rui-selectable-container"}).insert([this.trigger=i("div",{html:this.options.hCont,"class":"rui-selectable-handle"}),this.display=i("ul",{"class":"rui-selectable-display"})]).onClick(e(this.toggleList).bind(this));this.parent()&&this.container.insertTo(this,"instead");this.container.insert(this);g(h).onClick(e(this.hideList).bind(this));return this.onSelect("showItem").onSelect("hideList").addClass("rui-dd-menu")},
|
19
|
+
toggleList:function(a){a.stop();return this.visible()?this.hideList():this.showList(a)},showList:function(a){a.stop();p(".rui-selectable-single").without(this).each("hide");a=this.container.dimensions();var b=this.container.position();this.setStyle({top:a.top+a.height-b.y-1+"px",left:a.left-b.x+"px",width:a.width+"px"}).show(this.options.fxName,{duration:this.options.fxDuration,onFinish:this.fire.bind(this,"show",this)});this.options.fxName||this.fire("show",this)},hideList:function(){if(this.isSingle&&
|
20
|
+
this.visible()){this.hide(this.options.fxName,{duration:this.options.fxDuration,onFinish:this.fire.bind(this,"hide")});this.options.fxName||this.fire("hide")}},showItem:function(){var a=this.items().first("hasClass","rui-selectable-selected")||this.items().first();this.display.html("<li>"+(a?a.html():" ")+"</li>")},harvestOptions:function(a){var b={};b.multiple=a.has("multiple");b.options=e([]);b.selected=e([]);b.disabled=e([]);o(a._.getElementsByTagName("OPTION")).each(function(d,c){b.options.push([d.innerHTML,
|
21
|
+
g(d).get("value")||d.innerHTML]);d.selected&&b.selected.push(c);d.disabled&&b.disabled.push(c)});if(b.selected.empty())b.selected=0;return b}});g(h).onReady(function(){k.rescan()});h.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} *.rui-selectable, *.rui-selectable li, *.rui-selectable dt, *.rui-selectable dd, *.rui-selectable ul,div.rui-selectable-container ul.rui-selectable-display,div.rui-selectable-container ul.rui-selectable-display li{margin:0;padding:0;border:none;background:none;list-style:none} *.rui-selectable{border:1px solid #CCC;border-bottom:none;display:inline-block; *display:inline; *zoom:1;min-width:10em;-moz-border-radius:.2em;-webkit-border-radius:.2em;user-select:none;-moz-user-select:none;-webkit-user-select:none} *.rui-selectable li{padding:.3em 1em;cursor:pointer;border-bottom:1px solid #CCC} *.rui-selectable li:hover{background:#EEE} *.rui-selectable li.rui-selectable-selected{font-weight:bold;background:#DDD} *.rui-selectable li.rui-selectable-disabled, *.rui-selectable li.rui-selectable-disabled:hover{background:#CCC;color:#777;cursor:default}dl.rui-selectable dt{padding:.3em .5em;cursor:default;font-weight:bold;font-style:italic;color:#444;background:#EEE;border-bottom:1px solid #CCC}dl.rui-selectable dd li{padding-left:1.5em} *.rui-selectable-single{background:#FFF;display:none}div.rui-selectable-container{border:1px solid #CCC;-moz-border-radius:.2em;-webkit-border-radius:.2em;display:inline-block; *display:inline; *zoom:1; *width:10em;vertical-align:middle;min-width:10em;cursor:pointer;height:1.6em;position:relative}div.rui-selectable-container div.rui-selectable-handle{font-family:Arial;float:right;width:0.8em;background:#DDD;text-align:center;height:100%;line-height:0.8em;font-size:200%;color:#888;border-left:1px solid #CCC}div.rui-selectable-container:hover div.rui-selectable-handle{color:#666}div.rui-selectable-container ul.rui-selectable-display{display:block;width:auto;margin-right:2em;overflow:hidden}div.rui-selectable-container ul.rui-selectable-display li{line-height:1.6em;padding:0 .5em}select.rui-selectable{visibility:hidden}</style>');
|
22
|
+
return k}(document,RightJS);
|
@@ -0,0 +1,377 @@
|
|
1
|
+
/**
|
2
|
+
* RightJS UI Slider unit
|
3
|
+
* http://rightjs.org/ui/slider
|
4
|
+
*
|
5
|
+
* Copyright (C) 2009-2010 Nikolay Nemshilov
|
6
|
+
*/
|
7
|
+
var Slider = RightJS.Slider = (function(document, Math, 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
|
+
$A = RightJS.$A,
|
27
|
+
isHash = RightJS.isHash,
|
28
|
+
Element = RightJS.Element;
|
29
|
+
|
30
|
+
|
31
|
+
|
32
|
+
|
33
|
+
|
34
|
+
|
35
|
+
/**
|
36
|
+
* The widget units constructor
|
37
|
+
*
|
38
|
+
* @param String tag-name or Object methods
|
39
|
+
* @param Object methods
|
40
|
+
* @return Widget wrapper
|
41
|
+
*/
|
42
|
+
function Widget(tag_name, methods) {
|
43
|
+
if (!methods) {
|
44
|
+
methods = tag_name;
|
45
|
+
tag_name = 'DIV';
|
46
|
+
}
|
47
|
+
|
48
|
+
/**
|
49
|
+
* An Abstract Widget Unit
|
50
|
+
*
|
51
|
+
* Copyright (C) 2010 Nikolay Nemshilov
|
52
|
+
*/
|
53
|
+
var AbstractWidget = new RightJS.Wrapper(RightJS.Element.Wrappers[tag_name] || RightJS.Element, {
|
54
|
+
/**
|
55
|
+
* The common constructor
|
56
|
+
*
|
57
|
+
* @param Object options
|
58
|
+
* @param String optional tag name
|
59
|
+
* @return void
|
60
|
+
*/
|
61
|
+
initialize: function(key, options) {
|
62
|
+
this.key = key;
|
63
|
+
var args = [{'class': 'rui-' + key}];
|
64
|
+
|
65
|
+
// those two have different constructors
|
66
|
+
if (!(this instanceof RightJS.Input || this instanceof RightJS.Form)) {
|
67
|
+
args.unshift(tag_name);
|
68
|
+
}
|
69
|
+
this.$super.apply(this, args);
|
70
|
+
|
71
|
+
if (RightJS.isString(options)) {
|
72
|
+
options = RightJS.$(options);
|
73
|
+
}
|
74
|
+
|
75
|
+
// if the options is another element then
|
76
|
+
// try to dynamically rewrap it with our widget
|
77
|
+
if (options instanceof RightJS.Element) {
|
78
|
+
this._ = options._;
|
79
|
+
if ('$listeners' in options) {
|
80
|
+
options.$listeners = options.$listeners;
|
81
|
+
}
|
82
|
+
options = {};
|
83
|
+
}
|
84
|
+
this.setOptions(options, this);
|
85
|
+
return this;
|
86
|
+
},
|
87
|
+
|
88
|
+
// protected
|
89
|
+
|
90
|
+
/**
|
91
|
+
* Catches the options
|
92
|
+
*
|
93
|
+
* @param Object user-options
|
94
|
+
* @param Element element with contextual options
|
95
|
+
* @return void
|
96
|
+
*/
|
97
|
+
setOptions: function(options, element) {
|
98
|
+
element = element || this;
|
99
|
+
RightJS.Options.setOptions.call(this,
|
100
|
+
RightJS.Object.merge(options, eval("("+(
|
101
|
+
element.get('data-'+ this.key) || '{}'
|
102
|
+
)+")"))
|
103
|
+
);
|
104
|
+
return this;
|
105
|
+
}
|
106
|
+
});
|
107
|
+
|
108
|
+
/**
|
109
|
+
* Creating the actual widget class
|
110
|
+
*
|
111
|
+
*/
|
112
|
+
var Klass = new RightJS.Wrapper(AbstractWidget, methods);
|
113
|
+
|
114
|
+
// creating the widget related shortcuts
|
115
|
+
RightJS.Observer.createShortcuts(Klass.prototype, Klass.EVENTS || []);
|
116
|
+
|
117
|
+
return Klass;
|
118
|
+
}
|
119
|
+
|
120
|
+
|
121
|
+
/**
|
122
|
+
* Same as the assignable, only it doesn't work with popups
|
123
|
+
* instead it simply updates the assigned unit value/content
|
124
|
+
*
|
125
|
+
* Copyright (C) 2010 Nikolay Nemshilov
|
126
|
+
*/
|
127
|
+
var Updater = {
|
128
|
+
|
129
|
+
/**
|
130
|
+
* Assigns the unit to work with an input element
|
131
|
+
*
|
132
|
+
* @param mixed element reference
|
133
|
+
* @return Rater this
|
134
|
+
*/
|
135
|
+
assignTo: function(element) {
|
136
|
+
var assign = R(function(element, event) {
|
137
|
+
if ((element = $(element))) {
|
138
|
+
element[element.setValue ? 'setValue' : 'update'](event.target.getValue());
|
139
|
+
}
|
140
|
+
}).curry(element);
|
141
|
+
|
142
|
+
var connect = R(function(element, object) {
|
143
|
+
element = $(element);
|
144
|
+
if (element && element.onChange) {
|
145
|
+
element.onChange(R(function() {
|
146
|
+
this.setValue(element.value());
|
147
|
+
}).bind(object));
|
148
|
+
}
|
149
|
+
}).curry(element);
|
150
|
+
|
151
|
+
if ($(element)) {
|
152
|
+
assign({target: this});
|
153
|
+
connect(this);
|
154
|
+
} else {
|
155
|
+
$(document).onReady(R(function() {
|
156
|
+
assign({target: this});
|
157
|
+
connect(this);
|
158
|
+
}.bind(this)));
|
159
|
+
}
|
160
|
+
|
161
|
+
return this.onChange(assign);
|
162
|
+
}
|
163
|
+
};
|
164
|
+
|
165
|
+
|
166
|
+
/**
|
167
|
+
* RightJS UI Slider unit
|
168
|
+
*
|
169
|
+
* Copyright (C) 2009-2010 Nikolay Nemshilov
|
170
|
+
*/
|
171
|
+
var Slider = new Widget({
|
172
|
+
include: Updater,
|
173
|
+
|
174
|
+
extend: {
|
175
|
+
version: '2.0.0',
|
176
|
+
|
177
|
+
EVENTS: $w('change'),
|
178
|
+
|
179
|
+
Options: {
|
180
|
+
min: 0, // the min value
|
181
|
+
max: 100, // the max value
|
182
|
+
snap: 0, // the values threshold
|
183
|
+
value: null, // start value, if null then the min value will be used
|
184
|
+
direction: 'x', // slider direction 'x', 'y'
|
185
|
+
update: null, // reference to an element to update
|
186
|
+
round: 0 // the number of symbols after the decimal pointer
|
187
|
+
},
|
188
|
+
|
189
|
+
current: false
|
190
|
+
},
|
191
|
+
|
192
|
+
/**
|
193
|
+
* basic constructor
|
194
|
+
* USAGE:
|
195
|
+
* new Slider('element-id'[, {options}]);
|
196
|
+
* new Slider({options});
|
197
|
+
*
|
198
|
+
* @param mixed slider element reference or options
|
199
|
+
* @param Object options
|
200
|
+
*/
|
201
|
+
initialize: function() {
|
202
|
+
var args = $A(arguments).compact(), options = args.pop(), element = args.pop();
|
203
|
+
|
204
|
+
// figuring out the arguments
|
205
|
+
if (!isHash(options) || options instanceof Element) {
|
206
|
+
element = $(element || options);
|
207
|
+
options = {};
|
208
|
+
}
|
209
|
+
|
210
|
+
this.$super('slider', element).setOptions(options)
|
211
|
+
.on('selectstart', 'stopEvent'); // disable select under IE
|
212
|
+
|
213
|
+
this.level = this.first('.level') || $E('div', {'class': 'level'}).insertTo(this);
|
214
|
+
this.handle = this.first('.handle') || $E('div', {'class': 'handle'}).insertTo(this);
|
215
|
+
|
216
|
+
options = this.options;
|
217
|
+
this.value = options.value === null ? options.min : options.value;
|
218
|
+
|
219
|
+
if (options.update) { this.assignTo(options.update); }
|
220
|
+
if (options.direction === 'y') { this.addClass('rui-slider-vertical'); }
|
221
|
+
else if (this.hasClass('rui-slider-vertical')) { options.direction = 'y'; }
|
222
|
+
|
223
|
+
this.setValue(this.value);
|
224
|
+
},
|
225
|
+
|
226
|
+
/**
|
227
|
+
* The value setter
|
228
|
+
*
|
229
|
+
* NOTE: will get snapped according to the options
|
230
|
+
*
|
231
|
+
* @param mixed string or number value
|
232
|
+
* @return Slider this
|
233
|
+
*/
|
234
|
+
setValue: function(value) {
|
235
|
+
return this.precalc().shiftTo(value);
|
236
|
+
},
|
237
|
+
|
238
|
+
/**
|
239
|
+
* Returns the value
|
240
|
+
*
|
241
|
+
* @return Float number
|
242
|
+
*/
|
243
|
+
getValue: function() {
|
244
|
+
return this.value;
|
245
|
+
},
|
246
|
+
|
247
|
+
/**
|
248
|
+
* Inserts the widget into the element
|
249
|
+
*
|
250
|
+
* @param mixed element reference
|
251
|
+
* @param String optional position
|
252
|
+
* @return Slider this
|
253
|
+
*/
|
254
|
+
insertTo: function(element, position) {
|
255
|
+
return this.$super(element, position).setValue(this.value);
|
256
|
+
},
|
257
|
+
|
258
|
+
// protected
|
259
|
+
|
260
|
+
// precalculates dimensions, direction and offset for further use
|
261
|
+
precalc: function() {
|
262
|
+
var horizontal = this.options.direction === 'x',
|
263
|
+
handle = this.handle.setStyle(horizontal ? {left: 0} : {bottom: 0}).dimensions(),
|
264
|
+
handle_size = this.hSize = horizontal ? handle.width : handle.height,
|
265
|
+
dims = this.dims = this.dimensions();
|
266
|
+
|
267
|
+
this.offset = horizontal ? handle.left - dims.left : dims.top + dims.height - handle.top - handle_size;
|
268
|
+
this.space = (horizontal ? dims.width - handle_size - this.offset * 2 : dims.height - handle_size) - this.offset * 2;
|
269
|
+
|
270
|
+
return this;
|
271
|
+
},
|
272
|
+
|
273
|
+
// initializes the slider drag
|
274
|
+
start: function(event) {
|
275
|
+
return this.precalc().e2val(event);
|
276
|
+
},
|
277
|
+
|
278
|
+
// processes the slider-drag
|
279
|
+
move: function(event) {
|
280
|
+
return this.e2val(event);
|
281
|
+
},
|
282
|
+
|
283
|
+
// shifts the slider to the value
|
284
|
+
shiftTo: function(value) {
|
285
|
+
var options = this.options, base = Math.pow(10, options.round), horizontal = options.direction === 'x';
|
286
|
+
|
287
|
+
// rounding the value up
|
288
|
+
value = Math.round(value * base) / base;
|
289
|
+
|
290
|
+
// checking the value constraings
|
291
|
+
if (value < options.min) { value = options.min; }
|
292
|
+
if (value > options.max) { value = options.max; }
|
293
|
+
if (options.snap) {
|
294
|
+
var snap = options.snap;
|
295
|
+
var diff = value % snap;
|
296
|
+
value = diff < snap/2 ? value - diff : value - diff + snap;
|
297
|
+
}
|
298
|
+
|
299
|
+
// calculating and setting the actual position
|
300
|
+
var position = this.space / (options.max - options.min) * (value - options.min);
|
301
|
+
|
302
|
+
this.handle._.style[horizontal ? 'left' : 'bottom'] = position + 'px';
|
303
|
+
this.level._.style[horizontal ? 'width': 'height'] = ((position > 0 ? position : 0) + 2) + 'px';
|
304
|
+
|
305
|
+
// checking the change status
|
306
|
+
if (value !== this.value) {
|
307
|
+
this.value = value;
|
308
|
+
this.fire('change');
|
309
|
+
}
|
310
|
+
|
311
|
+
return this;
|
312
|
+
},
|
313
|
+
|
314
|
+
// converts the event position into the actual value in terms of the slider measures
|
315
|
+
e2val: function(event) {
|
316
|
+
var options = this.options, horizontal = options.direction === 'x',
|
317
|
+
dims = this.dims, offset = this.offset, space = this.space,
|
318
|
+
cur_pos = event.position()[horizontal ? 'x' : 'y'] - offset - this.hSize/2,
|
319
|
+
min_pos = horizontal ? dims.left + offset : dims.top + offset,
|
320
|
+
value = (options.max - options.min) / space * (cur_pos - min_pos);
|
321
|
+
|
322
|
+
return this.shiftTo(horizontal ? options.min + value : options.max - value);
|
323
|
+
}
|
324
|
+
});
|
325
|
+
|
326
|
+
/**
|
327
|
+
* Document onReady hook for sliders
|
328
|
+
*
|
329
|
+
* Copyright (C) 2009-2010 Nikolay Nemshilov
|
330
|
+
*/
|
331
|
+
$(document).on({
|
332
|
+
// preinitializing the sliders
|
333
|
+
ready: function() {
|
334
|
+
$$('.rui-slider').each(function(element) {
|
335
|
+
if (!(element instanceof Slider)) {
|
336
|
+
element = new Slider(element);
|
337
|
+
}
|
338
|
+
});
|
339
|
+
},
|
340
|
+
|
341
|
+
// initiates the slider move
|
342
|
+
mousedown: function(event) {
|
343
|
+
var slider = event.find('.rui-slider');
|
344
|
+
if (slider) {
|
345
|
+
event.stop();
|
346
|
+
if (!(slider instanceof Slider)) {
|
347
|
+
slider = new Slider(slider);
|
348
|
+
}
|
349
|
+
Slider.current = slider.start(event);
|
350
|
+
}
|
351
|
+
},
|
352
|
+
|
353
|
+
// handles the slider move
|
354
|
+
mousemove: function(event) {
|
355
|
+
if (Slider.current) {
|
356
|
+
Slider.current.move(event);
|
357
|
+
}
|
358
|
+
},
|
359
|
+
|
360
|
+
// handles the slider release
|
361
|
+
mouseup: function(event) {
|
362
|
+
if (Slider.current) {
|
363
|
+
Slider.current = false;
|
364
|
+
}
|
365
|
+
}
|
366
|
+
});
|
367
|
+
|
368
|
+
$(window).onBlur(function() {
|
369
|
+
if (Slider.current) {
|
370
|
+
Slider.current = false;
|
371
|
+
}
|
372
|
+
});
|
373
|
+
|
374
|
+
document.write("<style type=\"text/css\">div.rui-slider,div.rui-slider .handle div.rui-slider .level{margin:0;padding:0;border:none;background:none}div.rui-slider{height:0.4em;width:20em;border:1px solid #bbb;background:#F8F8F8;border-radius:.2em;-moz-border-radius:.2em;-webkit-border-radius:.2em;position:relative;margin:.6em 0;display:inline-block; *display:inline; *zoom:1;vertical-align:middle;user-select:none;-moz-user-select:none;-webkit-user-select:none;cursor:pointer}div.rui-slider .handle{font-size:25%;position:absolute;left:0;top:0;width:4pt;height:4em;margin-top:-1.6em;margin-left:0.4em;background:#BBB;border:1px solid #999;border-radius:.8em;-moz-border-radius:.8em;-webkit-border-radius:.8em;z-index:20}div.rui-slider .level{font-size:25%;position:absolute;top:0;left:0;width:0;height:100%;background:#ddd;z-index:1}div.rui-slider-vertical{height:10em;width:0.4em;margin:0 .3em}div.rui-slider-vertical .handle{top:auto;bottom:0;margin:0;margin-left:-1.6em;margin-bottom:0.4em;height:4pt;width:4em}div.rui-slider-vertical .level{height:0;width:100%;top:auto;bottom:0}</style>");
|
375
|
+
|
376
|
+
return Slider;
|
377
|
+
})(document, Math, RightJS);
|
@@ -0,0 +1,14 @@
|
|
1
|
+
/**
|
2
|
+
* RightJS UI Slider unit
|
3
|
+
* http://rightjs.org/ui/slider
|
4
|
+
*
|
5
|
+
* Copyright (C) 2009-2010 Nikolay Nemshilov
|
6
|
+
*/
|
7
|
+
var Slider=RightJS.Slider=function(j,k,e){var h=e.$,m=e.$$,n=e.$w,l=e.$E,o=e.$A,p=e.isHash,q=e.Element,g=new (function(b,a){if(!a){a=b;b="DIV"}var f=new e.Wrapper(e.Element.Wrappers[b]||e.Element,{initialize:function(c,d){this.key=c;var i=[{"class":"rui-"+c}];this instanceof e.Input||this instanceof e.Form||i.unshift(b);this.$super.apply(this,i);if(e.isString(d))d=e.$(d);if(d instanceof e.Element){this._=d._;if("$listeners"in d)d.$listeners=d.$listeners;d={}}this.setOptions(d,this);return this},setOptions:function(c,
|
8
|
+
d){d=d||this;e.Options.setOptions.call(this,e.Object.merge(c,eval("("+(d.get("data-"+this.key)||"{}")+")")));return this}});f=new e.Wrapper(f,a);e.Observer.createShortcuts(f.prototype,f.EVENTS||[]);return f})({include:{assignTo:function(b){var a=e(function(c,d){if(c=h(c))c[c.setValue?"setValue":"update"](d.target.getValue())}).curry(b),f=e(function(c,d){(c=h(c))&&c.onChange&&c.onChange(e(function(){this.setValue(c.value())}).bind(d))}).curry(b);if(h(b)){a({target:this});f(this)}else h(j).onReady(e(function(){a({target:this});
|
9
|
+
f(this)}.bind(this)));return this.onChange(a)}},extend:{version:"2.0.0",EVENTS:n("change"),Options:{min:0,max:100,snap:0,value:null,direction:"x",update:null,round:0},current:false},initialize:function(){var b=o(arguments).compact(),a=b.pop();b=b.pop();if(!p(a)||a instanceof q){b=h(b||a);a={}}this.$super("slider",b).setOptions(a).on("selectstart","stopEvent");this.level=this.first(".level")||l("div",{"class":"level"}).insertTo(this);this.handle=this.first(".handle")||l("div",{"class":"handle"}).insertTo(this);
|
10
|
+
a=this.options;this.value=a.value===null?a.min:a.value;a.update&&this.assignTo(a.update);if(a.direction==="y")this.addClass("rui-slider-vertical");else if(this.hasClass("rui-slider-vertical"))a.direction="y";this.setValue(this.value)},setValue:function(b){return this.precalc().shiftTo(b)},getValue:function(){return this.value},insertTo:function(b,a){return this.$super(b,a).setValue(this.value)},precalc:function(){var b=this.options.direction==="x",a=this.handle.setStyle(b?{left:0}:{bottom:0}).dimensions(),
|
11
|
+
f=this.hSize=b?a.width:a.height,c=this.dims=this.dimensions();this.offset=b?a.left-c.left:c.top+c.height-a.top-f;this.space=(b?c.width-f-this.offset*2:c.height-f)-this.offset*2;return this},start:function(b){return this.precalc().e2val(b)},move:function(b){return this.e2val(b)},shiftTo:function(b){var a=this.options,f=k.pow(10,a.round),c=a.direction==="x";b=k.round(b*f)/f;if(b<a.min)b=a.min;if(b>a.max)b=a.max;if(a.snap){f=a.snap;var d=b%f;b=d<f/2?b-d:b-d+f}a=this.space/(a.max-a.min)*(b-a.min);this.handle._.style[c?
|
12
|
+
"left":"bottom"]=a+"px";this.level._.style[c?"width":"height"]=(a>0?a:0)+2+"px";if(b!==this.value){this.value=b;this.fire("change")}return this},e2val:function(b){var a=this.options,f=a.direction==="x",c=this.dims,d=this.offset,i=this.space;b=b.position()[f?"x":"y"]-d-this.hSize/2;c=(a.max-a.min)/i*(b-(f?c.left+d:c.top+d));return this.shiftTo(f?a.min+c:a.max-c)}});h(j).on({ready:function(){m(".rui-slider").each(function(b){b instanceof g||new g(b)})},mousedown:function(b){var a=b.find(".rui-slider");
|
13
|
+
if(a){b.stop();a instanceof g||(a=new g(a));g.current=a.start(b)}},mousemove:function(b){g.current&&g.current.move(b)},mouseup:function(){if(g.current)g.current=false}});h(window).onBlur(function(){if(g.current)g.current=false});j.write('<style type="text/css">div.rui-slider,div.rui-slider .handle div.rui-slider .level{margin:0;padding:0;border:none;background:none}div.rui-slider{height:0.4em;width:20em;border:1px solid #bbb;background:#F8F8F8;border-radius:.2em;-moz-border-radius:.2em;-webkit-border-radius:.2em;position:relative;margin:.6em 0;display:inline-block; *display:inline; *zoom:1;vertical-align:middle;user-select:none;-moz-user-select:none;-webkit-user-select:none;cursor:pointer}div.rui-slider .handle{font-size:25%;position:absolute;left:0;top:0;width:4pt;height:4em;margin-top:-1.6em;margin-left:0.4em;background:#BBB;border:1px solid #999;border-radius:.8em;-moz-border-radius:.8em;-webkit-border-radius:.8em;z-index:20}div.rui-slider .level{font-size:25%;position:absolute;top:0;left:0;width:0;height:100%;background:#ddd;z-index:1}div.rui-slider-vertical{height:10em;width:0.4em;margin:0 .3em}div.rui-slider-vertical .handle{top:auto;bottom:0;margin:0;margin-left:-1.6em;margin-bottom:0.4em;height:4pt;width:4em}div.rui-slider-vertical .level{height:0;width:100%;top:auto;bottom:0}</style>');
|
14
|
+
return g}(document,Math,RightJS);
|