2009-11-26 04:08:55 +01:00
|
|
|
function testData(index) {
|
2010-03-11 03:29:18 +01:00
|
|
|
var data = jQuery.metadata.get(this);
|
|
|
|
switch(index) {
|
|
|
|
case 0:
|
|
|
|
ok( data.foo == "bar", "Check foo property" );
|
|
|
|
ok( data.bar == "baz", "Check baz property" );
|
|
|
|
ok( data.arr[0] == 1, "Check arr[0] property" );
|
|
|
|
ok( data.arr[1] == 2, "Check arr[1] property" );
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
ok( data.test == "bar", "Check test property" );
|
|
|
|
ok( data.bar == "baz", "Check bar property" );
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
ok( data.zoooo == "bar", "Check zoooo property" );
|
|
|
|
ok( data.bar.test == "baz", "Check bar.test property" );
|
|
|
|
break;
|
|
|
|
case 3:
|
|
|
|
ok( data.number, "Check number property" );
|
|
|
|
ok( data.stuff[0] == 2, "Check stuff[0] property" );
|
|
|
|
ok( data.stuff[1] == 8, "Check stuff[1] property" );
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
ok( false, ["Assertion failed on index ", index, ", with data ", data].join('') );
|
|
|
|
}
|
2009-11-26 04:08:55 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// check if set can be intercepted without breaking metadata plugin
|
|
|
|
var oldSet = jQuery.fn.set;
|
|
|
|
jQuery.fn.set = function() {
|
2010-03-11 03:29:18 +01:00
|
|
|
ok( true, "set was interecepted" );
|
|
|
|
oldSet.apply(this, arguments);
|
2009-11-26 04:08:55 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
//jQuery.meta.single = "";
|
|
|
|
|
|
|
|
test("meta: type attr - from data attribute", function() {
|
2010-03-11 03:29:18 +01:00
|
|
|
expect(11);
|
|
|
|
jQuery.metadata.setType("attr", "data");
|
|
|
|
jQuery("#one li").each(testData);
|
2009-11-26 04:08:55 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
test("meta: type class - from className", function() {
|
2010-03-11 03:29:18 +01:00
|
|
|
expect(11);
|
|
|
|
jQuery.metadata.setType( "class" );
|
|
|
|
jQuery("#two li").each(testData);
|
2009-11-26 04:08:55 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
test("meta: children script element - get data from child script element", function() {
|
2010-03-11 03:29:18 +01:00
|
|
|
expect(11);
|
|
|
|
jQuery.metadata.setType( "elem", "script" );
|
|
|
|
jQuery("#three li").each(testData);
|
2009-11-26 04:08:55 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
test("check if window doesn't break anything", function() {
|
2010-03-11 03:29:18 +01:00
|
|
|
jQuery(window).get();
|
2009-11-26 04:08:55 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
test("meta: default with single data object", function() {
|
2010-03-11 03:29:18 +01:00
|
|
|
expect(11);
|
|
|
|
jQuery.metadata.setType("attr","data");
|
|
|
|
jQuery.metadata.defaults.single = "data";
|
|
|
|
jQuery("#four li").each(testData);
|
2009-11-26 04:08:55 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
test("meta with select and class", function() {
|
2010-03-11 03:29:18 +01:00
|
|
|
expect(2);
|
|
|
|
jQuery.metadata.setType("class");
|
|
|
|
jQuery.metadata.single = "stuff";
|
|
|
|
var e = $('#meal').metadata();
|
|
|
|
ok( e, "data property" );
|
|
|
|
ok( e.required, "property on data property" );
|
2009-11-26 04:08:55 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
test("try to add and remove classes on metadata elements", function() {
|
2010-03-11 03:29:18 +01:00
|
|
|
$("#two li").addClass("foobar").addClass("foo bar").removeClass("foobar");
|
|
|
|
ok( $("#two li").is(".foo"), 'Check class foo was added.' );
|
|
|
|
ok( $("#two li").is(".bar"), 'Check class bar was added.' );
|
|
|
|
});
|
|
|
|
|
|
|
|
test("meta: type html5 - from data-*", function() {
|
|
|
|
expect(11);
|
|
|
|
jQuery.metadata.setType("html5");
|
|
|
|
jQuery("#five li").each(testData);
|
2009-11-26 04:08:55 +01:00
|
|
|
});
|