diff --git a/includes/common.inc b/includes/common.inc
index 43f05d4c6df..9dde138d684 100644
--- a/includes/common.inc
+++ b/includes/common.inc
@@ -2122,6 +2122,8 @@ function drupal_clear_css_cache() {
* Executes a piece of JavaScript code on the current page by placing the code
* 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.
+ * When adding inline code, make sure that you are not relying ont $ 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
diff --git a/install.php b/install.php
index 68b35406d89..1e9c7fb6fab 100644
--- a/install.php
+++ b/install.php
@@ -745,7 +745,7 @@ function install_tasks($profile, $task) {
drupal_add_js('
// Global Killswitch
if (Drupal.jsEnabled) {
- $(document).ready(function() {
+ jQuery(document).ready(function() {
Drupal.cleanURLsInstallCheck();
Drupal.setDefaultTimezone();
});
diff --git a/misc/ahah.js b/misc/ahah.js
index 118c4def4d2..5df872d36ba 100644
--- a/misc/ahah.js
+++ b/misc/ahah.js
@@ -1,3 +1,4 @@
+(function($) {
/**
* Provides AJAX-like page updating via AHAH (Asynchronous HTML and HTTP).
@@ -135,7 +136,7 @@ Drupal.ahah.prototype.beforeSubmit = function (form_values, element, options) {
else if (this.progress.type == 'throbber') {
this.progress.element = $('
');
if (this.progress.message) {
- $('.throbber', this.progress.element).after('' + this.progress.message + '
')
+ $('.throbber', this.progress.element).after('' + this.progress.message + '
');
}
$(this.element).after(this.progress.element);
}
@@ -222,3 +223,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 8d0dcbe2721..c3c00de8a86 100644
--- a/misc/autocomplete.js
+++ b/misc/autocomplete.js
@@ -1,3 +1,4 @@
+(function($) {
/**
* Attaches the autocomplete behavior to all required fields
@@ -295,3 +296,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 fe015543773..ccd4d98d708 100644
--- a/misc/batch.js
+++ b/misc/batch.js
@@ -1,3 +1,4 @@
+(function($) {
/**
* Attaches the batch behavior to progress bars.
@@ -35,3 +36,5 @@ Drupal.behaviors.batch = function (context) {
progress.startMonitoring(uri+'&op=do', 10);
});
};
+
+})(jQuery);
diff --git a/misc/collapse.js b/misc/collapse.js
index 9581db999e1..f9afc90dcdb 100644
--- a/misc/collapse.js
+++ b/misc/collapse.js
@@ -1,3 +1,4 @@
+(function($) {
/**
* Toggle the visibility of a fieldset using smooth animations
@@ -74,3 +75,5 @@ Drupal.behaviors.collapse = function (context) {
.addClass('collapse-processed');
});
};
+
+})(jQuery);
diff --git a/misc/drupal.js b/misc/drupal.js
index 035da0c21cb..da84897961f 100644
--- a/misc/drupal.js
+++ b/misc/drupal.js
@@ -1,6 +1,11 @@
var Drupal = Drupal || { 'settings': {}, 'behaviors': {}, 'themes': {}, 'locale': {} };
+// Allow other JavaScript libraries to use $.
+jQuery.noConflict();
+
+(function($) {
+
/**
* Set the variable that indicates if JavaScript behaviors should be applied
*/
@@ -250,7 +255,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 {
@@ -287,3 +292,5 @@ Drupal.theme.prototype = {
return '' + Drupal.checkPlain(str) + '';
}
};
+
+})(jQuery);
diff --git a/misc/farbtastic/farbtastic.js b/misc/farbtastic/farbtastic.js
index 0094a725175..862eddfe39e 100644
--- a/misc/farbtastic/farbtastic.js
+++ b/misc/farbtastic/farbtastic.js
@@ -1,16 +1,17 @@
// Farbtastic 1.2
+(function($) {
-jQuery.fn.farbtastic = function (callback) {
+$.fn.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;
@@ -311,4 +312,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 3b0bb9cc475..4abe90fd75f 100644
--- a/misc/form.js
+++ b/misc/form.js
@@ -1,3 +1,4 @@
+(function($) {
Drupal.behaviors.multiselectSelector = function() {
// Automatically selects the right radio button in a multiselect control.
@@ -7,3 +8,5 @@ Drupal.behaviors.multiselectSelector = function() {
.attr('checked', true);
});
};
+
+})(jQuery);
diff --git a/misc/progress.js b/misc/progress.js
index b588948c61b..514020372b0 100644
--- a/misc/progress.js
+++ b/misc/progress.js
@@ -1,3 +1,4 @@
+(function($) {
/**
* A progressbar object. Initialized with the given id. Must be inserted into
@@ -104,3 +105,5 @@ Drupal.progressBar.prototype.displayError = function (string) {
this.errorCallback(this);
}
};
+
+})(jQuery);
diff --git a/misc/tabledrag.js b/misc/tabledrag.js
index 99168215dea..fee08054834 100644
--- a/misc/tabledrag.js
+++ b/misc/tabledrag.js
@@ -1,3 +1,4 @@
+(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.
@@ -958,7 +961,7 @@ Drupal.tableDrag.prototype.row.prototype.validIndentInterval = function (prevRow
}
return {'min':minIndent, 'max':maxIndent};
-}
+};
/**
* Indent a row within the legal bounds of the table.
@@ -1022,7 +1025,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 indentaiton.
if (this.indentEnabled) {
- var checkRowIndentation = $('.indentation', checkRow).length
+ var checkRowIndentation = $('.indentation', checkRow).length;
}
if (!(this.indentEnabled) || (checkRowIndentation == rowIndentation)) {
@@ -1097,3 +1100,5 @@ Drupal.theme.prototype.tableDragIndentation = function () {
Drupal.theme.prototype.tableDragChangedWarning = function () {
return '' + Drupal.theme('tableDragChangedMarker') + ' ' + Drupal.t("Changes made in this table will not be saved until the form is submitted.") + '
';
};
+
+})(jQuery);
diff --git a/misc/tableheader.js b/misc/tableheader.js
index 9d05e2307fe..5fad6e504d4 100644
--- a/misc/tableheader.js
+++ b/misc/tableheader.js
@@ -1,3 +1,4 @@
+(function($) {
Drupal.tableHeaderDoScroll = function() {
if (typeof(Drupal.tableHeaderOnScroll)=='function') {
@@ -114,3 +115,5 @@ Drupal.behaviors.tableHeader = function (context) {
};
$(window).resize(resize);
};
+
+})(jQuery);
diff --git a/misc/tableselect.js b/misc/tableselect.js
index d085a9b46fc..7b82317e056 100644
--- a/misc/tableselect.js
+++ b/misc/tableselect.js
@@ -1,3 +1,4 @@
+(function($) {
Drupal.behaviors.tableSelect = function (context) {
$('form table:has(th.select-all):not(.tableSelect-processed)', context).each(Drupal.tableSelect);
@@ -79,8 +80,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 da1acfbbaa3..7c1a81201b7 100644
--- a/misc/teaser.js
+++ b/misc/teaser.js
@@ -1,3 +1,4 @@
+(function($) {
/**
* Auto-attach for teaser behavior.
@@ -93,3 +94,5 @@ Drupal.behaviors.teaser = function(context) {
});
};
+
+})(jQuery);
diff --git a/misc/textarea.js b/misc/textarea.js
index 067586b4385..575f39d3a7a 100644
--- a/misc/textarea.js
+++ b/misc/textarea.js
@@ -1,4 +1,4 @@
-
+(function($) {
Drupal.behaviors.textarea = function(context) {
$('textarea.resizable:not(.textarea-processed)', context).each(function() {
// Avoid non-processed teasers.
@@ -33,3 +33,5 @@ Drupal.behaviors.textarea = function(context) {
}
});
};
+
+})(jQuery);
diff --git a/modules/block/block.js b/modules/block/block.js
index c1b7eb6c59d..6b1337ae8ad 100644
--- a/modules/block/block.js
+++ b/modules/block/block.js
@@ -1,3 +1,4 @@
+(function($) {
/**
* Move a block in the blocks table from one region to another via select list.
@@ -92,3 +93,5 @@ Drupal.behaviors.blockDrag = function(context) {
});
};
};
+
+})(jQuery);
diff --git a/modules/book/book.module b/modules/book/book.module
index 966330b373a..2b49d4df025 100644
--- a/modules/book/book.module
+++ b/modules/book/book.module
@@ -361,7 +361,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 e024cf5c9dd..57d44852708 100644
--- a/modules/color/color.js
+++ b/modules/color/color.js
@@ -1,3 +1,4 @@
+(function($) {
Drupal.behaviors.color = function (context) {
// This behavior attaches by ID, so is only valid once on a page.
@@ -248,3 +249,5 @@ Drupal.behaviors.color = function (context) {
// Render preview
preview();
};
+
+})(jQuery);
diff --git a/modules/comment/comment.js b/modules/comment/comment.js
index 451bc8a5672..01fa7c68c4a 100644
--- a/modules/comment/comment.js
+++ b/modules/comment/comment.js
@@ -1,3 +1,4 @@
+(function($) {
Drupal.behaviors.comment = function (context) {
var parts = new Array("name", "homepage", "mail");
@@ -32,3 +33,5 @@ Drupal.comment.getCookie = function(name) {
return returnValue;
};
+
+})(jQuery);
diff --git a/modules/profile/profile.js b/modules/profile/profile.js
index 7661d23b2d7..9a44096c789 100644
--- a/modules/profile/profile.js
+++ b/modules/profile/profile.js
@@ -1,3 +1,4 @@
+(function($) {
/**
* Add functionality to the profile drag and drop table.
@@ -51,3 +52,5 @@ Drupal.behaviors.profileDrag = function(context) {
}
};
};
+
+})(jQuery);
diff --git a/modules/simpletest/simpletest.js b/modules/simpletest/simpletest.js
index 16e9869acd2..f7c98dd78e8 100644
--- a/modules/simpletest/simpletest.js
+++ b/modules/simpletest/simpletest.js
@@ -1,6 +1,6 @@
// $Id: simpletest.js,v 1.2.4.6 2009/12/14 23:29:36 boombatower Exp $
// Core: Id: simpletest.js,v 1.11 2009/04/27 20:19:37 webchick Exp
-//(function ($) {
+(function ($) {
/**
* Add the cool table collapsing on the testing overview page.
@@ -111,4 +111,4 @@ Drupal.behaviors.simpleTestSelectAll = function() {
// }
};
-//})(jQuery);
+})(jQuery);
diff --git a/modules/system/system.js b/modules/system/system.js
index 48fd016a5f9..1aee373e4c7 100644
--- a/modules/system/system.js
+++ b/modules/system/system.js
@@ -1,3 +1,4 @@
+(function($) {
/**
* Internal function to check using Ajax if clean URLs can be enabled on the
@@ -73,7 +74,7 @@ Drupal.behaviors.copyFieldValue = function (context) {
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() {
@@ -110,3 +111,5 @@ Drupal.behaviors.dateTime = function(context) {
// Trigger the event handler to show the form input if necessary.
$('select.date-format', context).trigger('change');
};
+
+})(jQuery);
diff --git a/modules/taxonomy/taxonomy.js b/modules/taxonomy/taxonomy.js
index 34ae84adbda..c1017f351b0 100644
--- a/modules/taxonomy/taxonomy.js
+++ b/modules/taxonomy/taxonomy.js
@@ -1,3 +1,4 @@
+(function($) {
/**
* Move a block in the blocks table from one region to another via select list.
@@ -33,3 +34,5 @@ Drupal.behaviors.termDrag = function(context) {
}
};
};
+
+})(jQuery);
diff --git a/modules/user/user.js b/modules/user/user.js
index 46bfad0032b..0b1196b73e2 100644
--- a/modules/user/user.js
+++ b/modules/user/user.js
@@ -1,3 +1,4 @@
+(function($) {
/**
* Attach handlers to evaluate the strength of any password fields and to check
@@ -185,3 +186,4 @@ Drupal.behaviors.userSettings = function (context) {
});
};
+})(jQuery);