暫無描述

jquery.init.js 1.6KB

12345678910111213141516171819202122232425262728293031323334353637
  1. var yl = yl || {};
  2. if (typeof django !== 'undefined' && typeof django.jQuery !== 'undefined') {
  3. // If django.jQuery is already defined, use it.
  4. yl.jQuery = django.jQuery;
  5. }
  6. else {
  7. // We include jquery itself in our widget's media, because we need it.
  8. // Normally, we expect our widget's reference to admin/js/vendor/jquery/jquery.js
  9. // to be skipped, because django's own code has already included it.
  10. // However, if django.jQuery is NOT defined, we know that jquery was not
  11. // included before we did it ourselves. This can happen if we're not being
  12. // rendered in a django admin form.
  13. // However, someone ELSE'S jQuery may have been included before ours, in
  14. // which case we must ensure that our jquery doesn't override theirs, since
  15. // it might be a newer version that other code on the page relies on.
  16. // Thus, we must run jQuery.noConflict(true) here to move our jQuery out of
  17. // the way.
  18. yl.jQuery = jQuery.noConflict(true);
  19. }
  20. // In addition to all of this, we must ensure that the global jQuery and $ are
  21. // defined, because Select2 requires that. jQuery will only be undefined at
  22. // this point if only we or django included it.
  23. if (typeof jQuery === 'undefined') {
  24. jQuery = yl.jQuery;
  25. $ = yl.jQuery;
  26. }
  27. else {
  28. // jQuery IS still defined, which means someone else also included jQuery.
  29. // In this situation, we need to store the old jQuery in a
  30. // temp variable, set the global jQuery to our yl.jQuery, then let select2
  31. // set itself up. We restore the global jQuery to its original value in
  32. // jquery.post-setup.js.
  33. dal_jquery_backup = jQuery.noConflict(true);
  34. jQuery = yl.jQuery;
  35. }