-
Notifications
You must be signed in to change notification settings - Fork 1
/
stage-directive.js
36 lines (33 loc) · 1.1 KB
/
stage-directive.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
35
36
(function() {
'use strict';
angular.module('kinetic', [])
.directive('stage', ['$rootScope',
function stageDirective ($rootScope) {
return {
restrict: 'EA',
scope: {
stageWidth: '=',
stageHeight: '='
},
link: function linkFn (scope, elem, attrs) {
var id = attrs["id"];
if (!id) {
id = Math.random().toString(36).substring(8);
elem.attr('id', id);
}
var stageWidth = scope.stageWidth || 800;
var stageHeight = scope.stageHeight || 600;
var kinetic = {
stage: new Kinetic.Stage({
container: id,
width: stageWidth,
height: stageHeight
})
};
scope.kinetic = kinetic;
// console.log('New Stage Created', kinetic.stage);
$rootScope.$broadcast('KINETIC:READY', kinetic.stage);
}
};
}]);
})();