1 | var Dialog = module.exports = function(message, options){
|
2 | this.options = (options || {});
|
3 | this.message = message;
|
4 |
|
5 | this.createElement();
|
6 | };
|
7 |
|
8 | Dialog.prototype.createElement = function(){
|
9 | this.element = document.createElement('div');
|
10 | this.element.className = "leapjs-dialog";
|
11 | this.element.style.position = "fixed";
|
12 | this.element.style.top = '8px';
|
13 | this.element.style.left = 0;
|
14 | this.element.style.right = 0;
|
15 | this.element.style.textAlign = 'center';
|
16 | this.element.style.zIndex = 1000;
|
17 |
|
18 | var dialog = document.createElement('div');
|
19 | this.element.appendChild(dialog);
|
20 | dialog.style.display = "inline-block";
|
21 | dialog.style.margin = "auto";
|
22 | dialog.style.padding = "8px";
|
23 | dialog.style.color = "#222";
|
24 | dialog.style.background = "#eee";
|
25 | dialog.style.borderRadius = "4px";
|
26 | dialog.style.border = "1px solid #999";
|
27 | dialog.style.textAlign = "left";
|
28 | dialog.style.cursor = "pointer";
|
29 | dialog.style.whiteSpace = "nowrap";
|
30 | dialog.style.transition = "box-shadow 1s linear";
|
31 | dialog.innerHTML = this.message;
|
32 |
|
33 |
|
34 | if (this.options.onclick){
|
35 | dialog.addEventListener('click', this.options.onclick);
|
36 | }
|
37 |
|
38 | if (this.options.onmouseover){
|
39 | dialog.addEventListener('mouseover', this.options.onmouseover);
|
40 | }
|
41 |
|
42 | if (this.options.onmouseout){
|
43 | dialog.addEventListener('mouseout', this.options.onmouseout);
|
44 | }
|
45 |
|
46 | if (this.options.onmousemove){
|
47 | dialog.addEventListener('mousemove', this.options.onmousemove);
|
48 | }
|
49 | };
|
50 |
|
51 | Dialog.prototype.show = function(){
|
52 | document.body.appendChild(this.element);
|
53 | return this;
|
54 | };
|
55 |
|
56 | Dialog.prototype.hide = function(){
|
57 | document.body.removeChild(this.element);
|
58 | return this;
|
59 | };
|
60 |
|
61 |
|
62 |
|
63 |
|
64 |
|
65 |
|
66 |
|
67 | Dialog.warnOutOfDate = function(params){
|
68 | params || (params = {});
|
69 |
|
70 | var url = "http://developer.leapmotion.com?";
|
71 |
|
72 | params.returnTo = window.location.href;
|
73 |
|
74 | for (var key in params){
|
75 | url += key + '=' + encodeURIComponent(params[key]) + '&';
|
76 | }
|
77 |
|
78 | var dialog,
|
79 | onclick = function(event){
|
80 |
|
81 | if (event.target.id != 'leapjs-decline-upgrade'){
|
82 |
|
83 | var popup = window.open(url,
|
84 | '_blank',
|
85 | 'height=800,width=1000,location=1,menubar=1,resizable=1,status=1,toolbar=1,scrollbars=1'
|
86 | );
|
87 |
|
88 | if (window.focus) {popup.focus()}
|
89 |
|
90 | }
|
91 |
|
92 | dialog.hide();
|
93 |
|
94 | return true;
|
95 | },
|
96 |
|
97 |
|
98 | message = "This site requires Leap Motion Tracking Beta, now available for developers." +
|
99 | "<button id='leapjs-accept-upgrade' style='color: #444; transition: box-shadow 100ms linear; cursor: pointer; vertical-align: baseline; margin-left: 16px;'>Upgrade</button>" +
|
100 | "<button id='leapjs-decline-upgrade' style='color: #444; transition: box-shadow 100ms linear; cursor: pointer; vertical-align: baseline; margin-left: 8px; '>Not Now</button>";
|
101 |
|
102 | dialog = new Dialog(message, {
|
103 | onclick: onclick,
|
104 | onmousemove: function(e){
|
105 | if (e.target == document.getElementById('leapjs-decline-upgrade')){
|
106 | document.getElementById('leapjs-decline-upgrade').style.color = '#000';
|
107 | document.getElementById('leapjs-decline-upgrade').style.boxShadow = '0px 0px 2px #5daa00';
|
108 |
|
109 | document.getElementById('leapjs-accept-upgrade').style.color = '#444';
|
110 | document.getElementById('leapjs-accept-upgrade').style.boxShadow = 'none';
|
111 | }else{
|
112 | document.getElementById('leapjs-accept-upgrade').style.color = '#000';
|
113 | document.getElementById('leapjs-accept-upgrade').style.boxShadow = '0px 0px 2px #5daa00';
|
114 |
|
115 | document.getElementById('leapjs-decline-upgrade').style.color = '#444';
|
116 | document.getElementById('leapjs-decline-upgrade').style.boxShadow = 'none';
|
117 | }
|
118 | },
|
119 | onmouseout: function(){
|
120 | document.getElementById('leapjs-decline-upgrade').style.color = '#444';
|
121 | document.getElementById('leapjs-decline-upgrade').style.boxShadow = 'none';
|
122 | document.getElementById('leapjs-accept-upgrade').style.color = '#444';
|
123 | document.getElementById('leapjs-accept-upgrade').style.boxShadow = 'none';
|
124 | }
|
125 | }
|
126 | );
|
127 |
|
128 | return dialog.show();
|
129 | };
|
130 |
|
131 |
|
132 |
|
133 | Dialog.hasWarnedBones = false;
|
134 |
|
135 | Dialog.warnBones = function(){
|
136 | if (this.hasWarnedBones) return;
|
137 | this.hasWarnedBones = true;
|
138 |
|
139 | console.warn("Your Leap Service is out of date");
|
140 |
|
141 | if ( !(typeof(process) !== 'undefined' && process.versions && process.versions.node) ){
|
142 | this.warnOutOfDate({reason: 'bones'});
|
143 | }
|
144 |
|
145 | } |
\ | No newline at end of file |