Skip to content

Instantly share code, notes, and snippets.

@jhyland87
Created August 31, 2016 19:56
Show Gist options
  • Save jhyland87/8dc77cda2a7c4ec79d7fd38665c519f0 to your computer and use it in GitHub Desktop.
Save jhyland87/8dc77cda2a7c4ec79d7fd38665c519f0 to your computer and use it in GitHub Desktop.
switch ( true ) {
// Search Applied filter
case /^(search)?applied$/.test( selectStr ):
return { search: 'applied' }
break
// Search Removed filter
case /^(search)?removed$/.test( selectStr ):
return { search: 'removed' }
break
// Selected Rows filter
case /^select(ed)?$/.test( selectStr ):
return { selected: true }
break
// Deselected Rows filter
case /^(de|un)select(ed)?$/.test( selectStr ):
return { selected: false }
break
// Current Page Rows Filer
case /^(current|page|currentpage)$/.test( selectStr ):
return { page: 'current' }
break
// Focused Rows filter
case /^focused$/.test( selectStr ):
return { focused: true }
break
// Unfocused rows filter
case /^(not|un)focused$/.test( selectStr ):
return { focused: false }
break
// All/Every Row Filter
case /^(all|every(thing)?)$/.test( selectStr ):
return { page: 'all' }
break
// If the selectStr didnt match anything, then determine what to do based off of defaultOpt
default:
// If the defaultOpt was defined as the string "bool" or "boolean", then just return false
if( typeof defaultOpt === 'string' && defaultOpt.match( new RegExp('^bool(ean)?$', 'i') ) ){
return false
// If its an object, then use that as the default selector
if( $.isPlainObject( defaultOpt ) )
return defaultOpt
// If its undefined, then return the default selector (configured above)
if( typeof defaultOpt === 'undefined' )
return defaultRowSelector
// If it gets here, then we can assume defaultOpt was set incorrectly
var defType
try{
defType = defaultOpt.constructor.name.toLowerCase()
}
catch(e){
defType = "Unknown (Failed to get type: " + e
}
// Throw a fancy/detailed exception
//throw Utils.substVars('The defaultOpt given to _getRowSelector() was defined improperly, expected either the '
// +'string "bool" or "boolean"; the boolean value "false"; an object (default selector to return); or '
// +'undefined (to return the default selector configured internally) - The value specified was the type "%type%", with the value: %value%',
// { type: defType, value: defType})
throw "something happened"
break
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment