Use noConflict to avoid polluting globale namespace

with lodash and Backbone.
This commit is contained in:
JC Brand 2017-04-21 15:52:16 +02:00
parent 39b3aa34d8
commit 3ea43c6a0f
20 changed files with 59 additions and 35 deletions

View File

@ -150,9 +150,9 @@ dist/converse.min.js: src locale node_modules *.js
dist/converse.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 $(RJS) -o src/build.js include=converse out=dist/converse.js optimize=none
dist/converse-no-jquery.min.js: src locale node_modules *.js 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 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 dist/converse-no-dependencies.min.js: src locale node_modules *.js
$(RJS) -o src/build-no-dependencies.js $(RJS) -o src/build-no-dependencies.js
dist/converse-no-dependencies.js: src locale node_modules *.js dist/converse-no-dependencies.js: src locale node_modules *.js

View File

@ -9,6 +9,7 @@
- sinon 2.1.0 - sinon 2.1.0
- eslint 3.19.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: MUC user's nickname wasn't being shown in HTML5 notification messages. [jcbrand]
- Bugfix: OTR meta-messages were being shown in HTML5 notifications. [jcbrand] - Bugfix: OTR meta-messages were being shown in HTML5 notifications. [jcbrand]
- CSS fix: Icon lock wasn't showing. [jcbrand] - CSS fix: Icon lock wasn't showing. [jcbrand]

View File

@ -0,0 +1,4 @@
/*global define */
define(['backbone'], function (Backbone) {
return Backbone.noConflict();
});

View File

