From f72d4a175d44283e1d2d35bccff706093600c1c2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ale=C5=A1=20Smodi=C5=A1?= Date: Fri, 2 Oct 2015 11:07:52 +0200 Subject: Bugfix console: remove click and blur event handlers on destroy, so new instances work correctly. --- js/codeq/console.js | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'js') diff --git a/js/codeq/console.js b/js/codeq/console.js index 859b064..ebf09cc 100644 --- a/js/codeq/console.js +++ b/js/codeq/console.js @@ -159,6 +159,8 @@ return result; }; + var instanceCounter = 1; // for generating unique console instance numbers + codeq.makeConsole = function (jqElt, options) { var lines = [],// console content, line descriptors of the form {'content': 'string', 'classNames': [], 'jqLine': jQuery object, 'row': number} maxLines = (options && options.maxLines) || 10000, // how many lines to display at most @@ -172,6 +174,7 @@ history = [], // the list of entered lines, it is only appended currentHistory = [], // the list of entered lines, some possibly modified (it is copied from history on each new line editing) currentHistoryIndex = -1, + instanceNumber = instanceCounter++, // unique instace number, to be used with stuff tied to this instance, e.g.: jqElt events, life-cycle debug output renderSpan = function (lineDescriptor, startCol, length) { var jqLine = lineDescriptor.jqLine, @@ -751,6 +754,8 @@ delete handler[i]; } } + jqElt.off('click.console' + instanceNumber); + jqElt.off('blur.console' + instanceNumber); jqElt.empty(); jqElt = null; options = null; @@ -910,11 +915,11 @@ jqElt.empty(); jqElt.append(jqContent); jqElt.append(jqInput); - jqElt.on('click', function () { + jqElt.on('click.console' + instanceNumber, function () { // set focus to the textarea so we pick up keypresses jqInput.css('position', 'fixed').focus(); }); - jqElt.on('blur', function () { + jqElt.on('blur.console' + instanceNumber, function () { jqInput.css('position', 'absolute'); }); -- cgit v1.2.1