Permalink
Browse files

Remove dependency on jQuery

  • Loading branch information...
1 parent 92a4bb0 commit 99f714924be384483268d2755dac660f29b8affe @birtles birtles committed Mar 13, 2013
@@ -9,7 +9,6 @@
require_once("db.inc");
$connection = getConnection();
-
$list = array();
try {
if (!isset($_GET["sessionId"])) {
@@ -96,13 +96,12 @@ var Main = {
animateMotion.addEventListener("endEvent", function(e) {
var gElement = e.originalTarget.parentNode;
gElement.parentNode.removeChild(gElement);
- //console.error("remove:"+character.id);
}, true);
// Add the animation to the group, then add the group to the scene
g.appendChild(animateMotion);
Main.main_layer.appendChild(g);
-
+
// Update the character's status so we don't add it again
character.repeatCount++;
}

Large diffs are not rendered by default.

Oops, something went wrong.
@@ -120,11 +120,13 @@ var Main = {
loadAllCharacters: function(callback) {
var url = API_DIR+"get_all_characters_before_restart.php?"+(new Date()).getTime();
- $.getJSON(url, function(json) {
- Main.characters = [];
- Main.appendCharacters(json);
- callback();
- });
+ ParaPara.getUrl(url,
+ function(response) {
+ Main.characters = [];
+ Main.appendCharacters(response);
+ callback();
+ }
+ );
},
appendCharacters: function(json) {

Large diffs are not rendered by default.

Oops, something went wrong.
@@ -198,22 +198,32 @@ var Main = {
loadUncompletedCharacters: function() {
var url = API_DIR+"get_uncompleted_characters.php?x="+
Main.currentSimpleTime+"&"+(new Date()).getTime();
- $.getJSON(url, function(json) {
- Main.appendCharacters(json);
- setTimeout(Main.loadUncompletedCharacters, 1000);
- });
+ ParaPara.getUrl(url,
+ function(json) {
+ Main.appendCharacters(json);
+ setTimeout(Main.loadUncompletedCharacters, 1000);
+ },
+ function(key, detail) {
+ // Got an error, but just keep going anyway
+ setTimeout(Main.loadUncompletedCharacters, 1000);
+ }
+ );
},
// Get all characters that have already been assigned an x value (i.e. have
// already made their debut on the stage)
loadAllCharacters: function(callback) {
var url = API_DIR+"get_all_characters_before_restart.php?threshold="+
NUM_CHARACTERS_THRESHOLD+"&"+(new Date()).getTime();
- $.getJSON(url, function(json) {
- Main.characters = [];
- Main.appendCharacters(json);
- callback();
- });
+ ParaPara.getUrl(url,
+ function (response) {
+ Main.characters = [];
+ Main.appendCharacters(response);
+ callback();
+ },
+ function (key, detail) {
+ console.log("Couldn't get characters: " + key + ": " + detail);
+ });
},
appendCharacters: function(json) {
@@ -39,9 +39,9 @@ var CreateWallController =
Navigation.showScreen("screen-new");
// Send request
var payload = CreateWallForm.getFormValues();
- ParaPara.postRequest(WallMaker.rootUrl + '/api/createWall', payload,
- this.createSuccess.bind(this),
- this.createError.bind(this));
+ ParaPara.postUrl(WallMaker.rootUrl + '/api/createWall', payload,
+ this.createSuccess.bind(this),
+ this.createError.bind(this));
},
createSuccess: function(response) {
@@ -37,7 +37,7 @@ ParaPara.Login.prototype.relogin = function() {
// See if we still have a valid session
if (this.haveSessionCookie()) {
- ParaPara.postRequest('/api/whoami', null,
+ ParaPara.getUrl('/api/whoami',
// Got a cookie and the server recognises the session
alreadyLoggedIn,
// Server error, probably session has expired
@@ -99,14 +99,14 @@ ParaPara.Login.prototype.onlogout = function() {
// Verify an assertion and if it's ok, finish logging in
ParaPara.Login.prototype.gotAssertion = function(assertion) {
- ParaPara.postRequest('/api/login',
- { assertion: assertion },
- // Success, finish logging in
- function(response) {
- this.loggedIn(response.email);
- }.bind(this),
- // Couldn't verify
- this.loginFail.bind(this));
+ ParaPara.postUrl('/api/login',
+ { assertion: assertion },
+ // Success, finish logging in
+ function(response) {
+ this.loggedIn(response.email);
+ }.bind(this),
+ // Couldn't verify
+ this.loginFail.bind(this));
}
ParaPara.Login.prototype.loginFail = function(reason, detail) {
@@ -58,11 +58,11 @@ var ManageWallController =
this.clearError();
// Fetch wall information
- ParaPara.postRequest('/api/walls/' + wallId, null,
- function(response) {
- this.loadSuccess(response, tabName);
- }.bind(this),
- this.loadError.bind(this));
+ ParaPara.getUrl('/api/walls/' + wallId,
+ function(response) {
+ this.loadSuccess(response, tabName);
+ }.bind(this),
+ this.loadError.bind(this));
},
selectTab: function(tabName) {
@@ -129,7 +129,7 @@ var ManageWallController =
sendCommand: function(url, payload, messageElement) {
// XXX Display the error somewhere now that I've removed the message labels
- ParaPara.postRequest(url, payload,
+ ParaPara.postUrl(url, payload,
function(response) {
messageElement.classList.remove("error");
messageElement.textContent = response;
@@ -287,7 +287,7 @@ var ManageWallController =
*/
startSession: function() {
this.startUpdateSessionInfo();
- ParaPara.postRequest(WallMaker.rootUrl + '/api/startSession',
+ ParaPara.postUrl(WallMaker.rootUrl + '/api/startSession',
{wallId: this.wallId, sessionId: this.sessionId},
this.updateSessionInfo.bind(this),
this.handleSessionError.bind(this)
@@ -296,7 +296,7 @@ var ManageWallController =
closeSession: function() {
this.startUpdateSessionInfo();
- ParaPara.postRequest(WallMaker.rootUrl + '/api/closeSession',
+ ParaPara.postUrl(WallMaker.rootUrl + '/api/closeSession',
{wallId: this.wallId, sessionId: this.sessionId},
this.updateSessionInfo.bind(this),
this.handleSessionError.bind(this)
@@ -22,8 +22,6 @@
*/
var UserData =
{
- connectionMaxRetries: 2,
- connectionTimeout: 6000,
onupdate: null,
update: function (onupdate) {
@@ -39,11 +37,9 @@ var UserData =
UserData.onupdate = onupdate;
}
- ParaPara.postRequest('/api/userSummary', null,
- UserData._gotUserData,
- UserData._gotUserDataFailed,
- UserData.connectionMaxRetries,
- UserData.connectionTimeout);
+ ParaPara.getUrl('/api/userSummary',
+ UserData._gotUserData,
+ UserData._gotUserDataFailed);
},
_gotUserData: function (response, wallsOnly) {
@@ -75,15 +71,13 @@ var UserData =
updateWalls: function () {
WallSummaryController.showLoading();
var wallsOnly = true;
- ParaPara.postRequest('/api/userSummary', null,
+ ParaPara.getUrl('/api/userSummary',
function (response) {
UserData._gotUserData(response, wallsOnly);
},
function (reason, detail) {
UserData._gotUserDataFailed(reason, detail, wallsOnly);
- },
- UserData.connectionMaxRetries,
- UserData.connectionTimeout
+ }
);
},
@@ -8,30 +8,40 @@
var ParaPara = ParaPara || {};
-ParaPara.XHR_TIMEOUT = 8000;
+ParaPara.XHR_DEFAULT_TIMEOUT = 8000;
-// XXX Remove this wrapper and just use XHRequest directly
-ParaPara.postRequest = function(url, payload,
- successCallback, failureCallback,
- maxTries, timeout) {
+ParaPara.getUrl = function(url, successCallback, failureCallback,
+ maxTries, timeout) {
+ if (typeof maxTries === "undefined")
+ /* GET is indempotent so by default we retry twice */
+ maxTries = 2;
+ if (typeof timeout === "undefined")
+ timeout = ParaPara.XHR_DEFAULT_TIMEOUT;
+
+ new ParaPara.XHRequest("GET", url, null,
+ successCallback, failureCallback,
+ maxTries, timeout);
+}
+
+ParaPara.postUrl = function(url, payload,
+ successCallback, failureCallback,
+ maxTries, timeout) {
if (typeof maxTries === "undefined")
- // XXX Once we support different methods, we should probably make GET and
- // PUT retry automatically (i.e. maxTries = 2 by default) since they should
- // be indempotent
maxTries = 1;
if (typeof timeout === "undefined")
- timeout = ParaPara.XHR_TIMEOUT;
+ timeout = ParaPara.XHR_DEFAULT_TIMEOUT;
- var req = new ParaPara.XHRequest(url, payload,
- successCallback, failureCallback,
- maxTries, timeout);
+ new ParaPara.XHRequest("POST", url, payload,
+ successCallback, failureCallback,
+ maxTries, timeout);
}
-ParaPara.XHRequest = function(url, payload,
+ParaPara.XHRequest = function(method, url, payload,
successCallback, failureCallback,
maxTries, timeout) {
this.timeoutCount = 0;
this.gotResponse = false;
+ this.method = method;
this.url = url;
this.successCallback = successCallback;
this.failureCallback = failureCallback;
@@ -48,10 +58,11 @@ ParaPara.XHRequest = function(url, payload,
ParaPara.XHRequest.prototype.sendRequest = function() {
// Create request
var req = new XMLHttpRequest();
- req.open("POST", this.url, true);
+ req.open(this.method, this.url, true);
// Set headers
- req.setRequestHeader("Content-Type", "application/json");
+ if (this.jsonPayload)
+ req.setRequestHeader("Content-Type", "application/json");
// Event listeners
req.onreadystatechange = function() {
@@ -88,7 +99,7 @@ ParaPara.XHRequest.prototype.sendRequest = function() {
// Send away
try {
- req.send(this.jsonPayload);
+ req.send(this.jsonPayload ? this.jsonPayload : null);
} catch (e) {
console.debug(e);
this.failureCallback('send-fail');
@@ -85,8 +85,8 @@
var BEGIN_TIME = <?php echo $beginTime ?>;
var BEFORE_LOADED_TIME = (new Date()).getTime();
</script>
- <script xlink:href="js/jquery-1.7.1.min.js"></script>
<script xlink:href="js/utility.js"></script>
+ <script xlink:href="../wall-maker/js/xhr.js"></script>
<script xlink:href="js/<?php echo $database; ?>"></script>
<script xlink:href="/designs/<?php echo $design; ?>/main.js"></script>
<?php require("../designs/$design/wall.svg.inc"); ?>
@@ -54,10 +54,14 @@ var Database = {
loadAllCharacters: function(callback) {
var url = API_DIR+"get_all_characters.php?threshold="+
NUM_CHARACTERS_THRESHOLD+"&sessionId="+SESSION_ID+"&"+(new Date()).getTime();
- $.getJSON(url, function(json) {
- Database.append(json);
- Database.idle();
- });
+ ParaPara.getUrl(url,
+ function(response) {
+ Database.append(response);
+ Database.idle();
+ },
+ function (key, detail) {
+ console.log("Couldn't get characters: " + key + ": " + detail);
+ });
},
append: function(json) {
Oops, something went wrong.

0 comments on commit 99f7149

Please sign in to comment.