summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAngie Byron <webchick@24967.no-reply.drupal.org>2009-02-18 13:46:55 +0000
committerAngie Byron <webchick@24967.no-reply.drupal.org>2009-02-18 13:46:55 +0000
commitac484c277a0ac0627561d2cac1f4ea47ab5da00b (patch)
treeeac82650ab4c17d3f62461127403e2aff344cd82
parentb6025a8820ffc84fccbde3a8f77ba6f9c183bfc4 (diff)
downloadbrdo-ac484c277a0ac0627561d2cac1f4ea47ab5da00b.tar.gz
brdo-ac484c277a0ac0627561d2cac1f4ea47ab5da00b.tar.bz2
#125030 by kkaefer, quicksketch, dvessel, Steven, and John Resig: Allow compatibility with other JavaScript libraries.
-rw-r--r--includes/common.inc6
-rw-r--r--install.php2
-rw-r--r--misc/ahah.js5
-rw-r--r--misc/autocomplete.js3
-rw-r--r--misc/batch.js3
-rw-r--r--misc/collapse.js3
-rw-r--r--misc/drupal.js29
-rw-r--r--misc/farbtastic/farbtastic.js13
-rw-r--r--misc/form.js3
-rw-r--r--misc/progress.js3
-rw-r--r--misc/tabledrag.js11
-rw-r--r--misc/tableheader.js5
-rw-r--r--misc/tableselect.js5
-rw-r--r--misc/teaser.js3
-rw-r--r--misc/textarea.js3
-rw-r--r--misc/timezone.js5
-rw-r--r--modules/block/block.js3
-rw-r--r--modules/book/book.module2
-rw-r--r--modules/color/color.js3
-rw-r--r--modules/comment/comment.js3
-rw-r--r--modules/node/content_types.js5
-rw-r--r--modules/openid/openid.js3
-rw-r--r--modules/profile/profile.js3
-rw-r--r--modules/simpletest/simpletest.js5
-rw-r--r--modules/simpletest/tests/common.test4
-rw-r--r--modules/system/system.js7
-rw-r--r--modules/taxonomy/taxonomy.js3
-rw-r--r--modules/user/user.js5
28 files changed, 119 insertions, 29 deletions
diff --git a/includes/common.inc b/includes/common.inc
index 7b97fe67d..806ae97e0 100644
--- a/includes/common.inc
+++ b/includes/common.inc
@@ -2334,6 +2334,8 @@ function drupal_clear_css_cache() {
* directly in the page. This can, for example, be useful to tell the user that
* a new message arrived, by opening a pop up, alert box etc. This should only
* be used for JavaScript which cannot be placed and executed from a file.
+ * When adding inline code, make sure that you are not relying on $ being jQuery.
+ * Wrap your code in (function($) { ... })(jQuery); or use jQuery instead of $.
*
* - Add settings ('setting'):
* Adds a setting to Drupal's global storage of JavaScript settings. Per-page
@@ -2344,8 +2346,8 @@ function drupal_clear_css_cache() {
* @code
* drupal_add_js('misc/collapse.js');
* drupal_add_js('misc/collapse.js', 'file');
- * drupal_add_js('$(document).ready(function(){alert("Hello!");});', 'inline');
- * drupal_add_js('$(document).ready(function(){alert("Hello!");});',
+ * drupal_add_js('jQuery(document).ready(function(){alert("Hello!");});', 'inline');
+ * drupal_add_js('jQuery(document).ready(function(){alert("Hello!");});',
* array('type' => 'inline', 'scope' => 'footer', 'weight' => 5)
* );
* @endcode
diff --git a/install.php b/install.php
index bd31efdc0..67d1af596 100644
--- a/install.php
+++ b/install.php
@@ -731,7 +731,7 @@ function install_tasks($profile, $task) {
drupal_add_js('
// Global Killswitch
if (Drupal.jsEnabled) {
- $(document).ready(function() {
+ jQuery(document).ready(function() {
Drupal.cleanURLsInstallCheck();
});
}', 'inline');
diff --git a/misc/ahah.js b/misc/ahah.js
index ca5580a46..e2469fe37 100644
--- a/misc/ahah.js
+++ b/misc/ahah.js
@@ -1,4 +1,5 @@
// $Id$
+(function($) {
/**
* Provides AJAX-like page updating via AHAH (Asynchronous HTML and HTTP).
@@ -138,7 +139,7 @@ Drupal.ahah.prototype.beforeSubmit = function (form_values, element, options) {
else if (this.progress.type == 'throbber') {
this.progress.element = $('<div class="ahah-progress ahah-progress-throbber"><div class="throbber">&nbsp;</div></div>');
if (this.progress.message) {
- $('.throbber', this.progress.element).after('<div class="message">' + this.progress.message + '</div>')
+ $('.throbber', this.progress.element).after('<div class="message">' + this.progress.message + '</div>');
}
$(this.element).after(this.progress.element);
}
@@ -225,3 +226,5 @@ Drupal.ahah.prototype.error = function (response, uri) {
// Re-enable the element.
$(this.element).removeClass('progess-disabled').attr('disabled', false);
};
+
+})(jQuery);
diff --git a/misc/autocomplete.js b/misc/autocomplete.js
index da76380c4..48253c70f 100644
--- a/misc/autocomplete.js
+++ b/misc/autocomplete.js
@@ -1,4 +1,5 @@
// $Id$
+(function($) {
/**
* Attaches the autocomplete behavior to all required fields.
@@ -298,3 +299,5 @@ Drupal.ACDB.prototype.cancel = function() {
if (this.timer) clearTimeout(this.timer);
this.searchString = '';
};
+
+})(jQuery);
diff --git a/misc/batch.js b/misc/batch.js
index 4d1a4d551..17c4caae9 100644
--- a/misc/batch.js
+++ b/misc/batch.js
@@ -1,4 +1,5 @@
// $Id$
+(function($) {
/**
* Attaches the batch behavior to progress bars.
@@ -38,3 +39,5 @@ Drupal.behaviors.batch = {
});
}
};
+
+})(jQuery);
diff --git a/misc/collapse.js b/misc/collapse.js
index 4626b4519..7da7e16b1 100644
--- a/misc/collapse.js
+++ b/misc/collapse.js
@@ -1,4 +1,5 @@
// $Id$
+(function($) {
/**
* Toggle the visibility of a fieldset using smooth animations
@@ -77,3 +78,5 @@ Drupal.behaviors.collapse = {
});
}
};
+
+})(jQuery);
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);
diff --git a/misc/farbtastic/farbtastic.js b/misc/farbtastic/farbtastic.js
index 028b00b36..18b083eab 100644
--- a/misc/farbtastic/farbtastic.js
+++ b/misc/farbtastic/farbtastic.js
@@ -1,17 +1,18 @@
// $Id$
// Farbtastic 1.2
+(function($) {
-jQuery.fn.farbtastic = function (callback) {
+$.farbtastic = function (callback) {
$.farbtastic(this, callback);
return this;
};
-jQuery.farbtastic = function (container, callback) {
+$.farbtastic = function (container, callback) {
var container = $(container).get(0);
- return container.farbtastic || (container.farbtastic = new jQuery._farbtastic(container, callback));
+ return container.farbtastic || (container.farbtastic = new $._farbtastic(container, callback));
};
-jQuery._farbtastic = function (container, callback) {
+$._farbtastic = function (container, callback) {
// Store farbtastic object
var fb = this;
@@ -266,4 +267,6 @@ jQuery._farbtastic = function (container, callback) {
if (callback) {
fb.linkTo(callback);
}
-}; \ No newline at end of file
+};
+
+})(jQuery);
diff --git a/misc/form.js b/misc/form.js
index d3a9f692f..8631ed68c 100644
--- a/misc/form.js
+++ b/misc/form.js
@@ -1,4 +1,5 @@
// $Id$
+(function($) {
Drupal.behaviors.multiselectSelector = {
attach: function(context) {
@@ -10,3 +11,5 @@ Drupal.behaviors.multiselectSelector = {
});
}
};
+
+})(jQuery);
diff --git a/misc/progress.js b/misc/progress.js
index 631a5f4f8..b0fad1573 100644
--- a/misc/progress.js
+++ b/misc/progress.js
@@ -1,4 +1,5 @@
// $Id$
+(function($) {
/**
* A progressbar object. Initialized with the given id. Must be inserted into
@@ -105,3 +106,5 @@ Drupal.progressBar.prototype.displayError = function (string) {
this.errorCallback(this);
}
};
+
+})(jQuery);
diff --git a/misc/tabledrag.js b/misc/tabledrag.js
index 3fce73041..aea64d617 100644
--- a/misc/tabledrag.js
+++ b/misc/tabledrag.js
@@ -1,4 +1,5 @@
// $Id$
+(function($) {
/**
* Drag and drop table rows with field manipulation.
@@ -321,7 +322,9 @@ Drupal.tableDrag.prototype.makeDraggable = function(item) {
var groupHeight = 0;
nextGroup = new self.row(nextRow, 'keyboard', self.indentEnabled, self.maxDepth, false);
if (nextGroup) {
- $(nextGroup.group).each(function () {groupHeight += $(this).is(':hidden') ? 0 : this.offsetHeight});
+ $(nextGroup.group).each(function () {
+ groupHeight += $(this).is(':hidden') ? 0 : this.offsetHeight;
+ });
nextGroupRow = $(nextGroup.group).filter(':last').get(0);
self.rowObject.swap('after', nextGroupRow);
// No need to check for indentation, 0 is the only valid one.
@@ -957,7 +960,7 @@ Drupal.tableDrag.prototype.row.prototype.validIndentInterval = function (prevRow
}
return {'min':minIndent, 'max':maxIndent};
-}
+};
/**
* Indent a row within the legal bounds of the table.
@@ -1021,7 +1024,7 @@ Drupal.tableDrag.prototype.row.prototype.findSiblings = function(rowSettings) {
// Either add immediately if this is a flat table, or check to ensure
// that this row has the same level of indentation.
if (this.indentEnabled) {
- var checkRowIndentation = $('.indentation', checkRow).length
+ var checkRowIndentation = $('.indentation', checkRow).length;
}
if (!(this.indentEnabled) || (checkRowIndentation == rowIndentation)) {
@@ -1096,3 +1099,5 @@ Drupal.theme.prototype.tableDragIndentation = function () {
Drupal.theme.prototype.tableDragChangedWarning = function () {
return '<div class="warning">' + Drupal.theme('tableDragChangedMarker') + ' ' + Drupal.t("Changes made in this table will not be saved until the form is submitted.") + '</div>';
};
+
+})(jQuery); \ No newline at end of file
diff --git a/misc/tableheader.js b/misc/tableheader.js
index dbb8873ea..1c8c9bf1c 100644
--- a/misc/tableheader.js
+++ b/misc/tableheader.js
@@ -1,4 +1,5 @@
// $Id$
+(function($) {
Drupal.tableHeaderDoScroll = function() {
if (typeof(Drupal.tableHeaderOnScroll)=='function') {
@@ -9,7 +10,7 @@ Drupal.tableHeaderDoScroll = function() {
Drupal.behaviors.tableHeader = {
attach: function(context) {
// This breaks in anything less than IE 7. Prevent it from running.
- if (jQuery.browser.msie && parseInt(jQuery.browser.version, 10) < 7) {
+ if ($.browser.msie && parseInt($.browser.version, 10) < 7) {
return;
}
@@ -113,3 +114,5 @@ Drupal.behaviors.tableHeader = {
$(window).resize(resize);
}
};
+
+})(jQuery);
diff --git a/misc/tableselect.js b/misc/tableselect.js
index 36a209f3c..152e93fb4 100644
--- a/misc/tableselect.js
+++ b/misc/tableselect.js
@@ -1,4 +1,5 @@
// $Id$
+(function($) {
Drupal.behaviors.tableSelect = {
attach: function(context) {
@@ -82,8 +83,10 @@ Drupal.tableSelectRange = function(from, to, state) {
}
}
// A faster alternative to doing $(i).filter(to).length.
- else if (jQuery.filter(to, [i]).r.length) {
+ else if ($.filter(to, [i]).r.length) {
break;
}
}
};
+
+})(jQuery);
diff --git a/misc/teaser.js b/misc/teaser.js
index e303aa963..af50803d4 100644
--- a/misc/teaser.js
+++ b/misc/teaser.js
@@ -1,4 +1,5 @@
// $Id$
+(function($) {
/**
* Auto-attach for teaser behavior.
@@ -96,3 +97,5 @@ Drupal.behaviors.teaser = {
});
}
};
+
+})(jQuery);
diff --git a/misc/textarea.js b/misc/textarea.js
index 246ca1571..68e696b2d 100644
--- a/misc/textarea.js
+++ b/misc/textarea.js
@@ -1,4 +1,5 @@
// $Id$
+(function($) {
Drupal.behaviors.textarea = {
attach: function(context) {
@@ -36,3 +37,5 @@ Drupal.behaviors.textarea = {
});
}
};
+
+})(jQuery);
diff --git a/misc/timezone.js b/misc/timezone.js
index 7cd4cdde9..db7c4560a 100644
--- a/misc/timezone.js
+++ b/misc/timezone.js
@@ -1,4 +1,5 @@
// $Id$
+(function($) {
/**
* Set the client's system time zone as default values of form fields.
@@ -57,8 +58,10 @@ Drupal.behaviors.setTimezone = {
if (data) {
$(element).val(data);
}
- },
+ }
});
});
}
};
+
+})(jQuery);
diff --git a/modules/block/block.js b/modules/block/block.js
index eeb9306e0..c9c00fab2 100644
--- a/modules/block/block.js
+++ b/modules/block/block.js
@@ -1,4 +1,5 @@
// $Id$
+(function($) {
/**
* Move a block in the blocks table from one region to another via select list.
@@ -95,3 +96,5 @@ Drupal.behaviors.blockDrag = {
};
}
};
+
+})(jQuery);
diff --git a/modules/book/book.module b/modules/book/book.module
index f2ffb7177..9ef7cecbb 100644
--- a/modules/book/book.module
+++ b/modules/book/book.module
@@ -415,7 +415,7 @@ function _book_parent_select($book_link) {
function _book_add_form_elements(&$form, $node) {
// Need this for AJAX.
$form['#cache'] = TRUE;
- drupal_add_js("if (Drupal.jsEnabled) { $(document).ready(function() { $('#edit-book-pick-book').css('display', 'none'); }); }", 'inline');
+ drupal_add_js("if (Drupal.jsEnabled) { jQuery(function() { jQuery('#edit-book-pick-book').css('display', 'none'); }); }", 'inline');
$form['book'] = array(
'#type' => 'fieldset',
diff --git a/modules/color/color.js b/modules/color/color.js
index 89c94dc37..ff2e51952 100644
--- a/modules/color/color.js
+++ b/modules/color/color.js
@@ -1,4 +1,5 @@
// $Id$
+(function($) {
Drupal.behaviors.color = {
attach: function(context) {
@@ -251,3 +252,5 @@ Drupal.behaviors.color = {
preview();
}
};
+
+})(jQuery);
diff --git a/modules/comment/comment.js b/modules/comment/comment.js
index b951f4211..acd450200 100644
--- a/modules/comment/comment.js
+++ b/modules/comment/comment.js
@@ -1,4 +1,5 @@
// $Id$
+(function($) {
Drupal.behaviors.comment = {
attach: function(context) {
@@ -35,3 +36,5 @@ Drupal.comment.getCookie = function(name) {
return returnValue;
};
+
+})(jQuery);
diff --git a/modules/node/content_types.js b/modules/node/content_types.js
index 61ff33493..7f6ff3a2d 100644
--- a/modules/node/content_types.js
+++ b/modules/node/content_types.js
@@ -1,3 +1,6 @@
+// $Id$
+(function($) {
+
Drupal.behaviors.contentTypes = {
attach: function() {
if ($('#edit-type').val() == $('#edit-name').val().toLowerCase().replace(/[^a-z0-9]+/g, '_').replace(/_+/g, '_') || $('#edit-type').val() == '') {
@@ -22,3 +25,5 @@ Drupal.behaviors.contentTypes = {
}
}
};
+
+})(jQuery);
diff --git a/modules/openid/openid.js b/modules/openid/openid.js
index eeb84300d..1511348c8 100644
--- a/modules/openid/openid.js
+++ b/modules/openid/openid.js
@@ -1,4 +1,5 @@
// $Id$
+(function($) {
Drupal.behaviors.openid = {
attach: function(context) {
@@ -38,3 +39,5 @@ Drupal.behaviors.openid = {
});
}
};
+
+})(jQuery);
diff --git a/modules/profile/profile.js b/modules/profile/profile.js
index d14be4b7d..7668e0ac5 100644
--- a/modules/profile/profile.js
+++ b/modules/profile/profile.js
@@ -1,4 +1,5 @@
// $Id$
+(function($) {
/**
* Add functionality to the profile drag and drop table.
@@ -54,3 +55,5 @@ Drupal.behaviors.profileDrag = {
};
}
};
+
+})(jQuery); \ No newline at end of file
diff --git a/modules/simpletest/simpletest.js b/modules/simpletest/simpletest.js
index efdc28366..9026de11b 100644
--- a/modules/simpletest/simpletest.js
+++ b/modules/simpletest/simpletest.js
@@ -1,4 +1,5 @@
// $Id$
+(function($) {
/**
* Add the cool table collapsing on the testing overview page.
@@ -76,7 +77,7 @@ Drupal.behaviors.simpleTestSelectAll = {
});
}
$(groupCheckbox).attr('checked', (checkedTests == testCheckboxes.length));
- }
+ };
// Have the single-test checkboxes follow the group checkbox.
groupCheckbox.change(function() {
@@ -99,3 +100,5 @@ Drupal.behaviors.simpleTestSelectAll = {
});
}
};
+
+})(jQuery);
diff --git a/modules/simpletest/tests/common.test b/modules/simpletest/tests/common.test
index 3aa248e6b..1bd40c27e 100644
--- a/modules/simpletest/tests/common.test
+++ b/modules/simpletest/tests/common.test
@@ -445,7 +445,7 @@ class JavaScriptTestCase extends DrupalWebTestCase {
* Test adding inline scripts.
*/
function testAddInline() {
- $inline = '$(document).ready(function(){});';
+ $inline = 'jQuery(function(){});';
$javascript = drupal_add_js($inline, array('type' => 'inline', 'scope' => 'footer'));
$this->assertTrue(array_key_exists('misc/jquery.js', $javascript), t('jQuery is added when inline scripts are added.'));
$data = end($javascript);
@@ -456,7 +456,7 @@ class JavaScriptTestCase extends DrupalWebTestCase {
* Test drupal_get_js() with a footer scope.
*/
function testFooterHTML() {
- $inline = '$(document).ready(function(){});';
+ $inline = 'jQuery(function(){});';
drupal_add_js($inline, array('type' => 'inline', 'scope' => 'footer'));
$javascript = drupal_get_js('footer');
$this->assertTrue(strpos($javascript, $inline) > 0, t('Rendered JavaScript footer returns the inline code.'));
diff --git a/modules/system/system.js b/modules/system/system.js
index 514dfb40a..8a47c3d10 100644
--- a/modules/system/system.js
+++ b/modules/system/system.js
@@ -1,4 +1,5 @@
// $Id$
+(function($) {
/**
* Internal function to check using Ajax if clean URLs can be enabled on the
@@ -80,7 +81,7 @@ Drupal.behaviors.copyFieldValue = {
for (var sourceId in Drupal.settings.copyFieldValue) {
// Get the list of target fields.
targetIds = Drupal.settings.copyFieldValue[sourceId];
- if (!$('#'+ sourceId + '.copy-field-values-processed').size(), context) {
+ if (!$('#'+ sourceId + '.copy-field-values-processed', context).size()) {
// Add the behavior to update target fields on blur of the primary field.
sourceField = $('#' + sourceId);
sourceField.bind('blur', function() {
@@ -131,4 +132,6 @@ Drupal.behaviors.poweredByPreview = {
$('img.powered-by-preview').attr('src', path);
});
}
-}; \ No newline at end of file
+};
+
+})(jQuery); \ No newline at end of file
diff --git a/modules/taxonomy/taxonomy.js b/modules/taxonomy/taxonomy.js
index bbf1f5c47..2ea68eb08 100644
--- a/modules/taxonomy/taxonomy.js
+++ b/modules/taxonomy/taxonomy.js
@@ -1,4 +1,5 @@
// $Id$
+(function($) {
/**
* Move a block in the blocks table from one region to another via select list.
@@ -36,3 +37,5 @@ Drupal.behaviors.termDrag = {
};
}
};
+
+})(jQuery);
diff --git a/modules/user/user.js b/modules/user/user.js
index 926a92137..0d3727a66 100644
--- a/modules/user/user.js
+++ b/modules/user/user.js
@@ -1,4 +1,5 @@
// $Id$
+(function($) {
/**
* Attach handlers to evaluate the strength of any password fields and to check
@@ -76,7 +77,7 @@ Drupal.behaviors.password = {
else {
confirmResult.css({ visibility: "hidden" });
}
- }
+ };
// Monitor keyup and blur events.
// Blur must be used because a mouse paste does not trigger keyup.
@@ -171,3 +172,5 @@ Drupal.behaviors.userSettings = {
});
}
};
+
+})(jQuery);