Skip to content

Commit

Permalink
Merge pull request twbs#17751 from twbs/v4-dev-xmr-clipboardjs
Browse files Browse the repository at this point in the history
Replace ZeroClipboard with clipboard.js.
  • Loading branch information
XhmikosR committed Oct 24, 2015
2 parents e544bf4 + 270c0b1 commit f246362
Show file tree
Hide file tree
Showing 11 changed files with 55 additions and 70 deletions.
2 changes: 1 addition & 1 deletion docs/assets/css/docs.min.css

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/assets/css/docs.min.css.map

Large diffs are not rendered by default.

Binary file removed docs/assets/flash/ZeroClipboard.swf
Binary file not shown.
29 changes: 13 additions & 16 deletions docs/assets/js/docs.min.js

Large diffs are not rendered by default.

62 changes: 26 additions & 36 deletions docs/assets/js/src/application.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
* details, see https://creativecommons.org/licenses/by/3.0/.
*/

/* global ZeroClipboard, anchors */
/* global Clipboard, anchors */

!function ($) {
'use strict';
Expand All @@ -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 clipboard = new Clipboard('.btn-clipboard', {
target: function (trigger) {
return trigger.parentNode.nextElementSibling
}
})
var zeroClipboard = new ZeroClipboard($('.btn-clipboard'))
var $htmlBridge = $('#global-zeroclipboard-html-bridge')

// Handlers for ZeroClipboard
zeroClipboard.on('load', function () {
$htmlBridge
.data('placement', 'top')
clipboard.on('success', function (e) {
$(e.trigger)
.attr('title', 'Copied!')
.tooltip('_fixTitle')
.tooltip('show')
.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')
})
.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')
})

})
Expand Down
9 changes: 0 additions & 9 deletions docs/assets/js/vendor/ZeroClipboard.min.js

This file was deleted.

7 changes: 7 additions & 0 deletions docs/assets/js/vendor/clipboard.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
// ZeroClipboard
// clipboard.js
//
// Flash-based `Copy` buttons for code snippets.

.zero-clipboard {
.bd-clipboard {
position: relative;
display: none;
float: right;
Expand All @@ -28,7 +28,7 @@
}

@media (min-width: 768px) {
.zero-clipboard {
.bd-clipboard {
display: block;
}
}
2 changes: 1 addition & 1 deletion docs/assets/scss/_component-examples.scss
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@
}

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

Expand Down
2 changes: 1 addition & 1 deletion docs/assets/scss/docs.scss
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ $bd-info: #5bc0de;
@import "team";
@import "browser-bugs";
@import "brand";
@import "zeroclipboard";
@import "clipboard-js";

// Load docs dependencies
@import "syntax";
Expand Down
4 changes: 2 additions & 2 deletions grunt/configBridge.json
Original file line number Diff line number Diff line change
@@ -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"
]
Expand Down

0 comments on commit f246362

Please sign in to comment.