Created
June 5, 2013 10:36
-
-
Save zorbash/5713028 to your computer and use it in GitHub Desktop.
jQuery plugin data parsing function
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
### | |
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