app/assets/javascripts/iqvoc/label_resolver.js in iqvoc-4.12.1 vs app/assets/javascripts/iqvoc/label_resolver.js in iqvoc-4.13.0

- old
+ new

@@ -1,32 +1,37 @@ -IQVOC.labelResolver = (function($) { +(function($) { -"use strict"; + "use strict"; -return function(context) { - $("a.unlabeled", context).each(processNode); -}; + function retrieveLabel(conceptURL, el, callback) { + var datasets = $("body").data("datasets"); + var proxy = $("body").data("remote-label-path"); + var matchedDatasets = Object.keys(datasets).filter(function(datasetURL) { + return conceptURL.indexOf(datasetURL, 0) === 0; + }); -function retrieveLabel(conceptURL, el, callback) { - var datasets = $("body").data("datasets"); - var proxy = $("body").data("remote-label-path"); - var matchedDatasets = Object.keys(datasets).filter(function(datasetURL) { - return conceptURL.indexOf(datasetURL, 0) === 0; - }); + if (matchedDatasets.length === 0) { + return false; + } - if (matchedDatasets.length === 0) { - return false; - } + $.get(proxy, { concept_url: conceptURL }, function(data, status, xhr) { + el.text(data.label); + el.removeClass("unlabeled"); + }); + } - $.get(proxy, { concept_url: conceptURL }, function(data, status, xhr) { - el.text(data.label); - el.removeClass("unlabeled"); - }); -} + function processNode(i, node) { + var el = $(node); + var uri = el.attr("href"); + retrieveLabel(uri, el); + } -function processNode(i, node) { - var el = $(node); - var uri = el.attr("href"); - retrieveLabel(uri, el); -} + $(function() { + $("a.unlabeled").each(processNode); + + // initialise new dynamically added links + $(document.body).on("concept-label", function(ev, container) { + $("a.unlabeled", container).each(processNode); + }); + }); }(jQuery));