Copy to clipboard feature for code block (#152)
Co-authored-by: Jacky Zhao <j.zhao2k19@gmail.com>
This commit is contained in:
		
							parent
							
								
									015ed4cfa2
								
							
						
					
					
						commit
						f54df35767
					
				
					 6 changed files with 114 additions and 14 deletions
				
			
		| 
						 | 
				
			
			@ -54,6 +54,13 @@
 | 
			
		|||
  <script src="{{$codeTitle.Permalink}}"></script>
 | 
			
		||||
  {{end}}
 | 
			
		||||
 | 
			
		||||
  {{ if $.Site.Data.config.enableCodeBlockCopy }}
 | 
			
		||||
  {{ $clipboard := resources.Get "js/clipboard.js" | resources.Fingerprint "md5" | resources.Minify }}
 | 
			
		||||
  {{ if (findRE "<pre" .Content 1) }}
 | 
			
		||||
    <script src="{{$clipboard.Permalink}}"></script>
 | 
			
		||||
  {{ end }}
 | 
			
		||||
  {{ end }}
 | 
			
		||||
 | 
			
		||||
  <!--  Preload page vars  -->
 | 
			
		||||
  {{$linkIndex := resources.Get "indices/linkIndex.json" | resources.Fingerprint
 | 
			
		||||
  "md5" | resources.Minify | }} {{$contentIndex := resources.Get
 | 
			
		||||
| 
						 | 
				
			
			@ -85,6 +92,10 @@
 | 
			
		|||
      const pathWindow = window.location.pathname;
 | 
			
		||||
      const isHome = pathBase == pathWindow;
 | 
			
		||||
 | 
			
		||||
      {{if $.Site.Data.config.enableCodeBlockCopy -}}
 | 
			
		||||
      addCopyButtons();
 | 
			
		||||
      {{ end }}
 | 
			
		||||
 | 
			
		||||
      {{if $.Site.Data.config.enableSPA -}}
 | 
			
		||||
      addTitleToCodeBlocks();
 | 
			
		||||
      {{ end }}
 | 
			
		||||
| 
						 | 
				
			
			@ -118,12 +129,12 @@
 | 
			
		|||
 | 
			
		||||
    const init = (doc = document) => {
 | 
			
		||||
      // NOTE: everything within this callback will be executed for initial page navigation. This is a good place to put JavaScript that only replaces DOM nodes.
 | 
			
		||||
      {{if $.Site.Data.config.enableCodeBlockCopy -}}
 | 
			
		||||
      addCopyButtons();
 | 
			
		||||
      {{ end }}
 | 
			
		||||
 | 
			
		||||
      {{if $.Site.Data.config.enableCodeBlockTitle -}}
 | 
			
		||||
      {{if $.Site.Data.config.enableSPA -}}
 | 
			
		||||
      addTitleToCodeBlocks();
 | 
			
		||||
      {{ else }}
 | 
			
		||||
      window.addEventListener("DOMContentLoaded", addTitleToCodeBlocks);
 | 
			
		||||
      {{- end -}}
 | 
			
		||||
      {{- end -}}
 | 
			
		||||
      {{if $.Site.Data.config.enableLatex}}
 | 
			
		||||
      renderMathInElement(doc.body, {
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue