aboutsummaryrefslogtreecommitdiff
path: root/docs/assets/js/_src
diff options
context:
space:
mode:
authorsoundarapandian <[email protected]>2014-01-08 17:32:35 +0530
committerXhmikosR <[email protected]>2014-06-10 08:30:16 +0300
commit250e021ff1206a70188e46bc5ade81b491d50196 (patch)
tree5a70751b01e0be1eda6e8d07ade0c80537aae191 /docs/assets/js/_src
parent9e1652aa50a9d315d333362b68de88e931dc872b (diff)
downloadbootstrap-250e021ff1206a70188e46bc5ade81b491d50196.tar.xz
bootstrap-250e021ff1206a70188e46bc5ade81b491d50196.zip
Integrate ZeroClipboard to easily copy code snippets
Diffstat (limited to 'docs/assets/js/_src')
-rw-r--r--docs/assets/js/_src/application.js47
1 files changed, 47 insertions, 0 deletions
diff --git a/docs/assets/js/_src/application.js b/docs/assets/js/_src/application.js
index 85237d0cd..b84445fed 100644
--- a/docs/assets/js/_src/application.js
+++ b/docs/assets/js/_src/application.js
@@ -15,6 +15,19 @@
$(function () {
+ // Insert copy to clipboard button before .highlight or .bs-example
+ $('.highlight').each(function() {
+ var highlight = $(this)
+ var previous = highlight.prev()
+ var btnHtml = '<div class="zero-clipboard"><span class="glyphicon glyphicon-list-alt btn-clipboard"></span></div>'
+
+ if (previous.hasClass('bs-example')) {
+ previous.before(btnHtml.replace(/btn-clipboard/, 'btn-clipboard with-example'))
+ } else {
+ highlight.before(btnHtml)
+ }
+ })
+
var $window = $(window)
var $body = $(document.body)
@@ -102,6 +115,40 @@
btn.button('reset')
}, 3000)
})
+
+ // Handlers for ZeroClipboard
+ zeroClipboard.on('load', function(client) {
+ htmlBridge
+ .data('placement', 'left')
+ .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(client) {
+ htmlBridge
+ .attr('title', 'copied!')
+ .tooltip('fixTitle')
+ .tooltip('show')
+ .attr('title', 'copy to clipboard')
+ .tooltip('fixTitle')
+ })
+
+ // Notify copy failure
+ zeroClipboard.on('noflash wrongflash', function(client) {
+ htmlBridge
+ .attr('title', 'flash not supported!')
+ .tooltip('fixTitle')
+ .tooltip('show')
+ })
+
})
}(jQuery)