blinker / firefox.plugin / data / settings / html-gaze-attr.js @ 76dd22bd
History | View | Annotate | Download (6.685 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 |
jQuery(document).ready(function($) { |
22 |
jQuery('.save').click(function(event) { |
23 |
saveToSettings(); |
24 |
}); |
25 |
}); |
26 |
|
27 |
self.port.on('getElements', function(htmlelements){ |
28 |
showSettings(htmlelements); |
29 |
}); |
30 |
|
31 |
|
32 |
function showSettings(elements) { |
33 |
|
34 |
jQuery.each(elements, function(index, val) {
|
35 |
var newEl = '<li>'; |
36 |
var elmodel = ''; |
37 |
var eltype = ''; |
38 |
jQuery.each(val, function(mi, mval) {
|
39 |
switch(mi) {
|
40 |
case "data-gaze-type": |
41 |
eltype = mval; |
42 |
break;
|
43 |
case "data-gaze-model": |
44 |
elmodel = mval; |
45 |
break;
|
46 |
} |
47 |
}); |
48 |
|
49 |
// Attribut
|
50 |
newEl += '<div class="deleteCross">×</div>';
|
51 |
newEl += '<label>HTML-Item: </label>';
|
52 |
newEl += '<input class="elementname" type="text" value="' + index + '" />'; |
53 |
|
54 |
// Type
|
55 |
newEl += '<div class="gaze-type-cont tcont"><label>GAZE-Type</label>';
|
56 |
newEl += '<select class="gaze-type">';
|
57 |
newEl += getOptionElement('text', eltype);
|
58 |
newEl += getOptionElement('action', eltype);
|
59 |
newEl += getOptionElement('choice', eltype);
|
60 |
newEl += '</select></div>';
|
61 |
|
62 |
// Modell
|
63 |
newEl += '<div class="gaze-model-cont tcont"><label>GAZE-Model</label>';
|
64 |
newEl += '<select class="gaze-model">';
|
65 |
newEl += getOptionElement('onscreen', elmodel);
|
66 |
newEl += getOptionElement('piemenu', elmodel);
|
67 |
newEl += getOptionElement('dwell', elmodel);
|
68 |
newEl += '</select></div>';
|
69 |
|
70 |
newEl += '</li>';
|
71 |
|
72 |
jQuery('ol.settings').append(newEl);
|
73 |
}); |
74 |
|
75 |
|
76 |
$('.save').click(function(event) { |
77 |
saveToSettings(); |
78 |
}); |
79 |
|
80 |
|
81 |
$('.additem').click(function(event) { |
82 |
addSettings(); |
83 |
}); |
84 |
|
85 |
$('.deleteCross').click(function(event) { |
86 |
deleteSettings(this);
|
87 |
}); |
88 |
|
89 |
$('.resetToDef').click(function(event) { |
90 |
resetToDefault(); |
91 |
}); |
92 |
} |
93 |
|
94 |
function getOptionElement(value, selectedValue) { |
95 |
var OptionElement = '<option value="'; |
96 |
OptionElement += value + '"';
|
97 |
if(value == selectedValue) OptionElement += ' selected'; |
98 |
OptionElement += '>';
|
99 |
OptionElement += value; |
100 |
OptionElement += '</option>';
|
101 |
return OptionElement;
|
102 |
} |
103 |
|
104 |
|
105 |
function saveToSettings() { |
106 |
var htmlEles = {};
|
107 |
jQuery('ol.settings li').each(function(index, el) { |
108 |
var inputField = jQuery(this).children('.elementname').val(); |
109 |
var inputType = jQuery(this).children('.tcont').children('.gaze-type').children('option:selected').attr('value'); |
110 |
var inputModel = jQuery(this).children('.tcont').children('.gaze-model').children('option:selected').attr('value'); |
111 |
|
112 |
var htmlEle = {};
|
113 |
htmlEle['data-gaze'] = 'true'; |
114 |
htmlEle['data-gaze-type'] = inputType;
|
115 |
htmlEle['data-gaze-model'] = inputModel;
|
116 |
|
117 |
|
118 |
htmlEles[inputField] = htmlEle; |
119 |
}); |
120 |
|
121 |
$.notify("Settings updated","success"); |
122 |
|
123 |
self.port.emit("setElements", htmlEles);
|
124 |
console.log("Save Options");
|
125 |
console.log(htmlEles); |
126 |
} |
127 |
|
128 |
function addSettings() { |
129 |
var newEl = '<li>'; |
130 |
|
131 |
// Attribut
|
132 |
newEl += '<div class="deleteCross">×</div>';
|
133 |
newEl += '<label>HTML-Item: </label>';
|
134 |
newEl += '<input class="elementname" type="text" value="" />';
|
135 |
|
136 |
// Type
|
137 |
newEl += '<div class="gaze-type-cont tcont"><label>GAZE-Model</label>';
|
138 |
newEl += '<select class="gaze-type">';
|
139 |
newEl += getOptionElement('text', 'text'); |
140 |
newEl += getOptionElement('action', 'text'); |
141 |
newEl += getOptionElement('choice', 'text'); |
142 |
newEl += '</select></div>';
|
143 |
|
144 |
// Modell
|
145 |
newEl += '<div class="gaze-model-cont tcont"><label>GAZE-Model</label>';
|
146 |
newEl += '<select class="gaze-model">';
|
147 |
newEl += getOptionElement('onscreen', 'onscreen'); |
148 |
newEl += getOptionElement('piemenu', 'onscreen'); |
149 |
newEl += getOptionElement('dwell', 'onscreen'); |
150 |
newEl += '</select></div>';
|
151 |
|
152 |
newEl += '</li>';
|
153 |
|
154 |
jQuery('ol.settings').append(newEl);
|
155 |
|
156 |
$('.deleteCross').click(function(event) { |
157 |
deleteSettings(this);
|
158 |
}); |
159 |
} |
160 |
|
161 |
function deleteSettings(element) { |
162 |
if (confirm('Do you want delete this item?')) { |
163 |
jQuery(element).parent().remove(); |
164 |
} |
165 |
} |
166 |
|
167 |
function resetToDefault() { |
168 |
if (confirm('Do you want reset default settings?')) { |
169 |
htmlele = { |
170 |
a : {
|
171 |
"data-gaze" : "true", |
172 |
"data-gaze-type" : "action", |
173 |
"data-gaze-model" : "onscreen" |
174 |
}, |
175 |
button : {
|
176 |
"data-gaze" : "true", |
177 |
"data-gaze-type" : "action", |
178 |
"data-gaze-model" : "onscreen" |
179 |
}, |
180 |
img : {
|
181 |
"data-gaze" : "true", |
182 |
"data-gaze-type" : "action", |
183 |
"data-gaze-model" : "onscreen" |
184 |
}, |
185 |
audio: {
|
186 |
"data-gaze" : "true", |
187 |
"data-gaze-type" : "action", |
188 |
"data-gaze-model" : "onscreen" |
189 |
}, |
190 |
video: {
|
191 |
"data-gaze" : "true", |
192 |
"data-gaze-type" : "action", |
193 |
"data-gaze-model" : "onscreen" |
194 |
}, |
195 |
"input\[type=text\]": {
|
196 |
"data-gaze" : "true", |
197 |
"data-gaze-type" : "text", |
198 |
"data-gaze-model" : "onscreen" |
199 |
}, |
200 |
"input\[type=submit\]": {
|
201 |
"data-gaze" : "true", |
202 |
"data-gaze-type" : "action", |
203 |
"data-gaze-model" : "onscreen" |
204 |
}, |
205 |
"input\[type=reset\]": {
|
206 |
"data-gaze" : "true", |
207 |
"data-gaze-type" : "action", |
208 |
"data-gaze-model" : "onscreen" |
209 |
}, |
210 |
"input\[type=email\]": {
|
211 |
"data-gaze" : "true", |
212 |
"data-gaze-type" : "text", |
213 |
"data-gaze-model" : "onscreen" |
214 |
}, |
215 |
"input\[type=password\]": {
|
216 |
"data-gaze" : "true", |
217 |
"data-gaze-type" : "text", |
218 |
"data-gaze-model" : "onscreen" |
219 |
}, |
220 |
"select": {
|
221 |
"data-gaze" : "true", |
222 |
"data-gaze-type" : "choice", |
223 |
"data-gaze-model" : "onscreen" |
224 |
}, |
225 |
}; |
226 |
|
227 |
self.port.emit("setElements", htmlele);
|
228 |
location.reload(); |
229 |
} |
230 |
} |