-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtriggerEventsDirective
More file actions
27 lines (26 loc) · 1.01 KB
/
triggerEventsDirective
File metadata and controls
27 lines (26 loc) · 1.01 KB
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
angular.module('app').directive('triggerEvents', function ($timeout) {
return {
restrict: 'A',
link : function(scope, elem, attrs, ctrl){
var tokens = attrs.triggerEvents.split(',');
console.log(tokens);
for(var i=0; i < tokens.length; i++) {
var token = tokens[i].split(':');
console.log(token[1]);
var element = document.getElementById(token[0]);
console.log(element);
var fn = element[token[1]];
triggerEventWithFunctionNameAsString(element, fn);
}
function triggerEventWithFunctionNameAsString(context, eventName){
$timeout(function(){
if(typeof eventName === "function"){
eventName.call(context);
}else{
console.log('Cannot trigger event ' + eventName + ' on ' + context);
}
},0);
}
}
};
});