diff options
author | Angie Byron <webchick@24967.no-reply.drupal.org> | 2009-02-18 13:46:55 +0000 |
---|---|---|
committer | Angie Byron <webchick@24967.no-reply.drupal.org> | 2009-02-18 13:46:55 +0000 |
commit | ac484c277a0ac0627561d2cac1f4ea47ab5da00b (patch) | |
tree | eac82650ab4c17d3f62461127403e2aff344cd82 /misc/drupal.js | |
parent | b6025a8820ffc84fccbde3a8f77ba6f9c183bfc4 (diff) | |
download | brdo-ac484c277a0ac0627561d2cac1f4ea47ab5da00b.tar.gz brdo-ac484c277a0ac0627561d2cac1f4ea47ab5da00b.tar.bz2 |
#125030 by kkaefer, quicksketch, dvessel, Steven, and John Resig: Allow compatibility with other JavaScript libraries.
Diffstat (limited to 'misc/drupal.js')
-rw-r--r-- | misc/drupal.js | 29 |
1 files changed, 22 insertions, 7 deletions
diff --git a/misc/drupal.js b/misc/drupal.js index 9d5941f36..9b99a1d2e 100644 --- a/misc/drupal.js +++ b/misc/drupal.js @@ -2,6 +2,19 @@ var Drupal = Drupal || { 'settings': {}, 'behaviors': {}, 'locale': {} }; +// Allow other JavaScript libraries to use $. +jQuery.noConflict(); + +// Indicate when other scripts use $ with out wrapping their code. +if ($ === undefined) { + $ = function() { + alert("Please wrap your JavaScript code in (function($) { ... })(jQuery); to be compatible. See http://docs.jquery.com/Using_jQuery_with_Other_Libraries."); + }; +} + + +(function($) { + /** * Set the variable that indicates if JavaScript behaviors should be applied. */ @@ -42,8 +55,8 @@ Drupal.jsEnabled = document.getElementsByTagName && document.createElement && do Drupal.attachBehaviors = function(context) { context = context || document; // Execute all of them. - jQuery.each(Drupal.behaviors, function() { - if (jQuery.isFunction(this.attach)) { + $.each(Drupal.behaviors, function() { + if ($.isFunction(this.attach)) { this.attach(context); } }); @@ -71,8 +84,8 @@ Drupal.attachBehaviors = function(context) { Drupal.detachBehaviors = function(context) { context = context || document; // Execute all of them. - jQuery.each(Drupal.behaviors, function() { - if (jQuery.isFunction(this.detach)) { + $.each(Drupal.behaviors, function() { + if ($.isFunction(this.detach)) { this.detach(context); } }); @@ -286,7 +299,7 @@ Drupal.getSelection = function (element) { */ Drupal.ahahError = function(xmlhttp, uri) { if (xmlhttp.status == 200) { - if (jQuery.trim(xmlhttp.responseText)) { + if ($.trim(xmlhttp.responseText)) { var message = Drupal.t("An error occurred. \n@uri\n@text", {'@uri': uri, '@text': xmlhttp.responseText }); } else { @@ -296,8 +309,8 @@ Drupal.ahahError = function(xmlhttp, uri) { else { var message = Drupal.t("An HTTP error @status occurred. \n@uri", {'@uri': uri, '@status': xmlhttp.status }); } - return message.replace(/\n/g, '<br />');; -} + return message.replace(/\n/g, '<br />'); +}; // Global Killswitch on the <html> element. if (Drupal.jsEnabled) { @@ -328,3 +341,5 @@ Drupal.theme.prototype = { return '<em>' + Drupal.checkPlain(str) + '</em>'; } }; + +})(jQuery); |