Skip to content
This repository was archived by the owner on Sep 18, 2021. It is now read-only.

Commit af38cb0

Browse files
authored
Merge pull request #66 from mozilla/john-g-launch-issues
finish my remaining launch issues
2 parents c641375 + d0851c1 commit af38cb0

File tree

8 files changed

+160
-110
lines changed

8 files changed

+160
-110
lines changed

extension/assets/Firefox LOGO.svg

Lines changed: 0 additions & 18 deletions
This file was deleted.

extension/assets/feedback.svg

Lines changed: 26 additions & 0 deletions
Loading

extension/assets/ff-logo.png

5.07 KB
Loading

extension/assets/icon-48.png

1.03 KB
Loading

extension/assets/icon-96.png

2.19 KB
Loading

extension/content.js

Lines changed: 79 additions & 83 deletions
Original file line numberDiff line numberDiff line change
@@ -19,25 +19,49 @@
1919
const SPINNING_ANIMATION = browser.extension.getURL("Spinning.json");
2020
const START_ANIMATION = browser.extension.getURL("Start.json");
2121

22-
// This is a list of anchors on pages we are running stm on.
23-
// In current order they are: google, ddg home, ddg search page, yahoo home, yahoo search page
24-
const ACCEPTABLE_ANCHORS = [
25-
"sfdiv",
26-
"search_form_homepage",
27-
"seach_form",
28-
"uh-search-form",
29-
"sf"
30-
];
22+
23+
const getSTMAnchors = documentDomain => {
24+
switch (documentDomain) {
25+
case "www.google.com":
26+
case "www.google.ca":
27+
case "www.google.co.uk":
28+
return {
29+
input: "lst-ib",
30+
anchor: "sfdiv"
31+
}
32+
case "duckduckgo.com":
33+
if (document.body.classList.contains("body--serp")) {
34+
return {
35+
input: "search_form_input",
36+
anchor: "search_form"
37+
};
38+
}
39+
return {
40+
input: "search_form_input_homepage",
41+
anchor: "search_form_homepage"
42+
};
43+
case "ca.yahoo.com":
44+
case "uk.yahoo.com":
45+
case "www.yahoo.com":
46+
return {
47+
input: "uh-search-box",
48+
anchor: "uh-search-form"
49+
};
50+
default:
51+
return null;
52+
}
53+
}
54+
3155

3256
// Encapsulation of the popup we use to provide our UI.
3357
const POPUP_WRAPPER_MARKUP = `<div id="stm-popup">
34-
<div id="stm-header"><div role="button" tabindex="1" id="stm-close"></div></div>
35-
<div id="stm-inject"></div>
36-
</div>`;
58+
<div id="stm-header"><div role="button" tabindex="1" id="stm-close"></div></div>
59+
<div id="stm-inject"></div>
60+
<a href="https://qsurvey.mozilla.com/s3/voice-fill" id="stm-feedback" role="button" tabindex="2">Feedback</a>
61+
</div>`;
3762

3863
// When submitting, this markup is passed in
39-
const SUBMISSION_MARKUP = `
40-
<div id="stm-levels-wrapper">
64+
const SUBMISSION_MARKUP = `<div id="stm-levels-wrapper">
4165
<canvas hidden id="stm-levels" width=720 height=310></canvas>
4266
</div>
4367
<div id="stm-animation-wrapper">
@@ -49,13 +73,13 @@
4973

5074
// When Selecting, this markup is passed in
5175
const SELECTION_MARKUP = `<form id="stm-selection-wrapper">
52-
<div id="stm-list-wrapper">
53-
<input id="stm-input" type="text" />
54-
<div id="stm-list"></div>
55-
</div>
56-
<button id="stm-reset-button" title="reset"></button>
57-
<input id="stm-submit-button" type="submit" title="sumbit" value=""/>
58-
</form>`
76+
<div id="stm-list-wrapper">
77+
<input id="stm-input" type="text" />
78+
<div id="stm-list"></div>
79+
</div>
80+
<button id="stm-reset-button" title="reset" type="button"></button>
81+
<input id="stm-submit-button" type="submit" title="sumbit" value=""/>
82+
</form>`;
5983

6084
const SpeakToMePopup = {
6185
// closeClicked used to skip out of media recording handling
@@ -142,35 +166,52 @@
142166
html += "</ul>";
143167
list.innerHTML = html;
144168
}
145-
169+
146170
input.value = firstChoice.text;
147171
input.size = input.value.length;
148172

