Ejemplo n.º 1
0
function loadFeeds(users, meta) {
	vars.users = vars.users.concat(users);
	vars.total_pages = meta.total_pages;
	vars.total_results = meta.total_results;
	
	var len = users.length;
	if (len) {
		// load first users
		if (meta.page == 1) {
			for(var i=0,ii=len >= 3 ? 3 : len; i<ii; i++){
				loadCard(i, i);
			};
			
			// mark view for the first user
	  		Api.onViewPhoto( users[0].id );
	  		
	  		vars.dataIndex = ii - 1;
	  		vars.containerIndex = 0;
	  		
	  		vars.swipeEnable = len > 1;
	  		$.card_0.parent.addEventListener('swipe', listSwipe);
		}
	}
	
	Alloy.Globals.toggleAI(false);
}
Ejemplo n.º 2
0
function listSwipe(e) {
  	if (e.direction == 'up') {
  		if (vars.swipeEnable == false) {
  			Alloy.Globals.Common.showDialog({
	            title:    'That\'s all folks!',
 				message:  'Give us a day or so to analyze the data and find more matches for you.'
         	});
  			return;
  		}
  		
  		var prev    = vars.containerIndex, 
  			current = prev + 1,
  			next	= current + 1;
  		
  		if (prev == 1) {
  			next = 0;
  		} else if (prev == 2) {
  			current = 0;
  			next = 1;
  		}
  		
  		vars.containerIndex = current;
  		
  		//
  		
  		var currentCard = $['card_' + current];
  		currentCard.zIndex = 2;
  		
  		// mark view for current user
  		Api.onViewPhoto( currentCard.userId );
  		
  		$['card_' + prev].animate({ top: -vars.height, duration: 500 });
  		
  		currentCard.animate({ top: 0, duration: 500 }, function(e){ 
  			$['card_' + vars.containerIndex].zIndex = 1;
  		});
  		
  		$['card_' + next].animate({ top: vars.height, duration: 500 }, function(e) {
  			var currentIndex = vars.containerIndex,
  				previousIndex = (currentIndex == 0 ? 2 : currentIndex == 1 ? 0 : 1);
  				
  			var element = $['card_' + previousIndex];
  			element.top = 2 * vars.height;
  			element.removeAllChildren();
  			
  			vars.dataIndex++;
  			
  			var len = vars.total_results;
  			if (vars.dataIndex < len) {
  				loadCard(vars.dataIndex, previousIndex);
  			} else {
  				if (vars.dataIndex > len) {
  					vars.swipeEnable = false;
  				}
  			}
  		});
  		
  		// prefetch feed
	  	vars.swipe_count++;
  		if (vars.swipe_count % vars.PER_PREFETCH == 0) {
			vars.page++;
			if (vars.page <= vars.total_pages) {
				getFeeds();
			}
		}
  	}
}