1
0
mirror of https://github.com/twbs/bootstrap.git synced 2025-09-25 12:59:05 +02:00

Replace ZeroClipboard with clipboard.js.

Things left:
1. clear the selection after copy
2. add messages for success and error
This commit is contained in:
XhmikosR
2015-10-14 00:50:42 +03:00
parent e544bf4cf8
commit c343b9f59d
8 changed files with 32 additions and 53 deletions

View File

@@ -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 = '<div class="zero-clipboard"><span class="btn-clipboard">Copy</span></div>'
var btnHtml = '<div class="bd-clipboard"><span class="btn-clipboard">Copy</span></div>'
$(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()
var clipboard = new Clipboard('.bd-clipboard', {
target: function (trigger) {
return trigger.nextElementSibling;
}
});
// Copy to clipboard
zeroClipboard.on('dataRequested', function (client) {
var highlight = $(this).parent().nextAll('.highlight').first()
client.setText(highlight.text())
})
/*
clipboard.on('success', function (e) {
console.info('Action:', e.action);
console.info('Text:', e.text);
console.info('Trigger:', e.trigger);
// 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')
})
})
e.clearSelection();
});
// Hide copy button when no Flash is found
// or wrong Flash version is present
zeroClipboard.on('noflash wrongflash', function () {
$('.zero-clipboard').remove()
ZeroClipboard.destroy()
})
clipboard.on('error', function (e) {
console.error('Action:', e.action);
console.error('Trigger:', e.trigger);
});*/
})

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long