-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
66 lines (62 loc) · 2.05 KB
/
index.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
var angular = require('angularjs')
, query = require('query')
, tip = require('tip')
, template = require('./template');
var t = new tip('Name');
angular.module('boxes', [])
.directive('boxes', ['$compile',
function ($compile) {
return {
scope: {},
replace: true,
restrict: 'A',
link: function (scope, element, attrs) {
var name = attrs.boxes
, clickName;
scope.boxes = null;
scope.undoneTodos = function () {
var undone = 0;
for (var i=0; i<scope.boxes.todos.length; i++) {
if (!scope.boxes.todos[i].completed) {
undone += 1;
}
}
return undone;
};
if (attrs.clickBox) {
clickName = attrs.clickBox;
scope.$parent.$watch(clickName, function (value) {
scope.clickBox = value;
});
scope.$watch('clickBox', function (value) {
scope.$parent[clickName] = value;
});
}
scope.$parent.$watch(name, function(value) {
if (!scope.boxes && value) {
element.addClass('boxes');
element.html(template);
$compile(element.contents())(scope);
var box = element[0].querySelector('.box');
box.parentNode.addEventListener('mouseover', function () {
t.message(value.display.name);
t.show(box);
t.el.addClass('tip-nomouse');
});
box.parentNode.addEventListener('mouseout', function () {
t.hide();
});
box.addEventListener('click', function () {
if (!scope.clickBox) return;
scope.clickBox(scope.boxes, box);
});
}
scope.boxes = value;
});
scope.$watch('boxes', function(value) {
scope.$parent[name] = value;
});
// should take care of itself from here
}
};
}]);