/*HTMLElement.prototype.originalRemoveEventListener
= HTMLElement.prototype.removeEventListener;
HTMLElement.prototype.removeEventListener = function(type, listener, useCapture)
{
console.log('remove: ' + type);
this.originalRemoveEventListener(type, listener, useCapture);
};
*/
var markets = [];
var viewAssembler = new ViewAssembler();
$(document).ready( function(){
loadTemplates( setupDefaultView );
} );
function setupDefaultView() {
var bodyView = viewAssembler.defaultView();
//Setup the default view
var defaultView = { title: "Welcome!",
view: bodyView,
};
//Setup the ViewNavigator
window.viewNavigator = new ViewNavigator( 'body' );
window.viewNavigator.pushView( defaultView );
$.getScript("data.js", scriptSuccess);
}
function onMapButtonClick( event ) {
var view = { title: "Map",
backLabel: (isTablet() ? "Back" : " "),
view: viewAssembler.mapView(),
scroll:false
};
window.viewNavigator.pushView( view );
event.stopPropagation();
return false;
}
function onSearchResultMapButtonClick( event ) {
var centerPoint = {x:0,y:0};
var len = 0;
for( var i = 0; i 0 ) {
criteria[field] = value;
}
}
else {
value = $input.is(":checked");
if ( value == true ) {
criteria[field] = value;
}
}
}
var markets = filterMarketsBySearchCriteria( criteria );
var view = { title: "Search Results",
backLabel: (isTablet() ? "Back" : " "),
view: viewAssembler.searchResultsView( markets, criteria )
};
window.viewNavigator.pushView( view );
}
function filterMarketsBySearchCriteria( criteria ) {
var result = [];
var startTime = new Date().getTime();
for ( var i =0; i < markets.length; i++ )
{
if ( marketRowMatchesCriteria( markets[i], criteria ) ) {
result.push( markets[i] );
}
}
//console.log( new Date().getTime() - startTime );
return result;
}
function marketRowMatchesCriteria( row, criteria ) {
//state
if ( row[6] != criteria.state ) { return false; }
if ( criteria.credit == true ) { if ( row[11] != "Y" ) return false; };
if ( criteria.wic == true ) { if ( row[12] != "Y" ) return false; };
if ( criteria.wiccash == true ) { if ( row[13] != "Y" ) return false; };
if ( criteria.sfmnp == true ) { if ( row[14] != "Y" ) return false; };
if ( criteria.snap == true ) { if ( row[15] != "Y" ) return false; };
if ( criteria.bakedGoods == true ) { if ( row[16] != "Y" ) return false; };
if ( criteria.cheese == true ) { if ( row[17] != "Y" ) return false; };
if ( criteria.crafts == true ) { if ( row[18] != "Y" ) return false; };
if ( criteria.flowers == true ) { if ( row[19] != "Y" ) return false; };
if ( criteria.seafood == true ) { if ( row[20] != "Y" ) return false; };
if ( criteria.fruit == true ) { if ( row[21] != "Y" ) return false; };
if ( criteria.herbs == true ) { if ( row[22] != "Y" ) return false; };
if ( criteria.vegetables == true ) { if ( row[23] != "Y" ) return false; };
if ( criteria.honey == true ) { if ( row[24] != "Y" ) return false; };
if ( criteria.jams == true ) { if ( row[25] != "Y" ) return false; };
if ( criteria.maple == true ) { if ( row[26] != "Y" ) return false; };
if ( criteria.meat == true ) { if ( row[27] != "Y" ) return false; };
if ( criteria.nuts == true ) { if ( row[28] != "Y" ) return false; };
if ( criteria.plants == true ) { if ( row[29] != "Y" ) return false; };
if ( criteria.soap == true ) { if ( row[31] != "Y" ) return false; };
//searchString last
if ( criteria.searchPhrase != undefined && criteria.searchPhrase.length > 0 ) {
var tokens = criteria.searchPhrase.split(" ");
var result = true;
for ( var i=0; i= 32 ) {
result[ fields[index] ] = arr[ index ];
}
else {
result[ fields[index] ] = (arr[ index ] == "Y");
}
}
result.paymentDetail = result.credit || result.wic || result.wicash || result.sfmnp || result.snap;
result.productDetail = result.bakedgoods || result.cheese || result.crafts || result.flowers || result.seafood || result.fruit || result.herbs || result.vegetables || result.honey || result.jams || result.maple || result.meat || result.nuts || result.plants || result.prepared || result.soap;
return result;
}
function openExternalURL( url ) {
var result=confirm("You will leave the Farmers Market Finder App. Continue?");
if (result==true) {
window.open( url, '_blank' );
}
}
function viewInMap( index ) {
var market = arrayToMarketObject( markets[index] );
var view = { title: market.marketName,
backLabel: (isTablet() ? "Back" : " "),
view: viewAssembler.marketMapView( market ),
scroll:false
};
window.viewNavigator.pushView( view );
}
function getDirections( index ) {
var market = arrayToMarketObject( markets[index] );
var result=confirm("You will leave the Farmers Market Finder App. Continue?");
if (result==true) {
var win = navigator.userAgent.search( "Windows Phone" ) >= 0;
var android = navigator.userAgent.search( "Android" ) >= 0;
/*if (win) {
window.open( ('maps:' + market.y + ',' + market.x), '_blank' );
}
else
*/
if (android) {
navigator.app.loadUrl( 'http://maps.google.com/maps?q=' + market.y + ',' + market.x);
}
else {
window.open( ('http://maps.google.com/maps?q=' + market.y + ',' + market.x), '_blank' );
}
}
}
document.addEventListener("deviceready", onDeviceReady, false);
function onDeviceReady() {
document.addEventListener("backbutton", onBackKey, false);
}
function onBackKey( event ) {
if ( window.viewNavigator.history.length > 1 ){
event.preventDefault();
window.viewNavigator.popView();
return false;
}
navigator.app.exitApp();
}
document.addEventListener('touchmove', function (e) { e.preventDefault(); }, false);