mirror of
				https://github.com/TriliumNext/Notes.git
				synced 2025-10-30 12:13:52 +08:00 
			
		
		
		
	easier API to add button to toolbar
This commit is contained in:
		
							parent
							
								
									0f106fb96f
								
							
						
					
					
						commit
						e39d1d08ac
					
				| @ -17,12 +17,29 @@ function ScriptApi(startNote, currentNote, originEntity = null) { | |||||||
|         await treeService.activateNode(notePath, true); |         await treeService.activateNode(notePath, true); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     function addButtonToToolbar(buttonId, button) { |     function addButtonToToolbar(opts) { | ||||||
|  |         const buttonId = "toolbar-button-" + opts.title.replace(/[^a-zA-Z0-9]/g, "-"); | ||||||
|  | 
 | ||||||
|         $("#" + buttonId).remove(); |         $("#" + buttonId).remove(); | ||||||
| 
 | 
 | ||||||
|  |         const icon = $("<span>") | ||||||
|  |             .addClass("ui-icon ui-icon-" + opts.icon); | ||||||
|  | 
 | ||||||
|  |         const button = $('<button>') | ||||||
|  |             .addClass("btn btn-xs") | ||||||
|  |             .click(opts.action) | ||||||
|  |             .append(icon) | ||||||
|  |             .append($("<span>").text(opts.title)); | ||||||
|  | 
 | ||||||
|         button.attr('id', buttonId); |         button.attr('id', buttonId); | ||||||
| 
 | 
 | ||||||
|         $pluginButtons.append(button); |         $pluginButtons.append(button); | ||||||
|  | 
 | ||||||
|  |         if (opts.shortcut) { | ||||||
|  |             $(document).bind('keydown', opts.shortcut, opts.action); | ||||||
|  | 
 | ||||||
|  |             button.attr("title", "Shortcut " + opts.shortcut); | ||||||
|  |         } | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     function prepareParams(params) { |     function prepareParams(params) { | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user
	 azivner
						azivner