mdbootstrap / material-design-for-bootstrap

Important! A new UI Kit version for Bootstrap 5 is available. Access the latest free version via the link below.
https://mdbootstrap.com/docs/standard/
MIT License
9.34k stars 1.15k forks source link

$ is not a function. #163

Closed mopsyd closed 5 years ago

mopsyd commented 6 years ago

Expected behavior

Expected that the assumption will not be made that $ is always equal to jQuery in the global scope.

This is a really easy fix though. Just use jQuery all of the time instead of $. There's really no reason to ever have this bug. It's five extra keystrokes and this will never happen. Replace-all in your editor will easily fix it.

Actual behavior

Chokes when using jQuery.noConflict(); Oops.

Your working environment and MDB version information

MDB 4.4.5

Resources (screenshots, code snippets etc.)

by default 2018-04-20 at 10 06 41 pm

mopsyd commented 6 years ago

This seems to be the offending block (line 15389 from the unminified source):

/*
    Enhanced Bootstrap Modals
    https://mdbootstrap.com
    office@mdbootstrap.com
*/

$('body').on('shown.bs.modal', '.modal', function() {
    if($('.modal-backdrop').length) {
    } else {

        $modal_dialog = $(this).children('.modal-dialog')

        if($modal_dialog.hasClass('modal-side')) {
            $(this).addClass('modal-scrolling');
            $('body').addClass('scrollable');
        }

        if($modal_dialog.hasClass('modal-frame')) {
            $(this).addClass('modal-content-clickable');
            $('body').addClass('scrollable');
        }
    }
});
$('body').on('hidden.bs.modal', '.modal', function() {
    $('body').removeClass('scrollable');
});

You will notice that the block above it uses a safe closure, and does not encounter this problem (ln: 15196 ... 15382):

(function($){
    // Do stuff...
})(jQuery);

A similar approach with the Bootstrap Modal section at the end of the script document would close this out without issue.

JStrebeyko commented 6 years ago

hi @mopsyd , thanks for reaching out, changing