-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
140 lines (134 loc) · 4.29 KB
/
main.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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
var app = angular.module('twitterApp', []);
app.controller("AppCtrl", function($scope){
$scope.loadMoreTweets = function(){
alert("Laoding tweets");
};
$scope.deleteTweets = function(){
alert("deleting");
};
$scope.expanders = [
{
title : "Eins",
text: "Hallo eins"
},
{
title : "zwei",
text: "Hallo zwei"
},
{
title : "drei",
text: "Hallo drei"
}];
$scope.format = 'M/d/yy h:mm:ss a';
$scope.choreDone = function(chore){
alert(chore + "ist done!");
console.log(chore + "ist done");
}
}).controller("timeDate", function($scope){
$scope.format = 'M/d/yy h:mm:ss a';
})
.directive("superhero", function(){
return {
restrict : "E",
scope:{},
controller: function ($scope) {
$scope.abilities = [];
this.addStength = function (){
$scope.abilities.push("strength")
};
this.addSpeed = function(){
$scope.abilities.push("speed");
};
this.addFlight = function(){
$scope.abilities.push("flight");
};
},
link : function (scope, element) {
element.bind("mouseenter", function(){
console.log(scope.abilities);
})
}
}})
.directive("speed", function(){
return {
require: "^superhero",
link: function (scope, element, attr, superheroCtrl) {
superheroCtrl.addSpeed();
console.log('added speed');
element.bind("mouseenter", function(){
superheroCtrl.addSpeed();
console.log("now added really");
});
}
}})
.directive("showDetails", function () {
return {
restrict: "EA",
scope: {
title : "@detailsTitle"
},
require: "^accordion",
replace: true,
transclude: true,
template: '<div><div class="title" ng-click="toggle()">{{title}}</div><div class="body" ng-show="shouldShow" ng-transclude></div></div>',
link: function(scope, element, attr, controllers){
scope.shouldShow = false;
controllers.addExpander(scope);
scope.toggle = function() {
scope.shouldShow = !scope.shouldShow;
};
}
}
})
.directive("accordion", function () {
return {
restrict: "EA",
replace: true,
transclude: true,
template: "<div ng-transclude></div>",
controller: function () {
var expanders = [];
console.log("accordion init");
this.gotOpened = function(selectedItem){
angular.forEach(expanders, function(expander){
if (selectedItem = !expander){
expander.shouldShow = false;
}
});
};
this.addExpander = function(expander){
expanders.push(expander);
}
}
}
})
.directive("currentTime", ['$interval', 'dateFilter',function(interval, dateFilter){
return{
link: function(scope, element, attr) {
var format, timeoutId;
console.log("init current time");
function updateTime() {
element.text(dateFilter(new Date(), format));
}
scope.$watch(attr.currentTime, function (value) {
format = value;
updateTime();
});
element.on('$destroy', function () {
$interval.cancel(timeoutId);
});
interval(function () {
updateTime();
}, 1000);
}
}
}])
.directive("kid", function () {
return {
restrict:"E",
scope: {
done : "&"
},
template: '<input type ="text" ng-model="chore"><div>{{chore}} <button ng-click="done({chore:chore})">OK im done</button></div>'
}
});