Destroy previous Clipboard object before creating it again

As a new Clipboard object needs to be created again when its
corresponding button is rerendered the previous object is now explicitly
destroyed to ensure proper lifecycle management.

Signed-off-by: Daniel Calviño Sánchez <danxuliu@gmail.com>
This commit is contained in:
Daniel Calviño Sánchez 2019-08-19 23:30:53 +02:00
Родитель b21fb210b7
Коммит 2c3994e78d
2 изменённых файлов: 16 добавлений и 6 удалений

Просмотреть файл

@ -298,12 +298,17 @@
* Clipboard * Clipboard
*/ */
initClipboard: function() { initClipboard: function() {
if (this._clipboard) {
this._clipboard.destroy();
delete this._clipboard;
}
if (this.ui.clipboardButton.length === 0) { if (this.ui.clipboardButton.length === 0) {
return; return;
} }
var clipboard = new Clipboard(this.ui.clipboardButton[0]); this._clipboard = new Clipboard(this.ui.clipboardButton[0]);
clipboard.on('success', function(e) { this._clipboard.on('success', function(e) {
var $input = $(e.trigger); var $input = $(e.trigger);
$input.tooltip('hide') $input.tooltip('hide')
.attr('data-original-title', t('core', 'Link copied!')) .attr('data-original-title', t('core', 'Link copied!'))
@ -316,7 +321,7 @@
.tooltip('fixTitle'); .tooltip('fixTitle');
}, 3000); }, 3000);
}); });
clipboard.on('error', function (e) { this._clipboard.on('error', function (e) {
var $input = $(e.trigger); var $input = $(e.trigger);
var actionMsg = ''; var actionMsg = '';
if (/iPhone|iPad/i.test(navigator.userAgent)) { if (/iPhone|iPad/i.test(navigator.userAgent)) {

Просмотреть файл

@ -271,12 +271,17 @@
* Clipboard * Clipboard
*/ */
initClipboard: function() { initClipboard: function() {
if (this._clipboard) {
this._clipboard.destroy();
delete this._clipboard;
}
if (this.ui.clipboardButton.length === 0) { if (this.ui.clipboardButton.length === 0) {
return; return;
} }
var clipboard = new Clipboard(this.ui.clipboardButton[0]); this._clipboard = new Clipboard(this.ui.clipboardButton[0]);
clipboard.on('success', function(e) { this._clipboard.on('success', function(e) {
var $input = $(e.trigger); var $input = $(e.trigger);
$input.tooltip('hide') $input.tooltip('hide')
.attr('data-original-title', t('core', 'Link copied!')) .attr('data-original-title', t('core', 'Link copied!'))
@ -289,7 +294,7 @@
.tooltip('fixTitle'); .tooltip('fixTitle');
}, 3000); }, 3000);
}); });
clipboard.on('error', function (e) { this._clipboard.on('error', function (e) {
var $input = $(e.trigger); var $input = $(e.trigger);
var actionMsg = ''; var actionMsg = '';
if (/iPhone|iPad/i.test(navigator.userAgent)) { if (/iPhone|iPad/i.test(navigator.userAgent)) {