mirror of
				https://github.com/emrusz/emrusz.git
				synced 2025-10-31 05:19:58 -04:00 
			
		
		
		
	Merge pull request #21 from emrusz/update-copy
Enable code copy and search
This commit is contained in:
		
						commit
						73bebb8eee
					
				
					 3 changed files with 4 additions and 51 deletions
				
			
		|  | @ -19,7 +19,7 @@ description: >- # this means to ignore newlines until "baseurl:" | |||
|   Blog and portfolio for Em (Ethan) Ruszanowski. | ||||
| github_username: emrusz | ||||
| minimal_mistakes_skin: dark | ||||
| search: false | ||||
| search: true | ||||
| 
 | ||||
| # Build settings | ||||
| markdown: kramdown | ||||
|  | @ -59,6 +59,7 @@ author: | |||
|   name: "Em (Ethan) Ruszanowski" | ||||
|   avatar: "/assets/images/avatar.jpg" | ||||
|   bio: "Data engineer, polyglot developer, and RIT Computing and Information Technologies alum." | ||||
|   location: "Rochester, NY" | ||||
|   links: | ||||
|     - label: "Email" | ||||
|       icon: "fas fa-fw fa-envelope" | ||||
|  | @ -91,9 +92,6 @@ footer: | |||
|       icon: "fas fa-fw fa-heartbeat" | ||||
|       url: "https://status.rusz.dev" | ||||
| 
 | ||||
| after_footer_scripts: | ||||
|   - assets/js/clipboard.js | ||||
| 
 | ||||
| social: | ||||
|   type: | ||||
|   names: | ||||
|  | @ -121,6 +119,8 @@ defaults: | |||
|       layout: single | ||||
|       author_profile: true | ||||
| 
 | ||||
| enable_copy_code_button: true | ||||
| 
 | ||||
| category_archive: | ||||
|   type: liquid | ||||
|   path: /categories/ | ||||
|  |  | |||
							
								
								
									
										0
									
								
								_drafts/placeholder.md
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										0
									
								
								_drafts/placeholder.md
									
										
									
									
									
										Normal file
									
								
							|  | @ -1,47 +0,0 @@ | |||
| /*  | ||||
|  * A nice little clipboard script provided by crykn. Thanks! | ||||
|  */ | ||||
| 
 | ||||
| function sleep(ms) { | ||||
|     return new Promise(resolve => setTimeout(resolve, ms)); | ||||
| } | ||||
| 
 | ||||
| async function onClickEffect(btn, style) { | ||||
|     btn.removeClass("btn-light"); | ||||
|     btn.addClass(style); | ||||
|     await sleep(250); | ||||
|     btn.removeClass(style); | ||||
|     btn.addClass("btn-light"); | ||||
| } | ||||
| 
 | ||||
| $(document).ready(function() { | ||||
|     // Create butons
 | ||||
|     $(".page__content pre > code").each(function() { | ||||
|         $(this).parent().prepend( | ||||
|             $(document.createElement('button')).prop({ | ||||
|                 type: 'button', | ||||
|                 innerHTML: '<i class="far fa-copy"></i>', | ||||
|             }) | ||||
|             .attr('title', 'Copy to clipboard') | ||||
|             .addClass('btn') | ||||
|             .addClass('btn--primary') | ||||
|             .css('position', 'absolute') | ||||
|             .css('right', '1em') | ||||
|             // Click listener
 | ||||
|             .on('click', function() { | ||||
|                 let codeElement = $(this).parent().children('code').first(); | ||||
| 
 | ||||
|                 if (!codeElement) { | ||||
|                     throw new Error("Unexpected error! No corresponding code block was found for this button."); | ||||
|                 } | ||||
| 
 | ||||
|                 // Blink effect
 | ||||
|                 onClickEffect($(this), "btn--success") | ||||
| 
 | ||||
|                 // Copy to clipoard function
 | ||||
|                 navigator.clipboard.writeText($(codeElement).text()).then(() => true, () => true); | ||||
|                 return true; | ||||
|             }) | ||||
|         ); | ||||
|     }); | ||||
| }); | ||||
		Loading…
	
	Add table
		
		Reference in a new issue