1
1
/**
2
2
* http://git.oschina.net/hbbcs/bootStrap-addTabs
3
3
* Created by joe on 2015-12-19.
4
- * @param {type } options {
5
- * content string||html 直接指定内容
6
- * close bool 是否可以关闭
7
- * monitor 监视的区域
8
- * }
9
- *
10
- * @returns
11
4
*/
12
5
$ . fn . addtabs = function ( options ) {
13
6
var obj = $ ( this ) ;
@@ -19,6 +12,7 @@ $.fn.addtabs = function (options) {
19
12
tab : '.tab-addtabs' ,
20
13
iframeUse : true , //使用iframe还是ajax
21
14
iframeHeight : $ ( window ) . height ( ) - 50 , //固定TAB中IFRAME高度,根据需要自己修改
15
+ iframeForceRefresh : false , //点击后强制刷新对应的iframe
22
16
callback : function ( ) {
23
17
//关闭后回调函数
24
18
}
@@ -35,7 +29,7 @@ $.fn.addtabs = function (options) {
35
29
} ) ;
36
30
}
37
31
$ ( options . monitor ) . on ( 'click' , '[addtabs]' , function ( e ) {
38
- if ( $ ( this ) . attr ( 'url' ) . indexOf ( "javascript" ) !== 0 ) {
32
+ if ( $ ( this ) . attr ( 'url' ) . indexOf ( "javascript: " ) !== 0 ) {
39
33
if ( $ ( this ) . is ( "a" ) ) {
40
34
e . preventDefault ( ) ;
41
35
}
@@ -54,7 +48,7 @@ $.fn.addtabs = function (options) {
54
48
window . history . pushState ( state , title , pushurl ) ;
55
49
}
56
50
$ ( this ) . data ( "pushstate" , null ) ;
57
- _add ( {
51
+ _add . call ( this , {
58
52
id : id ,
59
53
title : $ ( this ) . attr ( 'title' ) ? $ ( this ) . attr ( 'title' ) : $ ( this ) . html ( ) ,
60
54
content : content ,
@@ -118,17 +112,24 @@ $.fn.addtabs = function (options) {
118
112
navobj . append ( title ) ;
119
113
}
120
114
tabobj . append ( content ) ;
115
+ } else {
116
+ //强制刷新iframe
117
+ if ( options . iframeForceRefresh ) {
118
+ $ ( "#" + conid + " iframe" ) . attr ( 'src' , function ( i , val ) {
119
+ return val ;
120
+ } ) ;
121
+ }
121
122
}
122
-
123
+ localStorage . setItem ( "addtabs" , $ ( this ) . prop ( 'outerHTML' ) ) ;
123
124
//激活TAB
124
125
$ ( "#" + tabid ) . addClass ( 'active' ) ;
125
126
$ ( "#" + conid ) . addClass ( "active" ) ;
126
127
_drop ( ) ;
127
128
} ;
128
129
129
130
_close = function ( id ) {
130
- var tabid = 'tab_' + id ;
131
- var conid = 'con_' + id ;
131
+ var tabid = 'tab_' + id ;
132
+ var conid = 'con_' + id ;
132
133
//如果关闭的是当前激活的TAB,激活他的前一个TAB
133
134
if ( obj . find ( "li.active" ) . attr ( 'id' ) == tabid ) {
134
135
if ( $ ( "#" + tabid ) . prev ( ) . not ( ".tabdrop" ) . size ( ) > 0 ) {
0 commit comments