Skip to content

Commit

Permalink
$.classes helper function
Browse files Browse the repository at this point in the history
  • Loading branch information
Thomas-Gelf committed Mar 4, 2014
1 parent 0909744 commit 9531dbb
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions public/js/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,36 @@
}, Function.prototype.bind);
}
})(console);

/* Get class list */
(function ($) {

'use strict';

$.fn.classes = function (callback) {

var classes = [];

$.each(this, function (i, el) {
var c = $(el).attr('class');
if (typeof c === 'string') {
$.each(c.split(/\s+/), function(i, p) {
if (classes.indexOf(p) === -1) {
classes.push(p);
}
});
}
});

if (typeof callback === 'function') {
for (var i in classes) {
if (classes.hasOwnProperty(i)) {
callback(classes[i]);
}
}
}

return classes;
};

})(jQuery);

0 comments on commit 9531dbb

Please sign in to comment.