190 lines
5.0 KiB
JavaScript
190 lines
5.0 KiB
JavaScript
|
|
window.AbstractTab = {};
|
|||
|
|
AbstractTab.add = function( option ){
|
|||
|
|
// <20><><EFBFBD><EFBFBD><EFBFBD>Ѿ<EFBFBD><D1BE><EFBFBD><EFBFBD><EFBFBD>,<2C>ͼ<EFBFBD><CDBC><EFBFBD><EFBFBD>ò˵<C3B2>
|
|||
|
|
if( this.isExist(option.id) ){
|
|||
|
|
this.click(option.id);
|
|||
|
|
$('#'+this.getFrameID(option.id)).attr('src', option.url);
|
|||
|
|
return false;
|
|||
|
|
}
|
|||
|
|
this.addTab(option);
|
|||
|
|
this.addFrame(option);
|
|||
|
|
};
|
|||
|
|
|
|||
|
|
// <20><><EFBFBD><EFBFBD>һ<EFBFBD><D2BB>Tab
|
|||
|
|
AbstractTab.addTab = function( option ){
|
|||
|
|
var _this = this;
|
|||
|
|
var id = option.id;
|
|||
|
|
var isLock = (option.lock ? true : false);
|
|||
|
|
var lock = option.lock ? this.lockClass : "";
|
|||
|
|
var active = this.activeClass;
|
|||
|
|
var title = option.title ? option.title : "";
|
|||
|
|
var name = this.getCutName(option.name);
|
|||
|
|
var args = {id:id,name:name,active:active,title:title,lock:lock,isLock:isLock};
|
|||
|
|
var html = this.getTabHtml(args);
|
|||
|
|
var element = jQuery(html);
|
|||
|
|
// <20><><EFBFBD><EFBFBD>ѡ<EFBFBD><D1A1><EFBFBD>¼<EFBFBD><C2BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
element.click( function(){
|
|||
|
|
_this.click(this.id);
|
|||
|
|
}).click();
|
|||
|
|
// <20>رհ<D8B1>ť<EFBFBD>¼<EFBFBD>
|
|||
|
|
element.find(".closeTab").click( function(){
|
|||
|
|
_this.close(jQuery(this).parent().attr("id"));
|
|||
|
|
return false;
|
|||
|
|
});
|
|||
|
|
element.appendTo(this.tabs);
|
|||
|
|
};
|
|||
|
|
|
|||
|
|
// ȡ<><C8A1>HTML
|
|||
|
|
AbstractTab.getTabHtml = function( o ){
|
|||
|
|
var li = "<li lock='" + o.isLock + "' id='" + o.id + "' class='" + o.active + "' title='" + o.title + "'> \n";
|
|||
|
|
li += "<a href=\"#\" class='li " + o.lock + "'> \n";
|
|||
|
|
li += "<span class=\"text\"><span>" + o.name + "</span></span> \n";
|
|||
|
|
li += "<a href='javascript:void(0)' class='closeTab'></a>\n";
|
|||
|
|
li += "</li> \n";
|
|||
|
|
return li;
|
|||
|
|
};
|
|||
|
|
|
|||
|
|
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ǩ
|
|||
|
|
AbstractTab.click = function( id ){
|
|||
|
|
this.tabs.find("li").removeClass(this.activeClass);
|
|||
|
|
jQuery("#" + id).addClass(this.activeClass);
|
|||
|
|
this.loadFrame(id);
|
|||
|
|
jQuery("#lockids").val(id);//<2F><>ǰID
|
|||
|
|
};
|
|||
|
|
|
|||
|
|
// <20>жϱ<D0B6>ǩ<EFBFBD>Ƿ<EFBFBD><C7B7><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
AbstractTab.isExist = function( id ){
|
|||
|
|
return jQuery("#" + id).size() > 0;
|
|||
|
|
};
|
|||
|
|
// ȡ<>ü<EFBFBD><C3BC>̵<EFBFBD><CCB5><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
AbstractTab.getCutName = function( name ){
|
|||
|
|
var text = new String(name);
|
|||
|
|
//if(text.length > 5){
|
|||
|
|
// return text.substring(0,5) + ".";
|
|||
|
|
//}
|
|||
|
|
return text;
|
|||
|
|
};
|
|||
|
|
// <20><><EFBFBD><EFBFBD>Frame
|
|||
|
|
AbstractTab.addFrame = function( option ){
|
|||
|
|
var url = option.url;
|
|||
|
|
var id = this.getFrameID(option.id);
|
|||
|
|
var frame = option.frame || {};
|
|||
|
|
var style = frame.style || "width:100%;height:100%";
|
|||
|
|
var name = frame.name || id;
|
|||
|
|
var frame = "<iframe id='" + id + "' name='" + name + "' frameborder='0' style='" + style + "' src='" + url + "'></iframe>";
|
|||
|
|
jQuery(frame).appendTo(this.frames);
|
|||
|
|
this.loadFrame(option.id);
|
|||
|
|
};
|
|||
|
|
|
|||
|
|
// <20><><EFBFBD><EFBFBD>Tab<61><62>Ӧ<EFBFBD><D3A6>Frame
|
|||
|
|
AbstractTab.loadFrame = function( id ){
|
|||
|
|
var id = this.getFrameID(id);
|
|||
|
|
this.frames.find("iframe").hide();
|
|||
|
|
jQuery("#" + id ).show();
|
|||
|
|
};
|
|||
|
|
|
|||
|
|
// ȡ<><C8A1>FrameID
|
|||
|
|
AbstractTab.getFrameID = function( id ){
|
|||
|
|
return "Frame" + id;
|
|||
|
|
};
|
|||
|
|
|
|||
|
|
// <20>ر<EFBFBD>Tab
|
|||
|
|
AbstractTab.close = function( id ){
|
|||
|
|
var activeClass = this.activeClass;
|
|||
|
|
var tab = jQuery("#" + id);
|
|||
|
|
var lock = tab.attr("lock");
|
|||
|
|
var isActive = tab.hasClass(activeClass);
|
|||
|
|
if( lock != "true" ){
|
|||
|
|
var frame = jQuery("#" + this.getFrameID(id) );
|
|||
|
|
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ǰ<EFBFBD><C7B0>ǩ<EFBFBD>Ǽ<EFBFBD><C7BC><EFBFBD>״̬,Ҫ<><D2AA><EFBFBD><EFBFBD>һ<EFBFBD><D2BB><EFBFBD><EFBFBD>Ҫ<EFBFBD><D2AA><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ǰһ<C7B0><D2BB>
|
|||
|
|
if( isActive ){
|
|||
|
|
if( tab.next().is("li") ){
|
|||
|
|
tab.next().click();
|
|||
|
|
}else if( tab.prev().is("li") ){
|
|||
|
|
tab.prev().click();
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
tab.remove();// ɾ<><C9BE>Tab
|
|||
|
|
frame.remove();// ɾ<><C9BE>IFrame
|
|||
|
|
}
|
|||
|
|
};
|
|||
|
|
|
|||
|
|
// <20>ر<EFBFBD><D8B1><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
AbstractTab.closeAll = function(){
|
|||
|
|
var _this = this;
|
|||
|
|
// ɾ<><C9BE>û<EFBFBD><C3BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ı<EFBFBD>ǩ
|
|||
|
|
this.tabs.find("li[lock!='true']").each( function(){
|
|||
|
|
jQuery(this).remove();
|
|||
|
|
var id = _this.getFrameID(this.id);
|
|||
|
|
jQuery("#" + id).remove();
|
|||
|
|
});
|
|||
|
|
var activeClass = this.activeClass;
|
|||
|
|
// <20><><EFBFBD><EFBFBD>û<EFBFBD>м<EFBFBD><D0BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ı<EFBFBD>ǩ<EFBFBD><C7A9><EFBFBD><EFBFBD>ô<EFBFBD><C3B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><D2BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ı<EFBFBD>ǩ<EFBFBD><C7A9>
|
|||
|
|
if( this.tabs.find("." + activeClass).size() == 0 ){
|
|||
|
|
this.tabs.find("li:last").click();
|
|||
|
|
}
|
|||
|
|
};
|
|||
|
|
|
|||
|
|
// <20><><EFBFBD><EFBFBD>/<2F><><EFBFBD><EFBFBD>
|
|||
|
|
AbstractTab.lock = function( id , lock ){
|
|||
|
|
var lockClass = this.lockClass;
|
|||
|
|
jQuery("#" + id).attr("lock",new String(lock));
|
|||
|
|
var a = jQuery("#" + id ).find("a");
|
|||
|
|
if( lock ){
|
|||
|
|
a.addClass(lockClass);
|
|||
|
|
}else{
|
|||
|
|
a.removeClass(lockClass);
|
|||
|
|
}
|
|||
|
|
};
|
|||
|
|
|
|||
|
|
// <20><><EFBFBD>ơ<EFBFBD><C6A1><EFBFBD><EFBFBD>ƶ<EFBFBD><C6B6><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
AbstractTab.move = function( option ){
|
|||
|
|
if( option.action == "left" ){
|
|||
|
|
this.tabs.find("li:hidden:last").show();
|
|||
|
|
}else if(option.action == "right"){
|
|||
|
|
this.tabs.find("li:visible:first").hide();
|
|||
|
|
}else if(option.action == "reset"){
|
|||
|
|
this.tabs.find("li").show();
|
|||
|
|
}
|
|||
|
|
};
|
|||
|
|
|
|||
|
|
// <20><>ʼ<EFBFBD><CABC>
|
|||
|
|
AbstractTab.init = function(){
|
|||
|
|
var _this = this;
|
|||
|
|
jQuery("#" + this.leftID ).click( function(){
|
|||
|
|
_this.move({action:'left'});
|
|||
|
|
});
|
|||
|
|
jQuery("#" + this.rightID ).click( function(){
|
|||
|
|
_this.move({action:'right'});
|
|||
|
|
});
|
|||
|
|
jQuery("#" + this.resetID ).click( function(){
|
|||
|
|
_this.move({action:'reset'});
|
|||
|
|
});
|
|||
|
|
jQuery("#" + this.closeID ).click( function(){
|
|||
|
|
_this.closeAll();
|
|||
|
|
});
|
|||
|
|
return this;
|
|||
|
|
};
|
|||
|
|
|
|||
|
|
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
window.FantasyTab = function( option ){
|
|||
|
|
var op = option || {}
|
|||
|
|
this.tabID = op.tabID || "Tabs";
|
|||
|
|
this.frameID = op.frameID || "Frames";
|
|||
|
|
this.activeClass = op.activeClass || "on";
|
|||
|
|
this.lockClass = op.lockClass || "locked";
|
|||
|
|
this.leftID = op.leftID || "Left";
|
|||
|
|
this.rightID = op.rightID || "Right";
|
|||
|
|
this.resetID = op.resetID || "Reset";
|
|||
|
|
this.closeID = op.closeID || "Close";
|
|||
|
|
this.tabs = jQuery("#" + this.tabID);
|
|||
|
|
this.frames = jQuery("#" + this.frameID);
|
|||
|
|
};
|
|||
|
|
// <20>̳<EFBFBD> AbstractTab;
|
|||
|
|
jQuery.extend(FantasyTab.prototype,AbstractTab);
|
|||
|
|
|
|||
|
|
//<2F><>˵<EFBFBD>еľ<D0B5>̬<EFBFBD><CCAC><EFBFBD><EFBFBD>.......
|
|||
|
|
window.FantasyTab.create = function( option ){
|
|||
|
|
var tab = new FantasyTab(option);
|
|||
|
|
return tab.init();
|
|||
|
|
};
|