2
0
mirror of https://github.com/tenrok/bootstrap.git synced 2026-06-17 19:21:23 +03: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
11 changed files with 54 additions and 69 deletions
+1 -1
View File
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.
+13 -16
View File
File diff suppressed because one or more lines are too long
+25 -35
View File
@@ -9,7 +9,7 @@
* details, see https://creativecommons.org/licenses/by/3.0/. * details, see https://creativecommons.org/licenses/by/3.0/.
*/ */
/* global ZeroClipboard, anchors */ /* global Clipboard, anchors */
!function ($) { !function ($) {
'use strict'; 'use strict';
@@ -36,49 +36,39 @@
e.preventDefault() e.preventDefault()
}) })
// Config ZeroClipboard
ZeroClipboard.config({
moviePath: '/assets/flash/ZeroClipboard.swf',
hoverClass: 'btn-clipboard-hover'
})
// Insert copy to clipboard button before .highlight // Insert copy to clipboard button before .highlight
$('.highlight').each(function () { $('.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) $(this).before(btnHtml)
$('.btn-clipboard').tooltip()
}) })
var zeroClipboard = new ZeroClipboard($('.btn-clipboard'))
var $htmlBridge = $('#global-zeroclipboard-html-bridge')
// Handlers for ZeroClipboard var clipboard = new Clipboard('.btn-clipboard', {
zeroClipboard.on('load', function () { target: function (trigger) {
$htmlBridge return trigger.parentNode.nextElementSibling
.data('placement', 'top') }
})
clipboard.on('success', function (e) {
$(e.trigger)
.attr('title', 'Copied!')
.tooltip('_fixTitle')
.tooltip('show')
.attr('title', 'Copy to clipboard') .attr('title', 'Copy to clipboard')
.tooltip() .tooltip('_fixTitle')
// Copy to clipboard e.clearSelection()
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 clipboard.on('error', function (e) {
// or wrong Flash version is present var fallbackMsg = /Mac/i.test(navigator.userAgent) ? 'Press \u2318 to copy' : 'Press Ctrl-C to copy'
zeroClipboard.on('noflash wrongflash', function () {
$('.zero-clipboard').remove() $(e.trigger)
ZeroClipboard.destroy() .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
@@ -1,8 +1,8 @@
// ZeroClipboard // clipboard.js
// //
// Flash-based `Copy` buttons for code snippets. // Flash-based `Copy` buttons for code snippets.
.zero-clipboard { .bd-clipboard {
position: relative; position: relative;
display: none; display: none;
float: right; float: right;
@@ -28,7 +28,7 @@
} }
@media (min-width: 768px) { @media (min-width: 768px) {
.zero-clipboard { .bd-clipboard {
display: block; display: block;
} }
} }
+1 -1
View File
@@ -75,7 +75,7 @@
} }
+ .highlight, + .highlight,
+ .zero-clipboard + .highlight { + .clipboard + .highlight {
margin-top: 0; margin-top: 0;
} }
+1 -1
View File
@@ -57,7 +57,7 @@ $bd-info: #5bc0de;
@import "team"; @import "team";
@import "browser-bugs"; @import "browser-bugs";
@import "brand"; @import "brand";
@import "zeroclipboard"; @import "clipboard-js";
// Load docs dependencies // Load docs dependencies
@import "syntax"; @import "syntax";
+2 -2
View File
@@ -1,9 +1,9 @@
{ {
"paths": { "paths": {
"docsJs": [ "docsJs": [
"../assets/js/vendor/holder.min.js",
"../assets/js/vendor/ZeroClipboard.min.js",
"../assets/js/vendor/anchor.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/vendor/tether.min.js",
"../assets/js/src/application.js" "../assets/js/src/application.js"
] ]