Skip to content

Commit

Permalink
added eventing to ajax
Browse files Browse the repository at this point in the history
  • Loading branch information
Dan Lasky committed Sep 25, 2015
1 parent b820b67 commit 3961710
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 7 deletions.
19 changes: 13 additions & 6 deletions src/shared/js/ajax.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
<link rel="import" href="request.html"/>
<link rel="import" href="requestqueue.html"/>
<link rel="import" href="zousan.html"/>
<link rel="import" href="eventdispatcher.html"/>
<script>
/**
* @license
Expand All @@ -11,6 +12,8 @@
*/
(function (scope) {

var _eventPrefix = "ajax-";

function _paramaterize(name, value) {
return encodeURIComponent(name) + "=" + encodeURIComponent(value);
}
Expand Down Expand Up @@ -115,19 +118,21 @@
abort: function() {
if (this.current) {
this.current.abort();
this.dispatchEvent(new CustomEvent(_eventPrefix + "abort", {instance:this}));
}
},

abortQueue: function(queueName) {
_getQueue(queueName).running.abort();
this.dispatchEvent(new CustomEvent(_eventPrefix + "abort-queue", {instance:this}));
},

handleProgress: function(e) {
// this.fire("data-progress", {
// percent: e.totalSize/e.position,
// total: e.totalSize,
// current: e.position
// });
this.dispatchEvent(new CustomEvent(_eventPrefix + "progress", {
percent: e.totalSize/e.position,
total: e.totalSize,
current: e.position
}));
},

addHeader: function(name, value) {
Expand Down Expand Up @@ -216,7 +221,7 @@
try {
data = JSON.parse(data);
} catch(e) {
// this.fire("data-error", {error: e.message, instance: this});
this.dispatchEvent(new CustomEvent(_eventPrefix + "error", {error:e, instance:this}));
}
}
if ( StrandLib.DataUtils.isType(data, "array") ) {
Expand Down Expand Up @@ -247,6 +252,8 @@
}
};

EventDispatcher.prototype.apply(Ajax.prototype);

scope.Ajax = Ajax;

})(window.StrandLib = window.StrandLib || {});
Expand Down
2 changes: 1 addition & 1 deletion test/behavior_pageable.html
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@

/** begin tests **/

describe("syncable", function() {
describe("Pageable", function() {

it("should exist", function() {
StrandTraits.should.be.an.object;
Expand Down

0 comments on commit 3961710

Please sign in to comment.