aboutsummaryrefslogtreecommitdiffstats
path: root/src/modules/optional/class.js
diff options
context:
space:
mode:
Diffstat (limited to 'src/modules/optional/class.js')
-rw-r--r--src/modules/optional/class.js48
1 files changed, 16 insertions, 32 deletions
diff --git a/src/modules/optional/class.js b/src/modules/optional/class.js
index 93ccd0e..b08c82b 100644
--- a/src/modules/optional/class.js
+++ b/src/modules/optional/class.js
@@ -3,58 +3,42 @@ import { registerMethods } from '../../utils/methods.js'
// Return array of classes on the node
export function classes () {
-
- var attr = this.attr( 'class' )
- return attr == null ? [] : attr.trim().split( delimiter )
-
+ var attr = this.attr('class')
+ return attr == null ? [] : attr.trim().split(delimiter)
}
// Return true if class exists on the node, false otherwise
-export function hasClass ( name ) {
-
- return this.classes().indexOf( name ) !== -1
-
+export function hasClass (name) {
+ return this.classes().indexOf(name) !== -1
}
// Add class to the node
-export function addClass ( name ) {
-
- if ( !this.hasClass( name ) ) {
-
+export function addClass (name) {
+ if (!this.hasClass(name)) {
var array = this.classes()
- array.push( name )
- this.attr( 'class', array.join( ' ' ) )
-
+ array.push(name)
+ this.attr('class', array.join(' '))
}
return this
-
}
// Remove class from the node
-export function removeClass ( name ) {
-
- if ( this.hasClass( name ) ) {
-
- this.attr( 'class', this.classes().filter( function ( c ) {
-
+export function removeClass (name) {
+ if (this.hasClass(name)) {
+ this.attr('class', this.classes().filter(function (c) {
return c !== name
-
- } ).join( ' ' ) )
-
+ }).join(' '))
}
return this
-
}
// Toggle the presence of a class on the node
-export function toggleClass ( name ) {
-
- return this.hasClass( name ) ? this.removeClass( name ) : this.addClass( name )
-
+export function toggleClass (name) {
+ return this.hasClass(name) ? this.removeClass(name) : this.addClass(name)
}
-registerMethods( 'Dom', {
+registerMethods('Dom', {
classes, hasClass, addClass, removeClass, toggleClass
-} )
+})