Skip to content

Instantly share code, notes, and snippets.

@rbinksy
Last active May 12, 2016 14:26
Show Gist options
  • Save rbinksy/3300c785b63a043322687a43a00aa103 to your computer and use it in GitHub Desktop.
Save rbinksy/3300c785b63a043322687a43a00aa103 to your computer and use it in GitHub Desktop.
CardDirective.$inject = ['VicStripeService', 'vicPayments'];
function CardDirective(VicStripeService, vicPayments){
return {
restrict: 'E',
scope: {
card: '='
},
templateUrl: function(elem, attrs) {
return attrs.template || 'victor/stripeForm.html';
},
controllerAs: 'vm',
bindToController: true,
controller: function($scope) {
var vm = this;
vm.paymentsService = vicPayments;
vm.cardTypeClass = 'vic-card-type-unknown';
$scope.$watch('card.number', function(){
vm.cardTypeClass = 'vic-card-type-' + VicStripeService.getCardType(vm.card.number).toLowerCase();
vm.card.cardType = VicStripeService.getCardType(vm.card.number).toLowerCase();
});
}
};
}
templateCache.$inject = ['$templateCache'];
function templateCache($templateCache) {
var tpl = [ //<troll>JSX</troll>
'<div>',
'<section id="form-placeholder"></section>',
'<div class="row" ng-init="card = card || {}">',
'<div class="form-group col-xs-2">',
'<span ng-class="{{vm.cardTypeClass}}"></span>',
'</div>',
];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment