diff --git a/Gruntfile.js b/Gruntfile.js
index 97f0acbb..6c095d7a 100644
--- a/Gruntfile.js
+++ b/Gruntfile.js
@@ -24,7 +24,7 @@ module.exports = function(grunt){
concat: {
dist: {
- src: ['src/base64.js', "src/sha1.js", "src/md5.js", "src/core.js", "src/bosh.js", "src/websocket.js" ],
+ 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'],
dest: '<%= pkg.name %>'
},
options: {
diff --git a/src/core.js b/src/core.js
index 8243d676..ce1e65dc 100644
--- a/src/core.js
+++ b/src/core.js
@@ -25,86 +25,12 @@
* http://tools.ietf.org/html/draft-ietf-xmpp-websocket-00
*/
-/** PrivateFunction: Function.prototype.bind
- * Bind a function to an instance.
- *
- * This Function object extension method creates a bound method similar
- * to those in Python. This means that the 'this' object will point
- * to the instance you want. See
- * MDC's bind() documentation and
- * Bound Functions and Function Imports in JavaScript
- * for a complete explanation.
- *
- * This extension already exists in some browsers (namely, Firefox 3), but
- * we provide it to support those that don't.
- *
- * Parameters:
- * (Object) obj - The object that will become 'this' in the bound function.
- * (Object) argN - An option argument that will be prepended to the
- * arguments given for the function call
- *
- * Returns:
- * The bound function.
- */
-if (!Function.prototype.bind) {
- Function.prototype.bind = function (obj /*, arg1, arg2, ... */)
- {
- var func = this;
- var _slice = Array.prototype.slice;
- var _concat = Array.prototype.concat;
- var _args = _slice.call(arguments, 1);
-
- return function () {
- return func.apply(obj ? obj : this,
- _concat.call(_args,
- _slice.call(arguments, 0)));
- };
- };
-}
-
-/** PrivateFunction: Array.prototype.indexOf
- * Return the index of an object in an array.
- *
- * This function is not supplied by some JavaScript implementations, so
- * we provide it if it is missing. This code is from:
- * http://developer.mozilla.org/En/Core_JavaScript_1.5_Reference:Objects:Array:indexOf
- *
- * Parameters:
- * (Object) elt - The object to look for.
- * (Integer) from - The index from which to start looking. (optional).
- *
- * Returns:
- * The index of elt in the array or -1 if not found.
- */
-if (!Array.prototype.indexOf)
-{
- Array.prototype.indexOf = function(elt /*, from*/)
- {
- var len = this.length;
-
- var from = Number(arguments[1]) || 0;
- from = (from < 0) ? Math.ceil(from) : Math.floor(from);
- if (from < 0) {
- from += len;
- }
-
- for (; from < len; from++) {
- if (from in this && this[from] === elt) {
- return from;
- }
- }
-
- return -1;
- };
-}
-
/* All of the Strophe globals are defined in this special function below so
* that references to the globals become closures. This will ensure that
* on page reload, these references will still be available to callbacks
* that are still executing.
*/
-(function (callback) {
var Strophe;
/** Function: $build
@@ -128,7 +54,9 @@ function $build(name, attrs) { return new Strophe.Builder(name, attrs); }
* Returns:
* A new Strophe.Builder object.
*/
+/* jshint ignore:start */
function $msg(attrs) { return new Strophe.Builder("message", attrs); }
+/* jshint ignore:end */
/** Function: $iq
* Create a Strophe.Builder with an element as the root.
*
@@ -2947,10 +2875,6 @@ Strophe.Connection.prototype = {
}
};
-if (callback) {
- callback(Strophe, $build, $msg, $iq, $pres);
-}
-
/** Class: Strophe.SASLMechanism
*
* encapsulates SASL authentication mechanisms.
@@ -3315,10 +3239,3 @@ Strophe.SASLMD5.prototype.onChallenge = function(connection, challenge, test_cno
Strophe.Connection.prototype.mechanisms[Strophe.SASLMD5.prototype.name] = Strophe.SASLMD5;
-})(function () {
- window.Strophe = arguments[0];
- window.$build = arguments[1];
- window.$msg = arguments[2];
- window.$iq = arguments[3];
- window.$pres = arguments[4];
-});
diff --git a/src/polyfills.js b/src/polyfills.js
new file mode 100644
index 00000000..7700133c
--- /dev/null
+++ b/src/polyfills.js
@@ -0,0 +1,87 @@
+/*
+ This program is distributed under the terms of the MIT license.
+ Please see the LICENSE file for details.
+
+ Copyright 2006-2008, OGG, LLC
+*/
+
+/* jshint undef: true, unused: true:, noarg: true, latedef: true */
+
+/** File: polyfills.js
+ * A JavaScript library for XMPP BOSH/XMPP over Websocket.
+ *
+ * This file contains some polyfills used by strophe.js
+ */
+
+/** PrivateFunction: Function.prototype.bind
+ * Bind a function to an instance.
+ *
+ * This Function object extension method creates a bound method similar
+ * to those in Python. This means that the 'this' object will point
+ * to the instance you want. See
+ * MDC's bind() documentation and
+ * Bound Functions and Function Imports in JavaScript
+ * for a complete explanation.
+ *
+ * This extension already exists in some browsers (namely, Firefox 3), but
+ * we provide it to support those that don't.
+ *
+ * Parameters:
+ * (Object) obj - The object that will become 'this' in the bound function.
+ * (Object) argN - An option argument that will be prepended to the
+ * arguments given for the function call
+ *
+ * Returns:
+ * The bound function.
+ */
+if (!Function.prototype.bind) {
+ Function.prototype.bind = function (obj /*, arg1, arg2, ... */)
+ {
+ var func = this;
+ var _slice = Array.prototype.slice;
+ var _concat = Array.prototype.concat;
+ var _args = _slice.call(arguments, 1);
+
+ return function () {
+ return func.apply(obj ? obj : this,
+ _concat.call(_args,
+ _slice.call(arguments, 0)));
+ };
+ };
+}
+
+/** PrivateFunction: Array.prototype.indexOf
+ * Return the index of an object in an array.
+ *
+ * This function is not supplied by some JavaScript implementations, so
+ * we provide it if it is missing. This code is from:
+ * http://developer.mozilla.org/En/Core_JavaScript_1.5_Reference:Objects:Array:indexOf
+ *
+ * Parameters:
+ * (Object) elt - The object to look for.
+ * (Integer) from - The index from which to start looking. (optional).
+ *
+ * Returns:
+ * The index of elt in the array or -1 if not found.
+ */
+if (!Array.prototype.indexOf)
+ {
+ Array.prototype.indexOf = function(elt /*, from*/)
+ {
+ var len = this.length;
+
+ var from = Number(arguments[1]) || 0;
+ from = (from < 0) ? Math.ceil(from) : Math.floor(from);
+ if (from < 0) {
+ from += len;
+ }
+
+ for (; from < len; from++) {
+ if (from in this && this[from] === elt) {
+ return from;
+ }
+ }
+
+ return -1;
+ };
+ }
diff --git a/src/wrap_footer.js b/src/wrap_footer.js
new file mode 100644
index 00000000..0af8d8da
--- /dev/null
+++ b/src/wrap_footer.js
@@ -0,0 +1,14 @@
+/* jshint ignore:start */
+if (callback) {
+ return callback(Strophe, $build, $msg, $iq, $pres);
+}
+
+
+})(function (Strophe, build, msg, iq, pres) {
+ window.Strophe = Strophe;
+ window.$build = build;
+ window.$msg = msg;
+ window.$iq = iq;
+ window.$pres = pres;
+});
+/* jshint ignore:end */
diff --git a/src/wrap_header.js b/src/wrap_header.js
new file mode 100644
index 00000000..f9d13449
--- /dev/null
+++ b/src/wrap_header.js
@@ -0,0 +1,9 @@
+/* All of the Strophe globals are defined in this special function below so
+ * that references to the globals become closures. This will ensure that
+ * on page reload, these references will still be available to callbacks
+ * that are still executing.
+ */
+
+/* jshint ignore:start */
+(function (callback) {
+/* jshint ignore:end */