21
21
controller : function ( $element ) {
22
22
return {
23
23
getHeader : function ( td ) {
24
+ var firstHeader = td . parentElement . querySelector ( "th" ) ;
25
+ if ( firstHeader ) return firstHeader ;
24
26
var headers = getHeaders ( $element [ 0 ] ) ;
25
27
if ( headers . length ) {
26
28
var row = td . parentElement ;
37
39
} ;
38
40
} ,
39
41
compile : function ( element , attrs ) {
40
- function apply ( ) {
41
- var headers = getHeaders ( element [ 0 ] ) ;
42
- if ( headers . length ) {
43
- var rows = element [ 0 ] . querySelectorAll ( "tbody > tr" ) ;
44
- Array . prototype . forEach . call ( rows , function ( row ) {
45
- var headerIndex = 0 ;
46
- Array . prototype . forEach . call ( row . querySelectorAll ( "td" ) , function ( value , index ) {
47
- if ( ! value . getAttributeNode ( "responsive-dynamic" ) ) {
48
- var th = value . parentElement . querySelector ( "th" ) || headers . item ( headerIndex ) ;
49
- updateTitle ( value , th ) ;
50
- }
51
- headerIndex += colspan ( value ) ;
52
- } ) ;
53
- } ) ;
54
- }
55
- }
56
42
attrs . $addClass ( "responsive" ) ;
57
- if ( Array . prototype . some . call ( element . find ( "th" ) , function ( it ) {
58
- return it . getAttributeNode ( "ng-repeat" ) || it . getAttributeNode ( "data-ng-repeat" ) ;
59
- } ) ) {
60
- setTimeout ( function ( ) {
61
- apply ( ) ;
62
- } , 0 ) ;
63
- } else {
64
- apply ( ) ;
43
+ var headers = getHeaders ( element [ 0 ] ) ;
44
+ if ( headers . length ) {
45
+ var rows = element [ 0 ] . querySelectorAll ( "tbody > tr" ) ;
46
+ Array . prototype . forEach . call ( rows , function ( row ) {
47
+ var headerIndex = 0 ;
48
+ Array . prototype . forEach . call ( row . querySelectorAll ( "td" ) , function ( value , index ) {
49
+ var th = value . parentElement . querySelector ( "th" ) || headers . item ( headerIndex ) ;
50
+ updateTitle ( value , th ) ;
51
+ headerIndex += colspan ( value ) ;
52
+ } ) ;
53
+ } ) ;
65
54
}
66
55
}
67
56
} ;
68
57
}
69
58
function wtResponsiveDynamic ( ) {
70
59
return {
71
- restrict : "A " ,
60
+ restrict : "E " ,
72
61
require : "^^wtResponsiveTable" ,
73
62
link : function ( scope , element , attrs , tableCtrl ) {
74
- Array . prototype . forEach . call ( element [ 0 ] . parentElement . querySelectorAll ( "td" ) , function ( td ) {
75
- var th = tableCtrl . getHeader ( td ) ;
76
- updateTitle ( td , th ) ;
77
- } ) ;
63
+ setTimeout ( function ( ) {
64
+ Array . prototype . forEach . call ( element [ 0 ] . parentElement . querySelectorAll ( "td" ) , function ( td ) {
65
+ var th = tableCtrl . getHeader ( td ) ;
66
+ updateTitle ( td , th ) ;
67
+ } ) ;
68
+ } , 0 ) ;
78
69
}
79
70
} ;
80
71
}
81
72
"use strict" ;
82
- angular . module ( "wt.responsive" , [ ] ) . directive ( "wtResponsiveTable" , [ wtResponsiveTable ] ) . directive ( "responsiveDynamic " , [ wtResponsiveDynamic ] ) ;
73
+ angular . module ( "wt.responsive" , [ ] ) . directive ( "wtResponsiveTable" , [ wtResponsiveTable ] ) . directive ( "td " , [ wtResponsiveDynamic ] ) ;
83
74
} ) ( ) ;
0 commit comments