diff --git a/includes/common.inc b/includes/common.inc index 7b97fe67d19fe56c5e2980b5457bd7b011c33200..806ae97e04fb1db877c5c4850bef6d044ce2c194 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 bd31efdc09cc87ba1a44ce166d64c6cf397bae29..67d1af596019f1eb25994ac07acf58202bff2401 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 ca5580a46be63bcc0fd05143d3868869deecbae5..e2469fe37294c91e30bb23b9b17f2df28b7179a7 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"> </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 da76380c450c531d100726f4f4bd2926ee7f3dc5..48253c70fec63461915713c2f597dd7164895fe7 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 4d1a4d551fbd4c4ce100d5b5f7739db3f113062e..17c4caae986dd5fdf288ba75881e22e3d95f6c18 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 4626b4519683d90f65b7787e3cbb15baf4a99ee6..7da7e16b1aaf55eb49795f11d102e156d4dd815a 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 9d5941f36dfde3448333de7c25e898847899849f..9b99a1d2eff62e36154c1478af0e1e9d91872f32 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 028b00b3649acb957e9ad8facf3d36bdfca199a0..18b083eab4372047cce11b0e45cf625a1171a77f 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 d3a9f692fbf9ef201c17426c3c5c24f20ab0fa06..8631ed68c81b3be762f3085777deb0e99c26d820 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 631a5f4f877892dd2621a637ed013cedaa33678d..b0fad15733d69364da50a349242263323dbe8d63 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 3fce730419aba736c28ac9be9530c39b60be3a9f..aea64d6170e1547377d0d1f38292071d917f19bc 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 dbb8873eac54221133c9b6d32d5ac808ef89f1fb..1c8c9bf1c9a69ea51b52f930a66b2d90dcf234c4 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 36a209f3ca19725c3b34296ef6ae7e17fd653a81..152e93fb4d7b24cd7ed0dc74623c4de5fd3c0d03 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 e303aa963e15d097056182426ad5d60e7ae53e06..af50803d4f83e419ea79adeeca823043cec735e6 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 246ca15715a9d27642760550f60cfb8dc9f6e851..68e696b2dff177120990cdb8b228bb1289908ddd 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 7cd4cdde9653b24393d849495197b7d33d23db5b..db7c4560af8beaa6151cd58c97c11c9fe27ad035 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 eeb9306e03cd36da686c8147e9f9a92381907c18..c9c00fab2330a169fd270896dea3885ff7fba157 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 f2ffb7177f73312c93d525bad16b8fd5d459d0f9..9ef7cecbb3339f6e91ca0f95551877330d5f5585 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 89c94dc37b97b3bf1c62994620ac1be362c76bc6..ff2e5195231fce1ae73876ed216884d5c425cde0 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 b951f4211839a4942551dcb01e540624de905e05..acd4502005d3f6ae57c97032b4d6f5bbbb1d99be 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 61ff334934e892737520e2152538acac3534b4a1..7f6ff3a2d3abf6ff0158ad0489504c2be1d0559d 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 eeb84300d80173a5358bebd89b90d2912b6894f5..1511348c8005bc9bf726740778bab79584dcaa65 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 d14be4b7d0d324c47c6c978396c706f49d1450de..7668e0ac55b64c0429e6e569b91af297326db2f0 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 efdc28366f7aaee12ef954077c6a01182d0cdd06..9026de11b002d7292a8d94c0de0de3031df64a15 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 3aa248e6baea98b94f277cdb801847cc149d5baf..1bd40c27ef5c8efc2a3b76c6007189d3ed8e6b87 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 514dfb40ab265ea66eab1939f612c41c897c6df3..8a47c3d10f26a4942bf39a4a360703c5273136ae 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 bbf1f5c47113fef22a66ed8bb4f8af7cde34d6ad..2ea68eb080c9718aef194810570330fcf0da9fc6 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 926a92137f6753f1b87e03f13df40e4f08bb83e3..0d3727a669509ccafcfdb62e25e767f5ca12f5e2 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);