Skip to content

Commit

Permalink
fix: start handling android devices.
Browse files Browse the repository at this point in the history
  • Loading branch information
chjj committed Jun 27, 2014
1 parent c69340b commit 0b10f6c
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 6 deletions.
3 changes: 2 additions & 1 deletion example/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ <h1>term.js</h1>
cols: 80,
rows: 24,
useStyle: true,
screenKeys: true
screenKeys: true,
cursorBlink: false
});

term.on('data', function(data) {
Expand Down
1 change: 1 addition & 0 deletions example/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ io.sockets.on('connection', function(sock) {

socket.on('data', function(data) {
if (stream) stream.write('IN: ' + data + '\n-\n');
//console.log(JSON.stringify(data));
term.write(data);
});

Expand Down
23 changes: 18 additions & 5 deletions src/term.js
Original file line number Diff line number Diff line change
Expand Up @@ -470,8 +470,8 @@ Terminal.prototype.initGlobal = function() {

Terminal.bindCopy(document);

if (this.isIpad || this.isIphone) {
Terminal.fixIpad(document);
if (this.isMobile) {
this.fixMobile(document);
}

if (this.useStyle) {
Expand Down Expand Up @@ -598,10 +598,12 @@ Terminal.bindCopy = function(document) {
};

/**
* Fix iPad - no idea if this works
* Fix Mobile
*/

Terminal.fixIpad = function(document) {
Terminal.prototype.fixMobile = function(document) {
var self = this;

var textarea = document.createElement('textarea');
textarea.style.position = 'absolute';
textarea.style.left = '-32000px';
Expand All @@ -622,6 +624,15 @@ Terminal.fixIpad = function(document) {
setTimeout(function() {
textarea.focus();
}, 1000);

if (this.isAndroid) {
on(textarea, 'change', function() {
var value = textarea.textContent || textarea.value;
textarea.value = '';
textarea.textContent = '';
self.send(value + '\r');
});
}
};

/**
Expand Down Expand Up @@ -695,6 +706,8 @@ Terminal.prototype.open = function(parent) {
this.isMac = !!~this.context.navigator.userAgent.indexOf('Mac');
this.isIpad = !!~this.context.navigator.userAgent.indexOf('iPad');
this.isIphone = !!~this.context.navigator.userAgent.indexOf('iPhone');
this.isAndroid = !!~this.context.navigator.userAgent.indexOf('Android');
this.isMobile = this.isIpad || this.isIphone || this.isAndroid;
this.isMSIE = !!~this.context.navigator.userAgent.indexOf('MSIE');
}

Expand Down Expand Up @@ -733,7 +746,7 @@ Terminal.prototype.open = function(parent) {
// to focus and paste behavior.
on(this.element, 'focus', function() {
self.focus();
if (self.isIpad || self.isIphone) {
if (self.isMobile) {
Terminal._textarea.focus();
}
});
Expand Down

0 comments on commit 0b10f6c

Please sign in to comment.