Skip to content

Commit 15d8547

Browse files
author
Brian Hines
committed
Merge pull request #4 from devginie/patch-1
Update angular-peity.js
2 parents 9c8a515 + 9277d78 commit 15d8547

1 file changed

Lines changed: 50 additions & 43 deletions

File tree

angular-peity.js

Lines changed: 50 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,49 +1,56 @@
11
var angularPeity = angular.module( 'angular-peity', [] );
22

33

4-
var buildChartDirective = function ( chartType ) {
5-
return {
6-
restrict: 'E',
7-
scope: {
8-
data: "=",
9-
options: "="
10-
},
11-
link: function ( scope, element, attrs ) {
12-
13-
var options = {};
14-
if ( scope.options ) {
15-
options = scope.options;
16-
}
17-
18-
var span = document.createElement( 'span' );
19-
span.textContent = scope.data.join();
20-
21-
if ( !attrs.class ) {
22-
span.className = "";
23-
} else {
24-
span.className = attrs.class;
25-
}
26-
27-
if (element[0].nodeType === 8) {
28-
element.replaceWith( span );
29-
} else {
30-
element[0].appendChild( span );
31-
}
32-
33-
jQuery( span ).peity( chartType, options );
34-
35-
var watcher = scope.$watch('data', function(){
36-
span.textContent = scope.data.join();
37-
jQuery( span ).change();
38-
})
39-
40-
scope.$on('$destroy', function(){
41-
watcher();
42-
});
43-
44-
45-
}
46-
};
4+
var buildChartDirective = function(chartType) {
5+
'use strict';
6+
7+
return {
8+
restrict: 'E',
9+
scope: {
10+
data: "=",
11+
options: "="
12+
},
13+
link: function(scope, element, attrs) {
14+
15+
var options = {};
16+
17+
if (scope.options) {
18+
options = scope.options;
19+
}
20+
21+
var span = document.createElement('span');
22+
span.style.display = "none";
23+
span.textContent = scope.data.join();
24+
25+
if (!attrs.class) {
26+
span.className = "";
27+
} else {
28+
span.className = attrs.class;
29+
}
30+
31+
if (element[0].nodeType === 8) {
32+
element.replaceWith(span);
33+
} else {
34+
element[0].appendChild(span);
35+
}
36+
37+
jQuery(span).peity(chartType, options);
38+
39+
var watcher = scope.$watch('data', function(){
40+
span.textContent = scope.data.join();
41+
jQuery( span ).change();
42+
});
43+
44+
scope.$on('$destroy', function(){
45+
watcher();
46+
});
47+
48+
jQuery(window).resize(function() {
49+
jQuery(span).peity(chartType, options);
50+
});
51+
52+
}
53+
};
4754
};
4855

4956

0 commit comments

Comments
 (0)