From c343b9f59d78e0221b6e8f073b6bd6d42b0a68a6 Mon Sep 17 00:00:00 2001 From: XhmikosR Date: Wed, 14 Oct 2015 00:50:42 +0300 Subject: Replace ZeroClipboard with clipboard.js. Things left: 1. clear the selection after copy 2. add messages for success and error --- docs/assets/js/src/application.js | 61 ++++++++++++++------------------------- 1 file changed, 21 insertions(+), 40 deletions(-) (limited to 'docs/assets/js/src') diff --git a/docs/assets/js/src/application.js b/docs/assets/js/src/application.js index 6d3226d9a..85a578649 100644 --- a/docs/assets/js/src/application.js +++ b/docs/assets/js/src/application.js @@ -9,7 +9,7 @@ * details, see https://creativecommons.org/licenses/by/3.0/. */ -/* global ZeroClipboard, anchors */ +/* global Clipboard, anchors */ !function ($) { 'use strict'; @@ -36,50 +36,31 @@ e.preventDefault() }) - // Config ZeroClipboard - ZeroClipboard.config({ - moviePath: '/assets/flash/ZeroClipboard.swf', - hoverClass: 'btn-clipboard-hover' - }) - // Insert copy to clipboard button before .highlight $('.highlight').each(function () { - var btnHtml = '
Copy
' + var btnHtml = '
Copy
' $(this).before(btnHtml) }) - var zeroClipboard = new ZeroClipboard($('.btn-clipboard')) - var $htmlBridge = $('#global-zeroclipboard-html-bridge') - - // Handlers for ZeroClipboard - zeroClipboard.on('load', function () { - $htmlBridge - .data('placement', 'top') - .attr('title', 'Copy to clipboard') - .tooltip() - - // Copy to clipboard - zeroClipboard.on('dataRequested', function (client) { - var highlight = $(this).parent().nextAll('.highlight').first() - client.setText(highlight.text()) - }) - - // Notify copy success and reset tooltip title - zeroClipboard.on('complete', function () { - $htmlBridge - .attr('title', 'Copied!') - .tooltip('fixTitle') - .tooltip('show') - .attr('title', 'Copy to clipboard') - .tooltip('fixTitle') - }) - }) - // Hide copy button when no Flash is found - // or wrong Flash version is present - zeroClipboard.on('noflash wrongflash', function () { - $('.zero-clipboard').remove() - ZeroClipboard.destroy() - }) + var clipboard = new Clipboard('.bd-clipboard', { + target: function (trigger) { + return trigger.nextElementSibling; + } + }); + + /* + clipboard.on('success', function (e) { + console.info('Action:', e.action); + console.info('Text:', e.text); + console.info('Trigger:', e.trigger); + + e.clearSelection(); + }); + + clipboard.on('error', function (e) { + console.error('Action:', e.action); + console.error('Trigger:', e.trigger); + });*/ }) -- cgit v1.2.3 From e4590aca61deb2d2ddd2853593f8a95fea5b9a47 Mon Sep 17 00:00:00 2001 From: Zeno Rocha Date: Wed, 14 Oct 2015 00:51:03 +0300 Subject: Fix the remaining issues for the clipboard.js switch. --- docs/assets/js/src/application.js | 37 +++++++++++++++++++++++-------------- 1 file changed, 23 insertions(+), 14 deletions(-) (limited to 'docs/assets/js/src') diff --git a/docs/assets/js/src/application.js b/docs/assets/js/src/application.js index 85a578649..1fec20079 100644 --- a/docs/assets/js/src/application.js +++ b/docs/assets/js/src/application.js @@ -38,29 +38,38 @@ // Insert copy to clipboard button before .highlight $('.highlight').each(function () { - var btnHtml = '
Copy
' + var btnHtml = '
Copy
' $(this).before(btnHtml) + $('.btn-clipboard').tooltip() }) - var clipboard = new Clipboard('.bd-clipboard', { + var clipboard = new Clipboard('.btn-clipboard', { target: function (trigger) { - return trigger.nextElementSibling; + return trigger.parentNode.nextElementSibling } - }); + }) - /* clipboard.on('success', function (e) { - console.info('Action:', e.action); - console.info('Text:', e.text); - console.info('Trigger:', e.trigger); - - e.clearSelection(); - }); + $(e.trigger) + .attr('title', 'Copied!') + .tooltip('_fixTitle') + .tooltip('show') + .attr('title', 'Copy to clipboard') + .tooltip('_fixTitle') + + e.clearSelection() + }) clipboard.on('error', function (e) { - console.error('Action:', e.action); - console.error('Trigger:', e.trigger); - });*/ + var fallbackMsg = /Mac/i.test(navigator.userAgent) ? 'Press \u2318 to copy' : 'Press Ctrl-C to copy' + + $(e.trigger) + .attr('title', fallbackMsg) + .tooltip('_fixTitle') + .tooltip('show') + .attr('title', 'Copy to clipboard') + .tooltip('_fixTitle') + }) }) -- cgit v1.2.3