Permalink
Browse files

Fixed #215, #383 and #491

All the bugs fixed in this commit are duplicates.

Executing Javascript once the DOM yielded constant loading in some
browsers where they viewed the page as continuously loading since the
entire page had not been loaded, even though the DOM had.  Fixed this
issue by re-routing the connection.start call to the window.load event
by default but also allowing the user to overwrite the default via the
startAfterPageLoad flag.
  • Loading branch information...
1 parent 32bde20 commit d2b5c6039acb6b3cb5bf46dfb68f1bfcff52921c @NTaylorMullen NTaylorMullen committed Aug 1, 2012
@@ -24,6 +24,7 @@
var signalR,
_connection,
+ _pageLoaded = false,
events = {
onStart: "onStart",
@@ -118,6 +119,8 @@
}
};
+ $(window).load(function () { _pageLoaded = true; });
+
signalR.fn = signalR.prototype = {
init: function (url, qs, logging) {
this.url = url;
@@ -141,20 +144,13 @@
/// <param name="callback" type="Function">A callback function to execute when the connection has started</param>
var connection = this,
config = {
+ startAfterPageLoad: true,
transport: "auto",
jsonp: false
},
initialize,
- deferred = $.Deferred(),
- parser = window.document.createElement("a");
-
- if (changeState(connection,
- signalR.connectionState.disconnected,
- signalR.connectionState.connecting) === false) {
- // Already started, just return
- deferred.resolve(connection);
- return deferred.promise();
- }
+ deferred = ($(this).attr("deferral")) ? this.deferral : $.Deferred(),//Check to see if there is a pre-existing deferral that's being built on, if so we want to keep using it
+ parser = window.document.createElement("a");
if ($.type(options) === "function") {
// Support calling with single callback parameter
@@ -166,6 +162,24 @@
}
}
+ //Check to see if start is being called prior to page load
+ //If startAfterPageLoad is true we then want to re-direct function call to the window load event
+ if (!_pageLoaded && config.startAfterPageLoad === true) {
+ $(window).load(function () {
+ connection.deferral = deferred;
+ connection.start(options, callback);
+ });
+ return deferred.promise();
+ }
+
+ if (changeState(connection,
+ signalR.connectionState.disconnected,
+ signalR.connectionState.connecting) === false) {
+ // Already started, just return
+ deferred.resolve(connection);
+ return deferred.promise();
+ }
+
// Resolve the full url
parser.href = connection.url;
if (!parser.protocol || parser.protocol === ":") {
@@ -25,6 +25,7 @@
var signalR,
_connection,
+ _pageLoaded = false,
events = {
onStart: "onStart",
@@ -119,6 +120,8 @@
}
};
+ $(window).load(function () { _pageLoaded = true; });
+
signalR.fn = signalR.prototype = {
init: function (url, qs, logging) {
this.url = url;
@@ -142,20 +145,13 @@
/// <param name="callback" type="Function">A callback function to execute when the connection has started</param>
var connection = this,
config = {
+ startAfterPageLoad: true,
transport: "auto",
jsonp: false
},
initialize,
- deferred = $.Deferred(),
- parser = window.document.createElement("a");
-
- if (changeState(connection,
- signalR.connectionState.disconnected,
- signalR.connectionState.connecting) === false) {
- // Already started, just return
- deferred.resolve(connection);
- return deferred.promise();
- }
+ deferred = ($(this).attr("deferral")) ? this.deferral : $.Deferred(),//Check to see if there is a pre-existing deferral that's being built on, if so we want to keep using it
+ parser = window.document.createElement("a");
if ($.type(options) === "function") {
// Support calling with single callback parameter
@@ -167,6 +163,24 @@
}
}
+ //Check to see if start is being called prior to page load
+ //If startAfterPageLoad is true we then want to re-direct function call to the window load event
+ if (!_pageLoaded && config.startAfterPageLoad === true) {
+ $(window).load(function () {
+ connection.deferral = deferred;
+ connection.start(options, callback);
+ });
+ return deferred.promise();
+ }
+
+ if (changeState(connection,
+ signalR.connectionState.disconnected,
+ signalR.connectionState.connecting) === false) {
+ // Already started, just return
+ deferred.resolve(connection);
+ return deferred.promise();
+ }
+
// Resolve the full url
parser.href = connection.url;
if (!parser.protocol || parser.protocol === ":") {
Oops, something went wrong. Retry.

0 comments on commit d2b5c60

Please sign in to comment.