@@ -10,12 +10,11 @@ import {
10
10
emulateTransitionEnd ,
11
11
getElementFromSelector ,
12
12
getTransitionDurationFromElement ,
13
- isVisible ,
14
13
isRTL ,
14
+ isVisible ,
15
15
reflow ,
16
16
typeCheckConfig
17
17
} from './util/index'
18
- import Data from './dom/data'
19
18
import EventHandler from './dom/event-handler'
20
19
import Manipulator from './dom/manipulator'
21
20
import SelectorEngine from './dom/selector-engine'
@@ -222,6 +221,7 @@ class Modal extends BaseComponent {
222
221
_getConfig ( config ) {
223
222
config = {
224
223
...Default ,
224
+ ...Manipulator . getDataAttributes ( this . _element ) ,
225
225
...config
226
226
}
227
227
typeCheckConfig ( NAME , config , DefaultType )
@@ -509,24 +509,17 @@ class Modal extends BaseComponent {
509
509
510
510
static jQueryInterface ( config , relatedTarget ) {
511
511
return this . each ( function ( ) {
512
- let data = Data . get ( this , DATA_KEY )
513
- const _config = {
514
- ...Default ,
515
- ...Manipulator . getDataAttributes ( this ) ,
516
- ...( typeof config === 'object' && config ? config : { } )
517
- }
512
+ const data = Modal . getInstance ( this ) || new Modal ( this , typeof config === 'object' ? config : { } )
518
513
519
- if ( ! data ) {
520
- data = new Modal ( this , _config )
514
+ if ( typeof config !== 'string' ) {
515
+ return
521
516
}
522
517
523
- if ( typeof config === 'string' ) {
524
- if ( typeof data [ config ] === 'undefined' ) {
525
- throw new TypeError ( `No method named "${ config } "` )
526
- }
527
-
528
- data [ config ] ( relatedTarget )
518
+ if ( typeof data [ config ] === 'undefined' ) {
519
+ throw new TypeError ( `No method named "${ config } "` )
529
520
}
521
+
522
+ data [ config ] ( relatedTarget )
530
523
} )
531
524
}
532
525
}
@@ -540,7 +533,7 @@ class Modal extends BaseComponent {
540
533
EventHandler . on ( document , EVENT_CLICK_DATA_API , SELECTOR_DATA_TOGGLE , function ( event ) {
541
534
const target = getElementFromSelector ( this )
542
535
543
- if ( this . tagName === 'A' || this . tagName === 'AREA' ) {
536
+ if ( [ 'A' , 'AREA' ] . includes ( this . tagName ) ) {
544
537
event . preventDefault ( )
545
538
}
546
539
@@ -557,15 +550,7 @@ EventHandler.on(document, EVENT_CLICK_DATA_API, SELECTOR_DATA_TOGGLE, function (
557
550
} )
558
551
} )
559
552
560
- let data = Data . get ( target , DATA_KEY )
561
- if ( ! data ) {
562
- const config = {
563
- ...Manipulator . getDataAttributes ( target ) ,
564
- ...Manipulator . getDataAttributes ( this )
565
- }
566
-
567
- data = new Modal ( target , config )
568
- }
553
+ const data = Modal . getInstance ( target ) || new Modal ( target , Manipulator . getDataAttributes ( this ) )
569
554
570
555
data . toggle ( this )
571
556
} )
0 commit comments