diff options
Diffstat (limited to 'ng-vaadin.js')
-rw-r--r-- | ng-vaadin.js | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/ng-vaadin.js b/ng-vaadin.js new file mode 100644 index 0000000..07f1664 --- /dev/null +++ b/ng-vaadin.js @@ -0,0 +1,50 @@ +(function(angular) {'use strict'; + + var vModule = angular.module('vaadin-x', []); + + 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 + }); + + scope.$watch(function() { + for ( var attr in attrMap) { + var value = element.attr(attr); + var tokens = attrMap[attr].split(/\./); + var parent = scope; + for (var i = 0; i < tokens.length - 1; i++) { + if (typeof (parent[tokens[i]]) == 'undefined') { + parent[tokens[i]] = {}; + } + parent = parent[tokens[i]]; + } + // console.log(tokens[tokens.length - 1] + " " + value); + parent[tokens[tokens.length - 1]] = value; + } + }); + } + }; + } + + var vaadinComponents = ['vSlider', 'vProgress', 'vGrid']; + + angular.forEach(vaadinComponents, function(tag) { + vModule.directive(tag, attrFnc); + }); + +})(angular);
\ No newline at end of file |