mirror of https://github.com/twbs/bootstrap.git
				
				
				
			Replace ZeroClipboard with clipboard.js.
Things left: 1. clear the selection after copy 2. add messages for success and error
This commit is contained in:
		
							parent
							
								
									e544bf4cf8
								
							
						
					
					
						commit
						c343b9f59d
					
				
										
											Binary file not shown.
										
									
								
							| 
						 | 
				
			
			@ -9,7 +9,7 @@
 | 
			
		|||
 * details, see https://creativecommons.org/licenses/by/3.0/.
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
/* global ZeroClipboard, anchors */
 | 
			
		||||
/* global Clipboard, anchors */
 | 
			
		||||
 | 
			
		||||
!function ($) {
 | 
			
		||||
  'use strict';
 | 
			
		||||
| 
						 | 
				
			
			@ -36,50 +36,31 @@
 | 
			
		|||
      e.preventDefault()
 | 
			
		||||
    })
 | 
			
		||||
 | 
			
		||||
    // Config ZeroClipboard
 | 
			
		||||
    ZeroClipboard.config({
 | 
			
		||||
      moviePath: '/assets/flash/ZeroClipboard.swf',
 | 
			
		||||
      hoverClass: 'btn-clipboard-hover'
 | 
			
		||||
    })
 | 
			
		||||
 | 
			
		||||
    // Insert copy to clipboard button before .highlight
 | 
			
		||||
    $('.highlight').each(function () {
 | 
			
		||||
      var btnHtml = '<div class="zero-clipboard"><span class="btn-clipboard">Copy</span></div>'
 | 
			
		||||
      var btnHtml = '<div class="bd-clipboard"><span class="btn-clipboard">Copy</span></div>'
 | 
			
		||||
      $(this).before(btnHtml)
 | 
			
		||||
    })
 | 
			
		||||
    var zeroClipboard = new ZeroClipboard($('.btn-clipboard'))
 | 
			
		||||
    var $htmlBridge = $('#global-zeroclipboard-html-bridge')
 | 
			
		||||
 | 
			
		||||
    // Handlers for ZeroClipboard
 | 
			
		||||
    zeroClipboard.on('load', function () {
 | 
			
		||||
      $htmlBridge
 | 
			
		||||
        .data('placement', 'top')
 | 
			
		||||
        .attr('title', 'Copy to clipboard')
 | 
			
		||||
        .tooltip()
 | 
			
		||||
    var clipboard = new Clipboard('.bd-clipboard', {
 | 
			
		||||
      target: function (trigger) {
 | 
			
		||||
        return trigger.nextElementSibling;
 | 
			
		||||
      }
 | 
			
		||||
    });
 | 
			
		||||
 | 
			
		||||
      // Copy to clipboard
 | 
			
		||||
      zeroClipboard.on('dataRequested', function (client) {
 | 
			
		||||
        var highlight = $(this).parent().nextAll('.highlight').first()
 | 
			
		||||
        client.setText(highlight.text())
 | 
			
		||||
      })
 | 
			
		||||
    /*
 | 
			
		||||
    clipboard.on('success', function (e) {
 | 
			
		||||
      console.info('Action:', e.action);
 | 
			
		||||
      console.info('Text:', e.text);
 | 
			
		||||
      console.info('Trigger:', e.trigger);
 | 
			
		||||
 | 
			
		||||
      // Notify copy success and reset tooltip title
 | 
			
		||||
      zeroClipboard.on('complete', function () {
 | 
			
		||||
        $htmlBridge
 | 
			
		||||
          .attr('title', 'Copied!')
 | 
			
		||||
          .tooltip('fixTitle')
 | 
			
		||||
          .tooltip('show')
 | 
			
		||||
          .attr('title', 'Copy to clipboard')
 | 
			
		||||
          .tooltip('fixTitle')
 | 
			
		||||
      })
 | 
			
		||||
    })
 | 
			
		||||
      e.clearSelection();
 | 
			
		||||
    });
 | 
			
		||||
 | 
			
		||||
    // Hide copy button when no Flash is found
 | 
			
		||||
    // or wrong Flash version is present
 | 
			
		||||
    zeroClipboard.on('noflash wrongflash', function () {
 | 
			
		||||
      $('.zero-clipboard').remove()
 | 
			
		||||
      ZeroClipboard.destroy()
 | 
			
		||||
    })
 | 
			
		||||
    clipboard.on('error', function (e) {
 | 
			
		||||
      console.error('Action:', e.action);
 | 
			
		||||
      console.error('Trigger:', e.trigger);
 | 
			
		||||
    });*/
 | 
			
		||||
 | 
			
		||||
  })
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
										
											
												File diff suppressed because one or more lines are too long
											
										
									
								
							
										
											
												File diff suppressed because one or more lines are too long
											
										
									
								
							| 
						 | 
				
			
			@ -1,8 +1,8 @@
 | 
			
		|||
// ZeroClipboard
 | 
			
		||||
// clipboard.js
 | 
			
		||||
//
 | 
			
		||||
// Flash-based `Copy` buttons for code snippets.
 | 
			
		||||
 | 
			
		||||
.zero-clipboard {
 | 
			
		||||
.bd-clipboard {
 | 
			
		||||
  position: relative;
 | 
			
		||||
  display: none;
 | 
			
		||||
  float: right;
 | 
			
		||||
| 
						 | 
				
			
			@ -28,7 +28,7 @@
 | 
			
		|||
}
 | 
			
		||||
 | 
			
		||||
@media (min-width: 768px) {
 | 
			
		||||
  .zero-clipboard {
 | 
			
		||||
  .bd-clipboard {
 | 
			
		||||
    display: block;
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			@ -75,7 +75,7 @@
 | 
			
		|||
  }
 | 
			
		||||
 | 
			
		||||
  + .highlight,
 | 
			
		||||
  + .zero-clipboard + .highlight {
 | 
			
		||||
  + .clipboard + .highlight {
 | 
			
		||||
    margin-top: 0;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -57,7 +57,7 @@ $bd-info:           #5bc0de;
 | 
			
		|||
@import "team";
 | 
			
		||||
@import "browser-bugs";
 | 
			
		||||
@import "brand";
 | 
			
		||||
@import "zeroclipboard";
 | 
			
		||||
@import "clipboard-js";
 | 
			
		||||
 | 
			
		||||
// Load docs dependencies
 | 
			
		||||
@import "syntax";
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1,9 +1,9 @@
 | 
			
		|||
{
 | 
			
		||||
  "paths": {
 | 
			
		||||
    "docsJs": [
 | 
			
		||||
      "../assets/js/vendor/holder.min.js",
 | 
			
		||||
      "../assets/js/vendor/ZeroClipboard.min.js",
 | 
			
		||||
      "../assets/js/vendor/anchor.min.js",
 | 
			
		||||
      "../assets/js/vendor/clipboard.min.js",
 | 
			
		||||
      "../assets/js/vendor/holder.min.js",
 | 
			
		||||
      "../assets/js/vendor/tether.min.js",
 | 
			
		||||
      "../assets/js/src/application.js"
 | 
			
		||||
    ]
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in New Issue