I'm trying to configure jQuery plugins trough classes applied to elements to which these plugins are attached.
for example:
<div class="move amt-10 dir-left">
...
</div>
and the js:
$('.move').each(function(){
var classes = $(this).attr('class');
// this is from: http://stackoverflow.com/questions/3955345/javascript-jquery-get-number-from-string
var amount = parseInt(/amt-(\d+)/.exec(classes)[1], 10);
var direction = /dir-([^\s]+)/.exec(classes)[1];
// do stuff here based on amount/direction variables
});
it works for this particular case, but since I'm doing this for other plugins too, I was wondering how could create some kind of "parser" for this kind of options passed trough classes, so I can write less code :)