Changed node find method from data- attributes to jquery data()

This maintains validation on pre-HTML5 documents
master
Jonathon Smith 2012-04-06 01:25:24 +01:00
parent f1432f80d2
commit b034e9900d
2 changed files with 32 additions and 26 deletions

View File

@ -69,11 +69,14 @@
// Drop event handler for nodes // Drop event handler for nodes
$('div.node').bind("drop", function handleDropEvent( event, ui ) { $('div.node').bind("drop", function handleDropEvent( event, ui ) {
var targetLi = $this.find("[data-tree-node=" + $(this).data("tree-node") + "]"); var targetID = $(this).data("tree-node");
var sourceLi = $this.find("[data-tree-node=" + ui.draggable.data("tree-node") + "]"); var targetLi = $this.find("li").filter(function() { return $(this).data("tree-node") === targetID; } );
var targetUl = targetLi.children('ul');
var sourceID = ui.draggable.data("tree-node");
var sourceLi = $this.find("li").filter(function() { return $(this).data("tree-node") === sourceID; } );
var sourceUl = sourceLi.parent('ul'); var sourceUl = sourceLi.parent('ul');
var targetUl = targetLi.children('ul');
if (targetUl.length > 0){ if (targetUl.length > 0){
targetUl.append(sourceLi); targetUl.append(sourceLi);
} else { } else {
@ -124,9 +127,9 @@
//Increaments the node count which is used to link the source list and the org chart //Increaments the node count which is used to link the source list and the org chart
nodeCount++; nodeCount++;
$node.attr("data-tree-node", nodeCount); $node.data("tree-node", nodeCount);
$nodeDiv = $("<div>").addClass("node") $nodeDiv = $("<div>").addClass("node")
.attr("data-tree-node", nodeCount) .data("tree-node", nodeCount)
.append($nodeContent); .append($nodeContent);
// Expand and contract nodes // Expand and contract nodes

View File

@ -69,11 +69,14 @@
// Drop event handler for nodes // Drop event handler for nodes
$('div.node').bind("drop", function handleDropEvent( event, ui ) { $('div.node').bind("drop", function handleDropEvent( event, ui ) {
var targetLi = $this.find("[data-tree-node=" + $(this).data("tree-node") + "]"); var targetID = $(this).data("tree-node");
var sourceLi = $this.find("[data-tree-node=" + ui.draggable.data("tree-node") + "]"); var targetLi = $this.find("li").filter(function() { return $(this).data("tree-node") === targetID; } );
var targetUl = targetLi.children('ul');
var sourceID = ui.draggable.data("tree-node");
var sourceLi = $this.find("li").filter(function() { return $(this).data("tree-node") === sourceID; } );
var sourceUl = sourceLi.parent('ul'); var sourceUl = sourceLi.parent('ul');
var targetUl = targetLi.children('ul');
if (targetUl.length > 0){ if (targetUl.length > 0){
targetUl.append(sourceLi); targetUl.append(sourceLi);
} else { } else {
@ -124,9 +127,9 @@
//Increaments the node count which is used to link the source list and the org chart //Increaments the node count which is used to link the source list and the org chart
nodeCount++; nodeCount++;
$node.attr("data-tree-node", nodeCount); $node.data("tree-node", nodeCount);
$nodeDiv = $("<div>").addClass("node") $nodeDiv = $("<div>").addClass("node")
.attr("data-tree-node", nodeCount) .data("tree-node", nodeCount)
.append($nodeContent); .append($nodeContent);
// Expand and contract nodes // Expand and contract nodes