From d4abeb91f9397d3fbb8ff63b2095f59f4fa79022 Mon Sep 17 00:00:00 2001 From: Michael Klement Date: Mon, 2 May 2016 17:46:24 -0400 Subject: [PATCH 1/2] Added option "noDivWrapper" to suppress wrapping instantiated templates in
elements. --- dist/jquery.loadTemplate-1.5.7.js | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/dist/jquery.loadTemplate-1.5.7.js b/dist/jquery.loadTemplate-1.5.7.js index 7f6df6e..d9efaad 100644 --- a/dist/jquery.loadTemplate-1.5.7.js +++ b/dist/jquery.loadTemplate-1.5.7.js @@ -28,6 +28,7 @@ paged: false, pageNo: 1, elemPerPage: 10, + noDivWrapper: false, append: false, prepend: false, beforeInsert: null, @@ -140,10 +141,12 @@ $that.html(""); } + if (settings.noDivWrapper) { newOptions.append = true; } + if (doPrepend) data.reverse(); $(data).each(function () { var $div = $("
"); - loadTemplate.call($div, template, this, newOptions); + loadTemplate.call(settings.noDivWrapper ? $that : $div, template, this, newOptions); if (errored) { return false; } @@ -156,7 +159,7 @@ if (queue[template]) { queue[template].push({ data: data, selection: selection, settings: settings }); } else { - queue[template] = [{ data: data, selection: selection, settings: settings}]; + queue[template] = [{ data: data, selection: selection, settings: settings }]; } } @@ -194,7 +197,7 @@ url: templateUrl, async: settings.async, success: function (templateContent) { - $templateContainer.html(templateContent); + $templateContainer = settings.noDivWrapper ? $(templateContent) : $templateContainer.html(templateContent); handleTemplateLoadingSuccess($templateContainer, template, selection, data, settings); }, error: function (e) { @@ -207,10 +210,10 @@ var $templateContainer = $("
"); if ($template.is("script") || $template.is("template")) { - $template = $.parseHTML($.trim($template.html())); + $template = $($.parseHTML($.trim($template.html()))); } - $templateContainer.html($template); + $templateContainer = settings.noDivWrapper ? $template : $templateContainer.html($template); prepareTemplate.call(selection, $templateContainer, data, settings); if (typeof settings.success === "function") { From 5ad2402ad037d65f82b9b33956f2d2ee3c26ccf4 Mon Sep 17 00:00:00 2001 From: Michael Klement Date: Tue, 3 May 2016 19:00:03 -0400 Subject: [PATCH 2/2] Fixed bug where the enclosing element of a template was not itself processed with setting noDivWrappers on. --- dist/jquery.loadTemplate-1.5.7.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dist/jquery.loadTemplate-1.5.7.js b/dist/jquery.loadTemplate-1.5.7.js index d9efaad..b6333ba 100644 --- a/dist/jquery.loadTemplate-1.5.7.js +++ b/dist/jquery.loadTemplate-1.5.7.js @@ -222,7 +222,7 @@ } function prepareTemplate(template, data, settings) { - bindData(template, data, settings); + bindData(settings.noDivWrapper ? $('
').append(template) : template, data, settings); $(this).each(function () { var $templateHtml = template.clone(true);