(function($,_){var Attributes=function(attributes){this.data={};this.data['class']=[];this.merge(attributes);};Attributes.prototype.toString=function(){var output='';var name,value;var checkPlain=function(str){return str&&str.toString().replace(/&/g,'&').replace(/"/g,'"').replace(//g,'>')||'';};var data=this.getData();for(name in data){if(!data.hasOwnProperty(name))continue;value=data[name];if(_.isFunction(value))value=value();if(_.isObject(value))value=_.values(value);if(_.isArray(value))value=value.join(' ');output+=' '+checkPlain(name)+'="'+checkPlain(value)+'"';} return output;};Attributes.prototype.toPlainObject=function(){var object={};var name,value;var data=this.getData();for(name in data){if(!data.hasOwnProperty(name))continue;value=data[name];if(_.isFunction(value))value=value();if(_.isObject(value))value=_.values(value);if(_.isArray(value))value=value.join(' ');object[name]=value;} return object;};Attributes.prototype.addClass=function(value){var args=Array.prototype.slice.call(arguments);this.data['class']=this.sanitizeClasses(this.data['class'].concat(args));return this;};Attributes.prototype.exists=function(name){return this.data[name]!==void(0)&&this.data[name]!==null;};Attributes.prototype.get=function(name,defaultValue){if(!this.exists(name))this.data[name]=defaultValue;return this.data[name];};Attributes.prototype.getData=function(){return _.extend({},this.data);};Attributes.prototype.getClasses=function(){return this.get('class',[]);};Attributes.prototype.hasClass=function(className){className=this.sanitizeClasses(Array.prototype.slice.call(arguments));var classes=this.getClasses();for(var i=0,l=className.length;i=0){classes[i]=newValue;this.set('class',classes);} return this;};Attributes.prototype.sanitizeClasses=function(classes){return _.chain(Array.prototype.slice.call(arguments)).flatten().map(function(string){return string.split(' ');}).flatten().filter().map(function(value){return Attributes.cleanClass(value);}).uniq().value();};Attributes.prototype.set=function(name,value){var obj=$.isPlainObject(name)?name:{};if(typeof name==='string'){obj[name]=value;} return this.merge(obj);};Attributes.cleanClass=function(identifier,filter){filter=filter||{' ':'-','_':'-','/':'-','[':'-',']':''};identifier=identifier.toLowerCase();if(filter['__']===void 0){identifier=identifier.replace('__','#DOUBLE_UNDERSCORE#');} identifier=identifier.replace(Object.keys(filter),Object.keys(filter).map(function(key){return filter[key];}));if(filter['__']===void 0){identifier=identifier.replace('#DOUBLE_UNDERSCORE#','__');} identifier=identifier.replace(/[^\u002D\u0030-\u0039\u0041-\u005A\u005F\u0061-\u007A\u00A1-\uFFFF]/g,'');identifier=identifier.replace(['/^[0-9]/','/^(-[0-9])|^(--)/'],['_','__']);return identifier;};Attributes.create=function(attributes){return new Attributes(attributes);};window.Attributes=Attributes;})(window.jQuery,window._);