Skip to content

Instantly share code, notes, and snippets.

@adrian-enspired
Last active March 3, 2017 18:24
Show Gist options
  • Save adrian-enspired/4f40311499798224577644a17cd3c27f to your computer and use it in GitHub Desktop.
Save adrian-enspired/4f40311499798224577644a17cd3c27f to your computer and use it in GitHub Desktop.
riot mixin for converting opts.class to a list.
(function(riot) {
/** resets the classlist from tag options. */
var listClasses = function(tag) {
tag.classlist = tag.opts.class ? tag.opts.class.split(/\s+/) : [];
};
var mixin = {
init: function() {
listClasses(this);
this.on('before-update', function() { listClasses(this); }.bind(this));
},
/** conatiner for classnames. */
classlist: [],
/**
* gets the classlist as a string.
*
* @return string space-separated list of classnames
*/
classes: function() { return this.classlist.join(' '); }
};
riot.mixin('classlister', mixin);
})(riot);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment