Skip to content

Commit

Permalink
split files up, strophe si now correctly wrapped
Browse files Browse the repository at this point in the history
  • Loading branch information
Gordin committed Sep 26, 2014
1 parent d3f9db5 commit 6196d0a
Show file tree
Hide file tree
Showing 5 changed files with 113 additions and 86 deletions.
2 changes: 1 addition & 1 deletion Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down
87 changes: 2 additions & 85 deletions src/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
* <a href='https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Function/bind'>MDC's bind() documentation</a> and
* <a href='http://benjamin.smedbergs.us/blog/2007-01-03/bound-functions-and-function-imports-in-javascript/'>Bound Functions and Function Imports in JavaScript</a>
* 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
Expand All @@ -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 <iq/> element as the root.
*
Expand Down Expand Up @@ -2947,10 +2875,6 @@ Strophe.Connection.prototype = {
}
};

if (callback) {
callback(Strophe, $build, $msg, $iq, $pres);
}

/** Class: Strophe.SASLMechanism
*
* encapsulates SASL authentication mechanisms.
Expand Down Expand Up @@ -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];
});
87 changes: 87 additions & 0 deletions src/polyfills.js
Original file line number Diff line number Diff line change
@@ -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
* <a href='https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Function/bind'>MDC's bind() documentation</a> and
* <a href='http://benjamin.smedbergs.us/blog/2007-01-03/bound-functions-and-function-imports-in-javascript/'>Bound Functions and Function Imports in JavaScript</a>
* 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;
};
}
14 changes: 14 additions & 0 deletions src/wrap_footer.js
Original file line number Diff line number Diff line change
@@ -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 */
9 changes: 9 additions & 0 deletions src/wrap_header.js
Original file line number Diff line number Diff line change
@@ -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 */

0 comments on commit 6196d0a

Please sign in to comment.