Skip to content

Commit d66cf97

Browse files
committed
Improve support for AMD when loading compiled strophe.js
1 parent a11ebef commit d66cf97

File tree

5 files changed

+35
-9
lines changed

5 files changed

+35
-9
lines changed

.gitattributes

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
*.min.js binary

Gruntfile.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ module.exports = function(grunt){
3333

3434
concat: {
3535
dist: {
36-
src: ['src/wrap_header.js', 'src/base64.js', 'src/sha1.js', 'src/md5.js', 'src/polyfills.js', 'src/core.js', 'src/bosh.js', 'src/websocket.js', 'src/wrap_footer.js'],
36+
src: ['src/wrap_header.js', 'src/base64.js', 'src/sha1.js', 'src/md5.js', 'src/polyfills.js', 'src/core.js', 'src/bosh.js', 'src/websocket.js', 'src/wrapper.js', 'src/wrap_footer.js'],
3737
dest: '<%= pkg.name %>'
3838
},
3939
options: {

src/polyfills.js

+13
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,18 @@
66
*/
77

88
/* jshint undef: true, unused: true:, noarg: true, latedef: true */
9+
/* global define */
10+
11+
(function (root, factory) {
12+
if (typeof define === 'function' && define.amd) {
13+
define('strophe-polyfill', [], function () {
14+
return factory();
15+
});
16+
} else {
17+
// Browser globals
18+
return factory();
19+
}
20+
}(this, function () {
921

1022
/** PrivateFunction: Function.prototype.bind
1123
* Bind a function to an instance.
@@ -88,3 +100,4 @@ if (!Array.prototype.indexOf)
88100
return -1;
89101
};
90102
}
103+
}));

src/wrap_footer.js

+9-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,14 @@
11
/* jshint ignore:start */
22
if (callback) {
3-
return callback(Strophe, $build, $msg, $iq, $pres);
3+
if(typeof define === 'function' && define.amd){
4+
//For backwards compatability
5+
var n_callback = callback;
6+
require(["strophe"],function(o){
7+
n_callback(o.Strophe,o.$build,o.$msg,o.$iq,o.$pres);
8+
});
9+
}else{
10+
return callback(Strophe, $build, $msg, $iq, $pres);
11+
}
412
}
513

614

src/wrapper.js

+11-7
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
1-
define("strophe", [
2-
"strophe-core",
3-
"strophe-bosh",
4-
"strophe-websocket"
5-
], function (wrapper) {
6-
return wrapper;
7-
});
1+
(function(root){
2+
if(typeof define === 'function' && define.amd){
3+
define("strophe", [
4+
"strophe-core",
5+
"strophe-bosh",
6+
"strophe-websocket"
7+
], function (wrapper) {
8+
return wrapper;
9+
});
10+
}
11+
})(this);

0 commit comments

Comments
 (0)