-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathfamous-object.js
34 lines (30 loc) · 965 Bytes
/
famous-object.js
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
angular.module('famous.angular')
.directive('faObject', ['$famous', '$famousDecorator', 'faObject', function ($famous, $famousDecorator, faObject) {
return {
compile: function() {
var Engine = $famous['famous/core/Engine'];
return {
post: function(scope, element, attrs) {
var isolate = $famousDecorator.ensureIsolate(scope);
faObject(attrs.faObject,isolate.renderNode);
}
};
}
};
}]).
factory('faObject', function($rootScope) {
var faObjects = {};
return function(name,objectOrMethod) {
var type = (typeof objectOrMethod === "function") ? "function" :
(typeof objectOrMethod === "object") ? "object" : false;
if(type === "function") {
$rootScope.$watch(function(){
return faObjects;
},function(faObjects){
objectOrMethod(faObjects[name]);
});
} else if(type === "object") {
faObjects[name] = objectOrMethod;
}
};
});