Commit be799896 authored by Xiaowu Zhang's avatar Xiaowu Zhang

copy of mixin_promise.js

parent 05ab24fb
......@@ -11,7 +11,7 @@
<script src="../lib/uritemplate.min.js" type="text/javascript"></script>
<script src="../lib/jio.js" type="text/javascript"></script>
<script src="http://git.erp5.org/gitweb/dream.git/blob_plain/01bbb0b10edd731fb24898ce8b5e193ecbc989ca:/dream/platform/src/dream/mixin_promise.js?js=1" type="text/javascript"></script>
<script src="../mixin_promise/mixin_promise.js" type="text/javascript"></script>
<!-- custom script -->
<script src="./control.js" type="text/javascript"></script>
<link rel="stylesheet" href="./control.css" media="screen" ></link>
......
......@@ -8,7 +8,7 @@
<script src="../lib/jquery.js" type="text/javascript"></script>
<script src="../lib/handlebars.min.js"></script>
<script src="http://git.erp5.org/gitweb/dream.git/blob_plain/01bbb0b10edd731fb24898ce8b5e193ecbc989ca:/dream/platform/src/dream/mixin_promise.js?js=1" type="text/javascript"></script>
<script src="../mixin_promise/mixin_promise.js" type="text/javascript"></script>
<script id="network" type="text/x-handlebars-template">
{{#each rows}}
......
......@@ -8,7 +8,7 @@
<script src="../lib/jquery.js" type="text/javascript"></script>
<script src="../lib/handlebars.min.js"></script>
<script src="http://git.erp5.org/gitweb/dream.git/blob_plain/01bbb0b10edd731fb24898ce8b5e193ecbc989ca:/dream/platform/src/dream/mixin_promise.js?js=1" type="text/javascript"></script>
<script src="../mixin_promise/mixin_promise.js" type="text/javascript"></script>
<script id="rows-template" type="text/x-handlebars-template">
{{#each rows}}
......
......@@ -8,7 +8,7 @@
<script src="../lib/jquery.js" type="text/javascript"></script>
<script src="../lib/handlebars.min.js"></script>
<script src="http://git.erp5.org/gitweb/dream.git/blob_plain/01bbb0b10edd731fb24898ce8b5e193ecbc989ca:/dream/platform/src/dream/mixin_promise.js?js=1" type="text/javascript"></script>
<script src="../mixin_promise/mixin_promise.js" type="text/javascript"></script>
<script id="network" type="text/x-handlebars-template">
{{#each rows}}
......
......@@ -10,7 +10,7 @@
<script src="../lib/URI.js" type="text/javascript"></script>
<script src="../lib/uritemplate.min.js" type="text/javascript"></script>
<script src="../lib/jio.js" type="text/javascript"></script>
<script src="http://git.erp5.org/gitweb/dream.git/blob_plain/01bbb0b10edd731fb24898ce8b5e193ecbc989ca:/dream/platform/src/dream/mixin_promise.js?js=1" type="text/javascript"></script>
<script src="../mixin_promise/mixin_promise.js" type="text/javascript"></script>
<!-- custom script -->
<script src="./upload.js" type="text/javascript"></script>
......
......@@ -11,7 +11,7 @@
<script src="../lib/uritemplate.min.js" type="text/javascript"></script>
<script src="../lib/jio.js" type="text/javascript"></script>
<script src="http://git.erp5.org/gitweb/dream.git/blob_plain/01bbb0b10edd731fb24898ce8b5e193ecbc989ca:/dream/platform/src/dream/mixin_promise.js?js=1" type="text/javascript"></script>
<script src="../mixin_promise/mixin_promise.js" type="text/javascript"></script>
<!-- custom script -->
<script src="./control.js" type="text/javascript"></script>
<link rel="stylesheet" href="./control.css" media="screen" ></link>
......
/*global RSVP, FileReader */
/*jslint unparam: true */
(function(window, RSVP, FileReader) {
"use strict";
window.loopEventListener = function(target, type, useCapture, callback, allowDefault) {
//////////////////////////
// Infinite event listener (promise is never resolved)
// eventListener is removed when promise is cancelled/rejected
//////////////////////////
var handle_event_callback, callback_promise;
function cancelResolver() {
if (callback_promise !== undefined && typeof callback_promise.cancel === "function") {
callback_promise.cancel();
}
}
function canceller() {
if (handle_event_callback !== undefined) {
target.removeEventListener(type, handle_event_callback, useCapture);
}
cancelResolver();
}
function itsANonResolvableTrap(resolve, reject) {
handle_event_callback = function(evt) {
evt.stopPropagation();
if (allowDefault !== true) {
evt.preventDefault();
}
cancelResolver();
callback_promise = new RSVP.Queue().push(function() {
return callback(evt);
}).push(undefined, function(error) {
if (!(error instanceof RSVP.CancellationError)) {
canceller();
reject(error);
}
});
};
target.addEventListener(type, handle_event_callback, useCapture);
}
return new RSVP.Promise(itsANonResolvableTrap, canceller);
};
window.promiseEventListener = function(target, type, useCapture) {
//////////////////////////
// Resolve the promise as soon as the event is triggered
// eventListener is removed when promise is cancelled/resolved/rejected
//////////////////////////
var handle_event_callback;
function canceller() {
target.removeEventListener(type, handle_event_callback, useCapture);
}
function resolver(resolve) {
handle_event_callback = function(evt) {
canceller();
evt.stopPropagation();
evt.preventDefault();
resolve(evt);
return false;
};
target.addEventListener(type, handle_event_callback, useCapture);
}
return new RSVP.Promise(resolver, canceller);
};
window.promiseReadAsText = function(file) {
return new RSVP.Promise(function(resolve, reject) {
var reader = new FileReader();
reader.onload = function(evt) {
resolve(evt.target.result);
};
reader.onerror = function(evt) {
reject(evt);
};
reader.readAsText(file);
});
};
})(window, RSVP, FileReader);
\ No newline at end of file
......@@ -11,7 +11,7 @@
<script src="../<%= copy.uritemplate.relative_dest %>" type="text/javascript"></script>
<script src="../<%= concat.jio.relative_dest %>" type="text/javascript"></script>
<script src="http://git.erp5.org/gitweb/dream.git/blob_plain/01bbb0b10edd731fb24898ce8b5e193ecbc989ca:/dream/platform/src/dream/mixin_promise.js?js=1" type="text/javascript"></script>
<script src="../mixin_promise/mixin_promise.js" type="text/javascript"></script>
<!-- custom script -->
<script src="./control.js" type="text/javascript"></script>
<link rel="stylesheet" href="./control.css" media="screen" ></link>
......
......@@ -8,7 +8,7 @@
<script src="../<%= curl.jquery.relative_dest %>" type="text/javascript"></script>
<script src="../<%= copy.handlebars.relative_dest%>"></script>
<script src="http://git.erp5.org/gitweb/dream.git/blob_plain/01bbb0b10edd731fb24898ce8b5e193ecbc989ca:/dream/platform/src/dream/mixin_promise.js?js=1" type="text/javascript"></script>
<script src="../mixin_promise/mixin_promise.js" type="text/javascript"></script>
<script id="network" type="text/x-handlebars-template">
{{#each rows}}
......
......@@ -8,7 +8,7 @@
<script src="../<%= curl.jquery.relative_dest %>" type="text/javascript"></script>
<script src="../<%= copy.handlebars.relative_dest%>"></script>
<script src="http://git.erp5.org/gitweb/dream.git/blob_plain/01bbb0b10edd731fb24898ce8b5e193ecbc989ca:/dream/platform/src/dream/mixin_promise.js?js=1" type="text/javascript"></script>
<script src="../mixin_promise/mixin_promise.js" type="text/javascript"></script>
<script id="rows-template" type="text/x-handlebars-template">
{{#each rows}}
......
......@@ -8,7 +8,7 @@
<script src="../<%= curl.jquery.relative_dest %>" type="text/javascript"></script>
<script src="../<%= copy.handlebars.relative_dest%>"></script>
<script src="http://git.erp5.org/gitweb/dream.git/blob_plain/01bbb0b10edd731fb24898ce8b5e193ecbc989ca:/dream/platform/src/dream/mixin_promise.js?js=1" type="text/javascript"></script>
<script src="../mixin_promise/mixin_promise.js" type="text/javascript"></script>
<script id="network" type="text/x-handlebars-template">
{{#each rows}}
......
......@@ -10,7 +10,7 @@
<script src="../<%= copy.uri.relative_dest %>" type="text/javascript"></script>
<script src="../<%= copy.uritemplate.relative_dest %>" type="text/javascript"></script>
<script src="../<%= concat.jio.relative_dest %>" type="text/javascript"></script>
<script src="http://git.erp5.org/gitweb/dream.git/blob_plain/01bbb0b10edd731fb24898ce8b5e193ecbc989ca:/dream/platform/src/dream/mixin_promise.js?js=1" type="text/javascript"></script>
<script src="../mixin_promise/mixin_promise.js" type="text/javascript"></script>
<!-- custom script -->
<script src="./upload.js" type="text/javascript"></script>
......
......@@ -11,7 +11,7 @@
<script src="../<%= copy.uritemplate.relative_dest %>" type="text/javascript"></script>
<script src="../<%= concat.jio.relative_dest %>" type="text/javascript"></script>
<script src="http://git.erp5.org/gitweb/dream.git/blob_plain/01bbb0b10edd731fb24898ce8b5e193ecbc989ca:/dream/platform/src/dream/mixin_promise.js?js=1" type="text/javascript"></script>
<script src="../mixin_promise/mixin_promise.js" type="text/javascript"></script>
<!-- custom script -->
<script src="./control.js" type="text/javascript"></script>
<link rel="stylesheet" href="./control.css" media="screen" ></link>
......
/*global RSVP, FileReader */
/*jslint unparam: true */
(function (window, RSVP, FileReader) {
"use strict";
window.loopEventListener = function (target, type, useCapture, callback,
allowDefault) {
//////////////////////////
// Infinite event listener (promise is never resolved)
// eventListener is removed when promise is cancelled/rejected
//////////////////////////
var handle_event_callback,
callback_promise;
function cancelResolver() {
if ((callback_promise !== undefined) &&
(typeof callback_promise.cancel === "function")) {
callback_promise.cancel();
}
}
function canceller() {
if (handle_event_callback !== undefined) {
target.removeEventListener(type, handle_event_callback, useCapture);
}
cancelResolver();
}
function itsANonResolvableTrap(resolve, reject) {
handle_event_callback = function (evt) {
evt.stopPropagation();
if (allowDefault !== true) {
evt.preventDefault();
}
cancelResolver();
callback_promise = new RSVP.Queue()
.push(function () {
return callback(evt);
})
.push(undefined, function (error) {
if (!(error instanceof RSVP.CancellationError)) {
canceller();
reject(error);
}
});
};
target.addEventListener(type, handle_event_callback, useCapture);
}
return new RSVP.Promise(itsANonResolvableTrap, canceller);
};
window.promiseEventListener = function (target, type, useCapture) {
//////////////////////////
// Resolve the promise as soon as the event is triggered
// eventListener is removed when promise is cancelled/resolved/rejected
//////////////////////////
var handle_event_callback;
function canceller() {
target.removeEventListener(type, handle_event_callback, useCapture);
}
function resolver(resolve) {
handle_event_callback = function (evt) {
canceller();
evt.stopPropagation();
evt.preventDefault();
resolve(evt);
return false;
};
target.addEventListener(type, handle_event_callback, useCapture);
}
return new RSVP.Promise(resolver, canceller);
};
window.promiseReadAsText = function (file) {
return new RSVP.Promise(function (resolve, reject) {
var reader = new FileReader();
reader.onload = function (evt) {
resolve(evt.target.result);
};
reader.onerror = function (evt) {
reject(evt);
};
reader.readAsText(file);
});
};
}(window, RSVP, FileReader));
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment