From 250e021ff1206a70188e46bc5ade81b491d50196 Mon Sep 17 00:00:00 2001 From: soundarapandian Date: Wed, 8 Jan 2014 17:32:35 +0530 Subject: Integrate ZeroClipboard to easily copy code snippets --- docs/assets/js/_src/application.js | 47 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) (limited to 'docs/assets/js/_src/application.js') 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 = '
' + + 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) -- cgit v1.2.3