提交 | 用户 | 时间
|
58d006
|
1 |
var closableTab = { |
A |
2 |
//frame加载完成后设置父容器的高度,使iframe页面与父页面无缝对接 |
|
3 |
frameLoad:function (frame){ |
|
4 |
|
|
5 |
var mainheight = $(frame).contents().find('body').height(); |
|
6 |
alert(mainheight); |
|
7 |
$(frame).parent().height(mainheight); |
|
8 |
}, |
|
9 |
|
|
10 |
//添加tab |
|
11 |
addTab:function(tabItem){ //tabItem = {id,name,url,closable} |
|
12 |
|
|
13 |
var id = "tab_seed_" + tabItem.id; |
|
14 |
var container ="tab_container_" + tabItem.id; |
|
15 |
|
|
16 |
$("li[id^=tab_seed_]").removeClass("active"); |
|
17 |
$("div[id^=tab_container_]").removeClass("active"); |
|
18 |
|
|
19 |
if(!$('#'+id)[0]){ |
|
20 |
var li_tab = '<li role="presentation" class="" id="'+id+'"><a href="#'+container + '" tabclose="' + id +'" role="tab" data-toggle="tab" ondblclick="closableTab.closeTab(this)" style="position: relative;padding:2px 20px 2px 15px">'+tabItem.name; |
|
21 |
if(tabItem.closable){ |
|
22 |
li_tab = li_tab + '<i class="ace-icon fa fa-times" tabclose="'+id+'" style="position: absolute;right:2px;top: 9px;" onclick="closableTab.closeTab(this)"></i></a></li> '; |
|
23 |
}else{ |
|
24 |
li_tab = li_tab + '</a></li>'; |
|
25 |
} |
|
26 |
var iframeHeight = $(window).height() - 117; |
|
27 |
var tabpanel = '<div role="tabpanel" class="tab-pane" id="'+container+'" style="width: 100%;">'+ |
|
28 |
'<iframe src="'+tabItem.url+'" id="tab_frame_2" frameborder="0" style="overflow-x: hidden; overflow-y: hidden;width:100%;min-height:' + iframeHeight + 'px" onloads="closableTab.frameLoad(this)"></iframe>'+ |
|
29 |
'</div>'; |
|
30 |
|
|
31 |
|
|
32 |
$('.nav-tabs').append(li_tab); |
|
33 |
$('.tab-content').append(tabpanel); |
|
34 |
} |
|
35 |
$("#"+id).addClass("active"); |
|
36 |
$("#"+container).addClass("active"); |
|
37 |
$("#"+container).find($('iframe')).attr('src', tabItem.url); |
|
38 |
}, |
|
39 |
|
|
40 |
//关闭tab |
|
41 |
closeTab:function(item){ |
|
42 |
var val = $(item).attr('tabclose'); |
|
43 |
var containerId = "tab_container_"+val.substring(9); |
|
44 |
|
|
45 |
if($('#'+containerId).hasClass('active')){ |
|
46 |
$('#'+val).prev().addClass('active'); |
|
47 |
$('#'+containerId).prev().addClass('active'); |
|
48 |
} |
|
49 |
|
|
50 |
|
|
51 |
$("#"+val).remove(); |
|
52 |
$("#"+containerId).remove(); |
|
53 |
} |
|
54 |
} |