1
+ import { Platform , setIcon } from 'obsidian'
2
+ import { Env } from 'src/api'
3
+
4
+ function GetTooltip ( name : string )
5
+ {
6
+ if ( name . includes ( ':' ) )
7
+ {
8
+ return name . split ( ':' ) [ 1 ] . trim ( )
9
+ }
10
+ else
11
+ {
12
+ return name
13
+ }
14
+ }
15
+
16
+ /*
17
+ Get Icon Size
18
+ */
19
+
20
+ export function GetIconSize ( )
21
+ {
22
+ const iconSize = Platform . isDesktop ? 18 : 24
23
+ return iconSize
24
+ }
25
+
26
+ /*
27
+ Remove Elements
28
+ */
29
+
30
+ export function RemoveElements ( element : HTMLCollectionOf < Element > ) : void
31
+ {
32
+ for ( let i = element . length ; i >= 0 ; i -- )
33
+ {
34
+ if ( element [ i ] )
35
+ {
36
+ element [ i ] . remove ( )
37
+ }
38
+ }
39
+ }
40
+
41
+ /*
42
+ Remove all viewaction buttons
43
+ */
44
+
45
+ export function RemoveLeafButtonsAll ( )
46
+ {
47
+ const activeLeaves : HTMLElement [ ] = [ ]
48
+
49
+ app . workspace . iterateAllLeaves ( ( leaf ) =>
50
+ {
51
+ activeLeaves . push ( leaf . view . containerEl )
52
+ } )
53
+
54
+ for ( let i = 0 ; i < activeLeaves . length ; i ++ )
55
+ {
56
+ const leaf = activeLeaves [ i ]
57
+ const element = leaf . getElementsByClassName ( Env . pluginId )
58
+
59
+ if ( element . length > 0 )
60
+ {
61
+ RemoveElements ( element )
62
+ }
63
+ }
64
+ }
65
+
66
+ /*
67
+ Get Button Icon
68
+ */
69
+
70
+ export function GetButtonIcon ( name : string , id : string , icon : string , iconSize : number , classNames : string [ ] , tag : 'a' | 'div' = 'a' )
71
+ {
72
+ const tooltip = GetTooltip ( name )
73
+ const buttonClasses = classNames . concat ( [ id ] )
74
+
75
+ const buttonIcon = createEl ( tag ,
76
+ {
77
+ cls : buttonClasses ,
78
+ attr : { 'aria-label-position' : 'bottom' , 'aria-label' : tooltip } ,
79
+ } )
80
+
81
+ setIcon ( buttonIcon , icon )
82
+
83
+ return buttonIcon
84
+ }
0 commit comments