javascript 框架小结 个人工作经验

时间:2021-05-28

/**************************************************************************************** 作者:萧 枫
QQ:77182997
MSN:xiaofengnet@hotmail.com
Email:xiaofengnet@163.com
网址:http://pat'){
s.x = document.documentElement.scrollTop;
s.y = document.documentElement.scrollLeft;
}else if(document.body){
s.x = document.body.scrollTop;
s.y = document.body.scrollLeft;
}
return s;
},
getRnd : function(){return Math.floor(Math.random()*1000000);}
}

function FileType(FName){
FName = FName.replace(/\\/gi,"/");
FName = FName.substr(FName.lastIndexOf("/") + 1);
return {Name : FName.substr(0,FName.indexOf(".")),Type : FName.substr(FName.indexOf(".") + 1)};
}
/*===========================================================================================
【打开选择窗口及保存窗口】
[2009-05-28]
第一种方法:
var dialog = new XiaoFeng.Dialog("请选择文件","txt 文件(*.txt)|*.txt|所有文件(*.*)|*.*",".txt");
第二种方法:
var dialog = new XiaoFeng.Dialog({
Title : "请选择文件",
Filter : "txt 文件(*.txt)|*.txt|所有文件(*.*)|*.*",
DefaultExt : ".txt"
});
dialog.Open();
注:参数可以不填写,则为默认的.
*/
XiaoFeng.Dialog = function(){
this.DialogTitle = "请选择要打开的文件";
this.DialogFilter = "Excel 文件(*.xls)|*.xls|所有文件(*.*)|*.*";
this.DialogDefaultExt = ".xls";
this.Query = arguments;
var self = this;
this.Init = function(){
if(typeof self.Query[0] == "string"){
self.DialogTitle = self.Query[0]?self.Query[0]:self.DialogTitle;
self.DialogFilter = self.Query[1]?self.Query[1]:self.DialogFilter;
self.DialogDefaultExt = self.Query[2]?self.Query[2]:self.DialogDefaultExt;
}else if(typeof self.Query[0] == "object"){
self.DialogTitle = self.Query[0].Title?self.Query[0].Title:self.DialogTitle;
self.DialogFilter = self.Query[0].Filter?self.Query[0].Filter:self.DialogFilter;
self.DialogDefaultExt = self.Query[0].DefaultExt?self.Query[0].DefaultExt:self.DialogDefaultExt;
}
try{
if(!$("Dialog_OpenSave")){
var _Dialog_Open = $C("object");
_Dialog_Open.id = "Dialog_OpenSave";
_Dialog_Open.classid = "CLSID:F9043C85-F6F2-101A-A3C9-08002B2F49FB";
_Dialog_Open.style.display = "none";
document.body.appendChild(_Dialog_Open);
}
$("Dialog_OpenSave").CancelError = true;
}catch(e){}
}
this.Open = function(){
$("Dialog_OpenSave").DialogTitle = this.DialogTitle;
$("Dialog_OpenSave").Filter = this.DialogFilter;
$("Dialog_OpenSave").DefaultExt = this.DialogDefaultExt;
$("Dialog_OpenSave").ShowOpen();
return $("Dialog_OpenSave").FileName;
}
this.Save = function(){
$("Dialog_OpenSave").DialogTitle = this.DialogTitle.replace("打开","保存");
$("Dialog_OpenSave").Filter = this.DialogFilter;
$("Dialog_OpenSave").DefaultExt = this.DialogDefaultExt;
$("Dialog_OpenSave").ShowSave();
return $("Dialog_OpenSave").FileName;
}
this.Init();
}

