[FIX] ws doc: fix DOM order for copy/paste usability
The toggle button for the setup code in code examples of the webservice page was mistakenly inserted between the setup code and the "actual" code in the DOM. Trying to select the whole snippet (including setup) would thus also select the text of the button and copy it to the clipboard, breaking the copied code and confusing users. Fix DOM order so selecting setup and actual code does not include the text of the toggle button.
This commit is contained in:
parent
6c37747057
commit
f24df6a93c
|
@ -66,22 +66,25 @@ $(function () {
|
|||
.prependTo('.switchable:not(.setup) .highlight');
|
||||
$(document).on('click', '.btn-show-setup', function (e) {
|
||||
var $target = $(e.target);
|
||||
var target = $target.closest('.switchable:not(.setup)').get(0);
|
||||
var switchable = $target.closest('.switchable:not(.setup)').get(0);
|
||||
// not in a switchable (???)
|
||||
if (!target) { return; }
|
||||
var lang = getHighlightLanguage(target);
|
||||
if (!switchable) { return; }
|
||||
|
||||
var lang = getHighlightLanguage(switchable);
|
||||
if (!lang) {
|
||||
// switchable without highlight (e.g. language-specific notes),
|
||||
// don't munge
|
||||
return;
|
||||
}
|
||||
|
||||
var $setup_code = $target.prev();
|
||||
if ($setup_code.length) {
|
||||
// remove existing setup code
|
||||
$setup_code.remove();
|
||||
var $following_siblings = $target.nextAll();
|
||||
if ($following_siblings.length > 1) {
|
||||
// remove all but the very last following sibling (which
|
||||
// should be the non-setup <pre>)
|
||||
$following_siblings.slice(0, -1).remove();
|
||||
} else {
|
||||
$('.setupcode.highlight-' + lang + ' pre').clone().insertBefore($target);
|
||||
// otherwise insert setupcode
|
||||
$('.setupcode.highlight-' + lang + ' pre').clone().insertAfter($target);
|
||||
}
|
||||
});
|
||||
})(); }
|
||||
|
|
Loading…
Reference in New Issue