149173
if (list) {
150174
list.style.width = `${input.offsetWidth}px`;
151175
}
152-
176+
153177
input.focus();
154178

155179
form.addEventListener("submit", function _submit_form(e) {
180+
console.log('!!!!!!!!');
156181
e.preventDefault();
182+
e.stopPropagation();
157183
form.removeEventListener("submit", _submit_form);
158184
resolve(input.value);
159185
});
160186

161187
list.addEventListener("click", function _choose_item(e) {
188+
e.preventDefault();
162189
list.removeEventListener("click", _choose_item);
163190
if (e.target instanceof HTMLLIElement) {
164191
resolve(e.target.textContent);
165192
}
166193
});
167194

195+
list.addEventListener("keypress", function _choose_item(e) {
196+
e.preventDefault();
197+
const key = e.which || e.keyCode;
198+
if (key === 13) {
199+
list.removeEventListener("click", _choose_item);
200+
if (e.target instanceof HTMLLIElement) {
201+
resolve(e.target.textContent);
202+
}
203+
}
204+
});
205+
168206
reset.addEventListener("click", function _reset_click(e) {
207+
console.log('reject');
208+
e.preventDefault();
169209
close.removeEventListener("click", _reset_click);
170210
reject(e.target.id);
171211
});
172212

173213
close.addEventListener("click", function _close_click(e) {
214+
e.preventDefault();
174215
close.removeEventListener("click", _close_click);
175216
reject(e.target.id);
176217
});
@@ -184,77 +225,33 @@
184225
class SpeakToMeIcon {
185226
constructor() {
186227
console.log(`SpeakToMeIcon constructor ${this}`);
228+
const register = getSTMAnchors(document.domain);
187229
this.icon = document.createElement("button");
188230
this.icon.classList.add("stm-icon");
189231
this.icon.classList.add("stm-hidden");
190232
this.hasAnchor = false;
191-
document.body.appendChild(this.icon);
233+
this.input = document.getElementById(register.input);
234+
this.anchor = document.getElementById(register.anchor);
192235

193-
this.icon.addEventListener("click", on_stm_icon_click);
194-
195-
const self = this;
196-
197-
// Note: remove the event so and toggle has anchor to ensure the anchor doesn't move around
198-
document.body.addEventListener("focusin", function _set_anchor(event) {
199-
if (event.target.id === "stm-input") {
200-
return;
201-
}
202-
self.anchor_to(event.target);
203-
self.hasAnchor = true;
204-
});
205-
206-
// Check if an element is already focused in the document.
207-
if (document.hasFocus() && document.activeElement && !this.hasAnchor) {
208-
self.anchor_to(document.activeElement);
209-
}
210-
}
211-
212-
// util finding the right parent element for any given acceptable page
213-
// to add additional pages, review ACCEPTABLE_ANCHORS const above, and add appropriate pages to the manifest
214-
// TODO: this whole thing feels like a hack!
215-
find_ancestor(root_el) {
216-
let el = root_el;
217-
218-
219-
const currentNotAcceptable = (item, index, array) => {
220-
return item !== el.id;
221-
}
222-
223-
//traverse up the Dom Tree until it finds the right acceptable anchor
224-
// Dead end when we hit the body
225-
while (ACCEPTABLE_ANCHORS.every(currentNotAcceptable) && el !== document.body) {
226-
el = el.parentElement;
227-
}
228-
229-
return el;
230-
}
231-
232-
// this anchors the speak to me button to the closest acceptable DOM element (ui_anchor) and then unhides the button
233-
anchor_to(target) {
234-
console.log(`SpeakToMeIcon anchor_to ${target}`);
235-
236-
237-
if (
238-
!(
239-
target instanceof HTMLInputElement &&
240-
["text", "email", "search"].indexOf(target.type) >= 0
241-
)
242-
) {
243-
return;
236+
if (this.input.ownerDocument !== document) {
237+
return null;
244238
}
245239

246-
const ui_anchor = this.find_ancestor(target);
247-
this._input_field = target;
248-
ui_anchor.style.position = "relative";
249-
ui_anchor.append(this.icon);
240+
document.body.appendChild(this.icon);
241+
this.icon.addEventListener("click", on_stm_icon_click);
242+
this.input.focus();
243+
this.anchor.style.position = "relative";
244+
this.anchor.style.overflow = "visible";
245+
this.anchor.append(this.icon);
250246
this.icon.classList.remove("stm-hidden");
251247
}
252248

249+
253250
set_input(text) {
254251
console.log(`SpeakToMeIcon set_input ${text}`);
255-
this._input_field.value = text;
256-
this._input_field.focus();
257-
this._input_field.form.submit();
252+
this.input.value = text;
253+
this.input.focus();
254+
this.input.form.submit();
258255
}
259256
}
260257

@@ -537,7 +534,6 @@
537534
};
538535

