riot mixin for converting opts.class to a list.
This file contains 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