-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdirectives.js
27 lines (26 loc) · 950 Bytes
/
directives.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
'use strict';
angular.module('myApp').directive('pebbleView', function(pebbleService) {
return {
restrict: 'A',
scope: true,
template: '<div><div class="header" ng-bind="view.header"></div><div class="body" ng-bind="view.body"></div></div>',
link: function(scope, iElem, iAttrs) {
scope.view = pebbleService.views[iAttrs.pebbleView];
}
};
}).directive('pebbleButton', function($rootScope, pebbleService) {
return {
restrict: 'A',
link: function(scope, iElem, iAttrs) {
var tDown = 0,
tLongMin = 500;
iElem.on('mousedown', function(event) {
tDown = now();
});
iElem.on('mouseup', function(event) {
var evName = (now() - tDown > tLongMin) ? 'longClick' : 'click';
$rootScope.$broadcast(evName + '.' + iAttrs.pebbleButton);
});
}
};
});