bitcoin-atm
bitcoin atm for pyc inc.
git clone https://9o.is/git/bitcoin-atm.git
ngKey.js
(2084B)
1 /**
2 * @overview
3 * @copyright 2013 Tommy Rochette http://trochette.github.com/
4 * @author Tommy Rochette
5 * @version 0.0.1
6 *
7 * @license MIT
8 */
9 (function () {
10 "use strict";
11
12 /**
13 * @Class
14 */
15 window.Key = function ($scope, $element, $attrs) {
16
17 var body = $('body');
18
19 /**
20 * Initialize Key to default settings
21 */
22 function init() {
23 if ("ontouchstart" in document.documentElement) {
24 $element.bind('touchstart.ngKey', keyPressed);
25 body.bind('touchend.ngKey', keyDepressed);
26 } else {
27 $element.bind('mousedown.ngKey', keyPressed);
28 body.bind('mouseup.ngKey', keyDepressed);
29 }
30
31 $scope.$on('destroy', destroy);
32 };
33
34
35 /**
36 * Triggered when a user press on this element
37 *
38 * @param event
39 */
40 function keyPressed(event) {
41 $element.addClass('pressed');
42 event.preventDefault();
43 event.stopImmediatePropagation();
44 $scope.$emit(Key.PRESSED, $attrs.ngKey);
45 }
46
47
48 /**
49 * Triggered when a user stop pressing this element
50 *
51 * @param event
52 */
53 function keyDepressed(event) {
54 $element.removeClass('pressed');
55 }
56
57 /**
58 * Cleanup all listeners before destroying this directive.
59 */
60 function destroy() {
61 $element.bind('touchstart.ngKey', keyPressed);
62 bodybind('touchend.ngKey', keyDepressed);
63 $element.bind('mousedown.ngKey', keyPressed);
64 body.bind('mouseup.ngKey', keyDepressed);
65 }
66
67
68 init();
69 };
70
71 /**
72 * @Event
73 */
74 Key.PRESSED = "Key.PRESSED";
75
76 angular.module('ngKeypad', [])
77 .directive('ngKey', function () {
78 return {
79 restrict: 'A',
80 link: function ($scope, $element, $attrs) {
81 new Key($scope, $element, $attrs);
82 }
83 };
84 });
85 })();