blinker / firefox.plugin / data / scripts / functions.js @ master
History | View | Annotate | Download (48.864 KB)
1 |
/*
|
---|---|
2 |
* Copyright 2015 Thies Pfeiffer and Dimitri Heil and Kevin Taron
|
3 |
* Blinker is distributed under the terms of the GNU General Public License
|
4 |
*
|
5 |
* This file is part of Blinker.
|
6 |
*
|
7 |
* Blinker is free software: you can redistribute it and/or modify
|
8 |
* it under the terms of the GNU General Public License as published by
|
9 |
* the Free Software Foundation, either version 3 of the License, or
|
10 |
* (at your option) any later version.
|
11 |
*
|
12 |
* Blinker is distributed in the hope that it will be useful,
|
13 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
14 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
15 |
* GNU General Public License for more details.
|
16 |
*
|
17 |
* You should have received a copy of the GNU General Public License
|
18 |
* along with Blinker. If not, see <http://www.gnu.org/licenses/>.
|
19 |
*/
|
20 |
|
21 |
var gazeFunctions = {
|
22 |
/*
|
23 |
* open a given url in a given target (_self / _blank)
|
24 |
*/
|
25 |
openURL: function(url, target) { |
26 |
//console.log("functions.js :: " + "gazeFunctions.openURL()" + ", url: " + url + ", target: " + target);
|
27 |
$("#wheelSelector").css("display", "none"); |
28 |
edgeFunctions.clearDivs(); |
29 |
$("#wheelSelector").empty(); |
30 |
wheelSelectorShowing = false;
|
31 |
window.open(url, target); |
32 |
}, |
33 |
/*
|
34 |
* Positions the gazeLinkOption-fields according to the number of gazeConfirmations-fileds and the gazeLinks-Div position
|
35 |
*
|
36 |
* @gazeLinkNumber: the number of the gazeLink the gazeLinkOptions should be appended to
|
37 |
*/
|
38 |
showGazeLinkOptions: function(gazeLinkNumber) { |
39 |
return;
|
40 |
//console.log("functions.js :: " + "gazeFunctions.showGazeLinkOptions()" + ", gazeLinkNumber: " + gazeLinkNumber);
|
41 |
gazeFunctions.hideGazeLinkOptions(); |
42 |
//console.log("gazeLinkNumber: "+ gazeLinkNumber);
|
43 |
|
44 |
var selectedDivOffset = $("#gazeLinkNum_" + gazeLinkNumber).offset(); |
45 |
//console.log("selectedDivOffset X: "+selectedDivOffset.left);
|
46 |
//console.log("selectedDivOffset Y: "+selectedDivOffset.top);
|
47 |
|
48 |
if (blickBrowserSettings.gazeConfirmationSteps === 0) { |
49 |
$("#leftGazeOption_" + gazeLinkNumber).css("left", (gazeInformation.gazeLinksPosition.x - $("#leftGazeOption_" + gazeLinkNumber).width() - window.scrollX) - 1 + "px"); |
50 |
$("#leftGazeOption_" + gazeLinkNumber).css("top", (gazeInformation.gazeLinksPosition.y + selectedDivOffset.top - $("#gazeLinks").offset().top) + "px"); |
51 |
$("#leftGazeOption_" + gazeLinkNumber).css("height", blickBrowserSettings.gazeConfirmationSize+"px"); |
52 |
$("#leftGazeOption_" + gazeLinkNumber).css("width", blickBrowserSettings.gazeConfirmationSize+"px"); |
53 |
|
54 |
|
55 |
|
56 |
|
57 |
$("#rightGazeOption_" + gazeLinkNumber).css("left", (gazeInformation.gazeLinksPosition.x + $("#gazeLinks").width() - window.scrollX) - 1 + "px"); |
58 |
$("#rightGazeOption_" + gazeLinkNumber).css("top", (gazeInformation.gazeLinksPosition.y + selectedDivOffset.top - $("#gazeLinks").offset().top) + "px"); |
59 |
$("#rightGazeOption_" + gazeLinkNumber).css("height", blickBrowserSettings.gazeConfirmationSize+"px"); |
60 |
$("#rightGazeOption_" + gazeLinkNumber).css("width", blickBrowserSettings.gazeConfirmationSize+"px"); |
61 |
|
62 |
|
63 |
$('.gazeLinkOption').stop(); |
64 |
$("#leftGazeOption_" + gazeLinkNumber).fadeIn(); |
65 |
$("#rightGazeOption_" + gazeLinkNumber).fadeIn(); |
66 |
//gazeInformation.gazeLinks[gazeLinkNumber]
|
67 |
} else {
|
68 |
//console.log("GAZEPOS X: "+gazeInformation.gazeLinksPosition.x);
|
69 |
$("#leftGazeConfirmation_" + gazeLinkNumber + "_0").css("left", (gazeInformation.gazeLinksPosition.x - $("#leftGazeOption_" + gazeLinkNumber).width() - window.scrollX) - 1 + "px"); |
70 |
$("#leftGazeConfirmation_" + gazeLinkNumber + "_0").css("top", (gazeInformation.gazeLinksPosition.y + selectedDivOffset.top - $("#gazeLinks").offset().top) + "px"); |
71 |
$("#leftGazeConfirmation_" + gazeLinkNumber + "_0").css("height", blickBrowserSettings.gazeConfirmationSize+"px"); |
72 |
$("#leftGazeConfirmation_" + gazeLinkNumber + "_0").css("width", blickBrowserSettings.gazeConfirmationSize+"px"); |
73 |
|
74 |
|
75 |
$("#rightGazeConfirmation_" + gazeLinkNumber + "_0").css("left", (gazeInformation.gazeLinksPosition.x + $("#gazeLinks").width() - window.scrollX) - 1 + "px"); |
76 |
$("#rightGazeConfirmation_" + gazeLinkNumber + "_0").css("top", (gazeInformation.gazeLinksPosition.y + selectedDivOffset.top - $("#gazeLinks").offset().top) + "px"); |
77 |
$("#rightGazeConfirmation_" + gazeLinkNumber + "_0").css("height", blickBrowserSettings.gazeConfirmationSize+"px"); |
78 |
$("#rightGazeConfirmation_" + gazeLinkNumber + "_0").css("width", blickBrowserSettings.gazeConfirmationSize+"px"); |
79 |
|
80 |
|
81 |
$('.gazeLinkOption').stop(); |
82 |
$("#leftGazeConfirmation_" + gazeLinkNumber + "_0").fadeIn(); |
83 |
$("#rightGazeConfirmation_" + gazeLinkNumber + "_0").fadeIn(); |
84 |
} |
85 |
|
86 |
}, |
87 |
/*
|
88 |
* Hide all gazeLinkOption-fields
|
89 |
*/
|
90 |
hideGazeLinkOptions: function() { |
91 |
//console.log("functions.js :: " + "gazeFunctions.hideGazeLinkOptions()");
|
92 |
|
93 |
$(".gazeLinkOption").css("display", "none"); |
94 |
|
95 |
}, |
96 |
/*
|
97 |
* Check for links at the current gazePosition
|
98 |
*/
|
99 |
checkForLinks: function() { |
100 |
return false; |
101 |
/*if (!blickBrowserSettings.autoReadingMode) {*/
|
102 |
if (!blickBrowserSettings.explicitMode) {
|
103 |
if (!gazeCorrectionMode) {
|
104 |
//console.log("functions.js :: "+"gazeFunctions.checkForLinks()" );
|
105 |
if ($("#noFocusHider").css("display") == "none") { |
106 |
//console.log("functions.js :: "+"gazeFunctions.checkForLinks()"+" :: #noFocusHider is not displayed" );
|
107 |
if (!linkCheckRunning) {
|
108 |
//console.log("functions.js :: "+"gazeFunctions.checkForLinks()"+" :: linkCheckRunning is false" );
|
109 |
if (!controlBarShowing) {
|
110 |
//console.log("functions.js :: "+"gazeFunctions.checkForLinks()"+" :: controlBarShowing is false" );
|
111 |
if (!wheelSelectorShowing) {
|
112 |
//console.log("functions.js :: "+"gazeFunctions.checkForLinks()"+" :: wheelSelectorShowing is false" );
|
113 |
if (!gazeLinksShowing) {
|
114 |
//console.log("functions.js :: "+"gazeFunctions.checkForLinks()"+" :: gazeLinksShowing is false" );
|
115 |
|
116 |
//console.log("Check for links initiated");
|
117 |
|
118 |
$("#gazeLinks").css("display", "none"); |
119 |
$("#closeGazeLinks").css("display", "none"); |
120 |
$("#itemSelector").css("display", "none"); |
121 |
$("#gazeLinks").empty(); |
122 |
|
123 |
|
124 |
//getLinksFromElementBelow
|
125 |
if (blickBrowserSettings.getLinksFromElementBelow === true) { |
126 |
linkCheckRunning = true;
|
127 |
findLinksInElementBelow(); |
128 |
linkCheckRunning = false;
|
129 |
|
130 |
|
131 |
} |
132 |
|
133 |
//getLinksFromArea
|
134 |
if (blickBrowserSettings.getLinksFromArea === true) { |
135 |
linkCheckRunning = true;
|
136 |
findLinksInAreaFast(); |
137 |
linkCheckRunning = false;
|
138 |
} |
139 |
|
140 |
|
141 |
|
142 |
|
143 |
} else {
|
144 |
//console.log("functions.js :: " + "gazeFunctions.checkForLinks()" + " :: gazeLinksShowing: " + gazeLinksShowing);
|
145 |
} |
146 |
} else {
|
147 |
//console.log("functions.js :: " + "gazeFunctions.checkForLinks()" + " :: wheelSelectorShowing: " + wheelSelectorShowing);
|
148 |
} |
149 |
} else {
|
150 |
//console.log("functions.js :: " + "gazeFunctions.checkForLinks()" + " :: linkCheckRunning: " + linkCheckRunning);
|
151 |
} |
152 |
} else {
|
153 |
//console.log("functions.js :: " + "gazeFunctions.checkForLinks()" + " :: gazeCorrectionMode: " + gazeCorrectionMode);
|
154 |
} |
155 |
} |
156 |
} else {
|
157 |
//console.log("functions.js :: " + "gazeFunctions.checkForLinks()" + " :: #noFocusHider: " + $("#noFocusHider").css("display"));
|
158 |
} |
159 |
} else {
|
160 |
//console.log("functions.js :: " + "gazeFunctions.checkForLinks()" + " :: explicitMode: " + blickBrowserSettings.explicitMode);
|
161 |
/*}
|
162 |
} else {*/
|
163 |
//console.log("functions.js :: " + "gazeFunctions.checkForLinks()" + " :: autoReadingMode: " + blickBrowserSettings.autoReadingMode);
|
164 |
} |
165 |
}, |
166 |
|
167 |
/*
|
168 |
* Show gazeConfirmations according to it's id and the selected gazeLink and gazeLink-Div position
|
169 |
*
|
170 |
* @id: the id of the gazeOption or gazeConfirmation that should be positioned
|
171 |
*/
|
172 |
showConfirmationDiv: function(id) { |
173 |
console.log("functions.js :: " + "gazeFunctionss.showConfirmationDiv() ID:" + id); |
174 |
var selectedDivOffset;
|
175 |
var split;
|
176 |
/*
|
177 |
* if it is a gazeOption
|
178 |
*/
|
179 |
if (id.toLowerCase().indexOf("option") > -1) { |
180 |
split = id.split("_");
|
181 |
selectedDivOffset = $("#gazeLinkNum_" + parseInt(split[1])).offset(); |
182 |
|
183 |
if (id.indexOf("left") > -1) { |
184 |
|
185 |
$("#" + id).css("left", (gazeInformation.gazeLinksPosition.x - window.scrollX - ((blickBrowserSettings.gazeConfirmationSteps + 1) * blickBrowserSettings.gazeConfirmationSize)) - 2 + "px"); |
186 |
|
187 |
} else if (id.indexOf("right") > -1) { |
188 |
|
189 |
$("#" + id).css("left", (gazeInformation.gazeLinksPosition.x + $("#gazeLinks").width() - window.scrollX + (blickBrowserSettings.gazeConfirmationSteps * blickBrowserSettings.gazeConfirmationSize)) - 2 + "px"); |
190 |
} |
191 |
|
192 |
|
193 |
/*
|
194 |
* if it is a gazeConfirmation
|
195 |
*/
|
196 |
} else {
|
197 |
split = id.split("_");
|
198 |
selectedDivOffset = $("#gazeLinkNum_" + parseInt(split[1])).offset(); |
199 |
|
200 |
if (split[0].indexOf("left") > -1) { |
201 |
$("#" + id).css("left", (gazeInformation.gazeLinksPosition.x - window.scrollX - ((parseInt(split[2]) + 1) * blickBrowserSettings.gazeConfirmationSize)) - 2 + "px"); |
202 |
} else if (split[0].indexOf("right") > -1) { |
203 |
$("#" + id).css("left", (gazeInformation.gazeLinksPosition.x + $("#gazeLinks").width() - window.scrollX + (parseInt(split[2]) * blickBrowserSettings.gazeConfirmationSize)) - 2 + "px"); |
204 |
|
205 |
|
206 |
} |
207 |
|
208 |
} |
209 |
//set the size according to the value in settings (gazeConfirmationSize)
|
210 |
$("#" + id).width(blickBrowserSettings.gazeConfirmationSize); |
211 |
$("#" + id).height(blickBrowserSettings.gazeConfirmationSize); |
212 |
|
213 |
$("#" + id).css("top", (selectedDivOffset.top) + "px"); |
214 |
$("#" + id).css("display", "block"); |
215 |
|
216 |
|
217 |
}, |
218 |
|
219 |
/*
|
220 |
* Show wheelSelector for gazeLink with a certain gazeLinkNumber (position in gazeLink array)
|
221 |
*/
|
222 |
showWheelSelector: function(gazeLinkNumber) { |
223 |
//console.log("functions.js :: " + "gazeFunctions.showWheelSelector()" + " gazeLinkNumber: " + gazeLinkNumber);
|
224 |
//console.log("gazeLinksCount: "+gazeInformation.gazeLinks.length);
|
225 |
if (!controlBarShowing) {
|
226 |
if (!wheelSelectorShowing) {
|
227 |
gazeInformation.currentElementFixatedAt = Date.now(); |
228 |
|
229 |
//let top = $( "#wheelSelector" ).css("top")+window.scrollY;
|
230 |
$("#wheelSelector").css("top", window.scrollY + (window.innerHeight * 0.1) + "px"); |
231 |
|
232 |
$("#wheelSelector").fadeIn(); |
233 |
wheelSelectorShowing = true;
|
234 |
|
235 |
/*
|
236 |
* APPEND MORE ELEMENTS INSIDE OF THE WHEELSELECTOR HERE [START]
|
237 |
*/
|
238 |
|
239 |
var dataGazeString = ''; |
240 |
dataGazeString = "{\"isFixated\":{\"funcType\":\"dynamic\",\"func\":\"edgeFunctions.clearDivs();gazeFunctions[\\\"openURL\\\"](\\\"" + gazeInformation.gazeLinks[gazeLinkNumber].url + "\\\",\\\"_self\\\")\"}}"; |
241 |
$("#wheelSelector").append("<div id='wheelSelectorOpenHere' data-gaze='" + dataGazeString + "' class='wheelSelector' target='_self'></div"); |
242 |
$("#wheelSelectorOpenHere").append("<i data-gaze='" + dataGazeString + "' class='wheelSelectorIcon fa fa-folder-open-o'></i><p class=\"subtitle\">Open</p>"); |
243 |
|
244 |
|
245 |
dataGazeString = "{\"isFixated\":{\"funcType\":\"dynamic\",\"func\":\"edgeFunctions.clearDivs();gazeFunctions[\\\"openURL\\\"](\\\"" + gazeInformation.gazeLinks[gazeLinkNumber].url + "\\\",\\\"_blank\\\")\"}}"; |
246 |
$("#wheelSelector").append("<div id='wheelSelectorOpenNew' data-gaze='" + dataGazeString + "' class='wheelSelector' target='_blank'></div>"); |
247 |
$("#wheelSelectorOpenNew").append("<i data-gaze='" + dataGazeString + "' class='wheelSelectorIcon fa fa-external-link'></i><p class=\"subtitle\">Open in new Tab</p></div>"); |
248 |
|
249 |
dataGazeString = "{\"isFixated\":{\"funcType\":\"dynamic\",\"func\":\"edgeFunctions.clearDivs();blickBrowserSettings.bookmarks += \\\"" + gazeInformation.gazeLinks[gazeLinkNumber].name+"|"+gazeInformation.gazeLinks[gazeLinkNumber].url + ";\\\"; writeSettings();\"}}"; |
250 |
$("#wheelSelector").append("<div id='wheelSelectorAddBookmark' data-gaze='" + dataGazeString + "' class='wheelSelector'></div"); |
251 |
$("#wheelSelectorAddBookmark").append("<i data-gaze='" + dataGazeString + "' class='wheelSelectorIcon fa fa-star'></i><p class=\"subtitle\">Bookmark</p>"); |
252 |
|
253 |
|
254 |
/*
|
255 |
* APPEND MORE ELEMENTS INSIDE OF THE WHEELSELECTOR HERE [END]
|
256 |
*/
|
257 |
|
258 |
|
259 |
//arrange the wheelelements in a circle
|
260 |
arrangeWheelElements(); |
261 |
|
262 |
$("#wheelSelector").append("<div class='wheelSelector gazeLinkName'><br />" + (shortenString(gazeInformation.gazeLinks[gazeLinkNumber].name, 25) || shortenString(gazeInformation.gazeLinks[gazeLinkNumber].url, 25)) + "</div>"); |
263 |
|
264 |
} else {
|
265 |
$("#wheelSelector").css("display", "none"); |
266 |
$("#wheelSelector").empty(); |
267 |
wheelSelectorShowing = false;
|
268 |
gazeFunctions.showWheelSelector(); |
269 |
} |
270 |
} |
271 |
} |
272 |
}; |
273 |
|
274 |
/*
|
275 |
* Find links in area and only the 4 surrounding districts around the current gazePosition and put the found links into the gazeLink array
|
276 |
*/
|
277 |
function findLinksInAreaFast() { |
278 |
return false; |
279 |
//console.log("functions.js :: " + "findLinksInAreaFast()");
|
280 |
var fieldX = Math.floor(gazeInformation.x / fieldWidth);
|
281 |
//console.log("2_FieldX: " + fieldX);
|
282 |
var fieldY = Math.floor(gazeInformation.y / fieldHeight);
|
283 |
//console.log("2_FieldY: " + fieldY);
|
284 |
|
285 |
//TODO PARSE FIELDTOCHECK
|
286 |
|
287 |
var xRest = gazeInformation.x % fieldWidth;
|
288 |
var yRest = gazeInformation.y % fieldHeight;
|
289 |
|
290 |
var positionX;
|
291 |
var positionY;
|
292 |
if (xRest >= (fieldWidth / 2)) { |
293 |
positionX = "right";
|
294 |
} else {
|
295 |
positionX = "left";
|
296 |
} |
297 |
|
298 |
if (yRest >= (fieldHeight / 2)) { |
299 |
positionY = "bottom";
|
300 |
} else {
|
301 |
positionY = "top";
|
302 |
} |
303 |
|
304 |
gazeInformation.gazeLinks = []; |
305 |
if (fieldX >= 0 && fieldY >= 0) { |
306 |
if (positionY == "top" && positionX == "left") { |
307 |
|
308 |
if (checkField(fields[fieldX]) && checkField(fields[fieldX][fieldY])) {
|
309 |
parseField(fields[fieldX][fieldY]); |
310 |
} |
311 |
if (checkField(fields[fieldX - 1]) && checkField(fields[fieldX - 1][fieldY - 1])) { |
312 |
parseField(fields[fieldX - 1][fieldY - 1]); |
313 |
} |
314 |
|
315 |
if (checkField(fields[fieldX]) && checkField(fields[fieldX][fieldY - 1])) { |
316 |
parseField(fields[fieldX][fieldY - 1]);
|
317 |
} |
318 |
|
319 |
if (checkField(fields[fieldX - 1]) && checkField(fields[fieldX - 1][fieldY])) { |
320 |
parseField(fields[fieldX - 1][fieldY]);
|
321 |
} |
322 |
|
323 |
} else if (positionY == "top" && positionX == "right") { |
324 |
if (checkField(fields[fieldX]) && checkField(fields[fieldX][fieldY])) {
|
325 |
parseField(fields[fieldX][fieldY]); |
326 |
} |
327 |
|
328 |
if (checkField(fields[fieldX + 1]) && checkField(fields[fieldX + 1][fieldY - 1])) { |
329 |
parseField(fields[fieldX + 1][fieldY - 1]); |
330 |
} |
331 |
|
332 |
if (checkField(fields[fieldX]) && checkField(fields[fieldX][fieldY - 1])) { |
333 |
parseField(fields[fieldX][fieldY - 1]);
|
334 |
} |
335 |
|
336 |
if (checkField(fields[fieldX + 1]) && checkField(fields[fieldX + 1][fieldY])) { |
337 |
parseField(fields[fieldX + 1][fieldY]);
|
338 |
} |
339 |
} else if (positionY == "bottom" && positionX == "left") { |
340 |
if (checkField(fields[fieldX]) && checkField(fields[fieldX][fieldY])) {
|
341 |
parseField(fields[fieldX][fieldY]); |
342 |
} |
343 |
|
344 |
if (checkField(fields[fieldX - 1]) && checkField(fields[fieldX - 1][fieldY + 1])) { |
345 |
parseField(fields[fieldX - 1][fieldY + 1]); |
346 |
} |
347 |
|
348 |
if (checkField(fields[fieldX - 1]) && checkField(fields[fieldX - 1][fieldY + 1])) { |
349 |
parseField(fields[fieldX - 1][fieldY + 1]); |
350 |
} |
351 |
if (checkField(fields[fieldX - 1]) && checkField(fields[fieldX - 1][fieldY])) { |
352 |
parseField(fields[fieldX - 1][fieldY]);
|
353 |
} |
354 |
} else if (positionY == "bottom" && positionX == "right") { |
355 |
if (checkField(fields[fieldX]) && checkField(fields[fieldX][fieldY])) {
|
356 |
parseField(fields[fieldX][fieldY]); |
357 |
} |
358 |
if (checkField(fields[fieldX + 1]) && checkField(fields[fieldX + 1][fieldY + 1])) { |
359 |
parseField(fields[fieldX + 1][fieldY + 1]); |
360 |
} |
361 |
if (checkField(fields[fieldX + 1]) && checkField(fields[fieldX + 1][fieldY])) { |
362 |
parseField(fields[fieldX + 1][fieldY]);
|
363 |
} |
364 |
if (checkField(fields[fieldX + 1]) && checkField(fields[fieldX + 1][fieldY])) { |
365 |
parseField(fields[fieldX + 1][fieldY]);
|
366 |
} |
367 |
} |
368 |
} |
369 |
appendGazeLinks(); |
370 |
} |
371 |
|
372 |
/*
|
373 |
* Check if a given field has links inside of it at all
|
374 |
*/
|
375 |
function checkField(field) { |
376 |
return false; |
377 |
//console.log("functions.js :: " + "checkField()" + ", field: " + typeof field);
|
378 |
//console.log("checking");
|
379 |
if (field !== undefined) { |
380 |
return true; |
381 |
} else {
|
382 |
return false; |
383 |
} |
384 |
|
385 |
} |
386 |
|
387 |
|
388 |
/*
|
389 |
* Parse a given field for links that lie in the linkParsingArea
|
390 |
*/
|
391 |
function parseField(fieldToParse) { |
392 |
return false; |
393 |
//console.log("functions.js :: " + "parseField()" + ", fieldToParse: " + typeof fieldToParse);
|
394 |
var topLeft_x = 0; |
395 |
topLeft_x = gazeInformation.x - (blickBrowserSettings.linkParsingAreaWidth / 2);
|
396 |
var topLeft_y = 0; |
397 |
topLeft_y = gazeInformation.y - (blickBrowserSettings.linkParsingAreaHeight / 2);
|
398 |
|
399 |
|
400 |
for (var s = 0; s < fieldToParse.length; s++) { |
401 |
|
402 |
if (fieldToParse[s].x > topLeft_x && fieldToParse[s].x < (topLeft_x + blickBrowserSettings.linkParsingAreaWidth)) {
|
403 |
|
404 |
if (fieldToParse[s].y > topLeft_y && fieldToParse[s].y < (topLeft_y + blickBrowserSettings.linkParsingAreaHeight)) {
|
405 |
|
406 |
gazeInformation.gazeLinks.push({ |
407 |
"index": s,
|
408 |
"name": fieldToParse[s].text,
|
409 |
"url": fieldToParse[s].url
|
410 |
}); |
411 |
//console.log("GazeLink ADD index: "+s+" name: "+fieldToParse[s]['text']+" url: "+fieldToParse[s]['url']);
|
412 |
|
413 |
|
414 |
|
415 |
} |
416 |
} |
417 |
} |
418 |
} |
419 |
|
420 |
/*
|
421 |
* Parse element below at current gazePosition for links and put them into the gazeLink Array
|
422 |
*/
|
423 |
function findLinksInElementBelow() { |
424 |
return false; |
425 |
//console.log("functions.js :: " + "findLinksInElementBelow()");
|
426 |
var sourceData = $(gazeInformation.elementBelow).find("a"); |
427 |
|
428 |
gazeInformation.gazeLinks = []; |
429 |
for (var s = 0; s < sourceData.length; s++) { |
430 |
gazeInformation.gazeLinks.push({ |
431 |
"index": s,
|
432 |
"name": $(sourceData[s]).text(), |
433 |
"url": $(sourceData[s]).attr("href") |
434 |
}); |
435 |
} |
436 |
//console.log("Number of GazeLinksFound in elementBelow " + gazeInformation.gazeLinks.length);
|
437 |
appendGazeLinks(); |
438 |
|
439 |
} |
440 |
|
441 |
|
442 |
/*
|
443 |
* Take the links from the gazeLink Array and arrange them in the gazeLink Div as a list
|
444 |
* Also append all needed gazeConfirmations and gazeLinkOptions to them
|
445 |
*/
|
446 |
function appendGazeLinks() { |
447 |
return false; |
448 |
//console.log("functions.js :: " + "appendGazeLinks()");
|
449 |
$("#gazeLinks").empty(); |
450 |
var dataGazeString = '{\"isFixated\":{\"funcType\":\"fixed\",\"func\":\"showWheelSelector\"}}'; |
451 |
|
452 |
//console.log("gazelinksLength: "+gazeInformation.gazeLinks.length);
|
453 |
if (gazeInformation.gazeLinks.length > 0) { |
454 |
for (var l = 0; l < gazeInformation.gazeLinks.length; l++) { |
455 |
|
456 |
|
457 |
|
458 |
if (blickBrowserSettings.selectionMode == "isFixated"){ |
459 |
//console.log("because selectionMode is 'isFixated' the gazeConfirmationSteps are set to 1");
|
460 |
blickBrowserSettings.gazeConfirmationSteps = 0;
|
461 |
} |
462 |
|
463 |
if (blickBrowserSettings.gazeConfirmationSteps === 0) { |
464 |
|
465 |
dataGazeString = '{\"gazeEnter\":{\"funcType\":\"dynamic\",\"func\":\"gazeInformation.selectedGazeLink=\\\"' + l + '\\\";gazeFunctions[\\\"showGazeLinkOptions\\\"](' + l + ');\"}}'; |
466 |
|
467 |
if ($("#gazeLinkNum_" + l).length > 0) { |
468 |
$("#gazeLinkNum_" + l).remove(); |
469 |
} |
470 |
$("#gazeLinks").append("<div id='gazeLinkNum_" + l + "' class='gazeLink' data-gaze='" + dataGazeString + "' ><strong class='gazeLinkName'>" + (shortenString(gazeInformation.gazeLinks[l].name, 25) || shortenString(gazeInformation.gazeLinks[l].url, 25)) + "</strong><br />" + shortenString(gazeInformation.gazeLinks[l].url, 60) + "</div>"); |
471 |
|
472 |
//dataGazeString = '{\"'+blickBrowserSettings.selectionMode+'\":{\"funcType\":\"dynamic\",\"func\":\"gazeInformation.selectedGazeLink=\\\"' + l + '\\\";gazeFunctions[\\\"showGazeLinkOptions\\\"](' + l + ');\"}}';
|
473 |
dataGazeString = "{\""+blickBrowserSettings.selectionMode+"\":{\"funcType\":\"dynamic\",\"func\":\"edgeFunctions.clearDivs();gazeFunctions.showWheelSelector(" + l + ")\"}}"; |
474 |
|
475 |
if (blickBrowserSettings.showLeftGazeLinkOption){
|
476 |
if ($("#leftGazeOption_" + l).length > 0) { |
477 |
$("#leftGazeOption_" + l).remove(); |
478 |
} |
479 |
$("#gazeLinks").parent().append("<div data-gaze='" + dataGazeString + "' id='leftGazeOption_" + l + "' class='gazeLinkOption'></div>"); |
480 |
$("#leftGazeOption_" + l).append("<i id='gazeLinkOptionIcon_left' data-gaze='" + dataGazeString + "' class='gazeLinkOptionIcon fa fa-cogs'></i>"); |
481 |
|
482 |
//appendGazeEvents($("#gazeLinkOptionIcon_left")[0]);
|
483 |
$("#leftGazeOption_" + l).height(blickBrowserSettings.gazeConfirmationSize); |
484 |
$("#leftGazeOption_" + l).width(blickBrowserSettings.gazeConfirmationSize); |
485 |
} |
486 |
|
487 |
dataGazeString = "{\""+blickBrowserSettings.selectionMode+"\":{\"funcType\":\"dynamic\",\"func\":\"edgeFunctions.clearDivs();gazeFunctions.openURL(\\\"" + gazeInformation.gazeLinks[l].url + "\\\",\\\"_self\\\")\"}}"; |
488 |
|
489 |
if ($("#rightGazeOption_" + l).length > 0) { |
490 |
$("#rightGazeOption_" + l).remove(); |
491 |
} |
492 |
$("#gazeLinks").parent().append("<div data-gaze='" + dataGazeString + "' id='rightGazeOption_" + l + "' class='gazeLinkOption'></div>"); |
493 |
$("#rightGazeOption_" + l).append("<i id='gazeLinkOptionIcon_right' data-gaze='" + dataGazeString + "' class='gazeLinkOptionIcon fa fa-external-link'></i>"); |
494 |
//appendGazeEvents($("#gazeLinkOptionIcon_right")[0]);
|
495 |
$("#rightGazeOption_" + l).height(blickBrowserSettings.gazeConfirmationSize); |
496 |
$("#rightGazeOption_" + l).width(blickBrowserSettings.gazeConfirmationSize); |
497 |
} else {
|
498 |
|
499 |
|
500 |
dataGazeString = '{\"'+blickBrowserSettings.selectionMode+'\":{\"funcType\":\"dynamic\",\"func\":\"gazeInformation.selectedGazeLink=\\\"' + l + '\\\";gazeFunctions.showGazeLinkOptions(' + l + ');\"}}'; |
501 |
dataGazeString = '{\"gazeEnter\":{\"funcType\":\"dynamic\",\"func\":\"gazeInformation.selectedGazeLink=\\\"' + l + '\\\";gazeFunctions.showGazeLinkOptions(' + l + ');\"}}'; |
502 |
|
503 |
if ($("#gazeLinkNum_" + l).length > 0) { |
504 |
$("#gazeLinkNum_" + l).remove(); |
505 |
} |
506 |
$("#gazeLinks").append("<div id='gazeLinkNum_" + l + "' class='gazeLink' data-gaze='" + dataGazeString + "' ><strong class='gazeLinkName'>" + (shortenString(gazeInformation.gazeLinks[l].name, 25) || shortenString(gazeInformation.gazeLinks[l].url, 25)) + "</strong><br />" + shortenString(gazeInformation.gazeLinks[l].url, 60) + "</div>"); |
507 |
|
508 |
|
509 |
if (blickBrowserSettings.showLeftGazeLinkOption){
|
510 |
dataGazeString = "{\""+blickBrowserSettings.selectionMode+"\":{\"funcType\":\"dynamic\",\"func\":\"edgeFunctions.clearDivs();gazeFunctions.showWheelSelector(" + l + ")\"}}"; |
511 |
if ($("#leftGazeOption_" + l).length > 0) { |
512 |
$("#leftGazeOption_" + l).remove(); |
513 |
} |
514 |
$("#gazeLinks").parent().append("<div data-gaze='" + dataGazeString + "' id='leftGazeOption_" + l + "' class='gazeLinkOption'></div>"); |
515 |
$("#leftGazeOption_" + l).append("<i data-gaze='" + dataGazeString + "' class='gazeLinkOptionIcon fa fa-cogs'></i>"); |
516 |
$("#leftGazeOption_" + l).height(blickBrowserSettings.gazeConfirmationSize); |
517 |
$("#leftGazeOption_" + l).width(blickBrowserSettings.gazeConfirmationSize); |
518 |
} |
519 |
|
520 |
dataGazeString = "{\""+blickBrowserSettings.selectionMode+"\":{\"funcType\":\"dynamic\",\"func\":\"edgeFunctions.clearDivs();gazeFunctions.openURL(\\\"" + gazeInformation.gazeLinks[l].url + "\\\",\\\"_self\\\")\"}}"; |
521 |
|
522 |
|
523 |
if ($("#rightGazeOption_" + l).length > 0) { |
524 |
$("#rightGazeOption_" + l).remove(); |
525 |
} |
526 |
$("#gazeLinks").parent().append("<div data-gaze='" + dataGazeString + "' id='rightGazeOption_" + l + "' class='gazeLinkOption'></div>"); |
527 |
$("#rightGazeOption_" + l).append("<i data-gaze='" + dataGazeString + "' class='gazeLinkOptionIcon fa fa-external-link'></i>"); |
528 |
|
529 |
$("#rightGazeOption_" + l).height(blickBrowserSettings.gazeConfirmationSize); |
530 |
$("#rightGazeOption_" + l).width(blickBrowserSettings.gazeConfirmationSize); |
531 |
|
532 |
|
533 |
for (var confirmation = 0; confirmation < blickBrowserSettings.gazeConfirmationSteps; confirmation++) { |
534 |
if (confirmation == (blickBrowserSettings.gazeConfirmationSteps - 1)) { |
535 |
dataGazeString = "{\""+blickBrowserSettings.selectionMode+"\":{\"funcType\":\"dynamic\",\"func\":\"gazeFunctions.showConfirmationDiv(\\\"rightGazeOption_" + l + " \\\")\"}}"; |
536 |
if ($("#rightGazeConfirmation_" + l + "_" + confirmation ).length > 0) { |
537 |
$("#rightGazeConfirmation_" + l + "_" + confirmation).remove(); |
538 |
} |
539 |
$("#gazeLinks").parent().append("<div data-gaze='" + dataGazeString + "' id='rightGazeConfirmation_" + l + "_" + confirmation + "' class='gazeLinkOption'></div>"); |
540 |
$("#rightGazeConfirmation_" + l + "_" + confirmation).append("<span id='rightGazeConfirmation_" + l + "_" + confirmation+"_span' data-gaze='" + dataGazeString + "' class='gazeLinkOptionIcon gazeConfirmation'></span>"); |
541 |
$("#rightGazeConfirmation_" + l + "_" + confirmation+"_span").append("<i data-gaze='" + dataGazeString + "' class='fa fa-external-link'></i><br />" + (confirmation + 1) + " / " + blickBrowserSettings.gazeConfirmationSteps); |
542 |
|
543 |
|
544 |
|
545 |
if (blickBrowserSettings.showLeftGazeLinkOption){
|
546 |
dataGazeString = "{\""+blickBrowserSettings.selectionMode+"\":{\"funcType\":\"dynamic\",\"func\":\"gazeFunctions.showConfirmationDiv(\\\"leftGazeOption_" + l + " \\\")\"}}"; |
547 |
|
548 |
if ($("#leftGazeConfirmation_" + l + "_" + confirmation ).length > 0) { |
549 |
$("#leftGazeConfirmation_" + l + "_" + confirmation).remove(); |
550 |
} |
551 |
$("#gazeLinks").parent().append("<div data-gaze='" + dataGazeString + "' id='leftGazeConfirmation_" + l + "_" + confirmation + "' class='gazeLinkOption'></div>"); |
552 |
$("#leftGazeConfirmation_" + l + "_" + confirmation).append("<span id='leftGazeConfirmation_" + l + "_" + confirmation+"_span' data-gaze='" + dataGazeString + "' class='gazeLinkOptionIcon gazeConfirmation'></span>"); |
553 |
$("#leftGazeConfirmation_" + l + "_" + confirmation+"_span").append("<i data-gaze='" + dataGazeString + "' class='fa fa-cogs'></i><br />" + (confirmation + 1) + " / " + blickBrowserSettings.gazeConfirmationSteps ); |
554 |
} |
555 |
|
556 |
} else {
|
557 |
dataGazeString = "{\""+blickBrowserSettings.selectionMode+"\":{\"funcType\":\"dynamic\",\"func\":\"gazeFunctions.showConfirmationDiv(\\\"rightGazeConfirmation_" + l + "_" + (confirmation + 1) + " \\\")\"}}"; |
558 |
if ($("#rightGazeConfirmation_" + l + "_" + confirmation ).length > 0) { |
559 |
$("#rightGazeConfirmation_" + l + "_" + confirmation).remove(); |
560 |
} |
561 |
$("#gazeLinks").parent().append("<div data-gaze='" + dataGazeString + "' id='rightGazeConfirmation_" + l + "_" + confirmation + "' class='gazeLinkOption'><div>"); |
562 |
$("#rightGazeConfirmation_" + l + "_" + confirmation).append("<span id='rightGazeConfirmation_" + l + "_" + confirmation+"_span' data-gaze='" + dataGazeString + "' class='gazeLinkOptionIcon gazeConfirmation'></span>"); |
563 |
$("#rightGazeConfirmation_" + l + "_" + confirmation+"_span").append("<i data-gaze='" + dataGazeString + "' class='fa fa-external-link'></i><br />" + (confirmation + 1) + " / " + blickBrowserSettings.gazeConfirmationSteps); |
564 |
|
565 |
if (blickBrowserSettings.showLeftGazeLinkOption){
|
566 |
dataGazeString = "{\""+blickBrowserSettings.selectionMode+"\":{\"funcType\":\"dynamic\",\"func\":\"gazeFunctions.showConfirmationDiv(\\\"leftGazeConfirmation_" + l + "_" + (confirmation + 1) + " \\\")\"}}"; |
567 |
if ($("#leftGazeConfirmation_" + l + "_" + confirmation ).length > 0) { |
568 |
$("#leftGazeConfirmation_" + l + "_" + confirmation).remove(); |
569 |
} |
570 |
|
571 |
$("#gazeLinks").parent().append("<div data-gaze='" + dataGazeString + "' id='leftGazeConfirmation_" + l + "_" + confirmation + "' class='gazeLinkOption'></div>"); |
572 |
$("#leftGazeConfirmation_" + l + "_" + confirmation).append("<span id='leftGazeConfirmation_" + l + "_" + confirmation +"_span' data-gaze='" + dataGazeString + "' class='gazeLinkOptionIcon gazeConfirmation'></span>"); |
573 |
$("#leftGazeConfirmation_" + l + "_" + confirmation +"_span").append("<i data-gaze='" + dataGazeString + "' class='fa fa-cogs'></i><br />" + (confirmation + 1) + " / " + blickBrowserSettings.gazeConfirmationSteps); |
574 |
} |
575 |
} |
576 |
} |
577 |
|
578 |
} |
579 |
} |
580 |
|
581 |
if (blickBrowserSettings.explicitMode === true){ |
582 |
//appendGazeEvents();
|
583 |
} |
584 |
|
585 |
positionGazeLinks(); |
586 |
} |
587 |
|
588 |
} |
589 |
|
590 |
/*
|
591 |
* Position the gazeConfirmations, gazeLinkOptions and the gazeLink-DIV properly
|
592 |
*/
|
593 |
function positionGazeLinks() { |
594 |
//console.log("functions.js :: " + "positionGazeLinks()");
|
595 |
return false; |
596 |
|
597 |
if (blickBrowserSettings.explicitMode){
|
598 |
if ($(gazeInformation.elementBelow).width() < 100){ |
599 |
$("#gazeLinks").width(312); |
600 |
$("#gazeLinkNum_0").width(300); |
601 |
} else {
|
602 |
$("#gazeLinks").width($(gazeInformation.elementBelow).width()+12); |
603 |
$("#gazeLinkNum_0").width($(gazeInformation.elementBelow).width()); |
604 |
} |
605 |
|
606 |
|
607 |
if (blickBrowserSettings.showLeftGazeLinkOption){
|
608 |
if ($(gazeInformation.elementBelow).offset().left < ((blickBrowserSettings.gazeConfirmationSteps + 1) * blickBrowserSettings.gazeConfirmationSize)){ |
609 |
$("#gazeLinks").css("left", ((blickBrowserSettings.gazeConfirmationSteps + 1) * blickBrowserSettings.gazeConfirmationSize)+"px" ); |
610 |
} else {
|
611 |
$("#gazeLinks").css("left", $(gazeInformation.elementBelow).offset().left + "px"); |
612 |
} |
613 |
} else {
|
614 |
$("#gazeLinks").css("left", $(gazeInformation.elementBelow).offset().left + "px"); |
615 |
} |
616 |
|
617 |
if (($(window).width() - $("#gazeLinks").offset().left - $("#gazeLinks").width() ) < ((blickBrowserSettings.gazeConfirmationSteps + 1) * blickBrowserSettings.gazeConfirmationSize)){ |
618 |
console.log("too far right");
|
619 |
$("#gazeLinks").css("left", ( $(window).width() - ((blickBrowserSettings.gazeConfirmationSteps + 1) * blickBrowserSettings.gazeConfirmationSize) - $("#gazeLinks").width() )+"px" ); |
620 |
} |
621 |
|
622 |
|
623 |
|
624 |
|
625 |
$("#gazeLinks").css("top", $(gazeInformation.elementBelow).offset().top + "px"); |
626 |
} else {
|
627 |
|
628 |
if ((gazeInformation.x - 150) < ((blickBrowserSettings.gazeConfirmationSteps + 1) * blickBrowserSettings.gazeConfirmationSize)){ |
629 |
console.log("too far left");
|
630 |
//$("#" + id).css("left", "0px");
|
631 |
$("#gazeLinks").css("left", ((blickBrowserSettings.gazeConfirmationSteps + 1) * blickBrowserSettings.gazeConfirmationSize)+"px" ); |
632 |
} else {
|
633 |
$("#gazeLinks").css("left", (gazeInformation.x - 150) + "px"); |
634 |
} |
635 |
|
636 |
if (($(window).width() - (gazeInformation.x - 150) - $("#gazeLinks").width() ) < ((blickBrowserSettings.gazeConfirmationSteps + 1) * blickBrowserSettings.gazeConfirmationSize)){ |
637 |
console.log("too far right");
|
638 |
$("#gazeLinks").css("left", ( $(window).width() - ((blickBrowserSettings.gazeConfirmationSteps + 1) * blickBrowserSettings.gazeConfirmationSize) - $("#gazeLinks").width() )+"px" ); |
639 |
} |
640 |
|
641 |
|
642 |
$("#gazeLinks").css("top", (gazeInformation.y - 20)); |
643 |
} |
644 |
|
645 |
|
646 |
|
647 |
$('.gazeLinkOption').stop(); |
648 |
$(".gazeLinkOption").css("display", "none"); |
649 |
|
650 |
$("#gazeLinks").fadeIn(); |
651 |
|
652 |
var gazeLinksOffset = $("#gazeLinks").offset(); |
653 |
gazeInformation.gazeLinksPosition.x = gazeLinksOffset.left; |
654 |
gazeInformation.gazeLinksPosition.y = gazeLinksOffset.top; |
655 |
gazeLinksShowing = true;
|
656 |
//console.log("linkcheckrunning false");
|
657 |
linkCheckRunning = false;
|
658 |
//console.log("gazeLinkOffset x,y :"+ gazeInformation.gazeLinksPosition.x+ " , "+ gazeInformation.gazeLinksPosition.y);
|
659 |
|
660 |
|
661 |
} |
662 |
|
663 |
/*
|
664 |
* Arrange the elements inside the wheelSelector circled
|
665 |
*/
|
666 |
function arrangeWheelElements() { |
667 |
return false; |
668 |
//console.log("functions.js :: " + "arrangeWheelElements()");
|
669 |
var radius = 170; |
670 |
var fields = $('.wheelSelector'), |
671 |
container = $('#wheelSelector'), |
672 |
width = container.width(), |
673 |
width = container.width(), |
674 |
height = container.height(), |
675 |
angle = 0,
|
676 |
step = (2 * Math.PI) / fields.length;
|
677 |
fields.each(function() {
|
678 |
//alert($(this).width());
|
679 |
var x = Math.round(width / 2 + radius * Math.cos(angle) - $(this).width() / 2); |
680 |
var y = Math.round(height / 2 + radius * Math.sin(angle) - $(this).height() / 2); |
681 |
if (window.console) {
|
682 |
//console.log($(this).text(), x, y);
|
683 |
} |
684 |
$(this).css({ |
685 |
left: x + 'px', |
686 |
top: y + 'px' |
687 |
}); |
688 |
angle += step; |
689 |
}); |
690 |
} |
691 |
|
692 |
/*
|
693 |
* Functions that can be used as edgeGazeGestures (looking left, top or right of the screen)
|
694 |
*/
|
695 |
var edgeFunctions = {
|
696 |
|
697 |
openHome: function() { |
698 |
self.port.emit("openHomepage");
|
699 |
}, |
700 |
/*
|
701 |
* clears all seen gaze elements
|
702 |
*/
|
703 |
clearDivs: function() { |
704 |
//console.log("clearGazeElements()");
|
705 |
|
706 |
$('#gazeOption_single').css('display','none'); |
707 |
|
708 |
$("#gazeLinks").css("display", "none"); |
709 |
$("#closeGazeLinks").css("display", "none"); |
710 |
|
711 |
//$('.gazeLinkOption').stop();
|
712 |
//$(".gazeLinkOption").css("display", "none");
|
713 |
$('.gazeLinkOption').remove(); |
714 |
|
715 |
$("#gazeLinks").empty(); |
716 |
gazeLinksShowing = false;
|
717 |
$("#wheelSelector").css("display", "none"); |
718 |
$("#wheelSelector").empty(); |
719 |
wheelSelectorShowing = false;
|
720 |
$("#controlBar").css("display", "none"); |
721 |
controlBarShowing = false;
|
722 |
$("#itemSelector").css("display", "none"); |
723 |
|
724 |
$(".gazeGestures").css("display","none"); |
725 |
gestureMode = false;
|
726 |
if (!calibrationRunning){
|
727 |
$("#calibration_blackout").css("display", "none"); |
728 |
} |
729 |
|
730 |
closeAll(); |
731 |
|
732 |
|
733 |
}, |
734 |
/*
|
735 |
* initiate a 4 point gazeGesture
|
736 |
*/
|
737 |
initiateGesture: function() { |
738 |
$("#calibration_blackout").css("display", "block"); |
739 |
$(".gazeGestures").css("display", "block"); |
740 |
gestureTimer = Date.now(); |
741 |
lastGesture = "";
|
742 |
gestureString = "";
|
743 |
gestureMode = true;
|
744 |
}, |
745 |
/*
|
746 |
* shows the controlBar
|
747 |
*/
|
748 |
showControlBar: function() { |
749 |
|
750 |
|
751 |
//console.log("showControlBar()");
|
752 |
$("#controlBar").empty(); |
753 |
|
754 |
if (blickBrowserSettings.eyeTracker == "eyetribe"){ |
755 |
if (blickBrowserSettings.controlBarCalibInfo){
|
756 |
$("#controlBar").append("<div id='controlBarCalibInfo' class='topBarItem' ><i class='topBarIcon fa fa-info'></i><p class=\"subtitle\">Accuracy: "+ calibrationResult.deg +"° </p></div>"); |
757 |
} |
758 |
} |
759 |
|
760 |
|
761 |
|
762 |
$("#controlBar").append("<div id='controlBarBack' data-gaze='true' data-gaze='true' data-gaze-type='action' data-gaze-model='dwell' data-gaze-function='edgeFunctions.clearDivs();window.history.back()' class='topBarItem' ></div>"); |
763 |
$("#controlBarBack").append("<i data-gaze='true' data-gaze='true' data-gaze-type='action' data-gaze-model='dwell' data-gaze-function='edgeFunctions.clearDivs();window.history.back()' class='topBarIcon fa fa-mail-reply'></i><p class=\"subtitle\">Back</p>"); |
764 |
|
765 |
$("#controlBar").append("<div id='controlBarForward' data-gaze='true' data-gaze='true' data-gaze-type='action' data-gaze-model='dwell' data-gaze-function='edgeFunctions.clearDivs();window.history.forward()' class='topBarItem' ></div>"); |
766 |
$("#controlBarForward").append("<i data-gaze='true' data-gaze='true' data-gaze-type='action' data-gaze-model='dwell' data-gaze-function='edgeFunctions.clearDivs();window.history.forward()' class='topBarIcon fa fa-mail-forward'></i><p class=\"subtitle\">Forward</p>"); |
767 |
|
768 |
$("#controlBar").append("<div id='controlBarReload' data-gaze='true' data-gaze-type='action' data-gaze-model='dwell' data-gaze-function='edgeFunctions.clearDivs();location.reload()' class='topBarItem'></div>"); |
769 |
$("#controlBarReload").append("<i data-gaze='true' data-gaze='true' data-gaze-type='action' data-gaze-model='dwell' data-gaze-function='edgeFunctions.clearDivs();location.reload()' class='topBarIcon fa fa-refresh'></i><p class=\"subtitle\">Refresh</p>"); |
770 |
|
771 |
$("#controlBar").append("<div id='controlBarHome' data-gaze='true' data-gaze-type='action' data-gaze-model='dwell' data-gaze-function='edgeFunctions.clearDivs();window.close();edgeFunctions.openHome()' class='topBarItem'></div>"); |
772 |
$("#controlBarHome").append("<i data-gaze='true' data-gaze='true' data-gaze-type='action' data-gaze-model='dwell' data-gaze-function='edgeFunctions.clearDivs();window.close();edgeFunctions.openHome()' class='topBarIcon fa fa-home'></i><p class=\"subtitle\">Home</p>"); |
773 |
|
774 |
$("#controlBar").append("<div id='controlBarToggleReading' data-gaze='true' data-gaze='true' data-gaze-type='action' data-gaze-model='dwell' data-gaze-function='edgeFunctions.clearDivs();edgeFunctions.toggleReadingMode()' class='topBarItem'></div>"); |
775 |
$("#controlBarToggleReading").append("<i data-gaze='true' data-gaze='true' data-gaze-type='action' data-gaze-model='dwell' data-gaze-function='edgeFunctions.clearDivs();edgeFunctions.toggleReadingMode()' class='topBarIcon fa fa-book'></i><p class=\"subtitle\">"+(blickBrowserSettings.blickBrowserMode==="reading" ? "Disable Reading" : "Enable Reading")+"</p>"); |
776 |
|
777 |
$("#controlBar").append("<div id='controlBarToggleAutoReading' data-gaze='true' data-gaze='true' data-gaze-type='action' data-gaze-model='dwell' data-gaze-function='edgeFunctions.clearDivs();edgeFunctions.toggleAutoReadingMode()' class='topBarItem'></div>"); |
778 |
$("#controlBarToggleAutoReading").append("<i data-gaze='true' data-gaze='true' data-gaze-type='action' data-gaze-model='dwell' data-gaze-function='edgeFunctions.clearDivs();edgeFunctions.toggleAutoReadingMode()' class='topBarIcon fa fa-history'></i><p class=\"subtitle\">"+(blickBrowserSettings.autoReadingMode ? "Disable AutoRead" : "Enable AutoRead")+"</p>"); |
779 |
|
780 |
$("#controlBar").append("<div id='toggleExplicitMode' data-gaze='true' data-gaze='true' data-gaze-type='action' data-gaze-model='dwell' data-gaze-function='edgeFunctions.clearDivs();edgeFunctions.toggleExplicitMode()' class='topBarItem'></div>"); |
781 |
$("#toggleExplicitMode").append("<i data-gaze='true' data-gaze='true' data-gaze-type='action' data-gaze-model='dwell' data-gaze-function='edgeFunctions.clearDivs();edgeFunctions.toggleExplicitMode()' class='topBarIcon fa fa-dot-circle-o'></i><p class=\"subtitle\">"+ (blickBrowserSettings.explicitMode ? "Disable ExplicitMode" : "Enable ExplicitMode") +"</p>"); |
782 |
|
783 |
$("#controlBar").append("<div id='controlBarToggleScrolling' data-gaze='true' data-gaze='true' data-gaze-type='action' data-gaze-model='dwell' data-gaze-function='edgeFunctions.clearDivs();edgeFunctions.toggleScrolling()' class='topBarItem'></div>"); |
784 |
$("#controlBarToggleScrolling").append("<i data-gaze='true' data-gaze='true' data-gaze-type='action' data-gaze-model='dwell' data-gaze-function='edgeFunctions.clearDivs();edgeFunctions.toggleScrolling()' class='topBarIcon fa fa-arrows-v'></i><p class=\"subtitle\">"+ (blickBrowserSettings.scrollAtBorders ? "Disable Scrolling" : "Enable Scrolling") +"</p>"); |
785 |
|
786 |
$("#controlBar").append("<div id='controlBarInitiateGesture' data-gaze='true' data-gaze='true' data-gaze-type='action' data-gaze-model='dwell' data-gaze-function='edgeFunctions.clearDivs();edgeFunctions.initiateGesture();' class='topBarItem'></div>"); |
787 |
$("#controlBarInitiateGesture").append("<i data-gaze='true' data-gaze='true' data-gaze-type='action' data-gaze-model='dwell' data-gaze-function='edgeFunctions.clearDivs();edgeFunctions.initiateGesture();' class='topBarIcon fa fa-crosshairs'></i><p class=\"subtitle\">Initiate Gesture</p>"); |
788 |
|
789 |
|
790 |
|
791 |
/*
|
792 |
* Put all available blickBrowser Bookmarks into controlbar
|
793 |
*/
|
794 |
var myBookmarks = blickBrowserSettings.bookmarks.split(";"); |
795 |
if (myBookmarks.length > 0){ |
796 |
//console.log(myBookmarks);
|
797 |
for (var b = 0;b< myBookmarks.length; b++){ |
798 |
var splittedBookmark = myBookmarks[b].split("|"); |
799 |
var bookmarkName = splittedBookmark[0]; |
800 |
var bookmarkURL = splittedBookmark[1]; |
801 |
if (bookmarkURL !== undefined){ |
802 |
$("#controlBar").append("<div id='controlBarBookmark_"+b+"' data-gaze='{\"isFixated\": {\"funcType\":\"dynamic\",\"func\":\"edgeFunctions.clearDivs();gazeFunctions[\\\"openURL\\\"](\\\"" + bookmarkURL + "\\\",\\\"_self\\\")\"}}' class='topBarItem'></div>"); |
803 |
$("#controlBarBookmark_"+b).append("<i data-gaze='{\"isFixated\": {\"funcType\":\"dynamic\",\"func\":\"edgeFunctions.clearDivs();gazeFunctions[\\\"openURL\\\"](\\\"" + bookmarkURL + "\\\",\\\"_self\\\")\"}}' class='topBarIcon fa fa-star'></i><p class=\"subtitle\">"+ shortenString(bookmarkName, 12) +"</p>"); |
804 |
} |
805 |
} |
806 |
} |
807 |
|
808 |
|
809 |
|
810 |
//appendGazeEvents($("#gazeLinkOptionIcon_right")[0]);
|
811 |
//appendGazeEvents();
|
812 |
|
813 |
if ($("#controlBar").children().length > 0) { |
814 |
if (!controlBarShowing) {
|
815 |
//clearDivs();
|
816 |
controlBarShowing = true;
|
817 |
$("#controlBar").fadeIn(); |
818 |
|
819 |
/*var controlbar = document.getElementById('#controlBar');
|
820 |
var hasHorizontalScrollbar = controlbar.scrollWidth > div.clientWidth;
|
821 |
//document.getElementById("controlBar").scrollLeft+=100;
|
822 |
if (hasHorizontalScrollbar){
|
823 |
alert("SCROLL!!!");
|
824 |
}*/
|
825 |
|
826 |
|
827 |
} |
828 |
} |
829 |
}, |
830 |
|
831 |
/*
|
832 |
* toggle fixed reading mode for undisturbed reading of articles etc.
|
833 |
*/
|
834 |
toggleReadingMode: function() { |
835 |
|
836 |
if (Date.now() - modeToggleCounter > blickBrowserSettings.modeToggleRefractionTime) {
|
837 |
//console.log("functions.js :: "+"toggleReadingMode()" );
|
838 |
if (blickBrowserSettings.blickBrowserMode == "reading") { |
839 |
checkForLinksInterval = setInterval(gazeFunctions.checkForLinks, 1000);
|
840 |
self.port.emit("blickBrowserMode", "browse"); |
841 |
modeToggleCounter = Date.now(); |
842 |
$.notify("Switched to browse mode","success"); |
843 |
//showNotification('eye', 'Switched to browse mode');
|
844 |
//$("#notification").text("switched to browsing mode");
|
845 |
edgeFunctions.clearDivs(); |
846 |
} else if (blickBrowserSettings.blickBrowserMode == "browse") { |
847 |
clearTimeout(checkForLinksInterval); |
848 |
self.port.emit("blickBrowserMode", "reading"); |
849 |
modeToggleCounter = Date.now(); |
850 |
$.notify("Switched to reading mode","success"); |
851 |
//showNotification('book', 'Switched to reading mode');
|
852 |
//$("#notification").text("switched to reading mode");
|
853 |
edgeFunctions.clearDivs(); |
854 |
} |
855 |
} |
856 |
}, |
857 |
toggleAutoReadingMode: function(){ |
858 |
if (Date.now() - modeToggleCounter > blickBrowserSettings.modeToggleRefractionTime) {
|
859 |
//console.log("functions.js :: "+"toggleScrolling()" );
|
860 |
|
861 |
if (blickBrowserSettings.autoReadingMode === true){ |
862 |
blickBrowserSettings.autoReadingMode = false;
|
863 |
} else {
|
864 |
blickBrowserSettings.autoReadingMode = true;
|
865 |
} |
866 |
|
867 |
|
868 |
|
869 |
modeToggleCounter = Date.now(); |
870 |
$.notify("Switched autoReadingMode "+ ( blickBrowserSettings.scrollAtBorders ? "on" : "off"),"success"); |
871 |
writeSettings(); |
872 |
//showNotification('eye', 'Switched to browse mode');
|
873 |
//$("#notification").text("switched to browsing mode");
|
874 |
edgeFunctions.clearDivs(); |
875 |
|
876 |
} |
877 |
}, |
878 |
toggleExplicitMode: function(){ |
879 |
if (Date.now() - modeToggleCounter > blickBrowserSettings.modeToggleRefractionTime) {
|
880 |
//console.log("functions.js :: "+"toggleScrolling()" );
|
881 |
|
882 |
if (blickBrowserSettings.explicitMode === true){ |
883 |
blickBrowserSettings.explicitMode = false;
|
884 |
} else {
|
885 |
blickBrowserSettings.explicitMode = true;
|
886 |
} |
887 |
|
888 |
|
889 |
|
890 |
modeToggleCounter = Date.now(); |
891 |
$.notify("Switched explicitMode "+ ( blickBrowserSettings.scrollAtBorders ? "on" : "off"),"success"); |
892 |
writeSettings(); |
893 |
//showNotification('eye', 'Switched to browse mode');
|
894 |
//$("#notification").text("switched to browsing mode");
|
895 |
edgeFunctions.clearDivs(); |
896 |
|
897 |
} |
898 |
}, |
899 |
/*
|
900 |
* enable / disable scrolling
|
901 |
*/
|
902 |
toggleScrolling: function() { |
903 |
if (Date.now() - modeToggleCounter > blickBrowserSettings.modeToggleRefractionTime) {
|
904 |
//console.log("functions.js :: "+"toggleScrolling()" );
|
905 |
|
906 |
if (blickBrowserSettings.scrollAtBorders === true){ |
907 |
blickBrowserSettings.scrollAtBorders = false;
|
908 |
} else {
|
909 |
blickBrowserSettings.scrollAtBorders = true;
|
910 |
} |
911 |
|
912 |
|
913 |
|
914 |
modeToggleCounter = Date.now(); |
915 |
$.notify("Switched scrolling "+ ( blickBrowserSettings.scrollAtBorders ? "on" : "off"),"success"); |
916 |
writeSettings(); |
917 |
//showNotification('eye', 'Switched to browse mode');
|
918 |
//$("#notification").text("switched to browsing mode");
|
919 |
edgeFunctions.clearDivs(); |
920 |
|
921 |
} |
922 |
}, |
923 |
none: function(){ |
924 |
|
925 |
} |
926 |
|
927 |
}; |
928 |
|
929 |
function gazeOverFunc(element) { |
930 |
|
931 |
} |
932 |
|
933 |
function isFixationFunc(element) { |
934 |
|
935 |
|
936 |
} |
937 |
|
938 |
function gazeEnterFunc(element) { |
939 |
//console.log("functions.js :: "+"gazeEnterFunc()" + ", element: " + typeof element );
|
940 |
|
941 |
if (blickBrowserSettings.borderGazedObjects === true) { |
942 |
$(element).css("outline", "2px dashed #000000"); |
943 |
$(element).css("outline-offset", "-2px"); |
944 |
} |
945 |
|
946 |
|
947 |
} |
948 |
|
949 |
function gazeLeaveFunc(element) { |
950 |
//console.log("functions.js :: "+"gazeLeaveFunc()" +", element: "+typeof element );
|
951 |
if (blickBrowserSettings.borderGazedObjects === true) { |
952 |
$(element).css("outline", "0px none"); |
953 |
} |
954 |
|
955 |
|
956 |
} |
957 |
|
958 |
|
959 |
/*
|
960 |
* Copy current gazeInformationX/Y to unsafeWindow and make the function visible from a page-script
|
961 |
*/
|
962 |
function getGazeInformation(){ |
963 |
unsafeWindow.gazeInformationX = cloneInto(gazeInformation.x, unsafeWindow); |
964 |
unsafeWindow.gazeInformationY = cloneInto(gazeInformation.y, unsafeWindow); |
965 |
//return gazeInformation;
|
966 |
} |
967 |
exportFunction(getGazeInformation, unsafeWindow, {defineAs: "getGazeInformation"}); |
968 |
|
969 |
|
970 |
function checkCalibration() { |
971 |
//console.log("check Calibration");
|
972 |
$("#calibration_check").css("display", "block"); |
973 |
$("#calibrationImage").css("display", "block"); |
974 |
var imageMovingSpeed = 1000; |
975 |
|
976 |
gazeCorrectionX = 0;
|
977 |
gazeCorrectionY = 0;
|
978 |
|
979 |
gc_left = window.innerWidth * 0.2;
|
980 |
gc_right = window.innerWidth - gc_left; |
981 |
gc_top = window.innerHeight * 0.2;
|
982 |
gc_bottom = window.innerHeight - gc_top; |
983 |
|
984 |
switch(blickBrowserSettings.gazeCorrectionPoints){
|
985 |
|
986 |
case 4: gazeCorrectionPoints = [{x:gc_left,y:gc_top}, {x:gc_right,y:gc_bottom}, {x:gc_left,y:gc_bottom}, {x:gc_right,y:gc_top}]; break; |
987 |
case 1: gazeCorrectionPoints = [{x:(window.innerWidth/2),y:(window.innerHeight/2)}]; break; |
988 |
default: break; |
989 |
|
990 |
} |
991 |
|
992 |
|
993 |
|
994 |
|
995 |
$("#calibrationImage").animate({ |
996 |
left: "+" + (gazeCorrectionPoints[gazeCorrectionPointNr].x - calibrationIconSizeHalf), |
997 |
top: "+" + (gazeCorrectionPoints[gazeCorrectionPointNr].y - calibrationIconSizeHalf) |
998 |
}, imageMovingSpeed); |
999 |
|
1000 |
gazeCorrectionMode = true;
|
1001 |
|
1002 |
setTimeout(function() {
|
1003 |
var gcSumX = 0; |
1004 |
var gcSumY = 0; |
1005 |
for (var gc = 0; gc < gazeCorrectionData.length; gc++) { |
1006 |
gcSumX += gazeCorrectionData[gc].x; |
1007 |
gcSumY += gazeCorrectionData[gc].y; |
1008 |
|
1009 |
} |
1010 |
//console.log("GC X: " + (gcSumX / gazeCorrectionData.length));
|
1011 |
//console.log("GC Y: " + (gcSumY / gazeCorrectionData.length));
|
1012 |
gazeCorrectionValues.push({ |
1013 |
x: gcSumX / gazeCorrectionData.length,
|
1014 |
y: gcSumY / gazeCorrectionData.length
|
1015 |
}); |
1016 |
gazeCorrectionX += (gazeCorrectionPoints[gazeCorrectionPointNr].x - gazeCorrectionValues[gazeCorrectionPointNr].x); |
1017 |
gazeCorrectionY += (gazeCorrectionPoints[gazeCorrectionPointNr].y - gazeCorrectionValues[gazeCorrectionPointNr].y); |
1018 |
//console.log("difference x:"+(gazeCorrectionPoints[gazeCorrectionPointNr].x - gazeCorrectionValues[gazeCorrectionPointNr].x));
|
1019 |
//console.log("difference y:"+(gazeCorrectionPoints[gazeCorrectionPointNr].y - gazeCorrectionValues[gazeCorrectionPointNr].y));
|
1020 |
gazeCorrectionData = []; |
1021 |
gazeCorrectionPointNr++; |
1022 |
|
1023 |
if (gazeCorrectionPointNr < gazeCorrectionPoints.length){
|
1024 |
gazeCorrectionValues = []; |
1025 |
gazeCorrectionPoints = []; |
1026 |
checkCalibration(); |
1027 |
} else {
|
1028 |
gazeCorrectionMode = false;
|
1029 |
|
1030 |
gazeCorrectionX = (gazeCorrectionX/gazeCorrectionPointNr); |
1031 |
gazeCorrectionY = (gazeCorrectionY/gazeCorrectionPointNr); |
1032 |
|
1033 |
blickBrowserSettings.gazeOffsetX = Math.floor(gazeCorrectionX); |
1034 |
blickBrowserSettings.gazeOffsetY = Math.floor(gazeCorrectionY); |
1035 |
writeSettings(); |
1036 |
|
1037 |
console.log("gazeCorrectionX: "+gazeCorrectionX);
|
1038 |
console.log("gazeCorrectionY: "+gazeCorrectionY);
|
1039 |
$("#calibration_check").css("display", "none"); |
1040 |
$("#calibrationImage").css("display", "none"); |
1041 |
if (calibrationResult.deg < 0.5) { |
1042 |
showNotification('star',"Calibration result: Very Good 5/5 stars.<br /><i class=\"fa fa-star\"></i><i class=\"fa fa-star\"></i><i class=\"fa fa-star\"></i><i class=\"fa fa-star\"></i><i class=\"fa fa-star\"></i>"); |
1043 |
|
1044 |
} else if (calibrationResult.deg < 0.7) { |
1045 |
showNotification('star',"Calibration result: Good 4/5 stars.<br /><i class=\"fa fa-star\"></i><i class=\"fa fa-star\"></i><i class=\"fa fa-star\"></i><i class=\"fa fa-star\"></i>"); |
1046 |
|
1047 |
} else if (calibrationResult.deg < 1) { |
1048 |
showNotification('star',"Calibration result: Moderate 3/5 stars.<br /><i class=\"fa fa-star\"></i><i class=\"fa fa-star\"></i><i class=\"fa fa-star\"></i>"); |
1049 |
|
1050 |
} else if (calibrationResult.deg < 1.5) { |
1051 |
showNotification('star',"Calibration result: Not good 2/5 stars.<br /><i class=\"fa fa-star\"></i><i class=\"fa fa-star\"></i>"); |
1052 |
|
1053 |
} else if (calibrationResult.deg >= 1.5) { |
1054 |
showNotification('star',"Calibration result: Bad 1/5 stars.<br /><i class=\"fa fa-star\"></i>"); |
1055 |
|
1056 |
} |
1057 |
gazeCorrectionPointNr = 0;
|
1058 |
/*for (var dp = 0;dp<gazeCorrectionValues.length;dp++){
|
1059 |
console.log("Point "+gazeCorrectionPointNr+": "+gazeCorrectionValues[dp].x+"|"+gazeCorrectionValues[dp].y);
|
1060 |
//console.log(": "+gazeCorrectionPoints[dp].x+"|"+gazeCorrectionPoints[dp].y);
|
1061 |
//gazeCorrectionX +=
|
1062 |
console.log("difference x:"+(gazeCorrectionPoints[dp].x - gazeCorrectionValues[dp].x));
|
1063 |
console.log("difference y:"+(gazeCorrectionPoints[dp].y - gazeCorrectionValues[dp].y));
|
1064 |
}*/
|
1065 |
|
1066 |
} |
1067 |
/*
|
1068 |
setTimeout(function() {
|
1069 |
|
1070 |
},1000); */
|
1071 |
}, imageMovingSpeed+300+3000); |
1072 |
|
1073 |
|
1074 |
} |
1075 |
|
1076 |
function distanceToGaze(obj) { |
1077 |
//console.log("functions.js :: "+"distanceToGaze()" + ", obj: "+typeof obj );
|
1078 |
var o1 = $(obj).offset(); |
1079 |
var dx = o1.left - gazeInformation.x;
|
1080 |
var dy = o1.top - gazeInformation.y;
|
1081 |
return Math.sqrt(dx * dx + dy * dy);
|
1082 |
} |