Created
May 19, 2014 11:22
-
-
Save dancourse/45ad644fe6d4cc55c209 to your computer and use it in GitHub Desktop.
DalekJS: Custom `hasClass` method
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
// _addNewFunc is just a function that adds this to the main DalekJS test at run-time | |
_addNewFunc("hasClass", function (__selector, __needle) | |
{ | |
// generate a random name for this element | |
var name = "hasClass-" + new Date().getTime(), | |
nameElem = "span#"+name; | |
return this.dse_self | |
.execute(function(__selector, __needle, __name) | |
{ | |
// create a new element to house the result | |
var newELEM = $('<span />').attr('id', __name).attr("data-has-class", "false"); | |
$("body").append(newELEM); | |
// use jquery to test if the class exists | |
if($(__selector).hasClass(__needle)) | |
{ | |
// it exists, change the value | |
$(newELEM).attr('data-has-class', 'true'); | |
} | |
}, __selector, __needle, name) | |
// test the elem if the data is true | |
.assert.attr(nameElem, 'data-has-class', 'true', __selector + " has the class, " + __needle) | |
// cleanup | |
.execute(function(__nameElem) | |
{ | |
$(__nameElem).remove(); | |
}, nameElem); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment