1
0
mirror of https://github.com/DataTables/DataTables.git synced 2025-01-18 11:52:11 +01:00

New: It is now possible to have elements created by sDom have an ID assigned to them as well as a class. An extension of the previous class only syntax you can now do something like "#id.class", "#id" or "class" - 2666

This commit is contained in:
Allan Jardine 2010-09-08 21:08:52 +01:00
parent 5ea6a59af6
commit a8ade0297b
2 changed files with 91 additions and 9 deletions

View File

@ -3255,7 +3255,7 @@
/* Loop over the user set positioning and place the elements as needed */
var aDom = oSettings.sDom.split('');
var nTmp, iPushFeature, cOption, nNewNode, cNext, sClass, j;
var nTmp, iPushFeature, cOption, nNewNode, cNext, sAttr, j;
for ( var i=0 ; i<aDom.length ; i++ )
{
iPushFeature = 0;
@ -3266,29 +3266,46 @@
/* New container div */
nNewNode = document.createElement( 'div' );
/* Check to see if we should append a class name to the container */
/* Check to see if we should append an id and/or a class name to the container */
cNext = aDom[i+1];
if ( cNext == "'" || cNext == '"' )
{
sClass = "";
sAttr = "";
j = 2;
while ( aDom[i+j] != cNext )
{
sClass += aDom[i+j];
sAttr += aDom[i+j];
j++;
}
/* Replace jQuery UI constants */
if ( sClass == "H" )
if ( sAttr == "H" )
{
sClass = "fg-toolbar ui-toolbar ui-widget-header ui-corner-tl ui-corner-tr ui-helper-clearfix";
sAttr = "fg-toolbar ui-toolbar ui-widget-header ui-corner-tl ui-corner-tr ui-helper-clearfix";
}
else if ( sClass == "F" )
else if ( sAttr == "F" )
{
sClass = "fg-toolbar ui-toolbar ui-widget-header ui-corner-bl ui-corner-br ui-helper-clearfix";
sAttr = "fg-toolbar ui-toolbar ui-widget-header ui-corner-bl ui-corner-br ui-helper-clearfix";
}
/* The attribute can be in the format of "#id.class", "#id" or "class" This logic
* breaks the string into parts and applies them as needed
*/
if ( sAttr.indexOf('.') != -1 )
{
var aSplit = sAttr.split('.');
nNewNode.setAttribute('id', aSplit[0].substr(1, aSplit[0].length-1) );
nNewNode.className = aSplit[1];
}
else if ( sAttr.charAt(0) == "#" )
{
nNewNode.setAttribute('id', sAttr.substr(1, sAttr.length-1) );
}
else
{
nNewNode.className = sAttr;
}
nNewNode.className = sClass;
i += j; /* Move along the position array */
}

View File

@ -249,6 +249,71 @@ $(document).ready( function () {
}
);
oTest.fnTest(
"Element with an id",
function () {
$('#example').dataTable( {
"bDestroy": true,
"sDom": '<"#test"lf>rti'
} );
},
function () {
return $('#test').length == 1;
}
);
oTest.fnTest(
"Element with an id and a class",
function () {
$('#example').dataTable( {
"bDestroy": true,
"sDom": '<"#test.classTest"lf>rti'
} );
},
function () {
return ($('#test').length == 1 && $('#test')[0].className == "classTest");
}
);
oTest.fnTest(
"Element with just a class",
function () {
$('#example').dataTable( {
"bDestroy": true,
"sDom": '<"classTest"lf>rti'
} );
},
function () {
return ($('div.classTest').length == 1 );
}
);
oTest.fnTest(
"Two elements with an id",
function () {
$('#example').dataTable( {
"bDestroy": true,
"sDom": '<"#test1"lf>rti<"#test2"lf>'
} );
},
function () {
return ($('#test1').length == 1 && $('#test2').length == 1);
}
);
oTest.fnTest(
"Two elements with an id and one with a class",
function () {
$('#example').dataTable( {
"bDestroy": true,
"sDom": '<"#test1"lf>rti<"#test2.classTest"lf>'
} );
},
function () {
return ($('#test1').length == 1 && $('#test2').length == 1 && $('div.classTest').length == 1);
}
);
oTest.fnComplete();
} );