6 changed files with 38 additions and 24 deletions
File diff suppressed because one or more lines are too long
Binary file not shown.
File diff suppressed because one or more lines are too long
@ -1,26 +1,43 @@
@@ -1,26 +1,43 @@
|
||||
window.Spring = window.Spring || {}; |
||||
|
||||
ZeroClipboard.setDefaults( { moviePath: siteBaseUrl + '/js/ZeroClipboard.swf' } ); |
||||
|
||||
$(document).ready(function() { |
||||
Spring.configureCopyButtons(); |
||||
}); |
||||
|
||||
Spring.configureCopyButtons = function() { |
||||
if (ZeroClipboard.detectFlashSupport()) { |
||||
$(".highlighter-rouge > pre").each(function(index) { |
||||
Spring.buildCopyButton($(this), index); |
||||
} |
||||
); |
||||
} |
||||
|
||||
$("pre.highlight").each(function(index) { |
||||
Spring.buildCopyButton($(this), index); |
||||
} |
||||
); |
||||
var errorMessage = function() { |
||||
if (/Mac/i.test(navigator.userAgent)) { |
||||
return 'Press Cmd-C to Copy'; |
||||
} |
||||
else { |
||||
return 'Press Ctrl-C to Copy'; |
||||
} |
||||
}; |
||||
var snippets = new Clipboard('.copy-button'); |
||||
snippets.on('success', function(e) { |
||||
e.clearSelection(); |
||||
Spring.showTooltip(e.trigger, "Copied!"); |
||||
}); |
||||
snippets.on('error', function(e) { |
||||
Spring.showTooltip(e.trigger, errorMessage()); |
||||
}); |
||||
} |
||||
|
||||
Spring.showTooltip = function(elem, message) { |
||||
$(elem).tooltip({placement:'right', title:message}); |
||||
$(elem).tooltip('show'); |
||||
setTimeout(function(){$(elem).tooltip('destroy');},1000); |
||||
} |
||||
|
||||
Spring.buildCopyButton = function (preEl, id) { |
||||
var codeBlockId = "code-block-"+ id; |
||||
var codeBlockId = "code-block-"+ id; |
||||
var copyButtonId = "copy-button-" + id; |
||||
preEl.attr('id', codeBlockId); |
||||
var button = $('<button class="copy-button snippet" id="' + copyButtonId + '" data-clipboard-target="' + codeBlockId + '"></button>'); |
||||
var button = $('<button class="copy-button snippet" id="' + copyButtonId + '" data-clipboard-target="#' + codeBlockId + '"></button>'); |
||||
preEl.before(button); |
||||
var zero = new ZeroClipboard(button); |
||||
$(zero.htmlBridge).tooltip({title: "copy to clipboard", placement: 'bottom'}); |
||||
} |
||||
|
||||
Loading…
Reference in new issue