1
-
2
1
let instanceId = 0
3
2
4
3
const Draggabilly = require ( 'draggabilly' )
@@ -23,7 +22,6 @@ class ChromeTabs {
23
22
24
23
init ( el ) {
25
24
this . DOM_chrome_tabs = el
26
-
27
25
this . instanceId = instanceId
28
26
this . DOM_chrome_tabs . setAttribute ( DATA_TABS_INSTANCE_ID , this . instanceId )
29
27
instanceId += 1
@@ -36,7 +34,9 @@ class ChromeTabs {
36
34
}
37
35
38
36
emit ( eventName , data ) {
39
- this . DOM_chrome_tabs . dispatchEvent ( new CustomEvent ( eventName , { detail : data } ) )
37
+ this . DOM_chrome_tabs . dispatchEvent ( new CustomEvent ( eventName , {
38
+ detail : data
39
+ } ) )
40
40
}
41
41
42
42
setupCustomProperties ( ) {
@@ -149,7 +149,10 @@ class ChromeTabs {
149
149
return div . firstElementChild
150
150
}
151
151
152
- addTab ( tabProperties , { animate = true , background = false } = { } ) {
152
+ addTab ( tabProperties , {
153
+ animate = true ,
154
+ background = false
155
+ } = { } ) {
153
156
const tabEl = this . createNewTabEl ( )
154
157
155
158
if ( animate ) {
@@ -161,7 +164,9 @@ class ChromeTabs {
161
164
this . tabContentEl . appendChild ( tabEl )
162
165
this . setTabCloseEventListener ( tabEl )
163
166
this . updateTab ( tabEl , tabProperties )
164
- this . emit ( 'tabAdd' , { tabEl } )
167
+ this . emit ( 'tabAdd' , {
168
+ tabEl
169
+ } )
165
170
if ( ! background ) this . setCurrentTab ( tabEl )
166
171
this . cleanUpPreviouslyDraggedTabs ( )
167
172
this . layoutTabs ( )
@@ -191,10 +196,15 @@ class ChromeTabs {
191
196
}
192
197
tabEl . setAttribute ( 'active' , '' )
193
198
tabEl . classList . add ( "selected" )
194
- this . emit ( 'activeTabChange' , { tabEl } )
199
+ this . emit ( 'activeTabChange' , {
200
+ tabEl
201
+ } )
195
202
}
196
203
197
204
removeTab ( tabEl ) {
205
+ if ( document . getElementsByTagName ( 'webview' ) . length == 1 ) {
206
+ return
207
+ }
198
208
if ( tabEl === this . activeTabEl ) {
199
209
if ( tabEl . nextElementSibling ) {
200
210
this . setCurrentTab ( tabEl . nextElementSibling )
@@ -203,7 +213,9 @@ class ChromeTabs {
203
213
}
204
214
}
205
215
tabEl . parentNode . removeChild ( tabEl )
206
- this . emit ( 'tabRemove' , { tabEl } )
216
+ this . emit ( 'tabRemove' , {
217
+ tabEl
218
+ } )
207
219
this . cleanUpPreviouslyDraggedTabs ( )
208
220
this . layoutTabs ( )
209
221
this . setupDraggabilly ( )
@@ -226,6 +238,10 @@ class ChromeTabs {
226
238
}
227
239
}
228
240
241
+ setTitle ( tabEl , title ) {
242
+ tabEl . querySelector ( `.${ TAB_CLASS } -title` ) . textContent = title
243
+ }
244
+
229
245
cleanUpPreviouslyDraggedTabs ( ) {
230
246
this . tabEls . forEach ( ( tabEl ) => tabEl . classList . remove ( `${ TAB_CLASS } -was-just-dragged` ) )
231
247
}
@@ -317,13 +333,17 @@ class ChromeTabs {
317
333
} else {
318
334
tabEl . parentNode . insertBefore ( tabEl , this . tabEls [ destinationIndex + 1 ] )
319
335
}
320
- this . emit ( 'tabReorder' , { tabEl, originIndex, destinationIndex } )
336
+ this . emit ( 'tabReorder' , {
337
+ tabEl,
338
+ originIndex,
339
+ destinationIndex
340
+ } )
321
341
this . layoutTabs ( )
322
342
}
323
343
}
324
344
325
345
326
- const noop = _ => { }
346
+ const noop = _ => { }
327
347
328
348
const closest = ( value , array ) => {
329
349
let closest = Infinity
@@ -352,7 +372,7 @@ const tabTemplate = `
352
372
`
353
373
354
374
const defaultTapProperties = {
355
- title : 'New tab ' ,
375
+ title : '新标签 ' ,
356
376
favicon : false
357
377
}
358
378
@@ -365,7 +385,7 @@ class ElectronChromeTabs {
365
385
accTabId = 0 ; //Tab id accumulator
366
386
367
387
tabs = [ ]
368
- views = [ ]
388
+ views = [ ]
369
389
370
390
viewToPush = undefined ;
371
391
@@ -405,9 +425,8 @@ class ElectronChromeTabs {
405
425
let id = this . accTabId ++
406
426
tab [ "data-ectTabId" ] = id
407
427
this . tabs . push ( tab )
408
- //console.debug("Tab added:", id, event.detail)
409
428
410
- if ( this . viewToPush )
429
+ if ( this . viewToPush )
411
430
this . views . push ( this . viewToPush )
412
431
else {
413
432
throw "View to push is undefined"
@@ -417,35 +436,28 @@ class ElectronChromeTabs {
417
436
this . DOM_tabs . addEventListener ( "tabRemove" , ( event ) => {
418
437
let tab = event . detail . tabEl
419
438
let id = tab [ "data-ectTabId" ]
420
- console . debug ( "Tab remove: " , id )
421
-
422
- console . debug ( "Tab array: " , this . views )
423
-
424
- this . views [ id ] . remove ( ) //Delete from document
425
- delete this . views [ id ] //Delete from array
426
-
427
- console . debug ( "Tab array after delete: " , this . views )
439
+ this . views [ id ] . remove ( )
440
+ delete this . views [ id ]
428
441
} ) ;
429
442
}
430
443
431
- addTab ( title , favicon = "" , src = undefined ) {
444
+ addTab ( title , favicon = "" , src = undefined ) {
432
445
let child = undefined
433
- if ( src ) {
434
- console . log ( "Adding webview view" )
446
+ if ( src ) {
447
+ // console.log("Adding webview view" + this.accTabId )
435
448
child = document . createElement ( "webview" )
436
449
child . setAttribute ( "src" , src ) ;
450
+ child . setAttribute ( "id" , 'julan' + ( this . accTabId ? this . accTabId : null ) ) ;
451
+ child . setAttribute ( "allowpopups" , true )
437
452
} else {
438
- console . log ( "Adding div view" )
453
+ // console.log("Adding div view")
439
454
child = document . createElement ( "div" ) ;
440
-
441
- //child.innerHTML = "<html><body>Test Body</body></html>"
442
455
}
443
456
child . classList . add ( "eb-view" ) ;
444
457
child . dataset . eb_view_id = this . accTabId ;
445
458
446
459
this . viewToPush = child ;
447
460
448
-
449
461
this . DOM_browser_views . appendChild ( child ) ;
450
462
451
463
let tabEl = chromeTabs . addTab ( {
@@ -473,6 +485,9 @@ class ElectronChromeTabs {
473
485
"activeWebview" : this . activeView
474
486
}
475
487
}
488
+ setCurrentTitle ( title ) {
489
+ chromeTabs . setTitle ( this . activeTab , title )
490
+ }
476
491
477
492
hideTabsBar ( ) {
478
493
document . getElementById ( "eb-tabs-bar" ) . style . display = "none" ;
0 commit comments