quick update to mooui fixing a recursion error

This commit is contained in:
Damien Churchill 2008-09-30 16:27:17 +00:00
parent 27d2a86c74
commit df84e34660
2 changed files with 3 additions and 3 deletions

View File

@ -98,9 +98,9 @@ el.getElements('li').each(function(item){var width=item.getSize().x
if(width>widest){widest=width}});el.setStyle('width',widest+2)
el.getElements('li ul').each(function(item){item.setStyle('left',widest-20)});},showPos:function(x,y){this.element.setStyles({'left':x,'top':y-2});this.element.inject(document.body)
this.element.addEvent('mouseleave',function(e){this.hide()}.bind(this));}})
Widgets.ProgressBar=new Class({Extends:Widgets.Base,initialize:function(){this.parent(new Element('div'));this.bound={onResize:this.onResize.bindWithEvent(this)};this.element.addClass('moouiProgressBar');this.bar=new Element('div').inject(this.element);this.textSpan=new Element('span').inject(this.bar);this.sets({width:200,height:20});this.addEvent('resize',this.bound.onResize);},onResize:function(){this.textSpan.setStyles({'width':this.width,'height':this.height});this.update(this.text,this.percent);},update:function(text,percent){if(this.text!=text){this.text=text;this.textSpan.set('text',text);};if(this.percent!=percent){this.percent=percent;this.bar.setStyles({'width':Math.floor(this.width/100.0*percent),'height':this.height});};}});Widgets.Spinner=new Class({Extends:Widgets.Base,options:{precision:0,step:1,limit:{high:200,low:-1}},initialize:function(input,options){this.parent(new Element('div'),options);this.bound={onMouseDown:this.onMouseDown.bindWithEvent(this),onMouseUp:this.onMouseUp.bindWithEvent(this),onMouseWheel:this.onMouseWheel.bindWithEvent(this),onKeyDown:this.onKeyDown.bindWithEvent(this),onKeyUp:this.onKeyUp.bindWithEvent(this),onChange:this.onChange.bindWithEvent(this)};value=0;this.keyDown=false;if(input){this.element.replaces(input);value=new Number(input.value);};this.input=(input)?input:new Element('input');this.input.store('moouiWidget',this);this.element.grab(this.input);this.element.addClass('moouiSpinner');this.element.addEvent('mousewheel',this.bound.onMouseWheel);this.input.addEvent('keydown',this.bound.onKeyDown);this.input.addEvent('change',this.bound.onChange);this.buttons=new Element('div').addClass('moouiSpinnerButtons');this.up=new Element('div').addClass('moouiSpinnerUp');this.down=new Element('div').addClass('moouiSpinnerDown');this.up.addEvent('mousedown',this.bound.onMouseDown);this.down.addEvent('mousedown',this.bound.onMouseDown);this.buttons.grab(this.up);this.buttons.grab(this.down);this.element.grab(this.buttons);this.setValue(value);},getPrecision:function(){return Math.pow(10,this.options.precision+1)/10;},setValue:function(value){if(this.options.limit){if(this.options.limit.low&&value<=this.options.limit.low){value=this.options.limit.low;this.down.setStyle('opacity','0.5');}else if(this.options.limit.high&&value>=this.options.limit.high){value=this.options.limit.high;this.up.setStyle('opacity','0.5');}else{this.up.setStyle('opacity','1');this.down.setStyle('opacity','1');};};this.value=new Number(value);this.input.set('value',this.value.toFixed(this.options.precision));this.input.fireEvent('change');},changeValue:function(change){value=this.value+(change/this.getPrecision());this.setValue(value);},acceleratingChange:function(change){if(this.stop)return;this.changeValue(change);if(this.interval>100)this.interval-=100
Widgets.ProgressBar=new Class({Extends:Widgets.Base,initialize:function(){this.parent(new Element('div'));this.bound={onResize:this.onResize.bindWithEvent(this)};this.element.addClass('moouiProgressBar');this.bar=new Element('div').inject(this.element);this.textSpan=new Element('span').inject(this.bar);this.sets({width:200,height:20});this.addEvent('resize',this.bound.onResize);},onResize:function(){this.textSpan.setStyles({'width':this.width,'height':this.height});this.update(this.text,this.percent);},update:function(text,percent){if(this.text!=text){this.text=text;this.textSpan.set('text',text);};if(this.percent!=percent){this.percent=percent;this.bar.setStyles({'width':Math.floor(this.width/100.0*percent),'height':this.height});};}});Widgets.Spinner=new Class({Extends:Widgets.Base,options:{precision:0,step:1,limit:{high:200,low:-1}},initialize:function(input,options){this.parent(new Element('div'),options);this.bound={onMouseDown:this.onMouseDown.bindWithEvent(this),onMouseUp:this.onMouseUp.bindWithEvent(this),onMouseWheel:this.onMouseWheel.bindWithEvent(this),onKeyDown:this.onKeyDown.bindWithEvent(this),onKeyUp:this.onKeyUp.bindWithEvent(this),onChange:this.onChange.bindWithEvent(this)};value=0;this.keyDown=false;if(input){this.element.replaces(input);value=new Number(input.value);};this.input=(input)?input:new Element('input');this.input.store('moouiWidget',this);this.element.grab(this.input);this.element.addClass('moouiSpinner');this.element.addEvent('mousewheel',this.bound.onMouseWheel);this.input.addEvent('keydown',this.bound.onKeyDown);this.input.addEvent('change',this.bound.onChange);this.buttons=new Element('div').addClass('moouiSpinnerButtons');this.up=new Element('div').addClass('moouiSpinnerUp');this.down=new Element('div').addClass('moouiSpinnerDown');this.up.addEvent('mousedown',this.bound.onMouseDown);this.down.addEvent('mousedown',this.bound.onMouseDown);this.buttons.grab(this.up);this.buttons.grab(this.down);this.element.grab(this.buttons);this.setValue(value);},getPrecision:function(){return Math.pow(10,this.options.precision+1)/10;},setValue:function(value){if(this.options.limit){if(this.options.limit.low&&value<=this.options.limit.low){value=this.options.limit.low;this.down.setStyle('opacity','0.5');}else if(this.options.limit.high&&value>=this.options.limit.high){value=this.options.limit.high;this.up.setStyle('opacity','0.5');}else{this.up.setStyle('opacity','1');this.down.setStyle('opacity','1');};};this.value=new Number(value);this.input.set('value',this.value.toFixed(this.options.precision));this.settingValue=true;this.input.fireEvent('change');},changeValue:function(change){value=this.value+(change/this.getPrecision());this.setValue(value);},acceleratingChange:function(change){if(this.stop)return;this.changeValue(change);if(this.interval>100)this.interval-=100
else if(this.interval>10)this.interval-=10
this.acceleratingChange.delay(this.interval,this,change);},onMouseDown:function(e){this.value=new Number(this.input.value);document.addEvent('mouseup',this.bound.onMouseUp);if(e.target.hasClass('moouiSpinnerUp'))change=this.options.step;else change=this.options.step*-1;this.interval=600;this.stop=false;this.acceleratingChange(change);},onMouseUp:function(e){this.stop=true;document.removeEvent('mouseup',this.bound.onMouseUp);},onKeyDown:function(e){if(e.key=='up'||e.key=='down'){if(this.keyDown)return;this.value=new Number(this.input.value);change=(e.key=='up')?this.options.step:this.options.step*-1;this.input.addEvent('keyup',this.bound.onKeyUp);this.interval=600;this.stop=false;this.keyDown=true;this.acceleratingChange(change);}else if($A(['left','right','backspace']).contains(e.key)){return;}else{e.key=(e.code==190)?'.':e.key;pattern=/[0-9]/;if(!this.input.value.match(/\./)&&this.options.precision>0){pattern=/[0-9\.]/;};if(!e.key.match(pattern)){e.stop();return;};};},onKeyUp:function(e){this.stop=true;this.keyDown=false;this.input.removeEvent('keyup',this.bound.onKeyUp);},onMouseWheel:function(e){this.changeValue(this.options.step*e.wheel);},onChange:function(e){this.setValue(new Number(this.input.value));}});Widgets.SplitPane=new Class({Extends:Widgets.Base,options:{direction:'horizontal',name:null,splitSize:6,pane1:{},pane2:{}},initialize:function(element,pane1,pane2,options){this.parent(element,options);this.bound={onResize:this.onResize.bindWithEvent(this),onMouseDown:this.onMouseDown.bindWithEvent(this),onMouseMove:this.onMouseMove.bindWithEvent(this),onMouseUp:this.onMouseUp.bindWithEvent(this)};this.horizontal=(this.options.direction=='horizontal')?true:false;this.pane1=$W(pane1);this.pane2=$W(pane2);if(this.options.expand)this.expand();this.initPane(this.pane1,this.options.pane1);this.initPane(this.pane2,this.options.pane2);this.initSplitter();this.calculatePositions();this.setPosition(this.pane1);this.setPosition(this.splitter);this.setPosition(this.pane2);this.splitter.addEvent('mousedown',this.bound.onMouseDown);this.addEvent('resize',this.onResize.bindWithEvent(this));},initSplitter:function(){this.splitter=new Element('div').addClass('moouiSplitter');this.splitter.inject(this.pane1,'after');this.splitter.paneinfo={};if(this.horizontal){this.splitter.addClass('moouiSplitterVertical');}else{this.splitter.addClass('moouiSplitterHorizontal');};this.splitter.grab(new Element('div'));this.splitter.grab(new Element('div'));this.splitter.grab(new Element('div'));},onMouseDown:function(e){window.addEvent('mouseup',this.bound.onMouseUp);window.addEvent('mousemove',this.bound.onMouseMove);this.mouseStart={x:e.client.x,y:e.client.y};this.paneInfo={one:{startWidth:this.pane1.paneinfo.width,startHeight:this.pane1.paneinfo.height},two:{startWidth:this.pane2.paneinfo.width,startHeight:this.pane2.paneinfo.height}};},onMouseMove:function(e){if(this.horizontal){diff=e.client.x-this.mouseStart.x;p1width=this.paneInfo.one.startWidth+diff;p2width=this.paneInfo.two.startWidth-diff;if((this.pane1.paneinfo.min-this.pane1.element.modifiers.y)>p1width){this.pane1.paneinfo.width=this.pane1.paneinfo.min;this.pane2.paneinfo.width=this.paneInfo.two.startWidth+(this.paneInfo.one.startWidth-this.pane1.paneinfo.min);}else if((this.pane2.paneinfo.min-this.pane2.element.modifiers.y)>p2width){this.pane2.paneinfo.width=this.pane2.paneinfo.min;this.pane1.paneinfo.width=this.paneInfo.one.startWidth+(this.paneInfo.two.startWidth-this.pane2.paneinfo.min);}else{this.pane1.paneinfo.width=p1width;this.pane2.paneinfo.width=p2width;};}else{diff=e.client.y-this.mouseStart.y;p1height=this.paneInfo.one.startHeight+diff;p2height=this.paneInfo.two.startHeight-diff;if(this.pane1.paneinfo.min>p1height){this.pane1.paneinfo.height=this.pane1.paneinfo.min;this.pane2.paneinfo.height=this.paneInfo.two.startHeight+(this.paneInfo.one.startHeight-this.pane1.paneinfo.min);}else if(this.pane2.paneinfo.min>p2height){this.pane2.paneinfo.height=this.pane2.paneinfo.min;this.pane1.paneinfo.height=this.paneInfo.one.startHeight+(this.paneInfo.two.startHeight-this.pane2.paneinfo.min);}else{this.pane1.paneinfo.height=p1height;this.pane2.paneinfo.height=p2height;};};this.setPosition(this.pane1);this.setPosition(this.pane2);},onMouseUp:function(e){window.removeEvent('mouseup',this.bound.onMouseUp);window.removeEvent('mousemove',this.bound.onMouseMove);},initPane:function(pane,options){pane.addClass('moouiPane');pane.paneinfo={}
this.acceleratingChange.delay(this.interval,this,change);},onMouseDown:function(e){this.value=new Number(this.input.value);document.addEvent('mouseup',this.bound.onMouseUp);if(e.target.hasClass('moouiSpinnerUp'))change=this.options.step;else change=this.options.step*-1;this.interval=600;this.stop=false;this.acceleratingChange(change);},onMouseUp:function(e){this.stop=true;document.removeEvent('mouseup',this.bound.onMouseUp);},onKeyDown:function(e){if(e.key=='up'||e.key=='down'){if(this.keyDown)return;this.value=new Number(this.input.value);change=(e.key=='up')?this.options.step:this.options.step*-1;this.input.addEvent('keyup',this.bound.onKeyUp);this.interval=600;this.stop=false;this.keyDown=true;this.acceleratingChange(change);}else if($A(['left','right','backspace']).contains(e.key)){return;}else{e.key=(e.code==190)?'.':e.key;pattern=/[0-9]/;if(!this.input.value.match(/\./)&&this.options.precision>0){pattern=/[0-9\.]/;};if(!e.key.match(pattern)){e.stop();return;};};},onKeyUp:function(e){this.stop=true;this.keyDown=false;this.input.removeEvent('keyup',this.bound.onKeyUp);},onMouseWheel:function(e){this.changeValue(this.options.step*e.wheel);},onChange:function(e){if(this.settingValue){this.settingValue=false;return;};this.setValue(new Number(this.input.value));}});Widgets.SplitPane=new Class({Extends:Widgets.Base,options:{direction:'horizontal',name:null,splitSize:6,pane1:{},pane2:{}},initialize:function(element,pane1,pane2,options){this.parent(element,options);this.bound={onResize:this.onResize.bindWithEvent(this),onMouseDown:this.onMouseDown.bindWithEvent(this),onMouseMove:this.onMouseMove.bindWithEvent(this),onMouseUp:this.onMouseUp.bindWithEvent(this)};this.horizontal=(this.options.direction=='horizontal')?true:false;this.pane1=$W(pane1);this.pane2=$W(pane2);if(this.options.expand)this.expand();this.initPane(this.pane1,this.options.pane1);this.initPane(this.pane2,this.options.pane2);this.initSplitter();this.calculatePositions();this.setPosition(this.pane1);this.setPosition(this.splitter);this.setPosition(this.pane2);this.splitter.addEvent('mousedown',this.bound.onMouseDown);this.addEvent('resize',this.onResize.bindWithEvent(this));},initSplitter:function(){this.splitter=new Element('div').addClass('moouiSplitter');this.splitter.inject(this.pane1,'after');this.splitter.paneinfo={};if(this.horizontal){this.splitter.addClass('moouiSplitterVertical');}else{this.splitter.addClass('moouiSplitterHorizontal');};this.splitter.grab(new Element('div'));this.splitter.grab(new Element('div'));this.splitter.grab(new Element('div'));},onMouseDown:function(e){window.addEvent('mouseup',this.bound.onMouseUp);window.addEvent('mousemove',this.bound.onMouseMove);this.mouseStart={x:e.client.x,y:e.client.y};this.paneInfo={one:{startWidth:this.pane1.paneinfo.width,startHeight:this.pane1.paneinfo.height},two:{startWidth:this.pane2.paneinfo.width,startHeight:this.pane2.paneinfo.height}};},onMouseMove:function(e){if(this.horizontal){diff=e.client.x-this.mouseStart.x;p1width=this.paneInfo.one.startWidth+diff;p2width=this.paneInfo.two.startWidth-diff;if((this.pane1.paneinfo.min-this.pane1.element.modifiers.y)>p1width){this.pane1.paneinfo.width=this.pane1.paneinfo.min;this.pane2.paneinfo.width=this.paneInfo.two.startWidth+(this.paneInfo.one.startWidth-this.pane1.paneinfo.min);}else if((this.pane2.paneinfo.min-this.pane2.element.modifiers.y)>p2width){this.pane2.paneinfo.width=this.pane2.paneinfo.min;this.pane1.paneinfo.width=this.paneInfo.one.startWidth+(this.paneInfo.two.startWidth-this.pane2.paneinfo.min);}else{this.pane1.paneinfo.width=p1width;this.pane2.paneinfo.width=p2width;};}else{diff=e.client.y-this.mouseStart.y;p1height=this.paneInfo.one.startHeight+diff;p2height=this.paneInfo.two.startHeight-diff;if(this.pane1.paneinfo.min>p1height){this.pane1.paneinfo.height=this.pane1.paneinfo.min;this.pane2.paneinfo.height=this.paneInfo.two.startHeight+(this.paneInfo.one.startHeight-this.pane1.paneinfo.min);}else if(this.pane2.paneinfo.min>p2height){this.pane2.paneinfo.height=this.pane2.paneinfo.min;this.pane1.paneinfo.height=this.paneInfo.one.startHeight+(this.paneInfo.two.startHeight-this.pane2.paneinfo.min);}else{this.pane1.paneinfo.height=p1height;this.pane2.paneinfo.height=p2height;};};this.setPosition(this.pane1);this.setPosition(this.pane2);},onMouseUp:function(e){window.removeEvent('mouseup',this.bound.onMouseUp);window.removeEvent('mousemove',this.bound.onMouseMove);},initPane:function(pane,options){pane.addClass('moouiPane');pane.paneinfo={}
if(options){pane.paneinfo.min=(options.min)?options.min:0;pane.paneinfo.expand=(options.expand)?options.expand:false;};},calculatePositions:function(resized){if(resized){if(this.horizontal){this.calculateResize(resized,'width','height','x','y');}else{this.calculateResize(resized,'height','width','y','x');}}else{if(this.horizontal){this.calculateInitial('width','height','x','y');}else{this.calculateInitial('height','width','y','x');}}},calculateInitial:function(dm,ds,pm,ps){var size=this.getInnerSize();this.pane1.getSizeModifiers();this.pane2.getSizeModifiers();this.splitter.getSizeModifiers();if(this.pane1.paneinfo.expand){this.pane2.paneinfo[dm]=this.pane2.paneinfo.min;this.pane1.paneinfo[dm]=size[pm]-this.pane2.paneinfo.min-this.options.splitSize;this.pane1.paneinfo[dm]-=this.pane1.element.modifiers[pm]+this.pane2.element.modifiers[pm];}else{this.pane1.paneinfo[dm]=this.pane1.paneinfo.min;this.pane2.paneinfo[dm]=size[pm]-this.pane1.paneinfo.min-this.options.splitSize;this.pane2.paneinfo[dm]-=this.pane2.element.modifiers[pm]+this.pane1.element.modifiers[pm];}
this.pane1.paneinfo[ds]=this.pane2.paneinfo[ds]=size[ps];this.pane1.paneinfo[ds]-=this.pane1.element.modifiers[ps];this.pane2.paneinfo[ds]-=this.pane2.element.modifiers[ps];this.splitter.paneinfo[ds]=size[ps];this.splitter.paneinfo[dm]=this.options.splitSize;},calculateResize:function(resized,dm,ds,pm,ps){size=this.getInnerSize();this.pane1.getSizeModifiers();this.pane2.getSizeModifiers();this.splitter.getSizeModifiers();if(resized[dm]&&resized[dm]!=resized[('old-'+dm).camelCase()]){if(this.pane1.paneinfo.expand){this.pane1.paneinfo[dm]=size[pm]-this.pane2.paneinfo[dm]-this.options.splitSize;this.pane1.paneinfo[dm]-=this.pane1.element.modifiers[pm]+this.pane2.element.modifiers[pm];}else{this.pane2.paneinfo[dm]=size[pm]-this.pane1.paneinfo[dm]-this.options.splitSize;this.pane2.paneinfo[dm]-=this.pane2.element.modifiers[pm]+this.pane1.element.modifiers[pm];}};if(resized[ds]&&resized[ds]!=resized[('old-'+ds).camelCase()]){this.pane1.paneinfo[ds]=this.pane2.paneinfo[ds]=size[ps];this.splitter.paneinfo[ds]=size[ps];this.splitter.paneinfo[ds]-=this.splitter.modifiers[ps];this.pane1.paneinfo[ds]-=this.pane1.element.modifiers[ps];this.pane2.paneinfo[ds]-=this.pane2.element.modifiers[ps];};},setPosition:function(object){if(object.hasClass('moouiSplitter')){sets=object.setStyles.bind(object);}else{sets=object.sets.bind(object);};sets({width:object.paneinfo.width,height:object.paneinfo.height});},onResize:function(event){this.calculatePositions(event)
this.setPosition(this.pane1);this.setPosition(this.splitter);this.setPosition(this.pane2);}})