diff --git a/Makefile b/Makefile index 8856acf37..82db05223 100644 --- a/Makefile +++ b/Makefile @@ -150,9 +150,9 @@ dist/converse.min.js: src locale node_modules *.js dist/converse.js: src locale node_modules *.js $(RJS) -o src/build.js include=converse out=dist/converse.js optimize=none dist/converse-no-jquery.min.js: src locale node_modules *.js - $(RJS) -o src/build.js include=converse wrap.endFile=end-no-jquery.frag exclude=jquery exclude=jquery-private out=dist/converse-no-jquery.min.js + $(RJS) -o src/build.js include=converse wrap.endFile=end-no-jquery.frag exclude=jquery exclude=jquery.noconflict out=dist/converse-no-jquery.min.js dist/converse-no-jquery.js: src locale node_modules *.js - $(RJS) -o src/build.js include=converse wrap.endFile=end-no-jquery.frag exclude=jquery exclude=jquery-private out=dist/converse-no-jquery.js optimize=none + $(RJS) -o src/build.js include=converse wrap.endFile=end-no-jquery.frag exclude=jquery exclude=jquery.noconflict out=dist/converse-no-jquery.js optimize=none dist/converse-no-dependencies.min.js: src locale node_modules *.js $(RJS) -o src/build-no-dependencies.js dist/converse-no-dependencies.js: src locale node_modules *.js diff --git a/docs/CHANGES.md b/docs/CHANGES.md index 9fa622848..70a549865 100755 --- a/docs/CHANGES.md +++ b/docs/CHANGES.md @@ -9,6 +9,7 @@ - sinon 2.1.0 - eslint 3.19.0 +- Use `noConflict` to avoid polluting globale namespace with lodash and Backbone. [jcbrand] - Bugfix: MUC user's nickname wasn't being shown in HTML5 notification messages. [jcbrand] - Bugfix: OTR meta-messages were being shown in HTML5 notifications. [jcbrand] - CSS fix: Icon lock wasn't showing. [jcbrand] diff --git a/src/backbone.noconflict.js b/src/backbone.noconflict.js new file mode 100644 index 000000000..07c6b1adb --- /dev/null +++ b/src/backbone.noconflict.js @@ -0,0 +1,4 @@ +/*global define */ +define(['backbone'], function (Backbone) { + return Backbone.noConflict(); +}); diff --git a/src/build-no-dependencies.js b/src/build-no-dependencies.js index cf533abc3..18c49ea77 100644 --- a/src/build-no-dependencies.js +++ b/src/build-no-dependencies.js @@ -26,7 +26,7 @@ exclude: [ "awesomplete", "jquery", - "jquery-private", + "jquery.noconflict", "backbone.browserStorage", "backbone.overview", "moment_with_locales", diff --git a/src/config.js b/src/config.js index 6e5c74b2e..dcc2bcff8 100644 --- a/src/config.js +++ b/src/config.js @@ -18,12 +18,13 @@ require.config({ "almond": "node_modules/almond/almond", "awesomplete": "node_modules/awesomplete/awesomplete", "backbone": "node_modules/backbone/backbone", + "backbone.noconflict": "src/backbone.noconflict", "backbone.browserStorage": "node_modules/backbone.browserStorage/backbone.browserStorage", "backbone.overview": "node_modules/backbone.overview/backbone.overview", "eventemitter": "node_modules/otr/build/dep/eventemitter", "es6-promise": "node_modules/es6-promise/dist/es6-promise", "jquery": "node_modules/jquery/dist/jquery", - "jquery-private": "src/jquery-private", + "jquery.noconflict": "src/jquery.noconflict", "jquery.browser": "node_modules/jquery.browser/dist/jquery.browser", "jquery.easing": "node_modules/jquery-easing/jquery.easing.1.3.umd", // XXX: Only required for https://conversejs.org website "pluggable": "node_modules/pluggable.js/dist/pluggable", @@ -38,6 +39,7 @@ require.config({ "tpl": "node_modules/lodash-template-loader/loader", "typeahead": "components/typeahead.js/index", "lodash": "node_modules/lodash/lodash", + "lodash.noconflict": "src/lodash.noconflict", "underscore": "src/underscore-shim", "utils": "src/utils", @@ -166,18 +168,20 @@ require.config({ }], map: { - // '*' means all modules will get 'jquery-private' - // for their 'jquery' dependency. + // '*' means all modules will get the '*.noconflict' version + // as their dependency. '*': { - 'jquery': 'jquery-private', + 'jquery': 'jquery.noconflict', + 'backbone': 'backbone.noconflict', + 'lodash': 'lodash.noconflict', + 'underscore': 'lodash.noconflict' }, - 'backbone': { - "underscore": "lodash" - }, - // 'jquery-private' wants the real jQuery module - // though. If this line was not here, there would + // '*.noconflict' wants the real module + // If this line was not here, there would // be an unresolvable cyclic dependency. - 'jquery-private': { 'jquery': 'jquery' } + 'backbone.noconflict': { 'backbone': 'backbone' }, + 'jquery.noconflict': { 'jquery': 'jquery' }, + 'lodash.noconflict': { 'lodash': 'lodash' } }, lodashLoader: { diff --git a/src/converse-bookmarks.js b/src/converse-bookmarks.js index e374d882e..8e2d4fc30 100644 --- a/src/converse-bookmarks.js +++ b/src/converse-bookmarks.js @@ -4,7 +4,7 @@ // Copyright (c) 2012-2017, Jan-Carel Brand // Licensed under the Mozilla Public License (MPLv2) // -/*global Backbone, define */ +/*global define */ /* This is a Converse.js plugin which add support for bookmarks specified * in XEP-0048. @@ -30,6 +30,7 @@ ) { var $ = converse.env.jQuery, + Backbone = converse.env.Backbone, Strophe = converse.env.Strophe, $iq = converse.env.$iq, b64_sha1 = converse.env.b64_sha1, diff --git a/src/converse-chatview.js b/src/converse-chatview.js index ba8a1de57..6d88f40c6 100644 --- a/src/converse-chatview.js +++ b/src/converse-chatview.js @@ -4,7 +4,7 @@ // Copyright (c) 2012-2017, Jan-Carel Brand // Licensed under the Mozilla Public License (MPLv2) // -/*global Backbone, define */ +/*global define */ (function (root, factory) { define([ @@ -27,11 +27,12 @@ ) { "use strict"; var $ = converse.env.jQuery, - utils = converse.env.utils, - Strophe = converse.env.Strophe, $msg = converse.env.$msg, + Backbone = converse.env.Backbone, + Strophe = converse.env.Strophe, _ = converse.env._, - moment = converse.env.moment; + moment = converse.env.moment, + utils = converse.env.utils; var KEY = { ENTER: 13, diff --git a/src/converse-controlbox.js b/src/converse-controlbox.js index c28d2c265..f4b9e8eeb 100644 --- a/src/converse-controlbox.js +++ b/src/converse-controlbox.js @@ -4,7 +4,7 @@ // Copyright (c) 2012-2017, Jan-Carel Brand // Licensed under the Mozilla Public License (MPLv2) // -/*global define, Backbone */ +/*global define */ (function (root, factory) { define(["converse-core", @@ -45,6 +45,7 @@ var USERS_PANEL_ID = 'users'; // Strophe methods for building stanzas var Strophe = converse.env.Strophe, + Backbone = converse.env.Backbone, utils = converse.env.utils; // Other necessary globals var $ = converse.env.jQuery, diff --git a/src/converse-core.js b/src/converse-core.js index 0f4b67c5e..1b40f4947 100755 --- a/src/converse-core.js +++ b/src/converse-core.js @@ -7,18 +7,19 @@ /*global Backbone, define, window, document, JSON */ (function (root, factory) { define(["sizzle", - "jquery-private", - "lodash", + "jquery.noconflict", + "lodash.noconflict", "polyfill", "utils", "moment_with_locales", "strophe", "pluggable", + "backbone.noconflict", "strophe.disco", "backbone.browserStorage", "backbone.overview", ], factory); -}(this, function (sizzle, $, _, polyfill, utils, moment, Strophe, pluggable) { +}(this, function (sizzle, $, _, polyfill, utils, moment, Strophe, pluggable, Backbone) { /* Cannot use this due to Safari bug. * See https://github.com/jcbrand/converse.js/issues/196 */ @@ -2267,12 +2268,13 @@ '$iq': $iq, '$msg': $msg, '$pres': $pres, + 'Backbone': Backbone, 'Strophe': Strophe, - 'b64_sha1': b64_sha1, '_': _, + 'b64_sha1': b64_sha1, 'jQuery': $, - 'sizzle': sizzle, 'moment': moment, + 'sizzle': sizzle, 'utils': utils } }; diff --git a/src/converse-minimize.js b/src/converse-minimize.js index 668bc277d..0d8bb34a6 100644 --- a/src/converse-minimize.js +++ b/src/converse-minimize.js @@ -4,7 +4,7 @@ // Copyright (c) 2012-2017, Jan-Carel Brand // Licensed under the Mozilla Public License (MPLv2) // -/*global Backbone, define, window */ +/*global define, window */ (function (root, factory) { define(["converse-core", @@ -26,6 +26,7 @@ "use strict"; var $ = converse.env.jQuery, _ = converse.env._, + Backbone = converse.env.Backbone, b64_sha1 = converse.env.b64_sha1, moment = converse.env.moment; diff --git a/src/converse-muc-embedded.js b/src/converse-muc-embedded.js index fd1dd7ec6..b7368900d 100644 --- a/src/converse-muc-embedded.js +++ b/src/converse-muc-embedded.js @@ -4,11 +4,11 @@ // Copyright (c) 2012-2017, Jan-Carel Brand // Licensed under the Mozilla Public License (MPLv2) // -/*global Backbone */ (function (root, factory) { define(["converse-core", "converse-muc"], factory); }(this, function (converse) { "use strict"; + var Backbone = converse.env.Backbone; converse.plugins.add('converse-muc-embedded', { overrides: { diff --git a/src/converse-muc.js b/src/converse-muc.js index 1803a9415..e08b4809d 100755 --- a/src/converse-muc.js +++ b/src/converse-muc.js @@ -4,7 +4,7 @@ // Copyright (c) 2012-2017, Jan-Carel Brand // Licensed under the Mozilla Public License (MPLv2) // -/*global Backbone, define */ +/*global define */ /* This is a Converse.js plugin which add support for multi-user chat rooms, as * specified in XEP-0045 Multi-user chat. @@ -56,6 +56,7 @@ // Strophe methods for building stanzas var Strophe = converse.env.Strophe, + Backbone = converse.env.Backbone, $iq = converse.env.$iq, $build = converse.env.$build, $msg = converse.env.$msg, diff --git a/src/converse-otr.js b/src/converse-otr.js index 89a5a1b21..314ee9289 100644 --- a/src/converse-otr.js +++ b/src/converse-otr.js @@ -4,7 +4,7 @@ // Copyright (c) 2012-2017, Jan-Carel Brand // Licensed under the Mozilla Public License (MPLv2) // -/*global Backbone, define, window, crypto, CryptoJS */ +/*global define, window, crypto, CryptoJS */ /* This is a Converse.js plugin which add support Off-the-record (OTR) * encryption of one-on-one chat messages. diff --git a/src/converse-register.js b/src/converse-register.js index cc897fed8..b4f4b7f9b 100644 --- a/src/converse-register.js +++ b/src/converse-register.js @@ -4,7 +4,7 @@ // Copyright (c) 2012-2017, Jan-Carel Brand // Licensed under the Mozilla Public License (MPLv2) // -/*global Backbone, define */ +/*global define */ /* This is a Converse.js plugin which add support for in-band registration * as specified in XEP-0077. @@ -30,6 +30,7 @@ // Strophe methods for building stanzas var Strophe = converse.env.Strophe, + Backbone = converse.env.Backbone, utils = converse.env.utils, $iq = converse.env.$iq; // Other necessary globals diff --git a/src/converse-rosterview.js b/src/converse-rosterview.js index e7d5664de..623022f6b 100644 --- a/src/converse-rosterview.js +++ b/src/converse-rosterview.js @@ -4,7 +4,7 @@ // Copyright (c) 2012-2017, Jan-Carel Brand // Licensed under the Mozilla Public License (MPLv2) // -/*global Backbone, define */ +/*global define */ (function (root, factory) { define(["converse-core", @@ -25,6 +25,7 @@ tpl_roster_item) { "use strict"; var $ = converse.env.jQuery, + Backbone = converse.env.Backbone, utils = converse.env.utils, Strophe = converse.env.Strophe, $iq = converse.env.$iq, diff --git a/src/end-no-dependencies.frag b/src/end-no-dependencies.frag index 8b19b210f..164d87b5d 100644 --- a/src/end-no-dependencies.frag +++ b/src/end-no-dependencies.frag @@ -1,9 +1,10 @@ define('jquery', [], function () { return jQuery; }); - define('jquery-private', [], function () { return jQuery; }); + define('jquery.noconflict', [], function () { return jQuery; }); define('jquery.browser', [], function () { return jQuery; }); define('awesomplete', [], function () { return jQuery; }); define('lodash', [], function () { return _; }); + define('lodash.noconflict', [], function () { return _; }); define('moment_with_locales', [], function () { return moment; }); define('strophe', [], function () { return { @@ -26,7 +27,8 @@ define('strophe.ping', ['strophe'], strophePlugin); define('strophe.rsm', ['strophe'], strophePlugin); define('strophe.vcard', ['strophe'], strophePlugin); - define('backbone', [], emptyFunction); + define('backbone', [], function () { return Backbone; }); + define('backbone.noconflict', [], function () { return Backbone; }); define('backbone.browserStorage', ['backbone'], emptyFunction); define('backbone.overview', ['backbone'], emptyFunction); define('otr', [], function () { return { 'DSA': DSA, 'OTR': OTR };}); diff --git a/src/end-no-jquery.frag b/src/end-no-jquery.frag index 30cd069fb..9f92b4633 100644 --- a/src/end-no-jquery.frag +++ b/src/end-no-jquery.frag @@ -1,4 +1,4 @@ define('jquery', [], function () { return jQuery; }); - define('jquery-private', [], function () { return jQuery; }); + define('jquery.noconflict', [], function () { return jQuery; }); return require('converse'); })); diff --git a/src/jquery-private.js b/src/jquery.noconflict.js similarity index 100% rename from src/jquery-private.js rename to src/jquery.noconflict.js diff --git a/src/lodash.noconflict.js b/src/lodash.noconflict.js new file mode 100644 index 000000000..deb172f0b --- /dev/null +++ b/src/lodash.noconflict.js @@ -0,0 +1,4 @@ +/*global define */ +define(['lodash'], function (_) { + return _.noConflict(); +}); diff --git a/src/utils.js b/src/utils.js index 1e1b3a55c..f716b27c0 100755 --- a/src/utils.js +++ b/src/utils.js @@ -1,9 +1,9 @@ /*global define, escape, locales, Jed */ (function (root, factory) { define([ - "jquery-private", + "jquery.noconflict", "jquery.browser", - "lodash", + "lodash.noconflict", "locales", "moment_with_locales", "tpl!field",