").attr({"class":"card-body"}),this.el.front.appendTo(this.el.cardBody),this.el.back.appendTo(this.el.cardBody),this.el.cardBody.appendTo(this.el.container),this._tabViews.front=new Skeuocard.prototype.FlipTabView(this,"front",{strings:this.options.strings}),this._tabViews.back=new Skeuocard.prototype.FlipTabView(this,"back",{strings:this.options.strings}),this.el.front.prepend(this._tabViews.front.el),this.el.back.prepend(this._tabViews.back.el),this._tabViews.front.hide(),this._tabViews.back.hide(),this._inputViews={number:new this.SegmentedCardNumberInputView,exp:new this.ExpirationInputView({currentDate:this.options.currentDate}),name:new this.TextInputView({"class":"cc-name",placeholder:"YOUR NAME"}),cvc:new this.TextInputView({"class":"cc-cvc",placeholder:"XXX",requireMaxLength:!0})},this._inputViews.number.el.addClass("cc-number"),this._inputViews.number.el.appendTo(this.el.front),this._inputViews.name.el.appendTo(this.el.front),this._inputViews.exp.el.addClass("cc-exp"),this._inputViews.exp.el.appendTo(this.el.front),this._inputViews.cvc.el.appendTo(this.el.back),this.el.container},Skeuocard.prototype._importImplicitOptions=function(){var fieldEl,fieldName,_initialExp,_ref,_this=this;_ref=this.el.underlyingFields;for(fieldName in _ref)fieldEl=_ref[fieldName],null==this.options.initialValues[fieldName]?this.options.initialValues[fieldName]=fieldEl.val():(this.options.initialValues[fieldName]=this.options.initialValues[fieldName].toString(),this._setUnderlyingValue(fieldName,this.options.initialValues[fieldName])),this.options.initialValues[fieldName].length>0&&(this._state.initiallyFilled=!0),null==this.options.validationState[fieldName]&&(this.options.validationState[fieldName]=!fieldEl.hasClass("invalid"));return null==this.options.acceptedCardProducts&&(this.options.acceptedCardProducts=[],this.el.underlyingFields.type.find("option").each(function(i,_el){var el,shortname;return el=$(_el),shortname=el.attr("data-sc-type")||el.attr("value"),_this.options.acceptedCardProducts.push(shortname)})),this.options.initialValues.number.length>0&&this.set("number",this.options.initialValues.number),this.options.initialValues.name.length>0&&this.set("name",this.options.initialValues.name),this.options.initialValues.cvc.length>0&&this.set("cvc",this.options.initialValues.cvc),this.options.initialValues.expYear.length>0&&this.options.initialValues.expMonth.length>0&&(_initialExp=new Date(parseInt(this.options.initialValues.expYear),parseInt(this.options.initialValues.expMonth)-1,1),this.set("exp",_initialExp)),this._updateValidationForFace("front"),this._updateValidationForFace("back")},Skeuocard.prototype.set=function(field,newValue){return this._inputViews[field].setValue(newValue),this._inputViews[field].trigger("valueChanged",this._inputViews[field])},Skeuocard.prototype._bindInputEvents=function(){var _expirationChange,_this=this;return this.el.underlyingFields.number.bind("change",function(){return _this._inputViews.number.setValue(_this._getUnderlyingValue("number")),_this.render()}),_expirationChange=function(){var month,year;return month=parseInt(_this._getUnderlyingValue("expMonth")),year=parseInt(_this._getUnderlyingValue("expYear")),_this._inputViews.exp.setValue(new Date(year,month-1)),_this.render()},this.el.underlyingFields.expMonth.bind("change",_expirationChange),this.el.underlyingFields.expYear.bind("change",_expirationChange),this.el.underlyingFields.name.bind("change",function(){return _this._inputViews.exp.setValue(_this._getUnderlyingValue("name")),_this.render()}),this.el.underlyingFields.cvc.bind("change",function(){return _this._inputViews.exp.setValue(_this._getUnderlyingValue("cvc")),_this.render()}),this._inputViews.number.bind("change valueChanged",function(e,input){var cardNumber,matchedProduct,number,previousProduct,_ref,_ref1;return cardNumber=input.getValue(),_this._setUnderlyingValue("number",cardNumber),_this._updateValidation("number",cardNumber),number=_this._getUnderlyingValue("number"),matchedProduct=Skeuocard.prototype.CardProduct.firstMatchingNumber(number),(null!=(_ref=_this.product)?_ref.eql(matchedProduct):void 0)?void 0:(_this._log("Product will change:",_this.product,"=>",matchedProduct),_ref1=null!=matchedProduct?matchedProduct.attrs.companyShortname:void 0,__indexOf.call(_this.options.acceptedCardProducts,_ref1)>=0?(_this.trigger("productWillChange.skeuocard",[_this,_this.product,matchedProduct]),previousProduct=_this.product,_this.el.container.removeClass("unaccepted"),_this._renderProduct(matchedProduct),_this.product=matchedProduct):null!=matchedProduct?(_this.trigger("productWillChange.skeuocard",[_this,_this.product,null]),_this.el.container.addClass("unaccepted"),_this._renderProduct(null),_this.product=null):(_this.trigger("productWillChange.skeuocard",[_this,_this.product,null]),_this.el.container.removeClass("unaccepted"),_this._renderProduct(null),_this.product=null),_this.trigger("productDidChange.skeuocard",[_this,previousProduct,_this.product]))}),this._inputViews.exp.bind("keyup valueChanged",function(e,input){var newDate;return newDate=input.getValue(),_this._updateValidation("exp",newDate),null!=newDate?(_this._setUnderlyingValue("expMonth",newDate.getMonth()+1),_this._setUnderlyingValue("expYear",newDate.getFullYear())):void 0}),this._inputViews.name.bind("keyup valueChanged",function(e,input){var value;return value=input.getValue(),_this._setUnderlyingValue("name",value),_this._updateValidation("name",value)}),this._inputViews.cvc.bind("keyup valueChanged",function(e,input){var value;return value=input.getValue(),_this._setUnderlyingValue("cvc",value),_this._updateValidation("cvc",value)}),this.el.container.delegate("input","keyup keydown",this._handleFieldTab.bind(this)),this._tabViews.front.el.click(function(){return _this.flip()}),this._tabViews.back.el.click(function(){return _this.flip()})},Skeuocard.prototype._handleFieldTab=function(e){var backFieldEls,currentFieldEl,frontFieldEls,_currentFace,_oppositeFace;return 9===e.which&&(currentFieldEl=$(e.currentTarget),_oppositeFace="front"===this.visibleFace?"back":"front",_currentFace="front"===this.visibleFace?"front":"back",backFieldEls=this.el[_oppositeFace].find("input"),frontFieldEls=this.el[_currentFace].find("input"),"front"===this.visibleFace&&this.el.front.hasClass("filled")&&backFieldEls.length>0&&frontFieldEls.index(currentFieldEl)===frontFieldEls.length-1&&!e.shiftKey&&(this.flip(),backFieldEls.first().focus(),e.preventDefault()),"back"===this.visibleFace&&e.shiftKey&&(this.flip(),backFieldEls.last().focus(),e.preventDefault())),!0},Skeuocard.prototype._updateValidation=function(fieldName,newValue){var fillStateChanged,isFilled,isFixed,isValid,needsFix,validationStateChanged;return null==this.product?!1:(isFilled=this.product[fieldName].isFilled(newValue),needsFix=null!=this.options.validationState[fieldName]==!1,isFixed=null!=this.options.initialValues[fieldName]&&newValue!==this.options.initialValues[fieldName],isValid=this.product[fieldName].isValid(newValue)&&(needsFix&&isFixed||!0),fillStateChanged=this._state[""+fieldName+"Filled"]!==isFilled,validationStateChanged=this._state[""+fieldName+"Valid"]!==isValid,fillStateChanged&&(this.trigger("fieldFillStateWillChange.skeuocard",[this,fieldName,isFilled]),this._inputViews[fieldName].el.toggleClass("filled",isFilled),this._state[""+fieldName+"Filled"]=isFilled,this.trigger("fieldFillStateDidChange.skeuocard",[this,fieldName,isFilled])),validationStateChanged&&(this.trigger("fieldValidationStateWillChange.skeuocard",[this,fieldName,isValid]),this._inputViews[fieldName].el.toggleClass("valid",isValid),this._inputViews[fieldName].el.toggleClass("invalid",!isValid),this._state[""+fieldName+"Valid"]=isValid,this.trigger("fieldValidationStateDidChange.skeuocard",[this,fieldName,isValid])),this._updateValidationForFace(this.visibleFace))},Skeuocard.prototype._updateValidationForFace=function(face){var fieldsFilled,fieldsValid,fillStateChanged,isFilled,isValid,iv,validationStateChanged;return fieldsFilled=function(){var _i,_len,_ref,_results;for(_ref=this._inputViewsByFace[face],_results=[],_i=0,_len=_ref.length;_len>_i;_i++)iv=_ref[_i],_results.push(iv.el.hasClass("filled"));return _results}.call(this).every(Boolean),fieldsValid=function(){var _i,_len,_ref,_results;for(_ref=this._inputViewsByFace[face],_results=[],_i=0,_len=_ref.length;_len>_i;_i++)iv=_ref[_i],_results.push(iv.el.hasClass("valid"));return _results}.call(this).every(Boolean),isFilled=fieldsFilled&&null!=this.product||this._state.initiallyFilled||!1,isValid=fieldsValid&&null!=this.product,fillStateChanged=this._state[""+face+"Filled"]!==isFilled,validationStateChanged=this._state[""+face+"Valid"]!==isValid,fillStateChanged&&(this.trigger("faceFillStateWillChange.skeuocard",[this,face,isFilled]),this.el[face].toggleClass("filled",isFilled),this._state[""+face+"Filled"]=isFilled,this.trigger("faceFillStateDidChange.skeuocard",[this,face,isFilled])),validationStateChanged?(this.trigger("faceValidationStateWillChange.skeuocard",[this,face,isValid]),this.el[face].toggleClass("valid",isValid),this.el[face].toggleClass("invalid",!isValid),this._state[""+face+"Valid"]=isValid,this.trigger("faceValidationStateDidChange.skeuocard",[this,face,isValid])):void 0},Skeuocard.prototype._renderProduct=function(product){var destFace,fieldName,focused,view,viewEl,_ref,_ref1;if(this._log("[_renderProduct]","Rendering product:",product),this.el.container.removeClass(function(index,css){return(css.match(/\b(product|issuer)-\S+/g)||[]).join(" ")}),null!=(null!=product?product.attrs.companyShortname:void 0)&&this.el.container.addClass("product-"+product.attrs.companyShortname),null!=(null!=product?product.attrs.issuerShortname:void 0)&&this.el.container.addClass("issuer-"+product.attrs.issuerShortname),this._setUnderlyingValue("type",(null!=product?product.attrs.companyShortname:void 0)||null),this._inputViews.number.setGroupings((null!=product?product.attrs.cardNumberGrouping:void 0)||[this.options.genericPlaceholder.length],this.options.dontFocus),delete this.options.dontFocus,null!=product){this._inputViews.exp.reconfigure({pattern:(null!=product?product.attrs.expirationFormat:void 0)||"MM/YY"}),this._inputViews.cvc.attr({maxlength:product.attrs.cvcLength,placeholder:new Array(product.attrs.cvcLength+1).join(this.options.cardNumberPlaceholderChar)}),this._inputViewsByFace={front:[],back:[]},focused=$("input:focus"),_ref=product.attrs.layout;for(fieldName in _ref)destFace=_ref[fieldName],this._log("Moving",fieldName,"to",destFace),viewEl=this._inputViews[fieldName].el.detach(),viewEl.appendTo(this.el[destFace]),this._inputViewsByFace[destFace].push(this._inputViews[fieldName]),this._inputViews[fieldName].show();setTimeout(function(){var fieldEl,fieldLength;return null!=(fieldEl=focused.first())?(fieldLength=fieldEl[0].maxLength,fieldEl.focus(),fieldEl[0].setSelectionRange(fieldLength,fieldLength)):void 0},10)}else{_ref1=this._inputViews;for(fieldName in _ref1)view=_ref1[fieldName],"number"!==fieldName&&view.hide()}return product},Skeuocard.prototype._renderValidation=function(){var fieldName,fieldView,_ref,_results;_ref=this._inputViews,_results=[];for(fieldName in _ref)fieldView=_ref[fieldName],_results.push(this._updateValidation(fieldName,fieldView.getValue()));return _results},Skeuocard.prototype.render=function(){return this._renderProduct(this.product),this._renderValidation()},Skeuocard.prototype.flip=function(){var surfaceName,targetFace;return targetFace="front"===this.visibleFace?"back":"front",this.trigger("faceWillBecomeVisible.skeuocard",[this,targetFace]),this.visibleFace=targetFace,this.el.cardBody.toggleClass("flip"),surfaceName="front"===this.visibleFace?"front":"back",this.el[surfaceName].find(".cc-field").not(".filled").find("input").first().focus(),this.trigger("faceDidBecomeVisible.skeuocard",[this,targetFace])},Skeuocard.prototype._setUnderlyingValue=function(field,newValue){var fieldEl,remapAttrKey,_newValue,_this=this;if(fieldEl=this.el.underlyingFields[field],_newValue=(newValue||"").toString(),null==fieldEl)throw"Set underlying value of unknown field: "+field+".";return this.trigger("change.skeuocard",[this]),fieldEl.is("select")?(remapAttrKey="data-sc-"+field.toLowerCase(),fieldEl.find("option").each(function(i,_el){var optionEl;return optionEl=$(_el),_newValue===(optionEl.attr(remapAttrKey)||optionEl.attr("value"))?_this.el.underlyingFields[field].val(optionEl.attr("value")):void 0})):this.el.underlyingFields[field].val(_newValue)},Skeuocard.prototype._getUnderlyingValue=function(field){var _ref;return null!=(_ref=this.el.underlyingFields[field])?_ref.val():void 0},Skeuocard.prototype.isValid=function(){return!this.el.front.hasClass("invalid")&&!this.el.back.hasClass("invalid")},Skeuocard}(),window.Skeuocard=Skeuocard,Skeuocard.prototype.FlipTabView=function(){function FlipTabView(sc,face,opts){var _this=this;null==opts&&(opts={}),this.card=sc,this.face=face,this.el=$('
'),this.options=opts,this._state={},this.card.bind("faceFillStateWillChange.skeuocard",this._faceStateChanged.bind(this)),this.card.bind("faceValidationStateWillChange.skeuocard",this._faceValidationChanged.bind(this)),this.card.bind("productWillChange.skeuocard",function(e,card,prevProduct,newProduct){return null==newProduct?_this.hide():void 0})}return FlipTabView.prototype._faceStateChanged=function(e,card,face,isFilled){var oppositeFace;return oppositeFace="front"===face?"back":"front",isFilled===!0&&this.card._inputViewsByFace[oppositeFace].length>0&&this.show(),face!==this.face&&(this._state.opposingFaceFilled=isFilled),this._state.opposingFaceFilled!==!0?this.warn(this.options.strings.hiddenFaceFillPrompt,!0):void 0},FlipTabView.prototype._faceValidationChanged=function(e,card,face,isValid){return face!==this.face&&(this._state.opposingFaceValid=isValid),this._state.opposingFaceValid?this.prompt(this.options.strings.hiddenFaceSwitchPrompt):this._state.opposingFaceFilled?this.warn(this.options.strings.hiddenFaceErrorWarning):this.warn(this.options.strings.hiddenFaceFillPrompt)},FlipTabView.prototype._setText=function(text){return this.el.find("p").first().html(text)},FlipTabView.prototype.warn=function(message){return this._resetClasses(),this._setText(message),this.el.addClass("warn")},FlipTabView.prototype.prompt=function(message){return this._resetClasses(),this._setText(message),this.el.addClass("prompt")},FlipTabView.prototype._resetClasses=function(){return this.el.removeClass("warn"),this.el.removeClass("prompt")},FlipTabView.prototype.show=function(){return this.el.show()},FlipTabView.prototype.hide=function(){return this.el.hide()},FlipTabView}(),Skeuocard.prototype.SegmentedCardNumberInputView=function(){function SegmentedCardNumberInputView(opts){null==opts&&(opts={}),this.optDefaults={value:"",groupings:[19],placeholderChar:"X"},this.options=$.extend({},this.optDefaults,opts),this._state={selectingAll:!1},this._buildDOM(),this.setGroupings(this.options.groupings)}return SegmentedCardNumberInputView.prototype._digits=["0","1","2","3","4","5","6","7","8","9"],SegmentedCardNumberInputView.prototype._keys={backspace:8,tab:9,enter:13,del:46,arrowLeft:37,arrowUp:38,arrowRight:39,arrowDown:40,arrows:[37,38,39,40],command:16,alt:17},SegmentedCardNumberInputView.prototype._specialKeys=[8,9,13,46,37,38,39,40,16,17],SegmentedCardNumberInputView.prototype._buildDOM=function(){var _this=this;return this.el=$("