Javascript: Add `copy-to-clipboard` behavior

Utilizes `CopyToClipboard.js` from ipl-web
This commit is contained in:
raviks789 2023-05-25 10:29:52 +02:00 committed by Johannes Meyer
parent 65b9024bc5
commit f74041e00a
2 changed files with 43 additions and 1 deletions

View File

@ -42,7 +42,8 @@ class JavaScript
'js/icinga/behavior/selectable.js',
'js/icinga/behavior/modal.js',
'js/icinga/behavior/input-enrichment.js',
'js/icinga/behavior/datetime-picker.js'
'js/icinga/behavior/datetime-picker.js',
'js/icinga/behavior/copy-to-clipboard.js'
];
protected static $vendorFiles = [];

View File

@ -0,0 +1,41 @@
(function (Icinga) {
"use strict";
try {
var CopyToClipboard = require('icinga/icinga-php-library/widget/CopyToClipboard');
} catch (e) {
console.warn('Unable to provide copy to clipboard feature. Libraries not available:', e);
return;
}
class CopyToClipboardBehavior extends Icinga.EventListener {
constructor(icinga)
{
super(icinga);
this.on('rendered', '#main > .container', this.onRendered, this);
/**
* Clipboard buttons
*
* @type {WeakMap<object, CopyToClipboard>}
* @private
*/
this._clipboards = new WeakMap();
}
onRendered(event)
{
let _this = event.data.self;
event.currentTarget.querySelectorAll('[data-icinga-clipboard]').forEach(button => {
_this._clipboards.set(button, new CopyToClipboard(button));
});
}
}
Icinga.Behaviors = Icinga.Behaviors || {};
Icinga.Behaviors.CopyToClipboardBehavior = CopyToClipboardBehavior;
})(Icinga);