aboutsummaryrefslogtreecommitdiff
path: root/resources/assets/javascripts/bootstrap/copyable_links.js
blob: b4f6fc6327232da6b56e5df4ef2b96603c862f6b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
import { $gettext } from '../lib/gettext';

$(document).on('click', 'a.copyable-link', function (event) {
    event.preventDefault();

    // Create dummy element and position it off screen
    // This element must be "visible" (as in "not hidden") or otherwise
    // the copy command will fail
    let dummy = $('<textarea>').val(this.href).css({
        position: 'absolute',
        left: '-9999px'
    }).appendTo('body');

    // Select text and copy it to clipboard
    dummy[0].select();
    document.execCommand('Copy');
    dummy.remove();

    STUDIP.eventBus.emit(
        'push-system-notification',
        { type: 'success', message: $gettext('Link wurde kopiert') }
    );
});