/* Check for disable-clipbboard parameter to be passed in */ var _disable_clipboard_tst = $('[data-clipboard]').first().attr('data-clipboard'); var _disable_clipboard = ( (_disable_clipboard_tst === undefined) || (_disable_clipboard_tst === "") ) ? false : (_disable_clipboard_tst.toLowerCase() == 'true'); /* console.log("_disable_clipboard: " + _disable_clipboard); */ var __unique_identifier = 164; jQuery(document).ready(function ($) { //Only add copy to clipboard support if enabled if (_disable_clipboard !== true) { // for each codeblock, add a button to the bottom and mark both codeblock and button with a unique identifier $("table.highlighttable").each(function () { wrapCodeBlock($(this)); }); } function wrapCodeBlock(codeBlock) { console.log("located a codeblock"); var this_id = "copy_" + __unique_identifier; codeBlock.find("td.code").children("div.highlight").attr('id', this_id); codeBlock.wrap('
'); codeBlock.after('
'); __unique_identifier += 38; } }); // Clipboard.js initiator var clipboard = new ClipboardJS('.btn'); clipboard.on('success', function (e) { console.log(e); $(e.trigger).text("Copied!"); e.clearSelection(); setTimeout(function () { $(e.trigger).text("Copy"); }, 2500); }); clipboard.on('error', function (e) { $(e.trigger).text("Not Supported"); setTimeout(function () { $(e.trigger).text("Copy"); }, 2500); });