0
0
mirror of https://github.com/twbs/bootstrap.git synced 2024-11-29 11:24:18 +01:00

Merge pull request #17751 from twbs/v4-dev-xmr-clipboardjs

Replace ZeroClipboard with clipboard.js.
This commit is contained in:
XhmikosR 2015-10-24 19:07:47 +03:00
commit f24636279d
11 changed files with 54 additions and 69 deletions

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

Binary file not shown.

File diff suppressed because one or more lines are too long

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,49 +36,39 @@
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" title="Copy to clipboard">Copy</span></div>'
$(this).before(btnHtml)
$('.btn-clipboard').tooltip()
})
var zeroClipboard = new ZeroClipboard($('.btn-clipboard'))
var $htmlBridge = $('#global-zeroclipboard-html-bridge')
// Handlers for ZeroClipboard
zeroClipboard.on('load', function () {
$htmlBridge
.data('placement', 'top')
var clipboard = new Clipboard('.btn-clipboard', {
target: function (trigger) {
return trigger.parentNode.nextElementSibling
}
})
clipboard.on('success', function (e) {
$(e.trigger)
.attr('title', 'Copied!')
.tooltip('_fixTitle')
.tooltip('show')
.attr('title', 'Copy to clipboard')
.tooltip()
.tooltip('_fixTitle')
// 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')
})
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) {
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')
})
})

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -1,8 +1,8 @@
// ZeroClipboard
// clipboard.js
//
// Flash-based `Copy` buttons for code snippets.
.zero-clipboard {
.bd-clipboard {
position: relative;
display: none;
float: right;
@ -28,7 +28,7 @@
}
@media (min-width: 768px) {
.zero-clipboard {
.bd-clipboard {
display: block;
}
}

View File

@ -75,7 +75,7 @@
}
+ .highlight,
+ .zero-clipboard + .highlight {
+ .clipboard + .highlight {
margin-top: 0;
}

View File

@ -57,7 +57,7 @@ $bd-info: #5bc0de;
@import "team";
@import "browser-bugs";
@import "brand";
@import "zeroclipboard";
@import "clipboard-js";
// Load docs dependencies
@import "syntax";

View File

@ -1,9 +1,9 @@
{
"paths": {
"docsJs": [
"../assets/js/vendor/holder.min.js",
"../assets/js/vendor/ZeroClipboard.min.js",
"../assets/js/vendor/anchor.min.js",
"../assets/js/vendor/clipboard.min.js",
"../assets/js/vendor/holder.min.js",
"../assets/js/vendor/tether.min.js",
"../assets/js/src/application.js"
]