forked from BillyBlaze/OctoPrint-TouchUI
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
51e1508
commit bfa7fec
Showing
2 changed files
with
184 additions
and
171 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,171 +1,177 @@ | ||
TouchUI.prototype.components.keyboard = { | ||
|
||
isActive: ko.observable(false), | ||
config: { | ||
|
||
default: { | ||
|
||
display: { | ||
'accept' : 'Save', | ||
'bksp' : ' ', | ||
'default': 'ABC', | ||
'meta1' : '.?123', | ||
'meta2' : '#+=' | ||
}, | ||
|
||
layout: 'custom', | ||
customLayout: { | ||
'default': [ | ||
'q w e r t y u i o p', | ||
'a s d f g h j k l', | ||
'{bksp} {s} z x c v b n m', | ||
'{accept} {c} {left} {right} {meta1} {space}' | ||
], | ||
'shift': [ | ||
'Q W E R T Y U I O P', | ||
'A S D F G H J K L', | ||
'{bksp} {s} Z X C V B N M', | ||
'{accept} {c} {left} {right} {meta1} {space}' | ||
], | ||
'meta1': [ | ||
'1 2 3 4 5 6 7 8 9 0', | ||
'- / : ; ( ) \u20ac & @', | ||
'{bksp} {meta2} . , ? ! \' "', | ||
'{accept} {c} {left} {right} {default} {space}' | ||
], | ||
'meta2': [ | ||
'[ ] { } # % ^ * + =', | ||
'_ \\ | ~ < > $ \u00a3 \u00a5', | ||
'{bksp} {meta1} . , ? ! \' "', | ||
'{accept} {c} {left} {right} {default} {space}' | ||
] | ||
} | ||
|
||
}, | ||
terminal: { | ||
display: { | ||
'bksp' : ' ', | ||
'accept' : 'Save', | ||
'default': 'ABC', | ||
'meta1' : '.?123', | ||
'meta2' : '#+=' | ||
}, | ||
|
||
layout: 'custom', | ||
customLayout: { | ||
'default': [ | ||
'Q W E R T Y U I O P', | ||
'A S D F G H J K L', | ||
'{bksp} {s} Z X C V B N M', | ||
'{accept} {c} {left} {right} {meta1} {space}' | ||
], | ||
'meta1': [ | ||
'1 2 3 4 5 6 7 8 9 0', | ||
'- / : ; ( ) \u20ac & @', | ||
'{bksp} {meta2} . , ? ! \' "', | ||
'{accept} {c} {left} {right} {default} {space}' | ||
], | ||
'meta2': [ | ||
'[ ] { } # % ^ * + =', | ||
'_ \\ | ~ < > $ \u00a3 \u00a5', | ||
'{bksp} {meta1} . , ? ! \' "', | ||
'{accept} {c} {left} {right} {default} {space}' | ||
] | ||
} | ||
|
||
}, | ||
number: { | ||
display: { | ||
'bksp' : ' ', | ||
'a' : 'Save', | ||
'c' : 'Cancel' | ||
}, | ||
|
||
layout: 'custom', | ||
customLayout: { | ||
'default' : [ | ||
'{bksp} 1 2 3 4 5 6 7 ', | ||
'{accept} {c} {left} {right} 8 9 0 - , . ' | ||
] | ||
}, | ||
} | ||
|
||
|
||
}, | ||
|
||
init: function() { | ||
var self = this; | ||
|
||
// Add virtual keyboard | ||
var obj = { | ||
visible: self.components.keyboard.onShow, | ||
beforeClose: self.components.keyboard.onClose | ||
}; | ||
|
||
var notThis = ['[type="file"]','[type="checkbox"]','[type="radio"]']; | ||
$(document).on("mousedown", 'input:not('+notThis+'), textarea', function(e) { | ||
var $elm = $(e.target); | ||
|
||
if(!self.components.keyboard.isActive()) { | ||
|
||
if($elm.data("keyboard")) { | ||
$elm.data("keyboard").close().destroy(); | ||
} | ||
|
||
} else { | ||
|
||
if(!self.settings.hasTouch) { | ||
|
||
// Force iScroll to stop following the mouse (bug) | ||
self.scroll.currentActive._end(e); | ||
setTimeout(function() { | ||
self.scroll.currentActive.scrollToElement($elm[0], 200, 0, -30); | ||
}, 0); | ||
|
||
} | ||
|
||
// $elm already has a keyboard | ||
if($elm.data("keyboard")) { | ||
$elm.data('keyboard').reveal(); | ||
return; | ||
} | ||
|
||
if($elm.attr("type") === "number") { | ||
$elm.keyboard($.extend(self.components.keyboard.config.number, obj)); | ||
} else if($elm.attr("id") === "terminal-command") { | ||
$elm.keyboard($.extend(self.components.keyboard.config.terminal, obj)); | ||
} else { | ||
$elm.keyboard($.extend(self.components.keyboard.config.default, obj)); | ||
} | ||
} | ||
|
||
}); | ||
}, | ||
|
||
onShow: function(event, keyboard, el) { | ||
// Set the input cursor to the end of the input field | ||
setTimeout(function() { | ||
var prev = keyboard.$preview.get(0); | ||
if (prev) { | ||
prev.selectionStart = prev.selectionEnd = prev.value.length; | ||
} | ||
}, 10); | ||
|
||
keyboard.$keyboard.find("button").on("mousedown", function(e) { | ||
$(e.target).addClass("touch-focus"); | ||
|
||
if(typeof $(e.target).data("timeout") !== "function") { | ||
clearTimeout($(e.target).data("timeout")); | ||
} | ||
var timeout = setTimeout(function() { | ||
$(e.target).removeClass("touch-focus").data("timeout", ""); | ||
}, 600); | ||
$(e.target).data("timeout", timeout); | ||
}); | ||
}, | ||
|
||
onClose: function(event, keyboard, el) { | ||
keyboard.$keyboard.find("button").off("mousedown"); | ||
} | ||
|
||
} | ||
TouchUI.prototype.components.keyboard = { | ||
|
||
isActive: ko.observable(false), | ||
config: { | ||
|
||
default: { | ||
usePreview : false, | ||
autoAccept : true, | ||
|
||
display: { | ||
'accept' : 'Save', | ||
'bksp' : ' ', | ||
'default': 'ABC', | ||
'meta1' : '.?123', | ||
'meta2' : '#+=' | ||
}, | ||
|
||
layout: 'custom', | ||
customLayout: { | ||
'default': [ | ||
'q w e r t y u i o p', | ||
'a s d f g h j k l', | ||
'{bksp} {s} z x c v b n m', | ||
'{accept} {c} {left} {right} {meta1} {space}' | ||
], | ||
'shift': [ | ||
'Q W E R T Y U I O P', | ||
'A S D F G H J K L', | ||
'{bksp} {s} Z X C V B N M', | ||
'{accept} {c} {left} {right} {meta1} {space}' | ||
], | ||
'meta1': [ | ||
'1 2 3 4 5 6 7 8 9 0', | ||
'- / : ; ( ) \u20ac & @', | ||
'{bksp} {meta2} . , ? ! \' "', | ||
'{accept} {c} {left} {right} {default} {space}' | ||
], | ||
'meta2': [ | ||
'[ ] { } # % ^ * + =', | ||
'_ \\ | ~ < > $ \u00a3 \u00a5', | ||
'{bksp} {meta1} . , ? ! \' "', | ||
'{accept} {c} {left} {right} {default} {space}' | ||
] | ||
} | ||
|
||
}, | ||
terminal: { | ||
usePreview : false, | ||
autoAccept : true, | ||
display: { | ||
'bksp' : ' ', | ||
'accept' : 'Save', | ||
'default': 'ABC', | ||
'meta1' : '.?123', | ||
'meta2' : '#+=' | ||
}, | ||
|
||
layout: 'custom', | ||
customLayout: { | ||
'default': [ | ||
'Q W E R T Y U I O P', | ||
'A S D F G H J K L', | ||
'{bksp} {s} Z X C V B N M', | ||
'{accept} {c} {left} {right} {meta1} {space}' | ||
], | ||
'meta1': [ | ||
'1 2 3 4 5 6 7 8 9 0', | ||
'- / : ; ( ) \u20ac & @', | ||
'{bksp} {meta2} . , ? ! \' "', | ||
'{accept} {c} {left} {right} {default} {space}' | ||
], | ||
'meta2': [ | ||
'[ ] { } # % ^ * + =', | ||
'_ \\ | ~ < > $ \u00a3 \u00a5', | ||
'{bksp} {meta1} . , ? ! \' "', | ||
'{accept} {c} {left} {right} {default} {space}' | ||
] | ||
} | ||
|
||
}, | ||
number: { | ||
usePreview : false, | ||
autoAccept : true, | ||
display: { | ||
'bksp' : ' ', | ||
'a' : 'Save', | ||
'c' : 'Cancel' | ||
}, | ||
|
||
layout: 'custom', | ||
customLayout: { | ||
'default' : [ | ||
'{bksp} 1 2 3 4 5 6 7 ', | ||
'{accept} {c} {left} {right} 8 9 0 - , . ' | ||
] | ||
}, | ||
} | ||
|
||
|
||
}, | ||
|
||
init: function() { | ||
var self = this; | ||
|
||
// Add virtual keyboard | ||
var obj = { | ||
visible: self.components.keyboard.onShow, | ||
beforeClose: self.components.keyboard.onClose | ||
}; | ||
|
||
var notThis = ['[type="file"]','[type="checkbox"]','[type="radio"]']; | ||
$(document).on("mousedown", 'input:not('+notThis+'), textarea', function(e) { | ||
var $elm = $(e.target); | ||
|
||
if(!self.components.keyboard.isActive()) { | ||
|
||
if($elm.data("keyboard")) { | ||
$elm.data("keyboard").close().destroy(); | ||
} | ||
|
||
} else { | ||
|
||
if(!self.settings.hasTouch) { | ||
|
||
// Force iScroll to stop following the mouse (bug) | ||
self.scroll.currentActive._end(e); | ||
setTimeout(function() { | ||
self.scroll.currentActive.scrollToElement($elm[0], 200, 0, -30); | ||
}, 0); | ||
|
||
} | ||
|
||
// $elm already has a keyboard | ||
if($elm.data("keyboard")) { | ||
$elm.data('keyboard').reveal(); | ||
return; | ||
} | ||
|
||
if($elm.attr("type") === "number") { | ||
$elm.keyboard($.extend(self.components.keyboard.config.number, obj)); | ||
} else if($elm.attr("id") === "terminal-command") { | ||
$elm.keyboard($.extend(self.components.keyboard.config.terminal, obj)); | ||
} else { | ||
$elm.keyboard($.extend(self.components.keyboard.config.default, obj)); | ||
} | ||
} | ||
|
||
}); | ||
}, | ||
|
||
onShow: function(event, keyboard, el) { | ||
// Set the input cursor to the end of the input field | ||
setTimeout(function() { | ||
var prev = keyboard.$preview.get(0); | ||
if (prev) { | ||
prev.selectionStart = prev.selectionEnd = prev.value.length; | ||
} | ||
}, 10); | ||
|
||
keyboard.$keyboard.find("button").on("mousedown", function(e) { | ||
$(e.target).addClass("touch-focus"); | ||
|
||
if(typeof $(e.target).data("timeout") !== "function") { | ||
clearTimeout($(e.target).data("timeout")); | ||
} | ||
var timeout = setTimeout(function() { | ||
$(e.target).removeClass("touch-focus").data("timeout", ""); | ||
}, 600); | ||
$(e.target).data("timeout", timeout); | ||
}); | ||
}, | ||
|
||
onClose: function(event, keyboard, el) { | ||
keyboard.$keyboard.find("button").off("mousedown"); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters