From b034e9900d4d4ba9a80288802ac4642dbe9124f7 Mon Sep 17 00:00:00 2001 From: Jonathon Smith Date: Fri, 6 Apr 2012 01:25:24 +0100 Subject: [PATCH] Changed node find method from data- attributes to jquery data() This maintains validation on pre-HTML5 documents --- example/jquery.jOrgChart.js | 29 ++++++++++++++++------------- jquery.jOrgChart.js | 29 ++++++++++++++++------------- 2 files changed, 32 insertions(+), 26 deletions(-) diff --git a/example/jquery.jOrgChart.js b/example/jquery.jOrgChart.js index b2a3027..627309c 100644 --- a/example/jquery.jOrgChart.js +++ b/example/jquery.jOrgChart.js @@ -69,22 +69,25 @@ // Drop event handler for nodes $('div.node').bind("drop", function handleDropEvent( event, ui ) { - var targetLi = $this.find("[data-tree-node=" + $(this).data("tree-node") + "]"); - var sourceLi = $this.find("[data-tree-node=" + ui.draggable.data("tree-node") + "]"); + var targetID = $(this).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 targetUl = targetLi.children('ul'); - if (targetUl.length > 0){ - targetUl.append(sourceLi); + if (targetUl.length > 0){ + targetUl.append(sourceLi); } else { - targetLi.append(""); - targetLi.children('ul').append(sourceLi); + targetLi.append(""); + targetLi.children('ul').append(sourceLi); } - //Removes any empty lists - if (sourceUl.children().length === 0){ - sourceUl.remove(); - } + //Removes any empty lists + if (sourceUl.children().length === 0){ + sourceUl.remove(); + } }); // handleDropEvent @@ -124,9 +127,9 @@ //Increaments the node count which is used to link the source list and the org chart nodeCount++; - $node.attr("data-tree-node", nodeCount); + $node.data("tree-node", nodeCount); $nodeDiv = $("
").addClass("node") - .attr("data-tree-node", nodeCount) + .data("tree-node", nodeCount) .append($nodeContent); // Expand and contract nodes diff --git a/jquery.jOrgChart.js b/jquery.jOrgChart.js index b2a3027..627309c 100644 --- a/jquery.jOrgChart.js +++ b/jquery.jOrgChart.js @@ -69,22 +69,25 @@ // Drop event handler for nodes $('div.node').bind("drop", function handleDropEvent( event, ui ) { - var targetLi = $this.find("[data-tree-node=" + $(this).data("tree-node") + "]"); - var sourceLi = $this.find("[data-tree-node=" + ui.draggable.data("tree-node") + "]"); + var targetID = $(this).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 targetUl = targetLi.children('ul'); - if (targetUl.length > 0){ - targetUl.append(sourceLi); + if (targetUl.length > 0){ + targetUl.append(sourceLi); } else { - targetLi.append(""); - targetLi.children('ul').append(sourceLi); + targetLi.append(""); + targetLi.children('ul').append(sourceLi); } - //Removes any empty lists - if (sourceUl.children().length === 0){ - sourceUl.remove(); - } + //Removes any empty lists + if (sourceUl.children().length === 0){ + sourceUl.remove(); + } }); // handleDropEvent @@ -124,9 +127,9 @@ //Increaments the node count which is used to link the source list and the org chart nodeCount++; - $node.attr("data-tree-node", nodeCount); + $node.data("tree-node", nodeCount); $nodeDiv = $("
").addClass("node") - .attr("data-tree-node", nodeCount) + .data("tree-node", nodeCount) .append($nodeContent); // Expand and contract nodes