/** * Selectable unit for RightJS * http://rightjs.org/ui/selectable * * Copyright (C) 2009-2010 Nikolay Nemshilov */ 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= 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); 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= 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"); 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)}, 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); 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.lengtha)a=c=a;for(c=c;c"+(a?a.html():" ")+"")},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, g(d).get("value")||d.innerHTML]);d.selected&&!a._.disabled&&b.selected.push(c);if(d.disabled||a._.disabled)b.disabled.push(c)});if(b.selected.empty())b.selected=0;return b}});g(h).onReady(function(){k.rescan()});h.write(''); return k}(document,RightJS);