From f24df6a93c14c59d7393368370e969b8ff30ddcc Mon Sep 17 00:00:00 2001 From: Xavier Morel Date: Fri, 20 Feb 2015 10:26:13 +0100 Subject: [PATCH] [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. --- doc/_themes/odoodoc/static/app.js | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/doc/_themes/odoodoc/static/app.js b/doc/_themes/odoodoc/static/app.js index 208a29dcf42..64a77c15c40 100644 --- a/doc/_themes/odoodoc/static/app.js +++ b/doc/_themes/odoodoc/static/app.js @@ -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
)
+                $following_siblings.slice(0, -1).remove();
             } else {
-                $('.setupcode.highlight-' + lang + ' pre').clone().insertBefore($target);
+                // otherwise insert setupcode
+                $('.setupcode.highlight-' + lang + ' pre').clone().insertAfter($target);
             }
         });
     })(); }