From 735d8168628e3b18eab9f365b15214dd7dc93bad Mon Sep 17 00:00:00 2001 From: Paul Adamson Date: Fri, 4 Nov 2022 08:27:44 -0400 Subject: [PATCH 1/3] support jQuery >= 3.0 --- data-tree.js | 70 +++++++++++++++++++++++++++++++++++----------------- 1 file changed, 48 insertions(+), 22 deletions(-) diff --git a/data-tree.js b/data-tree.js index 12e0994..e714226 100644 --- a/data-tree.js +++ b/data-tree.js @@ -292,28 +292,54 @@ DataTree = function(params, subTreeRequest) { //...get data... let dataType = !params.jsonp ? (!params.json || typeof params.json == 'object' ? 'xml' : 'json') : 'jsonp'; - $.ajax({ - url: params.fpath, - type: !params.post ? 'GET' : 'POST', - data: params.req_data, - cache: params.cache == undefined ? true : params.cache, - dataType: dataType - }) - .error(function() { debug('could not load XML from '+params.fpath); }) - - //...success. Establish XML. If params.json, convert JSON respone to XML text then reinitialise - .done(function(data) { - if (params.json && typeof params.json != 'object') { - if (params.jsonCallback) data = params.jsonCallback(data); - delete params.fpath; - params.xml = json_to_xml(data); - return new DataTree(params, subTreeRequest); - } - if (params.jsonp) data = decodeURIComponent(data).replace(/\{space\}/g, ' '); - thiss.xml = data; - actOnXML.call(thiss, data, !!subTreeRequest); - treeRenderedDfd.resolve(); - }); + var jquery_ver = parseInt($.fn.jquery.split('.')[0]) + if (jquery_ver >= 3) { + $.ajax({ + url: params.fpath, + type: !params.post ? 'GET' : 'POST', + data: params.req_data, + cache: params.cache == undefined ? true : params.cache, + dataType: dataType + }) + .fail(function() { debug('could not load XML from '+params.fpath); }) + + //...success. Establish XML. If params.json, convert JSON respone to XML text then reinitialise + .done(function(data) { + if (params.json && typeof params.json != 'object') { + if (params.jsonCallback) data = params.jsonCallback(data); + delete params.fpath; + params.xml = json_to_xml(data); + return new DataTree(params, subTreeRequest); + } + if (params.jsonp) data = decodeURIComponent(data).replace(/\{space\}/g, ' '); + thiss.xml = data; + actOnXML.call(thiss, data, !!subTreeRequest); + treeRenderedDfd.resolve(); + }); + } else { + $.ajax({ + url: params.fpath, + type: !params.post ? 'GET' : 'POST', + data: params.req_data, + cache: params.cache == undefined ? true : params.cache, + dataType: dataType + }) + .error(function() { debug('could not load XML from '+params.fpath); }) + + //...success. Establish XML. If params.json, convert JSON respone to XML text then reinitialise + .done(function(data) { + if (params.json && typeof params.json != 'object') { + if (params.jsonCallback) data = params.jsonCallback(data); + delete params.fpath; + params.xml = json_to_xml(data); + return new DataTree(params, subTreeRequest); + } + if (params.jsonp) data = decodeURIComponent(data).replace(/\{space\}/g, ' '); + thiss.xml = data; + actOnXML.call(thiss, data, !!subTreeRequest); + treeRenderedDfd.resolve(); + }); + } //from passed string (XML) } else if (typeof params.xml == 'string') { From 8f1bf2e10bd17680fd68fbeb842c0646b39f8b25 Mon Sep 17 00:00:00 2001 From: Paul Adamson Date: Fri, 4 Nov 2022 11:01:55 -0400 Subject: [PATCH 2/3] more fixes for jquery 3 --- data-tree.js | 51 +++++++++++++++++++++++++++++++++++++-------------- 1 file changed, 37 insertions(+), 14 deletions(-) diff --git a/data-tree.js b/data-tree.js index e714226..37feb7c 100644 --- a/data-tree.js +++ b/data-tree.js @@ -6,10 +6,13 @@ DataTree = function(params, subTreeRequest) { + /* --- | PREP & VALIDATION --- */ + const jquery_ver = parseInt($.fn.jquery.split('.')[0]) + const thiss = this, treeRenderedDfd = new $.Deferred; @@ -268,15 +271,23 @@ DataTree = function(params, subTreeRequest) { for(let y in paths) { let parts = paths[y].split(','); let selStr = []; - for(let i in parts) selStr.push('li:eq('+parts[i]+') > ul'); - this.tree.find(selStr.join(' > ')).parents('ul').andSelf().show().each(function() { - $(this).parent().children('.plusMin').html('-'); - }); + for(let i in parts) selStr.push('li:eq('+parts[i]+') > ul'); { + if (jquery_ver >= 3) { + this.tree.find(selStr.join(' > ')).parents('ul').addBack().show().each(function() { + $(this).parent().children('.plusMin').html('-'); + }); + } else { + this.tree.find(selStr.join(' > ')).parents('ul').andSelf().show().each(function() { + $(this).parent().children('.plusMin').html('-'); + }); + }; + } } //...stipulated in params - } else + } else { this.tree.find('.currSel').parentsUntil('.xmltree').children('.plusMin').trigger('click'); + } } @@ -292,7 +303,6 @@ DataTree = function(params, subTreeRequest) { //...get data... let dataType = !params.jsonp ? (!params.json || typeof params.json == 'object' ? 'xml' : 'json') : 'jsonp'; - var jquery_ver = parseInt($.fn.jquery.split('.')[0]) if (jquery_ver >= 3) { $.ajax({ url: params.fpath, @@ -377,7 +387,11 @@ DataTree = function(params, subTreeRequest) { let el = this.tree.find(selector).filter('li'); if (!el.length) return debug('jumpTo() - no branch (
  • ) found matching selector', selector); if (el.children('.plusMin').is('.collapsed')) - el.parentsUntil('.xmltree').andSelf().children('.plusMin.collapsed').trigger('click'); + if (jquery_ver >= 3) { + el.parentsUntil('.xmltree').addBack().children('.plusMin.collapsed').trigger('click'); + } else { + el.parentsUntil('.xmltree').andSelf().children('.plusMin.collapsed').trigger('click'); + } }); } @@ -432,13 +446,22 @@ DataTree = function(params, subTreeRequest) { //XPath - return XPath of clicked node function returnXPathToNode(nodeEl) { let path = []; - nodeEl.parents('li').andSelf().each(function() { - let nodeName = $(this).children('.LIText').children('.node').text(); - let step = nodeName; - let index = $(this).prevAll().filter(function() { return $(this).children('.LIText').children('.node').text() == nodeName; }).length + 1; - if (index > 1) step += '['+index+']' - path.push(step); - }); + if (jquery_ver >= 3){ + nodeEl.parents('li').addBack().each(function() { + let nodeName = $(this).children('.LIText').children('.node').text(); + let step = nodeName; + let index = $(this).prevAll().filter(function() { return $(this).children('.LIText').children('.node').text() == nodeName; }).length + 1; + if (index > 1) step += '['+index+']' + path.push(step); + }); + } else { + nodeEl.parents('li').andSelf().each(function() { + let nodeName = $(this).children('.LIText').children('.node').text(); + let step = nodeName; + let index = $(this).prevAll().filter(function() { return $(this).children('.LIText').children('.node').text() == nodeName; }).length + 1; + if (index > 1) step += '['+index+']' + path.push(step); + } return path.join('/'); } From eb6520cf2dbbe7840c770e8b4815a973913da058 Mon Sep 17 00:00:00 2001 From: Paul Adamson Date: Fri, 4 Nov 2022 11:04:15 -0400 Subject: [PATCH 3/3] fix typo --- data-tree.js | 1 + 1 file changed, 1 insertion(+) diff --git a/data-tree.js b/data-tree.js index 37feb7c..dc66da8 100644 --- a/data-tree.js +++ b/data-tree.js @@ -461,6 +461,7 @@ DataTree = function(params, subTreeRequest) { let index = $(this).prevAll().filter(function() { return $(this).children('.LIText').children('.node').text() == nodeName; }).length + 1; if (index > 1) step += '['+index+']' path.push(step); + }); } return path.join('/'); }