Skip to content

Commit

Permalink
Fix CTRL+V in Firefox #283 and throw excption when event.key is not s…
Browse files Browse the repository at this point in the history
…upported
  • Loading branch information
jcubic committed Feb 7, 2017
1 parent 4e1f769 commit 80e80fb
Show file tree
Hide file tree
Showing 10 changed files with 109 additions and 52 deletions.
2 changes: 1 addition & 1 deletion css/jquery.terminal-1.0.1.css
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
* Copyright (c) 2011-2017 Jakub Jankiewicz <http://jcubic.pl>
* Released under the MIT license
*
* Date: Sun, 05 Feb 2017 17:28:27 +0000
* Date: Tue, 07 Feb 2017 14:11:54 +0000
*/
.terminal .terminal-output .format, .cmd .format,
.cmd .prompt, .cmd .prompt div, .terminal .terminal-output div div{
Expand Down
2 changes: 1 addition & 1 deletion css/jquery.terminal-1.0.1.min.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion css/jquery.terminal.css
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
* Copyright (c) 2011-2017 Jakub Jankiewicz <http://jcubic.pl>
* Released under the MIT license
*
* Date: Sun, 05 Feb 2017 17:28:27 +0000
* Date: Tue, 07 Feb 2017 14:11:54 +0000
*/
.terminal .terminal-output .format, .cmd .format,
.cmd .prompt, .cmd .prompt div, .terminal .terminal-output div div{
Expand Down
2 changes: 1 addition & 1 deletion css/jquery.terminal.min.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

47 changes: 33 additions & 14 deletions js/jquery.terminal-1.0.1.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
* Copyright (c) 2007-2013 Alexandru Marasteanu <hello at alexei dot ro>
* licensed under 3 clause BSD license
*
* Date: Sun, 05 Feb 2017 17:28:26 +0000
* Date: Tue, 07 Feb 2017 14:11:53 +0000
*/

/* TODO:
Expand Down Expand Up @@ -946,6 +946,10 @@
return len > command.length ? command.length : len;
}
function get_key(e) {
if (!e.key) {
throw new Error('key event property not supported try ' +
'https://github.com/cvan/keyboardevent-key-polyfill');
}
var key = e.key.toUpperCase();
if (key === 'CONTROL') {
return 'CTRL';
Expand Down Expand Up @@ -1582,6 +1586,9 @@
}
if ($.isFunction(keymap[key])) {
result = keymap[key]();
if (result === true) {
return;
}
if (result !== undefined) {
return result;
}
Expand Down Expand Up @@ -1688,7 +1695,16 @@
if (typeof new_keymap === 'undefined') {
return keymap;
} else {
keymap = $.extend({}, default_keymap, new_keymap || {});
keymap = $.extend(
{},
default_keymap,
$.omap(new_keymap || {}, function(key, fn) {
return function(e) {
// new keymap function will get default as 2nd argument
return fn(e, default_keymap[key]);
};
})
);
return self;
}
},
Expand Down Expand Up @@ -2427,9 +2443,8 @@
}
}
};

// -----------------------------------------------------------------------
// Helper plugins
// Helper plugins and functions
// -----------------------------------------------------------------------
$.fn.visible = function() {
return this.css('visibility', 'visible');
Expand All @@ -2438,6 +2453,14 @@
return this.css('visibility', 'hidden');
};
// -----------------------------------------------------------------------
function warn(msg) {
if (console && console.warn) {
console.warn(msg);
} else {
throw new Error('WARN: ' + msg);
}
}
// -----------------------------------------------------------------------
// JSON-RPC CALL
// -----------------------------------------------------------------------
var ids = {}; // list of url based ids of JSON-RPC
Expand Down Expand Up @@ -2480,13 +2503,8 @@
success: function(response, status, jqXHR) {
var content_type = jqXHR.getResponseHeader('Content-Type');
if (!content_type.match(/(application|text)\/json/)) {
var msg = 'Response Content-Type is neither application/json' +
' nor text/json';
if (console && console.warn) {
console.warn(msg);
} else {
throw new Error('WARN: ' + msg);
}
warn('Response Content-Type is neither application/json' +
' nor text/json');
}
var json;
try {
Expand Down Expand Up @@ -3804,7 +3822,7 @@
// throw e; // it will be catched by terminal
} finally {
onPause = $.noop;
if (!was_paused && self.enabled()) {
if (!was_paused) {
// resume login if user didn't call pause in onInit
// if user pause in onInit wait with exec until it
// resume
Expand Down Expand Up @@ -3904,7 +3922,8 @@
}
return false;
},
'CTRL+V': function() {
'CTRL+V': function(e, original) {
original(e);
self.oneTime(1, function() {
scroll_to_bottom();
});
Expand Down Expand Up @@ -5164,7 +5183,7 @@
} else {
init();
}
if (!was_paused && self.enabled()) {
if (!was_paused) {
self.resume();
}
});
Expand Down
9 changes: 4 additions & 5 deletions js/jquery.terminal-1.0.1.min.js

Large diffs are not rendered by default.

Loading

0 comments on commit 80e80fb

Please sign in to comment.