right-rails 1.2.2 → 1.3.0
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +7 -0
- data/README.rdoc +1 -1
- data/Rakefile +1 -1
- data/init.rb +1 -0
- data/lib/generators/right_rails/right_rails_generator.rb +15 -6
- data/lib/right_rails.rb +1 -1
- data/lib/right_rails/controller_extensions.rb +28 -15
- data/lib/right_rails/helpers/misc.rb +38 -38
- data/lib/right_rails/helpers/rails.rb +50 -7
- data/lib/rjs_renderer.rb +26 -0
- data/spec/lib/right_rails/controller_extensions_spec.rb +25 -14
- data/spec/lib/right_rails/helpers/forms_spec.rb +6 -6
- data/spec/lib/right_rails/helpers/rails_spec.rb +44 -45
- data/vendor/assets/images/rightjs-ui/rte.png +0 -0
- data/vendor/assets/javascripts/right-safe-src.js +2 -2
- data/vendor/assets/javascripts/right-safe.js +2 -2
- data/vendor/assets/javascripts/right-src.js +386 -100
- data/vendor/assets/javascripts/right.js +2 -2
- data/vendor/assets/javascripts/right/calendar-src.js +19 -3
- data/vendor/assets/javascripts/right/calendar.js +2 -2
- data/vendor/assets/javascripts/right/colorpicker-src.js +59 -20
- data/vendor/assets/javascripts/right/colorpicker.js +2 -2
- data/vendor/assets/javascripts/right/i18n/de.js +43 -42
- data/vendor/assets/javascripts/right/i18n/es.js +1 -0
- data/vendor/assets/javascripts/right/i18n/fi.js +1 -0
- data/vendor/assets/javascripts/right/i18n/fr.js +1 -0
- data/vendor/assets/javascripts/right/i18n/hu.js +1 -0
- data/vendor/assets/javascripts/right/i18n/it.js +1 -0
- data/vendor/assets/javascripts/right/i18n/jp.js +1 -0
- data/vendor/assets/javascripts/right/i18n/lt.js +96 -0
- data/vendor/assets/javascripts/right/i18n/nl.js +1 -0
- data/vendor/assets/javascripts/right/i18n/pt-br.js +1 -0
- data/vendor/assets/javascripts/right/i18n/ru.js +1 -0
- data/vendor/assets/javascripts/right/i18n/ua.js +1 -0
- data/vendor/assets/javascripts/right/jquerysh-src.js +4 -4
- data/vendor/assets/javascripts/right/jquerysh.js +2 -2
- data/vendor/assets/javascripts/right/rails-src.js +51 -15
- data/vendor/assets/javascripts/right/rails.js +2 -2
- data/vendor/assets/javascripts/right/resizable-src.js +11 -11
- data/vendor/assets/javascripts/right/rte-src.js +33 -13
- data/vendor/assets/javascripts/right/rte.js +2 -2
- data/vendor/assets/javascripts/right/slider-src.js +137 -28
- data/vendor/assets/javascripts/right/slider.js +2 -2
- metadata +24 -126
- data/generators/right_rails/right_rails_generator.rb +0 -46
- data/generators/right_rails/templates/iframed.html.erb +0 -10
- data/generators/right_scaffold/right_scaffold_generator.rb +0 -53
- data/generators/right_scaffold/templates/controller.rb +0 -99
- data/generators/right_scaffold/templates/helper.rb +0 -2
- data/generators/right_scaffold/templates/layout.html.erb +0 -18
- data/generators/right_scaffold/templates/style.css +0 -54
- data/generators/right_scaffold/templates/view__form.html.erb +0 -16
- data/generators/right_scaffold/templates/view__item.html.erb +0 -13
- data/generators/right_scaffold/templates/view_edit.html.erb +0 -6
- data/generators/right_scaffold/templates/view_index.html.erb +0 -9
- data/generators/right_scaffold/templates/view_new.html.erb +0 -5
- data/generators/right_scaffold/templates/view_show.html.erb +0 -10
- data/lib/generators/right_rails/templates/iframed.html.erb +0 -10
- data/public/images/rightjs-ui/colorpicker.png +0 -0
- data/public/images/rightjs-ui/resizable.png +0 -0
- data/public/images/rightjs-ui/rte.png +0 -0
- data/public/javascripts/right-olds-src.js +0 -652
- data/public/javascripts/right-olds.js +0 -9
- data/public/javascripts/right-safe-src.js +0 -68
- data/public/javascripts/right-safe.js +0 -7
- data/public/javascripts/right-src.js +0 -6014
- data/public/javascripts/right.js +0 -7
- data/public/javascripts/right/autocompleter-src.js +0 -625
- data/public/javascripts/right/autocompleter.js +0 -7
- data/public/javascripts/right/billboard-src.js +0 -564
- data/public/javascripts/right/billboard.js +0 -7
- data/public/javascripts/right/calendar-src.js +0 -1464
- data/public/javascripts/right/calendar.js +0 -7
- data/public/javascripts/right/casting-src.js +0 -183
- data/public/javascripts/right/casting.js +0 -7
- data/public/javascripts/right/colorpicker-src.js +0 -981
- data/public/javascripts/right/colorpicker.js +0 -7
- data/public/javascripts/right/dialog-src.js +0 -768
- data/public/javascripts/right/dialog.js +0 -7
- data/public/javascripts/right/dnd-src.js +0 -591
- data/public/javascripts/right/dnd.js +0 -7
- data/public/javascripts/right/effects-src.js +0 -508
- data/public/javascripts/right/effects.js +0 -7
- data/public/javascripts/right/i18n/de.js +0 -95
- data/public/javascripts/right/i18n/en-us.js +0 -11
- data/public/javascripts/right/i18n/es.js +0 -95
- data/public/javascripts/right/i18n/fi.js +0 -96
- data/public/javascripts/right/i18n/fr.js +0 -95
- data/public/javascripts/right/i18n/hu.js +0 -100
- data/public/javascripts/right/i18n/it.js +0 -95
- data/public/javascripts/right/i18n/jp.js +0 -99
- data/public/javascripts/right/i18n/nl.js +0 -95
- data/public/javascripts/right/i18n/pt-br.js +0 -95
- data/public/javascripts/right/i18n/ru.js +0 -95
- data/public/javascripts/right/i18n/ua.js +0 -99
- data/public/javascripts/right/in-edit-src.js +0 -373
- data/public/javascripts/right/in-edit.js +0 -7
- data/public/javascripts/right/jquerysh-src.js +0 -362
- data/public/javascripts/right/jquerysh.js +0 -7
- data/public/javascripts/right/json-src.js +0 -147
- data/public/javascripts/right/json.js +0 -7
- data/public/javascripts/right/keys-src.js +0 -87
- data/public/javascripts/right/keys.js +0 -7
- data/public/javascripts/right/lightbox-src.js +0 -931
- data/public/javascripts/right/lightbox.js +0 -7
- data/public/javascripts/right/rails-src.js +0 -402
- data/public/javascripts/right/rails.js +0 -7
- data/public/javascripts/right/rater-src.js +0 -384
- data/public/javascripts/right/rater.js +0 -7
- data/public/javascripts/right/resizable-src.js +0 -465
- data/public/javascripts/right/resizable.js +0 -7
- data/public/javascripts/right/rte-src.js +0 -2685
- data/public/javascripts/right/rte.js +0 -7
- data/public/javascripts/right/selectable-src.js +0 -725
- data/public/javascripts/right/selectable.js +0 -7
- data/public/javascripts/right/sizzle-src.js +0 -1132
- data/public/javascripts/right/sizzle.js +0 -7
- data/public/javascripts/right/slider-src.js +0 -395
- data/public/javascripts/right/slider.js +0 -7
- data/public/javascripts/right/sortable-src.js +0 -430
- data/public/javascripts/right/sortable.js +0 -7
- data/public/javascripts/right/table-src.js +0 -176
- data/public/javascripts/right/table.js +0 -7
- data/public/javascripts/right/tabs-src.js +0 -1157
- data/public/javascripts/right/tabs.js +0 -7
- data/public/javascripts/right/tags-src.js +0 -745
- data/public/javascripts/right/tags.js +0 -7
- data/public/javascripts/right/tooltips-src.js +0 -331
- data/public/javascripts/right/tooltips.js +0 -7
- data/public/javascripts/right/uploader-src.js +0 -302
- data/public/javascripts/right/uploader.js +0 -7
@@ -1,7 +0,0 @@
|
|
1
|
-
/**
|
2
|
-
* RightJS-UI Lightbox v2.2.3
|
3
|
-
* http://rightjs.org/ui/lightbox
|
4
|
-
*
|
5
|
-
* Copyright (C) 2009-2011 Nikolay Nemshilov
|
6
|
-
*/
|
7
|
-
var Lightbox=RightJS.Lightbox=function(a,b){function c(a,c){c||(c=a,a="DIV");var d=new b.Class(b.Element.Wrappers[a]||b.Element,{initialize:function(c,d){this.key=c;var e=[{"class":"rui-"+c}];this instanceof b.Input||this instanceof b.Form||e.unshift(a),this.$super.apply(this,e),b.isString(d)&&(d=b.$(d)),d instanceof b.Element&&(this._=d._,"$listeners"in d&&(d.$listeners=d.$listeners),d={}),this.setOptions(d,this);return b.Wrapper.Cache[b.$uid(this._)]=this},setOptions:function(a,c){c&&(a=b.Object.merge(a,(new Function("return "+(c.get("data-"+this.key)||"{}")))())),a&&b.Options.setOptions.call(this,b.Object.merge(this.options,a));return this}}),e=new b.Class(d,c);b.Observer.createShortcuts(e.prototype,e.EVENTS||b([]));return e}var d=new b.Class(b.Element,{initialize:function(a){this.$super("div",{"class":"rui-spinner"}),this.dots=[];for(var c=0;c<(a||4);c++)this.dots.push(new b.Element("div"));this.dots[0].addClass("glowing"),this.insert(this.dots),b(this.shift).bind(this).periodical(300)},shift:function(){if(this.visible()){var a=this.dots.pop();this.dots.unshift(a),this.insert(a,"top")}}}),e=b,f=b.$,g=b.$$,h=b.$w,i=b.$E,j=b.$ext,k=b.Xhr,l=b.Class,m=b.Object,n=b.Element,o=b.Browser;o.IE6=o.OLD&&navigator.userAgent.indexOf("MSIE 6")>0;var p=new c({extend:{version:"2.2.3",EVENTS:h("show hide load"),Options:{fxName:"fade",fxDuration:300,group:null,hideOnEsc:!0,hideOnOutClick:!0,showCloseButton:!0,cssRule:"a[data-lightbox]",mediaWidth:425,mediaHeight:350},i18n:{Close:"Close",Prev:"Previous Image",Next:"Next Image"},Images:/\.(jpg|jpeg|gif|png|bmp)/i,Medias:[[/(http:\/\/.*?youtube\.[a-z]+)\/watch\?v=([^&]+)/i,"$1/v/$2","swf"],[/(http:\/\/video.google.com)\/videoplay\?docid=([^&]+)/i,"$1/googleplayer.swf?docId=$2","swf"],[/(http:\/\/vimeo\.[a-z]+)\/([0-9]+).*?/i,"$1/moogaloop.swf?clip_id=$2","swf"]]},initialize:function(a,b){this.$super("lightbox",{}).setOptions(a,b).insert([this.locker=new q(this.options),this.dialog=new r(this.options)]).on({close:this._close,next:this._next,prev:this._prev})},setOptions:function(a,b){this.$super(a,b);if(b){var c=b.get("rel");c&&(c=c.match(/lightbox\[(.+?)\]/))&&(this.options.group=c[1])}return this},setTitle:function(a){this.dialog.setTitle(a);return this},show:function(a){return this._showAnd(function(){this.dialog.show(a,!a)})},hide:function(){p.current=null;return this.$super(this.options.fxName,{duration:this.options.fxDuration/3,onFinish:e(function(){this.fire("hide"),this.remove()}).bind(this)})},load:function(a,b){return this._showAnd(function(){this.dialog.load(a,b)})},resize:function(a){this.dialog.resize(a);return this},_close:function(a){a.stop(),this.hide()},_prev:function(a){a.stop(),t.prev()},_next:function(a){a.stop(),t.next()},_showAnd:function(b){p.current!==this?(p.current=this,g("div.rui-lightbox").each("remove"),this.insertTo(a.body),this.dialog.show("",!0),o.OLD?(this.reposition(),n.prototype.show.call(this),b.call(this)):(this.setStyle("display:none"),n.prototype.show.call(this,this.options.fxName,{duration:this.options.fxDuration/2,onFinish:e(function(){b.call(this),this.fire("show")}).bind(this)}))):b.call(this);return this},reposition:function(){if(o.IE6){var a=f(window);this.setStyle({top:a.scrolls().y+"px",width:a.size().x+"px",height:a.size().y+"px",position:"absolute"})}}});p.extend({hide:function(){p.current&&p.current.hide()},show:function(){return this.inst("show",arguments)},load:function(){return this.inst("load",arguments)},inst:function(a,b){var c=new p;return c[a].apply(c,b)}});var q=new l(n,{initialize:function(a){this.$super("div",{"class":"rui-lightbox-locker"}),a.hideOnOutClick&&this.onClick("fire","close")}}),r=new l(n,{initialize:function(a){var b=p.i18n;this.options=a,this.$super("div",{"class":"rui-lightbox-dialog"}),this.insert([this.title=i("div",{"class":"rui-lightbox-title"}),i("div",{"class":"rui-lightbox-body"}).insert(i("div",{"class":"rui-lightbox-body-inner"}).insert([this.locker=i("div",{"class":"rui-lightbox-body-locker"}).insert(new d(4)),this.scroller=i("div",{"class":"rui-lightbox-scroller"}).insert(this.content=i("div",{"class":"rui-lightbox-content"}))])),i("div",{"class":"rui-lightbox-navigation"}).insert([this.closeButton=i("div",{"class":"close",html:"×",title:b.Close}).onClick("fire","close"),this.prevLink=i("div",{"class":"prev",html:"←",title:b.Prev}).onClick("fire","prev"),this.nextLink=i("div",{"class":"next",html:"→",title:b.Next}).onClick("fire","next")])]),this.prevLink.hide(),this.nextLink.hide(),a.showCloseButton||this.closeButton.hide()},setTitle:function(a){this.title.update(a||"")},resize:function(a,c){var d=this.parent().size(),f=this.scroller.size(),g=(d.y-this.size().y)/2,h=this.size().x-f.x;a?(a=this.scroller.setStyle(a).size(),this.scroller.setStyle({width:f.x+"px",height:f.y+"px"})):a=this.content.size();var i=100;/^<img [^>]+>/img.test(this.content.html())?(e([["x","y"],["y","x"]]).each(function(b){var c=b[0],e=b[1],f=a[c];a[c]+i>d[c]&&(a[c]=d[c]-i,a[e]=Math.floor(a[e]*a[c]/f))}),this.content.first("img").setStyle({width:a.x+"px",height:a.y+"px"})):(a.x+i>d.x&&(a.x=d.x-i),a.y+i>d.y&&(a.y=d.y-i));var k=(g*2+f.y-a.y)/2,l=this._.style,m=this.scroller._.style;b.Fx&&c&&(a.x!=f.x||a.y!=f.y)?j(new b.Fx(this,{duration:this.options.fxDuration}),{render:function(b){m.width=f.x+(a.x-f.x)*b+"px",m.height=f.y+(a.y-f.y)*b+"px",l.top=g+(k-g)*b+"px",o.IE6&&(l.width=h+f.y+(a.y-f.y)*b+"px")}}).onFinish(e(this.unlock).bind(this)).start():(m.width=a.x+"px",m.height=a.y+"px",l.top=k+"px",o.IE6&&(l.width=h+a.x+"px"),this.request||this.unlock());return this},show:function(a,b){this.content.update(a||""),this.resize(null,!b)},load:function(a,b){a instanceof n&&(this.setTitle(a.get("title")),a=a.get("href")),t.show(this,a),this.lock().cancel(),this.request=new s(a,b,e(function(a,b){this.request=null,this.show(a,b)}).bind(this));return this.resize()},cancel:function(){this.request&&this.request.cancel();return this},lock:function(){this.locker.setStyle("opacity:1;display:block").insertTo(this.scroller,"before");return this},unlock:function(){this.locker.remove(e(this.content.html()).blank()?null:"fade",{duration:this.options.fxDuration*2/3});return this}}),s=new l({initialize:function(a,b,c){this.isImage(a,c)?p.current.addClass("rui-lightbox-image"):this.isMedia(a,c)?p.current.addClass("rui-lightbox-media"):this.xhr=(new k(a,m.merge({method:"get"},b))).onComplete(function(){c(this.text)}).send()},cancel:function(){this.xhr?this.xhr.cancel():this.img&&(this.img.onload=function(){})},isImage:function(a,b){if(a.match(p.Images)){var c=this.img=i("img")._;c.onload=function(){b(c)},c.src=a;return!0}},isMedia:function(a,b){var c=e(p.Medias).map(function(b){return a.match(b[0])?this.buildEmbed(a.replace(b[0],b[1]),b[2]):null},this).compact()[0];if(c){b(c,!0);return!0}},buildEmbed:function(a,b){var c={swf:["D27CDB6E-AE6D-11cf-96B8-444553540000","http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0","application/x-shockwave-flash"]},d=p.current?p.current.options:p.Options,e=' width="'+d.mediaWidth+'" height="'+d.mediaHeight+'"';return'<object classid="clsid:'+c[b][0]+'" codebase="'+c[b][1]+'"'+e+'><param name="src" value="'+a+'" /><embed src="'+a+'" type="'+c[b][2]+'"'+e+" /></object>"}}),t={show:function(a,b){if(a.options.group){this.dialog=a,this.links=this.find(a.options.group),this.link=this.links.first(function(a){return a.get("href")===b});var c=this.links.indexOf(this.link),d=this.links.length;a.prevLink[d&&c>0?"show":"hide"](),a.nextLink[d&&c<d-1?"show":"hide"]()}else this.dialog=null},prev:function(){if(this.dialog&&!this.timer){var a=this.links.indexOf(this.link),b=this.links[a-1];b&&(this.dialog.load(b),this.timeout())}},next:function(){if(this.dialog&&!this.timer){var a=this.links.indexOf(this.link),b=this.links[a+1];b&&(this.dialog.load(b),this.timeout())}},find:function(a){return g("a").filter(function(b){var c=b.get("data-lightbox"),d=b.get("rel");return c&&(new Function("return "+c))().group===a||d&&d.indexOf("lightbox["+a+"]")>-1})},timeout:function(){this.timer=e(function(){t.timer=null}).delay(300)}};f(a).on({click:function(a){var b=a.find(p.Options.cssRule)||a.find("a[rel^=lightbox]"),c=a._;b&&!(c.shiftKey||c.altKey||c.ctrlKey||c.metaKey)&&(a.stop(),(new p({},b)).load(b))},mousewheel:function(a){if(p.current){var b=a.target,c=b.parent("div.rui-lightbox-content");(!c||b.getStyle("overflow")==="visible")&&a.stop(),p.current.fire((a._.detail||-a._.wheelDelta)<0?"prev":"next")}},keydown:function(a){var b=p.current,c=({27:"close",33:"prev",37:"prev",38:"prev",39:"next",40:"next",34:"next"})[a.keyCode];if(b&&c)if(c!=="close"||b.options.hideOnEsc)a.stop(),b.fire(c)}}),f(window).on({resize:function(){p.current&&(p.current.reposition(),p.current.dialog.resize())},scroll:function(a){p.current&&o.IE6&&p.current.reposition()}});var u=a.createElement("style"),v=a.createTextNode("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;float:none;width:100%;height:100%;margin:0;padding:0;background:none;border:none;text-align:center;z-index:9999;z-index/*\\**/:auto\\9}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;z-index/*\\**/:9990\\9}div.rui-lightbox-dialog{display:inline-block; *display:inline; *zoom:1;position:relative;text-align:left;z-index/*\\**/:9999\\9}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}div.rui-lightbox-body{background-color:#FFF;padding:1em;border-radius:.5em;-moz-border-radius:.5em;-webkit-border-radius:.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%;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:160%;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:#D8D8D8}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}");u.type="text/css",a.getElementsByTagName("head")[0].appendChild(u),u.styleSheet?u.styleSheet.cssText=v.nodeValue:u.appendChild(v);return p}(document,RightJS)
|
@@ -1,402 +0,0 @@
|
|
1
|
-
/**
|
2
|
-
* RubyOnRails Support Module v2.2.2
|
3
|
-
* http://rightjs.org/plugins/rails
|
4
|
-
*
|
5
|
-
* Copyright (C) 2009-2011 Nikolay Nemshilov
|
6
|
-
*/
|
7
|
-
(function(window, document, RightJS) {
|
8
|
-
/**
|
9
|
-
* The Rails plugin initialization script
|
10
|
-
*
|
11
|
-
* Copyright (C) 2010-2011 Nikolay Nemshilov
|
12
|
-
*/
|
13
|
-
|
14
|
-
var R = RightJS,
|
15
|
-
$ = RightJS.$,
|
16
|
-
$$ = RightJS.$$,
|
17
|
-
$E = RightJS.$E,
|
18
|
-
Xhr = RightJS.Xhr,
|
19
|
-
Object = RightJS.Object;
|
20
|
-
|
21
|
-
RightJS.Rails = {
|
22
|
-
version: '2.2.2'
|
23
|
-
};
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
/**
|
28
|
-
* Underscored aliases for Ruby On Rails
|
29
|
-
*
|
30
|
-
* Copyright (C) 2009-2011 Nikolay Nemshilov
|
31
|
-
*/
|
32
|
-
|
33
|
-
// the language and window level aliases
|
34
|
-
R([
|
35
|
-
RightJS.String.prototype,
|
36
|
-
RightJS.Array.prototype,
|
37
|
-
RightJS.Function.prototype,
|
38
|
-
RightJS.Object,
|
39
|
-
RightJS.Options,
|
40
|
-
RightJS.Observer,
|
41
|
-
RightJS.Observer.prototype,
|
42
|
-
RightJS.Window.prototype,
|
43
|
-
RightJS.Document.prototype
|
44
|
-
]).each(function(object) {
|
45
|
-
for (var key in object) {
|
46
|
-
try { // some keys are not accessable
|
47
|
-
|
48
|
-
if (/[A-Z]/.test(key) && typeof(object[key]) === 'function') {
|
49
|
-
var u_key = R(key).underscored();
|
50
|
-
if (object[u_key] === null || object[u_key] === undefined) {
|
51
|
-
object[u_key] = object[key];
|
52
|
-
}
|
53
|
-
}
|
54
|
-
} catch (e) {}
|
55
|
-
}
|
56
|
-
});
|
57
|
-
|
58
|
-
|
59
|
-
// DOM package aliases
|
60
|
-
R([
|
61
|
-
RightJS.Element,
|
62
|
-
RightJS.Event,
|
63
|
-
RightJS.Form,
|
64
|
-
RightJS.Input
|
65
|
-
]).each(function(object) {
|
66
|
-
if (!object) { return; }
|
67
|
-
|
68
|
-
var aliases = {}, methods = object.prototype;
|
69
|
-
|
70
|
-
for (var key in methods) {
|
71
|
-
if (/[A-Z]/.test(key) && typeof(methods[key]) === 'function') {
|
72
|
-
object.prototype[R(key).underscored()] = methods[key];
|
73
|
-
}
|
74
|
-
}
|
75
|
-
});
|
76
|
-
|
77
|
-
// various ruby-like method aliases
|
78
|
-
RightJS.$alias(RightJS.String.prototype, {
|
79
|
-
index_of: 'indexOf',
|
80
|
-
last_index_of: 'lastIndexOf',
|
81
|
-
to_f: 'toFloat',
|
82
|
-
to_i: 'toInt',
|
83
|
-
gsub: 'replace',
|
84
|
-
downcase: 'toLowerCase',
|
85
|
-
upcase: 'toUpperCase',
|
86
|
-
index: 'indexOf',
|
87
|
-
rindex: 'lastIndexOf',
|
88
|
-
strip: 'trim'
|
89
|
-
});
|
90
|
-
|
91
|
-
RightJS.$alias(RightJS.Array.prototype, {
|
92
|
-
collect: 'map',
|
93
|
-
detect: 'filter',
|
94
|
-
index_of: 'indexOf',
|
95
|
-
last_index_of: 'lastIndexOf',
|
96
|
-
index: 'indexOf',
|
97
|
-
rindex: 'lastIndexOf'
|
98
|
-
});
|
99
|
-
|
100
|
-
/**
|
101
|
-
* Rails 3 UJS support module
|
102
|
-
*
|
103
|
-
* Copyright (C) 2010-2011 Nikolay Nemshilov
|
104
|
-
*/
|
105
|
-
// tries to cancel the event via confirmation
|
106
|
-
function user_cancels(event, element) {
|
107
|
-
var message = element.get('data-confirm');
|
108
|
-
if (message && !confirm(message)) {
|
109
|
-
event.stop();
|
110
|
-
return true;
|
111
|
-
}
|
112
|
-
}
|
113
|
-
|
114
|
-
// adds XHR events to the element
|
115
|
-
function add_xhr_events(element, options) {
|
116
|
-
return Object.merge({
|
117
|
-
onCreate: function() { element.fire('ajax:loading', {xhr: this}); },
|
118
|
-
onComplete: function() { element.fire('ajax:complete', {xhr: this}); },
|
119
|
-
onSuccess: function() { element.fire('ajax:success', {xhr: this}); },
|
120
|
-
onFailure: function() { element.fire('ajax:failure', {xhr: this}); }
|
121
|
-
}, options);
|
122
|
-
}
|
123
|
-
|
124
|
-
// processes link clicks
|
125
|
-
function try_link_submit(event, link) {
|
126
|
-
var url = link.get('href'),
|
127
|
-
method = link.get('data-method'),
|
128
|
-
remote = link.get('data-remote');
|
129
|
-
|
130
|
-
if (user_cancels(event, link)) { return; }
|
131
|
-
if (method || remote) { event.stop(); }
|
132
|
-
|
133
|
-
if (remote) {
|
134
|
-
Xhr.load(url, add_xhr_events(link, {
|
135
|
-
method: method || 'get',
|
136
|
-
spinner: link.get('data-spinner')
|
137
|
-
}));
|
138
|
-
|
139
|
-
} else if (method) {
|
140
|
-
var param = $$('meta[name=csrf-param]')[0],
|
141
|
-
token = $$('meta[name=csrf-token]')[0],
|
142
|
-
form = $E('form', {action: url, method: 'post'});
|
143
|
-
|
144
|
-
param = param && param.get('content');
|
145
|
-
token = token && token.get('content');
|
146
|
-
|
147
|
-
if (param && token) {
|
148
|
-
form.insert('<input type="hidden" name="'+param+'" value="'+token+'" />');
|
149
|
-
}
|
150
|
-
|
151
|
-
form.insert('<input type="hidden" name="_method" value="'+method+'"/>')
|
152
|
-
.insertTo(document.body).submit();
|
153
|
-
}
|
154
|
-
}
|
155
|
-
|
156
|
-
// global events listeners
|
157
|
-
$(document).on({
|
158
|
-
click: function(event) {
|
159
|
-
var link = event.find('a');
|
160
|
-
if (link) {
|
161
|
-
try_link_submit(event, link);
|
162
|
-
}
|
163
|
-
},
|
164
|
-
|
165
|
-
submit: function(event) {
|
166
|
-
var form = event.target;
|
167
|
-
if (form.has('data-remote') && !user_cancels(event, form)) {
|
168
|
-
event.stop();
|
169
|
-
form.send(add_xhr_events(form, {
|
170
|
-
spinner: form.get('data-spinner') || form.first('.spinner')
|
171
|
-
}));
|
172
|
-
}
|
173
|
-
}
|
174
|
-
});
|
175
|
-
|
176
|
-
/**
|
177
|
-
* RR is the common ajax operations wrapper for ruby on rails
|
178
|
-
*
|
179
|
-
* Copyright (C) 2009-2010 Nikolay Nemshilov
|
180
|
-
*/
|
181
|
-
var RR = {
|
182
|
-
/**
|
183
|
-
* Basic options
|
184
|
-
*
|
185
|
-
* NOTE: DO NOT CHANGE this hash right here
|
186
|
-
* Use your application.js file to alter the options
|
187
|
-
*/
|
188
|
-
Options: {
|
189
|
-
format: 'js', // the working format for remote requests over the application
|
190
|
-
|
191
|
-
flashId: 'flashes', // the flashes element id
|
192
|
-
flashHideFx: 'slide', // use null if you don't want any fx in here
|
193
|
-
flashHideDelay: 3200, // use -1 to disable the flash element hidding
|
194
|
-
|
195
|
-
highlightUpdates: true,
|
196
|
-
|
197
|
-
removeFx: 'fade', // blocks removing fx
|
198
|
-
insertFx: 'fade', // blocks insertion fx
|
199
|
-
|
200
|
-
insertPosition: 'bottom', // default insert position
|
201
|
-
|
202
|
-
linkToAjaxEdit: '.ajax_edit',
|
203
|
-
linkToAjaxDelete: '.ajax_delete',
|
204
|
-
|
205
|
-
rescanWithScopes: true // if it should rescan only updated elements
|
206
|
-
},
|
207
|
-
|
208
|
-
/**
|
209
|
-
* Updates the flashes block with the source
|
210
|
-
*
|
211
|
-
* @param String new content
|
212
|
-
* @return RR this
|
213
|
-
*/
|
214
|
-
update_flash: function(content) {
|
215
|
-
var element = $(this.Options.flashId);
|
216
|
-
if (element) {
|
217
|
-
this.replace(element, content).hide_flash();
|
218
|
-
}
|
219
|
-
return this;
|
220
|
-
},
|
221
|
-
|
222
|
-
/**
|
223
|
-
* Initializes the delayed flashes hide call
|
224
|
-
*
|
225
|
-
* @return RR this
|
226
|
-
*/
|
227
|
-
hide_flash: function() {
|
228
|
-
if (this.Options.flashHideDelay > -1) {
|
229
|
-
var element = $(this.Options.flashId);
|
230
|
-
if (element && element.visible()) {
|
231
|
-
element.hide.bind(element, this.Options.flashHideFx).delay(this.Options.flashHideDelay);
|
232
|
-
}
|
233
|
-
}
|
234
|
-
return this;
|
235
|
-
},
|
236
|
-
|
237
|
-
/**
|
238
|
-
* Highlights the element according to the options
|
239
|
-
*
|
240
|
-
* @param String element id
|
241
|
-
* @return RR this
|
242
|
-
*/
|
243
|
-
highlight: function(id) {
|
244
|
-
if ($(id) && this.Options.highlightUpdates) {
|
245
|
-
$(id).highlight();
|
246
|
-
}
|
247
|
-
return this;
|
248
|
-
},
|
249
|
-
|
250
|
-
/**
|
251
|
-
* Inserts the content into the given element
|
252
|
-
*
|
253
|
-
* @param destination String destination id
|
254
|
-
* @param content String content
|
255
|
-
* @param position String position
|
256
|
-
* @return RR this
|
257
|
-
*/
|
258
|
-
insert: function(where, what, in_position) {
|
259
|
-
var position = in_position || this.Options.insertPosition, new_element,
|
260
|
-
container = $(where).insert(what, position);
|
261
|
-
|
262
|
-
// trying to find the new block
|
263
|
-
switch (position) {
|
264
|
-
case 'bottom': new_element = container.children().last(); break;
|
265
|
-
case 'top': new_element = container.first(); break;
|
266
|
-
case 'before': new_element = container.prev(); break;
|
267
|
-
case 'after': new_element = container.next(); break;
|
268
|
-
}
|
269
|
-
|
270
|
-
// necely displaying the new block
|
271
|
-
if (new_element && this.Options.insertFx) {
|
272
|
-
new_element.hide().show(this.Options.insertFx, {
|
273
|
-
onFinish: this.highlight.bind(this, new_element)
|
274
|
-
});
|
275
|
-
} else {
|
276
|
-
this.highlight(new_element);
|
277
|
-
}
|
278
|
-
|
279
|
-
return this.rescan(where);
|
280
|
-
},
|
281
|
-
|
282
|
-
/**
|
283
|
-
* Replaces the given element with a new content
|
284
|
-
*
|
285
|
-
* @param destination String destination id
|
286
|
-
* @param content String content
|
287
|
-
* @return RR this
|
288
|
-
*/
|
289
|
-
replace: function(id, source) {
|
290
|
-
$(id).replace(source);
|
291
|
-
return this.highlight(id).rescan(id);
|
292
|
-
},
|
293
|
-
|
294
|
-
/**
|
295
|
-
* removes the element by id
|
296
|
-
*
|
297
|
-
* @param String element id
|
298
|
-
* @return RR this
|
299
|
-
*/
|
300
|
-
remove: function(id) {
|
301
|
-
if ($(id)) {
|
302
|
-
$(id).remove(this.Options.removeFx);
|
303
|
-
}
|
304
|
-
},
|
305
|
-
|
306
|
-
/**
|
307
|
-
* Makes a remote form out of the form
|
308
|
-
*
|
309
|
-
* @param String form id
|
310
|
-
* @return RR this
|
311
|
-
*/
|
312
|
-
remotize_form: function(id) {
|
313
|
-
var form = $(id);
|
314
|
-
if (form) {
|
315
|
-
form.remotize().enable()._.action += '.'+this.Options.format;
|
316
|
-
}
|
317
|
-
return this;
|
318
|
-
},
|
319
|
-
|
320
|
-
/**
|
321
|
-
* Replaces the form with new content and makes it remote
|
322
|
-
*
|
323
|
-
* @param form id String form id
|
324
|
-
* @param content String content
|
325
|
-
* @return RR this
|
326
|
-
*/
|
327
|
-
replace_form: function(id, source) {
|
328
|
-
var form = $(id);
|
329
|
-
if (form) {
|
330
|
-
form.replace(source);
|
331
|
-
this.remotize_form(id);
|
332
|
-
}
|
333
|
-
|
334
|
-
return this.rescan(id);
|
335
|
-
},
|
336
|
-
|
337
|
-
/**
|
338
|
-
* Inserts the form source into the given element
|
339
|
-
*
|
340
|
-
* @param target id String target id
|
341
|
-
* @param source String form source
|
342
|
-
* @return RR this
|
343
|
-
*/
|
344
|
-
show_form_for: function(id, source) {
|
345
|
-
$(id).find('form').each('remove'); // removing old forms
|
346
|
-
$(id).insert(source);
|
347
|
-
|
348
|
-
return this.remotize_form($(id).first('form')).rescan(id);
|
349
|
-
},
|
350
|
-
|
351
|
-
/**
|
352
|
-
* watches link clicks and processes the ajax edit/delete operations
|
353
|
-
*
|
354
|
-
* @param Event event
|
355
|
-
*/
|
356
|
-
process_click: function(event) {
|
357
|
-
var link;
|
358
|
-
|
359
|
-
if ((link = event.find('a'+ this.Options.linkToAjaxEdit))) {
|
360
|
-
event.stop();
|
361
|
-
Xhr.load(link.get('href') + '.' + this.Options.format);
|
362
|
-
} else if ((link = event.find('a'+ this.Options.linkToAjaxDelete)) && link.has('onclick')) {
|
363
|
-
event.stop();
|
364
|
-
new Function('return '+ link.onclick.toString().replace('.submit', '.send'))().call(link);
|
365
|
-
}
|
366
|
-
},
|
367
|
-
|
368
|
-
/**
|
369
|
-
* Scans for updated elements
|
370
|
-
*
|
371
|
-
* @return RR this
|
372
|
-
*/
|
373
|
-
rescan: function(scope) {
|
374
|
-
$w('Draggable Droppable Tabs Tags Slider Selectable').each(function(name) {
|
375
|
-
if (name in window) {
|
376
|
-
window[name].rescan(this.Options.rescanWithScopes ? scope : null);
|
377
|
-
}
|
378
|
-
}, this);
|
379
|
-
|
380
|
-
|
381
|
-
return this;
|
382
|
-
}
|
383
|
-
};
|
384
|
-
|
385
|
-
|
386
|
-
/**
|
387
|
-
* the document onload hooks
|
388
|
-
*
|
389
|
-
* Copyright (C) 2010-2011 Nikolay Nemshilov
|
390
|
-
*/
|
391
|
-
$(document).on({
|
392
|
-
ready: function() {
|
393
|
-
RR.hide_flash();
|
394
|
-
},
|
395
|
-
|
396
|
-
click: function(event) {
|
397
|
-
RR.process_click(event);
|
398
|
-
}
|
399
|
-
});
|
400
|
-
|
401
|
-
window.RR = RR;
|
402
|
-
})(window, document, RightJS);
|
@@ -1,7 +0,0 @@
|
|
1
|
-
/**
|
2
|
-
* RubyOnRails Support Module v2.2.2
|
3
|
-
* http://rightjs.org/plugins/rails
|
4
|
-
*
|
5
|
-
* Copyright (C) 2009-2011 Nikolay Nemshilov
|
6
|
-
*/
|
7
|
-
(function(a,b,c){function l(a,c){var d=c.get("href"),e=c.get("data-method"),i=c.get("data-remote");if(!j(a,c)){(e||i)&&a.stop();if(i)h.load(d,k(c,{method:e||"get",spinner:c.get("data-spinner")}));else if(e){var l=f("meta[name=csrf-param]")[0],m=f("meta[name=csrf-token]")[0],n=g("form",{action:d,method:"post"});l=l&&l.get("content"),m=m&&m.get("content"),l&&m&&n.insert('<input type="hidden" name="'+l+'" value="'+m+'" />'),n.insert('<input type="hidden" name="_method" value="'+e+'"/>').insertTo(b.body).submit()}}}function k(a,b){return i.merge({onCreate:function(){a.fire("ajax:loading",{xhr:this})},onComplete:function(){a.fire("ajax:complete",{xhr:this})},onSuccess:function(){a.fire("ajax:success",{xhr:this})},onFailure:function(){a.fire("ajax:failure",{xhr:this})}},b)}function j(a,b){var c=b.get("data-confirm");if(c&&!confirm(c)){a.stop();return!0}}var d=c,e=c.$,f=c.$$,g=c.$E,h=c.Xhr,i=c.Object;c.Rails={version:"2.2.2"},d([c.String.prototype,c.Array.prototype,c.Function.prototype,c.Object,c.Options,c.Observer,c.Observer.prototype,c.Window.prototype,c.Document.prototype]).each(function(a){for(var b in a)try{if(/[A-Z]/.test(b)&&typeof a[b]==="function"){var c=d(b).underscored();if(a[c]===null||a[c]===undefined)a[c]=a[b]}}catch(e){}}),d([c.Element,c.Event,c.Form,c.Input]).each(function(a){if(a){var b={},c=a.prototype;for(var e in c)/[A-Z]/.test(e)&&typeof c[e]==="function"&&(a.prototype[d(e).underscored()]=c[e])}}),c.$alias(c.String.prototype,{index_of:"indexOf",last_index_of:"lastIndexOf",to_f:"toFloat",to_i:"toInt",gsub:"replace",downcase:"toLowerCase",upcase:"toUpperCase",index:"indexOf",rindex:"lastIndexOf",strip:"trim"}),c.$alias(c.Array.prototype,{collect:"map",detect:"filter",index_of:"indexOf",last_index_of:"lastIndexOf",index:"indexOf",rindex:"lastIndexOf"}),e(b).on({click:function(a){var b=a.find("a");b&&l(a,b)},submit:function(a){var b=a.target;b.has("data-remote")&&!j(a,b)&&(a.stop(),b.send(k(b,{spinner:b.get("data-spinner")||b.first(".spinner")})))}});var m={Options:{format:"js",flashId:"flashes",flashHideFx:"slide",flashHideDelay:3200,highlightUpdates:!0,removeFx:"fade",insertFx:"fade",insertPosition:"bottom",linkToAjaxEdit:".ajax_edit",linkToAjaxDelete:".ajax_delete",rescanWithScopes:!0},update_flash:function(a){var b=e(this.Options.flashId);b&&this.replace(b,a).hide_flash();return this},hide_flash:function(){if(this.Options.flashHideDelay>-1){var a=e(this.Options.flashId);a&&a.visible()&&a.hide.bind(a,this.Options.flashHideFx).delay(this.Options.flashHideDelay)}return this},highlight:function(a){e(a)&&this.Options.highlightUpdates&&e(a).highlight();return this},insert:function(a,b,c){var d=c||this.Options.insertPosition,f,g=e(a).insert(b,d);switch(d){case"bottom":f=g.children().last();break;case"top":f=g.first();break;case"before":f=g.prev();break;case"after":f=g.next()}f&&this.Options.insertFx?f.hide().show(this.Options.insertFx,{onFinish:this.highlight.bind(this,f)}):this.highlight(f);return this.rescan(a)},replace:function(a,b){e(a).replace(b);return this.highlight(a).rescan(a)},remove:function(a){e(a)&&e(a).remove(this.Options.removeFx)},remotize_form:function(a){var b=e(a);b&&(b.remotize().enable()._.action+="."+this.Options.format);return this},replace_form:function(a,b){var c=e(a);c&&(c.replace(b),this.remotize_form(a));return this.rescan(a)},show_form_for:function(a,b){e(a).find("form").each("remove"),e(a).insert(b);return this.remotize_form(e(a).first("form")).rescan(a)},process_click:function(a){var b;(b=a.find("a"+this.Options.linkToAjaxEdit))?(a.stop(),h.load(b.get("href")+"."+this.Options.format)):(b=a.find("a"+this.Options.linkToAjaxDelete))&&b.has("onclick")&&(a.stop(),(new Function("return "+b.onclick.toString().replace(".submit",".send")))().call(b))},rescan:function(b){$w("Draggable Droppable Tabs Tags Slider Selectable").each(function(c){c in a&&a[c].rescan(this.Options.rescanWithScopes?b:null)},this);return this}};e(b).on({ready:function(){m.hide_flash()},click:function(a){m.process_click(a)}}),a.RR=m})(window,document,RightJS)
|
@@ -1,384 +0,0 @@
|
|
1
|
-
/**
|
2
|
-
* RightJS-UI Rater v2.2.0
|
3
|
-
* http://rightjs.org/ui/rater
|
4
|
-
*
|
5
|
-
* Copyright (C) 2009-2011 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-2011 Nikolay Nemshilov
|
14
|
-
*/
|
15
|
-
|
16
|
-
/**
|
17
|
-
* The widget units constructor
|
18
|
-
*
|
19
|
-
* @param String tag-name or Object methods
|
20
|
-
* @param Object methods
|
21
|
-
* @return Widget wrapper
|
22
|
-
*/
|
23
|
-
function Widget(tag_name, methods) {
|
24
|
-
if (!methods) {
|
25
|
-
methods = tag_name;
|
26
|
-
tag_name = 'DIV';
|
27
|
-
}
|
28
|
-
|
29
|
-
/**
|
30
|
-
* An Abstract Widget Unit
|
31
|
-
*
|
32
|
-
* Copyright (C) 2010 Nikolay Nemshilov
|
33
|
-
*/
|
34
|
-
var AbstractWidget = new RightJS.Class(RightJS.Element.Wrappers[tag_name] || RightJS.Element, {
|
35
|
-
/**
|
36
|
-
* The common constructor
|
37
|
-
*
|
38
|
-
* @param Object options
|
39
|
-
* @param String optional tag name
|
40
|
-
* @return void
|
41
|
-
*/
|
42
|
-
initialize: function(key, options) {
|
43
|
-
this.key = key;
|
44
|
-
var args = [{'class': 'rui-' + key}];
|
45
|
-
|
46
|
-
// those two have different constructors
|
47
|
-
if (!(this instanceof RightJS.Input || this instanceof RightJS.Form)) {
|
48
|
-
args.unshift(tag_name);
|
49
|
-
}
|
50
|
-
this.$super.apply(this, args);
|
51
|
-
|
52
|
-
if (RightJS.isString(options)) {
|
53
|
-
options = RightJS.$(options);
|
54
|
-
}
|
55
|
-
|
56
|
-
// if the options is another element then
|
57
|
-
// try to dynamically rewrap it with our widget
|
58
|
-
if (options instanceof RightJS.Element) {
|
59
|
-
this._ = options._;
|
60
|
-
if ('$listeners' in options) {
|
61
|
-
options.$listeners = options.$listeners;
|
62
|
-
}
|
63
|
-
options = {};
|
64
|
-
}
|
65
|
-
this.setOptions(options, this);
|
66
|
-
|
67
|
-
return (RightJS.Wrapper.Cache[RightJS.$uid(this._)] = this);
|
68
|
-
},
|
69
|
-
|
70
|
-
// protected
|
71
|
-
|
72
|
-
/**
|
73
|
-
* Catches the options
|
74
|
-
*
|
75
|
-
* @param Object user-options
|
76
|
-
* @param Element element with contextual options
|
77
|
-
* @return void
|
78
|
-
*/
|
79
|
-
setOptions: function(options, element) {
|
80
|
-
if (element) {
|
81
|
-
options = RightJS.Object.merge(options, new Function("return "+(
|
82
|
-
element.get('data-'+ this.key) || '{}'
|
83
|
-
))());
|
84
|
-
}
|
85
|
-
|
86
|
-
if (options) {
|
87
|
-
RightJS.Options.setOptions.call(this, RightJS.Object.merge(this.options, options));
|
88
|
-
}
|
89
|
-
|
90
|
-
return this;
|
91
|
-
}
|
92
|
-
});
|
93
|
-
|
94
|
-
/**
|
95
|
-
* Creating the actual widget class
|
96
|
-
*
|
97
|
-
*/
|
98
|
-
var Klass = new RightJS.Class(AbstractWidget, methods);
|
99
|
-
|
100
|
-
// creating the widget related shortcuts
|
101
|
-
RightJS.Observer.createShortcuts(Klass.prototype, Klass.EVENTS || RightJS([]));
|
102
|
-
|
103
|
-
return Klass;
|
104
|
-
}
|
105
|
-
|
106
|
-
|
107
|
-
/**
|
108
|
-
* Same as the assignable, only it doesn't work with popups
|
109
|
-
* instead it simply updates the assigned unit value/content
|
110
|
-
*
|
111
|
-
* Copyright (C) 2010 Nikolay Nemshilov
|
112
|
-
*/
|
113
|
-
var Updater = {
|
114
|
-
|
115
|
-
/**
|
116
|
-
* Assigns the unit to work with an input element
|
117
|
-
*
|
118
|
-
* @param mixed element reference
|
119
|
-
* @return Rater this
|
120
|
-
*/
|
121
|
-
assignTo: function(element) {
|
122
|
-
var assign = R(function(element, event) {
|
123
|
-
if ((element = $(element))) {
|
124
|
-
element[element.setValue ? 'setValue' : 'update'](event.target.getValue());
|
125
|
-
}
|
126
|
-
}).curry(element);
|
127
|
-
|
128
|
-
var connect = R(function(element, object) {
|
129
|
-
element = $(element);
|
130
|
-
if (element && element.onChange) {
|
131
|
-
element.onChange(R(function() {
|
132
|
-
this.setValue(element.value());
|
133
|
-
}).bind(object));
|
134
|
-
}
|
135
|
-
}).curry(element);
|
136
|
-
|
137
|
-
if ($(element)) {
|
138
|
-
assign({target: this});
|
139
|
-
connect(this);
|
140
|
-
} else {
|
141
|
-
$(document).onReady(R(function() {
|
142
|
-
assign({target: this});
|
143
|
-
connect(this);
|
144
|
-
}.bind(this)));
|
145
|
-
}
|
146
|
-
|
147
|
-
return this.onChange(assign);
|
148
|
-
}
|
149
|
-
};
|
150
|
-
|
151
|
-
|
152
|
-
/**
|
153
|
-
* The init script for Rater
|
154
|
-
*
|
155
|
-
* Copyright (C) 2010 Nikolay Nemshilov
|
156
|
-
*/
|
157
|
-
var R = RightJS,
|
158
|
-
$ = RightJS.$,
|
159
|
-
$w = RightJS.$w,
|
160
|
-
Xhr = RightJS.Xhr,
|
161
|
-
isString = RightJS.isString,
|
162
|
-
isNumber = RightJS.isNumber;
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
/**
|
170
|
-
* The Rating widget
|
171
|
-
*
|
172
|
-
* Copyright (C) 2009-2011 Nikolay Nemshilov
|
173
|
-
*/
|
174
|
-
var Rater = new Widget({
|
175
|
-
include: Updater,
|
176
|
-
|
177
|
-
extend: {
|
178
|
-
version: '2.2.0',
|
179
|
-
|
180
|
-
EVENTS: $w('change hover send'),
|
181
|
-
|
182
|
-
Options: {
|
183
|
-
html: '★', // the dot html code
|
184
|
-
|
185
|
-
size: 5, // number of stars in the line
|
186
|
-
value: null, // default value
|
187
|
-
update: null, // an element to update
|
188
|
-
|
189
|
-
disabled: false, // if it should be disabled
|
190
|
-
disableOnVote: false, // if it should be disabled when user clicks a value
|
191
|
-
|
192
|
-
url: null, // an url to send results with AJAX
|
193
|
-
param: 'rate', // the value param name
|
194
|
-
Xhr: null // additional Xhr options
|
195
|
-
}
|
196
|
-
},
|
197
|
-
|
198
|
-
/**
|
199
|
-
* basic constructor
|
200
|
-
*
|
201
|
-
* @param mixed element reference or an options hash
|
202
|
-
* @param Object options hash
|
203
|
-
*/
|
204
|
-
initialize: function(options) {
|
205
|
-
this
|
206
|
-
.$super('rater', options)
|
207
|
-
.on({
|
208
|
-
click: this._clicked,
|
209
|
-
mouseover: this._hovered,
|
210
|
-
mouseout: this._left
|
211
|
-
});
|
212
|
-
|
213
|
-
if (this.empty()) {
|
214
|
-
for (var i=0; i < this.options.size; i++) {
|
215
|
-
this.insert('<div>'+ this.options.html + '</div>');
|
216
|
-
}
|
217
|
-
}
|
218
|
-
|
219
|
-
options = this.options;
|
220
|
-
|
221
|
-
if (options.value === null) {
|
222
|
-
options.value = this.find('.active').length;
|
223
|
-
}
|
224
|
-
|
225
|
-
this.setValue(options.value);
|
226
|
-
|
227
|
-
if (options.disabled) {
|
228
|
-
this.disable();
|
229
|
-
}
|
230
|
-
|
231
|
-
if (options.update) {
|
232
|
-
this.assignTo(options.update);
|
233
|
-
}
|
234
|
-
},
|
235
|
-
|
236
|
-
/**
|
237
|
-
* Sets the element value
|
238
|
-
*
|
239
|
-
* @param Number or String value
|
240
|
-
* @return Rater this
|
241
|
-
*/
|
242
|
-
setValue: function(value) {
|
243
|
-
if (!this.disabled()) {
|
244
|
-
// converting the type and rounding the value
|
245
|
-
value = isString(value) ? R(value).toInt() : value;
|
246
|
-
value = isNumber(value) ? R(value).round() : 0;
|
247
|
-
|
248
|
-
// checking constraints
|
249
|
-
value = R(value).max(this.options.size);
|
250
|
-
value = R(value).min(0);
|
251
|
-
|
252
|
-
// highlighting the value
|
253
|
-
this.highlight(value);
|
254
|
-
|
255
|
-
if (this.value != value) {
|
256
|
-
this.fire('change', {value: this.value = value});
|
257
|
-
}
|
258
|
-
}
|
259
|
-
|
260
|
-
return this;
|
261
|
-
},
|
262
|
-
|
263
|
-
/**
|
264
|
-
* Returns the current value of the rater
|
265
|
-
*
|
266
|
-
* @return Number value
|
267
|
-
*/
|
268
|
-
getValue: function() {
|
269
|
-
return this.value;
|
270
|
-
},
|
271
|
-
|
272
|
-
/**
|
273
|
-
* Sends an Xhr request with the current value to the options.url address
|
274
|
-
*
|
275
|
-
* @return Rater this
|
276
|
-
*/
|
277
|
-
send: function() {
|
278
|
-
if (this.options.url) {
|
279
|
-
this.request = new Xhr(this.options.url, this.options.Xhr)
|
280
|
-
.send(this.options.param+"="+this.value);
|
281
|
-
this.fire('send', {value: this.value});
|
282
|
-
}
|
283
|
-
return this;
|
284
|
-
},
|
285
|
-
|
286
|
-
/**
|
287
|
-
* Disables the instance
|
288
|
-
*
|
289
|
-
* @return Rater this
|
290
|
-
*/
|
291
|
-
disable: function() {
|
292
|
-
return this.addClass('rui-rater-disabled');
|
293
|
-
},
|
294
|
-
|
295
|
-
/**
|
296
|
-
* Enables this instance
|
297
|
-
*
|
298
|
-
* @return Rater this
|
299
|
-
*/
|
300
|
-
enable: function() {
|
301
|
-
return this.removeClass('rui-rater-disabled');
|
302
|
-
},
|
303
|
-
|
304
|
-
/**
|
305
|
-
* Checks if the instance is disabled
|
306
|
-
*
|
307
|
-
* @return boolean
|
308
|
-
*/
|
309
|
-
disabled: function() {
|
310
|
-
return this.hasClass('rui-rater-disabled');
|
311
|
-
},
|
312
|
-
|
313
|
-
// protected
|
314
|
-
|
315
|
-
// callback for 'hover' event
|
316
|
-
_hovered: function(event) {
|
317
|
-
var index = this.children().indexOf(event.target);
|
318
|
-
if (!this.disabled() && index > -1) {
|
319
|
-
this.highlight(index + 1);
|
320
|
-
this.fire('hover', {value: index + 1});
|
321
|
-
}
|
322
|
-
},
|
323
|
-
|
324
|
-
// callback for user-click
|
325
|
-
_clicked: function(event) {
|
326
|
-
var index = this.children().indexOf(event.target);
|
327
|
-
if (!this.disabled() && index > -1) {
|
328
|
-
this.setValue(index + 1);
|
329
|
-
if (this.options.disableOnVote) {
|
330
|
-
this.disable();
|
331
|
-
}
|
332
|
-
this.send();
|
333
|
-
}
|
334
|
-
},
|
335
|
-
|
336
|
-
// callback when user moves the mouse out
|
337
|
-
_left: function() {
|
338
|
-
this.setValue(this.value);
|
339
|
-
},
|
340
|
-
|
341
|
-
// visually highlights the value
|
342
|
-
highlight: function(value) {
|
343
|
-
this.children().each(function(element, i) {
|
344
|
-
element[value - 1 < i ? 'removeClass' : 'addClass']('active');
|
345
|
-
});
|
346
|
-
}
|
347
|
-
});
|
348
|
-
|
349
|
-
|
350
|
-
/**
|
351
|
-
* Document level on-demand auto-initialization
|
352
|
-
*
|
353
|
-
* Copyright (C) 2009-2010 Nikolay Nemshilov
|
354
|
-
*/
|
355
|
-
$(document).onMouseover(function(event) {
|
356
|
-
var target = event.target, element = event.find('.rui-rater');
|
357
|
-
|
358
|
-
if (element) {
|
359
|
-
if (!(element instanceof Rater)) {
|
360
|
-
element = new Rater(element);
|
361
|
-
|
362
|
-
if (target.parent() === element) {
|
363
|
-
target.fire('mouseover');
|
364
|
-
}
|
365
|
-
}
|
366
|
-
}
|
367
|
-
});
|
368
|
-
|
369
|
-
|
370
|
-
var embed_style = document.createElement('style'),
|
371
|
-
embed_rules = document.createTextNode("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}");
|
372
|
-
|
373
|
-
embed_style.type = 'text/css';
|
374
|
-
document.getElementsByTagName('head')[0].appendChild(embed_style);
|
375
|
-
|
376
|
-
if(embed_style.styleSheet) {
|
377
|
-
embed_style.styleSheet.cssText = embed_rules.nodeValue;
|
378
|
-
} else {
|
379
|
-
embed_style.appendChild(embed_rules);
|
380
|
-
}
|
381
|
-
|
382
|
-
|
383
|
-
return Rater;
|
384
|
-
})(document, RightJS);
|