var SelectClass = XiaoFeng.SelectClass = function(){
this.Name = "";
this.Source = new Object();
this.FirstOption = [["==请选择==","0"]];
this.SelectFirst = true;
this.Select = "";
this.Fun = function(e){return;}
this.Run = function(){
if(!$(this.Name)){
var _Input = $C("input");
_Input.type = "hidden";
_Input.name = this.Name;
_Input.id = this.Name;
document.body.appendChild(_Input);
}
$(this.Name).value = this.Select;
if(typeof this.Source == "object")
if(this.Source.hasChildNodes){
this.CreateSelect(this.Source);
if(this.Select == ""){
var __Select = $(this.Name).parentNode.getElementsByTagName("select");
if(this.SelectFirst)
$(this.Name).value = __Select[__Select.length - 1].value;
else
$(this.Name).value = __Select[__Select.length - 1].options[1].value;
}
}else{
var _Span = $C("span");
_Span.innerHTML = "数据源为空。";
$(this.Name).parentNode.appendChild(_Span);
}
else{
var _Span = $C("span");
_Span.innerHTML = "数据源出错。";
$(this.Name).parentNode.appendChild(_Span);
}
}
this.CreateSelect = function(node){
if(!node.hasChildNodes){this._SelectFirstName();return;}
var Select = $C("select");
Select.id = Select.name = "select_"+ (new Date().getTime());
var _f = false,_s = 0;
if(typeof this.FirstOption == "string")this.FirstOption = [];
if(typeof this.FirstOption == "object" && this.FirstOption.length > 0)
Select.add(this.CreateOption("==请选择==","0",false));
for(var i = 0;i < node.childNodes.length; i++){
if(node.childNodes[i].getAttribute("s") == null){_f = false;}else{_f = true;_s = i;}
Select.add(this.CreateOption(node.childNodes[i].getAttribute("Name"),node.childNodes[i].getAttribute("Id"),_f));
}
$(this.Name).parentNode.insertBefore(Select,$(this.Name));
if(_s > 0)
this.CreateSelect(node.childNodes[_s]);
else{
this.CreateSelect(node.childNodes[0]);
if(this.SelectFirst)
if(this.FirstOption.length == 0)
Select.options[0].selected = true;
else
Select.options[1].selected = true;
}
}
this.CreateOption = function(t,v,f){
var OptionSub = new Option();
OptionSub.text = t;
OptionSub.value = v;
if(f)OptionSub.selected = f;
return OptionSub;
}
this._SelectFirstName = function(){
var _Select = $(this.Name).parentNode.getElementsByTagName("select");
var self = this,_f = true;
var _FirstOption = [],_FirstLength = this.FirstOption.length;
if(this.FirstOption.length == 0)_f = false;
for(var i = 0;i < _Select.length; i++){
if(_f){
if(i >= _FirstLength)
_FirstOption = this.FirstOption[0];
else
_FirstOption = this.FirstOption[i];
_Select[i].options[0].text = _FirstOption[0];
_Select[i].options[0].value = _FirstOption[1];
}
if(i == _Select.length - 1)
_Select[i].setAttribute("onchange",function(){
var __Select = this.parentNode.getElementsByTagName("select");
$(self.Name).value = __Select[__Select.length - 1].value;
if(self.FirstOption.length != 0 && this.selectedIndex == 0)
if(_Select.length > 1)
$(self.Name).value = __Select[__Select.length - 2].value;
self.Fun(this);
});
else
_Select[i].setAttribute("onchange",function(){
self._RemoveSelect(this);
self._SelectNode(self.Source,this.value);
var __Select = this.parentNode.getElementsByTagName("select");
if(self.SelectFirst){
$(self.Name).value = __Select[__Select.length - 1].value;
}else
$(self.Name).value = __Select[__Select.length - 1].options[1].value;
if(self.FirstOption.length != 0 && this.selectedIndex == 0)
if(_Select.length > 1)
$(self.Name).value = __Select[__Select.length - 2].value;
self.Fun(this);
});
}
}
this._SelectNode = function(node,s){
for(var i = 0;i < node.childNodes.length; i++)
if(node.childNodes[i].getAttribute("Id") == s)
this.CreateSelect(node.childNodes[i]);
else
if(node.childNodes[i].hasChildNodes)this._SelectNode(node.childNodes[i],s);
}
this._RemoveSelect = function(o){
var _Select = $(this.Name).parentNode.getElementsByTagName("select");
var _f = false;
for(var i = 0;i < _Select.length; i++){
if(_Select[i] == o){_f = true;continue;}
if(_f){_Select[i].parentNode.removeChild(_Select[i]);i--;}
}
}
}

声明:本页内容来源网络,仅供用户参考;我单位不保证亦不表示资料全面及准确无误,也不保证亦不表示这些资料为最新信息,如因任何原因,本网内容或者用户因倚赖本网内容造成任何损失或损害,我单位将不会负任何法律责任。如涉及版权问题,请提交至online#300.cn邮箱联系删除。

相关文章