📄 gui1.js
字号:
{this.setEnabled(this._command.getEnabled());this.setChecked(this._command.getChecked());this.setUserValue(this._command.getUserValue());}};function BiRadioButton(sText,bChecked){if(_biInPrototype)return;BiLabel.call(this,sText);this._checked=Boolean(bChecked);this._radioButtonId=this.getHtmlProperty("id")+"-radio-button";this.setTabIndex(1);this.addEventListener("click",this._onclick);this.addEventListener("keydown",this._onkeydown);this.addEventListener("keyup",this._onkeyup);this.setHtmlProperty("htmlFor",this._radioButtonId);}
_p=_biExtend(BiRadioButton,BiLabel,"BiRadioButton");_p._drawIcon=true;_p._iconTextGap=5;_p._radioGroup=null;_p._acceptsEnter=true;_p._acceptsEsc=false;_p._userValue=null;BiRadioButton.prototype.getUserValue=function(){return this._userValue;};_p.setUserValue=function(v)
{if(this._userValue!=v)
{this._userValue=v;if(this._command)
this._command.setUserValue(v);}};_p.setLabelFor=_p.getLabelFor=_p.setIcon=_p.getIcon=function(){throw new Error("Not supported by BiRadioButton");};_p.setChecked=function(bChecked){if(this._checked!=bChecked){this._checked=bChecked;if(this._created){this._input.checked=bChecked;this._input.defaultChecked=bChecked;}
this.dispatchEvent(new BiEvent("change"));if(this._group&&bChecked)
this._group.setSelected(this);}};_p.getChecked=function(bChecked){return this._checked;};_p.setGroup=function(oRadioGroup){if(this._group!=oRadioGroup){if(this._group)
this._group.remove(this);this._group=oRadioGroup;if(this._group){this._group.add(this);}
this._setHtml();}};BiRadioButton.prototype.getGroup=function(){return this._group;};_p._getGroupName=function()
{return this._group?this._group._groupName:this._radioButtonId;};_p._setHtml=function(){BiLabel.prototype._setHtml.call(this);if(this._created){this._input=this._element.getElementsByTagName("INPUT")[0];if(BiBrowserCheck.ie)
{this._element.onclick=BiComponent.__oninlineevent;}}};_p.dispose=function(){if(this._disposed)return;BiLabel.prototype.dispose.call(this);if(this._group)
{this._group.remove(this);this._group=null;}
if(this._input)
{this._input._biComponent=null;this._input.onclick=null;}
this._input=null;};_p._getIconHtml=function(){var marginSide,blockStyle="";switch(this._iconPosition){case"right":marginSide="left";break;case"top":marginSide="bottom";blockStyle="display:block;"
break;case"bottom":marginSide="top";blockStyle="display:block;"
break;default:marginSide="right";break;}
var bHasText=!(this._html==""||this._text=="")
var iconTextGap=bHasText?this._iconTextGap:0;return"<input type=\"radio\" class=\"bi-radio-button-input\""+(this._checked?" checked=\"true\"":"")+(!this._enabled?" disabled=\"true\"":"")+" id=\""+this._radioButtonId+"\""+" name=\""+this._getGroupName()+"\" style=\""+blockStyle+"margin-"+marginSide+":"+iconTextGap+"px;"+"\">";};_p._onclick=function(e)
{if(this.getIsEnabled())
{var be=e._event;var el=be.target||be.srcElement;if(el==this._input)
{this.setChecked(true);this.dispatchEvent(new BiEvent("action"))}
else if(BiBrowserCheck.moz)
{this.setChecked(true);this.dispatchEvent(new BiEvent("action"));}}};_p._onkeydown=function(e){var kc=e.getKeyCode();if(kc==BiKeyboardEvent.ENTER&&!e.getAltKey()){this.setChecked(true);this.dispatchEvent(new BiEvent("action"));}
else if(this._group&&(kc==BiKeyboardEvent.LEFT||kc==BiKeyboardEvent.UP))
this._group.selectPrevious(this);else if(this._group&&(kc==BiKeyboardEvent.RIGHT||kc==BiKeyboardEvent.DOWN))
this._group.selectNext(this);};_p._onkeyup=function(e)
{if(e.getKeyCode()==BiKeyboardEvent.SPACE)
{var be=e._event;var el=be.target||be.srcElement;if(el==this._input)
return;this.setChecked(true);this.dispatchEvent(new BiEvent("action"));}};_p._oninlineevent=function(e)
{if(BiBrowserCheck.ie)
{e=this._document.parentWindow.event;if(e.type=="click")
e.cancelBubble=e.srcElement!=this._input;else BiComponent.prototype._oninlineevent.call(this,e);}
else BiComponent.prototype._oninlineevent.call(this,e);};_p.setAttribute=function(sName,sValue,oParser)
{switch(sName)
{case"group":if(sValue.charAt(0)=="#")
sValue=sValue.substr(1);var c=oParser.getComponentById(sValue);this.setGroup(c);break;default:BiLabel.prototype.setAttribute.apply(this,arguments);}};_p._syncWithCommmand=function()
{if(this._command)
{this.setEnabled(this._command.getEnabled());this.setChecked(this._command.getChecked());this.setUserValue(this._command.getUserValue());}};_p.setValue=_p.setChecked;_p.getValue=_p.getChecked;function BiRadioGroup(){if(_biInPrototype)return;BiEventTarget.call(this);this._items=new BiSet;this._groupName=BiRadioGroup._radioGroupName+ ++BiRadioGroup._radioGroupCount;}
BiRadioGroup._radioGroupName="bi-radio-group-";BiRadioGroup._radioGroupCount=0;_p=_biExtend(BiRadioGroup,BiEventTarget,"BiRadioGroup");_p._selected=null;_p._enabled=true;BiRadioGroup.prototype.getItems=function(){return this._items;};_p.add=function(oRadioButton){if(!this._items.contains(oRadioButton)){this._items.add(oRadioButton);oRadioButton.setGroup(this);if(oRadioButton.getChecked()||this.getUserValue()!=null&&oRadioButton.getUserValue()==this.getUserValue())
{this.setSelected(oRadioButton);}
oRadioButton.setEnabled(this.getEnabled());}};_p.remove=function(oRadioButton){this._items.remove(oRadioButton);oRadioButton._group=null;if(oRadioButton.getChecked())
this.setSelected(null);};_p.setSelected=function(oRadioButton){if(this._selected!=oRadioButton){if(this._selected)
this._selected.setChecked(false);this._selected=oRadioButton;if(this._selected)
this._selected.setChecked(true);this.dispatchEvent(new BiEvent("change"));if(this._command)
this._command.setUserValue(oRadioButton?oRadioButton.getUserValue():null);}};BiRadioGroup.prototype.getSelected=function(){return this._selected;};_p.selectNext=function(oRadioButton){if(!this._items.contains(oRadioButton)){return;}
var items=this._items.toArray();var index=items.indexOf(oRadioButton);var i=0;var l=items.length;index=(index+1)%l;while(i<l&&!items[index].getIsEnabled()){index=(index+1)%l;i++;}
var item=items[index];if(item.getIsEnabled()){this.setSelected(item);item.setFocused(true);}};_p.selectPrevious=function(oRadioButton){if(!this._items.contains(oRadioButton)){return;}
var items=this._items.toArray();var index=items.indexOf(oRadioButton);var i=0;var l=items.length;index=(index-1+l)%l;while(i<l&&!items[index].getIsEnabled()){index=(index-1+l)%l;i++;}
var item=items[index];if(item.getIsEnabled()){this.setSelected(item);item.setFocused(true);}};_p.setEnabled=function(b)
{if(this._enabled!=b)
{this._enabled=b;var items=this._items.toArray();for(var i=0;i<items.length;i++)
{items[i].setEnabled(b);}
this.dispatchEvent(new BiEvent("enabledchanged"));}};BiRadioGroup.prototype.getEnabled=function(){return this._enabled;};_p.getUserValue=function()
{var s=this.getSelected()
return s?s.getUserValue():null;};_p.setUserValue=function(v)
{if(this.getUserValue()!=v)
{var items=this._items.toArray();for(var i=0;i<items.length;i++)
{if(items[i].getUserValue()==v)
{items[i].setChecked(true);break;}}
if(this._command)
this._command.setUserValue(v);}};_p._command=null;BiRadioGroup.prototype.getCommand=function(){return this._command;};_p.setCommand=function(oCommand)
{if(this._command!=oCommand)
{if(this._command)
{this._command.removeEventListener("enabledchanged",this._syncWithCommmand,this);this._command.removeEventListener("uservaluechanged",this._syncWithCommmand,this);}
this._command=oCommand;if(this._command)
{this._syncWithCommmand();this._command.addEventListener("enabledchanged",this._syncWithCommmand,this);this._command.addEventListener("uservaluechanged",this._syncWithCommmand,this);}}};_p._syncWithCommmand=function()
{if(this._command)
{this.setEnabled(this._command.getEnabled());this.setUserValue(this._command.getUserValue());}};_p.setAttribute=function(sName,sValue,oParser)
{switch(sName)
{case"command":if(sValue.charAt(0)=="#")
sValue=sValue.substr(1);var ref=oParser.getComponentById(sValue);this.setProperty(sName,ref);break;default:BiEventTarget.prototype.setAttribute.apply(this,arguments);}};_p.dispose=function()
{if(this._disposed)
return;BiEventTarget.prototype.dispose.call(this);this.setCommand(null);this._items.dispose();this._items=null;};function BiTextField(sText){if(_biInPrototype)return;BiComponent.call(this);if(sText)this._text=sText;this.setCssClassName("bi-text-field");this.setTabIndex(1);this.setCanSelect(true);this.setHtmlProperty("value",this._text);this.setHtmlProperty("type","text");this._setHtmlAttribute("autocomplete","OFF");this.addEventListener("keypress",this._onKeyPress);this.addEventListener("keydown",this._onKeyDown);this.addEventListener("focus",this._onFocus);this.addEventListener("blur",this._onBlur);this.setAppearance("text-field");}
_p=_biExtend(BiTextField,BiComponent,"BiTextField");_p._tagName="INPUT";_p._text="";_p._invalidMessage="";_p._validator=null;_p.setText=function(sText)
{var oldText=this.getText();if(oldText!=sText)
{this._text=sText;this.setHtmlProperty("value",sText);if(this._created&&BiBrowserCheck.moz)
this.dispatchEvent(new BiEvent("textchanged"));}};_p.getText=function(){if(this.getCreated())
return this._text=this._element.value;return this._text;};_p.setFont=function(oFont){this._font=oFont;oFont.paintFont(this);};_p.getFont=function(){return this._font?this._font:new BiFont;};_p.setAlign=function(sAlign){this.setStyleProperty("textAlign",sAlign);};_p.getAlign=function(){return this.getStyleProperty("textAlign");};_p.setVerticalAlign=function(sVerticalAlign){this.setStyleProperty("verticalAlign",sVerticalAlign);};_p.setMaxLength=function(nMaxLength){this.setHtmlProperty("maxLength",nMaxLength);};_p.getMaxLength=function(){return this.getHtmlProperty("maxLength");};_p.setReadOnly=function(bReadOnly){this.setHtmlProperty("readOnly",bReadOnly);};_p.getReadOnly=function(){return this.getHtmlProperty("readOnly");};BiTextField.prototype.getValidator=function(){return this._validator;};BiTextField.prototype.setValidator=function(v){this._validator=v;};BiTextField.prototype.getInvalidMessage=function(){return this._invalidMessage;};BiTextField.prototype.setInvalidMessage=function(v){this._invalidMessage=v;};_p.getIsValid=function()
{if(typeof this._validator!="function")
return true;return this._validator(this.getText());};BiTextField.createRegExpValidator=function(oRegExp)
{return function(s)
{return oRegExp.test(s);};};_p.setSelectionStart=function(nSelectionStart)
{if(BiBrowserCheck.ie)
{var s=this._element.value;for(var i=nSelectionStart++;i!= -1;i=s.substring(0,i).lastIndexOf('\r\n')){nSelectionStart--;}
var r=this._getRange();r.collapse();r.move("character",nSelectionStart);r.select();}
else {if(!this._created)
throw new Error("Visual property on non created component");this._element.selectionStart=nSelectionStart;}};_p.getSelectionStart=function()
{if(BiBrowserCheck.ie)
{var r=this._getRange();var sr=this._getSelectionRange();if(!this._element.contains(sr.parentElement()))
return-1;r.setEndPoint("EndToStart",sr);return r.text.length;}
else {if(!this._created)
throw new Error("Visual property on non created component");return this._element.selectionStart;}};_p.setSelectionLength=function(nSelectionLength)
{if(BiBrowserCheck.ie)
{var sr=this._getSelectionRange();if(!this._element.contains(sr.parentElement()))
return;sr.collapse();sr.moveEnd("character",nSelectionLength);sr.select();}
else {if(!this._created)
throw new Error("Visual property on non created component");this._element.selectionEnd=this._element.selectionStart+nSelectionLength;}};_p.getSelectionLength=function()
{if(BiBrowserCheck.ie)
{var sr=this._getSelectionRange();if(!this._element.contains(sr.parentElement()))
return 0;return sr.text.length;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -