Skip to content

Commit

Permalink
added events, fixes, typos
Browse files Browse the repository at this point in the history
  • Loading branch information
MarZab committed Jul 29, 2015
1 parent a810494 commit 4f56d29
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 20 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ build:
@echo "Building '$(VERSION)' $(FILENAME)..."
@cd "src" && 7za a -tzip "$(FILENAME)" *
@mv "src/$(FILENAME)" .
@7za a -tzip "$(FILENAME)" COPYING README
@7za a -tzip "$(FILENAME)" COPYING README.md
@echo "Done!"

clean:
Expand Down
2 changes: 1 addition & 1 deletion src/chrome/content/images/keyboard.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
78 changes: 60 additions & 18 deletions src/chrome/content/overlay.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,16 @@ var fxKeyboard = {
document.addEventListener("focus", this.onFocus, true);
document.addEventListener("blur", this.onFocus, true);

document.addEventListener("keypress", function () {
if (fxKeyboard.fromInside) {
fxKeyboard.fromInside = false;
return;
}
if (!fxKeyboard.keepOpen) {
fxKeyboard._setOpen(false);
}
}, true);

fxKeyboard.switchLocale(fxKeyboard.settings.locale_default);

},
Expand All @@ -40,13 +50,17 @@ var fxKeyboard = {
fxKeyboard.settings.key_height = this.prefs.getCharPref("key_height");
fxKeyboard.settings.main_max_width = this.prefs.getCharPref("main_max_width");

var locale_picker = fxKeyboard.prefs.getCharPref("locale_picker");
if (locale_picker) {
fxKeyboard.settings.locale_picker = locale_picker.split(' ');
}
fxKeyboard.settings.locale_picker = fxKeyboard.prefs.getCharPref("locale_picker")
.split(' ')
.filter(function(n){
return (n != '' && n != null && FxKeyboardLocales[n]);
});

var locale_default = fxKeyboard.prefs.getCharPref("locale_default");
if (locale_default && fxKeyboard.settings.locale_picker.indexOf(locale_default)) {
fxKeyboard.settings.locale_default = locale_default;
} else {
fxKeyboard.settings.locale_default = fxKeyboard.settings.locale_picker[0];
}

},
Expand Down Expand Up @@ -134,7 +148,7 @@ var fxKeyboard = {
fxKeyboard._dispatchAltKey(8);
},
'keepOpen': function () {
fxKeyboard.toogleKeepOpen();
fxKeyboard.toggleKeepOpen();
},
'toggleLocale': function () {
fxKeyboard.switchLocale();
Expand All @@ -160,7 +174,7 @@ var fxKeyboard = {
fxKeyboard.makeButtons();
},

toogleKeepOpen: function (keepOpen) {
toggleKeepOpen: function (keepOpen) {
if (keepOpen !== false && keepOpen !== true) {
keepOpen = !fxKeyboard.keepOpen;
}
Expand Down Expand Up @@ -198,8 +212,13 @@ var fxKeyboard = {
*/
state: 0,
keepOpen: false,
// temporaraly open, or switch locales
// temporary open, or switch locales
tempOpen: false,
fromInside: false, // key event was from inside

events: {
onFocus: []
},

// when a HTML element gets focus
onFocus: function () {
Expand All @@ -208,18 +227,21 @@ var fxKeyboard = {
var focus = document.commandDispatcher.focusedElement ||
document.commandDispatcher.focusedWindow.document.activeElement;
if (focus) {

var nodeName = focus.nodeName.toLowerCase();
var nodeType = focus.type;

// fxKB aware tag
if (focus.getAttribute('data-fxkeyboard') === 'false') {
// todo switch locale
} else {
var nodeName = focus.nodeName.toLowerCase();

if (nodeName in {
'input': '', 'select': '',
'option': '', 'textarea': '', 'textbox': ''
}) {
open = true;
} else {
var nodeType = focus.type;
if (nodeType && nodeType.toLowerCase() in {
'text':'','password':'','url':'','color':'','date':'','datetime':'',
'datetime-local':'','email':'','month':'','number':'','range':'',
Expand All @@ -229,6 +251,9 @@ var fxKeyboard = {
}
}
}
fxKeyboard.events.onFocus.forEach(function (f) {
open = f(open, focus, nodeName, nodeType);
});
}
if (fxKeyboard.keepOpen == true) {
// keep kb open regardless
Expand Down Expand Up @@ -313,6 +338,7 @@ var fxKeyboard = {
locale.side.forEach(function (rowitems) {
var row = document.createElementNS(XUL_NS, 'hbox');
row.setAttribute('flex', '1');
row.classList.add('items'+rowitems.length);
rowitems.forEach(function (item) {
row.appendChild(createButton(item));
});
Expand Down Expand Up @@ -344,12 +370,15 @@ var fxKeyboard = {

if (typeof key === 'string') {

button.label = key;
button.label = key.trim();
if (fxKeyboard.settings.repeat_all) {
button.setAttribute('type', 'repeat');
} else {
button.removeAttribute('type');
}
if (key.length > 1) {
button.classList.add('small');
}

} else {

Expand Down Expand Up @@ -417,6 +446,9 @@ var fxKeyboard = {
// enter a regular key into a focused element
_dispatchKey: function (key, target) {
if (!target) return;

fxKeyboard.fromInside = true;

var evt = gBrowser.selectedBrowser.contentDocument.createEvent("KeyboardEvent");
evt.initKeyEvent("keypress", true, true, null, false, false, false, false, 0, key);
target.dispatchEvent(evt);
Expand All @@ -439,6 +471,9 @@ var fxKeyboard = {
// send a special event to a focused element
_dispatchAltKey: function (key, target) {
if (!target) return;

fxKeyboard.fromInside = true;

var evt = gBrowser.selectedBrowser.contentDocument.createEvent("KeyboardEvent");
evt.initKeyEvent("keypress", true, true, null, false, false, false, false, key, 0);
target.dispatchEvent(evt);
Expand All @@ -462,7 +497,7 @@ var fxKeyboard = {
// 0 not active
// 1 active
// 2 locked
var buttons = document.querySelectorAll('.fxKeyboardButton.'+keyClass);
var buttons = document.querySelectorAll('.fxKeyboardButton.'+keyClass+',.toolbarbutton-1.'+keyClass);
if (buttons.length) {
[].forEach.call(buttons, function (button) {
if (state > 0) {
Expand All @@ -478,11 +513,15 @@ var fxKeyboard = {
},

pressToolbarButton: function () {
if (fxKeyboard.tempOpen) {
fxKeyboard.switchLocale();
} else {

// open regardless
fxKeyboard._setOpen(true);

if (fxKeyboard.settings.keep_closed && !fxKeyboard.tempOpen) {
// locked, unlock this time
fxKeyboard.tempOpen = true;
fxKeyboard._setOpen(true);
} else {
fxKeyboard.switchLocale();
}
},

Expand Down Expand Up @@ -522,8 +561,11 @@ var fxKeyboard = {

};

window.addEventListener("load", function(e) { fxKeyboard.startUp(); }, false);
window.addEventListener("unload", function(e) { fxKeyboard.shutDown(); }, false);
window.addEventListener("DOMContentLoaded", function (e) { fxKeyboard.DOMContentLoaded() }, true);
window.addEventListener("load", function load() {
window.removeEventListener("load", load, false);
fxKeyboard.startUp();
}, false);
window.addEventListener("unload", fxKeyboard.shutDown, false);
window.addEventListener("DOMContentLoaded", fxKeyboard.DOMContentLoaded, true);

// END fxKeyboard

0 comments on commit 4f56d29

Please sign in to comment.