|
1 | 1 | var angularPeity = angular.module( 'angular-peity', [] ); |
2 | 2 |
|
3 | 3 |
|
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 | + }; |
47 | 54 | }; |
48 | 55 |
|
49 | 56 |
|
|
0 commit comments