--- regenerate: false --- {% capture cache %} {% comment %} # ----------------------------------------------------------------------------- # ~/assets/themes/j1/adapter/js/clipboard.js # Liquid template to adapt Clipboard for J1 Template # # Product/Info: # https://jekyll.one # # Copyright (C) 2021 Juergen Adams # # J1 Template is licensed under the MIT License. # For details, see https://jekyll.one # ----------------------------------------------------------------------------- # Test data: # {{ liquid_var | debug }} # ----------------------------------------------------------------------------- # NOTE: # ----------------------------------------------------------------------------- {% endcomment %} {% comment %} Set config files -------------------------------------------------------------------------------- {% endcomment %} {% comment %} Set config data -------------------------------------------------------------------------------- {% endcomment %} {% assign environment = site.environment %} {% assign production = false %} {% if environment == 'prod' or environment == 'production' %} {% assign production = true %} {% endif %} /* # ----------------------------------------------------------------------------- # ~/assets/themes/j1/adapter/js/clipboard.js # JS Adapter for Clipboard # # Product/Info: # {{site.data.j1_config.theme_author_url}} # # Copyright (C) 2021 Juergen Adams # # J1 Template is licensed under the MIT License. # For details, see {{site.data.j1_config.theme_author_url}} # ----------------------------------------------------------------------------- # NOTE: # ----------------------------------------------------------------------------- # Adapter generated: {{site.time}} # ----------------------------------------------------------------------------- */ // ----------------------------------------------------------------------------- // ESLint shimming // ----------------------------------------------------------------------------- /* eslint indent: "off" */ // ----------------------------------------------------------------------------- 'use strict'; j1.adapter['clipboard'] = (function (j1, window) { // --------------------------------------------------------------------------- // globals // --------------------------------------------------------------------------- var environment = '{{environment}}'; var moduleOptions = {}; var logger; var logText; var _this; var clipboardJS; var language; var btnTitle; var btnText; var btnResponseText; // --------------------------------------------------------------------------- // main object // --------------------------------------------------------------------------- return { // ------------------------------------------------------------------------- // module initializer // ------------------------------------------------------------------------- init: function (options) { // ----------------------------------------------------------------------- // globals // ----------------------------------------------------------------------- _this = j1.adapter.clipboard; language = '{{site.language}}'; logger = log4javascript.getLogger('j1.adapter.clipboard'); // ----------------------------------------------------------------------- // defaults // ----------------------------------------------------------------------- var settings = $.extend({ module_name: 'j1.adapter.clipboard', generated: '{{site.time}}' }, options); // initialize state flag _this.state = 'started'; logText = '\n' + 'initialization: started'; logger.info(logText); if (language == 'en') { btnTitle = 'to clipboard'; btnText = 'Copy'; btnResponseText = 'copied!'; } else if (language == 'de') { btnTitle = 'zur Zwischenablage'; btnText = 'Kopieren'; btnResponseText = 'kopiert!'; } else { btnTitle = 'to clipboard'; btnText = 'Copy'; btnResponseText = 'copied!'; } // initialize ClipboardJS if page is loaded var dependencies_met_j1_finished = setInterval(function() { if ( j1.getState() == 'finished' ) { logText = '\n' + 'create clipboard'; logger.info(logText); clipboardJS = new ClipboardJS('.btn-clipboard', { target: function target(trigger) { return trigger.parentNode.nextElementSibling; } }); _this.initClipButtons(); _this.initEventHandler(clipboardJS); clearInterval(dependencies_met_j1_finished); logger.info('\n' + 'met dependencies for: j1'); _this.setState('finished'); logger.info('\n' + 'state: ' + _this.getState()); logger.info('\n' + 'module initialized successfully'); } }, 25); // END dependencies_met_j1_finished }, // ------------------------------------------------------------------------- // initClipboard // Create copy-to-clipboard for all pages // ------------------------------------------------------------------------- initClipButtons: function () { // insert copy to clipboard button before all elements having a // class of ".highlight" assigned to (e.g. Asciidoc source blocks) $('.highlight').each(function () { // Check if no clipboard should be applied var isNoClip = $(this).closest('.noclip'); if ( isNoClip.length == 0) { var btnHtml = ''; btnHtml = '
' + btnText + '
'; $(this).before(btnHtml); $('.btn-clipboard').tooltip(); } }); }, // END initClipboard // ------------------------------------------------------------------------- // Event handler // ------------------------------------------------------------------------- initEventHandler: function (clipboard) { // Manage clipboard events clipboard.on('success', function (e) { $(e.trigger).attr('title', btnResponseText).tooltip('_fixTitle').tooltip('show').attr('title', btnTitle).tooltip('_fixTitle'); var logger = log4javascript.getLogger('j1.initClipboard'); var logText = '\n' + 'initialization copy-to-clipboard sucessfull'; logger.debug(logText); /* Cleanup clipped data for trailing numbers */ var splitted = e.text.split('\n'); var concat; var i; for (i=0; i