Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

lib/webpeer.js: better comment. no more param in callback ready/monit…

…or. no export monitor()

	modified:   lib/webpeer.js
	modified:   lib/webpeer_test.js
  • Loading branch information...
commit 9032637e88a7e0d635755b4a9d246fdcd72af120 1 parent 7938b01
@jeromeetienne authored
Showing with 24 additions and 18 deletions.
  1. +21 −15 lib/webpeer.js
  2. +3 −3 lib/webpeer_test.js
View
36 lib/webpeer.js
@@ -6,34 +6,41 @@ var verbose = 1;
var webpeer = {};
/**
- * probe webpeer and notify the callback once completed
+ * Start a detection of webpeer. and notify the callback on completion
+ *
+ * - use webpeer.present() to get the result
*
- * @param completed_cb {function} callback notified on completion completed(present){}
+ * @param completed_cb {function} callback notified on completion completed(){}
*/
webpeer.ready = function(completed_cb){
// discover neoip-webpeer
app_detect.webpeer_probe({
completed_cb : function(status){
- if( status == "toinstall" ) completed_cb(false);
- else if( status == "toupgrade") completed_cb(true);
- else if( status == "installed") completed_cb(true);
- else console.assert(false);
+ if( status == "toinstall" ) completed_cb();
+ else if( status == "toupgrade") completed_cb();
+ else if( status == "installed") completed_cb();
+ else console.assert();
}
})
};
/**
- * @returns {boolean} true if webpeer is present, false otherwise
+ * webpeer.present() returns true if webpeer has been detected, false otherwise
+ *
+ * - do a webpeer.ready() before to get meaningfull results
+ *
+ * @returns {boolean} true if webpeer is detected, false otherwise
*/
webpeer.present = function(){
return app_detect.webpeer_status() == "installed";
}
/**
- * webpeerify a url to static file
- * - this is an minimal helper on top of url_builder_oload_t
- * - url_builder_oload_t implementation is complete and much more complex
+ * webpeerify a url to a file
+ * - if webpeer has not been detected the url is returned as is.
+ * - do a webpeer.ready() before to get meaningfull results
+ * - This is a simplified url convertion to webpeer
*
* @param url {string} original url to webpeerify
*/
@@ -73,13 +80,15 @@ webpeer.monitor = function(ctor_opts){
}
/**
- * - this function is web-only
+ * Generate a dynamic badge of webpeer. It is web-only function. a busy wheel is displayed
+ * during the detection, if detected it is replaced by a green checkmark, else it is
+ * replaced by a red cross
*
* @param {string} the dom element id of the img tag
*/
webpeer.badge = function(elem_id){
webpeer.ready(function(){
- var elem = document.getElementById("webpeer_badge");
+ var elem = document.getElementById(elem_id);
elem.src = "http://webpeer.it/images/badge/" + (webpeer.present() ? 'accept.png' : 'exclamation.png');
if( webpeer.present() ){
elem.title = "You are a web peer. Congrats!";
@@ -93,7 +102,4 @@ webpeer.badge = function(elem_id){
exports.present = webpeer.present;
exports.url = webpeer.url;
exports.ready = webpeer.ready;
-exports.monitor = webpeer.monitor;
exports.badge = webpeer.badge;
-// backward compatible API - deprecated
-exports.avail = function(){ console.log('Obsolet function. use .present()'); webpeer.present.apply(this, arguments); }
View
6 lib/webpeer_test.js
@@ -17,8 +17,8 @@ var test = function(testname, test_cb){
//////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////
-webpeer.monitor(function(){
- console.log("avail="+webpeer.avail());
- //console.log("url is " + webpeer.url("http://example.com/file.ext"));
+webpeer.ready(function(){
+ console.log("present="+webpeer.present());
+ console.log("url is " + webpeer.url("http://example.com/file.ext"));
})

0 comments on commit 9032637

Please sign in to comment.
Something went wrong with that request. Please try again.