openTab: function(tabid, url, options){ //if found tabid replace tab, else create a new tab.
var op = $.extend({title:"New Tab", data:{}, fresh:true, external:false}, options);
//这里判定如果未加载该 navtab 并且超出最大允许的navtab数量
if( navTab._getTabs().length > 4 )
{
//如果未加载过,或者已在main里面显示的
if( navTab._indexTabId(tabid) < 0 )
{
navTab._getTabs().eq(0).attr('true_tabid',tabid);
tabid = 'main';
}
}
else
{
var real_tabid = navTab._getTabs().eq(0).attr('true_tabid');
if( real_tabid && real_tabid == tabid )
{
tabid = 'main';
}
}
var iOpenIndex = this._indexTabId(tabid);
if (iOpenIndex >= 0){
var $tab = this._getTabs().eq(iOpenIndex);
var span$ = $tab.attr("tabid") == this._op.mainTabId ? "> span > span" : "> span";
$tab.find(">a").attr("title", op.title).find(span$).text(op.title);
var $panel = this._getPanels().eq(iOpenIndex);
if(op.fresh || $tab.attr("url") != url) {
$tab.attr("url", url);
if (op.external || url.isExternalUrl()) {
$tab.addClass("external");
navTab.openExternal(url, $panel);
} else {
$tab.removeClass("external");
$panel.ajaxUrl({
type:"GET", url:url, data:op.data, callback:function(){
navTab._loadUrlCallback($panel);
}
});
}
}
this._currentIndex = iOpenIndex;
} else {
var tabFrag = '<li tabid="#tabid#"><a xhref="javascript:" title="#title#" class="#tabid#"><span>#title#</span></a><a xhref="javascript:;" class="close">close</a></li>';
this._tabBox.append(tabFrag.replaceAll("#tabid#", tabid).replaceAll("#title#", op.title));
this._panelBox.append('<div class="page unitBox"></div>');
this._moreBox.append('<li><a xhref="javascript:" title="#title#">#title#</a></li>'.replaceAll("#title#", op.title));
var $tabs = this._getTabs();
var $tab = $tabs.filter(":last");
var $panel = this._getPanels().filter(":last");
if (op.external || url.isExternalUrl()) {
$tab.addClass("external");
navTab.openExternal(url, $panel);
} else {
$tab.removeClass("external");
$panel.ajaxUrl({
type:"GET", url:url, data:op.data, callback:function(){
navTab._loadUrlCallback($panel);
}
});
}
if ($.History) {
setTimeout(function(){
$.History.addHistory(tabid, function(tabid){
var i = navTab._indexTabId(tabid);
if (i >= 0) navTab._switchTab(i);
}, tabid);
}, 10);
}
this._currentIndex = $tabs.size() - 1;
this._contextmenu($tabs.filter(":last").hoverClass("hover"));
}
this._init();
this._scrollCurrent();
this._getTabs().eq(this._currentIndex).attr("url", url);
}
|