Skip to content

Instantly share code, notes, and snippets.

@atuttle atuttle/.jscsrc
Created Jul 1, 2015

Embed
What would you like to do?
My JSCS config and a sample of how it formats
{
"preset": "node-style-guide"
,"validateIndentation": "\t"
,"disallowAnonymousFunctions": true
,"disallowSpacesInsideParentheses": { "only": [ "{", "}" ] }
,"requireSpacesInsideParentheses": { "all": true, "except": [ "{", "}" ]
,"requireSpacesInsideBrackets": { "allExcept": [ "[", "]", "{", "}" ] }}
,"requireSpacesInsideObjectBrackets": "allButNested"
,"validateParameterSeparator": ", "
,"disallowCommaBeforeLineBreak": true
,"disallowMixedSpacesAndTabs": "smart"
}
'use strict';
var _ = require( 'lodash' );
var numeral = require( 'numeral' );
var $ = window.jQuery;
module.exports = {
calculateSubtotal: function() {
var totalPrice = 0;
$( '#partyMemberSelections select option:checked' ).each( function() {
var itemPrice = $( this ).data( 'price' );
if ( typeof ( itemPrice ) === 'undefined' ) {
//0
}else {
itemPrice = parseFloat( itemPrice );
totalPrice += itemPrice;
}
});
$( '#subtotal' ).show().html( 'Total: $ ' + numeral( totalPrice ).format( '9.99' ) );
}
, enableSectionsOptions: function( select ) {
var $this = $( select );
if ( $this.val() === 'true' ) {
$this.closest( '.row' ).find( 'select' ).removeAttr( 'disabled' );
}else {
var $selects = $this.closest( '.row' ).find( 'select' ).not( '.primary' );
$selects.find( 'option' ).removeAttr( 'selected' );
$selects.attr( 'disabled', 'disabled' );
}
}
, validateActivitySelections: function() {
var isSuccess = true;
var requiredSelects = $( '#partyMemberSelections' ).find( '.requireSelection' );
_.map( requiredSelects, function( el ) {
var $selected = $( el );
var $dependsOn = $selected.closest( '.row' ).find( '.primary' );
var selectedVal = $selected.val();
if ( selectedVal === '' && $dependsOn.val() === 'true' ) {
isSuccess = false;
$selected.closest( 'div' ).addClass( 'error' ).focus();
}else if ( $selected.is( '.primary' ) ) {
if ( selectedVal === '' ) {
isSuccess = false;
$selected.closest( 'div' ).addClass( 'error' ).focus();
}else {
$selected.closest( 'div' ).removeClass( 'error' );
}
}else {
$selected.closest( 'div' ).removeClass( 'error' );
}
});
if ( !isSuccess ) {
window.alert( 'Please make a selection in all fields marked in red' );
}
return isSuccess;
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.