Github user neykov commented on a diff in the pull request:

    https://github.com/apache/brooklyn-docs/pull/123#discussion_r86802168
  
    --- Diff: _layouts/base.html ---
    @@ -65,32 +63,70 @@
         }
     });
     
    -<!-- Clipboard support -->
    -  ZeroClipboard.config({ moviePath: '{{ site.path.style 
}}/js/zeroclipboard/ZeroClipboard.swf' });
    +<!-- Copying and clipboard support -->
    +
    +// first make the $% line starts not selectable 
    +
    +$(function() {
    +  $('div.highlight').attr('oncopy', 'handleHideCopy(this)');
    +  $('div.highlight').each(function(index,target) {
    +    if ($(target).find('code.bash')) {
    +      // Mark bash prompts from the start of each line (i.e. '$' or '%' 
characters
    +      // at the very start, or immediately following any newline) as 
not-selectable. 
    +      // Handle continuation lines where a leading '$' or '%' is *not* a 
prompt character.
    +      // (If example wants to exclude output, it can manually use 
class="nocopy".)
    +      target.innerHTML = 
target.innerHTML.replace(/(^\s*|[^\\]\n)(<.*>)?([$%]|&gt;) /g, '$1$2<span 
class="nocopy bash_prompt">$3 </span>');
    +    }
    +  });
    +});
    +
    +// normal cmd-C (non-icon) copying
    +
    +function handleHideCopy(el) {
    +//    var origHtml = $(el).clone();
    +    console.log("handling copy", el);
    +    $(el).addClass('copying');
    +    $(el).find('.nocopy').hide();
    +    $(el).find('.clipboard_button').addClass('manual-clipboard-is-active');
    +    setTimeout(function(){
    +        $(el).removeClass('copying');
    +        
$(el).find('.clipboard_button').removeClass('manual-clipboard-is-active');
    +        $(el).find('.nocopy').show();
    +//        $(el).html(origHtml);
    +    }, 600);
    +}
    +
    +// and icon (flash) copying
    +
    +</script>
    +
    +<script src="{{ site.path.style 
}}/js/zeroclipboard/ZeroClipboard.min.js"></script>
    +
    +<script language="JavaScript" type="application/javascript">
    +
    +ZeroClipboard.config({ moviePath: '{{ site.path.style 
}}/js/zeroclipboard/ZeroClipboard.swf' });
     
     $(function() {
       $('div.highlight').prepend(
    -  $('<div class="clipboard_container" title="Copy to Clipboard">'+
    -    '<div class="fa clipboard_button">'+
    -    '<div class="on-active"><div>Copied to Clipboard</div></div>'+
    -  '</div></div>'));
    +    $('<div class="clipboard_container" title="Copy to Clipboard">'+
    +      '<div class="fa clipboard_button">'+
    +      '<div class="on-active"><div>Copied to Clipboard</div></div>'+
    +    '</div></div>'));
       $('div.clipboard_container').each(function(index) {
         var clipboard = new ZeroClipboard();
         clipboard.clip( $(this).find(":first")[0], $(this)[0] );
    -    var target = $(this).next();
    -    var txt = target.text().trim();
    -    if (target.find('code.bash')) {
    -      // Strip out bash prompts from the start of each line (i.e. '$' or 
'%' characters
    -      // at the very start, or immediately following any newline). 
Correctly handles continuation
    -      // lines, where a leading '$' or '%' is *not* a prompt character.
    -      txt = txt.replace(/(^|[^\\]\n)[$%] /g, "$1");
    -    }
    +    var target0 = $(this).next();
    +    var target = target0.clone();
    +    target.find('.nocopy').remove();
    +    var txt = target.text();
         clipboard.on( 'dataRequested', function (client, args) {
    +      handleHideCopy( target0.closest('div.highlight') );  //not necessary 
but nicer feedback
    --- End diff --
    
    This won't be called if zeroclipboard is not active (no flash installed for 
example). Could use 
[`user-select`](https://developer.mozilla.org/en-US/docs/Web/CSS/user-select) 
for a similar effect.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---

Reply via email to