539536
const stm_icon = new SpeakToMeIcon();
540-
541537
SpeakToMePopup.init();
542538

543539

extension/main.css

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@
66
align-items: stretch;
77
animation-fill-mode: forwards;
88
background-color: white;
9+
background-image: url('assets/ff-logo.png');
10+
background-position: bottom 2em left 2em;
11+
background-repeat: no-repeat;
12+
background-size: 60px 19px;
913
box-shadow: 0 0 2em gray;
1014
box-sizing: border-box;
1115
display: none;
@@ -76,6 +80,38 @@
7680
background-color: #F0F0F0;;
7781
}
7882

83+
#stm-feedback {
84+
background-color: #00C8D7;
85+
background-image: url('assets/feedback.svg');
86+
background-position: 4px 4px;
87+
background-repeat: no-repeat;
88+
background-size: 14px;
89+
border: 1px solid #00C8D7;
90+
border-radius: 3px;
91+
box-shadow: 0 1px 2px rgba(0,0,0,.1);
92+
color: #fff;
93+
cursor: pointer;
94+
display: block;
95+
float: right;
96+
font-size: 10px;
97+
line-height: 12px;
98+
padding: 4px 6px 4px 20px;
99+
position: absolute;
100+
bottom: 2em;
101+
right: 2em;
102+
z-index: 11;
103+
opacity: .7;
104+
}
105+
106+
#stm-feedback:hover,
107+
#stm-feedback:focus {
108+
background-color: #00b8c7;
109+
}
110+
111+
#stm-feedback:active {
112+
background-color: #00b8c7;
113+
}
114+
79115
#stm-animation-wrapper {
80116
background: transparent;
81117
height: 200px;
@@ -279,7 +315,7 @@
279315
.stm-icon:hover,
280316
.stm-icon:focus,
281317
#stm-submit-button:hover,
282-
#stm-submit-button:focus, {
318+
#stm-submit-button:focus {
283319
background-color: #00b8c7;
284320
}
285321

extension/manifest.json

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,40 @@
11
{
22
"manifest_version": 2,
3-
"name": "speak-to-me",
3+
"name": "Voice Fill",
44
"version": "1.2.1",
5+
"description": "Adds voice input to popular search pages in Firefox. Learn more about Voice Fill at https://testpilot.firefox.com",
56
"developer": {
67
"name": "Fabrice Desré",
7-
"url": "https://github.com/fabricedesre"
8+
"url": "https://github.com/mozilla/speaktome"
9+
},
10+
"icons": {
11+
"48": "assets/icon-48.png",
12+
"96": "assets/icon-96.png"
813
},
9-
1014
"applications": {
1115
"gecko": {
1216
"id": "speaktome@mozilla.com",
1317
"update_url": "https://testpilot.firefox.com/files/@speak-to-me/updates.json"
1418
}
1519
},
16-
1720
"content_scripts": [
1821
{
1922
"matches": [
2023
"https://www.google.com/*",
2124
"https://www.google.com/",
2225
"https://www.google.co.uk/*",
2326
"https://www.google.co.uk/",
27+
"https://www.google.ca/*",
28+
"https://www.google.ca/",
2429
"https://duckduckgo.com/",
2530
"https://duckduckgo.com/*",
26-
"https://yahoo.com/",
27-
"https://yahoo.com/*",
31+
"https://www.yahoo.com/",
32+
"https://www.yahoo.com/*",
33+
"https://search.yahoo.com/*",
2834
"https://uk.yahoo.com/",
29-
"https://uk.yahoo.com/*"
35+
"https://uk.yahoo.com/*",
36+
"https://ca.yahoo.com/",
37+
"https://ca.yahoo.com/*"
3038
],
3139
"js": ["bodymovin.js", "content.js", "webrtc_vad.js"],
3240
"css": ["main.css"]
@@ -39,7 +47,9 @@
3947
"assets/icon-close.svg",
4048
"assets/icon-mic.svg",
4149
"assets/icon-redo.svg",
42-
"assets/icon-done.svg"
50+
"assets/icon-done.svg",
51+
"assets/ff-logo.png",
52+
"assets/feedback.svg"
4353
],
4454
"permissions": ["<all_urls>"]
4555
}

0 commit comments

Comments
 (0)