Last active
March 3, 2017 18:24
-
-
Save adrian-enspired/4f40311499798224577644a17cd3c27f to your computer and use it in GitHub Desktop.
riot mixin for converting opts.class to a list.
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
(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