FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
Method-Draw/editor/src/method-draw.js at master · jamesfebin/Method-Draw · GitHub
Method-Draw/editor/src/method-draw.js at master · jamesfebin/Method-Draw · GitHub
Skip to content
Navigation Menu
Sign in
Appearance settings
AI CODE CREATION
GitHub Copilot
Write better code with AI
GitHub Copilot app
Direct agents from issue to merge
MCP Registry
Integrate external tools
DEVELOPER WORKFLOWS
Actions
Automate any workflow
Codespaces
Instant dev environments
Issues
Plan and track work
Code Review
Manage code changes
Code Quality
Enforce quality at merge
APPLICATION SECURITY
GitHub Advanced Security
Find and fix vulnerabilities
Code security
Secure your code as you build
Secret protection
Stop leaks before they start
EXPLORE
Why GitHub
Documentation
Blog
Changelog
Marketplace
View all features
BY COMPANY SIZE
Enterprises
Small and medium teams
Startups
Nonprofits
BY USE CASE
App Modernization
DevSecOps
DevOps
CI/CD
View all use cases
BY INDUSTRY
Healthcare
Financial services
Manufacturing
Government
View all industries
View all solutions
EXPLORE BY TOPIC
AI
Software Development
DevOps
Security
View all topics
EXPLORE BY TYPE
Customer stories
Events & webinars
Ebooks & reports
Business insights
GitHub Skills
SUPPORT & SERVICES
Documentation
Customer support
Community forum
Trust center
Partners
View all resources
COMMUNITY
GitHub Sponsors
Fund open source developers
PROGRAMS
Security Lab
Maintainer Community
GitHub Stars
Archive Program
REPOSITORIES
Topics
Trending
Collections
ENTERPRISE SOLUTIONS
Enterprise platform
AI-powered developer platform
AVAILABLE ADD-ONS
GitHub Advanced Security
Enterprise-grade security features
Copilot for Business
Enterprise-grade AI features
Premium Support
Enterprise-grade 24/7 support
Pricing
Sign in
Sign up
Appearance settings
You signed in with another tab or window.
Reload
to refresh your session.
You signed out in another tab or window.
Reload
to refresh your session.
You switched accounts on another tab or window.
Reload
to refresh your session.
Dismiss alert
{{ message }}
jamesfebin
/
Method-Draw
Public
forked from
methodofaction/Method-Draw
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
Method-Draw
/
editor
/
src
/
method-draw.js
Copy path
More file actions
More file actions
Latest commit
History
History
History
4011 lines (3477 loc) · 144 KB
Breadcrumbs
Method-Draw
/
editor
/
src
/
method-draw.js
Copy path
File metadata and controls
4011 lines (3477 loc) · 144 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* svg-editor.js
*
* Licensed under the MIT License
*
* Copyright(c) 2010 Alexis Deveria
* Copyright(c) 2010 Pavol Rusnak
* Copyright(c) 2010 Jeff Schiller
* Copyright(c) 2010 Narendra Sisodiya
* Copyright(c) 2012 Mark MacKay
*
*/
// Dependencies:
// 1) units.js
// 2) browser.js
// 3) svgcanvas.js
(
function
(
)
{
if
(
!
window
.
methodDraw
)
window
.
methodDraw
=
function
(
$
)
{
var
svgCanvas
;
var
Editor
=
{
}
;
var
is_ready
=
false
;
var
curConfig
=
{
canvas_expansion
:
1
,
dimensions
:
[
580
,
400
]
,
initFill
:
{
color
:
'fff'
,
opacity
:
1
}
,
initStroke
:
{
width
:
1.5
,
color
:
'000'
,
opacity
:
1
}
,
initOpacity
:
1
,
imgPath
:
'images/'
,
extPath
:
'extensions/'
,
jGraduatePath
:
'lib/jgraduate/images/'
,
extensions
:
[
]
,
initTool
:
'select'
,
wireframe
:
false
,
colorPickerCSS
:
false
,
gridSnapping
:
false
,
gridColor
:
"#000"
,
baseUnit
:
'px'
,
snappingStep
:
10
,
showRulers
:
(
svgedit
.
browser
.
isTouch
(
)
)
?
false
:
true
,
show_outside_canvas
:
false
,
no_save_warning
:
true
,
initFont
:
'Helvetica, Arial, sans-serif'
}
;
var
curPrefs
=
{
}
;
//$.extend({}, defaultPrefs);
var
customHandlers
=
{
}
;
Editor
.
curConfig
=
curConfig
;
Editor
.
tool_scale
=
1
;
Editor
.
setConfig
=
function
(
opts
)
{
$
.
extend
(
true
,
curConfig
,
opts
)
;
if
(
opts
.
extensions
)
{
curConfig
.
extensions
=
opts
.
extensions
;
}
}
// Extension mechanisms must call setCustomHandlers with two functions: opts.open and opts.save
// opts.open's responsibilities are:
// - invoke a file chooser dialog in 'open' mode
// - let user pick a SVG file
// - calls setCanvas.setSvgString() with the string contents of that file
// opts.save's responsibilities are:
// - accept the string contents of the current document
// - invoke a file chooser dialog in 'save' mode
// - save the file to location chosen by the user
Editor
.
setCustomHandlers
=
function
(
opts
)
{
Editor
.
ready
(
function
(
)
{
if
(
opts
.
open
)
{
$
(
'#tool_open > input[type="file"]'
)
.
remove
(
)
;
$
(
'#tool_open'
)
.
show
(
)
;
svgCanvas
.
open
=
opts
.
open
;
}
if
(
opts
.
save
)
{
Editor
.
show_save_warning
=
false
;
svgCanvas
.
bind
(
"saved"
,
opts
.
save
)
;
}
if
(
opts
.
pngsave
)
{
svgCanvas
.
bind
(
"exported"
,
opts
.
pngsave
)
;
}
customHandlers
=
opts
;
}
)
;
}
Editor
.
randomizeIds
=
function
(
)
{
svgCanvas
.
randomizeIds
(
arguments
)
}
Editor
.
init
=
function
(
)
{
// For external openers
(
function
(
)
{
// let the opener know SVG Edit is ready
var
w
=
window
.
opener
;
if
(
w
)
{
try
{
var
methodDrawReadyEvent
=
w
.
document
.
createEvent
(
"Event"
)
;
methodDrawReadyEvent
.
initEvent
(
"methodDrawReady"
,
true
,
true
)
;
w
.
document
.
documentElement
.
dispatchEvent
(
methodDrawReadyEvent
)
;
}
catch
(
e
)
{
}
}
}
)
(
)
;
$
(
"body"
)
.
toggleClass
(
"touch"
,
svgedit
.
browser
.
isTouch
(
)
)
;
$
(
"#canvas_width"
)
.
val
(
curConfig
.
dimensions
[
0
]
)
;
$
(
"#canvas_height"
)
.
val
(
curConfig
.
dimensions
[
1
]
)
;
var
extFunc
=
function
(
)
{
$
.
each
(
curConfig
.
extensions
,
function
(
)
{
var
extname
=
this
;
$
.
getScript
(
curConfig
.
extPath
+
extname
,
function
(
d
)
{
// Fails locally in Chrome 5
if
(
!
d
)
{
var
s
=
document
.
createElement
(
'script'
)
;
s
.
src
=
curConfig
.
extPath
+
extname
;
document
.
querySelector
(
'head'
)
.
appendChild
(
s
)
;
}
}
)
;
}
)
;
}
// Load extensions
// Bit of a hack to run extensions in local Opera/IE9
if
(
document
.
location
.
protocol
===
'file:'
)
{
setTimeout
(
extFunc
,
100
)
;
}
else
{
extFunc
(
)
;
}
$
.
svgIcons
(
curConfig
.
imgPath
+
'svg_edit_icons.svg'
,
{
w
:
27
,
h
:
27
,
id_match
:
false
,
no_img
:
true
,
// Opera & Firefox 4 gives odd behavior w/images
fallback_path
:
curConfig
.
imgPath
,
fallback
:
{
'logo'
:
'logo.png'
,
'select'
:
'select.png'
,
'select_node'
:
'select_node.png'
,
'pencil'
:
'pencil.png'
,
'pen'
:
'line.png'
,
'rect'
:
'square.png'
,
'ellipse'
:
'ellipse.png'
,
'path'
:
'path.png'
,
'text'
:
'text.png'
,
'image'
:
'image.png'
,
'zoom'
:
'zoom.png'
,
'delete'
:
'delete.png'
,
'spapelib'
:
'shapelib.png'
,
'node_delete'
:
'node_delete.png'
,
'align_left'
:
'align-left.png'
,
'align_center'
:
'align-center.png'
,
'align_right'
:
'align-right.png'
,
'align_top'
:
'align-top.png'
,
'align_middle'
:
'align-middle.png'
,
'align_bottom'
:
'align-bottom.png'
,
'arrow_right'
:
'flyouth.png'
,
'arrow_down'
:
'dropdown.gif'
}
,
placement
:
{
'#logo'
:
'logo'
,
'#tool_select'
:
'select'
,
'#tool_fhpath'
:
'pencil'
,
'#tool_line'
:
'pen'
,
'#tool_rect,#tools_rect_show'
:
'rect'
,
'#tool_ellipse,#tools_ellipse_show'
:
'ellipse'
,
'#tool_path'
:
'path'
,
'#tool_text,#layer_rename'
:
'text'
,
'#tool_image'
:
'image'
,
'#tool_zoom'
:
'zoom'
,
'#tool_node_clone'
:
'node_clone'
,
'#tool_node_delete'
:
'node_delete'
,
'#tool_add_subpath'
:
'add_subpath'
,
'#tool_openclose_path'
:
'open_path'
,
'#tool_alignleft, #tool_posleft'
:
'align_left'
,
'#tool_aligncenter, #tool_poscenter'
:
'align_center'
,
'#tool_alignright, #tool_posright'
:
'align_right'
,
'#tool_aligntop, #tool_postop'
:
'align_top'
,
'#tool_alignmiddle, #tool_posmiddle'
:
'align_middle'
,
'#tool_alignbottom, #tool_posbottom'
:
'align_bottom'
,
'#cur_position'
:
'align'
,
'#zoomLabel'
:
'zoom'
}
,
resize
:
{
'#logo .svg_icon'
:
15
,
'.flyout_arrow_horiz .svg_icon'
:
5
,
'#fill_bg .svg_icon, #stroke_bg .svg_icon'
:
svgedit
.
browser
.
isTouch
(
)
?
24
:
24
,
'.palette_item:first .svg_icon'
:
svgedit
.
browser
.
isTouch
(
)
?
30
:
16
,
'#zoomLabel .svg_icon'
:
16
,
'#zoom_dropdown .svg_icon'
:
7
}
,
callback
:
function
(
icons
)
{
$
(
'.toolbar_button button > svg, .toolbar_button button > img'
)
.
each
(
function
(
)
{
$
(
this
)
.
parent
(
)
.
prepend
(
this
)
;
}
)
;
$
(
'.tool_button, .tool_button_current'
)
.
addClass
(
"loaded"
)
var
tleft
=
$
(
'#tools_left'
)
;
if
(
tleft
.
length
!=
0
)
{
var
min_height
=
tleft
.
offset
(
)
.
top
+
tleft
.
outerHeight
(
)
;
}
// Look for any missing flyout icons from plugins
$
(
'.tools_flyout'
)
.
each
(
function
(
)
{
var
shower
=
$
(
'#'
+
this
.
id
+
'_show'
)
;
var
sel
=
shower
.
attr
(
'data-curopt'
)
;
// Check if there's an icon here
if
(
!
shower
.
children
(
'svg, img'
)
.
length
)
{
var
clone
=
$
(
sel
)
.
children
(
)
.
clone
(
)
;
if
(
clone
.
length
)
{
clone
[
0
]
.
removeAttribute
(
'style'
)
;
//Needed for Opera
shower
.
append
(
clone
)
;
}
}
}
)
;
methodDraw
.
runCallbacks
(
)
;
setTimeout
(
function
(
)
{
$
(
'.flyout_arrow_horiz:empty'
)
.
each
(
function
(
)
{
$
(
this
)
.
append
(
$
.
getSvgIcon
(
'arrow_right'
)
.
width
(
5
)
.
height
(
5
)
)
;
}
)
;
}
,
1
)
;
}
}
)
;
$
(
'#rulers'
)
.
on
(
"dblclick"
,
function
(
e
)
{
$
(
"#base_unit_container"
)
.
css
(
{
top
:
e
.
pageY
-
10
,
left
:
e
.
pageX
-
50
,
display
:
'block'
}
)
}
)
$
(
"#base_unit_container"
)
.
on
(
"mouseleave mouseenter"
,
function
(
e
)
{
t
=
setTimeout
(
function
(
)
{
$
(
"#base_unit_container"
)
.
fadeOut
(
500
)
}
,
200
)
if
(
event
.
type
==
"mouseover"
)
clearTimeout
(
t
)
}
)
$
(
"#base_unit"
)
.
on
(
"change"
,
function
(
e
)
{
savePreferences
(
)
;
}
)
;
Editor
.
canvas
=
svgCanvas
=
new
$
.
SvgCanvas
(
document
.
getElementById
(
"svgcanvas"
)
,
curConfig
)
;
Editor
.
show_save_warning
=
false
;
Editor
.
paintBox
=
{
fill
:
null
,
stroke
:
null
,
canvas
:
null
}
;
var
palette
=
[
"#444444"
,
"#482816"
,
"#422C10"
,
"#3B2F0E"
,
"#32320F"
,
"#293414"
,
"#1F361B"
,
"#153723"
,
"#0C372C"
,
"#083734"
,
"#0E353B"
,
"#1A333F"
,
"#273141"
,
"#332D40"
,
"#3E2A3C"
,
"#462735"
,
"#4B252D"
,
"#4D2425"
,
"#4C261D"
,
"#666666"
,
"#845335"
,
"#7B572D"
,
"#6F5C2A"
,
"#62612C"
,
"#546433"
,
"#46673D"
,
"#396849"
,
"#306856"
,
"#2D6862"
,
"#33666C"
,
"#426373"
,
"#535F75"
,
"#645A73"
,
"#74556D"
,
"#805064"
,
"#884D58"
,
"#8B4D4B"
,
"#894F3F"
,
"#999999"
,
"#C48157"
,
"#B8874D"
,
"#A98E49"
,
"#97944B"
,
"#849854"
,
"#729C62"
,
"#619E73"
,
"#559E84"
,
"#529D94"
,
"#5B9BA2"
,
"#6D97AB"
,
"#8391AE"
,
"#9A8AAB"
,
"#AF84A3"
,
"#BF7E96"
,
"#C97A86"
,
"#CE7975"
,
"#CC7C65"
,
"#BBBBBB"
,
"#FFB27C"
,
"#FABA6F"
,
"#E6C36A"
,
"#CFCA6D"
,
"#B8D078"
,
"#A0D58A"
,
"#8CD79F"
,
"#7DD8B5"
,
"#7AD6CA"
,
"#84D3DB"
,
"#9ACEE6"
,
"#B6C7EA"
,
"#D3BEE7"
,
"#EDB6DC"
,
"#FFAFCC"
,
"#FFAAB8"
,
"#FFA9A2"
,
"#FFAC8D"
,
"#DDDDDD"
,
"#FFE7A2"
,
"#FFF093"
,
"#FFFA8D"
,
"#FFFF91"
,
"#EEFF9F"
,
"#D1FFB4"
,
"#B9FFCE"
,
"#A8FFE9"
,
"#A4FFFF"
,
"#B1FFFF"
,
"#CBFFFF"
,
"#EDFFFF"
,
"#FFF5FF"
,
"#FFEBFF"
,
"#FFE2FF"
,
"#FFDCEC"
,
"#FFDBD2"
,
"#FFDFB8"
]
,
isMac
=
(
navigator
.
platform
.
indexOf
(
"Mac"
)
>=
0
)
,
isWebkit
=
(
navigator
.
userAgent
.
indexOf
(
"AppleWebKit"
)
>=
0
)
,
modKey
=
(
isMac
?
"meta+"
:
"ctrl+"
)
,
// ⌘
path
=
svgCanvas
.
pathActions
,
undoMgr
=
svgCanvas
.
undoMgr
,
Utils
=
svgedit
.
utilities
,
default_img_url
=
curConfig
.
imgPath
+
"placeholder.svg"
,
workarea
=
$
(
"#workarea"
)
,
canv_menu
=
$
(
"#cmenu_canvas"
)
,
exportWindow
=
null
,
tool_scale
=
1
,
ui_context
=
'toolbars'
,
orig_source
=
''
;
// This puts the correct shortcuts in the menus
if
(
!
isMac
)
{
$
(
'.shortcut'
)
.
each
(
function
(
)
{
var
text
=
$
(
this
)
.
text
(
)
;
$
(
this
)
.
text
(
text
.
split
(
"⌘"
)
.
join
(
"Ctrl+"
)
)
}
)
;
}
// This sets up alternative dialog boxes. They mostly work the same way as
// their UI counterparts, expect instead of returning the result, a callback
// needs to be included that returns the result as its first parameter.
// In the future we may want to add additional types of dialog boxes, since
// they should be easy to handle this way.
(
function
(
)
{
$
(
'#dialog_container'
)
.
draggable
(
{
cancel
:
'#dialog_content, #dialog_buttons *'
,
containment
:
'window'
}
)
;
var
box
=
$
(
'#dialog_box'
)
,
btn_holder
=
$
(
'#dialog_buttons'
)
;
var
dbox
=
function
(
type
,
msg
,
callback
,
defText
)
{
$
(
'#dialog_content'
)
.
html
(
'<p>'
+
msg
.
replace
(
/
\n
/
g
,
'</p><p>'
)
+
'</p>'
)
.
toggleClass
(
'prompt'
,
(
type
==
'prompt'
)
)
;
btn_holder
.
empty
(
)
;
var
ok
=
$
(
'<input type="button" value="OK">'
)
.
appendTo
(
btn_holder
)
;
if
(
type
!=
'alert'
)
{
$
(
'<input type="button" value="Cancel">'
)
.
appendTo
(
btn_holder
)
.
on
(
"click touchstart"
,
function
(
)
{
box
.
hide
(
)
;
callback
(
false
)
}
)
;
}
if
(
type
==
'prompt'
)
{
var
input
=
$
(
'<input type="text">'
)
.
prependTo
(
btn_holder
)
;
input
.
val
(
defText
||
''
)
;
input
.
bind
(
'keydown'
,
'return'
,
function
(
)
{
ok
.
trigger
(
"click touchstart"
)
;
}
)
;
}
if
(
type
==
'process'
)
{
ok
.
hide
(
)
;
}
box
.
show
(
)
;
ok
.
on
(
"click touchstart"
,
function
(
)
{
box
.
hide
(
)
;
var
resp
=
(
type
==
'prompt'
)
?
input
.
val
(
)
:
true
;
if
(
callback
)
callback
(
resp
)
;
}
)
.
focus
(
)
;
if
(
type
==
'prompt'
)
input
.
focus
(
)
;
}
$
.
alert
=
function
(
msg
,
cb
)
{
dbox
(
'alert'
,
msg
,
cb
)
;
}
;
$
.
confirm
=
function
(
msg
,
cb
)
{
dbox
(
'confirm'
,
msg
,
cb
)
;
}
;
$
.
process_cancel
=
function
(
msg
,
cb
)
{
dbox
(
'process'
,
msg
,
cb
)
;
}
;
$
.
prompt
=
function
(
msg
,
txt
,
cb
)
{
dbox
(
'prompt'
,
msg
,
cb
,
txt
)
;
}
;
}
(
)
)
;
var
setSelectMode
=
function
(
)
{
var
curr
=
$
(
'.tool_button_current'
)
;
if
(
curr
.
length
&&
curr
[
0
]
.
id
!==
'tool_select'
)
{
curr
.
removeClass
(
'tool_button_current'
)
.
addClass
(
'tool_button'
)
;
$
(
'#tool_select'
)
.
addClass
(
'tool_button_current'
)
.
removeClass
(
'tool_button'
)
;
}
svgCanvas
.
setMode
(
'select'
)
;
}
;
var
setEyedropperMode
=
function
(
)
{
var
curr
=
$
(
'.tool_button_current'
)
;
if
(
curr
.
length
&&
curr
[
0
]
.
id
!==
'tool_eyedropper'
)
{
curr
.
removeClass
(
'tool_button_current'
)
.
addClass
(
'tool_button'
)
;
$
(
'#tool_eyedropper'
)
.
addClass
(
'tool_button_current'
)
.
removeClass
(
'tool_button'
)
;
}
svgCanvas
.
setMode
(
'eyedropper'
)
;
}
var
togglePathEditMode
=
function
(
editmode
,
elems
)
{
$
(
'#tools_bottom_2,#tools_bottom_3'
)
.
toggle
(
!
editmode
)
;
if
(
editmode
)
{
// Change select icon
$
(
'.context_panel'
)
.
hide
(
)
;
$
(
'#path_node_panel'
)
.
show
(
)
;
$
(
'.tool_button_current'
)
.
removeClass
(
'tool_button_current'
)
.
addClass
(
'tool_button'
)
;
$
(
'#tool_select'
)
.
addClass
(
'tool_button_current'
)
.
removeClass
(
'tool_button'
)
;
setIcon
(
'#tool_select'
,
'select_node'
)
;
multiselected
=
false
;
}
else
{
if
(
elems
[
0
]
)
{
var
selector
=
svgCanvas
.
selectorManager
.
requestSelector
(
elems
[
0
]
)
selector
.
reset
(
elems
[
0
]
)
;
selector
.
selectorRect
.
setAttribute
(
'display'
,
'inline'
)
;
}
setIcon
(
'#tool_select'
,
'select'
)
;
}
}
// used to make the flyouts stay on the screen longer the very first time
var
flyoutspeed
=
1250
;
var
textBeingEntered
=
false
;
var
selectedElement
=
null
;
var
multiselected
=
false
;
var
editingsource
=
false
;
var
docprops
=
false
;
var
preferences
=
false
;
var
cur_context
=
''
;
var
saveHandler
=
function
(
window
,
svg
)
{
}
;
var
exportHandler
=
function
(
window
,
data
)
{
var
issues
=
data
.
issues
;
if
(
!
$
(
'#export_canvas'
)
.
length
)
{
$
(
'<canvas>'
,
{
id
:
'export_canvas'
}
)
.
hide
(
)
.
appendTo
(
'body'
)
;
}
var
c
=
$
(
'#export_canvas'
)
[
0
]
;
c
.
width
=
svgCanvas
.
contentW
;
c
.
height
=
svgCanvas
.
contentH
;
canvg
(
c
,
data
.
svg
,
{
renderCallback
:
function
(
)
{
var
datauri
=
c
.
toDataURL
(
'image/png'
)
;
exportWindow
.
location
.
href
=
datauri
;
var
done
=
$
.
pref
(
'export_notice_done'
)
;
if
(
done
!==
"all"
)
{
var
note
=
"Select \"Save As...\" in your browser to save this image as a PNG file."
;
// Check if there's issues
if
(
issues
.
length
)
{
var
pre
=
"\n \u2022 "
;
note
+=
(
"\n\n"
+
"Also note the following issues: "
+
pre
+
issues
.
join
(
pre
)
)
;
}
// Note that this will also prevent the notice even though new issues may appear later.
// May want to find a way to deal with that without annoying the user
$
.
pref
(
'export_notice_done'
,
'all'
)
;
exportWindow
.
alert
(
note
)
;
}
}
}
)
;
}
;
// called when we've selected a different element
var
selectedChanged
=
function
(
window
,
elems
)
{
var
mode
=
svgCanvas
.
getMode
(
)
;
if
(
mode
===
"select"
)
setSelectMode
(
)
;
if
(
mode
===
"pathedit"
)
return
updateContextPanel
(
)
;
// if elems[1] is present, then we have more than one element
selectedElement
=
(
elems
.
length
==
1
||
elems
[
1
]
==
null
?
elems
[
0
]
:
null
)
;
elems
=
elems
.
filter
(
Boolean
)
multiselected
=
(
elems
.
length
>=
2
)
?
elems
:
false
;
if
(
svgCanvas
.
elementsAreSame
(
multiselected
)
)
selectedElement
=
multiselected
[
0
]
if
(
selectedElement
!=
null
)
{
$
(
'#multiselected_panel'
)
.
hide
(
)
updateToolbar
(
)
;
if
(
multiselected
.
length
)
{
//multiselected elements are the same
$
(
'#tools_top'
)
.
addClass
(
'multiselected'
)
}
}
else
if
(
multiselected
.
length
)
{
$
(
'.context_panel'
)
.
hide
(
)
$
(
'#tools_top'
)
.
removeClass
(
'multiselected'
)
$
(
'#multiselected_panel'
)
.
show
(
)
}
else
{
$
(
'.context_panel'
)
.
hide
(
)
$
(
'#canvas_panel'
)
.
show
(
)
$
(
'#tools_top'
)
.
removeClass
(
'multiselected'
)
}
svgCanvas
.
runExtensions
(
"selectedChanged"
,
{
elems
:
elems
,
selectedElement
:
selectedElement
,
multiselected
:
multiselected
}
)
;
}
;
// Call when part of element is in process of changing, generally
// on mousemove actions like rotate, move, etc.
var
elementTransition
=
function
(
window
,
elems
)
{
var
mode
=
svgCanvas
.
getMode
(
)
;
var
elem
=
elems
[
0
]
;
if
(
!
elem
)
return
;
multiselected
=
(
elems
.
length
>=
2
&&
elems
[
1
]
!=
null
)
?
elems
:
null
;
// Only updating fields for single elements for now
if
(
!
multiselected
)
{
switch
(
mode
)
{
case
"rotate"
:
var
ang
=
svgCanvas
.
getRotationAngle
(
elem
)
;
$
(
'#angle'
)
.
val
(
Math
.
round
(
ang
)
)
;
rotateCursor
(
ang
)
;
$
(
'#tool_reorient'
)
.
toggleClass
(
'disabled'
,
ang
==
0
)
;
break
;
// TODO: Update values that change on move/resize, etc
// case "select":
// case "resize":
// break;
}
}
svgCanvas
.
runExtensions
(
"elementTransition"
,
{
elems
:
elems
}
)
;
}
;
// called when any element has changed
var
elementChanged
=
function
(
window
,
elems
)
{
var
mode
=
svgCanvas
.
getMode
(
)
;
if
(
mode
===
"select"
)
{
setSelectMode
(
)
;
}
for
(
var
i
=
0
;
i
<
elems
.
length
;
++
i
)
{
var
elem
=
elems
[
i
]
;
// if the element changed was the svg, then it could be a resolution change
if
(
elem
&&
elem
.
tagName
===
"svg"
)
{
//populateLayers();
updateCanvas
(
)
;
}
// Update selectedElement if element is no longer part of the image.
// This occurs for the text elements in Firefox
else
if
(
elem
&&
selectedElement
&&
selectedElement
.
parentNode
==
null
)
{
// || elem && elem.tagName == "path" && !multiselected) { // This was added in r1430, but not sure why
selectedElement
=
elem
;
}
}
Editor
.
show_save_warning
=
true
;
// we update the contextual panel with potentially new
// positional/sizing information (we DON'T want to update the
// toolbar here as that creates an infinite loop)
// also this updates the history buttons
// we tell it to skip focusing the text control if the
// text element was previously in focus
updateContextPanel
(
)
;
// In the event a gradient was flipped:
if
(
selectedElement
&&
mode
===
"select"
)
{
Editor
.
paintBox
.
fill
.
update
(
)
;
Editor
.
paintBox
.
stroke
.
update
(
)
;
}
svgCanvas
.
runExtensions
(
"elementChanged"
,
{
elems
:
elems
}
)
;
}
;
var
zoomChanged
=
function
(
window
,
bbox
,
autoCenter
)
{
var
scrbar
=
15
,
res
=
svgCanvas
.
getResolution
(
)
,
w_area
=
workarea
,
canvas_pos
=
$
(
'#svgcanvas'
)
.
position
(
)
;
var
z_info
=
svgCanvas
.
setBBoxZoom
(
bbox
,
w_area
.
width
(
)
-
scrbar
,
w_area
.
height
(
)
-
scrbar
)
;
if
(
!
z_info
)
return
;
var
zoomlevel
=
z_info
.
zoom
,
bb
=
z_info
.
bbox
;
if
(
zoomlevel
<
.001
)
{
changeZoom
(
{
value
:
.1
}
)
;
return
;
}
if
(
typeof
animatedZoom
!=
'undefined'
)
window
.
cancelAnimationFrame
(
animatedZoom
)
// zoom duration 500ms
var
start
=
Date
.
now
(
)
;
var
duration
=
500
;
var
diff
=
(
zoomlevel
)
-
(
res
.
zoom
)
var
zoom
=
$
(
'#zoom'
)
[
0
]
var
current_zoom
=
res
.
zoom
var
animateZoom
=
function
(
timestamp
)
{
var
progress
=
Date
.
now
(
)
-
start
var
tick
=
progress
/
duration
tick
=
(
Math
.
pow
(
(
tick
-
1
)
,
3
)
+
1
)
;
svgCanvas
.
setZoom
(
current_zoom
+
(
diff
*
tick
)
)
;
updateCanvas
(
)
;
if
(
tick
<
1
&&
tick
>
-
.90
)
{
window
.
animatedZoom
=
requestAnimationFrame
(
animateZoom
)
}
else
{
$
(
"#zoom"
)
.
val
(
parseInt
(
zoomlevel
*
100
)
)
$
(
"option"
,
"#zoom_select"
)
.
removeAttr
(
"selected"
)
$
(
"option[value="
+
parseInt
(
zoomlevel
*
100
)
+
"]"
,
"#zoom_select"
)
.
attr
(
"selected"
,
"selected"
)
}
}
animateZoom
(
)
//if(autoCenter) {
// updateCanvas();
//} else {
// updateCanvas(false, {x: bb.x * zoomlevel + (bb.width * zoomlevel)/2, y: bb.y * zoomlevel + (bb.height * zoomlevel)/2});
//}
if
(
svgCanvas
.
getMode
(
)
==
'zoom'
&&
bb
.
width
)
{
// Go to select if a zoom box was drawn
setSelectMode
(
)
;
}
zoomDone
(
)
;
}
$
(
'#cur_context_panel'
)
.
delegate
(
'a'
,
'click'
,
function
(
)
{
var
link
=
$
(
this
)
;
if
(
link
.
attr
(
'data-root'
)
)
{
svgCanvas
.
leaveContext
(
)
;
}
else
{
svgCanvas
.
setContext
(
link
.
text
(
)
)
;
}
svgCanvas
.
clearSelection
(
)
;
return
false
;
}
)
;
var
contextChanged
=
function
(
win
,
context
)
{
var
link_str
=
''
;
if
(
context
)
{
var
str
=
''
;
link_str
=
'<a href="#" data-root="y">'
+
svgCanvas
.
getCurrentDrawing
(
)
.
getCurrentLayerName
(
)
+
'</a>'
;
$
(
context
)
.
parentsUntil
(
'#svgcontent > g'
)
.
andSelf
(
)
.
each
(
function
(
)
{
if
(
this
.
id
)
{
str
+=
' > '
+
this
.
id
;
if
(
this
!==
context
)
{
link_str
+=
' > <a href="#">'
+
this
.
id
+
'</a>'
;
}
else
{
link_str
+=
' > '
+
this
.
id
;
}
}
}
)
;
cur_context
=
str
;
}
else
{
cur_context
=
null
;
}
$
(
'#cur_context_panel'
)
.
toggle
(
!
!
context
)
.
html
(
link_str
)
;
}
// Makes sure the current selected paint is available to work with
var
prepPaints
=
function
(
)
{
Editor
.
paintBox
.
fill
.
prep
(
)
;
Editor
.
paintBox
.
stroke
.
prep
(
)
;
}
var
flyout_funcs
=
{
}
;
var
setupFlyouts
=
function
(
holders
)
{
$
.
each
(
holders
,
function
(
hold_sel
,
btn_opts
)
{
var
buttons
=
$
(
hold_sel
)
.
children
(
)
;
var
show_sel
=
hold_sel
+
'_show'
;
var
shower
=
$
(
show_sel
)
;
var
def
=
false
;
buttons
.
addClass
(
'tool_button'
)
.
unbind
(
'click mousedown mouseup'
)
// may not be necessary
.
each
(
function
(
i
)
{
// Get this buttons options
var
opts
=
btn_opts
[
i
]
;
// Remember the function that goes with this ID
flyout_funcs
[
opts
.
sel
]
=
opts
.
fn
;
if
(
opts
.
isDefault
)
def
=
i
;
// Clicking the icon in flyout should set this set's icon
var
func
=
function
(
event
)
{
var
options
=
opts
;
//find the currently selected tool if comes from keystroke
if
(
event
.
type
===
"keydown"
)
{
var
flyoutIsSelected
=
$
(
options
.
parent
+
"_show"
)
.
hasClass
(
'tool_button_current'
)
;
var
currentOperation
=
$
(
options
.
parent
+
"_show"
)
.
attr
(
"data-curopt"
)
;
$
.
each
(
holders
[
opts
.
parent
]
,
function
(
i
,
tool
)
{
if
(
tool
.
sel
==
currentOperation
)
{
if
(
!
event
.
shiftKey
||
!
flyoutIsSelected
)
{
options
=
tool
;
}
else
{
options
=
holders
[
opts
.
parent
]
[
i
+
1
]
||
holders
[
opts
.
parent
]
[
0
]
;
}
}
}
)
;
}
if
(
$
(
this
)
.
hasClass
(
'disabled'
)
)
return
false
;
if
(
toolButtonClick
(
show_sel
)
)
{
options
.
fn
(
)
;
}
if
(
options
.
icon
)
{
var
icon
=
$
.
getSvgIcon
(
options
.
icon
,
true
)
;
}
else
{
var
icon
=
$
(
options
.
sel
)
.
children
(
)
.
eq
(
0
)
.
clone
(
)
;
}
icon
[
0
]
.
setAttribute
(
'width'
,
shower
.
width
(
)
)
;
icon
[
0
]
.
setAttribute
(
'height'
,
shower
.
height
(
)
)
;
shower
.
children
(
':not(.flyout_arrow_horiz)'
)
.
remove
(
)
;
shower
.
append
(
icon
)
.
attr
(
'data-curopt'
,
options
.
sel
)
;
// This sets the current mode
}
$
(
this
)
.
mouseup
(
func
)
;
if
(
opts
.
key
)
{
$
(
document
)
.
bind
(
'keydown'
,
opts
.
key
[
0
]
+
" shift+"
+
opts
.
key
[
0
]
,
func
)
;
}
}
)
;
if
(
def
)
{
shower
.
attr
(
'data-curopt'
,
btn_opts
[
def
]
.
sel
)
;
}
else
if
(
!
shower
.
attr
(
'data-curopt'
)
)
{
// Set first as default
shower
.
attr
(
'data-curopt'
,
btn_opts
[
0
]
.
sel
)
;
}
var
timer
;
var
pos
=
$
(
show_sel
)
.
position
(
)
;
$
(
hold_sel
)
.
css
(
{
'left'
:
pos
.
left
+
34
,
'top'
:
pos
.
top
+
77
}
)
;
// Clicking the "show" icon should set the current mode
shower
.
mousedown
(
function
(
evt
)
{
$
(
'#workarea'
)
.
one
(
"mousedown"
,
function
(
)
{
$
(
'#tools_shapelib'
)
.
hide
(
)
}
)
if
(
$
(
'#tools_shapelib'
)
.
is
(
":visible"
)
)
toolButtonClick
(
show_sel
,
false
)
;
if
(
shower
.
hasClass
(
'disabled'
)
)
return
false
;
var
holder
=
$
(
hold_sel
)
;
var
l
=
pos
.
left
+
34
;
var
w
=
holder
.
width
(
)
*
-
1
;
var
time
=
holder
.
data
(
'shown_popop'
)
?
200
:
0
;
timer
=
setTimeout
(
function
(
)
{
// Show corresponding menu
if
(
!
shower
.
data
(
'isLibrary'
)
)
{
holder
.
css
(
'left'
,
w
)
.
show
(
)
.
animate
(
{
left
:
l
}
,
50
)
;
}
else
{
holder
.
css
(
'left'
,
l
)
.
show
(
)
;
}
holder
.
data
(
'shown_popop'
,
true
)
;
}
,
time
)
;
evt
.
preventDefault
(
)
;
}
)
.
mouseup
(
function
(
evt
)
{
clearTimeout
(
timer
)
;
var
opt
=
$
(
this
)
.
attr
(
'data-curopt'
)
;
// Is library and popped up, so do nothing
if
(
shower
.
data
(
'isLibrary'
)
&&
$
(
show_sel
.
replace
(
'_show'
,
''
)
)
.
is
(
':visible'
)
)
{
toolButtonClick
(
show_sel
,
true
)
;
return
;
}
if
(
toolButtonClick
(
show_sel
)
&&
(
opt
in
flyout_funcs
)
)
{
flyout_funcs
[
opt
]
(
)
;
}
}
)
;
// $('#tools_rect').mouseleave(function(){$('#tools_rect').fadeOut();});
}
)
;
setFlyoutTitles
(
)
;
}
var
makeFlyoutHolder
=
function
(
id
,
child
)
{
var
div
=
$
(
'<div>'
,
{
'class'
:
'tools_flyout'
,
id
:
id
}
)
.
appendTo
(
'#svg_editor'
)
.
append
(
child
)
;
return
div
;
}
var
setFlyoutPositions
=
function
(
)
{
$
(
'.tools_flyout'
)
.
each
(
function
(
)
{
var
shower
=
$
(
'#'
+
this
.
id
+
'_show'
)
;
var
pos
=
shower
.
offset
(
)
;
var
w
=
shower
.
outerWidth
(
)
;
$
(
this
)
.
css
(
{
left
:
(
pos
.
left
+
w
)
*
tool_scale
,
top
:
pos
.
top
}
)
;
}
)
;
}
var
setFlyoutTitles
=
function
(
)
{
$
(
'.tools_flyout'
)
.
each
(
function
(
)
{
var
shower
=
$
(
'#'
+
this
.
id
+
'_show'
)
;
if
(
shower
.
data
(
'isLibrary'
)
)
return
;
var
tooltips
=
[
]
;
$
(
this
)
.
children
(
)
.
each
(
function
(
)
{
tooltips
.
push
(
this
.
title
)
;
}
)
;
shower
[
0
]
.
title
=
tooltips
.
join
(
' / '
)
;
}
)
;
}
var
resize_timer
;
var
extAdded
=
function
(
window
,
ext
)
{
var
cb_called
=
false
;
var
resize_done
=
false
;
var
cb_ready
=
true
;
// Set to false to delay callback (e.g. wait for $.svgIcons)
function
prepResize
(
)
{
if
(
resize_timer
)
{
clearTimeout
(
resize_timer
)
;
resize_timer
=
null
;
}
if
(
!
resize_done
)
{
resize_timer
=
setTimeout
(
function
(
)
{
resize_done
=
true
;
setIconSize
(
curPrefs
.
iconsize
)
;
}
,
50
)
;
}
}
var
runCallback
=
function
(
)
{
if
(
ext
.
callback
&&
!
cb_called
&&
cb_ready
)
{
cb_called
=
true
;
ext
.
callback
(
)
;
}
}
var
btn_selects
=
[
]
;
if
(
ext
.
context_tools
)
{
$
.
each
(
ext
.
context_tools
,
function
(
i
,
tool
)
{
// Add select tool
var
cont_id
=
tool
.
container_id
?
(
' id="'
+
tool
.
container_id
+
'"'
)
:
""
;
var
panel
=
$
(
'#'
+
tool
.
panel
)
;
// create the panel if it doesn't exist
if
(
!
panel
.
length
)
panel
=
$
(
'<div>'
,
{
id
:
tool
.
panel
}
)
.
appendTo
(
"#tools_top"
)
.
hide
(
)
;
// TODO: Allow support for other types, or adding to existing tool
switch
(
tool
.
type
)
{
case
'tool_button'
:
var
html
=
'<div class="tool_button">'
+
tool
.
id
+
'</div>'
;
var
div
=
$
(
html
)
.
appendTo
(
panel
)
;
if
(
tool
.
events
)
{
$
.
each
(
tool
.
events
,
function
(
evt
,
func
)
{
$
(
div
)
.
bind
(
evt
,
func
)
;
}
)
;
}
break
;
case
'select'
:
var
html
=
'<label'
+
cont_id
+
'>'
+
'<select id="'
+
tool
.
id
+
'">'
;
$
.
each
(
tool
.
options
,
function
(
val
,
text
)
{
var
sel
=
(
val
==
tool
.
defval
)
?
" selected"
:
""
;
html
+=
'<option value="'
+
val
+
'"'
+
sel
+
'>'
+
text
+
'</option>'
;
}
)
;
html
+=
"</select></label>"
;
// Creates the tool, hides & adds it, returns the select element
var
sel
=
$
(
html
)
.
appendTo
(
panel
)
.
find
(
'select'
)
;
$
.
each
(
tool
.
events
,
function
(
evt
,
func
)
{
$
(
sel
)
.
bind
(
evt
,
func
)
;
}
)
;
break
;
case
'button-select'
:
var
html
=
'<div id="'
+
tool
.
id
+
'" class="dropdown toolset" title="'
+
tool
.
title
+
'">'
+
'<div id="cur_'
+
tool
.
id
+
'" class="icon_label"></div><button></button></div>'
;
var
list
=
$
(
'<ul id="'
+
tool
.
id
+
'_opts"></ul>'
)
.
appendTo
(
'#option_lists'
)
;
if
(
tool
.
colnum
)
{
list
.
addClass
(
'optcols'
+
tool
.
colnum
)
;
}
// Creates the tool, hides & adds it, returns the select element
var
dropdown
=
$
(
html
)
.
appendTo
(
panel
)
.
children
(
)
;
btn_selects
.
push
(
{
elem
:
(
'#'
+
tool
.
id
)
,
list
:
(
'#'
+
tool
.
id
+
'_opts'
)
,
title
:
tool
.
title
,
callback
:
tool
.
events
.
change
,
cur
:
(
'#cur_'
+
tool
.
id
)
}
)
;
break
;
case
'input'
:
var
html
=
'<label'
+
cont_id
+
'>'
+
'<span id="'
+
tool
.
id
+
'_label">'
+
tool
.
label
+
':</span>'
+
'<input id="'
+
tool
.
id
+
'" title="'
+
tool
.
title
+
'" size="'
+
(
tool
.
size
||
"4"
)
+
'" value="'
+
(
tool
.
defval
||
""
)
+
'" type="text"/></label>'
// Creates the tool, hides & adds it, returns the select element
// Add to given tool.panel
var
inp
=
$
(
html
)
.
appendTo
(
panel
)
.
find
(
'input'
)
;
if
(
tool
.
spindata
)
{
inp
.
SpinButton
(
tool
.
spindata
)
;
}
if
(
tool
.
events
)
{
$
.
each
(
tool
.
events
,
function
(
evt
,
func
)
{
inp
.
bind
(
evt
,
func
)
;
}
)
;
}
break
;
default
:
break
;
}
}
)
;
}
if
(
ext
.
buttons
)
{
var
fallback_obj
=
{
}
,
placement_obj
=
{
}
,
svgicons
=
ext
.
svgicons
;
var
holders
=
{
}
;
// Add buttons given by extension
$
.
each
(
ext
.
buttons
,
function
(
i
,
btn
)
{
var
icon
;
var
id
=
btn
.
id
;
var
num
=
i
;
// Give button a unique ID
while
(
$
(
'#'
+
id
)
.
length
)
{
id
=
btn
.
id
+
'_'
+
(
++
num
)
;
}
if
(
!
svgicons
)
{
icon
=
(
btn
.
type
==
"menu"
)
?
""
:
$
(
'<img src="'
+
btn
.
icon
+
'">'
)
;
}
else
{
fallback_obj
[
id
]
=
btn
.
icon
;
var
svgicon
=
btn
.
svgicon
?
btn
.
svgicon
:
btn
.
id
;
if
(
btn
.
type
==
'app_menu'
)
{
placement_obj
[
'#'
+
id
+
' > div'
]
=
svgicon
;
}
else
{
placement_obj
[
'#'
+
id
]
=
svgicon
;
}
}
var
cls
,
parent
;
// Set button up according to its type
switch
(
btn
.
type
)
{
case
'mode_flyout'
:
case
'mode'
:
cls
=
'tool_button'
;
if
(
btn
.
cls
)
{
cls
+=
" "
+
btn
.
cls
;
}
parent
=
"#tools_left"
;
break
;
case
'context'
:
cls
=
'tool_button'
;
parent
=
"#"
+
btn
.
panel
;
// create the panel if it doesn't exist
if
(
!
$
(
parent
)
.
length
)
$
(
'<div>'
,
{
id
:
btn
.
panel
}
)
.
appendTo
(
"#tools_top"
)
;
break
;
case
'menu'
:
cls
=
'menu_item tool_button'
;
parent
=
"#"
+
(
btn
.
after
||
btn
.
panel
)
;
break
;
case
'app_menu'
:
cls
=
''
;
parent
=
btn
.
parent
||
'#main_menu ul'
;
// create the panel if it doesn't exist
if
(
!
$
(
parent
)
.
length
)
$
(
'<div>'
,
{
id
:
btn
.
panel
}
)
.
appendTo
(
"#tools_top"
)
;
break
;
}
var
button
=
$
(
(
btn
.
list
||
btn
.
type
==
'app_menu'
)
?
'<li/>'
:
'<div/>'
)
.
attr
(
"id"
,
id
)
.
attr
(
"title"
,
btn
.
title
)
.
addClass
(
cls
)
;
if
(
!
btn
.
includeWith
&&
!
btn
.
list
)
{
if
(
"position"
in
btn
)
{
$
(
parent
)
.
children
(
)
.
eq
(
btn
.
position
)
.
before
(
button
)
;
}
else
{
if
(
btn
.
type
!=
"menu"
||
!
btn
.
after
)
button
.
appendTo
(
parent
)
;
else
$
(
parent
)
.
after
(
button
)
;
}
if
(
btn
.
type
==
'mode_flyout'
)
{
// Add to flyout menu / make flyout menu
// var opts = btn.includeWith;
// // opts.button, default, position
var
ref_btn
=
$
(
button
)
;
var
flyout_holder
=
ref_btn
.
parent
(
)
;
// Create a flyout menu if there isn't one already
if
(
!
ref_btn
.
parent
(
)
.
hasClass
(
'tools_flyout'
)
)
{
// Create flyout placeholder
var
tls_id
=
ref_btn
[
0
]
.
id
.
replace
(
'tool_'
,
'tools_'
)
var
show_btn
=
ref_btn
.
clone
(
)
.
attr
(
'id'
,
tls_id
+
'_show'
)
.
append
(
$
(
'<div>'
,
{
'class'
:
'flyout_arrow_horiz'
}
)
)
;
ref_btn
.
before
(
show_btn
)
;
// Create a flyout div
flyout_holder
=
makeFlyoutHolder
(
tls_id
,
ref_btn
)
;
flyout_holder
.
data
(
'isLibrary'
,
true
)
;
show_btn
.
data
(
'isLibrary'
,
true
)
;
}
// var ref_data = Actions.getButtonData(opts.button);
placement_obj
[
'#'
+
tls_id
+
'_show'
]
=
btn
.
id
;
// TODO: Find way to set the current icon using the iconloader if this is not default
// Include data for extension button as well as ref button
var
cur_h
=
holders
[
'#'
+
flyout_holder
[
0
]
.
id
]
=
[
{
sel
:
'#'
+
id
,
fn
:
btn
.
events
.
click
,
icon
:
btn
.
id
,
//key: btn.key,
View remainder of file in raw view
Footer
© 2026 GitHub, Inc.
Footer navigation
Terms
Privacy
Security
Status
Community
Docs
Contact
You can’t perform that action at this time.
Back
|
FazBrowse Home
|
New Git URL