File tree Expand file tree Collapse file tree 1 file changed +19
-6
lines changed
Expand file tree Collapse file tree 1 file changed +19
-6
lines changed Original file line number Diff line number Diff line change @@ -411,12 +411,25 @@ <h4 class="modal-title">Tag nodes</h4>
411411 $ ( this ) . find ( '#carve' ) . focus ( ) ;
412412 } ) ;
413413
414- // Select2 initialization
415- var tagsSelect = $ ( '#modal_tags' ) . select2 ( {
416- theme : "classic"
417- } ) ;
418- tagsSelect . on ( "select2:select" , function ( e ) {
419- $ ( '#add_tags' ) . append ( new Option ( e . params . data . text , e . params . data . text ) ) ;
414+ // Deferred Select2 initialization (only when tag modal first opens)
415+ var _tagsSelectReady = false ;
416+ function ensureSelect2 ( cb ) {
417+ if ( $ . fn . select2 ) { return cb ( ) ; }
418+ // If not loaded (edge case), dynamically load from CDN
419+ var s = document . createElement ( 'script' ) ;
420+ s . src = 'https://cdnjs.cloudflare.com/ajax/libs/select2/4.0.13/js/select2.min.js' ;
421+ s . onload = cb ;
422+ document . head . appendChild ( s ) ;
423+ }
424+ $ ( '#tagModal' ) . one ( 'shown.bs.modal' , function ( ) {
425+ ensureSelect2 ( function ( ) {
426+ if ( _tagsSelectReady ) return ;
427+ var tagsSelect = $ ( '#modal_tags' ) . select2 ( { theme : 'classic' } ) ;
428+ tagsSelect . on ( 'select2:select' , function ( e ) {
429+ $ ( '#add_tags' ) . append ( new Option ( e . params . data . text , e . params . data . text ) ) ;
430+ } ) ;
431+ _tagsSelectReady = true ;
432+ } ) ;
420433 } ) ;
421434 } ) ;
422435 </ script >
You can’t perform that action at this time.
0 commit comments