blob: d902b98719f48a90f9039b9dfad1a9522ae8a6cc (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
|
(function(angular) {'use strict';
var vModule = angular.module('vaadin-components', []);
function attrFnc() {
return {
restrict : 'E',
link : function(scope, element, attrs) {
var attrMap = {};
for ( var prop in attrs.$attr) {
var _attr = attrs.$attr[prop];
var _match = element.attr(_attr).match(/\{\{\s*([\.\w]+)\s*\}\}/);
if (_match) {
attrMap[_attr] = _match[1];
}
}
new MutationObserver(function() {
scope.$apply();
}).observe(element[0], {
attributes : true
});
for (var attr in attrMap) {
scope.$watch(function() {return element.attr(attr)}, function(value, oldValue) {
var parent = scope;
var tokens = attrMap[attr].split(/\./);
for (var i = 0; i < tokens.length - 1; i++) {
if (typeof (parent[tokens[i]]) == 'undefined') {
parent[tokens[i]] = {};
}
parent = parent[tokens[i]];
}
parent[tokens[tokens.length - 1]] = value;
});
}
}
};
}
var vaadinComponents = ['vSlider', 'vProgress', 'vGrid'];
angular.forEach(vaadinComponents, function(tag) {
vModule.directive(tag, attrFnc);
});
})(angular);
|