0
0
mirror of https://github.com/Doodle3D/doodle3d-connect.git synced 2024-11-16 19:17:56 +01:00
doodle3d-connect/js/BoxesPage.js

91 lines
3.1 KiB
JavaScript
Raw Normal View History

2014-04-24 12:46:26 +02:00
/*
* This file is part of the Doodle3D project (http://doodle3d.com).
*
* Copyright (c) 2013, Doodle3D
* This software is licensed under the terms of the GNU GPL v2 or later.
* See file LICENSE.txt or visit http://www.gnu.org/licenses/gpl.html for full license details.
*/
2014-05-12 14:44:21 +02:00
(function (w) {
2014-04-25 16:24:25 +02:00
var _connectAPI = new ConnectAPI();
2014-04-24 12:46:26 +02:00
var _page;
var _list;
var _findItem;
var PAGE_ID = "#boxes";
$.mobile.document.on( "pageinit", PAGE_ID, function( event, data ) {
//console.log("Boxes page pageinit");
_page = $(this);
_list = _page.find("#boxeslist");
_findItem = _list.find("#findItem");
2014-04-25 16:24:25 +02:00
_connectAPI.refreshing = onRefreshing;
2014-05-07 15:18:08 +02:00
_connectAPI.listFailed = onListFailed;
_connectAPI.listSuccess = onlistSuccess;
2014-04-25 16:24:25 +02:00
_connectAPI.listUpdated = onListUpdated;
_connectAPI.boxAppeared = onBoxAppeared;
_connectAPI.boxDisapeared = onBoxDisapeared;
2014-04-24 12:46:26 +02:00
});
$.mobile.document.on( "pagebeforeshow", PAGE_ID, function( event, data ) {
//console.log("Boxes page pagebeforeshow");
2014-04-25 16:24:25 +02:00
_connectAPI.start();
});
$.mobile.document.on( "pageshow", PAGE_ID, function( event, data ) {
//console.log("Boxes page pageshow");
addToHomescreen(/*{
debug: true, // activate debug mode in ios emulation
skipFirstVisit: false, // show at first access
startDelay: 0, // display the message right away
lifespan: 0, // do not automatically kill the call out
displayPace: 0, // do not obey the display pace
maxDisplayCount: 0 // do not obey the max display count
}*/);
2014-04-24 12:46:26 +02:00
});
$.mobile.document.on( "pagebeforehide", PAGE_ID, function( event, data ) {
2014-04-24 12:46:26 +02:00
//console.log("Boxes page pagehide");
2014-04-25 16:24:25 +02:00
_connectAPI.stop();
2014-04-24 12:46:26 +02:00
});
function onRefreshing() {
//console.log("onRefreshing");
d3d.util.showLoader(true);
}
2014-05-07 15:18:08 +02:00
function onListFailed() {
d3d.util.enableRefreshPrevention();
d3d.util.enableLeaveWarning("You're not connecting to the internet, leaving now will interrupt the connection proces");
}
function onlistSuccess() {
d3d.util.disableRefreshPrevention();
d3d.util.disableLeaveWarning();
}
2014-04-24 12:46:26 +02:00
function onListUpdated(boxesData) {
2014-04-28 16:55:33 +02:00
//console.log("onListUpdated: ",boxesData);
2014-04-24 12:46:26 +02:00
}
function onBoxAppeared(boxData) {
console.log("onBoxAppeared: ",boxData.localip);
2014-04-25 16:24:25 +02:00
var linkParams = {localip: boxData.localip,wifiboxid: boxData.wifiboxid};
if(boxData.link) { linkParams.link = boxData.link; }
var link = "#box";
link = d3d.util.replaceURLParameters(link,linkParams);
2014-04-24 12:46:26 +02:00
var id = boxData.localip.replace(/\./g,"-");
var linkElement = $("<a href='"+link+"' class='link'>"+boxData.wifiboxid+"</a>");
var box = $("<li id='"+id+"' class='box'></li>");
box.append(linkElement);
box.hide().appendTo(_list).fadeIn(500);
2014-04-28 16:55:33 +02:00
_list.append(_findItem); // make sure find is the last item
_list.listview('refresh'); // jQuery mobile enhance content
2014-04-24 12:46:26 +02:00
}
function onBoxDisapeared(boxData) {
console.log("onBoxDisapeared: ",boxData.localip);
var id = boxData.localip.replace(/\./g,"-");
var box = _list.find("#"+id);
console.log(" box: ",box);
box.fadeOut(500,function() {
box.remove();
//_list.listview('refresh');
});
}
})(window);