Skip to content

Commit

Permalink
Remove dependency on jQuery
Browse files Browse the repository at this point in the history
  • Loading branch information
birtles committed Mar 13, 2013
1 parent 92a4bb0 commit 99f7149
Show file tree
Hide file tree
Showing 17 changed files with 142 additions and 118 deletions.
1 change: 0 additions & 1 deletion wall/public/api/get_uncompleted_characters.php
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
require_once("db.inc"); require_once("db.inc");
$connection = getConnection(); $connection = getConnection();



$list = array(); $list = array();
try { try {
if (!isset($_GET["sessionId"])) { if (!isset($_GET["sessionId"])) {
Expand Down
3 changes: 1 addition & 2 deletions wall/public/designs/wa/main.js
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -96,13 +96,12 @@ var Main = {
animateMotion.addEventListener("endEvent", function(e) { animateMotion.addEventListener("endEvent", function(e) {
var gElement = e.originalTarget.parentNode; var gElement = e.originalTarget.parentNode;
gElement.parentNode.removeChild(gElement); gElement.parentNode.removeChild(gElement);
//console.error("remove:"+character.id);
}, true); }, true);


// Add the animation to the group, then add the group to the scene // Add the animation to the group, then add the group to the scene
g.appendChild(animateMotion); g.appendChild(animateMotion);
Main.main_layer.appendChild(g); Main.main_layer.appendChild(g);

// Update the character's status so we don't add it again // Update the character's status so we don't add it again
character.repeatCount++; character.repeatCount++;
} }
Expand Down
4 changes: 0 additions & 4 deletions wall/public/wall-gallery/js/jquery-1.7.1.min.js

This file was deleted.

12 changes: 7 additions & 5 deletions wall/public/wall-gallery/js/main.js
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -120,11 +120,13 @@ var Main = {


loadAllCharacters: function(callback) { loadAllCharacters: function(callback) {
var url = API_DIR+"get_all_characters_before_restart.php?"+(new Date()).getTime(); var url = API_DIR+"get_all_characters_before_restart.php?"+(new Date()).getTime();
$.getJSON(url, function(json) { ParaPara.getUrl(url,
Main.characters = []; function(response) {
Main.appendCharacters(json); Main.characters = [];
callback(); Main.appendCharacters(response);
}); callback();
}
);
}, },


appendCharacters: function(json) { appendCharacters: function(json) {
Expand Down
4 changes: 0 additions & 4 deletions wall/public/wall-live/js/jquery-1.7.1.min.js

This file was deleted.

28 changes: 19 additions & 9 deletions wall/public/wall-live/js/main.js
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -198,22 +198,32 @@ var Main = {
loadUncompletedCharacters: function() { loadUncompletedCharacters: function() {
var url = API_DIR+"get_uncompleted_characters.php?x="+ var url = API_DIR+"get_uncompleted_characters.php?x="+
Main.currentSimpleTime+"&"+(new Date()).getTime(); Main.currentSimpleTime+"&"+(new Date()).getTime();
$.getJSON(url, function(json) { ParaPara.getUrl(url,
Main.appendCharacters(json); function(json) {
setTimeout(Main.loadUncompletedCharacters, 1000); 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 // Get all characters that have already been assigned an x value (i.e. have
// already made their debut on the stage) // already made their debut on the stage)
loadAllCharacters: function(callback) { loadAllCharacters: function(callback) {
var url = API_DIR+"get_all_characters_before_restart.php?threshold="+ var url = API_DIR+"get_all_characters_before_restart.php?threshold="+
NUM_CHARACTERS_THRESHOLD+"&"+(new Date()).getTime(); NUM_CHARACTERS_THRESHOLD+"&"+(new Date()).getTime();
$.getJSON(url, function(json) { ParaPara.getUrl(url,
Main.characters = []; function (response) {
Main.appendCharacters(json); Main.characters = [];
callback(); Main.appendCharacters(response);
}); callback();
},
function (key, detail) {
console.log("Couldn't get characters: " + key + ": " + detail);
});
}, },


appendCharacters: function(json) { appendCharacters: function(json) {
Expand Down
6 changes: 3 additions & 3 deletions wall/public/wall-maker/js/create-wall.js
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@ var CreateWallController =
Navigation.showScreen("screen-new"); Navigation.showScreen("screen-new");
// Send request // Send request
var payload = CreateWallForm.getFormValues(); var payload = CreateWallForm.getFormValues();
ParaPara.postRequest(WallMaker.rootUrl + '/api/createWall', payload, ParaPara.postUrl(WallMaker.rootUrl + '/api/createWall', payload,
this.createSuccess.bind(this), this.createSuccess.bind(this),
this.createError.bind(this)); this.createError.bind(this));
}, },


createSuccess: function(response) { createSuccess: function(response) {
Expand Down
18 changes: 9 additions & 9 deletions wall/public/wall-maker/js/login.js
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ ParaPara.Login.prototype.relogin = function() {


// See if we still have a valid session // See if we still have a valid session
if (this.haveSessionCookie()) { if (this.haveSessionCookie()) {
ParaPara.postRequest('/api/whoami', null, ParaPara.getUrl('/api/whoami',
// Got a cookie and the server recognises the session // Got a cookie and the server recognises the session
alreadyLoggedIn, alreadyLoggedIn,
// Server error, probably session has expired // Server error, probably session has expired
Expand Down Expand Up @@ -99,14 +99,14 @@ ParaPara.Login.prototype.onlogout = function() {


// Verify an assertion and if it's ok, finish logging in // Verify an assertion and if it's ok, finish logging in
ParaPara.Login.prototype.gotAssertion = function(assertion) { ParaPara.Login.prototype.gotAssertion = function(assertion) {
ParaPara.postRequest('/api/login', ParaPara.postUrl('/api/login',
{ assertion: assertion }, { assertion: assertion },
// Success, finish logging in // Success, finish logging in
function(response) { function(response) {
this.loggedIn(response.email); this.loggedIn(response.email);
}.bind(this), }.bind(this),
// Couldn't verify // Couldn't verify
this.loginFail.bind(this)); this.loginFail.bind(this));
} }


ParaPara.Login.prototype.loginFail = function(reason, detail) { ParaPara.Login.prototype.loginFail = function(reason, detail) {
Expand Down
16 changes: 8 additions & 8 deletions wall/public/wall-maker/js/manage-wall.js
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -58,11 +58,11 @@ var ManageWallController =
this.clearError(); this.clearError();


// Fetch wall information // Fetch wall information
ParaPara.postRequest('/api/walls/' + wallId, null, ParaPara.getUrl('/api/walls/' + wallId,
function(response) { function(response) {
this.loadSuccess(response, tabName); this.loadSuccess(response, tabName);
}.bind(this), }.bind(this),
this.loadError.bind(this)); this.loadError.bind(this));
}, },


selectTab: function(tabName) { selectTab: function(tabName) {
Expand Down Expand Up @@ -129,7 +129,7 @@ var ManageWallController =


sendCommand: function(url, payload, messageElement) { sendCommand: function(url, payload, messageElement) {
// XXX Display the error somewhere now that I've removed the message labels // XXX Display the error somewhere now that I've removed the message labels
ParaPara.postRequest(url, payload, ParaPara.postUrl(url, payload,
function(response) { function(response) {
messageElement.classList.remove("error"); messageElement.classList.remove("error");
messageElement.textContent = response; messageElement.textContent = response;
Expand Down Expand Up @@ -287,7 +287,7 @@ var ManageWallController =
*/ */
startSession: function() { startSession: function() {
this.startUpdateSessionInfo(); this.startUpdateSessionInfo();
ParaPara.postRequest(WallMaker.rootUrl + '/api/startSession', ParaPara.postUrl(WallMaker.rootUrl + '/api/startSession',
{wallId: this.wallId, sessionId: this.sessionId}, {wallId: this.wallId, sessionId: this.sessionId},
this.updateSessionInfo.bind(this), this.updateSessionInfo.bind(this),
this.handleSessionError.bind(this) this.handleSessionError.bind(this)
Expand All @@ -296,7 +296,7 @@ var ManageWallController =


closeSession: function() { closeSession: function() {
this.startUpdateSessionInfo(); this.startUpdateSessionInfo();
ParaPara.postRequest(WallMaker.rootUrl + '/api/closeSession', ParaPara.postUrl(WallMaker.rootUrl + '/api/closeSession',
{wallId: this.wallId, sessionId: this.sessionId}, {wallId: this.wallId, sessionId: this.sessionId},
this.updateSessionInfo.bind(this), this.updateSessionInfo.bind(this),
this.handleSessionError.bind(this) this.handleSessionError.bind(this)
Expand Down
16 changes: 5 additions & 11 deletions wall/public/wall-maker/js/user-data.js
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@
*/ */
var UserData = var UserData =
{ {
connectionMaxRetries: 2,
connectionTimeout: 6000,
onupdate: null, onupdate: null,


update: function (onupdate) { update: function (onupdate) {
Expand All @@ -39,11 +37,9 @@ var UserData =
UserData.onupdate = onupdate; UserData.onupdate = onupdate;
} }


ParaPara.postRequest('/api/userSummary', null, ParaPara.getUrl('/api/userSummary',
UserData._gotUserData, UserData._gotUserData,
UserData._gotUserDataFailed, UserData._gotUserDataFailed);
UserData.connectionMaxRetries,
UserData.connectionTimeout);
}, },


_gotUserData: function (response, wallsOnly) { _gotUserData: function (response, wallsOnly) {
Expand Down Expand Up @@ -75,15 +71,13 @@ var UserData =
updateWalls: function () { updateWalls: function () {
WallSummaryController.showLoading(); WallSummaryController.showLoading();
var wallsOnly = true; var wallsOnly = true;
ParaPara.postRequest('/api/userSummary', null, ParaPara.getUrl('/api/userSummary',
function (response) { function (response) {
UserData._gotUserData(response, wallsOnly); UserData._gotUserData(response, wallsOnly);
}, },
function (reason, detail) { function (reason, detail) {
UserData._gotUserDataFailed(reason, detail, wallsOnly); UserData._gotUserDataFailed(reason, detail, wallsOnly);
}, }
UserData.connectionMaxRetries,
UserData.connectionTimeout
); );
}, },


Expand Down
43 changes: 27 additions & 16 deletions wall/public/wall-maker/js/xhr.js
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -8,30 +8,40 @@


var ParaPara = ParaPara || {}; var ParaPara = ParaPara || {};


ParaPara.XHR_TIMEOUT = 8000; ParaPara.XHR_DEFAULT_TIMEOUT = 8000;


// XXX Remove this wrapper and just use XHRequest directly ParaPara.getUrl = function(url, successCallback, failureCallback,
ParaPara.postRequest = function(url, payload, maxTries, timeout) {
successCallback, failureCallback, if (typeof maxTries === "undefined")
maxTries, timeout) { /* 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") 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; maxTries = 1;
if (typeof timeout === "undefined") if (typeof timeout === "undefined")
timeout = ParaPara.XHR_TIMEOUT; timeout = ParaPara.XHR_DEFAULT_TIMEOUT;


var req = new ParaPara.XHRequest(url, payload, new ParaPara.XHRequest("POST", url, payload,
successCallback, failureCallback, successCallback, failureCallback,
maxTries, timeout); maxTries, timeout);
} }


ParaPara.XHRequest = function(url, payload, ParaPara.XHRequest = function(method, url, payload,
successCallback, failureCallback, successCallback, failureCallback,
maxTries, timeout) { maxTries, timeout) {
this.timeoutCount = 0; this.timeoutCount = 0;
this.gotResponse = false; this.gotResponse = false;
this.method = method;
this.url = url; this.url = url;
this.successCallback = successCallback; this.successCallback = successCallback;
this.failureCallback = failureCallback; this.failureCallback = failureCallback;
Expand All @@ -48,10 +58,11 @@ ParaPara.XHRequest = function(url, payload,
ParaPara.XHRequest.prototype.sendRequest = function() { ParaPara.XHRequest.prototype.sendRequest = function() {
// Create request // Create request
var req = new XMLHttpRequest(); var req = new XMLHttpRequest();
req.open("POST", this.url, true); req.open(this.method, this.url, true);


// Set headers // Set headers
req.setRequestHeader("Content-Type", "application/json"); if (this.jsonPayload)
req.setRequestHeader("Content-Type", "application/json");


// Event listeners // Event listeners
req.onreadystatechange = function() { req.onreadystatechange = function() {
Expand Down Expand Up @@ -88,7 +99,7 @@ ParaPara.XHRequest.prototype.sendRequest = function() {


// Send away // Send away
try { try {
req.send(this.jsonPayload); req.send(this.jsonPayload ? this.jsonPayload : null);
} catch (e) { } catch (e) {
console.debug(e); console.debug(e);
this.failureCallback('send-fail'); this.failureCallback('send-fail');
Expand Down
2 changes: 1 addition & 1 deletion wall/public/wall/index.php
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -85,8 +85,8 @@
var BEGIN_TIME = <?php echo $beginTime ?>; var BEGIN_TIME = <?php echo $beginTime ?>;
var BEFORE_LOADED_TIME = (new Date()).getTime(); var BEFORE_LOADED_TIME = (new Date()).getTime();
</script> </script>
<script xlink:href="js/jquery-1.7.1.min.js"></script>
<script xlink:href="js/utility.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="js/<?php echo $database; ?>"></script>
<script xlink:href="/designs/<?php echo $design; ?>/main.js"></script> <script xlink:href="/designs/<?php echo $design; ?>/main.js"></script>
<?php require("../designs/$design/wall.svg.inc"); ?> <?php require("../designs/$design/wall.svg.inc"); ?>
Expand Down
12 changes: 8 additions & 4 deletions wall/public/wall/js/database4gallery.js
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -54,10 +54,14 @@ var Database = {
loadAllCharacters: function(callback) { loadAllCharacters: function(callback) {
var url = API_DIR+"get_all_characters.php?threshold="+ var url = API_DIR+"get_all_characters.php?threshold="+
NUM_CHARACTERS_THRESHOLD+"&sessionId="+SESSION_ID+"&"+(new Date()).getTime(); NUM_CHARACTERS_THRESHOLD+"&sessionId="+SESSION_ID+"&"+(new Date()).getTime();
$.getJSON(url, function(json) { ParaPara.getUrl(url,
Database.append(json); function(response) {
Database.idle(); Database.append(response);
}); Database.idle();
},
function (key, detail) {
console.log("Couldn't get characters: " + key + ": " + detail);
});
}, },


append: function(json) { append: function(json) {
Expand Down
Loading

0 comments on commit 99f7149

Please sign in to comment.