@ -26,7 +26,7 @@
exclude: [ exclude: [
"awesomplete", "awesomplete",
"jquery", "jquery",
"jquery-private", "jquery.noconflict",
"backbone.browserStorage", "backbone.browserStorage",
"backbone.overview", "backbone.overview",
"moment_with_locales", "moment_with_locales",

View File

@ -18,12 +18,13 @@ require.config({
"almond": "node_modules/almond/almond", "almond": "node_modules/almond/almond",
"awesomplete": "node_modules/awesomplete/awesomplete", "awesomplete": "node_modules/awesomplete/awesomplete",
"backbone": "node_modules/backbone/backbone", "backbone": "node_modules/backbone/backbone",
"backbone.noconflict": "src/backbone.noconflict",
"backbone.browserStorage": "node_modules/backbone.browserStorage/backbone.browserStorage", "backbone.browserStorage": "node_modules/backbone.browserStorage/backbone.browserStorage",
"backbone.overview": "node_modules/backbone.overview/backbone.overview", "backbone.overview": "node_modules/backbone.overview/backbone.overview",
"eventemitter": "node_modules/otr/build/dep/eventemitter", "eventemitter": "node_modules/otr/build/dep/eventemitter",
"es6-promise": "node_modules/es6-promise/dist/es6-promise", "es6-promise": "node_modules/es6-promise/dist/es6-promise",
"jquery": "node_modules/jquery/dist/jquery", "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.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 "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", "pluggable": "node_modules/pluggable.js/dist/pluggable",
@ -38,6 +39,7 @@ require.config({
"tpl": "node_modules/lodash-template-loader/loader", "tpl": "node_modules/lodash-template-loader/loader",
"typeahead": "components/typeahead.js/index", "typeahead": "components/typeahead.js/index",
"lodash": "node_modules/lodash/lodash", "lodash": "node_modules/lodash/lodash",
"lodash.noconflict": "src/lodash.noconflict",
"underscore": "src/underscore-shim", "underscore": "src/underscore-shim",
"utils": "src/utils", "utils": "src/utils",
@ -166,18 +168,20 @@ require.config({
}], }],
map: { map: {
// '*' means all modules will get 'jquery-private' // '*' means all modules will get the '*.noconflict' version
// for their 'jquery' dependency. // as their dependency.
'*': { '*': {
'jquery': 'jquery-private', 'jquery': 'jquery.noconflict',
'backbone': 'backbone.noconflict',
'lodash': 'lodash.noconflict',
'underscore': 'lodash.noconflict'
}, },
'backbone': { // '*.noconflict' wants the real module
"underscore": "lodash" // If this line was not here, there would
},
// 'jquery-private' wants the real jQuery module
// though. If this line was not here, there would
// be an unresolvable cyclic dependency. // be an unresolvable cyclic dependency.
'jquery-private': { 'jquery': 'jquery' } 'backbone.noconflict': { 'backbone': 'backbone' },
'jquery.noconflict': { 'jquery': 'jquery' },
'lodash.noconflict': { 'lodash': 'lodash' }
}, },
lodashLoader: { lodashLoader: {

View File

@ -4,7 +4,7 @@
// Copyright (c) 2012-2017, Jan-Carel Brand <jc@opkode.com> // Copyright (c) 2012-2017, Jan-Carel Brand <jc@opkode.com>
// Licensed under the Mozilla Public License (MPLv2) // Licensed under the Mozilla Public License (MPLv2)
// //
/*global Backbone, define */ /*global define */
/* This is a Converse.js plugin which add support for bookmarks specified /* This is a Converse.js plugin which add support for bookmarks specified
* in XEP-0048. * in XEP-0048.
@ -30,6 +30,7 @@
) { ) {
var $ = converse.env.jQuery, var $ = converse.env.jQuery,
Backbone = converse.env.Backbone,
Strophe = converse.env.Strophe, Strophe = converse.env.Strophe,
$iq = converse.env.$iq, $iq = converse.env.$iq,
b64_sha1 = converse.env.b64_sha1, b64_sha1 = converse.env.b64_sha1,

View File

@ -4,7 +4,7 @@
// Copyright (c) 2012-2017, Jan-Carel Brand <jc@opkode.com> // Copyright (c) 2012-2017, Jan-Carel Brand <jc@opkode.com>
// Licensed under the Mozilla Public License (MPLv2) // Licensed under the Mozilla Public License (MPLv2)
// //
/*global Backbone, define */ /*global define */
(function (root, factory) { (function (root, factory) {
define([ define([
@ -27,11 +27,12 @@
) { ) {
"use strict"; "use strict";
var $ = converse.env.jQuery, var $ = converse.env.jQuery,
utils = converse.env.utils,
Strophe = converse.env.Strophe,
$msg = converse.env.$msg, $msg = converse.env.$msg,
Backbone = converse.env.Backbone,
Strophe = converse.env.Strophe,
_ = converse.env._, _ = converse.env._,
moment = converse.env.moment; moment = converse.env.moment,
utils = converse.env.utils;
var KEY = { var KEY = {
ENTER: 13, ENTER: 13,

View File

@ -4,7 +4,7 @@
// Copyright (c) 2012-2017, Jan-Carel Brand <jc@opkode.com> // Copyright (c) 2012-2017, Jan-Carel Brand <jc@opkode.com>
// Licensed under the Mozilla Public License (MPLv2) // Licensed under the Mozilla Public License (MPLv2)
// //
/*global define, Backbone */ /*global define */
(function (root, factory) { (function (root, factory) {
define(["converse-core", define(["converse-core",
@ -45,6 +45,7 @@
var USERS_PANEL_ID = 'users'; var USERS_PANEL_ID = 'users';
// Strophe methods for building stanzas // Strophe methods for building stanzas
var Strophe = converse.env.Strophe, var Strophe = converse.env.Strophe,
Backbone = converse.env.Backbone,
utils = converse.env.utils; utils = converse.env.utils;
// Other necessary globals // Other necessary globals
var $ = converse.env.jQuery, var $ = converse.env.jQuery,

View File

@ -7,18 +7,19 @@
/*global Backbone, define, window, document, JSON */ /*global Backbone, define, window, document, JSON */
(function (root, factory) { (function (root, factory) {
define(["sizzle", define(["sizzle",
"jquery-private", "jquery.noconflict",
"lodash", "lodash.noconflict",
"polyfill", "polyfill",
"utils", "utils",
"moment_with_locales", "moment_with_locales",
"strophe", "strophe",
"pluggable", "pluggable",
"backbone.noconflict",
"strophe.disco", "strophe.disco",
"backbone.browserStorage", "backbone.browserStorage",
"backbone.overview", "backbone.overview",
], factory); ], 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. /* Cannot use this due to Safari bug.
* See https://github.com/jcbrand/converse.js/issues/196 * See https://github.com/jcbrand/converse.js/issues/196
*/ */
@ -2267,12 +2268,13 @@
'$iq': $iq, '$iq': $iq,
'$msg': $msg, '$msg': $msg,
'$pres': $pres, '$pres': $pres,
'Backbone': Backbone,
'Strophe': Strophe, 'Strophe': Strophe,
'b64_sha1': b64_sha1,
'_': _, '_': _,
'b64_sha1': b64_sha1,
'jQuery': $, 'jQuery': $,
'sizzle': sizzle,
'moment': moment, 'moment': moment,
'sizzle': sizzle,
'utils': utils 'utils': utils
} }
}; };

View File

@ -4,7 +4,7 @@
// Copyright (c) 2012-2017, Jan-Carel Brand <jc@opkode.com> // Copyright (c) 2012-2017, Jan-Carel Brand <jc@opkode.com>
// Licensed under the Mozilla Public License (MPLv2) // Licensed under the Mozilla Public License (MPLv2)
// //
/*global Backbone, define, window */ /*global define, window */
(function (root, factory) { (function (root, factory) {
define(["converse-core", define(["converse-core",
@ -26,6 +26,7 @@
"use strict"; "use strict";
var $ = converse.env.jQuery, var $ = converse.env.jQuery,
_ = converse.env._, _ = converse.env._,
Backbone = converse.env.Backbone,
b64_sha1 = converse.env.b64_sha1, b64_sha1 = converse.env.b64_sha1,
moment = converse.env.moment; moment = converse.env.moment;

View File

@ -4,11 +4,11 @@
// Copyright (c) 2012-2017, Jan-Carel Brand <jc@opkode.com> // Copyright (c) 2012-2017, Jan-Carel Brand <jc@opkode.com>
// Licensed under the Mozilla Public License (MPLv2) // Licensed under the Mozilla Public License (MPLv2)
// //
/*global Backbone */
(function (root, factory) { (function (root, factory) {
define(["converse-core", "converse-muc"], factory); define(["converse-core", "converse-muc"], factory);
}(this, function (converse) { }(this, function (converse) {
"use strict"; "use strict";
var Backbone = converse.env.Backbone;
converse.plugins.add('converse-muc-embedded', { converse.plugins.add('converse-muc-embedded', {
overrides: { overrides: {

View File

@ -4,7 +4,7 @@
// Copyright (c) 2012-2017, Jan-Carel Brand <jc@opkode.com> // Copyright (c) 2012-2017, Jan-Carel Brand <jc@opkode.com>
// Licensed under the Mozilla Public License (MPLv2) // 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 /* This is a Converse.js plugin which add support for multi-user chat rooms, as
* specified in XEP-0045 Multi-user chat. * specified in XEP-0045 Multi-user chat.
@ -56,6 +56,7 @@
// Strophe methods for building stanzas // Strophe methods for building stanzas
var Strophe = converse.env.Strophe, var Strophe = converse.env.Strophe,
Backbone = converse.env.Backbone,
$iq = converse.env.$iq, $iq = converse.env.$iq,
$build = converse.env.$build, $build = converse.env.$build,
$msg = converse.env.$msg, $msg = converse.env.$msg,

View File

@ -4,7 +4,7 @@
// Copyright (c) 2012-2017, Jan-Carel Brand <jc@opkode.com> // Copyright (c) 2012-2017, Jan-Carel Brand <jc@opkode.com>
// Licensed under the Mozilla Public License (MPLv2) // 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) /* This is a Converse.js plugin which add support Off-the-record (OTR)
* encryption of one-on-one chat messages. * encryption of one-on-one chat messages.

View File

@ -4,7 +4,7 @@
// Copyright (c) 2012-2017, Jan-Carel Brand <jc@opkode.com> // Copyright (c) 2012-2017, Jan-Carel Brand <jc@opkode.com>
// Licensed under the Mozilla Public License (MPLv2) // 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 /* This is a Converse.js plugin which add support for in-band registration
* as specified in XEP-0077. * as specified in XEP-0077.
@ -30,6 +30,7 @@
// Strophe methods for building stanzas // Strophe methods for building stanzas
var Strophe = converse.env.Strophe, var Strophe = converse.env.Strophe,
Backbone = converse.env.Backbone,
utils = converse.env.utils, utils = converse.env.utils,
$iq = converse.env.$iq; $iq = converse.env.$iq;
// Other necessary globals // Other necessary globals

View File

@ -4,7 +4,7 @@
// Copyright (c) 2012-2017, Jan-Carel Brand <jc@opkode.com> // Copyright (c) 2012-2017, Jan-Carel Brand <jc@opkode.com>
// Licensed under the Mozilla Public License (MPLv2) // Licensed under the Mozilla Public License (MPLv2)
// //
/*global Backbone, define */ /*global define */
(function (root, factory) { (function (root, factory) {
define(["converse-core", define(["converse-core",
@ -25,6 +25,7 @@
tpl_roster_item) { tpl_roster_item) {
"use strict"; "use strict";
var $ = converse.env.jQuery, var $ = converse.env.jQuery,
Backbone = converse.env.Backbone,
utils = converse.env.utils, utils = converse.env.utils,
Strophe = converse.env.Strophe, Strophe = converse.env.Strophe,
$iq = converse.env.$iq, $iq = converse.env.$iq,

View File

@ -1,9 +1,10 @@
define('jquery', [], function () { return jQuery; }); define('jquery', [], function () { return jQuery; });
define('jquery-private', [], function () { return jQuery; }); define('jquery.noconflict', [], function () { return jQuery; });
define('jquery.browser', [], function () { return jQuery; }); define('jquery.browser', [], function () { return jQuery; });
define('awesomplete', [], function () { return jQuery; }); define('awesomplete', [], function () { return jQuery; });
define('lodash', [], function () { return _; }); define('lodash', [], function () { return _; });
define('lodash.noconflict', [], function () { return _; });
define('moment_with_locales', [], function () { return moment; }); define('moment_with_locales', [], function () { return moment; });
define('strophe', [], function () { define('strophe', [], function () {
return { return {
@ -26,7 +27,8 @@
define('strophe.ping', ['strophe'], strophePlugin); define('strophe.ping', ['strophe'], strophePlugin);
define('strophe.rsm', ['strophe'], strophePlugin); define('strophe.rsm', ['strophe'], strophePlugin);
define('strophe.vcard', ['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.browserStorage', ['backbone'], emptyFunction);
define('backbone.overview', ['backbone'], emptyFunction); define('backbone.overview', ['backbone'], emptyFunction);
define('otr', [], function () { return { 'DSA': DSA, 'OTR': OTR };}); define('otr', [], function () { return { 'DSA': DSA, 'OTR': OTR };});

View File

@ -1,4 +1,4 @@
define('jquery', [], function () { return jQuery; }); define('jquery', [], function () { return jQuery; });
define('jquery-private', [], function () { return jQuery; }); define('jquery.noconflict', [], function () { return jQuery; });
return require('converse'); return require('converse');
})); }));

4
src/lodash.noconflict.js Normal file
View File

@ -0,0 +1,4 @@
/*global define */
define(['lodash'], function (_) {
return _.noConflict();
});

View File

@ -1,9 +1,9 @@
/*global define, escape, locales, Jed */ /*global define, escape, locales, Jed */
(function (root, factory) { (function (root, factory) {
define([ define([
"jquery-private", "jquery.noconflict",
"jquery.browser", "jquery.browser",
"lodash", "lodash.noconflict",
"locales", "locales",
"moment_with_locales", "moment_with_locales",
"tpl!field", "tpl!field",