mirror of
https://github.com/twbs/bootstrap.git
synced 2022-11-09 12:25:43 -05: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:
parent
e544bf4cf8
commit
c343b9f59d
8 changed files with 32 additions and 53 deletions
Binary file not shown.
|
@ -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,50 +36,31 @@
|
||||||
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">Copy</span></div>'
|
||||||
$(this).before(btnHtml)
|
$(this).before(btnHtml)
|
||||||
})
|
})
|
||||||
var zeroClipboard = new ZeroClipboard($('.btn-clipboard'))
|
|
||||||
var $htmlBridge = $('#global-zeroclipboard-html-bridge')
|
|
||||||
|
|
||||||
// Handlers for ZeroClipboard
|
var clipboard = new Clipboard('.bd-clipboard', {
|
||||||
zeroClipboard.on('load', function () {
|
target: function (trigger) {
|
||||||
$htmlBridge
|
return trigger.nextElementSibling;
|
||||||
.data('placement', 'top')
|
}
|
||||||
.attr('title', 'Copy to clipboard')
|
});
|
||||||
.tooltip()
|
|
||||||
|
|
||||||
// Copy to clipboard
|
/*
|
||||||
zeroClipboard.on('dataRequested', function (client) {
|
clipboard.on('success', function (e) {
|
||||||
var highlight = $(this).parent().nextAll('.highlight').first()
|
console.info('Action:', e.action);
|
||||||
client.setText(highlight.text())
|
console.info('Text:', e.text);
|
||||||
})
|
console.info('Trigger:', e.trigger);
|
||||||
|
|
||||||
// Notify copy success and reset tooltip title
|
e.clearSelection();
|
||||||
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
|
console.error('Action:', e.action);
|
||||||
zeroClipboard.on('noflash wrongflash', function () {
|
console.error('Trigger:', e.trigger);
|
||||||
$('.zero-clipboard').remove()
|
});*/
|
||||||
ZeroClipboard.destroy()
|
|
||||||
})
|
|
||||||
|
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
9
docs/assets/js/vendor/ZeroClipboard.min.js
vendored
9
docs/assets/js/vendor/ZeroClipboard.min.js
vendored
File diff suppressed because one or more lines are too long
7
docs/assets/js/vendor/clipboard.min.js
vendored
Normal file
7
docs/assets/js/vendor/clipboard.min.js
vendored
Normal file
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;
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -75,7 +75,7 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
+ .highlight,
|
+ .highlight,
|
||||||
+ .zero-clipboard + .highlight {
|
+ .clipboard + .highlight {
|
||||||
margin-top: 0;
|
margin-top: 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -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";
|
||||||
|
|
|
@ -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"
|
||||||
]
|
]
|
||||||
|
|
Loading…
Reference in a new issue