Last active
December 10, 2015 10:43
-
-
Save rickycheers/4422763 to your computer and use it in GitHub Desktop.
Backbone App - Unstoppable Templates Controller
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(function($){ | |
$(function(){ | |
//$('.box-content').hide(); | |
var AppRouter = Backbone.Router.extend({ | |
routes: { | |
//"section/:s": "goToSection", | |
"*actions": "goToSection" | |
}, | |
goToSection: function(s){ | |
var el = $('#'+s); | |
if( el.length !== 0 ){ | |
var destination = el.offset().top - 133; | |
el.find('div.more').toggleClass('open').toggleClass('close'); | |
$("html:not(:animated),body:not(:animated)").animate({scrollTop: destination}, 300, function(){ | |
if( s !== 'donate-now'){ | |
el.find('div.box-content').slideDown(); | |
} | |
}); | |
} | |
} | |
}); | |
var Router = new AppRouter; | |
var AppView = Backbone.View.extend({ | |
el: $('body'), | |
events: { | |
"click .more": 'toggleBox', | |
"click a": "preventClicks", | |
"click #payWith2D": "showForm", | |
"click #payWithPayPal": "submitToPaypal" | |
}, | |
showForm: function(){ | |
$('#part_2').slideDown(); | |
}, | |
submitToPaypal: function(){ | |
function setValueAndSubmit(amount){ | |
$('#ppRecurringSelect').val(amount + ' USD Recurring Donation'); | |
$('#ppSubscription').submit(); | |
} | |
$('#part_2').slideUp(); | |
$('input[name=frmItem_120]').each(function(){ | |
var $input = $(this); | |
if($input.is(':checked')){ | |
switch( $input.val() ){ | |
case '266': | |
if($('#rcr_identi_121').is(':checked')){ | |
setValueAndSubmit(50); | |
}else{ | |
$('#pp50').submit(); | |
} | |
break; | |
case '267': | |
if($('#rcr_identi_121').is(':checked')){ | |
setValueAndSubmit(100); | |
}else{ | |
$('#pp100').submit(); | |
} | |
break; | |
case '268': | |
if($('#rcr_identi_121').is(':checked')){ | |
setValueAndSubmit(150); | |
}else{ | |
$('#pp150').submit(); | |
} | |
break; | |
case '265': | |
if($('#rcr_identi_121').is(':checked')){ | |
setValueAndSubmit(1000); | |
}else{ | |
$('#pp1000').submit(); | |
} | |
break; | |
case '269': | |
var custom_value = $('#donation_value_90_269').val(); | |
$('#ppCustom') | |
.append('<input name="amount" value="'+custom_value+'">') | |
.submit(); | |
break; | |
} | |
} | |
}); | |
}, | |
toggleBox: function(e){ | |
var el = $(e.target); | |
el.toggleClass('open').toggleClass('close'); | |
if( el.hasClass('open') ){ | |
el.parents('div.box-head').next().slideUp(); | |
}else{ | |
el.parents('div.box-head').next().slideDown(); | |
} | |
}, | |
preventClicks: function(e){ | |
//e.preventDefault(); | |
} | |
}); | |
var App = new AppView; | |
Backbone.history.start(); | |
}); | |
})(jQuery); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment