Skip to content

Instantly share code, notes, and snippets.

@zorbash
Created June 5, 2013 10:36
Show Gist options
  • Save zorbash/5713028 to your computer and use it in GitHub Desktop.
Save zorbash/5713028 to your computer and use it in GitHub Desktop.
jQuery plugin data parsing function
###
Imports data attributes in form of data-slider-option
into the options
###
parseDataAttributes: ->
# Loop through the data that are not the plugin itself and are in
# the required form (data-slider-option)
for k, v of @$element.data() when k isnt 'plugin_slider' and /^slider/.test k
# separate the option name, here we have it capitalized
option_name = (k.match /(?:slider)(.*)/i)[1]
# uncapitalize it
option_name = "#{option_name[0...1].toLowerCase()}#{option_name[1..]}"
# use it as a key to set the new value
@options[option_name] = v
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment