| @@ -23,11 +23,17 @@ | ||
| 23 | 23 | |
| 24 | 24 | $overlay = $( '#lean_overlay' ); |
| 25 | 25 | |
| 26 | 26 | $trigger.on( 'click', function(e) { |
| 27 | - var modal_id = methods.get_target($(this)), | |
| 28 | - $modal = $(modal_id); | |
| 27 | + var modal_id = methods.get_target($(this)); | |
| 29 | 28 | |
| 29 | + // If no valid modal target, don't proceed | |
| 30 | + if ( ! modal_id ) { | |
| 31 | + return; | |
| 32 | + } | |
| 33 | + | |
| 34 | + var $modal = $(modal_id); | |
| 35 | + | |
| 30 | 36 | methods.open( $modal, e ); |
| 31 | 37 | |
| 32 | 38 | $modal.on( 'click', options.closeButton, function(e){ |
| 33 | 39 | methods.close( $modal ); |
| @@ -94,12 +100,18 @@ | ||
| 94 | 100 | /** |
| 95 | 101 | * Return the ID of the modal to open. |
| 96 | 102 | */ |
| 97 | 103 | get_target : function( $trigger ) { |
| 98 | - var id = '#' + $trigger.data( 'trigger-modal' ); | |
| 104 | + var id = $trigger.data( 'trigger-modal' ); | |
| 99 | 105 | |
| 100 | - if ( 1 === id.length ) { | |
| 101 | - id = $trigger.attr( "href" ); | |
| 106 | + // If data-trigger-modal is empty or undefined, don't use href as fallback | |
| 107 | + if ( ! id || id.length === 0 ) { | |
| 108 | + return null; | |
| 109 | + } | |
| 110 | + | |
| 111 | + // Ensure it starts with # for proper selector | |
| 112 | + if ( id.charAt( 0 ) !== '#' ) { | |
| 113 | + id = '#' + id; | |
| 102 | 114 | } |
| 103 | 115 | |
| 104 | 116 | return id; |
| 105 | 117 | }, |