diff --git a/jquery-loadTemplate/jquery.loadTemplate-1.0.0.min.js b/jquery-loadTemplate/jquery.loadTemplate-1.0.0.min.js
deleted file mode 100644
index 25c294a..0000000
--- a/jquery-loadTemplate/jquery.loadTemplate-1.0.0.min.js
+++ /dev/null
@@ -1 +0,0 @@
-(function (e) { "use strict"; function i(n, r, i) { var s = this, h, p, d; r = r || {}; p = e.extend({ overwriteCache: false, complete: null, success: null, error: function () { e(this).each(function () { e(this).html(p.errorMessage) }) }, errorMessage: "There was an error loading the template.", paged: false, pageNo: 1, elemPerPage: 10, append: false }, i); if (e.type(r) === "array") { return u.call(this, n, r, p) } if (!o(n)) { h = e(n) } d = p.isFile || typeof p.isFile === "undefined" && (typeof h === "undefined" || h.length === 0); if (d && !p.overwriteCache && t[n]) { f(n, s, r, p) } else if (d && !p.overwriteCache && t.hasOwnProperty(n)) { a(n, s, r, p) } else if (d) { l(n, s, r, p) } else { c(h, s, r, p) } return this } function s(t, n) { if (n) { r[t] = n } else { r = e.extend(r, t) } } function o(e) { return typeof e === "string" && e.indexOf("/") > -1 } function u(t, n, r) { var s = this, o = n.length, u = 0, a; r = r || {}; if (r.paged) { var f = (r.pageNo - 1) * r.elemPerPage; n = n.slice(f, f + r.elemPerPage) } a = e.extend({}, r, { complete: function () { s.append(this.html()); u++; if (u === o) { if (r && typeof r.complete === "function") { r.complete() } } } }); if (!r.append) { s.html("") } e(n).each(function () { var n = e(""); i.call(n, t, this, a) }); return this } function a(e, t, r, i) { if (n[e]) { n[e].push({ data: r, selection: t, settings: i }) } else { n[e] = [{ data: r, selection: t, settings: i }] } } function f(e, n, r, i) { var s = t[e].clone(); h.call(n, s, r, i); if (typeof i.success === "function") { i.success() } } function l(n, r, i, s) { var o = e(""); t[n] = null; o.load(n, function (e, t) { if (t === "error") { p(n, r, i, s) } else { d(o, n, r, i, s) } }) } function c(t, n, r, i) { var s = e(""); if (t.is("script")) { t = e.parseHTML(e.trim(t.html())) } s.html(t); h.call(n, s, r, i); if (typeof i.success === "function") { i.success() } } function h(t, n, r) { v(t, n); e(this).each(function () { if (r.append) { e(this).append(t.html()) } else { e(this).html(t.html()) } }); if (typeof r.complete === "function") { r.complete.call(e(this)) } } function p(t, r, i, s) { var o; if (typeof s.error === "function") { s.error.call(r) } e(n[t]).each(function (e, t) { if (typeof t.settings.error === "function") { t.settings.error.call(t.selection) } }); if (typeof s.complete === "function") { s.complete.call(r) } while (n[t] && (o = n[t].shift())) { if (typeof o.settings.complete === "function") { o.settings.complete.call(o.selection) } } if (typeof n[t] !== "undefined" && n[t].length > 0) { n[t] = [] } } function d(e, r, i, s, o) { var u; t[r] = e.clone(); h.call(i, e, s, o); if (typeof o.success === "function") { o.success.call(i) } while (n[r] && (u = n[r].shift())) { h.call(u.selection, t[r].clone(), u.data, u.settings); if (typeof u.settings.success === "function") { u.settings.success.call(u.selection) } } } function v(t, n) { n = n || {}; m("data-content", t, n, function (e, t) { e.html(w(e, t, "content")) }); m("data-content-append", t, n, function (e, t) { e.append(w(e, t, "content")) }); m("data-content-prepend", t, n, function (e, t) { e.prepend(w(e, t, "content")) }); m("data-src", t, n, function (e, t) { e.attr("src", w(e, t, "src")) }, function (e) { e.remove() }); m("data-alt", t, n, function (e, t) { e.attr("alt", w(e, t, "alt")) }); m("data-value", t, n, function (e, t) { e.val(w(e, t, "value")) }); m("data-link", t, n, function (t, n) { var r = e(""); r.attr("href", w(t, n, "link")); r.html(t.html()); t.html(r) }); m("data-link-wrap", t, n, function (t, n) { var r = e(""); r.attr("href", w(t, n, "link-wrap")); t.wrap(r) }); m("data-options", t, n, function (t, n) { e(n).each(function () { var n = e(""); n.attr("value", this).text(this).appendTo(t) }) }); g(t, n) } function m(t, n, r, i, s) { e("[" + t + "]", n).each(function () { var n = e(this), o = n.attr(t), u = b(r, o); n.removeAttr(t); if (u && i) { i(n, u) } else if (s) { s(n) } }); return } function g(t, n) { e("[data-template-bind]", t).each(function () { var t = e(this), r = e.parseJSON(t.attr("data-template-bind")); t.removeAttr("data-template-bind"); e(r).each(function () { var r; if (typeof this.value === "object") { r = b(n, this.value.data) } else { r = b(n, this.value) } if (typeof r !== "undefined" && this.attribute) { switch (this.attribute) { case "content": t.html(y(r, this)); break; case "contentAppend": t.append(y(r, this)); break; case "contentPrepend": t.prepend(y(r, this)); break; case "options": var i = this; e(r).each(function () { var n = e(""); n.attr("value", this[i.value.value]).text(y(this[i.value.content], i)).appendTo(t) }); break; default: t.attr(this.attribute, y(r, this)) } } }) }) } function y(e, t) { if (t.formatter && r[t.formatter]) { return r[t.formatter](e, t.formatOptions) } return e } function b(e, t) { var n = t.split("."), r, i = e; while ((r = n.shift()) && typeof i !== "undefined") { i = i[r] } return i } function w(e, t, n) { var i = e.attr("data-format-target"), s; if (i === n || !i && n === "content") { s = e.attr("data-format"); if (s && typeof r[s] === "function") { var o = e.attr("data-format-options"); return r[s](t, o) } } return t } var t = {}, n = {}, r = {}; e.fn.loadTemplate = i; e.addTemplateFormatter = s })(jQuery)
\ No newline at end of file
diff --git a/jquery-loadTemplate/jquery.loadTemplate-1.0.0.js b/jquery-loadTemplate/jquery.loadTemplate-1.1.0.js
similarity index 98%
rename from jquery-loadTemplate/jquery.loadTemplate-1.0.0.js
rename to jquery-loadTemplate/jquery.loadTemplate-1.1.0.js
index 258e0e4..6dc5601 100644
--- a/jquery-loadTemplate/jquery.loadTemplate-1.0.0.js
+++ b/jquery-loadTemplate/jquery.loadTemplate-1.1.0.js
@@ -26,7 +26,8 @@
paged: false,
pageNo: 1,
elemPerPage: 10,
- append: false
+ append: false,
+ prepend: false
}, options);
if ($.type(data) === "array") {
@@ -92,7 +93,7 @@
}
);
- if (!settings.append) {
+ if (!settings.append && !settings.prepend) {
$that.html("");
}
@@ -155,6 +156,8 @@
$(this).each(function () {
if (settings.append) {
$(this).append(template.html());
+ } else if(settings.prepend) {
+ $(this).prepend(template.html());
} else {
$(this).html(template.html());
}
diff --git a/jquery-loadTemplate/jquery.loadTemplate-1.1.0.min.js b/jquery-loadTemplate/jquery.loadTemplate-1.1.0.min.js
new file mode 100644
index 0000000..f1cb183
--- /dev/null
+++ b/jquery-loadTemplate/jquery.loadTemplate-1.1.0.min.js
@@ -0,0 +1 @@
+(function(a){var u={},t={},h={};function m(B,x,z){var w=this,v,A,y;x=x||{};A=a.extend({overwriteCache:false,complete:null,success:null,error:function(){a(this).each(function(){a(this).html(A.errorMessage)})},errorMessage:"There was an error loading the template.",paged:false,pageNo:1,elemPerPage:10,append:false,prepend:false},z);if(a.type(x)==="array"){return r.call(this,B,x,A)}if(!g(B)){v=a(B)}y=A.isFile||(typeof A.isFile==="undefined"&&(typeof v==="undefined"||v.length===0));if(y&&!A.overwriteCache&&u[B]){p(B,w,x,A)}else{if(y&&!A.overwriteCache&&u.hasOwnProperty(B)){c(B,w,x,A)}else{if(y){l(B,w,x,A)}else{n(v,w,x,A)}}}return this}function b(w,v){if(v){h[w]=v}else{h=a.extend(h,w)}}function g(v){return typeof v==="string"&&v.indexOf("/")>-1}function r(B,w,z){var v=this,C=w.length,x=0,y;z=z||{};if(z.paged){var A=(z.pageNo-1)*z.elemPerPage;w=w.slice(A,A+z.elemPerPage)}y=a.extend({},z,{complete:function(){v.append(this.html());x++;if(x===C){if(z&&typeof z.complete==="function"){z.complete()}}}});if(!z.append&&!z.prepend){v.html("")}a(w).each(function(){var D=a("");m.call(D,B,this,y)});return this}function c(y,w,v,x){if(t[y]){t[y].push({data:v,selection:w,settings:x})}else{t[y]=[{data:v,selection:w,settings:x}]}}function p(z,x,w,y){var v=u[z].clone();o.call(x,v,w,y);if(typeof y.success==="function"){y.success()}}function l(z,x,w,y){var v=a("");u[z]=null;v.load(z,function(A,B){if(B==="error"){j(z,x,w,y)}else{k(v,z,x,w,y)}})}function n(v,y,x,z){var w=a("");if(v.is("script")){v=a.parseHTML(a.trim(v.html()))}w.html(v);o.call(y,w,x,z);if(typeof z.success==="function"){z.success()}}function o(x,v,w){f(x,v);a(this).each(function(){if(w.append){a(this).append(x.html())}else{if(w.prepend){a(this).prepend(x.html())}else{a(this).html(x.html())}}});if(typeof w.complete==="function"){w.complete.call(a(this))}}function j(y,w,v,x){var z;if(typeof x.error==="function"){x.error.call(w)}a(t[y]).each(function(A,B){if(typeof B.settings.error==="function"){B.settings.error.call(B.selection)}});if(typeof x.complete==="function"){x.complete.call(w)}while(t[y]&&(z=t[y].shift())){if(typeof z.settings.complete==="function"){z.settings.complete.call(z.selection)}}if(typeof t[y]!=="undefined"&&t[y].length>0){t[y]=[]}}function k(v,z,x,w,y){var A;u[z]=v.clone();o.call(x,v,w,y);if(typeof y.success==="function"){y.success.call(x)}while(t[z]&&(A=t[z].shift())){o.call(A.selection,u[z].clone(),A.data,A.settings);if(typeof A.settings.success==="function"){A.settings.success.call(A.selection)}}}function f(w,v){v=v||{};s("data-content",w,v,function(x,y){x.html(e(x,y,"content"))});s("data-content-append",w,v,function(x,y){x.append(e(x,y,"content"))});s("data-content-prepend",w,v,function(x,y){x.prepend(e(x,y,"content"))});s("data-src",w,v,function(x,y){x.attr("src",e(x,y,"src"))},function(x){x.remove()});s("data-alt",w,v,function(x,y){x.attr("alt",e(x,y,"alt"))});s("data-value",w,v,function(x,y){x.val(e(x,y,"value"))});s("data-link",w,v,function(x,z){var y=a("");y.attr("href",e(x,z,"link"));y.html(x.html());x.html(y)});s("data-link-wrap",w,v,function(x,z){var y=a("");y.attr("href",e(x,z,"link-wrap"));x.wrap(y)});s("data-options",w,v,function(x,y){a(y).each(function(){var z=a("");z.attr("value",this).text(this).appendTo(x)})});q(w,v)}function s(v,z,w,x,y){a("["+v+"]",z).each(function(){var A=a(this),B=A.attr(v),C=i(w,B);A.removeAttr(v);if(C&&x){x(A,C)}else{if(y){y(A)}}});return}function q(w,v){a("[data-template-bind]",w).each(function(){var x=a(this),y=a.parseJSON(x.attr("data-template-bind"));x.removeAttr("data-template-bind");a(y).each(function(){var A;if(typeof(this.value)==="object"){A=i(v,this.value.data)}else{A=i(v,this.value)}if(typeof A!=="undefined"&&this.attribute){switch(this.attribute){case"content":x.html(d(A,this));break;case"contentAppend":x.append(d(A,this));break;case"contentPrepend":x.prepend(d(A,this));break;case"options":var z=this;a(A).each(function(){var B=a("");B.attr("value",this[z.value.value]).text(d(this[z.value.content],z)).appendTo(x)});break;default:x.attr(this.attribute,d(A,this))}}})})}function d(w,v){if(v.formatter&&h[v.formatter]){return h[v.formatter](w,v.formatOptions)}return w}function i(v,w){var x=w.split("."),y,z=v;while((y=x.shift())&&typeof z!=="undefined"){z=z[y]}return z}function e(v,A,w){var z=v.attr("data-format-target"),y;if(z===w||(!z&&w==="content")){y=v.attr("data-format");if(y&&typeof h[y]==="function"){var x=v.attr("data-format-options");return h[y](A,x)}}return A}a.fn.loadTemplate=m;a.addTemplateFormatter=b})(jQuery);
\ No newline at end of file
diff --git a/loadTemplate.jquery.json b/loadTemplate.jquery.json
index a9f614f..c8b0c0a 100644
--- a/loadTemplate.jquery.json
+++ b/loadTemplate.jquery.json
@@ -6,7 +6,7 @@
"templates",
"templating"
],
- "version": "1.0.0",
+ "version": "1.1.0",
"author": {
"name": "Paul Burgess and other contributors",
"url": "https://github.com/codepb/jquery-template"
From f19786a6213eb0bc407fa304c99370434a5413aa Mon Sep 17 00:00:00 2001
From: Paul Burgess
Date: Fri, 30 Aug 2013 14:40:23 +0100
Subject: [PATCH 02/71] Added callbacks before and after template insert
Added two options, beforeInsert and afterInsert, that are callback
functions that will be called before inserting the element into the DOM,
and after inserting the element into the DOM.
---
Examples/index.html | 2 +-
.../jquery.loadTemplate-1.1.0.min.js | 1 -
...-1.1.0.js => jquery.loadTemplate-1.2.0.js} | 20 ++++++++++++++-----
.../jquery.loadTemplate-1.2.0.min.js | 1 +
loadTemplate.jquery.json | 2 +-
readme.md | 4 ++++
6 files changed, 22 insertions(+), 8 deletions(-)
delete mode 100644 jquery-loadTemplate/jquery.loadTemplate-1.1.0.min.js
rename jquery-loadTemplate/{jquery.loadTemplate-1.1.0.js => jquery.loadTemplate-1.2.0.js} (95%)
create mode 100644 jquery-loadTemplate/jquery.loadTemplate-1.2.0.min.js
diff --git a/Examples/index.html b/Examples/index.html
index 3a6317c..e0994f7 100644
--- a/Examples/index.html
+++ b/Examples/index.html
@@ -10,7 +10,7 @@
-
+
diff --git a/jquery-loadTemplate/jquery.loadTemplate-1.1.0.min.js b/jquery-loadTemplate/jquery.loadTemplate-1.1.0.min.js
deleted file mode 100644
index f1cb183..0000000
--- a/jquery-loadTemplate/jquery.loadTemplate-1.1.0.min.js
+++ /dev/null
@@ -1 +0,0 @@
-(function(a){var u={},t={},h={};function m(B,x,z){var w=this,v,A,y;x=x||{};A=a.extend({overwriteCache:false,complete:null,success:null,error:function(){a(this).each(function(){a(this).html(A.errorMessage)})},errorMessage:"There was an error loading the template.",paged:false,pageNo:1,elemPerPage:10,append:false,prepend:false},z);if(a.type(x)==="array"){return r.call(this,B,x,A)}if(!g(B)){v=a(B)}y=A.isFile||(typeof A.isFile==="undefined"&&(typeof v==="undefined"||v.length===0));if(y&&!A.overwriteCache&&u[B]){p(B,w,x,A)}else{if(y&&!A.overwriteCache&&u.hasOwnProperty(B)){c(B,w,x,A)}else{if(y){l(B,w,x,A)}else{n(v,w,x,A)}}}return this}function b(w,v){if(v){h[w]=v}else{h=a.extend(h,w)}}function g(v){return typeof v==="string"&&v.indexOf("/")>-1}function r(B,w,z){var v=this,C=w.length,x=0,y;z=z||{};if(z.paged){var A=(z.pageNo-1)*z.elemPerPage;w=w.slice(A,A+z.elemPerPage)}y=a.extend({},z,{complete:function(){v.append(this.html());x++;if(x===C){if(z&&typeof z.complete==="function"){z.complete()}}}});if(!z.append&&!z.prepend){v.html("")}a(w).each(function(){var D=a("");m.call(D,B,this,y)});return this}function c(y,w,v,x){if(t[y]){t[y].push({data:v,selection:w,settings:x})}else{t[y]=[{data:v,selection:w,settings:x}]}}function p(z,x,w,y){var v=u[z].clone();o.call(x,v,w,y);if(typeof y.success==="function"){y.success()}}function l(z,x,w,y){var v=a("");u[z]=null;v.load(z,function(A,B){if(B==="error"){j(z,x,w,y)}else{k(v,z,x,w,y)}})}function n(v,y,x,z){var w=a("");if(v.is("script")){v=a.parseHTML(a.trim(v.html()))}w.html(v);o.call(y,w,x,z);if(typeof z.success==="function"){z.success()}}function o(x,v,w){f(x,v);a(this).each(function(){if(w.append){a(this).append(x.html())}else{if(w.prepend){a(this).prepend(x.html())}else{a(this).html(x.html())}}});if(typeof w.complete==="function"){w.complete.call(a(this))}}function j(y,w,v,x){var z;if(typeof x.error==="function"){x.error.call(w)}a(t[y]).each(function(A,B){if(typeof B.settings.error==="function"){B.settings.error.call(B.selection)}});if(typeof x.complete==="function"){x.complete.call(w)}while(t[y]&&(z=t[y].shift())){if(typeof z.settings.complete==="function"){z.settings.complete.call(z.selection)}}if(typeof t[y]!=="undefined"&&t[y].length>0){t[y]=[]}}function k(v,z,x,w,y){var A;u[z]=v.clone();o.call(x,v,w,y);if(typeof y.success==="function"){y.success.call(x)}while(t[z]&&(A=t[z].shift())){o.call(A.selection,u[z].clone(),A.data,A.settings);if(typeof A.settings.success==="function"){A.settings.success.call(A.selection)}}}function f(w,v){v=v||{};s("data-content",w,v,function(x,y){x.html(e(x,y,"content"))});s("data-content-append",w,v,function(x,y){x.append(e(x,y,"content"))});s("data-content-prepend",w,v,function(x,y){x.prepend(e(x,y,"content"))});s("data-src",w,v,function(x,y){x.attr("src",e(x,y,"src"))},function(x){x.remove()});s("data-alt",w,v,function(x,y){x.attr("alt",e(x,y,"alt"))});s("data-value",w,v,function(x,y){x.val(e(x,y,"value"))});s("data-link",w,v,function(x,z){var y=a("");y.attr("href",e(x,z,"link"));y.html(x.html());x.html(y)});s("data-link-wrap",w,v,function(x,z){var y=a("");y.attr("href",e(x,z,"link-wrap"));x.wrap(y)});s("data-options",w,v,function(x,y){a(y).each(function(){var z=a("");z.attr("value",this).text(this).appendTo(x)})});q(w,v)}function s(v,z,w,x,y){a("["+v+"]",z).each(function(){var A=a(this),B=A.attr(v),C=i(w,B);A.removeAttr(v);if(C&&x){x(A,C)}else{if(y){y(A)}}});return}function q(w,v){a("[data-template-bind]",w).each(function(){var x=a(this),y=a.parseJSON(x.attr("data-template-bind"));x.removeAttr("data-template-bind");a(y).each(function(){var A;if(typeof(this.value)==="object"){A=i(v,this.value.data)}else{A=i(v,this.value)}if(typeof A!=="undefined"&&this.attribute){switch(this.attribute){case"content":x.html(d(A,this));break;case"contentAppend":x.append(d(A,this));break;case"contentPrepend":x.prepend(d(A,this));break;case"options":var z=this;a(A).each(function(){var B=a("");B.attr("value",this[z.value.value]).text(d(this[z.value.content],z)).appendTo(x)});break;default:x.attr(this.attribute,d(A,this))}}})})}function d(w,v){if(v.formatter&&h[v.formatter]){return h[v.formatter](w,v.formatOptions)}return w}function i(v,w){var x=w.split("."),y,z=v;while((y=x.shift())&&typeof z!=="undefined"){z=z[y]}return z}function e(v,A,w){var z=v.attr("data-format-target"),y;if(z===w||(!z&&w==="content")){y=v.attr("data-format");if(y&&typeof h[y]==="function"){var x=v.attr("data-format-options");return h[y](A,x)}}return A}a.fn.loadTemplate=m;a.addTemplateFormatter=b})(jQuery);
\ No newline at end of file
diff --git a/jquery-loadTemplate/jquery.loadTemplate-1.1.0.js b/jquery-loadTemplate/jquery.loadTemplate-1.2.0.js
similarity index 95%
rename from jquery-loadTemplate/jquery.loadTemplate-1.1.0.js
rename to jquery-loadTemplate/jquery.loadTemplate-1.2.0.js
index 6dc5601..0c49a1d 100644
--- a/jquery-loadTemplate/jquery.loadTemplate-1.1.0.js
+++ b/jquery-loadTemplate/jquery.loadTemplate-1.2.0.js
@@ -27,7 +27,9 @@
pageNo: 1,
elemPerPage: 10,
append: false,
- prepend: false
+ prepend: false,
+ beforeInsert: null,
+ afterInsert: null
}, options);
if ($.type(data) === "array") {
@@ -154,12 +156,20 @@
bindData(template, data);
$(this).each(function () {
+ var $templateHtml = $(template.html());
+ if (settings.beforeInsert) {
+ settings.beforeInsert($templateHtml);
+ }
if (settings.append) {
- $(this).append(template.html());
- } else if(settings.prepend) {
- $(this).prepend(template.html());
+
+ $(this).append($templateHtml);
+ } else if (settings.prepend) {
+ $(this).prepend($templateHtml);
} else {
- $(this).html(template.html());
+ $(this).html($templateHtml);
+ }
+ if (settings.afterInsert) {
+ settings.afterInsert($templateHtml);
}
});
diff --git a/jquery-loadTemplate/jquery.loadTemplate-1.2.0.min.js b/jquery-loadTemplate/jquery.loadTemplate-1.2.0.min.js
new file mode 100644
index 0000000..9034686
--- /dev/null
+++ b/jquery-loadTemplate/jquery.loadTemplate-1.2.0.min.js
@@ -0,0 +1 @@
+(function(a){var u={},t={},h={};function m(B,x,z){var w=this,v,A,y;x=x||{};A=a.extend({overwriteCache:false,complete:null,success:null,error:function(){a(this).each(function(){a(this).html(A.errorMessage)})},errorMessage:"There was an error loading the template.",paged:false,pageNo:1,elemPerPage:10,append:false,prepend:false,beforeInsert:null,afterInsert:null},z);if(a.type(x)==="array"){return r.call(this,B,x,A)}if(!g(B)){v=a(B)}y=A.isFile||(typeof A.isFile==="undefined"&&(typeof v==="undefined"||v.length===0));if(y&&!A.overwriteCache&&u[B]){p(B,w,x,A)}else{if(y&&!A.overwriteCache&&u.hasOwnProperty(B)){c(B,w,x,A)}else{if(y){l(B,w,x,A)}else{n(v,w,x,A)}}}return this}function b(w,v){if(v){h[w]=v}else{h=a.extend(h,w)}}function g(v){return typeof v==="string"&&v.indexOf("/")>-1}function r(B,w,z){var v=this,C=w.length,x=0,y;z=z||{};if(z.paged){var A=(z.pageNo-1)*z.elemPerPage;w=w.slice(A,A+z.elemPerPage)}y=a.extend({},z,{complete:function(){v.append(this.html());x++;if(x===C){if(z&&typeof z.complete==="function"){z.complete()}}}});if(!z.append&&!z.prepend){v.html("")}a(w).each(function(){var D=a("");m.call(D,B,this,y)});return this}function c(y,w,v,x){if(t[y]){t[y].push({data:v,selection:w,settings:x})}else{t[y]=[{data:v,selection:w,settings:x}]}}function p(z,x,w,y){var v=u[z].clone();o.call(x,v,w,y);if(typeof y.success==="function"){y.success()}}function l(z,x,w,y){var v=a("");u[z]=null;v.load(z,function(A,B){if(B==="error"){j(z,x,w,y)}else{k(v,z,x,w,y)}})}function n(v,y,x,z){var w=a("");if(v.is("script")){v=a.parseHTML(a.trim(v.html()))}w.html(v);o.call(y,w,x,z);if(typeof z.success==="function"){z.success()}}function o(x,v,w){f(x,v);a(this).each(function(){var y=a(x.html());if(w.beforeInsert){w.beforeInsert(y)}if(w.append){a(this).append(y)}else{if(w.prepend){a(this).prepend(y)}else{a(this).html(y)}}if(w.afterInsert){w.afterInsert(y)}});if(typeof w.complete==="function"){w.complete.call(a(this))}}function j(y,w,v,x){var z;if(typeof x.error==="function"){x.error.call(w)}a(t[y]).each(function(A,B){if(typeof B.settings.error==="function"){B.settings.error.call(B.selection)}});if(typeof x.complete==="function"){x.complete.call(w)}while(t[y]&&(z=t[y].shift())){if(typeof z.settings.complete==="function"){z.settings.complete.call(z.selection)}}if(typeof t[y]!=="undefined"&&t[y].length>0){t[y]=[]}}function k(v,z,x,w,y){var A;u[z]=v.clone();o.call(x,v,w,y);if(typeof y.success==="function"){y.success.call(x)}while(t[z]&&(A=t[z].shift())){o.call(A.selection,u[z].clone(),A.data,A.settings);if(typeof A.settings.success==="function"){A.settings.success.call(A.selection)}}}function f(w,v){v=v||{};s("data-content",w,v,function(x,y){x.html(e(x,y,"content"))});s("data-content-append",w,v,function(x,y){x.append(e(x,y,"content"))});s("data-content-prepend",w,v,function(x,y){x.prepend(e(x,y,"content"))});s("data-src",w,v,function(x,y){x.attr("src",e(x,y,"src"))},function(x){x.remove()});s("data-alt",w,v,function(x,y){x.attr("alt",e(x,y,"alt"))});s("data-value",w,v,function(x,y){x.val(e(x,y,"value"))});s("data-link",w,v,function(x,z){var y=a("");y.attr("href",e(x,z,"link"));y.html(x.html());x.html(y)});s("data-link-wrap",w,v,function(x,z){var y=a("");y.attr("href",e(x,z,"link-wrap"));x.wrap(y)});s("data-options",w,v,function(x,y){a(y).each(function(){var z=a("");z.attr("value",this).text(this).appendTo(x)})});q(w,v)}function s(v,z,w,x,y){a("["+v+"]",z).each(function(){var A=a(this),B=A.attr(v),C=i(w,B);A.removeAttr(v);if(C&&x){x(A,C)}else{if(y){y(A)}}});return}function q(w,v){a("[data-template-bind]",w).each(function(){var x=a(this),y=a.parseJSON(x.attr("data-template-bind"));x.removeAttr("data-template-bind");a(y).each(function(){var A;if(typeof(this.value)==="object"){A=i(v,this.value.data)}else{A=i(v,this.value)}if(typeof A!=="undefined"&&this.attribute){switch(this.attribute){case"content":x.html(d(A,this));break;case"contentAppend":x.append(d(A,this));break;case"contentPrepend":x.prepend(d(A,this));break;case"options":var z=this;a(A).each(function(){var B=a("");B.attr("value",this[z.value.value]).text(d(this[z.value.content],z)).appendTo(x)});break;default:x.attr(this.attribute,d(A,this))}}})})}function d(w,v){if(v.formatter&&h[v.formatter]){return h[v.formatter](w,v.formatOptions)}return w}function i(v,w){var x=w.split("."),y,z=v;while((y=x.shift())&&typeof z!=="undefined"){z=z[y]}return z}function e(v,A,w){var z=v.attr("data-format-target"),y;if(z===w||(!z&&w==="content")){y=v.attr("data-format");if(y&&typeof h[y]==="function"){var x=v.attr("data-format-options");return h[y](A,x)}}return A}a.fn.loadTemplate=m;a.addTemplateFormatter=b})(jQuery);
\ No newline at end of file
diff --git a/loadTemplate.jquery.json b/loadTemplate.jquery.json
index c8b0c0a..51dc86a 100644
--- a/loadTemplate.jquery.json
+++ b/loadTemplate.jquery.json
@@ -6,7 +6,7 @@
"templates",
"templating"
],
- "version": "1.1.0",
+ "version": "1.2.0",
"author": {
"name": "Paul Burgess and other contributors",
"url": "https://github.com/codepb/jquery-template"
diff --git a/readme.md b/readme.md
index ad50652..d296d8b 100644
--- a/readme.md
+++ b/readme.md
@@ -133,6 +133,10 @@ There are a number of options the plugin accepts. These are:
- "paged" (default false) - A boolean flag to indicate whether arrays should be paged.
- "pageNo" (default 1) - An integer for which page to display if the data is being paged.
- "elemPerPage" (default 10) - The number of elements to display per page if the data is being paged.
+- "append" (default false) - If set to true, the template will be appended to the element rather than replacing the contents of the element.
+- "prepend" (default false) - If set to true, the template will be prepended to the element rather than replacing the contents of the element. The append option takes priority over prepend, so if both options are set to true, the element is appended and not prepended.
+- "beforeInsert" (default null) - Callback function to be called before inserting the template into the document. The format of the function is function($elem) where $elem is the jQuery object of the populated template about to be inserted into the document.
+- "afterInsert" (default null) - As above, a callback function to be called after inserting the template into the document. The format is the same as above.
## Future Plans
From f17fedad8eb30e1e107354b9bbf6ef6209e11b94 Mon Sep 17 00:00:00 2001
From: mamod
Date: Mon, 2 Sep 2013 16:34:26 +0300
Subject: [PATCH 03/71] Pass element to formatter function
let others control elements as well as values associated with template
formatters by passing element as this to to the formatter function
---
jquery-loadTemplate/jquery.loadTemplate-1.2.0.js | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/jquery-loadTemplate/jquery.loadTemplate-1.2.0.js b/jquery-loadTemplate/jquery.loadTemplate-1.2.0.js
index 0c49a1d..63d8e34 100644
--- a/jquery-loadTemplate/jquery.loadTemplate-1.2.0.js
+++ b/jquery-loadTemplate/jquery.loadTemplate-1.2.0.js
@@ -361,7 +361,7 @@
formatter = $elem.attr("data-format");
if (formatter && typeof formatters[formatter] === "function") {
var formatOptions = $elem.attr("data-format-options");
- return formatters[formatter](value, formatOptions);
+ return formatters[formatter].call($elem[0],value, formatOptions);
}
}
From 5ea7b42d38afa0db2384a0b7583b0827f4ff6819 Mon Sep 17 00:00:00 2001
From: mamod
Date: Mon, 2 Sep 2013 17:17:16 +0300
Subject: [PATCH 04/71] missing space
---
jquery-loadTemplate/jquery.loadTemplate-1.2.0.js | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/jquery-loadTemplate/jquery.loadTemplate-1.2.0.js b/jquery-loadTemplate/jquery.loadTemplate-1.2.0.js
index 63d8e34..ba75295 100644
--- a/jquery-loadTemplate/jquery.loadTemplate-1.2.0.js
+++ b/jquery-loadTemplate/jquery.loadTemplate-1.2.0.js
@@ -361,7 +361,7 @@
formatter = $elem.attr("data-format");
if (formatter && typeof formatters[formatter] === "function") {
var formatOptions = $elem.attr("data-format-options");
- return formatters[formatter].call($elem[0],value, formatOptions);
+ return formatters[formatter].call($elem[0], value, formatOptions);
}
}
From 6854d28e81438d8480a678bdfa66a33e10500792 Mon Sep 17 00:00:00 2001
From: Paul Burgess
Date: Mon, 2 Sep 2013 20:20:53 +0100
Subject: [PATCH 05/71] Added element to databindformatter as well
Added the element as this to the databind formatter function as well.
Incremented version numbers
---
Examples/index.html | 2 +-
...plate-1.2.0.js => jquery.loadTemplate-1.2.1.js} | 14 +++++++-------
...2.0.min.js => jquery.loadTemplate-1.2.1.min.js} | 2 +-
loadTemplate.jquery.json | 2 +-
4 files changed, 10 insertions(+), 10 deletions(-)
rename jquery-loadTemplate/{jquery.loadTemplate-1.2.0.js => jquery.loadTemplate-1.2.1.js} (96%)
rename jquery-loadTemplate/{jquery.loadTemplate-1.2.0.min.js => jquery.loadTemplate-1.2.1.min.js} (81%)
diff --git a/Examples/index.html b/Examples/index.html
index e0994f7..371e425 100644
--- a/Examples/index.html
+++ b/Examples/index.html
@@ -10,7 +10,7 @@
-
+
diff --git a/jquery-loadTemplate/jquery.loadTemplate-1.2.0.js b/jquery-loadTemplate/jquery.loadTemplate-1.2.1.js
similarity index 96%
rename from jquery-loadTemplate/jquery.loadTemplate-1.2.0.js
rename to jquery-loadTemplate/jquery.loadTemplate-1.2.1.js
index ba75295..676c5ac 100644
--- a/jquery-loadTemplate/jquery.loadTemplate-1.2.0.js
+++ b/jquery-loadTemplate/jquery.loadTemplate-1.2.1.js
@@ -311,32 +311,32 @@
if (typeof value !== "undefined" && this.attribute) {
switch (this.attribute) {
case "content":
- $this.html(applyDataBindFormatters(value, this));
+ $this.html(applyDataBindFormatters($this, value, this));
break;
case "contentAppend":
- $this.append(applyDataBindFormatters(value, this));
+ $this.append(applyDataBindFormatters($this, value, this));
break;
case "contentPrepend":
- $this.prepend(applyDataBindFormatters(value, this));
+ $this.prepend(applyDataBindFormatters($this, value, this));
break;
case "options":
var optionsData = this;
$(value).each(function () {
var $option = $("");
- $option.attr('value', this[optionsData.value.value]).text(applyDataBindFormatters(this[optionsData.value.content], optionsData)).appendTo($this);
+ $option.attr('value', this[optionsData.value.value]).text(applyDataBindFormatters($this, this[optionsData.value.content], optionsData)).appendTo($this);
});
break;
default:
- $this.attr(this.attribute, applyDataBindFormatters(value, this));
+ $this.attr(this.attribute, applyDataBindFormatters($this, value, this));
}
}
});
});
}
- function applyDataBindFormatters(value, data) {
+ function applyDataBindFormatters($elem, value, data) {
if (data.formatter && formatters[data.formatter]) {
- return formatters[data.formatter](value, data.formatOptions);
+ return formatters[data.formatter].call($elem, value, data.formatOptions);
}
return value;
}
diff --git a/jquery-loadTemplate/jquery.loadTemplate-1.2.0.min.js b/jquery-loadTemplate/jquery.loadTemplate-1.2.1.min.js
similarity index 81%
rename from jquery-loadTemplate/jquery.loadTemplate-1.2.0.min.js
rename to jquery-loadTemplate/jquery.loadTemplate-1.2.1.min.js
index 9034686..1caf7d4 100644
--- a/jquery-loadTemplate/jquery.loadTemplate-1.2.0.min.js
+++ b/jquery-loadTemplate/jquery.loadTemplate-1.2.1.min.js
@@ -1 +1 @@
-(function(a){var u={},t={},h={};function m(B,x,z){var w=this,v,A,y;x=x||{};A=a.extend({overwriteCache:false,complete:null,success:null,error:function(){a(this).each(function(){a(this).html(A.errorMessage)})},errorMessage:"There was an error loading the template.",paged:false,pageNo:1,elemPerPage:10,append:false,prepend:false,beforeInsert:null,afterInsert:null},z);if(a.type(x)==="array"){return r.call(this,B,x,A)}if(!g(B)){v=a(B)}y=A.isFile||(typeof A.isFile==="undefined"&&(typeof v==="undefined"||v.length===0));if(y&&!A.overwriteCache&&u[B]){p(B,w,x,A)}else{if(y&&!A.overwriteCache&&u.hasOwnProperty(B)){c(B,w,x,A)}else{if(y){l(B,w,x,A)}else{n(v,w,x,A)}}}return this}function b(w,v){if(v){h[w]=v}else{h=a.extend(h,w)}}function g(v){return typeof v==="string"&&v.indexOf("/")>-1}function r(B,w,z){var v=this,C=w.length,x=0,y;z=z||{};if(z.paged){var A=(z.pageNo-1)*z.elemPerPage;w=w.slice(A,A+z.elemPerPage)}y=a.extend({},z,{complete:function(){v.append(this.html());x++;if(x===C){if(z&&typeof z.complete==="function"){z.complete()}}}});if(!z.append&&!z.prepend){v.html("")}a(w).each(function(){var D=a("");m.call(D,B,this,y)});return this}function c(y,w,v,x){if(t[y]){t[y].push({data:v,selection:w,settings:x})}else{t[y]=[{data:v,selection:w,settings:x}]}}function p(z,x,w,y){var v=u[z].clone();o.call(x,v,w,y);if(typeof y.success==="function"){y.success()}}function l(z,x,w,y){var v=a("");u[z]=null;v.load(z,function(A,B){if(B==="error"){j(z,x,w,y)}else{k(v,z,x,w,y)}})}function n(v,y,x,z){var w=a("");if(v.is("script")){v=a.parseHTML(a.trim(v.html()))}w.html(v);o.call(y,w,x,z);if(typeof z.success==="function"){z.success()}}function o(x,v,w){f(x,v);a(this).each(function(){var y=a(x.html());if(w.beforeInsert){w.beforeInsert(y)}if(w.append){a(this).append(y)}else{if(w.prepend){a(this).prepend(y)}else{a(this).html(y)}}if(w.afterInsert){w.afterInsert(y)}});if(typeof w.complete==="function"){w.complete.call(a(this))}}function j(y,w,v,x){var z;if(typeof x.error==="function"){x.error.call(w)}a(t[y]).each(function(A,B){if(typeof B.settings.error==="function"){B.settings.error.call(B.selection)}});if(typeof x.complete==="function"){x.complete.call(w)}while(t[y]&&(z=t[y].shift())){if(typeof z.settings.complete==="function"){z.settings.complete.call(z.selection)}}if(typeof t[y]!=="undefined"&&t[y].length>0){t[y]=[]}}function k(v,z,x,w,y){var A;u[z]=v.clone();o.call(x,v,w,y);if(typeof y.success==="function"){y.success.call(x)}while(t[z]&&(A=t[z].shift())){o.call(A.selection,u[z].clone(),A.data,A.settings);if(typeof A.settings.success==="function"){A.settings.success.call(A.selection)}}}function f(w,v){v=v||{};s("data-content",w,v,function(x,y){x.html(e(x,y,"content"))});s("data-content-append",w,v,function(x,y){x.append(e(x,y,"content"))});s("data-content-prepend",w,v,function(x,y){x.prepend(e(x,y,"content"))});s("data-src",w,v,function(x,y){x.attr("src",e(x,y,"src"))},function(x){x.remove()});s("data-alt",w,v,function(x,y){x.attr("alt",e(x,y,"alt"))});s("data-value",w,v,function(x,y){x.val(e(x,y,"value"))});s("data-link",w,v,function(x,z){var y=a("");y.attr("href",e(x,z,"link"));y.html(x.html());x.html(y)});s("data-link-wrap",w,v,function(x,z){var y=a("");y.attr("href",e(x,z,"link-wrap"));x.wrap(y)});s("data-options",w,v,function(x,y){a(y).each(function(){var z=a("");z.attr("value",this).text(this).appendTo(x)})});q(w,v)}function s(v,z,w,x,y){a("["+v+"]",z).each(function(){var A=a(this),B=A.attr(v),C=i(w,B);A.removeAttr(v);if(C&&x){x(A,C)}else{if(y){y(A)}}});return}function q(w,v){a("[data-template-bind]",w).each(function(){var x=a(this),y=a.parseJSON(x.attr("data-template-bind"));x.removeAttr("data-template-bind");a(y).each(function(){var A;if(typeof(this.value)==="object"){A=i(v,this.value.data)}else{A=i(v,this.value)}if(typeof A!=="undefined"&&this.attribute){switch(this.attribute){case"content":x.html(d(A,this));break;case"contentAppend":x.append(d(A,this));break;case"contentPrepend":x.prepend(d(A,this));break;case"options":var z=this;a(A).each(function(){var B=a("");B.attr("value",this[z.value.value]).text(d(this[z.value.content],z)).appendTo(x)});break;default:x.attr(this.attribute,d(A,this))}}})})}function d(w,v){if(v.formatter&&h[v.formatter]){return h[v.formatter](w,v.formatOptions)}return w}function i(v,w){var x=w.split("."),y,z=v;while((y=x.shift())&&typeof z!=="undefined"){z=z[y]}return z}function e(v,A,w){var z=v.attr("data-format-target"),y;if(z===w||(!z&&w==="content")){y=v.attr("data-format");if(y&&typeof h[y]==="function"){var x=v.attr("data-format-options");return h[y](A,x)}}return A}a.fn.loadTemplate=m;a.addTemplateFormatter=b})(jQuery);
\ No newline at end of file
+(function(a){var u={},t={},h={};function m(B,x,z){var w=this,v,A,y;x=x||{};A=a.extend({overwriteCache:false,complete:null,success:null,error:function(){a(this).each(function(){a(this).html(A.errorMessage)})},errorMessage:"There was an error loading the template.",paged:false,pageNo:1,elemPerPage:10,append:false,prepend:false,beforeInsert:null,afterInsert:null},z);if(a.type(x)==="array"){return r.call(this,B,x,A)}if(!g(B)){v=a(B)}y=A.isFile||(typeof A.isFile==="undefined"&&(typeof v==="undefined"||v.length===0));if(y&&!A.overwriteCache&&u[B]){p(B,w,x,A)}else{if(y&&!A.overwriteCache&&u.hasOwnProperty(B)){c(B,w,x,A)}else{if(y){l(B,w,x,A)}else{n(v,w,x,A)}}}return this}function b(w,v){if(v){h[w]=v}else{h=a.extend(h,w)}}function g(v){return typeof v==="string"&&v.indexOf("/")>-1}function r(B,w,z){var v=this,C=w.length,x=0,y;z=z||{};if(z.paged){var A=(z.pageNo-1)*z.elemPerPage;w=w.slice(A,A+z.elemPerPage)}y=a.extend({},z,{complete:function(){v.append(this.html());x++;if(x===C){if(z&&typeof z.complete==="function"){z.complete()}}}});if(!z.append&&!z.prepend){v.html("")}a(w).each(function(){var D=a("");m.call(D,B,this,y)});return this}function c(y,w,v,x){if(t[y]){t[y].push({data:v,selection:w,settings:x})}else{t[y]=[{data:v,selection:w,settings:x}]}}function p(z,x,w,y){var v=u[z].clone();o.call(x,v,w,y);if(typeof y.success==="function"){y.success()}}function l(z,x,w,y){var v=a("");u[z]=null;v.load(z,function(A,B){if(B==="error"){j(z,x,w,y)}else{k(v,z,x,w,y)}})}function n(v,y,x,z){var w=a("");if(v.is("script")){v=a.parseHTML(a.trim(v.html()))}w.html(v);o.call(y,w,x,z);if(typeof z.success==="function"){z.success()}}function o(x,v,w){f(x,v);a(this).each(function(){var y=a(x.html());if(w.beforeInsert){w.beforeInsert(y)}if(w.append){a(this).append(y)}else{if(w.prepend){a(this).prepend(y)}else{a(this).html(y)}}if(w.afterInsert){w.afterInsert(y)}});if(typeof w.complete==="function"){w.complete.call(a(this))}}function j(y,w,v,x){var z;if(typeof x.error==="function"){x.error.call(w)}a(t[y]).each(function(A,B){if(typeof B.settings.error==="function"){B.settings.error.call(B.selection)}});if(typeof x.complete==="function"){x.complete.call(w)}while(t[y]&&(z=t[y].shift())){if(typeof z.settings.complete==="function"){z.settings.complete.call(z.selection)}}if(typeof t[y]!=="undefined"&&t[y].length>0){t[y]=[]}}function k(v,z,x,w,y){var A;u[z]=v.clone();o.call(x,v,w,y);if(typeof y.success==="function"){y.success.call(x)}while(t[z]&&(A=t[z].shift())){o.call(A.selection,u[z].clone(),A.data,A.settings);if(typeof A.settings.success==="function"){A.settings.success.call(A.selection)}}}function f(w,v){v=v||{};s("data-content",w,v,function(x,y){x.html(e(x,y,"content"))});s("data-content-append",w,v,function(x,y){x.append(e(x,y,"content"))});s("data-content-prepend",w,v,function(x,y){x.prepend(e(x,y,"content"))});s("data-src",w,v,function(x,y){x.attr("src",e(x,y,"src"))},function(x){x.remove()});s("data-alt",w,v,function(x,y){x.attr("alt",e(x,y,"alt"))});s("data-value",w,v,function(x,y){x.val(e(x,y,"value"))});s("data-link",w,v,function(x,z){var y=a("");y.attr("href",e(x,z,"link"));y.html(x.html());x.html(y)});s("data-link-wrap",w,v,function(x,z){var y=a("");y.attr("href",e(x,z,"link-wrap"));x.wrap(y)});s("data-options",w,v,function(x,y){a(y).each(function(){var z=a("");z.attr("value",this).text(this).appendTo(x)})});q(w,v)}function s(v,z,w,x,y){a("["+v+"]",z).each(function(){var A=a(this),B=A.attr(v),C=i(w,B);A.removeAttr(v);if(C&&x){x(A,C)}else{if(y){y(A)}}});return}function q(w,v){a("[data-template-bind]",w).each(function(){var x=a(this),y=a.parseJSON(x.attr("data-template-bind"));x.removeAttr("data-template-bind");a(y).each(function(){var A;if(typeof(this.value)==="object"){A=i(v,this.value.data)}else{A=i(v,this.value)}if(typeof A!=="undefined"&&this.attribute){switch(this.attribute){case"content":x.html(d(x,A,this));break;case"contentAppend":x.append(d(x,A,this));break;case"contentPrepend":x.prepend(d(x,A,this));break;case"options":var z=this;a(A).each(function(){var B=a("");B.attr("value",this[z.value.value]).text(d(x,this[z.value.content],z)).appendTo(x)});break;default:x.attr(this.attribute,d(x,A,this))}}})})}function d(v,x,w){if(w.formatter&&h[w.formatter]){return h[w.formatter].call(v,x,w.formatOptions)}return x}function i(v,w){var x=w.split("."),y,z=v;while((y=x.shift())&&typeof z!=="undefined"){z=z[y]}return z}function e(v,A,w){var z=v.attr("data-format-target"),y;if(z===w||(!z&&w==="content")){y=v.attr("data-format");if(y&&typeof h[y]==="function"){var x=v.attr("data-format-options");return h[y].call(v[0],A,x)}}return A}a.fn.loadTemplate=m;a.addTemplateFormatter=b})(jQuery);
\ No newline at end of file
diff --git a/loadTemplate.jquery.json b/loadTemplate.jquery.json
index 51dc86a..f6470e1 100644
--- a/loadTemplate.jquery.json
+++ b/loadTemplate.jquery.json
@@ -6,7 +6,7 @@
"templates",
"templating"
],
- "version": "1.2.0",
+ "version": "1.2.1",
"author": {
"name": "Paul Burgess and other contributors",
"url": "https://github.com/codepb/jquery-template"
From 6a211c045a8bdbcf52c7ec28bba4b5db26e9d349 Mon Sep 17 00:00:00 2001
From: mamod
Date: Mon, 2 Sep 2013 23:52:17 +0300
Subject: [PATCH 06/71] prepend elements fix
When prepending elements with an array of data it appends instead of
prepend
---
jquery-loadTemplate/jquery.loadTemplate-1.2.1.js | 11 ++++++++---
1 file changed, 8 insertions(+), 3 deletions(-)
diff --git a/jquery-loadTemplate/jquery.loadTemplate-1.2.1.js b/jquery-loadTemplate/jquery.loadTemplate-1.2.1.js
index 676c5ac..86ba965 100644
--- a/jquery-loadTemplate/jquery.loadTemplate-1.2.1.js
+++ b/jquery-loadTemplate/jquery.loadTemplate-1.2.1.js
@@ -67,13 +67,13 @@
}
function processArray(template, data, settings) {
+ settings = settings || {};
var $that = this,
todo = data.length,
+ doPrepend = settings.prepend && !settings.append,
done = 0,
newOptions;
- settings = settings || {};
-
if (settings.paged) {
var startNo = (settings.pageNo - 1) * settings.elemPerPage;
data = data.slice(startNo, startNo + settings.elemPerPage);
@@ -84,7 +84,11 @@
settings,
{
complete: function () {
- $that.append(this.html());
+ if (doPrepend){
+ $that.prepend(this.html());
+ } else {
+ $that.append(this.html());
+ }
done++;
if (done === todo) {
if (settings && typeof settings.complete === "function") {
@@ -99,6 +103,7 @@
$that.html("");
}
+ if (doPrepend) data.reverse();
$(data).each(function () {
var $div = $("");
loadTemplate.call($div, template, this, newOptions);
From f26f54672e53c6d82b1993d4b9fc90872abc7ab0 Mon Sep 17 00:00:00 2001
From: mamod
Date: Tue, 3 Sep 2013 19:12:41 +0300
Subject: [PATCH 07/71] examples minor fixes
1- updated jQuery version
2- Fixed mixed tabs with space indentation
3- Fix absolute links -> to work when running from non root location
---
Examples/ExampleSearchResults/search.html | 8 ++-
Examples/SimpleExample/Templates/simple.html | 9 +--
Examples/SimpleExample/example.html | 60 ++++++++++----------
Examples/index.html | 5 +-
4 files changed, 41 insertions(+), 41 deletions(-)
diff --git a/Examples/ExampleSearchResults/search.html b/Examples/ExampleSearchResults/search.html
index 36a5cb3..ccd94d1 100644
--- a/Examples/ExampleSearchResults/search.html
+++ b/Examples/ExampleSearchResults/search.html
@@ -24,10 +24,12 @@
Example of using jQuery.loadTemplate for improved search.
+
+
\ No newline at end of file
+ });
+
diff --git a/Examples/index.html b/Examples/index.html
index 371e425..f10ebdb 100644
--- a/Examples/index.html
+++ b/Examples/index.html
@@ -1,5 +1,4 @@
-
@@ -9,7 +8,7 @@
-
+
@@ -68,7 +67,6 @@
Code
}
function highlightSupported() {
var ver = getInternetExplorerVersion();
-
if (ver > -1) {
if (ver < 9) {
return false;
@@ -78,7 +76,6 @@
Code
}
$("a").click(function (e) {
e.preventDefault();
-
var $div = $("");
$($div).load($(this).attr("href"), function () {
$(".contentContainer > div").hide();
From 59427783270bcfbd01ece7d23f1e59716745d141 Mon Sep 17 00:00:00 2001
From: Paul Burgess
Date: Wed, 18 Sep 2013 20:43:10 +0100
Subject: [PATCH 08/71] Updated error/success for arrays
Error and Success callbacks now only fire at the end of the processing
of an array.
---
Examples/ExampleSearchResults/search.html | 2 +-
Examples/index.html | 2 +-
...-1.2.1.js => jquery.loadTemplate-1.2.2.js} | 19 ++++++++++++++++++-
...in.js => jquery.loadTemplate-1.2.2.min.js} | 2 +-
loadTemplate.jquery.json | 2 +-
5 files changed, 22 insertions(+), 5 deletions(-)
rename jquery-loadTemplate/{jquery.loadTemplate-1.2.1.js => jquery.loadTemplate-1.2.2.js} (94%)
rename jquery-loadTemplate/{jquery.loadTemplate-1.2.1.min.js => jquery.loadTemplate-1.2.2.min.js} (87%)
diff --git a/Examples/ExampleSearchResults/search.html b/Examples/ExampleSearchResults/search.html
index ccd94d1..f1c2f13 100644
--- a/Examples/ExampleSearchResults/search.html
+++ b/Examples/ExampleSearchResults/search.html
@@ -71,7 +71,7 @@
Example of using jQuery.loadTemplate for improved search.
diff --git a/jquery-loadTemplate/jquery.loadTemplate-1.2.6.js b/jquery-loadTemplate/jquery.loadTemplate-1.2.7.js
similarity index 100%
rename from jquery-loadTemplate/jquery.loadTemplate-1.2.6.js
rename to jquery-loadTemplate/jquery.loadTemplate-1.2.7.js
diff --git a/jquery-loadTemplate/jquery.loadTemplate-1.2.6.min.js b/jquery-loadTemplate/jquery.loadTemplate-1.2.7.min.js
similarity index 87%
rename from jquery-loadTemplate/jquery.loadTemplate-1.2.6.min.js
rename to jquery-loadTemplate/jquery.loadTemplate-1.2.7.min.js
index b802e27..95164eb 100644
--- a/jquery-loadTemplate/jquery.loadTemplate-1.2.6.min.js
+++ b/jquery-loadTemplate/jquery.loadTemplate-1.2.7.min.js
@@ -1 +1 @@
-(function(a){var u={},t={},h={};function m(B,x,z){var w=this,v,A,y;x=x||{};A=a.extend({overwriteCache:false,complete:null,success:null,error:function(){a(this).each(function(){a(this).html(A.errorMessage)})},errorMessage:"There was an error loading the template.",paged:false,pageNo:1,elemPerPage:10,append:false,prepend:false,beforeInsert:null,afterInsert:null},z);if(a.type(x)==="array"){return r.call(this,B,x,A)}if(!g(B)){v=a(B);if(typeof B==="string"&&B.indexOf("#")===0){A.isFile=false}}y=A.isFile||(typeof A.isFile==="undefined"&&(typeof v==="undefined"||v.length===0));if(y&&!A.overwriteCache&&u[B]){p(B,w,x,A)}else{if(y&&!A.overwriteCache&&u.hasOwnProperty(B)){c(B,w,x,A)}else{if(y){l(B,w,x,A)}else{n(v,w,x,A)}}}return this}function b(w,v){if(v){h[w]=v}else{h=a.extend(h,w)}}function g(v){return typeof v==="string"&&v.indexOf("/")>-1}function r(E,w,B){B=B||{};var v=this,F=w.length,y=B.prepend&&!B.append,x=0,D=0,z=false,A;if(B.paged){var C=(B.pageNo-1)*B.elemPerPage;w=w.slice(C,C+B.elemPerPage);F=w.length}A=a.extend({},B,{complete:function(){if(y){v.prepend(this.html())}else{v.append(this.html())}x++;if(x===F){if(z&&B&&typeof B.error==="function"){B.error.call(v)}if(B&&typeof B.complete==="function"){B.complete()}}},success:function(){D++;if(D===F){if(B&&typeof B.success==="function"){B.success()}}},error:function(){z=true}});if(!B.append&&!B.prepend){v.html("")}if(y){w.reverse()}a(w).each(function(){var G=a("");m.call(G,E,this,A)});return this}function c(y,w,v,x){if(t[y]){t[y].push({data:v,selection:w,settings:x})}else{t[y]=[{data:v,selection:w,settings:x}]}}function p(z,x,w,y){var v=u[z].clone();o.call(x,v,w,y);if(typeof y.success==="function"){y.success()}}function l(z,x,w,y){var v=a("");u[z]=null;v.load(z,function(A,B){if(B==="error"){j(z,x,w,y)}else{k(v,z,x,w,y)}})}function n(v,y,x,z){var w=a("");if(v.is("script")){v=a.parseHTML(a.trim(v.html()))}w.html(v);o.call(y,w,x,z);if(typeof z.success==="function"){z.success()}}function o(x,v,w){f(x,v);a(this).each(function(){var y=a(x.html());if(w.beforeInsert){w.beforeInsert(y)}if(w.append){a(this).append(y)}else{if(w.prepend){a(this).prepend(y)}else{a(this).html(y)}}if(w.afterInsert){w.afterInsert(y)}});if(typeof w.complete==="function"){w.complete.call(a(this))}}function j(y,w,v,x){var z;if(typeof x.error==="function"){x.error.call(w)}a(t[y]).each(function(A,B){if(typeof B.settings.error==="function"){B.settings.error.call(B.selection)}});if(typeof x.complete==="function"){x.complete.call(w)}while(t[y]&&(z=t[y].shift())){if(typeof z.settings.complete==="function"){z.settings.complete.call(z.selection)}}if(typeof t[y]!=="undefined"&&t[y].length>0){t[y]=[]}}function k(v,z,x,w,y){var A;u[z]=v.clone();o.call(x,v,w,y);if(typeof y.success==="function"){y.success.call(x)}while(t[z]&&(A=t[z].shift())){o.call(A.selection,u[z].clone(),A.data,A.settings);if(typeof A.settings.success==="function"){A.settings.success.call(A.selection)}}}function f(w,v){v=v||{};s("data-content",w,v,function(x,y){x.html(e(x,y,"content"))});s("data-content-append",w,v,function(x,y){x.append(e(x,y,"content"))});s("data-content-prepend",w,v,function(x,y){x.prepend(e(x,y,"content"))});s("data-src",w,v,function(x,y){x.attr("src",e(x,y,"src"))},function(x){x.remove()});s("data-alt",w,v,function(x,y){x.attr("alt",e(x,y,"alt"))});s("data-value",w,v,function(x,y){x.attr("value",e(x,y,"value"))});s("data-link",w,v,function(x,z){var y=a("");y.attr("href",e(x,z,"link"));y.html(x.html());x.html(y)});s("data-link-wrap",w,v,function(x,z){var y=a("");y.attr("href",e(x,z,"link-wrap"));x.wrap(y)});s("data-options",w,v,function(x,y){a(y).each(function(){var z=a("");z.attr("value",this).text(this).appendTo(x)})});q(w,v)}function s(v,z,w,x,y){a("["+v+"]",z).each(function(){var A=a(this),B=A.attr(v),C=i(w,B);A.removeAttr(v);if(typeof C!=="undefined"&&x){x(A,C)}else{if(y){y(A)}}});return}function q(w,v){a("[data-template-bind]",w).each(function(){var x=a(this),y=a.parseJSON(x.attr("data-template-bind"));x.removeAttr("data-template-bind");a(y).each(function(){var A;if(typeof(this.value)==="object"){A=i(v,this.value.data)}else{A=i(v,this.value)}if(typeof A!=="undefined"&&this.attribute){switch(this.attribute){case"content":x.html(d(x,A,this));break;case"contentAppend":x.append(d(x,A,this));break;case"contentPrepend":x.prepend(d(x,A,this));break;case"options":var z=this;a(A).each(function(){var B=a("");B.attr("value",this[z.value.value]).text(d(x,this[z.value.content],z)).appendTo(x)});break;default:x.attr(this.attribute,d(x,A,this))}}})})}function d(v,x,w){if(w.formatter&&h[w.formatter]){return h[w.formatter].call(v,x,w.formatOptions)}return x}function i(v,w){var x=w.split("."),y,z=v;while((y=x.shift())&&typeof z!=="undefined"){z=z[y]}return z}function e(v,A,w){var z=v.attr("data-format-target"),y;if(z===w||(!z&&w==="content")){y=v.attr("data-format");if(y&&typeof h[y]==="function"){var x=v.attr("data-format-options");return h[y].call(v[0],A,x)}}return A}a.fn.loadTemplate=m;a.addTemplateFormatter=b})(jQuery);
\ No newline at end of file
+(function(a){var u={},t={},h={};function m(B,x,z){var w=this,v,A,y;x=x||{};A=a.extend({overwriteCache:false,complete:null,success:null,error:function(){a(this).each(function(){a(this).html(A.errorMessage)})},errorMessage:"There was an error loading the template.",paged:false,pageNo:1,elemPerPage:10,append:false,prepend:false,beforeInsert:null,afterInsert:null},z);if(a.type(x)==="array"){return r.call(this,B,x,A)}if(!g(B)){v=a(B);if(typeof B==="string"&&B.indexOf("#")===0){A.isFile=false}}y=A.isFile||(typeof A.isFile==="undefined"&&(typeof v==="undefined"||v.length===0));if(y&&!A.overwriteCache&&u[B]){p(B,w,x,A)}else{if(y&&!A.overwriteCache&&u.hasOwnProperty(B)){c(B,w,x,A)}else{if(y){l(B,w,x,A)}else{n(v,w,x,A)}}}return this}function b(w,v){if(v){h[w]=v}else{h=a.extend(h,w)}}function g(v){return typeof v==="string"&&v.indexOf("/")>-1}function r(E,w,B){B=B||{};var v=this,F=w.length,y=B.prepend&&!B.append,x=0,D=0,z=false,A;if(B.paged){var C=(B.pageNo-1)*B.elemPerPage;w=w.slice(C,C+B.elemPerPage);F=w.length}A=a.extend({},B,{complete:function(){if(y){v.prepend(this.html())}else{v.append(this.html())}x++;if(x===F){if(z&&B&&typeof B.error==="function"){B.error.call(v)}if(B&&typeof B.complete==="function"){B.complete()}}},success:function(){D++;if(D===F){if(B&&typeof B.success==="function"){B.success()}}},error:function(){z=true}});if(!B.append&&!B.prepend){v.html("")}if(y){w.reverse()}a(w).each(function(){var G=a("");m.call(G,E,this,A)});return this}function c(y,w,v,x){if(t[y]){t[y].push({data:v,selection:w,settings:x})}else{t[y]=[{data:v,selection:w,settings:x}]}}function p(z,x,w,y){var v=u[z].clone();o.call(x,v,w,y);if(typeof y.success==="function"){y.success()}}function l(z,x,w,y){var v=a("");u[z]=null;v.load(z,function(A,B){if(B==="error"){j(z,x,w,y)}else{k(v,z,x,w,y)}})}function n(v,y,x,z){var w=a("");if(v.is("script")){v=a.parseHTML(a.trim(v.html()))}w.html(v);o.call(y,w,x,z);if(typeof z.success==="function"){z.success()}}function o(x,v,w){f(x,v);a(this).each(function(){var y=a(x.html());if(w.beforeInsert){w.beforeInsert(y)}if(w.append){a(this).append(y)}else{if(w.prepend){a(this).prepend(y)}else{a(this).html(y)}}if(w.afterInsert){w.afterInsert(y)}});if(typeof w.complete==="function"){w.complete.call(a(this))}}function j(y,w,v,x){var z;if(typeof x.error==="function"){x.error.call(w)}a(t[y]).each(function(A,B){if(typeof B.settings.error==="function"){B.settings.error.call(B.selection)}});if(typeof x.complete==="function"){x.complete.call(w)}while(t[y]&&(z=t[y].shift())){if(typeof z.settings.complete==="function"){z.settings.complete.call(z.selection)}}if(typeof t[y]!=="undefined"&&t[y].length>0){t[y]=[]}}function k(v,z,x,w,y){var A;u[z]=v.clone();o.call(x,v,w,y);if(typeof y.success==="function"){y.success.call(x)}while(t[z]&&(A=t[z].shift())){o.call(A.selection,u[z].clone(),A.data,A.settings);if(typeof A.settings.success==="function"){A.settings.success.call(A.selection)}}}function f(w,v){v=v||{};s("data-content",w,v,function(x,y){x.html(e(x,y,"content"))});s("data-content-append",w,v,function(x,y){x.append(e(x,y,"content"))});s("data-content-prepend",w,v,function(x,y){x.prepend(e(x,y,"content"))});s("data-src",w,v,function(x,y){x.attr("src",e(x,y,"src"))},function(x){x.remove()});s("data-alt",w,v,function(x,y){x.attr("alt",e(x,y,"alt"))});s("data-value",w,v,function(x,y){x.attr("value",e(x,y,"value"))});s("data-link",w,v,function(x,z){var y=a("");y.attr("href",e(x,z,"link"));y.html(x.html());x.html(y)});s("data-link-wrap",w,v,function(x,z){var y=a("");y.attr("href",e(x,z,"link-wrap"));x.wrap(y)});s("data-options",w,v,function(x,y){a(y).each(function(){var z=a("");z.attr("value",this).text(this).appendTo(x)})});q(w,v)}function s(v,z,w,x,y){a("["+v+"]",z).each(function(){var A=a(this),B=A.attr(v),C=i(w,B);A.removeAttr(v);if(typeof C!=="undefined"&&x){x(A,C)}else{if(y){y(A)}}});return}function q(w,v){a("[data-template-bind]",w).each(function(){var x=a(this),y=a.parseJSON(x.attr("data-template-bind"));x.removeAttr("data-template-bind");a(y).each(function(){var A;if(typeof(this.value)==="object"){A=i(v,this.value.data)}else{A=i(v,this.value)}if(typeof A!=="undefined"&&this.attribute){switch(this.attribute){case"content":x.html(d(x,A,this));break;case"contentAppend":x.append(d(x,A,this));break;case"contentPrepend":x.prepend(d(x,A,this));break;case"options":var z=this;a(A).each(function(){var B=a("");B.attr("value",this[z.value.value]).text(d(x,this[z.value.content],z)).attr("selected",typeof this[z.value.selected]==undefined?false:this[z.value.selected]).appendTo(x)});break;default:x.attr(this.attribute,d(x,A,this))}}})})}function d(v,x,w){if(w.formatter&&h[w.formatter]){return h[w.formatter].call(v,x,w.formatOptions)}return x}function i(v,w){var x=w.split("."),y,z=v;while((y=x.shift())&&typeof z!=="undefined"){z=z[y]}return z}function e(v,A,w){var z=v.attr("data-format-target"),y;if(z===w||(!z&&w==="content")){y=v.attr("data-format");if(y&&typeof h[y]==="function"){var x=v.attr("data-format-options");return h[y].call(v[0],A,x)}}return A}a.fn.loadTemplate=m;a.addTemplateFormatter=b})(jQuery);
\ No newline at end of file
diff --git a/loadTemplate.jquery.json b/loadTemplate.jquery.json
index fedf8ca..3115289 100644
--- a/loadTemplate.jquery.json
+++ b/loadTemplate.jquery.json
@@ -6,7 +6,7 @@
"templates",
"templating"
],
- "version": "1.2.6",
+ "version": "1.2.7",
"author": {
"name": "Paul Burgess and other contributors",
"url": "https://github.com/codepb/jquery-template"
diff --git a/tests/index.html b/tests/index.html
index 93c1bbf..8d3d426 100644
--- a/tests/index.html
+++ b/tests/index.html
@@ -3,7 +3,7 @@
loadTemplate Test Suite
-
+
From 131d4908d51c1d58c2ccf85fa8dfb94dd9116ad9 Mon Sep 17 00:00:00 2001
From: Paul Burgess
Date: Fri, 15 Nov 2013 20:58:17 +0000
Subject: [PATCH 19/71] Updated overwriteCache option
overwriteCache option now will append a random query parameter to the
url to overcome the browser cache.
---
Examples/SimpleExample/example.html | 2 +-
Examples/index.html | 6 +-----
.../jquery.loadTemplate-1.2.7.min.js | 1 -
...e-1.2.7.js => jquery.loadTemplate-1.2.8.js} | 18 +++++++++++++++++-
.../jquery.loadTemplate-1.2.8.min.js | 1 +
loadTemplate.jquery.json | 2 +-
tests/index.html | 2 +-
7 files changed, 22 insertions(+), 10 deletions(-)
delete mode 100644 jquery-loadTemplate/jquery.loadTemplate-1.2.7.min.js
rename jquery-loadTemplate/{jquery.loadTemplate-1.2.7.js => jquery.loadTemplate-1.2.8.js} (96%)
create mode 100644 jquery-loadTemplate/jquery.loadTemplate-1.2.8.min.js
diff --git a/Examples/SimpleExample/example.html b/Examples/SimpleExample/example.html
index 1f59aa6..d2914d8 100644
--- a/Examples/SimpleExample/example.html
+++ b/Examples/SimpleExample/example.html
@@ -63,7 +63,7 @@
Example of loading a template from a script tag within the same document.
-
+
@@ -48,10 +48,6 @@
Code
-
+
From 24b0695afb4072987ea78cca04fd9f099cee26ce Mon Sep 17 00:00:00 2001
From: Paul Burgess
Date: Sun, 17 Nov 2013 16:02:17 +0000
Subject: [PATCH 20/71] Nesting templates basic support
Added support for binding to "this" to bind to the object itself rather
than a parameter on the object. Also support for nested templates has
been improved by providing a default formatter for this. To nest a
template you can use the 'nestedTemplateFormatter'. An example is below:
data-format="nestedTemplateFormatter"
data-format-options='{"parentElement": "ul", "template":
"#templateThis"}'
data-format-options is required to at least provide a template in the
same format as the loadTemplate function requires. parentElement is the
element to use to contain the template. If this isn't provided then
parentElement will be a "div". It is also possible to just provide a
template and not an object.
Documentation will need to be produced on this change.
---
Examples/SimpleExample/example.html | 40 ++++--
Examples/index.html | 2 +-
...-1.2.8.js => jquery.loadTemplate-1.3.0.js} | 15 +++
...in.js => jquery.loadTemplate-1.3.0.min.js} | 2 +-
loadTemplate.jquery.json | 2 +-
tests/files/general.js | 126 +++++++++++-------
tests/index.html | 15 ++-
7 files changed, 140 insertions(+), 62 deletions(-)
rename jquery-loadTemplate/{jquery.loadTemplate-1.2.8.js => jquery.loadTemplate-1.3.0.js} (96%)
rename jquery-loadTemplate/{jquery.loadTemplate-1.2.8.min.js => jquery.loadTemplate-1.3.0.min.js} (88%)
diff --git a/Examples/SimpleExample/example.html b/Examples/SimpleExample/example.html
index d2914d8..f338d81 100644
--- a/Examples/SimpleExample/example.html
+++ b/Examples/SimpleExample/example.html
@@ -9,6 +9,10 @@
Example of loading a template from a script tag within the same document.
+
+
+
+
diff --git a/readme.md b/readme.md
index d296d8b..349eeec 100644
--- a/readme.md
+++ b/readme.md
@@ -1,143 +1,155 @@
-# jQuery.loadTemplate
-
-jQuery Template is a jQuery plugin that makes using templates easy and quick. The plugin supports loading HTML files as templates, or taking a jQuery object as the template (usually using script tags to hold the template).
-
-## Features
-
-jQuery.LoadTemplate provides the following:
-
-- Define Templates to display data
-- Provide Formatters to process data into a more readable format
-- Cache templates and data client side and pass processing to the client, allowing for a great user experience.
-- Powerful but simple syntax, utilising pure html for templates.
-
-## Getting Started
-
-Simply clone the repo. The only file required is the jquery.loadTemplate-version.js file in the jquery.loadTemplate folder. There is also a folder for examples in the same folder. Take a look at the index file in here for examples and the code to create the examples.
-
-To see examples of usage, visit the project page: [http://codepb.github.io/jquery-template/](http://codepb.github.io/jquery-template/)
-
-## Potential Applications
-
-jQuery.loadTemplate was originally designed with a single page application for a blog in mind. The idea was to create templates for blog posts, post snippets, etc. This could then be called from the client when required, and cached. The post data was sent as a JSON object from the server, and processed into the templates using the plugin. This meant a very light load on the server, and a great user experience, with smooth page transitions, and JavaScript engines doing all the work.
-
-However I saw many other potential applications for this. Any application that deals with a large amount of data displayed in a regular format, for example search results, live commentary, blogs, online stores, social media sites, and the list could go on.
-
-## How it works
-
-The plugin parses a template using data attributes to populate the data. Simply pass in a JavaScript object, and the plugin does the rest.
-
-An example template is below:
-
-
-
-And to use this do the following:
-
- $("#template-container").loadTemplate($("#template"),
- {
- author: 'Joe Bloggs',
- date: '25th May 2013',
- authorPicture: 'Authors/JoeBloggs.jpg',
- post: 'This is the contents of my post'
- });
-
-Similarly the content of the template could be held in a separate html file without the enclosing script tag, and used like the following:
-
- $("#template-container").loadTemplate("Templates/template.html",
- {
- author: 'Joe Bloggs',
- date: '25th May 2013',
- authorPicture: 'Authors/JoeBloggs.jpg',
- post: 'This is the contents of my post'
- });
-
-The plugin has a number of data-... attributes that can be used to populate various attributes with the data. There is also the powerful data-template-bind attribute that accepts a JSON object, enabling binding to any attribute, or the content of the element.
-
-### Data Formatters
-
-It is also possible to define data formatters. These are assigned through the `$.addTemplateFormatter` method. This function either accepts a map of functions and the keys that they will be referenced by, or a single function with a single key as two separate parameters. Each formatter takes two values, the value being assigned, and a template to use to define how this data is displayed. The data-format-template may be empty. Example usage of this is below:
-
- $.addTemplateFormatter("UpperCaseFormatter",
- function(value, template) {
- return value.toUpperCase();
- });
-
-Alternatively with a map:
-
- $.addTemplateFormatter({
- UpperCaseFormatter : function(value, template) {
- return value.toUpperCase();
- },
- LowerCaseFormatter : function(value, template) {
- return value.toLowerCase();
- },
- SameCaseFormatter : function(value, template) {
- if(template == "upper") {
- return value.toUpperCase();
- } else {
- return value.toLowerCase();
- }
- }
- });
-
-To call these formatters, simply the following will work:
-
-
-
-Formatters must be added before they are used else a template will not be able to access them. Formatters are used at the time of populating the data. You can also target any binding with the "data-format-target". The value of this is the binding to target so to target data-alt binding, set 'data-format-target="alt"'.
-
-### Bindings
-There are a number of different bindings and ways to bind the data. The following attributes are available:
-
-- "data-content" - binds the value supplied to the content of the element (uses $(elem).html(value))
-- "data-content-append" - appends the value to the end of the element (uses $(elem).append(value))
-- "data-content-prepend" - prepends the value to the beginning of the element (uses $(elem).prepend(value))
-- "data-alt" - sets the alt value of the element to the value provided (uses $(elem).attr("alt", value));
-- "data-value" - sets the value attribute of the element to the value provided (uses $(elem).val(value))
-- "data-link" - sets the innerHtml of the element to be a link to the value provided (wraps the content in an <a> tag).
-- "data-link-wrap" - wraps the element in a link to the value provided. Same as "data-link", but the <a> tag wraps the element as well as the content.
-- "data-options" - adds options to a select box. The value for this should reference an array of strings, each option will be output as a separate option. The value will be the same as the displayed text for each option. For a more powerful version of this look at the data-template-bind option.
-
-On top of the attributes above, there is also a "data-template-bind" attribute. This is designed to handle more complex situations and allows a wide range of control. The attribute takes a JSON string and allows multiple bindings and options to be set in the one attribute.
-
-The "data-template-bind" value should be an array of objects. Each object represents one complete binding. Each object can contain the following properties:
-
-- "value" (required) - The property representing the value to bind to.
-- "attribute" (required) - The attribute to bind to. This can be any attribute accepted by the jQuery.attr() method or one of the following: "content" - same as data-content, binds the innerHTML, "contentAppend" - same as data-append, appends the value, "contentPrepend" - same as data-prepend, prepends the value, "options" - same as data-options, but provides greater control. The value attribute for this is an object with a value property and a content property, and this will bind the value of the option to the value property, and the innerText of the option to the content property.
-- "formatter" (optional) - provides the formatter to apply to the specific binding. Multiple different attributes can use different formatters using this syntax.
-- "formatOptions" (optional) - the options to pass to the formatter applied.
-
-An example of using the "data-template-bind" attribute would be the following:
-
-
-
-### Options
-
-There are a number of options the plugin accepts. These are:
-
-- "overwriteCache" (default false) - Whether to ignore the cache and reload the template (if you've previously loaded the template, but it might have changed, you'll want to set this to true.
-- "complete" (default null) - Callback function to call on complete. Will always be called regardless of success or failure.
-- "success" (default null) - Callback function to call on successful completion.
-- "error" (default, outputting error message to template container) - Callback function to call on error.
-- "errorMessage" (default "There was an error loading the template.") - Error message for the default error callback to use. This will not be used if you set an error callback function.
-- "isFile" (default undefined) - flag to help speed up the process of deciding where to load the template from. Set to true if the template is an external file to load via ajax, false if it's a jQuery selector for an element in the document. Default undefined means the plugin will check first in the document, then attempt to load external file.
-- "paged" (default false) - A boolean flag to indicate whether arrays should be paged.
-- "pageNo" (default 1) - An integer for which page to display if the data is being paged.
-- "elemPerPage" (default 10) - The number of elements to display per page if the data is being paged.
-- "append" (default false) - If set to true, the template will be appended to the element rather than replacing the contents of the element.
-- "prepend" (default false) - If set to true, the template will be prepended to the element rather than replacing the contents of the element. The append option takes priority over prepend, so if both options are set to true, the element is appended and not prepended.
-- "beforeInsert" (default null) - Callback function to be called before inserting the template into the document. The format of the function is function($elem) where $elem is the jQuery object of the populated template about to be inserted into the document.
-- "afterInsert" (default null) - As above, a callback function to be called after inserting the template into the document. The format is the same as above.
-
-## Future Plans
-
+# jQuery.loadTemplate
+
+jQuery Template is a jQuery plugin that makes using templates easy and quick. The plugin supports loading HTML files as templates, or taking a jQuery object as the template (usually using script tags to hold the template).
+
+## Features
+
+jQuery.LoadTemplate provides the following:
+
+- Define Templates to display data
+- Provide Formatters to process data into a more readable format
+- Cache templates and data client side and pass processing to the client, allowing for a great user experience.
+- Powerful but simple syntax, utilising pure html for templates.
+
+## Getting Started
+
+Simply clone the repo. The only file required is the jquery.loadTemplate-version.js file in the jquery.loadTemplate folder. There is also a folder for examples in the same folder. Take a look at the index file in here for examples and the code to create the examples.
+
+To see examples of usage, visit the project page: [http://codepb.github.io/jquery-template/](http://codepb.github.io/jquery-template/)
+
+## Potential Applications
+
+jQuery.loadTemplate was originally designed with a single page application for a blog in mind. The idea was to create templates for blog posts, post snippets, etc. This could then be called from the client when required, and cached. The post data was sent as a JSON object from the server, and processed into the templates using the plugin. This meant a very light load on the server, and a great user experience, with smooth page transitions, and JavaScript engines doing all the work.
+
+However I saw many other potential applications for this. Any application that deals with a large amount of data displayed in a regular format, for example search results, live commentary, blogs, online stores, social media sites, and the list could go on.
+
+## How it works
+
+The plugin parses a template using data attributes to populate the data. Simply pass in a JavaScript object, and the plugin does the rest.
+
+An example template is below:
+
+
+
+And to use this do the following:
+
+ $("#template-container").loadTemplate($("#template"),
+ {
+ author: 'Joe Bloggs',
+ date: '25th May 2013',
+ authorPicture: 'Authors/JoeBloggs.jpg',
+ post: 'This is the contents of my post'
+ });
+
+Similarly the content of the template could be held in a separate html file without the enclosing script tag, and used like the following:
+
+ $("#template-container").loadTemplate("Templates/template.html",
+ {
+ author: 'Joe Bloggs',
+ date: '25th May 2013',
+ authorPicture: 'Authors/JoeBloggs.jpg',
+ post: 'This is the contents of my post'
+ });
+
+Several options can be passed as function parameters. For example, to specify that 'null' values should not be rendered, load the template like this:
+
+ $("#template-container").loadTemplate("Templates/template.html",
+ {
+ author: 'Joe Bloggs',
+ date: null,
+ authorPicture: 'Authors/JoeBloggs.jpg',
+ post: 'This is the contents of my post'
+ }, {"ignoreNull": true}});
+
+In addition, the plugin has a number of data-... attributes that can be used to populate various attributes with the data. There is also the powerful data-template-bind attribute that accepts a JSON object, enabling binding to any attribute, or the content of the element.
+
+### Data Formatters
+
+It is also possible to define data formatters. These are assigned through the `$.addTemplateFormatter` method. This function either accepts a map of functions and the keys that they will be referenced by, or a single function with a single key as two separate parameters. Each formatter takes two values, the value being assigned, and a template to use to define how this data is displayed. The data-format-template may be empty. Example usage of this is below:
+
+ $.addTemplateFormatter("UpperCaseFormatter",
+ function(value, template) {
+ return value.toUpperCase();
+ });
+
+Alternatively with a map:
+
+ $.addTemplateFormatter({
+ UpperCaseFormatter : function(value, template) {
+ return value.toUpperCase();
+ },
+ LowerCaseFormatter : function(value, template) {
+ return value.toLowerCase();
+ },
+ SameCaseFormatter : function(value, template) {
+ if(template == "upper") {
+ return value.toUpperCase();
+ } else {
+ return value.toLowerCase();
+ }
+ }
+ });
+
+To call these formatters, simply the following will work:
+
+
+
+Formatters must be added before they are used else a template will not be able to access them. Formatters are used at the time of populating the data. You can also target any binding with the "data-format-target". The value of this is the binding to target so to target data-alt binding, set 'data-format-target="alt"'.
+
+### Bindings
+There are a number of different bindings and ways to bind the data. The following attributes are available:
+
+- "data-content" - binds the value supplied to the content of the element (uses $(elem).html(value))
+- "data-content-append" - appends the value to the end of the element (uses $(elem).append(value))
+- "data-content-prepend" - prepends the value to the beginning of the element (uses $(elem).prepend(value))
+- "data-alt" - sets the alt value of the element to the value provided (uses $(elem).attr("alt", value));
+- "data-value" - sets the value attribute of the element to the value provided (uses $(elem).val(value))
+- "data-link" - sets the innerHtml of the element to be a link to the value provided (wraps the content in an <a> tag).
+- "data-link-wrap" - wraps the element in a link to the value provided. Same as "data-link", but the <a> tag wraps the element as well as the content.
+- "data-options" - adds options to a select box. The value for this should reference an array of strings, each option will be output as a separate option. The value will be the same as the displayed text for each option. For a more powerful version of this look at the data-template-bind option.
+- "data-binding-options" - Overrides global binding options passed as function parameters for this binding. For details check the options section below.
+On top of the attributes above, there is also a "data-template-bind" attribute. This is designed to handle more complex situations and allows a wide range of control. The attribute takes a JSON string and allows multiple bindings and options to be set in the one attribute.
+
+The "data-template-bind" value should be an array of objects. Each object represents one complete binding. Each object can contain the following properties:
+
+- "value" (required) - The property representing the value to bind to.
+- "attribute" (required) - The attribute to bind to. This can be any attribute accepted by the jQuery.attr() method or one of the following: "content" - same as data-content, binds the innerHTML, "contentAppend" - same as data-append, appends the value, "contentPrepend" - same as data-prepend, prepends the value, "options" - same as data-options, but provides greater control. The value attribute for this is an object with a value property and a content property, and this will bind the value of the option to the value property, and the innerText of the option to the content property.
+- "formatter" (optional) - provides the formatter to apply to the specific binding. Multiple different attributes can use different formatters using this syntax.
+- "formatOptions" (optional) - the options to pass to the formatter applied.
+- "bindingOptions" (optional) - Overrides global binding options passed as function parameters for this binding. For details check the options section below.
+
+An example of using the "data-template-bind" attribute would be the following:
+
+
+
+### Options
+
+There are a number of options the plugin accepts. These are:
+
+- "overwriteCache" (default false) - Whether to ignore the cache and reload the template (if you've previously loaded the template, but it might have changed, you'll want to set this to true.
+- "complete" (default null) - Callback function to call on complete. Will always be called regardless of success or failure.
+- "success" (default null) - Callback function to call on successful completion.
+- "error" (default, outputting error message to template container) - Callback function to call on error.
+- "errorMessage" (default "There was an error loading the template.") - Error message for the default error callback to use. This will not be used if you set an error callback function.
+- "isFile" (default undefined) - flag to help speed up the process of deciding where to load the template from. Set to true if the template is an external file to load via ajax, false if it's a jQuery selector for an element in the document. Default undefined means the plugin will check first in the document, then attempt to load external file.
+- "paged" (default false) - A boolean flag to indicate whether arrays should be paged.
+- "pageNo" (default 1) - An integer for which page to display if the data is being paged.
+- "elemPerPage" (default 10) - The number of elements to display per page if the data is being paged.
+- "append" (default false) - If set to true, the template will be appended to the element rather than replacing the contents of the element.
+- "prepend" (default false) - If set to true, the template will be prepended to the element rather than replacing the contents of the element. The append option takes priority over prepend, so if both options are set to true, the element is appended and not prepended.
+- "beforeInsert" (default null) - Callback function to be called before inserting the template into the document. The format of the function is function($elem) where $elem is the jQuery object of the populated template about to be inserted into the document.
+- "afterInsert" (default null) - As above, a callback function to be called after inserting the template into the document. The format is the same as above.
+- "bindingOptions" (default all flags false): add flags to ignore certain types of values. {"ignoreUndefined": false, "ignoreNull": false, "ignoreEmptyString": false}. The flags you set here, are overwritten on an element level by those specified in a template with a "data-binding-options" or a "data-template-bind" attribute. Examples can be found in the Examples/OptionalBinding folder.
+
+## Future Plans
+
I would like to develop the plugin further so it would be possible to watch the objects holding the data, so any changes to the data would be reflected in the UI. This would have to be simple, lightweight, and ideally would work just with natural JavaScript objects. I also welcome any ideas as to how the plugin could be improved.
\ No newline at end of file
From d92fe8a4dce931e6959d663c90c078518f26da09 Mon Sep 17 00:00:00 2001
From: Diego Adolf
Date: Thu, 6 Feb 2014 10:32:42 +0100
Subject: [PATCH 32/71] Settings are now inherted in $.loadTemplate calls for
nested templates (optional binding works for nested templates now)
---
Examples/OptionalBinding/example.html | 132 ++++++++++--------
.../jquery.loadTemplate-1.3.2.js | 2 +-
2 files changed, 74 insertions(+), 60 deletions(-)
diff --git a/Examples/OptionalBinding/example.html b/Examples/OptionalBinding/example.html
index 59fdab8..1f59f70 100644
--- a/Examples/OptionalBinding/example.html
+++ b/Examples/OptionalBinding/example.html
@@ -1,59 +1,73 @@
-
-
-
-
-
-
-
-
-
-
-
-
-Loaded with function parameters
-
-
-
-
-
-
-Loaded with template parameters
-
-
-
-
-
-
-Loaded with template as data-bind-template attribute
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+Loaded with function parameters
+
+
+
+
+
+
+Loaded with template parameters
+
+
+
+
+
+
+Loaded with template as data-bind-template attribute
+
+
+
+
+Loaded with nested template with function parameters
+
+
+
diff --git a/jquery-loadTemplate/jquery.loadTemplate-1.3.2.js b/jquery-loadTemplate/jquery.loadTemplate-1.3.2.js
index bd1be3c..6278ac3 100644
--- a/jquery-loadTemplate/jquery.loadTemplate-1.3.2.js
+++ b/jquery-loadTemplate/jquery.loadTemplate-1.3.2.js
@@ -486,7 +486,7 @@
var parentElement = options.parentElement || "div";
var template = options.template || options;
- return $("<" + parentElement + "/>").loadTemplate(template, value);
+ return $("<" + parentElement + "/>").loadTemplate(template, value, settings);
});
$.fn.loadTemplate = loadTemplate;
$.addTemplateFormatter = addTemplateFormatter;
From b0fa5ad281b71103a5231d72f4aefefeb455ba18 Mon Sep 17 00:00:00 2001
From: Diego Adolf
Date: Thu, 6 Feb 2014 10:37:32 +0100
Subject: [PATCH 33/71] Corrected example for optional binding
---
Examples/OptionalBinding/example.html | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/Examples/OptionalBinding/example.html b/Examples/OptionalBinding/example.html
index 1f59f70..2efd244 100644
--- a/Examples/OptionalBinding/example.html
+++ b/Examples/OptionalBinding/example.html
@@ -38,7 +38,7 @@
->>>>>>> b0fa5ad281b71103a5231d72f4aefefeb455ba18
diff --git a/jquery-loadTemplate/jquery.loadTemplate-1.3.4.min.js b/jquery-loadTemplate/jquery.loadTemplate-1.3.4.min.js
deleted file mode 100644
index b957523..0000000
--- a/jquery-loadTemplate/jquery.loadTemplate-1.3.4.min.js
+++ /dev/null
@@ -1 +0,0 @@
-(function(a){var u={},t={},h={};function m(D,z,B){var y=this,x,C,A;z=z||{};C=a.extend({async:true,overwriteCache:false,complete:null,success:null,error:function(){a(this).each(function(){a(this).html(C.errorMessage)})},errorMessage:"There was an error loading the template.",paged:false,pageNo:1,elemPerPage:10,append:false,prepend:false,beforeInsert:null,afterInsert:null},B);if(a.type(z)==="array"){return r.call(this,D,z,C)}if(!g(D)){x=a(D);if(typeof D==="string"&&D.indexOf("#")===0){C.isFile=false}}A=C.isFile||(typeof C.isFile==="undefined"&&(typeof x==="undefined"||x.length===0));if(A&&!C.overwriteCache&&u[D]){p(D,y,z,C)}else{if(A&&!C.overwriteCache&&u.hasOwnProperty(D)){c(D,y,z,C)}else{if(A){l(D,y,z,C)}else{n(x,y,z,C)}}}return this}function b(y,x){if(x){h[y]=x}else{h=a.extend(h,y)}}function g(x){return typeof x==="string"&&x.indexOf("/")>-1}function r(G,y,D){D=D||{};var x=this,H=y.length,A=D.prepend&&!D.append,z=0,F=0,B=false,C;if(D.paged){var E=(D.pageNo-1)*D.elemPerPage;y=y.slice(E,E+D.elemPerPage);H=y.length}C=a.extend({},D,{complete:function(){if(A){x.prepend(this.html())}else{x.append(this.html())}z++;if(z===H||B){if(B&&D&&typeof D.error==="function"){D.error.call(x)}if(D&&typeof D.complete==="function"){D.complete()}}},success:function(){F++;if(F===H){if(D&&typeof D.success==="function"){D.success()}}},error:function(){B=true}});if(!D.append&&!D.prepend){x.html("")}if(A){y.reverse()}a(y).each(function(){var I=a("");m.call(I,G,this,C);if(B){return false}});return this}function c(A,y,x,z){if(t[A]){t[A].push({data:x,selection:y,settings:z})}else{t[A]=[{data:x,selection:y,settings:z}]}}function p(B,z,y,A){var x=u[B].clone();o.call(z,x,y,A);if(typeof A.success==="function"){A.success()}}function v(){return new Date().getTime()}function w(x){if(x.indexOf("?")!==-1){return x+"&_="+v()}else{return x+"?_="+v()}}function l(B,z,y,A){var x=a("");u[B]=null;var C=B;if(A.overwriteCache){C=w(C)}a.ajax({url:C,async:A.async,success:function(D){x.html(D);k(x,B,z,y,A)},error:function(){j(B,z,y,A)}})}function n(x,A,z,B){var y=a("");if(x.is("script")){x=a.parseHTML(a.trim(x.html()))}y.html(x);o.call(A,y,z,B);if(typeof B.success==="function"){B.success()}}function o(z,x,y){f(z,x);a(this).each(function(){var A=a(z.html());if(y.beforeInsert){y.beforeInsert(A)}if(y.append){a(this).append(A)}else{if(y.prepend){a(this).prepend(A)}else{a(this).html(A)}}if(y.afterInsert){y.afterInsert(A)}});if(typeof y.complete==="function"){y.complete.call(a(this))}}function j(A,y,x,z){var B;if(typeof z.error==="function"){z.error.call(y)}a(t[A]).each(function(C,D){if(typeof D.settings.error==="function"){D.settings.error.call(D.selection)}});if(typeof z.complete==="function"){z.complete.call(y)}while(t[A]&&(B=t[A].shift())){if(typeof B.settings.complete==="function"){B.settings.complete.call(B.selection)}}if(typeof t[A]!=="undefined"&&t[A].length>0){t[A]=[]}}function k(x,B,z,y,A){var C;u[B]=x.clone();o.call(z,x,y,A);if(typeof A.success==="function"){A.success.call(z)}while(t[B]&&(C=t[B].shift())){o.call(C.selection,u[B].clone(),C.data,C.settings);if(typeof C.settings.success==="function"){C.settings.success.call(C.selection)}}}function f(y,x){x=x||{};s("data-content",y,x,function(z,A){z.html(e(z,A,"content"))});s("data-content-append",y,x,function(z,A){z.append(e(z,A,"content"))});s("data-content-prepend",y,x,function(z,A){z.prepend(e(z,A,"content"))});s("data-content-text",y,x,function(z,A){z.text(e(z,A,"content"))});s("data-src",y,x,function(z,A){z.attr("src",e(z,A,"src"))},function(z){z.remove()});s("data-alt",y,x,function(z,A){z.attr("alt",e(z,A,"alt"))});s("data-value",y,x,function(z,A){z.attr("value",e(z,A,"value"))});s("data-link",y,x,function(z,B){var A=a("");A.attr("href",e(z,B,"link"));A.html(z.html());z.html(A)});s("data-link-wrap",y,x,function(z,B){var A=a("");A.attr("href",e(z,B,"link-wrap"));z.wrap(A)});s("data-options",y,x,function(z,A){a(A).each(function(){var B=a("");B.attr("value",this).text(this).appendTo(z)})});q(y,x)}function s(x,B,y,z,A){a("["+x+"]",B).each(function(){var C=a(this),D=C.attr(x),E=i(y,D);C.removeAttr(x);if(typeof E!=="undefined"&&z){z(C,E)}else{if(A){A(C)}}});return}function q(y,x){a("[data-template-bind]",y).each(function(){var z=a(this),A=a.parseJSON(z.attr("data-template-bind"));z.removeAttr("data-template-bind");a(A).each(function(){var C;if(typeof(this.value)==="object"){C=i(x,this.value.data)}else{C=i(x,this.value)}if(typeof C!=="undefined"&&this.attribute){switch(this.attribute){case"content":z.html(d(z,C,this));break;case"contentAppend":z.append(d(z,C,this));break;case"contentPrepend":z.prepend(d(z,C,this));break;case"contentText":z.text(d(z,C,this));break;case"options":var B=this;a(C).each(function(){var D=a("");D.attr("value",this[B.value.value]).text(d(z,this[B.value.content],B)).attr("selected",typeof this[B.value.selected]==undefined?false:this[B.value.selected]).appendTo(z)});break;default:z.attr(this.attribute,d(z,C,this))}}})})}function d(x,z,y){if(y.formatter&&h[y.formatter]){return h[y.formatter].call(x,z,y.formatOptions)}return z}function i(x,y){if(y==="this"){return x}var z=y.split("."),A,B=x;while((A=z.shift())&&typeof B!=="undefined"){B=B[A]}return B}function e(x,C,y){var B=x.attr("data-format-target"),A;if(B===y||(!B&&y==="content")){A=x.attr("data-format");if(A&&typeof h[A]==="function"){var z=x.attr("data-format-options");return h[A].call(x[0],C,z)}}return C}b("nestedTemplateFormatter",function(A,x){if(!x){return}if(typeof x==="string"&&x[0]==="{"){x=a.parseJSON(x)}var y=x.parentElement||"div";var z=x.template||x;return a("<"+y+"/>").loadTemplate(z,A)});a.fn.loadTemplate=m;a.addTemplateFormatter=b})(jQuery);
\ No newline at end of file
diff --git a/jquery-loadTemplate/jquery.loadTemplate-1.3.4.js b/jquery-loadTemplate/jquery.loadTemplate-1.4.0.js
similarity index 77%
rename from jquery-loadTemplate/jquery.loadTemplate-1.3.4.js
rename to jquery-loadTemplate/jquery.loadTemplate-1.4.0.js
index 9b69ff6..23dfc5a 100644
--- a/jquery-loadTemplate/jquery.loadTemplate-1.3.4.js
+++ b/jquery-loadTemplate/jquery.loadTemplate-1.4.0.js
@@ -2,13 +2,13 @@
"use strict";
var templates = {},
queue = {},
- formatters = {},
- settings;
+ formatters = {};
function loadTemplate(template, data, options) {
var $that = this,
$template,
- isFile;
+ isFile,
+ settings;
data = data || {};
@@ -31,11 +31,11 @@
prepend: false,
beforeInsert: null,
afterInsert: null,
- bindingOptions: {
- ignoreUndefined: false,
- ignoreNull: false,
- ignoreEmptyString: false
- }
+ bindingOptions: {
+ ignoreUndefined: false,
+ ignoreNull: false,
+ ignoreEmptyString: false
+ }
}, options);
if ($.type(data) === "array") {
@@ -208,7 +208,7 @@
}
function prepareTemplate(template, data, settings) {
- bindData(template, data);
+ bindData(template, data, settings);
$(this).each(function () {
var $templateHtml = $(template.html());
@@ -279,74 +279,74 @@
}
}
- function bindData(template, data) {
+ function bindData(template, data, settings) {
data = data || {};
- processElements("data-content", template, data, function ($elem, value) {
- $elem.html(applyFormatters($elem, value, "content"));
+ processElements("data-content", template, data, settings, function ($elem, value) {
+ $elem.html(applyFormatters($elem, value, "content", settings));
});
- processElements("data-content-append", template, data, function ($elem, value) {
- $elem.append(applyFormatters($elem, value, "content"));
+ processElements("data-content-append", template, data, settings, function ($elem, value) {
+ $elem.append(applyFormatters($elem, value, "content", settings));
});
- processElements("data-content-prepend", template, data, function ($elem, value) {
- $elem.prepend(applyFormatters($elem, value, "content"));
+ processElements("data-content-prepend", template, data, settings, function ($elem, value) {
+ $elem.prepend(applyFormatters($elem, value, "content", settings));
});
- processElements("data-content-text", template, data, function ($elem, value) {
- $elem.text(applyFormatters($elem, value, "content"));
+ processElements("data-content-text", template, data, settings, function ($elem, value) {
+ $elem.text(applyFormatters($elem, value, "content", settings));
});
- processElements("data-src", template, data, function ($elem, value) {
- $elem.attr("src", applyFormatters($elem, value, "src"));
+ processElements("data-src", template, data, settings, function ($elem, value) {
+ $elem.attr("src", applyFormatters($elem, value, "src", settings));
}, function ($elem) {
$elem.remove();
});
- processElements("data-alt", template, data, function ($elem, value) {
- $elem.attr("alt", applyFormatters($elem, value, "alt"));
+ processElements("data-alt", template, data, settings, function ($elem, value) {
+ $elem.attr("alt", applyFormatters($elem, value, "alt", settings));
});
- processElements("data-value", template, data, function ($elem, value) {
- $elem.attr("value", applyFormatters($elem, value, "value"));
+ processElements("data-value", template, data, settings, function ($elem, value) {
+ $elem.attr("value", applyFormatters($elem, value, "value", settings));
});
- processElements("data-link", template, data, function ($elem, value) {
+ processElements("data-link", template, data, settings, function ($elem, value) {
var $linkElem = $("");
- $linkElem.attr("href", applyFormatters($elem, value, "link"));
+ $linkElem.attr("href", applyFormatters($elem, value, "link", settings));
$linkElem.html($elem.html());
$elem.html($linkElem);
});
- processElements("data-link-wrap", template, data, function ($elem, value) {
+ processElements("data-link-wrap", template, data, settings, function ($elem, value) {
var $linkElem = $("");
- $linkElem.attr("href", applyFormatters($elem, value, "link-wrap"));
+ $linkElem.attr("href", applyFormatters($elem, value, "link-wrap", settings));
$elem.wrap($linkElem);
});
- processElements("data-options", template, data, function ($elem, value) {
+ processElements("data-options", template, data, settings, function ($elem, value) {
$(value).each(function () {
var $option = $("");
$option.attr('value', this).text(this).appendTo($elem);
});
});
- processAllElements(template, data);
+ processAllElements(template, data, settings);
}
- function processElements(attribute, template, data, dataBindFunction, noDataFunction) {
+ function processElements(attribute, template, data, settings, dataBindFunction, noDataFunction) {
$("[" + attribute + "]", template).each(function () {
var $this = $(this),
param = $this.attr(attribute),
value = getValue(data, param);
- if (!valueIsAllowedByBindingOptions($this, value)) {
- $this.remove();
- return;
- }
-
- $this.removeAttr(attribute);
+ if (!valueIsAllowedByBindingOptions($this, value, settings)) {
+ $this.remove();
+ return;
+ }
+
+ $this.removeAttr(attribute);
if (typeof value !== 'undefined' && dataBindFunction) {
dataBindFunction($this, value);
@@ -357,44 +357,44 @@
return;
}
- function valueIsAllowedByBindingOptions(bindingOptionsContainer, value) {
-
- var bindingOptions = getBindingOptions(bindingOptionsContainer);
-
- if (bindingOptions.ignoreUndefined && typeof value === "undefined") {
- return false;
-
- } else if (bindingOptions.ignoreNull && value === null){
- return false;
-
- } else if (bindingOptions.ignoreEmptyString && value === "") {
- return false;
-
- } else {
- return true;
- }
- }
-
- function getBindingOptions(bindingOptionsContainer) {
-
- var bindingOptions = {};
-
- // binding options passed as template attribute, i.e. 'data-binding-options'
- if (bindingOptionsContainer instanceof jQuery && bindingOptionsContainer.attr("data-binding-options")) {
-
- bindingOptions = $.parseJSON(bindingOptionsContainer.attr("data-binding-options"));
- bindingOptionsContainer.removeAttr("data-binding-options");
-
- // binding options defined in a "data-template-bind" attribute
- } else if(typeof bindingOptionsContainer === "object" && bindingOptionsContainer.hasOwnProperty('bindingOptions')) {
- bindingOptions = bindingOptionsContainer.bindingOptions;
- }
-
- // extend general bindingOptions with specific settings
- return $.extend({}, settings.bindingOptions, bindingOptions);
- }
-
- function processAllElements(template, data) {
+ function valueIsAllowedByBindingOptions(bindingOptionsContainer, value, settings) {
+
+ var bindingOptions = getBindingOptions(bindingOptionsContainer, settings);
+
+ if (bindingOptions.ignoreUndefined && typeof value === "undefined") {
+ return false;
+
+ } else if (bindingOptions.ignoreNull && value === null) {
+ return false;
+
+ } else if (bindingOptions.ignoreEmptyString && value === "") {
+ return false;
+
+ } else {
+ return true;
+ }
+ }
+
+ function getBindingOptions(bindingOptionsContainer, settings) {
+
+ var bindingOptions = {};
+
+ // binding options passed as template attribute, i.e. 'data-binding-options'
+ if (bindingOptionsContainer instanceof jQuery && bindingOptionsContainer.attr("data-binding-options")) {
+
+ bindingOptions = $.parseJSON(bindingOptionsContainer.attr("data-binding-options"));
+ bindingOptionsContainer.removeAttr("data-binding-options");
+
+ // binding options defined in a "data-template-bind" attribute
+ } else if (typeof bindingOptionsContainer === "object" && bindingOptionsContainer.hasOwnProperty('bindingOptions')) {
+ bindingOptions = bindingOptionsContainer.bindingOptions;
+ }
+
+ // extend general bindingOptions with specific settings
+ return $.extend({}, settings.bindingOptions, bindingOptions);
+ }
+
+ function processAllElements(template, data, settings) {
$("[data-template-bind]", template).each(function () {
var $this = $(this),
param = $.parseJSON($this.attr("data-template-bind"));
@@ -410,12 +410,12 @@
value = getValue(data, this.value);
}
if (this.attribute) {
-
- if (!valueIsAllowedByBindingOptions(this, value)) {
- $this.remove();
- return;
- }
-
+
+ if (!valueIsAllowedByBindingOptions(this, value, settings)) {
+ $this.remove();
+ return;
+ }
+
switch (this.attribute) {
case "content":
$this.html(applyDataBindFormatters($this, value, this));
@@ -448,9 +448,11 @@
});
}
- function applyDataBindFormatters($elem, value, data) {
+ function applyDataBindFormatters($elem, value, data, settings) {
if (data.formatter && formatters[data.formatter]) {
- return formatters[data.formatter].call($elem, value, data.formatOptions);
+ return (function (formatterSettings) {
+ return formatters[data.formatter].call($elem, value, data.formatOptions, formatterSettings);
+ })(settings);
}
return value;
}
@@ -470,7 +472,7 @@
return value;
}
- function applyFormatters($elem, value, attr) {
+ function applyFormatters($elem, value, attr, settings) {
var formatterTarget = $elem.attr("data-format-target"),
formatter;
@@ -478,13 +480,15 @@
formatter = $elem.attr("data-format");
if (formatter && typeof formatters[formatter] === "function") {
var formatOptions = $elem.attr("data-format-options");
- return formatters[formatter].call($elem[0], value, formatOptions);
+ return (function (formatterSettings) {
+ return formatters[formatter].call($elem[0], value, formatOptions, $.extend({}, formatterSettings));
+ })(settings);
}
}
return value;
}
- addTemplateFormatter("nestedTemplateFormatter", function (value, options) {
+ addTemplateFormatter("nestedTemplateFormatter", function (value, options, internalSettings) {
if (!options) {
return;
}
@@ -495,7 +499,7 @@
var parentElement = options.parentElement || "div";
var template = options.template || options;
- return $("<" + parentElement + "/>").loadTemplate(template, value, settings);
+ return $("<" + parentElement + "/>").loadTemplate(template, value, internalSettings);
});
$.fn.loadTemplate = loadTemplate;
$.addTemplateFormatter = addTemplateFormatter;
diff --git a/jquery-loadTemplate/jquery.loadTemplate-1.4.0.min.js b/jquery-loadTemplate/jquery.loadTemplate-1.4.0.min.js
new file mode 100644
index 0000000..0ae3334
--- /dev/null
+++ b/jquery-loadTemplate/jquery.loadTemplate-1.4.0.min.js
@@ -0,0 +1 @@
+(function(a){var v={},u={},h={};function n(F,B,D){var A=this,z,C,E;B=B||{};E=a.extend(true,{async:true,overwriteCache:false,complete:null,success:null,error:function(){a(this).each(function(){a(this).html(E.errorMessage)})},errorMessage:"There was an error loading the template.",paged:false,pageNo:1,elemPerPage:10,append:false,prepend:false,beforeInsert:null,afterInsert:null,bindingOptions:{ignoreUndefined:false,ignoreNull:false,ignoreEmptyString:false}},D);if(a.type(B)==="array"){return s.call(this,F,B,E)}if(!g(F)){z=a(F);if(typeof F==="string"&&F.indexOf("#")===0){E.isFile=false}}C=E.isFile||(typeof E.isFile==="undefined"&&(typeof z==="undefined"||z.length===0));if(C&&!E.overwriteCache&&v[F]){q(F,A,B,E)}else{if(C&&!E.overwriteCache&&v.hasOwnProperty(F)){c(F,A,B,E)}else{if(C){m(F,A,B,E)}else{o(z,A,B,E)}}}return this}function b(A,z){if(z){h[A]=z}else{h=a.extend(h,A)}}function g(z){return typeof z==="string"&&z.indexOf("/")>-1}function s(I,A,F){F=F||{};var z=this,J=A.length,C=F.prepend&&!F.append,B=0,H=0,D=false,E;if(F.paged){var G=(F.pageNo-1)*F.elemPerPage;A=A.slice(G,G+F.elemPerPage);J=A.length}E=a.extend({},F,{complete:function(){if(C){z.prepend(this.html())}else{z.append(this.html())}B++;if(B===J||D){if(D&&F&&typeof F.error==="function"){F.error.call(z)}if(F&&typeof F.complete==="function"){F.complete()}}},success:function(){H++;if(H===J){if(F&&typeof F.success==="function"){F.success()}}},error:function(){D=true}});if(!F.append&&!F.prepend){z.html("")}if(C){A.reverse()}a(A).each(function(){var K=a("");n.call(K,I,this,E);if(D){return false}});return this}function c(C,A,z,B){if(u[C]){u[C].push({data:z,selection:A,settings:B})}else{u[C]=[{data:z,selection:A,settings:B}]}}function q(D,B,A,C){var z=v[D].clone();p.call(B,z,A,C);if(typeof C.success==="function"){C.success()}}function w(){return new Date().getTime()}function x(z){if(z.indexOf("?")!==-1){return z+"&_="+w()}else{return z+"?_="+w()}}function m(D,B,A,C){var z=a("");v[D]=null;var E=D;if(C.overwriteCache){E=x(E)}a.ajax({url:E,async:C.async,success:function(F){z.html(F);l(z,D,B,A,C)},error:function(){k(D,B,A,C)}})}function o(z,C,B,D){var A=a("");if(z.is("script")){z=a.parseHTML(a.trim(z.html()))}A.html(z);p.call(C,A,B,D);if(typeof D.success==="function"){D.success()}}function p(B,z,A){f(B,z,A);a(this).each(function(){var C=a(B.html());if(A.beforeInsert){A.beforeInsert(C)}if(A.append){a(this).append(C)}else{if(A.prepend){a(this).prepend(C)}else{a(this).html(C)}}if(A.afterInsert){A.afterInsert(C)}});if(typeof A.complete==="function"){A.complete.call(a(this))}}function k(C,A,z,B){var D;if(typeof B.error==="function"){B.error.call(A)}a(u[C]).each(function(E,F){if(typeof F.settings.error==="function"){F.settings.error.call(F.selection)}});if(typeof B.complete==="function"){B.complete.call(A)}while(u[C]&&(D=u[C].shift())){if(typeof D.settings.complete==="function"){D.settings.complete.call(D.selection)}}if(typeof u[C]!=="undefined"&&u[C].length>0){u[C]=[]}}function l(z,D,B,A,C){var E;v[D]=z.clone();p.call(B,z,A,C);if(typeof C.success==="function"){C.success.call(B)}while(u[D]&&(E=u[D].shift())){p.call(E.selection,v[D].clone(),E.data,E.settings);if(typeof E.settings.success==="function"){E.settings.success.call(E.selection)}}}function f(B,z,A){z=z||{};t("data-content",B,z,A,function(C,D){C.html(e(C,D,"content",A))});t("data-content-append",B,z,A,function(C,D){C.append(e(C,D,"content",A))});t("data-content-prepend",B,z,A,function(C,D){C.prepend(e(C,D,"content",A))});t("data-content-text",B,z,A,function(C,D){C.text(e(C,D,"content",A))});t("data-src",B,z,A,function(C,D){C.attr("src",e(C,D,"src",A))},function(C){C.remove()});t("data-alt",B,z,A,function(C,D){C.attr("alt",e(C,D,"alt",A))});t("data-value",B,z,A,function(C,D){C.attr("value",e(C,D,"value",A))});t("data-link",B,z,A,function(C,E){var D=a("");D.attr("href",e(C,E,"link",A));D.html(C.html());C.html(D)});t("data-link-wrap",B,z,A,function(C,E){var D=a("");D.attr("href",e(C,E,"link-wrap",A));C.wrap(D)});t("data-options",B,z,A,function(C,D){a(D).each(function(){var E=a("");E.attr("value",this).text(this).appendTo(C)})});r(B,z,A)}function t(z,E,A,D,B,C){a("["+z+"]",E).each(function(){var F=a(this),G=F.attr(z),H=j(A,G);if(!y(F,H,D)){F.remove();return}F.removeAttr(z);if(typeof H!=="undefined"&&B){B(F,H)}else{if(C){C(F)}}});return}function y(A,C,B){var z=i(A,B);if(z.ignoreUndefined&&typeof C==="undefined"){return false}else{if(z.ignoreNull&&C===null){return false}else{if(z.ignoreEmptyString&&C===""){return false}else{return true}}}}function i(A,B){var z={};if(A instanceof jQuery&&A.attr("data-binding-options")){z=a.parseJSON(A.attr("data-binding-options"));A.removeAttr("data-binding-options")}else{if(typeof A==="object"&&A.hasOwnProperty("bindingOptions")){z=A.bindingOptions}}return a.extend({},B.bindingOptions,z)}function r(B,z,A){a("[data-template-bind]",B).each(function(){var C=a(this),D=a.parseJSON(C.attr("data-template-bind"));C.removeAttr("data-template-bind");a(D).each(function(){var F;if(typeof(this.value)==="object"){F=j(z,this.value.data)}else{F=j(z,this.value)}if(this.attribute){if(!y(this,F,A)){C.remove();return}switch(this.attribute){case"content":C.html(d(C,F,this));break;case"contentAppend":C.append(d(C,F,this));break;case"contentPrepend":C.prepend(d(C,F,this));break;case"contentText":C.text(d(C,F,this));break;case"options":var E=this;a(F).each(function(){var G=a("");G.attr("value",this[E.value.value]).text(d(C,this[E.value.content],E)).attr("selected",typeof this[E.value.selected]==undefined?false:this[E.value.selected]).appendTo(C)});break;default:C.attr(this.attribute,d(C,F,this))}}})})}function d(z,C,A,B){if(A.formatter&&h[A.formatter]){return(function(D){return h[A.formatter].call(z,C,A.formatOptions,D)})(B)}return C}function j(z,A){if(A==="this"){return z}var B=A.split("."),C,D=z;while((C=B.shift())&&typeof D!=="undefined"){D=D[C]}return D}function e(z,F,A,E){var D=z.attr("data-format-target"),C;if(D===A||(!D&&A==="content")){C=z.attr("data-format");if(C&&typeof h[C]==="function"){var B=z.attr("data-format-options");return(function(G){return h[C].call(z[0],F,B,a.extend({},G))})(E)}}return F}b("nestedTemplateFormatter",function(D,A,z){if(!A){return}if(typeof A==="string"&&A[0]==="{"){A=a.parseJSON(A)}var B=A.parentElement||"div";var C=A.template||A;return a("<"+B+"/>").loadTemplate(C,D,z)});a.fn.loadTemplate=n;a.addTemplateFormatter=b})(jQuery);
\ No newline at end of file
diff --git a/loadTemplate.jquery.json b/loadTemplate.jquery.json
index 80a71a6..1058cb0 100644
--- a/loadTemplate.jquery.json
+++ b/loadTemplate.jquery.json
@@ -6,7 +6,7 @@
"templates",
"templating"
],
- "version": "1.3.4",
+ "version": "1.4.0",
"author": {
"name": "Paul Burgess and other contributors",
"url": "https://github.com/codepb/jquery-template"
diff --git a/readme.md b/readme.md
index b9c0c1d..18013cf 100644
--- a/readme.md
+++ b/readme.md
@@ -1,4 +1,3 @@
-<<<<<<< HEAD
# jQuery.loadTemplate
jQuery Template is a jQuery plugin that makes using templates easy and quick. The plugin supports loading HTML files as templates, or taking a jQuery object as the template (usually using script tags to hold the template).
@@ -125,160 +124,6 @@ An example of using the "data-template-bind" attribute would be the following:
There are a number of options the plugin accepts. These are:
-- "overwriteCache" (default false) - Whether to ignore the cache and reload the template (if you've previously loaded the template, but it might have changed, you'll want to set this to true.
-- "complete" (default null) - Callback function to call on complete. Will always be called regardless of success or failure.
-- "success" (default null) - Callback function to call on successful completion.
-- "error" (default, outputting error message to template container) - Callback function to call on error.
-- "errorMessage" (default "There was an error loading the template.") - Error message for the default error callback to use. This will not be used if you set an error callback function.
-- "isFile" (default undefined) - flag to help speed up the process of deciding where to load the template from. Set to true if the template is an external file to load via ajax, false if it's a jQuery selector for an element in the document. Default undefined means the plugin will check first in the document, then attempt to load external file.
-- "paged" (default false) - A boolean flag to indicate whether arrays should be paged.
-- "pageNo" (default 1) - An integer for which page to display if the data is being paged.
-- "elemPerPage" (default 10) - The number of elements to display per page if the data is being paged.
-- "append" (default false) - If set to true, the template will be appended to the element rather than replacing the contents of the element.
-- "prepend" (default false) - If set to true, the template will be prepended to the element rather than replacing the contents of the element. The append option takes priority over prepend, so if both options are set to true, the element is appended and not prepended.
-- "beforeInsert" (default null) - Callback function to be called before inserting the template into the document. The format of the function is function($elem) where $elem is the jQuery object of the populated template about to be inserted into the document.
-- "afterInsert" (default null) - As above, a callback function to be called after inserting the template into the document. The format is the same as above.
-
-## Future Plans
-
-=======
-# jQuery.loadTemplate
-
-jQuery Template is a jQuery plugin that makes using templates easy and quick. The plugin supports loading HTML files as templates, or taking a jQuery object as the template (usually using script tags to hold the template).
-
-## Features
-
-jQuery.LoadTemplate provides the following:
-
-- Define Templates to display data
-- Provide Formatters to process data into a more readable format
-- Cache templates and data client side and pass processing to the client, allowing for a great user experience.
-- Powerful but simple syntax, utilising pure html for templates.
-
-## Getting Started
-
-Simply clone the repo. The only file required is the jquery.loadTemplate-version.js file in the jquery.loadTemplate folder. There is also a folder for examples in the same folder. Take a look at the index file in here for examples and the code to create the examples.
-
-To see examples of usage, visit the project page: [http://codepb.github.io/jquery-template/](http://codepb.github.io/jquery-template/)
-
-## Potential Applications
-
-jQuery.loadTemplate was originally designed with a single page application for a blog in mind. The idea was to create templates for blog posts, post snippets, etc. This could then be called from the client when required, and cached. The post data was sent as a JSON object from the server, and processed into the templates using the plugin. This meant a very light load on the server, and a great user experience, with smooth page transitions, and JavaScript engines doing all the work.
-
-However I saw many other potential applications for this. Any application that deals with a large amount of data displayed in a regular format, for example search results, live commentary, blogs, online stores, social media sites, and the list could go on.
-
-## How it works
-
-The plugin parses a template using data attributes to populate the data. Simply pass in a JavaScript object, and the plugin does the rest.
-
-An example template is below:
-
-
-
-And to use this do the following:
-
- $("#template-container").loadTemplate($("#template"),
- {
- author: 'Joe Bloggs',
- date: '25th May 2013',
- authorPicture: 'Authors/JoeBloggs.jpg',
- post: 'This is the contents of my post'
- });
-
-Similarly the content of the template could be held in a separate html file without the enclosing script tag, and used like the following:
-
- $("#template-container").loadTemplate("Templates/template.html",
- {
- author: 'Joe Bloggs',
- date: '25th May 2013',
- authorPicture: 'Authors/JoeBloggs.jpg',
- post: 'This is the contents of my post'
- });
-
-Several options can be passed as function parameters. For example, to specify that 'null' values should not be rendered, load the template like this:
-
- $("#template-container").loadTemplate("Templates/template.html",
- {
- author: 'Joe Bloggs',
- date: null,
- authorPicture: 'Authors/JoeBloggs.jpg',
- post: 'This is the contents of my post'
- }, {"ignoreNull": true}});
-
-In addition, the plugin has a number of data-... attributes that can be used to populate various attributes with the data. There is also the powerful data-template-bind attribute that accepts a JSON object, enabling binding to any attribute, or the content of the element.
-
-### Data Formatters
-
-It is also possible to define data formatters. These are assigned through the `$.addTemplateFormatter` method. This function either accepts a map of functions and the keys that they will be referenced by, or a single function with a single key as two separate parameters. Each formatter takes two values, the value being assigned, and a template to use to define how this data is displayed. The data-format-template may be empty. Example usage of this is below:
-
- $.addTemplateFormatter("UpperCaseFormatter",
- function(value, template) {
- return value.toUpperCase();
- });
-
-Alternatively with a map:
-
- $.addTemplateFormatter({
- UpperCaseFormatter : function(value, template) {
- return value.toUpperCase();
- },
- LowerCaseFormatter : function(value, template) {
- return value.toLowerCase();
- },
- SameCaseFormatter : function(value, template) {
- if(template == "upper") {
- return value.toUpperCase();
- } else {
- return value.toLowerCase();
- }
- }
- });
-
-To call these formatters, simply the following will work:
-
-
-
-Formatters must be added before they are used else a template will not be able to access them. Formatters are used at the time of populating the data. You can also target any binding with the "data-format-target". The value of this is the binding to target so to target data-alt binding, set 'data-format-target="alt"'.
-
-### Bindings
-There are a number of different bindings and ways to bind the data. The following attributes are available:
-
-- "data-content" - binds the value supplied to the content of the element (uses $(elem).html(value))
-- "data-content-append" - appends the value to the end of the element (uses $(elem).append(value))
-- "data-content-prepend" - prepends the value to the beginning of the element (uses $(elem).prepend(value))
-- "data-alt" - sets the alt value of the element to the value provided (uses $(elem).attr("alt", value));
-- "data-value" - sets the value attribute of the element to the value provided (uses $(elem).val(value))
-- "data-link" - sets the innerHtml of the element to be a link to the value provided (wraps the content in an <a> tag).
-- "data-link-wrap" - wraps the element in a link to the value provided. Same as "data-link", but the <a> tag wraps the element as well as the content.
-- "data-options" - adds options to a select box. The value for this should reference an array of strings, each option will be output as a separate option. The value will be the same as the displayed text for each option. For a more powerful version of this look at the data-template-bind option.
-- "data-binding-options" - Overrides global binding options passed as function parameters for this binding. For details check the options section below.
-On top of the attributes above, there is also a "data-template-bind" attribute. This is designed to handle more complex situations and allows a wide range of control. The attribute takes a JSON string and allows multiple bindings and options to be set in the one attribute.
-
-The "data-template-bind" value should be an array of objects. Each object represents one complete binding. Each object can contain the following properties:
-
-- "value" (required) - The property representing the value to bind to.
-- "attribute" (required) - The attribute to bind to. This can be any attribute accepted by the jQuery.attr() method or one of the following: "content" - same as data-content, binds the innerHTML, "contentAppend" - same as data-append, appends the value, "contentPrepend" - same as data-prepend, prepends the value, "options" - same as data-options, but provides greater control. The value attribute for this is an object with a value property and a content property, and this will bind the value of the option to the value property, and the innerText of the option to the content property.
-- "formatter" (optional) - provides the formatter to apply to the specific binding. Multiple different attributes can use different formatters using this syntax.
-- "formatOptions" (optional) - the options to pass to the formatter applied.
-- "bindingOptions" (optional) - Overrides global binding options passed as function parameters for this binding. For details check the options section below.
-
-An example of using the "data-template-bind" attribute would be the following:
-
-
-
-### Options
-
-There are a number of options the plugin accepts. These are:
-
- "overwriteCache" (default false) - Whether to ignore the cache and reload the template (if you've previously loaded the template, but it might have changed, you'll want to set this to true.
- "complete" (default null) - Callback function to call on complete. Will always be called regardless of success or failure.
- "success" (default null) - Callback function to call on successful completion.
@@ -296,5 +141,4 @@ There are a number of options the plugin accepts. These are:
## Future Plans
->>>>>>> b0fa5ad281b71103a5231d72f4aefefeb455ba18
I would like to develop the plugin further so it would be possible to watch the objects holding the data, so any changes to the data would be reflected in the UI. This would have to be simple, lightweight, and ideally would work just with natural JavaScript objects. I also welcome any ideas as to how the plugin could be improved.
\ No newline at end of file
diff --git a/tests/index.html b/tests/index.html
index 0ecb084..d3e8ad8 100644
--- a/tests/index.html
+++ b/tests/index.html
@@ -3,7 +3,7 @@
loadTemplate Test Suite
-
+
From 41c476f38c52ffc87428630fb6fdd8888b6b381e Mon Sep 17 00:00:00 2001
From: Paul Burgess
Date: Sat, 22 Feb 2014 23:35:18 +0000
Subject: [PATCH 35/71] Temp fix for nested error + template tag support
Implemented temporary fix for the nested template error. Now also
support template html tags for templates, as well as script tags
---
Examples/SimpleExample/example.html | 24 ++++++++++++++++++-
Examples/index.html | 2 +-
.../jquery.loadTemplate-1.4.0.min.js | 1 -
...-1.4.0.js => jquery.loadTemplate-1.4.1.js} | 12 ++++++----
.../jquery.loadTemplate-1.4.1.min.js | 1 +
loadTemplate.jquery.json | 2 +-
tests/index.html | 2 +-
7 files changed, 34 insertions(+), 10 deletions(-)
delete mode 100644 jquery-loadTemplate/jquery.loadTemplate-1.4.0.min.js
rename jquery-loadTemplate/{jquery.loadTemplate-1.4.0.js => jquery.loadTemplate-1.4.1.js} (98%)
create mode 100644 jquery-loadTemplate/jquery.loadTemplate-1.4.1.min.js
diff --git a/Examples/SimpleExample/example.html b/Examples/SimpleExample/example.html
index 6629c4d..2a169b7 100644
--- a/Examples/SimpleExample/example.html
+++ b/Examples/SimpleExample/example.html
@@ -13,6 +13,8 @@
Example of loading a template from a script tag within the same document.
+
+
+
+
+
+
+
diff --git a/Examples/index.html b/Examples/index.html
index b17919d..97b7e80 100644
--- a/Examples/index.html
+++ b/Examples/index.html
@@ -9,7 +9,7 @@
-
+
diff --git a/jquery-loadTemplate/jquery.loadTemplate-1.4.0.min.js b/jquery-loadTemplate/jquery.loadTemplate-1.4.0.min.js
deleted file mode 100644
index 0ae3334..0000000
--- a/jquery-loadTemplate/jquery.loadTemplate-1.4.0.min.js
+++ /dev/null
@@ -1 +0,0 @@
-(function(a){var v={},u={},h={};function n(F,B,D){var A=this,z,C,E;B=B||{};E=a.extend(true,{async:true,overwriteCache:false,complete:null,success:null,error:function(){a(this).each(function(){a(this).html(E.errorMessage)})},errorMessage:"There was an error loading the template.",paged:false,pageNo:1,elemPerPage:10,append:false,prepend:false,beforeInsert:null,afterInsert:null,bindingOptions:{ignoreUndefined:false,ignoreNull:false,ignoreEmptyString:false}},D);if(a.type(B)==="array"){return s.call(this,F,B,E)}if(!g(F)){z=a(F);if(typeof F==="string"&&F.indexOf("#")===0){E.isFile=false}}C=E.isFile||(typeof E.isFile==="undefined"&&(typeof z==="undefined"||z.length===0));if(C&&!E.overwriteCache&&v[F]){q(F,A,B,E)}else{if(C&&!E.overwriteCache&&v.hasOwnProperty(F)){c(F,A,B,E)}else{if(C){m(F,A,B,E)}else{o(z,A,B,E)}}}return this}function b(A,z){if(z){h[A]=z}else{h=a.extend(h,A)}}function g(z){return typeof z==="string"&&z.indexOf("/")>-1}function s(I,A,F){F=F||{};var z=this,J=A.length,C=F.prepend&&!F.append,B=0,H=0,D=false,E;if(F.paged){var G=(F.pageNo-1)*F.elemPerPage;A=A.slice(G,G+F.elemPerPage);J=A.length}E=a.extend({},F,{complete:function(){if(C){z.prepend(this.html())}else{z.append(this.html())}B++;if(B===J||D){if(D&&F&&typeof F.error==="function"){F.error.call(z)}if(F&&typeof F.complete==="function"){F.complete()}}},success:function(){H++;if(H===J){if(F&&typeof F.success==="function"){F.success()}}},error:function(){D=true}});if(!F.append&&!F.prepend){z.html("")}if(C){A.reverse()}a(A).each(function(){var K=a("");n.call(K,I,this,E);if(D){return false}});return this}function c(C,A,z,B){if(u[C]){u[C].push({data:z,selection:A,settings:B})}else{u[C]=[{data:z,selection:A,settings:B}]}}function q(D,B,A,C){var z=v[D].clone();p.call(B,z,A,C);if(typeof C.success==="function"){C.success()}}function w(){return new Date().getTime()}function x(z){if(z.indexOf("?")!==-1){return z+"&_="+w()}else{return z+"?_="+w()}}function m(D,B,A,C){var z=a("");v[D]=null;var E=D;if(C.overwriteCache){E=x(E)}a.ajax({url:E,async:C.async,success:function(F){z.html(F);l(z,D,B,A,C)},error:function(){k(D,B,A,C)}})}function o(z,C,B,D){var A=a("");if(z.is("script")){z=a.parseHTML(a.trim(z.html()))}A.html(z);p.call(C,A,B,D);if(typeof D.success==="function"){D.success()}}function p(B,z,A){f(B,z,A);a(this).each(function(){var C=a(B.html());if(A.beforeInsert){A.beforeInsert(C)}if(A.append){a(this).append(C)}else{if(A.prepend){a(this).prepend(C)}else{a(this).html(C)}}if(A.afterInsert){A.afterInsert(C)}});if(typeof A.complete==="function"){A.complete.call(a(this))}}function k(C,A,z,B){var D;if(typeof B.error==="function"){B.error.call(A)}a(u[C]).each(function(E,F){if(typeof F.settings.error==="function"){F.settings.error.call(F.selection)}});if(typeof B.complete==="function"){B.complete.call(A)}while(u[C]&&(D=u[C].shift())){if(typeof D.settings.complete==="function"){D.settings.complete.call(D.selection)}}if(typeof u[C]!=="undefined"&&u[C].length>0){u[C]=[]}}function l(z,D,B,A,C){var E;v[D]=z.clone();p.call(B,z,A,C);if(typeof C.success==="function"){C.success.call(B)}while(u[D]&&(E=u[D].shift())){p.call(E.selection,v[D].clone(),E.data,E.settings);if(typeof E.settings.success==="function"){E.settings.success.call(E.selection)}}}function f(B,z,A){z=z||{};t("data-content",B,z,A,function(C,D){C.html(e(C,D,"content",A))});t("data-content-append",B,z,A,function(C,D){C.append(e(C,D,"content",A))});t("data-content-prepend",B,z,A,function(C,D){C.prepend(e(C,D,"content",A))});t("data-content-text",B,z,A,function(C,D){C.text(e(C,D,"content",A))});t("data-src",B,z,A,function(C,D){C.attr("src",e(C,D,"src",A))},function(C){C.remove()});t("data-alt",B,z,A,function(C,D){C.attr("alt",e(C,D,"alt",A))});t("data-value",B,z,A,function(C,D){C.attr("value",e(C,D,"value",A))});t("data-link",B,z,A,function(C,E){var D=a("");D.attr("href",e(C,E,"link",A));D.html(C.html());C.html(D)});t("data-link-wrap",B,z,A,function(C,E){var D=a("");D.attr("href",e(C,E,"link-wrap",A));C.wrap(D)});t("data-options",B,z,A,function(C,D){a(D).each(function(){var E=a("");E.attr("value",this).text(this).appendTo(C)})});r(B,z,A)}function t(z,E,A,D,B,C){a("["+z+"]",E).each(function(){var F=a(this),G=F.attr(z),H=j(A,G);if(!y(F,H,D)){F.remove();return}F.removeAttr(z);if(typeof H!=="undefined"&&B){B(F,H)}else{if(C){C(F)}}});return}function y(A,C,B){var z=i(A,B);if(z.ignoreUndefined&&typeof C==="undefined"){return false}else{if(z.ignoreNull&&C===null){return false}else{if(z.ignoreEmptyString&&C===""){return false}else{return true}}}}function i(A,B){var z={};if(A instanceof jQuery&&A.attr("data-binding-options")){z=a.parseJSON(A.attr("data-binding-options"));A.removeAttr("data-binding-options")}else{if(typeof A==="object"&&A.hasOwnProperty("bindingOptions")){z=A.bindingOptions}}return a.extend({},B.bindingOptions,z)}function r(B,z,A){a("[data-template-bind]",B).each(function(){var C=a(this),D=a.parseJSON(C.attr("data-template-bind"));C.removeAttr("data-template-bind");a(D).each(function(){var F;if(typeof(this.value)==="object"){F=j(z,this.value.data)}else{F=j(z,this.value)}if(this.attribute){if(!y(this,F,A)){C.remove();return}switch(this.attribute){case"content":C.html(d(C,F,this));break;case"contentAppend":C.append(d(C,F,this));break;case"contentPrepend":C.prepend(d(C,F,this));break;case"contentText":C.text(d(C,F,this));break;case"options":var E=this;a(F).each(function(){var G=a("");G.attr("value",this[E.value.value]).text(d(C,this[E.value.content],E)).attr("selected",typeof this[E.value.selected]==undefined?false:this[E.value.selected]).appendTo(C)});break;default:C.attr(this.attribute,d(C,F,this))}}})})}function d(z,C,A,B){if(A.formatter&&h[A.formatter]){return(function(D){return h[A.formatter].call(z,C,A.formatOptions,D)})(B)}return C}function j(z,A){if(A==="this"){return z}var B=A.split("."),C,D=z;while((C=B.shift())&&typeof D!=="undefined"){D=D[C]}return D}function e(z,F,A,E){var D=z.attr("data-format-target"),C;if(D===A||(!D&&A==="content")){C=z.attr("data-format");if(C&&typeof h[C]==="function"){var B=z.attr("data-format-options");return(function(G){return h[C].call(z[0],F,B,a.extend({},G))})(E)}}return F}b("nestedTemplateFormatter",function(D,A,z){if(!A){return}if(typeof A==="string"&&A[0]==="{"){A=a.parseJSON(A)}var B=A.parentElement||"div";var C=A.template||A;return a("<"+B+"/>").loadTemplate(C,D,z)});a.fn.loadTemplate=n;a.addTemplateFormatter=b})(jQuery);
\ No newline at end of file
diff --git a/jquery-loadTemplate/jquery.loadTemplate-1.4.0.js b/jquery-loadTemplate/jquery.loadTemplate-1.4.1.js
similarity index 98%
rename from jquery-loadTemplate/jquery.loadTemplate-1.4.0.js
rename to jquery-loadTemplate/jquery.loadTemplate-1.4.1.js
index 23dfc5a..8c12924 100644
--- a/jquery-loadTemplate/jquery.loadTemplate-1.4.0.js
+++ b/jquery-loadTemplate/jquery.loadTemplate-1.4.1.js
@@ -96,10 +96,12 @@
settings,
{
complete: function () {
- if (doPrepend) {
- $that.prepend(this.html());
- } else {
- $that.append(this.html());
+ if (this.html) {
+ if (doPrepend) {
+ $that.prepend(this.html());
+ } else {
+ $that.append(this.html());
+ }
}
done++;
if (done === todo || errored) {
@@ -195,7 +197,7 @@
function loadTemplateFromDocument($template, selection, data, settings) {
var $templateContainer = $("");
- if ($template.is("script")) {
+ if ($template.is("script") || $template.is("template")) {
$template = $.parseHTML($.trim($template.html()));
}
diff --git a/jquery-loadTemplate/jquery.loadTemplate-1.4.1.min.js b/jquery-loadTemplate/jquery.loadTemplate-1.4.1.min.js
new file mode 100644
index 0000000..3e570eb
--- /dev/null
+++ b/jquery-loadTemplate/jquery.loadTemplate-1.4.1.min.js
@@ -0,0 +1 @@
+(function(a){var v={},u={},h={};function n(F,B,D){var A=this,z,C,E;B=B||{};E=a.extend(true,{async:true,overwriteCache:false,complete:null,success:null,error:function(){a(this).each(function(){a(this).html(E.errorMessage)})},errorMessage:"There was an error loading the template.",paged:false,pageNo:1,elemPerPage:10,append:false,prepend:false,beforeInsert:null,afterInsert:null,bindingOptions:{ignoreUndefined:false,ignoreNull:false,ignoreEmptyString:false}},D);if(a.type(B)==="array"){return s.call(this,F,B,E)}if(!g(F)){z=a(F);if(typeof F==="string"&&F.indexOf("#")===0){E.isFile=false}}C=E.isFile||(typeof E.isFile==="undefined"&&(typeof z==="undefined"||z.length===0));if(C&&!E.overwriteCache&&v[F]){q(F,A,B,E)}else{if(C&&!E.overwriteCache&&v.hasOwnProperty(F)){c(F,A,B,E)}else{if(C){m(F,A,B,E)}else{o(z,A,B,E)}}}return this}function b(A,z){if(z){h[A]=z}else{h=a.extend(h,A)}}function g(z){return typeof z==="string"&&z.indexOf("/")>-1}function s(I,A,F){F=F||{};var z=this,J=A.length,C=F.prepend&&!F.append,B=0,H=0,D=false,E;if(F.paged){var G=(F.pageNo-1)*F.elemPerPage;A=A.slice(G,G+F.elemPerPage);J=A.length}E=a.extend({},F,{complete:function(){if(this.html){if(C){z.prepend(this.html())}else{z.append(this.html())}}B++;if(B===J||D){if(D&&F&&typeof F.error==="function"){F.error.call(z)}if(F&&typeof F.complete==="function"){F.complete()}}},success:function(){H++;if(H===J){if(F&&typeof F.success==="function"){F.success()}}},error:function(){D=true}});if(!F.append&&!F.prepend){z.html("")}if(C){A.reverse()}a(A).each(function(){var K=a("");n.call(K,I,this,E);if(D){return false}});return this}function c(C,A,z,B){if(u[C]){u[C].push({data:z,selection:A,settings:B})}else{u[C]=[{data:z,selection:A,settings:B}]}}function q(D,B,A,C){var z=v[D].clone();p.call(B,z,A,C);if(typeof C.success==="function"){C.success()}}function w(){return new Date().getTime()}function x(z){if(z.indexOf("?")!==-1){return z+"&_="+w()}else{return z+"?_="+w()}}function m(D,B,A,C){var z=a("");v[D]=null;var E=D;if(C.overwriteCache){E=x(E)}a.ajax({url:E,async:C.async,success:function(F){z.html(F);l(z,D,B,A,C)},error:function(){k(D,B,A,C)}})}function o(z,C,B,D){var A=a("");if(z.is("script")||z.is("template")){z=a.parseHTML(a.trim(z.html()))}A.html(z);p.call(C,A,B,D);if(typeof D.success==="function"){D.success()}}function p(B,z,A){f(B,z,A);a(this).each(function(){var C=a(B.html());if(A.beforeInsert){A.beforeInsert(C)}if(A.append){a(this).append(C)}else{if(A.prepend){a(this).prepend(C)}else{a(this).html(C)}}if(A.afterInsert){A.afterInsert(C)}});if(typeof A.complete==="function"){A.complete.call(a(this))}}function k(C,A,z,B){var D;if(typeof B.error==="function"){B.error.call(A)}a(u[C]).each(function(E,F){if(typeof F.settings.error==="function"){F.settings.error.call(F.selection)}});if(typeof B.complete==="function"){B.complete.call(A)}while(u[C]&&(D=u[C].shift())){if(typeof D.settings.complete==="function"){D.settings.complete.call(D.selection)}}if(typeof u[C]!=="undefined"&&u[C].length>0){u[C]=[]}}function l(z,D,B,A,C){var E;v[D]=z.clone();p.call(B,z,A,C);if(typeof C.success==="function"){C.success.call(B)}while(u[D]&&(E=u[D].shift())){p.call(E.selection,v[D].clone(),E.data,E.settings);if(typeof E.settings.success==="function"){E.settings.success.call(E.selection)}}}function f(B,z,A){z=z||{};t("data-content",B,z,A,function(C,D){C.html(e(C,D,"content",A))});t("data-content-append",B,z,A,function(C,D){C.append(e(C,D,"content",A))});t("data-content-prepend",B,z,A,function(C,D){C.prepend(e(C,D,"content",A))});t("data-content-text",B,z,A,function(C,D){C.text(e(C,D,"content",A))});t("data-src",B,z,A,function(C,D){C.attr("src",e(C,D,"src",A))},function(C){C.remove()});t("data-alt",B,z,A,function(C,D){C.attr("alt",e(C,D,"alt",A))});t("data-value",B,z,A,function(C,D){C.attr("value",e(C,D,"value",A))});t("data-link",B,z,A,function(C,E){var D=a("");D.attr("href",e(C,E,"link",A));D.html(C.html());C.html(D)});t("data-link-wrap",B,z,A,function(C,E){var D=a("");D.attr("href",e(C,E,"link-wrap",A));C.wrap(D)});t("data-options",B,z,A,function(C,D){a(D).each(function(){var E=a("");E.attr("value",this).text(this).appendTo(C)})});r(B,z,A)}function t(z,E,A,D,B,C){a("["+z+"]",E).each(function(){var F=a(this),G=F.attr(z),H=j(A,G);if(!y(F,H,D)){F.remove();return}F.removeAttr(z);if(typeof H!=="undefined"&&B){B(F,H)}else{if(C){C(F)}}});return}function y(A,C,B){var z=i(A,B);if(z.ignoreUndefined&&typeof C==="undefined"){return false}else{if(z.ignoreNull&&C===null){return false}else{if(z.ignoreEmptyString&&C===""){return false}else{return true}}}}function i(A,B){var z={};if(A instanceof jQuery&&A.attr("data-binding-options")){z=a.parseJSON(A.attr("data-binding-options"));A.removeAttr("data-binding-options")}else{if(typeof A==="object"&&A.hasOwnProperty("bindingOptions")){z=A.bindingOptions}}return a.extend({},B.bindingOptions,z)}function r(B,z,A){a("[data-template-bind]",B).each(function(){var C=a(this),D=a.parseJSON(C.attr("data-template-bind"));C.removeAttr("data-template-bind");a(D).each(function(){var F;if(typeof(this.value)==="object"){F=j(z,this.value.data)}else{F=j(z,this.value)}if(this.attribute){if(!y(this,F,A)){C.remove();return}switch(this.attribute){case"content":C.html(d(C,F,this));break;case"contentAppend":C.append(d(C,F,this));break;case"contentPrepend":C.prepend(d(C,F,this));break;case"contentText":C.text(d(C,F,this));break;case"options":var E=this;a(F).each(function(){var G=a("");G.attr("value",this[E.value.value]).text(d(C,this[E.value.content],E)).attr("selected",typeof this[E.value.selected]==undefined?false:this[E.value.selected]).appendTo(C)});break;default:C.attr(this.attribute,d(C,F,this))}}})})}function d(z,C,A,B){if(A.formatter&&h[A.formatter]){return(function(D){return h[A.formatter].call(z,C,A.formatOptions,D)})(B)}return C}function j(z,A){if(A==="this"){return z}var B=A.split("."),C,D=z;while((C=B.shift())&&typeof D!=="undefined"){D=D[C]}return D}function e(z,F,A,E){var D=z.attr("data-format-target"),C;if(D===A||(!D&&A==="content")){C=z.attr("data-format");if(C&&typeof h[C]==="function"){var B=z.attr("data-format-options");return(function(G){return h[C].call(z[0],F,B,a.extend({},G))})(E)}}return F}b("nestedTemplateFormatter",function(D,A,z){if(!A){return}if(typeof A==="string"&&A[0]==="{"){A=a.parseJSON(A)}var B=A.parentElement||"div";var C=A.template||A;return a("<"+B+"/>").loadTemplate(C,D,z)});a.fn.loadTemplate=n;a.addTemplateFormatter=b})(jQuery);
\ No newline at end of file
diff --git a/loadTemplate.jquery.json b/loadTemplate.jquery.json
index 1058cb0..fa145e1 100644
--- a/loadTemplate.jquery.json
+++ b/loadTemplate.jquery.json
@@ -6,7 +6,7 @@
"templates",
"templating"
],
- "version": "1.4.0",
+ "version": "1.4.1",
"author": {
"name": "Paul Burgess and other contributors",
"url": "https://github.com/codepb/jquery-template"
diff --git a/tests/index.html b/tests/index.html
index d3e8ad8..150ee81 100644
--- a/tests/index.html
+++ b/tests/index.html
@@ -3,7 +3,7 @@
loadTemplate Test Suite
-
+
From 0ee0d04a1f9f74db8ef1ed9f68c298fdb505c864 Mon Sep 17 00:00:00 2001
From: Paul Burgess
Date: Mon, 31 Mar 2014 18:08:29 +0100
Subject: [PATCH 36/71] Added data-id
There is now supported a data-id option to bind to the id. This
addresses issue #36.
---
Examples/index.html | 2 +-
...ery.loadTemplate-1.4.1.js => jquery.loadTemplate-1.4.2.js} | 4 ++++
...Template-1.4.1.min.js => jquery.loadTemplate-1.4.2.min.js} | 2 +-
readme.md | 1 +
tests/index.html | 2 +-
5 files changed, 8 insertions(+), 3 deletions(-)
rename jquery-loadTemplate/{jquery.loadTemplate-1.4.1.js => jquery.loadTemplate-1.4.2.js} (99%)
rename jquery-loadTemplate/{jquery.loadTemplate-1.4.1.min.js => jquery.loadTemplate-1.4.2.min.js} (56%)
diff --git a/Examples/index.html b/Examples/index.html
index 97b7e80..da13bed 100644
--- a/Examples/index.html
+++ b/Examples/index.html
@@ -9,7 +9,7 @@
-
+
diff --git a/jquery-loadTemplate/jquery.loadTemplate-1.4.1.js b/jquery-loadTemplate/jquery.loadTemplate-1.4.2.js
similarity index 99%
rename from jquery-loadTemplate/jquery.loadTemplate-1.4.1.js
rename to jquery-loadTemplate/jquery.loadTemplate-1.4.2.js
index 8c12924..52c43a0 100644
--- a/jquery-loadTemplate/jquery.loadTemplate-1.4.1.js
+++ b/jquery-loadTemplate/jquery.loadTemplate-1.4.2.js
@@ -310,6 +310,10 @@
$elem.attr("alt", applyFormatters($elem, value, "alt", settings));
});
+ processElements("data-id", template, data, settings, function ($elem, value) {
+ $elem.attr("id", applyFormatters($elem, value, "id", settings));
+ });
+
processElements("data-value", template, data, settings, function ($elem, value) {
$elem.attr("value", applyFormatters($elem, value, "value", settings));
});
diff --git a/jquery-loadTemplate/jquery.loadTemplate-1.4.1.min.js b/jquery-loadTemplate/jquery.loadTemplate-1.4.2.min.js
similarity index 56%
rename from jquery-loadTemplate/jquery.loadTemplate-1.4.1.min.js
rename to jquery-loadTemplate/jquery.loadTemplate-1.4.2.min.js
index 3e570eb..c162670 100644
--- a/jquery-loadTemplate/jquery.loadTemplate-1.4.1.min.js
+++ b/jquery-loadTemplate/jquery.loadTemplate-1.4.2.min.js
@@ -1 +1 @@
-(function(a){var v={},u={},h={};function n(F,B,D){var A=this,z,C,E;B=B||{};E=a.extend(true,{async:true,overwriteCache:false,complete:null,success:null,error:function(){a(this).each(function(){a(this).html(E.errorMessage)})},errorMessage:"There was an error loading the template.",paged:false,pageNo:1,elemPerPage:10,append:false,prepend:false,beforeInsert:null,afterInsert:null,bindingOptions:{ignoreUndefined:false,ignoreNull:false,ignoreEmptyString:false}},D);if(a.type(B)==="array"){return s.call(this,F,B,E)}if(!g(F)){z=a(F);if(typeof F==="string"&&F.indexOf("#")===0){E.isFile=false}}C=E.isFile||(typeof E.isFile==="undefined"&&(typeof z==="undefined"||z.length===0));if(C&&!E.overwriteCache&&v[F]){q(F,A,B,E)}else{if(C&&!E.overwriteCache&&v.hasOwnProperty(F)){c(F,A,B,E)}else{if(C){m(F,A,B,E)}else{o(z,A,B,E)}}}return this}function b(A,z){if(z){h[A]=z}else{h=a.extend(h,A)}}function g(z){return typeof z==="string"&&z.indexOf("/")>-1}function s(I,A,F){F=F||{};var z=this,J=A.length,C=F.prepend&&!F.append,B=0,H=0,D=false,E;if(F.paged){var G=(F.pageNo-1)*F.elemPerPage;A=A.slice(G,G+F.elemPerPage);J=A.length}E=a.extend({},F,{complete:function(){if(this.html){if(C){z.prepend(this.html())}else{z.append(this.html())}}B++;if(B===J||D){if(D&&F&&typeof F.error==="function"){F.error.call(z)}if(F&&typeof F.complete==="function"){F.complete()}}},success:function(){H++;if(H===J){if(F&&typeof F.success==="function"){F.success()}}},error:function(){D=true}});if(!F.append&&!F.prepend){z.html("")}if(C){A.reverse()}a(A).each(function(){var K=a("");n.call(K,I,this,E);if(D){return false}});return this}function c(C,A,z,B){if(u[C]){u[C].push({data:z,selection:A,settings:B})}else{u[C]=[{data:z,selection:A,settings:B}]}}function q(D,B,A,C){var z=v[D].clone();p.call(B,z,A,C);if(typeof C.success==="function"){C.success()}}function w(){return new Date().getTime()}function x(z){if(z.indexOf("?")!==-1){return z+"&_="+w()}else{return z+"?_="+w()}}function m(D,B,A,C){var z=a("");v[D]=null;var E=D;if(C.overwriteCache){E=x(E)}a.ajax({url:E,async:C.async,success:function(F){z.html(F);l(z,D,B,A,C)},error:function(){k(D,B,A,C)}})}function o(z,C,B,D){var A=a("");if(z.is("script")||z.is("template")){z=a.parseHTML(a.trim(z.html()))}A.html(z);p.call(C,A,B,D);if(typeof D.success==="function"){D.success()}}function p(B,z,A){f(B,z,A);a(this).each(function(){var C=a(B.html());if(A.beforeInsert){A.beforeInsert(C)}if(A.append){a(this).append(C)}else{if(A.prepend){a(this).prepend(C)}else{a(this).html(C)}}if(A.afterInsert){A.afterInsert(C)}});if(typeof A.complete==="function"){A.complete.call(a(this))}}function k(C,A,z,B){var D;if(typeof B.error==="function"){B.error.call(A)}a(u[C]).each(function(E,F){if(typeof F.settings.error==="function"){F.settings.error.call(F.selection)}});if(typeof B.complete==="function"){B.complete.call(A)}while(u[C]&&(D=u[C].shift())){if(typeof D.settings.complete==="function"){D.settings.complete.call(D.selection)}}if(typeof u[C]!=="undefined"&&u[C].length>0){u[C]=[]}}function l(z,D,B,A,C){var E;v[D]=z.clone();p.call(B,z,A,C);if(typeof C.success==="function"){C.success.call(B)}while(u[D]&&(E=u[D].shift())){p.call(E.selection,v[D].clone(),E.data,E.settings);if(typeof E.settings.success==="function"){E.settings.success.call(E.selection)}}}function f(B,z,A){z=z||{};t("data-content",B,z,A,function(C,D){C.html(e(C,D,"content",A))});t("data-content-append",B,z,A,function(C,D){C.append(e(C,D,"content",A))});t("data-content-prepend",B,z,A,function(C,D){C.prepend(e(C,D,"content",A))});t("data-content-text",B,z,A,function(C,D){C.text(e(C,D,"content",A))});t("data-src",B,z,A,function(C,D){C.attr("src",e(C,D,"src",A))},function(C){C.remove()});t("data-alt",B,z,A,function(C,D){C.attr("alt",e(C,D,"alt",A))});t("data-value",B,z,A,function(C,D){C.attr("value",e(C,D,"value",A))});t("data-link",B,z,A,function(C,E){var D=a("");D.attr("href",e(C,E,"link",A));D.html(C.html());C.html(D)});t("data-link-wrap",B,z,A,function(C,E){var D=a("");D.attr("href",e(C,E,"link-wrap",A));C.wrap(D)});t("data-options",B,z,A,function(C,D){a(D).each(function(){var E=a("");E.attr("value",this).text(this).appendTo(C)})});r(B,z,A)}function t(z,E,A,D,B,C){a("["+z+"]",E).each(function(){var F=a(this),G=F.attr(z),H=j(A,G);if(!y(F,H,D)){F.remove();return}F.removeAttr(z);if(typeof H!=="undefined"&&B){B(F,H)}else{if(C){C(F)}}});return}function y(A,C,B){var z=i(A,B);if(z.ignoreUndefined&&typeof C==="undefined"){return false}else{if(z.ignoreNull&&C===null){return false}else{if(z.ignoreEmptyString&&C===""){return false}else{return true}}}}function i(A,B){var z={};if(A instanceof jQuery&&A.attr("data-binding-options")){z=a.parseJSON(A.attr("data-binding-options"));A.removeAttr("data-binding-options")}else{if(typeof A==="object"&&A.hasOwnProperty("bindingOptions")){z=A.bindingOptions}}return a.extend({},B.bindingOptions,z)}function r(B,z,A){a("[data-template-bind]",B).each(function(){var C=a(this),D=a.parseJSON(C.attr("data-template-bind"));C.removeAttr("data-template-bind");a(D).each(function(){var F;if(typeof(this.value)==="object"){F=j(z,this.value.data)}else{F=j(z,this.value)}if(this.attribute){if(!y(this,F,A)){C.remove();return}switch(this.attribute){case"content":C.html(d(C,F,this));break;case"contentAppend":C.append(d(C,F,this));break;case"contentPrepend":C.prepend(d(C,F,this));break;case"contentText":C.text(d(C,F,this));break;case"options":var E=this;a(F).each(function(){var G=a("");G.attr("value",this[E.value.value]).text(d(C,this[E.value.content],E)).attr("selected",typeof this[E.value.selected]==undefined?false:this[E.value.selected]).appendTo(C)});break;default:C.attr(this.attribute,d(C,F,this))}}})})}function d(z,C,A,B){if(A.formatter&&h[A.formatter]){return(function(D){return h[A.formatter].call(z,C,A.formatOptions,D)})(B)}return C}function j(z,A){if(A==="this"){return z}var B=A.split("."),C,D=z;while((C=B.shift())&&typeof D!=="undefined"){D=D[C]}return D}function e(z,F,A,E){var D=z.attr("data-format-target"),C;if(D===A||(!D&&A==="content")){C=z.attr("data-format");if(C&&typeof h[C]==="function"){var B=z.attr("data-format-options");return(function(G){return h[C].call(z[0],F,B,a.extend({},G))})(E)}}return F}b("nestedTemplateFormatter",function(D,A,z){if(!A){return}if(typeof A==="string"&&A[0]==="{"){A=a.parseJSON(A)}var B=A.parentElement||"div";var C=A.template||A;return a("<"+B+"/>").loadTemplate(C,D,z)});a.fn.loadTemplate=n;a.addTemplateFormatter=b})(jQuery);
\ No newline at end of file
+(function(a){var v={},u={},h={};function n(F,B,D){var A=this,z,C,E;B=B||{};E=a.extend(true,{async:true,overwriteCache:false,complete:null,success:null,error:function(){a(this).each(function(){a(this).html(E.errorMessage)})},errorMessage:"There was an error loading the template.",paged:false,pageNo:1,elemPerPage:10,append:false,prepend:false,beforeInsert:null,afterInsert:null,bindingOptions:{ignoreUndefined:false,ignoreNull:false,ignoreEmptyString:false}},D);if(a.type(B)==="array"){return s.call(this,F,B,E)}if(!g(F)){z=a(F);if(typeof F==="string"&&F.indexOf("#")===0){E.isFile=false}}C=E.isFile||(typeof E.isFile==="undefined"&&(typeof z==="undefined"||z.length===0));if(C&&!E.overwriteCache&&v[F]){q(F,A,B,E)}else{if(C&&!E.overwriteCache&&v.hasOwnProperty(F)){c(F,A,B,E)}else{if(C){m(F,A,B,E)}else{o(z,A,B,E)}}}return this}function b(A,z){if(z){h[A]=z}else{h=a.extend(h,A)}}function g(z){return typeof z==="string"&&z.indexOf("/")>-1}function s(I,A,F){F=F||{};var z=this,J=A.length,C=F.prepend&&!F.append,B=0,H=0,D=false,E;if(F.paged){var G=(F.pageNo-1)*F.elemPerPage;A=A.slice(G,G+F.elemPerPage);J=A.length}E=a.extend({},F,{complete:function(){if(this.html){if(C){z.prepend(this.html())}else{z.append(this.html())}}B++;if(B===J||D){if(D&&F&&typeof F.error==="function"){F.error.call(z)}if(F&&typeof F.complete==="function"){F.complete()}}},success:function(){H++;if(H===J){if(F&&typeof F.success==="function"){F.success()}}},error:function(){D=true}});if(!F.append&&!F.prepend){z.html("")}if(C){A.reverse()}a(A).each(function(){var K=a("");n.call(K,I,this,E);if(D){return false}});return this}function c(C,A,z,B){if(u[C]){u[C].push({data:z,selection:A,settings:B})}else{u[C]=[{data:z,selection:A,settings:B}]}}function q(D,B,A,C){var z=v[D].clone();p.call(B,z,A,C);if(typeof C.success==="function"){C.success()}}function w(){return new Date().getTime()}function x(z){if(z.indexOf("?")!==-1){return z+"&_="+w()}else{return z+"?_="+w()}}function m(D,B,A,C){var z=a("");v[D]=null;var E=D;if(C.overwriteCache){E=x(E)}a.ajax({url:E,async:C.async,success:function(F){z.html(F);l(z,D,B,A,C)},error:function(){k(D,B,A,C)}})}function o(z,C,B,D){var A=a("");if(z.is("script")||z.is("template")){z=a.parseHTML(a.trim(z.html()))}A.html(z);p.call(C,A,B,D);if(typeof D.success==="function"){D.success()}}function p(B,z,A){f(B,z,A);a(this).each(function(){var C=a(B.html());if(A.beforeInsert){A.beforeInsert(C)}if(A.append){a(this).append(C)}else{if(A.prepend){a(this).prepend(C)}else{a(this).html(C)}}if(A.afterInsert){A.afterInsert(C)}});if(typeof A.complete==="function"){A.complete.call(a(this))}}function k(C,A,z,B){var D;if(typeof B.error==="function"){B.error.call(A)}a(u[C]).each(function(E,F){if(typeof F.settings.error==="function"){F.settings.error.call(F.selection)}});if(typeof B.complete==="function"){B.complete.call(A)}while(u[C]&&(D=u[C].shift())){if(typeof D.settings.complete==="function"){D.settings.complete.call(D.selection)}}if(typeof u[C]!=="undefined"&&u[C].length>0){u[C]=[]}}function l(z,D,B,A,C){var E;v[D]=z.clone();p.call(B,z,A,C);if(typeof C.success==="function"){C.success.call(B)}while(u[D]&&(E=u[D].shift())){p.call(E.selection,v[D].clone(),E.data,E.settings);if(typeof E.settings.success==="function"){E.settings.success.call(E.selection)}}}function f(B,z,A){z=z||{};t("data-content",B,z,A,function(C,D){C.html(e(C,D,"content",A))});t("data-content-append",B,z,A,function(C,D){C.append(e(C,D,"content",A))});t("data-content-prepend",B,z,A,function(C,D){C.prepend(e(C,D,"content",A))});t("data-content-text",B,z,A,function(C,D){C.text(e(C,D,"content",A))});t("data-src",B,z,A,function(C,D){C.attr("src",e(C,D,"src",A))},function(C){C.remove()});t("data-alt",B,z,A,function(C,D){C.attr("alt",e(C,D,"alt",A))});t("data-id",B,z,A,function(C,D){C.attr("id",e(C,D,"id",A))});t("data-value",B,z,A,function(C,D){C.attr("value",e(C,D,"value",A))});t("data-link",B,z,A,function(C,E){var D=a("");D.attr("href",e(C,E,"link",A));D.html(C.html());C.html(D)});t("data-link-wrap",B,z,A,function(C,E){var D=a("");D.attr("href",e(C,E,"link-wrap",A));C.wrap(D)});t("data-options",B,z,A,function(C,D){a(D).each(function(){var E=a("");E.attr("value",this).text(this).appendTo(C)})});r(B,z,A)}function t(z,E,A,D,B,C){a("["+z+"]",E).each(function(){var F=a(this),G=F.attr(z),H=j(A,G);if(!y(F,H,D)){F.remove();return}F.removeAttr(z);if(typeof H!=="undefined"&&B){B(F,H)}else{if(C){C(F)}}});return}function y(A,C,B){var z=i(A,B);if(z.ignoreUndefined&&typeof C==="undefined"){return false}else{if(z.ignoreNull&&C===null){return false}else{if(z.ignoreEmptyString&&C===""){return false}else{return true}}}}function i(A,B){var z={};if(A instanceof jQuery&&A.attr("data-binding-options")){z=a.parseJSON(A.attr("data-binding-options"));A.removeAttr("data-binding-options")}else{if(typeof A==="object"&&A.hasOwnProperty("bindingOptions")){z=A.bindingOptions}}return a.extend({},B.bindingOptions,z)}function r(B,z,A){a("[data-template-bind]",B).each(function(){var C=a(this),D=a.parseJSON(C.attr("data-template-bind"));C.removeAttr("data-template-bind");a(D).each(function(){var F;if(typeof(this.value)==="object"){F=j(z,this.value.data)}else{F=j(z,this.value)}if(this.attribute){if(!y(this,F,A)){C.remove();return}switch(this.attribute){case"content":C.html(d(C,F,this));break;case"contentAppend":C.append(d(C,F,this));break;case"contentPrepend":C.prepend(d(C,F,this));break;case"contentText":C.text(d(C,F,this));break;case"options":var E=this;a(F).each(function(){var G=a("");G.attr("value",this[E.value.value]).text(d(C,this[E.value.content],E)).attr("selected",typeof this[E.value.selected]==undefined?false:this[E.value.selected]).appendTo(C)});break;default:C.attr(this.attribute,d(C,F,this))}}})})}function d(z,C,A,B){if(A.formatter&&h[A.formatter]){return(function(D){return h[A.formatter].call(z,C,A.formatOptions,D)})(B)}return C}function j(z,A){if(A==="this"){return z}var B=A.split("."),C,D=z;while((C=B.shift())&&typeof D!=="undefined"){D=D[C]}return D}function e(z,F,A,E){var D=z.attr("data-format-target"),C;if(D===A||(!D&&A==="content")){C=z.attr("data-format");if(C&&typeof h[C]==="function"){var B=z.attr("data-format-options");return(function(G){return h[C].call(z[0],F,B,a.extend({},G))})(E)}}return F}b("nestedTemplateFormatter",function(D,A,z){if(!A){return}if(typeof A==="string"&&A[0]==="{"){A=a.parseJSON(A)}var B=A.parentElement||"div";var C=A.template||A;return a("<"+B+"/>").loadTemplate(C,D,z)});a.fn.loadTemplate=n;a.addTemplateFormatter=b})(jQuery);
\ No newline at end of file
diff --git a/readme.md b/readme.md
index 18013cf..1efda54 100644
--- a/readme.md
+++ b/readme.md
@@ -98,6 +98,7 @@ There are a number of different bindings and ways to bind the data. The followin
- "data-content" - binds the value supplied to the content of the element (uses $(elem).html(value))
- "data-content-append" - appends the value to the end of the element (uses $(elem).append(value))
- "data-content-prepend" - prepends the value to the beginning of the element (uses $(elem).prepend(value))
+- "data-id" - sets the id of the element to the value provided (uses $(elem).attr("id", value));
- "data-alt" - sets the alt value of the element to the value provided (uses $(elem).attr("alt", value));
- "data-value" - sets the value attribute of the element to the value provided (uses $(elem).val(value))
- "data-link" - sets the innerHtml of the element to be a link to the value provided (wraps the content in an <a> tag).
diff --git a/tests/index.html b/tests/index.html
index 150ee81..bbba95e 100644
--- a/tests/index.html
+++ b/tests/index.html
@@ -3,7 +3,7 @@
loadTemplate Test Suite
-
+
From 10e535a954391791811f8425fc898ae10572dc89 Mon Sep 17 00:00:00 2001
From: Paul Burgess
Date: Mon, 31 Mar 2014 18:10:45 +0100
Subject: [PATCH 37/71] Updated version
---
Examples/index.html | 2 +-
...query.loadTemplate-1.4.2.js => jquery.loadTemplate-1.4.3.js} | 0
...adTemplate-1.4.2.min.js => jquery.loadTemplate-1.4.3.min.js} | 0
loadTemplate.jquery.json | 2 +-
tests/index.html | 2 +-
5 files changed, 3 insertions(+), 3 deletions(-)
rename jquery-loadTemplate/{jquery.loadTemplate-1.4.2.js => jquery.loadTemplate-1.4.3.js} (100%)
rename jquery-loadTemplate/{jquery.loadTemplate-1.4.2.min.js => jquery.loadTemplate-1.4.3.min.js} (100%)
diff --git a/Examples/index.html b/Examples/index.html
index da13bed..6a4bc64 100644
--- a/Examples/index.html
+++ b/Examples/index.html
@@ -9,7 +9,7 @@
-
+
diff --git a/jquery-loadTemplate/jquery.loadTemplate-1.4.2.js b/jquery-loadTemplate/jquery.loadTemplate-1.4.3.js
similarity index 100%
rename from jquery-loadTemplate/jquery.loadTemplate-1.4.2.js
rename to jquery-loadTemplate/jquery.loadTemplate-1.4.3.js
diff --git a/jquery-loadTemplate/jquery.loadTemplate-1.4.2.min.js b/jquery-loadTemplate/jquery.loadTemplate-1.4.3.min.js
similarity index 100%
rename from jquery-loadTemplate/jquery.loadTemplate-1.4.2.min.js
rename to jquery-loadTemplate/jquery.loadTemplate-1.4.3.min.js
diff --git a/loadTemplate.jquery.json b/loadTemplate.jquery.json
index fa145e1..837eda8 100644
--- a/loadTemplate.jquery.json
+++ b/loadTemplate.jquery.json
@@ -6,7 +6,7 @@
"templates",
"templating"
],
- "version": "1.4.1",
+ "version": "1.4.3",
"author": {
"name": "Paul Burgess and other contributors",
"url": "https://github.com/codepb/jquery-template"
diff --git a/tests/index.html b/tests/index.html
index bbba95e..3b28627 100644
--- a/tests/index.html
+++ b/tests/index.html
@@ -3,7 +3,7 @@
loadTemplate Test Suite
-
+
From 1823add2ff5bfa27b307cb42e895932484be4e95 Mon Sep 17 00:00:00 2001
From: Chris Rogers
Date: Tue, 6 May 2014 10:00:52 -0500
Subject: [PATCH 38/71] Updates to jquery.loadTemplate-1.4.3.js
As per my two issue submissions:
1) Modified getValue to accommodate null values during data binding
2) Modified the nestedTemplateFormatter to only return the generated child nodes if the parentElement is not specified.
---
jquery-loadTemplate/jquery.loadTemplate-1.4.3.js | 9 +++++++--
1 file changed, 7 insertions(+), 2 deletions(-)
diff --git a/jquery-loadTemplate/jquery.loadTemplate-1.4.3.js b/jquery-loadTemplate/jquery.loadTemplate-1.4.3.js
index 52c43a0..b80b10e 100644
--- a/jquery-loadTemplate/jquery.loadTemplate-1.4.3.js
+++ b/jquery-loadTemplate/jquery.loadTemplate-1.4.3.js
@@ -471,7 +471,7 @@
part,
value = data;
- while ((part = paramParts.shift()) && typeof value !== "undefined") {
+ while ((part = paramParts.shift()) && typeof value !== "undefined" && value != null) {
value = value[part];
}
@@ -505,7 +505,12 @@
var parentElement = options.parentElement || "div";
var template = options.template || options;
- return $("<" + parentElement + "/>").loadTemplate(template, value, internalSettings);
+
+ //If a parent is specified, return it; otherwise only return the generated children.
+ if(options.parentElement)
+ return $("<" + parentElement + "/>").loadTemplate(template, value, internalSettings);
+ else
+ return $("<" + parentElement + "/>").loadTemplate(template, value, internalSettings).children();
});
$.fn.loadTemplate = loadTemplate;
$.addTemplateFormatter = addTemplateFormatter;
From 55407d3f7c65a7b086efd474f420d6a1d55b851a Mon Sep 17 00:00:00 2001
From: Adis
Date: Wed, 14 May 2014 00:44:26 +0600
Subject: [PATCH 39/71] Added data-href binding
Added data-href binding
---
jquery-loadTemplate/jquery.loadTemplate-1.4.3.js | 6 ++++++
1 file changed, 6 insertions(+)
diff --git a/jquery-loadTemplate/jquery.loadTemplate-1.4.3.js b/jquery-loadTemplate/jquery.loadTemplate-1.4.3.js
index 52c43a0..e2f60d9 100644
--- a/jquery-loadTemplate/jquery.loadTemplate-1.4.3.js
+++ b/jquery-loadTemplate/jquery.loadTemplate-1.4.3.js
@@ -305,6 +305,12 @@
}, function ($elem) {
$elem.remove();
});
+
+ processElements("data-href", template, data, settings, function ($elem, value) {
+ $elem.attr("href", applyFormatters($elem, value, "href", settings));
+ }, function ($elem) {
+ $elem.remove();
+ });
processElements("data-alt", template, data, settings, function ($elem, value) {
$elem.attr("alt", applyFormatters($elem, value, "alt", settings));
From 6964c08ba63eb49ce8d366fa4073a444cd5fb32d Mon Sep 17 00:00:00 2001
From: Paul Burgess
Date: Sun, 18 May 2014 13:40:50 +0100
Subject: [PATCH 40/71] Updated documentation, and version
---
Examples/index.html | 2 +-
...query.loadTemplate-1.4.3.js => jquery.loadTemplate-1.4.4.js} | 0
...adTemplate-1.4.3.min.js => jquery.loadTemplate-1.4.4.min.js} | 2 +-
loadTemplate.jquery.json | 2 +-
readme.md | 1 +
tests/index.html | 2 +-
6 files changed, 5 insertions(+), 4 deletions(-)
rename jquery-loadTemplate/{jquery.loadTemplate-1.4.3.js => jquery.loadTemplate-1.4.4.js} (100%)
rename jquery-loadTemplate/{jquery.loadTemplate-1.4.3.min.js => jquery.loadTemplate-1.4.4.min.js} (54%)
diff --git a/Examples/index.html b/Examples/index.html
index 6a4bc64..ad2f922 100644
--- a/Examples/index.html
+++ b/Examples/index.html
@@ -9,7 +9,7 @@
-
+
diff --git a/jquery-loadTemplate/jquery.loadTemplate-1.4.3.js b/jquery-loadTemplate/jquery.loadTemplate-1.4.4.js
similarity index 100%
rename from jquery-loadTemplate/jquery.loadTemplate-1.4.3.js
rename to jquery-loadTemplate/jquery.loadTemplate-1.4.4.js
diff --git a/jquery-loadTemplate/jquery.loadTemplate-1.4.3.min.js b/jquery-loadTemplate/jquery.loadTemplate-1.4.4.min.js
similarity index 54%
rename from jquery-loadTemplate/jquery.loadTemplate-1.4.3.min.js
rename to jquery-loadTemplate/jquery.loadTemplate-1.4.4.min.js
index c162670..b21b477 100644
--- a/jquery-loadTemplate/jquery.loadTemplate-1.4.3.min.js
+++ b/jquery-loadTemplate/jquery.loadTemplate-1.4.4.min.js
@@ -1 +1 @@
-(function(a){var v={},u={},h={};function n(F,B,D){var A=this,z,C,E;B=B||{};E=a.extend(true,{async:true,overwriteCache:false,complete:null,success:null,error:function(){a(this).each(function(){a(this).html(E.errorMessage)})},errorMessage:"There was an error loading the template.",paged:false,pageNo:1,elemPerPage:10,append:false,prepend:false,beforeInsert:null,afterInsert:null,bindingOptions:{ignoreUndefined:false,ignoreNull:false,ignoreEmptyString:false}},D);if(a.type(B)==="array"){return s.call(this,F,B,E)}if(!g(F)){z=a(F);if(typeof F==="string"&&F.indexOf("#")===0){E.isFile=false}}C=E.isFile||(typeof E.isFile==="undefined"&&(typeof z==="undefined"||z.length===0));if(C&&!E.overwriteCache&&v[F]){q(F,A,B,E)}else{if(C&&!E.overwriteCache&&v.hasOwnProperty(F)){c(F,A,B,E)}else{if(C){m(F,A,B,E)}else{o(z,A,B,E)}}}return this}function b(A,z){if(z){h[A]=z}else{h=a.extend(h,A)}}function g(z){return typeof z==="string"&&z.indexOf("/")>-1}function s(I,A,F){F=F||{};var z=this,J=A.length,C=F.prepend&&!F.append,B=0,H=0,D=false,E;if(F.paged){var G=(F.pageNo-1)*F.elemPerPage;A=A.slice(G,G+F.elemPerPage);J=A.length}E=a.extend({},F,{complete:function(){if(this.html){if(C){z.prepend(this.html())}else{z.append(this.html())}}B++;if(B===J||D){if(D&&F&&typeof F.error==="function"){F.error.call(z)}if(F&&typeof F.complete==="function"){F.complete()}}},success:function(){H++;if(H===J){if(F&&typeof F.success==="function"){F.success()}}},error:function(){D=true}});if(!F.append&&!F.prepend){z.html("")}if(C){A.reverse()}a(A).each(function(){var K=a("");n.call(K,I,this,E);if(D){return false}});return this}function c(C,A,z,B){if(u[C]){u[C].push({data:z,selection:A,settings:B})}else{u[C]=[{data:z,selection:A,settings:B}]}}function q(D,B,A,C){var z=v[D].clone();p.call(B,z,A,C);if(typeof C.success==="function"){C.success()}}function w(){return new Date().getTime()}function x(z){if(z.indexOf("?")!==-1){return z+"&_="+w()}else{return z+"?_="+w()}}function m(D,B,A,C){var z=a("");v[D]=null;var E=D;if(C.overwriteCache){E=x(E)}a.ajax({url:E,async:C.async,success:function(F){z.html(F);l(z,D,B,A,C)},error:function(){k(D,B,A,C)}})}function o(z,C,B,D){var A=a("");if(z.is("script")||z.is("template")){z=a.parseHTML(a.trim(z.html()))}A.html(z);p.call(C,A,B,D);if(typeof D.success==="function"){D.success()}}function p(B,z,A){f(B,z,A);a(this).each(function(){var C=a(B.html());if(A.beforeInsert){A.beforeInsert(C)}if(A.append){a(this).append(C)}else{if(A.prepend){a(this).prepend(C)}else{a(this).html(C)}}if(A.afterInsert){A.afterInsert(C)}});if(typeof A.complete==="function"){A.complete.call(a(this))}}function k(C,A,z,B){var D;if(typeof B.error==="function"){B.error.call(A)}a(u[C]).each(function(E,F){if(typeof F.settings.error==="function"){F.settings.error.call(F.selection)}});if(typeof B.complete==="function"){B.complete.call(A)}while(u[C]&&(D=u[C].shift())){if(typeof D.settings.complete==="function"){D.settings.complete.call(D.selection)}}if(typeof u[C]!=="undefined"&&u[C].length>0){u[C]=[]}}function l(z,D,B,A,C){var E;v[D]=z.clone();p.call(B,z,A,C);if(typeof C.success==="function"){C.success.call(B)}while(u[D]&&(E=u[D].shift())){p.call(E.selection,v[D].clone(),E.data,E.settings);if(typeof E.settings.success==="function"){E.settings.success.call(E.selection)}}}function f(B,z,A){z=z||{};t("data-content",B,z,A,function(C,D){C.html(e(C,D,"content",A))});t("data-content-append",B,z,A,function(C,D){C.append(e(C,D,"content",A))});t("data-content-prepend",B,z,A,function(C,D){C.prepend(e(C,D,"content",A))});t("data-content-text",B,z,A,function(C,D){C.text(e(C,D,"content",A))});t("data-src",B,z,A,function(C,D){C.attr("src",e(C,D,"src",A))},function(C){C.remove()});t("data-alt",B,z,A,function(C,D){C.attr("alt",e(C,D,"alt",A))});t("data-id",B,z,A,function(C,D){C.attr("id",e(C,D,"id",A))});t("data-value",B,z,A,function(C,D){C.attr("value",e(C,D,"value",A))});t("data-link",B,z,A,function(C,E){var D=a("");D.attr("href",e(C,E,"link",A));D.html(C.html());C.html(D)});t("data-link-wrap",B,z,A,function(C,E){var D=a("");D.attr("href",e(C,E,"link-wrap",A));C.wrap(D)});t("data-options",B,z,A,function(C,D){a(D).each(function(){var E=a("");E.attr("value",this).text(this).appendTo(C)})});r(B,z,A)}function t(z,E,A,D,B,C){a("["+z+"]",E).each(function(){var F=a(this),G=F.attr(z),H=j(A,G);if(!y(F,H,D)){F.remove();return}F.removeAttr(z);if(typeof H!=="undefined"&&B){B(F,H)}else{if(C){C(F)}}});return}function y(A,C,B){var z=i(A,B);if(z.ignoreUndefined&&typeof C==="undefined"){return false}else{if(z.ignoreNull&&C===null){return false}else{if(z.ignoreEmptyString&&C===""){return false}else{return true}}}}function i(A,B){var z={};if(A instanceof jQuery&&A.attr("data-binding-options")){z=a.parseJSON(A.attr("data-binding-options"));A.removeAttr("data-binding-options")}else{if(typeof A==="object"&&A.hasOwnProperty("bindingOptions")){z=A.bindingOptions}}return a.extend({},B.bindingOptions,z)}function r(B,z,A){a("[data-template-bind]",B).each(function(){var C=a(this),D=a.parseJSON(C.attr("data-template-bind"));C.removeAttr("data-template-bind");a(D).each(function(){var F;if(typeof(this.value)==="object"){F=j(z,this.value.data)}else{F=j(z,this.value)}if(this.attribute){if(!y(this,F,A)){C.remove();return}switch(this.attribute){case"content":C.html(d(C,F,this));break;case"contentAppend":C.append(d(C,F,this));break;case"contentPrepend":C.prepend(d(C,F,this));break;case"contentText":C.text(d(C,F,this));break;case"options":var E=this;a(F).each(function(){var G=a("");G.attr("value",this[E.value.value]).text(d(C,this[E.value.content],E)).attr("selected",typeof this[E.value.selected]==undefined?false:this[E.value.selected]).appendTo(C)});break;default:C.attr(this.attribute,d(C,F,this))}}})})}function d(z,C,A,B){if(A.formatter&&h[A.formatter]){return(function(D){return h[A.formatter].call(z,C,A.formatOptions,D)})(B)}return C}function j(z,A){if(A==="this"){return z}var B=A.split("."),C,D=z;while((C=B.shift())&&typeof D!=="undefined"){D=D[C]}return D}function e(z,F,A,E){var D=z.attr("data-format-target"),C;if(D===A||(!D&&A==="content")){C=z.attr("data-format");if(C&&typeof h[C]==="function"){var B=z.attr("data-format-options");return(function(G){return h[C].call(z[0],F,B,a.extend({},G))})(E)}}return F}b("nestedTemplateFormatter",function(D,A,z){if(!A){return}if(typeof A==="string"&&A[0]==="{"){A=a.parseJSON(A)}var B=A.parentElement||"div";var C=A.template||A;return a("<"+B+"/>").loadTemplate(C,D,z)});a.fn.loadTemplate=n;a.addTemplateFormatter=b})(jQuery);
\ No newline at end of file
+(function(a){var v={},u={},h={};function n(F,B,D){var A=this,z,C,E;B=B||{};E=a.extend(true,{async:true,overwriteCache:false,complete:null,success:null,error:function(){a(this).each(function(){a(this).html(E.errorMessage)})},errorMessage:"There was an error loading the template.",paged:false,pageNo:1,elemPerPage:10,append:false,prepend:false,beforeInsert:null,afterInsert:null,bindingOptions:{ignoreUndefined:false,ignoreNull:false,ignoreEmptyString:false}},D);if(a.type(B)==="array"){return s.call(this,F,B,E)}if(!g(F)){z=a(F);if(typeof F==="string"&&F.indexOf("#")===0){E.isFile=false}}C=E.isFile||(typeof E.isFile==="undefined"&&(typeof z==="undefined"||z.length===0));if(C&&!E.overwriteCache&&v[F]){q(F,A,B,E)}else{if(C&&!E.overwriteCache&&v.hasOwnProperty(F)){c(F,A,B,E)}else{if(C){m(F,A,B,E)}else{o(z,A,B,E)}}}return this}function b(A,z){if(z){h[A]=z}else{h=a.extend(h,A)}}function g(z){return typeof z==="string"&&z.indexOf("/")>-1}function s(I,A,F){F=F||{};var z=this,J=A.length,C=F.prepend&&!F.append,B=0,H=0,D=false,E;if(F.paged){var G=(F.pageNo-1)*F.elemPerPage;A=A.slice(G,G+F.elemPerPage);J=A.length}E=a.extend({},F,{complete:function(){if(this.html){if(C){z.prepend(this.html())}else{z.append(this.html())}}B++;if(B===J||D){if(D&&F&&typeof F.error==="function"){F.error.call(z)}if(F&&typeof F.complete==="function"){F.complete()}}},success:function(){H++;if(H===J){if(F&&typeof F.success==="function"){F.success()}}},error:function(){D=true}});if(!F.append&&!F.prepend){z.html("")}if(C){A.reverse()}a(A).each(function(){var K=a("");n.call(K,I,this,E);if(D){return false}});return this}function c(C,A,z,B){if(u[C]){u[C].push({data:z,selection:A,settings:B})}else{u[C]=[{data:z,selection:A,settings:B}]}}function q(D,B,A,C){var z=v[D].clone();p.call(B,z,A,C);if(typeof C.success==="function"){C.success()}}function w(){return new Date().getTime()}function x(z){if(z.indexOf("?")!==-1){return z+"&_="+w()}else{return z+"?_="+w()}}function m(D,B,A,C){var z=a("");v[D]=null;var E=D;if(C.overwriteCache){E=x(E)}a.ajax({url:E,async:C.async,success:function(F){z.html(F);l(z,D,B,A,C)},error:function(){k(D,B,A,C)}})}function o(z,C,B,D){var A=a("");if(z.is("script")||z.is("template")){z=a.parseHTML(a.trim(z.html()))}A.html(z);p.call(C,A,B,D);if(typeof D.success==="function"){D.success()}}function p(B,z,A){f(B,z,A);a(this).each(function(){var C=a(B.html());if(A.beforeInsert){A.beforeInsert(C)}if(A.append){a(this).append(C)}else{if(A.prepend){a(this).prepend(C)}else{a(this).html(C)}}if(A.afterInsert){A.afterInsert(C)}});if(typeof A.complete==="function"){A.complete.call(a(this))}}function k(C,A,z,B){var D;if(typeof B.error==="function"){B.error.call(A)}a(u[C]).each(function(E,F){if(typeof F.settings.error==="function"){F.settings.error.call(F.selection)}});if(typeof B.complete==="function"){B.complete.call(A)}while(u[C]&&(D=u[C].shift())){if(typeof D.settings.complete==="function"){D.settings.complete.call(D.selection)}}if(typeof u[C]!=="undefined"&&u[C].length>0){u[C]=[]}}function l(z,D,B,A,C){var E;v[D]=z.clone();p.call(B,z,A,C);if(typeof C.success==="function"){C.success.call(B)}while(u[D]&&(E=u[D].shift())){p.call(E.selection,v[D].clone(),E.data,E.settings);if(typeof E.settings.success==="function"){E.settings.success.call(E.selection)}}}function f(B,z,A){z=z||{};t("data-content",B,z,A,function(C,D){C.html(e(C,D,"content",A))});t("data-content-append",B,z,A,function(C,D){C.append(e(C,D,"content",A))});t("data-content-prepend",B,z,A,function(C,D){C.prepend(e(C,D,"content",A))});t("data-content-text",B,z,A,function(C,D){C.text(e(C,D,"content",A))});t("data-src",B,z,A,function(C,D){C.attr("src",e(C,D,"src",A))},function(C){C.remove()});t("data-href",B,z,A,function(C,D){C.attr("href",e(C,D,"href",A))},function(C){C.remove()});t("data-alt",B,z,A,function(C,D){C.attr("alt",e(C,D,"alt",A))});t("data-id",B,z,A,function(C,D){C.attr("id",e(C,D,"id",A))});t("data-value",B,z,A,function(C,D){C.attr("value",e(C,D,"value",A))});t("data-link",B,z,A,function(C,E){var D=a("");D.attr("href",e(C,E,"link",A));D.html(C.html());C.html(D)});t("data-link-wrap",B,z,A,function(C,E){var D=a("");D.attr("href",e(C,E,"link-wrap",A));C.wrap(D)});t("data-options",B,z,A,function(C,D){a(D).each(function(){var E=a("");E.attr("value",this).text(this).appendTo(C)})});r(B,z,A)}function t(z,E,A,D,B,C){a("["+z+"]",E).each(function(){var F=a(this),G=F.attr(z),H=j(A,G);if(!y(F,H,D)){F.remove();return}F.removeAttr(z);if(typeof H!=="undefined"&&B){B(F,H)}else{if(C){C(F)}}});return}function y(A,C,B){var z=i(A,B);if(z.ignoreUndefined&&typeof C==="undefined"){return false}else{if(z.ignoreNull&&C===null){return false}else{if(z.ignoreEmptyString&&C===""){return false}else{return true}}}}function i(A,B){var z={};if(A instanceof jQuery&&A.attr("data-binding-options")){z=a.parseJSON(A.attr("data-binding-options"));A.removeAttr("data-binding-options")}else{if(typeof A==="object"&&A.hasOwnProperty("bindingOptions")){z=A.bindingOptions}}return a.extend({},B.bindingOptions,z)}function r(B,z,A){a("[data-template-bind]",B).each(function(){var C=a(this),D=a.parseJSON(C.attr("data-template-bind"));C.removeAttr("data-template-bind");a(D).each(function(){var F;if(typeof(this.value)==="object"){F=j(z,this.value.data)}else{F=j(z,this.value)}if(this.attribute){if(!y(this,F,A)){C.remove();return}switch(this.attribute){case"content":C.html(d(C,F,this));break;case"contentAppend":C.append(d(C,F,this));break;case"contentPrepend":C.prepend(d(C,F,this));break;case"contentText":C.text(d(C,F,this));break;case"options":var E=this;a(F).each(function(){var G=a("");G.attr("value",this[E.value.value]).text(d(C,this[E.value.content],E)).attr("selected",typeof this[E.value.selected]==undefined?false:this[E.value.selected]).appendTo(C)});break;default:C.attr(this.attribute,d(C,F,this))}}})})}function d(z,C,A,B){if(A.formatter&&h[A.formatter]){return(function(D){return h[A.formatter].call(z,C,A.formatOptions,D)})(B)}return C}function j(z,A){if(A==="this"){return z}var B=A.split("."),C,D=z;while((C=B.shift())&&typeof D!=="undefined"&&D!=null){D=D[C]}return D}function e(z,F,A,E){var D=z.attr("data-format-target"),C;if(D===A||(!D&&A==="content")){C=z.attr("data-format");if(C&&typeof h[C]==="function"){var B=z.attr("data-format-options");return(function(G){return h[C].call(z[0],F,B,a.extend({},G))})(E)}}return F}b("nestedTemplateFormatter",function(D,A,z){if(!A){return}if(typeof A==="string"&&A[0]==="{"){A=a.parseJSON(A)}var B=A.parentElement||"div";var C=A.template||A;if(A.parentElement){return a("<"+B+"/>").loadTemplate(C,D,z)}else{return a("<"+B+"/>").loadTemplate(C,D,z).children()}});a.fn.loadTemplate=n;a.addTemplateFormatter=b})(jQuery);
\ No newline at end of file
diff --git a/loadTemplate.jquery.json b/loadTemplate.jquery.json
index 837eda8..1f52deb 100644
--- a/loadTemplate.jquery.json
+++ b/loadTemplate.jquery.json
@@ -6,7 +6,7 @@
"templates",
"templating"
],
- "version": "1.4.3",
+ "version": "1.4.4",
"author": {
"name": "Paul Burgess and other contributors",
"url": "https://github.com/codepb/jquery-template"
diff --git a/readme.md b/readme.md
index 1efda54..34ba5b7 100644
--- a/readme.md
+++ b/readme.md
@@ -99,6 +99,7 @@ There are a number of different bindings and ways to bind the data. The followin
- "data-content-append" - appends the value to the end of the element (uses $(elem).append(value))
- "data-content-prepend" - prepends the value to the beginning of the element (uses $(elem).prepend(value))
- "data-id" - sets the id of the element to the value provided (uses $(elem).attr("id", value));
+- "data-href" - sets the href value of the element to the value provided (uses $(elem).attr("href", value));
- "data-alt" - sets the alt value of the element to the value provided (uses $(elem).attr("alt", value));
- "data-value" - sets the value attribute of the element to the value provided (uses $(elem).val(value))
- "data-link" - sets the innerHtml of the element to be a link to the value provided (wraps the content in an <a> tag).
diff --git a/tests/index.html b/tests/index.html
index 3b28627..3b986d9 100644
--- a/tests/index.html
+++ b/tests/index.html
@@ -3,7 +3,7 @@
loadTemplate Test Suite
-
+
From cf7c6558b0b325cfa5876d6c855fc8d717ba6c0e Mon Sep 17 00:00:00 2001
From: codepb
Date: Sat, 26 Jul 2014 22:06:19 +0100
Subject: [PATCH 41/71] Update readme.md
Added the data-content-text documentation
---
readme.md | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/readme.md b/readme.md
index 34ba5b7..fc2c9b4 100644
--- a/readme.md
+++ b/readme.md
@@ -96,6 +96,7 @@ Formatters must be added before they are used else a template will not be able t
There are a number of different bindings and ways to bind the data. The following attributes are available:
- "data-content" - binds the value supplied to the content of the element (uses $(elem).html(value))
+- "data-content-text" - binds the value supplied to the content of the element as text (uses $(elem).text(value))
- "data-content-append" - appends the value to the end of the element (uses $(elem).append(value))
- "data-content-prepend" - prepends the value to the beginning of the element (uses $(elem).prepend(value))
- "data-id" - sets the id of the element to the value provided (uses $(elem).attr("id", value));
@@ -143,4 +144,4 @@ There are a number of options the plugin accepts. These are:
## Future Plans
-I would like to develop the plugin further so it would be possible to watch the objects holding the data, so any changes to the data would be reflected in the UI. This would have to be simple, lightweight, and ideally would work just with natural JavaScript objects. I also welcome any ideas as to how the plugin could be improved.
\ No newline at end of file
+I would like to develop the plugin further so it would be possible to watch the objects holding the data, so any changes to the data would be reflected in the UI. This would have to be simple, lightweight, and ideally would work just with natural JavaScript objects. I also welcome any ideas as to how the plugin could be improved.
From df4778525df5e8968ab55d885ad54af6ceab911d Mon Sep 17 00:00:00 2001
From: codepb
Date: Thu, 21 Aug 2014 16:38:48 +0100
Subject: [PATCH 42/71] Update readme.md
Showed how to use options in the plugin
---
readme.md | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)
diff --git a/readme.md b/readme.md
index fc2c9b4..0b74f72 100644
--- a/readme.md
+++ b/readme.md
@@ -125,7 +125,11 @@ An example of using the "data-template-bind" attribute would be the following:
### Options
-There are a number of options the plugin accepts. These are:
+There are a number of options the plugin accepts. These can be set by passing an object containing the settings you would like to set as the third parameter to .loadTemplate:
+
+ $(container).loadTemplate(template, data, { append: true, elemPerPage: 20 });
+
+The full list of options are:
- "overwriteCache" (default false) - Whether to ignore the cache and reload the template (if you've previously loaded the template, but it might have changed, you'll want to set this to true.
- "complete" (default null) - Callback function to call on complete. Will always be called regardless of success or failure.
From 6394a1fb2e845225fdcaa4d46c4bc01a5875b055 Mon Sep 17 00:00:00 2001
From: Paul Burgess
Date: Wed, 22 Oct 2014 11:01:22 +0100
Subject: [PATCH 43/71] Added data-class and data-innerHTML
data-innerHTML is the new name for data-content to prepare for version
2. data-content is maintained for legacy support, but the plan is to
remove this in version 2. data-template-bind will also accept
"innerHTML" as a replacement to content. Again the plan is to free up
content, as this could be a valid attribute of some elements. data-class
will bind to the class attribute
---
Examples/SimpleExample/Templates/simple.html | 2 +-
Examples/SimpleExample/example.html | 2 +-
Examples/index.html | 2 +-
...oadTemplate-1.4.4.js => jquery.loadTemplate-1.4.5.js} | 9 +++++++++
...ate-1.4.4.min.js => jquery.loadTemplate-1.4.5.min.js} | 2 +-
loadTemplate.jquery.json | 2 +-
readme.md | 4 +++-
tests/index.html | 2 +-
8 files changed, 18 insertions(+), 7 deletions(-)
rename jquery-loadTemplate/{jquery.loadTemplate-1.4.4.js => jquery.loadTemplate-1.4.5.js} (97%)
rename jquery-loadTemplate/{jquery.loadTemplate-1.4.4.min.js => jquery.loadTemplate-1.4.5.min.js} (52%)
diff --git a/Examples/SimpleExample/Templates/simple.html b/Examples/SimpleExample/Templates/simple.html
index dc613aa..c844792 100644
--- a/Examples/SimpleExample/Templates/simple.html
+++ b/Examples/SimpleExample/Templates/simple.html
@@ -5,7 +5,7 @@
Example of loading a template from a script tag within the same document.
-
+
diff --git a/jquery-loadTemplate/jquery.loadTemplate-1.4.4.js b/jquery-loadTemplate/jquery.loadTemplate-1.4.5.js
similarity index 97%
rename from jquery-loadTemplate/jquery.loadTemplate-1.4.4.js
rename to jquery-loadTemplate/jquery.loadTemplate-1.4.5.js
index b678cd8..46275a8 100644
--- a/jquery-loadTemplate/jquery.loadTemplate-1.4.4.js
+++ b/jquery-loadTemplate/jquery.loadTemplate-1.4.5.js
@@ -300,6 +300,10 @@
$elem.text(applyFormatters($elem, value, "content", settings));
});
+ processElements("data-innerHTML", template, data, settings, function ($elem, value) {
+ $elem.html(applyFormatters($elem, value, "content", settings));
+ });
+
processElements("data-src", template, data, settings, function ($elem, value) {
$elem.attr("src", applyFormatters($elem, value, "src", settings));
}, function ($elem) {
@@ -324,6 +328,10 @@
$elem.attr("value", applyFormatters($elem, value, "value", settings));
});
+ processElements("data-class", template, data, settings, function ($elem, value) {
+ $elem.addClass(applyFormatters($elem, value, "class", settings));
+ });
+
processElements("data-link", template, data, settings, function ($elem, value) {
var $linkElem = $("");
$linkElem.attr("href", applyFormatters($elem, value, "link", settings));
@@ -430,6 +438,7 @@
switch (this.attribute) {
case "content":
+ case "innerHTML":
$this.html(applyDataBindFormatters($this, value, this));
break;
case "contentAppend":
diff --git a/jquery-loadTemplate/jquery.loadTemplate-1.4.4.min.js b/jquery-loadTemplate/jquery.loadTemplate-1.4.5.min.js
similarity index 52%
rename from jquery-loadTemplate/jquery.loadTemplate-1.4.4.min.js
rename to jquery-loadTemplate/jquery.loadTemplate-1.4.5.min.js
index b21b477..64dab52 100644
--- a/jquery-loadTemplate/jquery.loadTemplate-1.4.4.min.js
+++ b/jquery-loadTemplate/jquery.loadTemplate-1.4.5.min.js
@@ -1 +1 @@
-(function(a){var v={},u={},h={};function n(F,B,D){var A=this,z,C,E;B=B||{};E=a.extend(true,{async:true,overwriteCache:false,complete:null,success:null,error:function(){a(this).each(function(){a(this).html(E.errorMessage)})},errorMessage:"There was an error loading the template.",paged:false,pageNo:1,elemPerPage:10,append:false,prepend:false,beforeInsert:null,afterInsert:null,bindingOptions:{ignoreUndefined:false,ignoreNull:false,ignoreEmptyString:false}},D);if(a.type(B)==="array"){return s.call(this,F,B,E)}if(!g(F)){z=a(F);if(typeof F==="string"&&F.indexOf("#")===0){E.isFile=false}}C=E.isFile||(typeof E.isFile==="undefined"&&(typeof z==="undefined"||z.length===0));if(C&&!E.overwriteCache&&v[F]){q(F,A,B,E)}else{if(C&&!E.overwriteCache&&v.hasOwnProperty(F)){c(F,A,B,E)}else{if(C){m(F,A,B,E)}else{o(z,A,B,E)}}}return this}function b(A,z){if(z){h[A]=z}else{h=a.extend(h,A)}}function g(z){return typeof z==="string"&&z.indexOf("/")>-1}function s(I,A,F){F=F||{};var z=this,J=A.length,C=F.prepend&&!F.append,B=0,H=0,D=false,E;if(F.paged){var G=(F.pageNo-1)*F.elemPerPage;A=A.slice(G,G+F.elemPerPage);J=A.length}E=a.extend({},F,{complete:function(){if(this.html){if(C){z.prepend(this.html())}else{z.append(this.html())}}B++;if(B===J||D){if(D&&F&&typeof F.error==="function"){F.error.call(z)}if(F&&typeof F.complete==="function"){F.complete()}}},success:function(){H++;if(H===J){if(F&&typeof F.success==="function"){F.success()}}},error:function(){D=true}});if(!F.append&&!F.prepend){z.html("")}if(C){A.reverse()}a(A).each(function(){var K=a("");n.call(K,I,this,E);if(D){return false}});return this}function c(C,A,z,B){if(u[C]){u[C].push({data:z,selection:A,settings:B})}else{u[C]=[{data:z,selection:A,settings:B}]}}function q(D,B,A,C){var z=v[D].clone();p.call(B,z,A,C);if(typeof C.success==="function"){C.success()}}function w(){return new Date().getTime()}function x(z){if(z.indexOf("?")!==-1){return z+"&_="+w()}else{return z+"?_="+w()}}function m(D,B,A,C){var z=a("");v[D]=null;var E=D;if(C.overwriteCache){E=x(E)}a.ajax({url:E,async:C.async,success:function(F){z.html(F);l(z,D,B,A,C)},error:function(){k(D,B,A,C)}})}function o(z,C,B,D){var A=a("");if(z.is("script")||z.is("template")){z=a.parseHTML(a.trim(z.html()))}A.html(z);p.call(C,A,B,D);if(typeof D.success==="function"){D.success()}}function p(B,z,A){f(B,z,A);a(this).each(function(){var C=a(B.html());if(A.beforeInsert){A.beforeInsert(C)}if(A.append){a(this).append(C)}else{if(A.prepend){a(this).prepend(C)}else{a(this).html(C)}}if(A.afterInsert){A.afterInsert(C)}});if(typeof A.complete==="function"){A.complete.call(a(this))}}function k(C,A,z,B){var D;if(typeof B.error==="function"){B.error.call(A)}a(u[C]).each(function(E,F){if(typeof F.settings.error==="function"){F.settings.error.call(F.selection)}});if(typeof B.complete==="function"){B.complete.call(A)}while(u[C]&&(D=u[C].shift())){if(typeof D.settings.complete==="function"){D.settings.complete.call(D.selection)}}if(typeof u[C]!=="undefined"&&u[C].length>0){u[C]=[]}}function l(z,D,B,A,C){var E;v[D]=z.clone();p.call(B,z,A,C);if(typeof C.success==="function"){C.success.call(B)}while(u[D]&&(E=u[D].shift())){p.call(E.selection,v[D].clone(),E.data,E.settings);if(typeof E.settings.success==="function"){E.settings.success.call(E.selection)}}}function f(B,z,A){z=z||{};t("data-content",B,z,A,function(C,D){C.html(e(C,D,"content",A))});t("data-content-append",B,z,A,function(C,D){C.append(e(C,D,"content",A))});t("data-content-prepend",B,z,A,function(C,D){C.prepend(e(C,D,"content",A))});t("data-content-text",B,z,A,function(C,D){C.text(e(C,D,"content",A))});t("data-src",B,z,A,function(C,D){C.attr("src",e(C,D,"src",A))},function(C){C.remove()});t("data-href",B,z,A,function(C,D){C.attr("href",e(C,D,"href",A))},function(C){C.remove()});t("data-alt",B,z,A,function(C,D){C.attr("alt",e(C,D,"alt",A))});t("data-id",B,z,A,function(C,D){C.attr("id",e(C,D,"id",A))});t("data-value",B,z,A,function(C,D){C.attr("value",e(C,D,"value",A))});t("data-link",B,z,A,function(C,E){var D=a("");D.attr("href",e(C,E,"link",A));D.html(C.html());C.html(D)});t("data-link-wrap",B,z,A,function(C,E){var D=a("");D.attr("href",e(C,E,"link-wrap",A));C.wrap(D)});t("data-options",B,z,A,function(C,D){a(D).each(function(){var E=a("");E.attr("value",this).text(this).appendTo(C)})});r(B,z,A)}function t(z,E,A,D,B,C){a("["+z+"]",E).each(function(){var F=a(this),G=F.attr(z),H=j(A,G);if(!y(F,H,D)){F.remove();return}F.removeAttr(z);if(typeof H!=="undefined"&&B){B(F,H)}else{if(C){C(F)}}});return}function y(A,C,B){var z=i(A,B);if(z.ignoreUndefined&&typeof C==="undefined"){return false}else{if(z.ignoreNull&&C===null){return false}else{if(z.ignoreEmptyString&&C===""){return false}else{return true}}}}function i(A,B){var z={};if(A instanceof jQuery&&A.attr("data-binding-options")){z=a.parseJSON(A.attr("data-binding-options"));A.removeAttr("data-binding-options")}else{if(typeof A==="object"&&A.hasOwnProperty("bindingOptions")){z=A.bindingOptions}}return a.extend({},B.bindingOptions,z)}function r(B,z,A){a("[data-template-bind]",B).each(function(){var C=a(this),D=a.parseJSON(C.attr("data-template-bind"));C.removeAttr("data-template-bind");a(D).each(function(){var F;if(typeof(this.value)==="object"){F=j(z,this.value.data)}else{F=j(z,this.value)}if(this.attribute){if(!y(this,F,A)){C.remove();return}switch(this.attribute){case"content":C.html(d(C,F,this));break;case"contentAppend":C.append(d(C,F,this));break;case"contentPrepend":C.prepend(d(C,F,this));break;case"contentText":C.text(d(C,F,this));break;case"options":var E=this;a(F).each(function(){var G=a("");G.attr("value",this[E.value.value]).text(d(C,this[E.value.content],E)).attr("selected",typeof this[E.value.selected]==undefined?false:this[E.value.selected]).appendTo(C)});break;default:C.attr(this.attribute,d(C,F,this))}}})})}function d(z,C,A,B){if(A.formatter&&h[A.formatter]){return(function(D){return h[A.formatter].call(z,C,A.formatOptions,D)})(B)}return C}function j(z,A){if(A==="this"){return z}var B=A.split("."),C,D=z;while((C=B.shift())&&typeof D!=="undefined"&&D!=null){D=D[C]}return D}function e(z,F,A,E){var D=z.attr("data-format-target"),C;if(D===A||(!D&&A==="content")){C=z.attr("data-format");if(C&&typeof h[C]==="function"){var B=z.attr("data-format-options");return(function(G){return h[C].call(z[0],F,B,a.extend({},G))})(E)}}return F}b("nestedTemplateFormatter",function(D,A,z){if(!A){return}if(typeof A==="string"&&A[0]==="{"){A=a.parseJSON(A)}var B=A.parentElement||"div";var C=A.template||A;if(A.parentElement){return a("<"+B+"/>").loadTemplate(C,D,z)}else{return a("<"+B+"/>").loadTemplate(C,D,z).children()}});a.fn.loadTemplate=n;a.addTemplateFormatter=b})(jQuery);
\ No newline at end of file
+(function(a){var v={},u={},h={};function n(F,B,D){var A=this,z,C,E;B=B||{};E=a.extend(true,{async:true,overwriteCache:false,complete:null,success:null,error:function(){a(this).each(function(){a(this).html(E.errorMessage)})},errorMessage:"There was an error loading the template.",paged:false,pageNo:1,elemPerPage:10,append:false,prepend:false,beforeInsert:null,afterInsert:null,bindingOptions:{ignoreUndefined:false,ignoreNull:false,ignoreEmptyString:false}},D);if(a.type(B)==="array"){return s.call(this,F,B,E)}if(!g(F)){z=a(F);if(typeof F==="string"&&F.indexOf("#")===0){E.isFile=false}}C=E.isFile||(typeof E.isFile==="undefined"&&(typeof z==="undefined"||z.length===0));if(C&&!E.overwriteCache&&v[F]){q(F,A,B,E)}else{if(C&&!E.overwriteCache&&v.hasOwnProperty(F)){c(F,A,B,E)}else{if(C){m(F,A,B,E)}else{o(z,A,B,E)}}}return this}function b(A,z){if(z){h[A]=z}else{h=a.extend(h,A)}}function g(z){return typeof z==="string"&&z.indexOf("/")>-1}function s(I,A,F){F=F||{};var z=this,J=A.length,C=F.prepend&&!F.append,B=0,H=0,D=false,E;if(F.paged){var G=(F.pageNo-1)*F.elemPerPage;A=A.slice(G,G+F.elemPerPage);J=A.length}E=a.extend({},F,{complete:function(){if(this.html){if(C){z.prepend(this.html())}else{z.append(this.html())}}B++;if(B===J||D){if(D&&F&&typeof F.error==="function"){F.error.call(z)}if(F&&typeof F.complete==="function"){F.complete()}}},success:function(){H++;if(H===J){if(F&&typeof F.success==="function"){F.success()}}},error:function(){D=true}});if(!F.append&&!F.prepend){z.html("")}if(C){A.reverse()}a(A).each(function(){var K=a("");n.call(K,I,this,E);if(D){return false}});return this}function c(C,A,z,B){if(u[C]){u[C].push({data:z,selection:A,settings:B})}else{u[C]=[{data:z,selection:A,settings:B}]}}function q(D,B,A,C){var z=v[D].clone();p.call(B,z,A,C);if(typeof C.success==="function"){C.success()}}function w(){return new Date().getTime()}function x(z){if(z.indexOf("?")!==-1){return z+"&_="+w()}else{return z+"?_="+w()}}function m(D,B,A,C){var z=a("");v[D]=null;var E=D;if(C.overwriteCache){E=x(E)}a.ajax({url:E,async:C.async,success:function(F){z.html(F);l(z,D,B,A,C)},error:function(){k(D,B,A,C)}})}function o(z,C,B,D){var A=a("");if(z.is("script")||z.is("template")){z=a.parseHTML(a.trim(z.html()))}A.html(z);p.call(C,A,B,D);if(typeof D.success==="function"){D.success()}}function p(B,z,A){f(B,z,A);a(this).each(function(){var C=a(B.html());if(A.beforeInsert){A.beforeInsert(C)}if(A.append){a(this).append(C)}else{if(A.prepend){a(this).prepend(C)}else{a(this).html(C)}}if(A.afterInsert){A.afterInsert(C)}});if(typeof A.complete==="function"){A.complete.call(a(this))}}function k(C,A,z,B){var D;if(typeof B.error==="function"){B.error.call(A)}a(u[C]).each(function(E,F){if(typeof F.settings.error==="function"){F.settings.error.call(F.selection)}});if(typeof B.complete==="function"){B.complete.call(A)}while(u[C]&&(D=u[C].shift())){if(typeof D.settings.complete==="function"){D.settings.complete.call(D.selection)}}if(typeof u[C]!=="undefined"&&u[C].length>0){u[C]=[]}}function l(z,D,B,A,C){var E;v[D]=z.clone();p.call(B,z,A,C);if(typeof C.success==="function"){C.success.call(B)}while(u[D]&&(E=u[D].shift())){p.call(E.selection,v[D].clone(),E.data,E.settings);if(typeof E.settings.success==="function"){E.settings.success.call(E.selection)}}}function f(B,z,A){z=z||{};t("data-content",B,z,A,function(C,D){C.html(e(C,D,"content",A))});t("data-content-append",B,z,A,function(C,D){C.append(e(C,D,"content",A))});t("data-content-prepend",B,z,A,function(C,D){C.prepend(e(C,D,"content",A))});t("data-content-text",B,z,A,function(C,D){C.text(e(C,D,"content",A))});t("data-innerHTML",B,z,A,function(C,D){C.html(e(C,D,"content",A))});t("data-src",B,z,A,function(C,D){C.attr("src",e(C,D,"src",A))},function(C){C.remove()});t("data-href",B,z,A,function(C,D){C.attr("href",e(C,D,"href",A))},function(C){C.remove()});t("data-alt",B,z,A,function(C,D){C.attr("alt",e(C,D,"alt",A))});t("data-id",B,z,A,function(C,D){C.attr("id",e(C,D,"id",A))});t("data-value",B,z,A,function(C,D){C.attr("value",e(C,D,"value",A))});t("data-class",B,z,A,function(C,D){C.addClass(e(C,D,"class",A))});t("data-link",B,z,A,function(C,E){var D=a("");D.attr("href",e(C,E,"link",A));D.html(C.html());C.html(D)});t("data-link-wrap",B,z,A,function(C,E){var D=a("");D.attr("href",e(C,E,"link-wrap",A));C.wrap(D)});t("data-options",B,z,A,function(C,D){a(D).each(function(){var E=a("");E.attr("value",this).text(this).appendTo(C)})});r(B,z,A)}function t(z,E,A,D,B,C){a("["+z+"]",E).each(function(){var F=a(this),G=F.attr(z),H=j(A,G);if(!y(F,H,D)){F.remove();return}F.removeAttr(z);if(typeof H!=="undefined"&&B){B(F,H)}else{if(C){C(F)}}});return}function y(A,C,B){var z=i(A,B);if(z.ignoreUndefined&&typeof C==="undefined"){return false}else{if(z.ignoreNull&&C===null){return false}else{if(z.ignoreEmptyString&&C===""){return false}else{return true}}}}function i(A,B){var z={};if(A instanceof jQuery&&A.attr("data-binding-options")){z=a.parseJSON(A.attr("data-binding-options"));A.removeAttr("data-binding-options")}else{if(typeof A==="object"&&A.hasOwnProperty("bindingOptions")){z=A.bindingOptions}}return a.extend({},B.bindingOptions,z)}function r(B,z,A){a("[data-template-bind]",B).each(function(){var C=a(this),D=a.parseJSON(C.attr("data-template-bind"));C.removeAttr("data-template-bind");a(D).each(function(){var F;if(typeof(this.value)==="object"){F=j(z,this.value.data)}else{F=j(z,this.value)}if(this.attribute){if(!y(this,F,A)){C.remove();return}switch(this.attribute){case"content":case"innerHTML":C.html(d(C,F,this));break;case"contentAppend":C.append(d(C,F,this));break;case"contentPrepend":C.prepend(d(C,F,this));break;case"contentText":C.text(d(C,F,this));break;case"options":var E=this;a(F).each(function(){var G=a("");G.attr("value",this[E.value.value]).text(d(C,this[E.value.content],E)).attr("selected",typeof this[E.value.selected]==undefined?false:this[E.value.selected]).appendTo(C)});break;default:C.attr(this.attribute,d(C,F,this))}}})})}function d(z,C,A,B){if(A.formatter&&h[A.formatter]){return(function(D){return h[A.formatter].call(z,C,A.formatOptions,D)})(B)}return C}function j(z,A){if(A==="this"){return z}var B=A.split("."),C,D=z;while((C=B.shift())&&typeof D!=="undefined"&&D!=null){D=D[C]}return D}function e(z,F,A,E){var D=z.attr("data-format-target"),C;if(D===A||(!D&&A==="content")){C=z.attr("data-format");if(C&&typeof h[C]==="function"){var B=z.attr("data-format-options");return(function(G){return h[C].call(z[0],F,B,a.extend({},G))})(E)}}return F}b("nestedTemplateFormatter",function(D,A,z){if(!A){return}if(typeof A==="string"&&A[0]==="{"){A=a.parseJSON(A)}var B=A.parentElement||"div";var C=A.template||A;if(A.parentElement){return a("<"+B+"/>").loadTemplate(C,D,z)}else{return a("<"+B+"/>").loadTemplate(C,D,z).children()}});a.fn.loadTemplate=n;a.addTemplateFormatter=b})(jQuery);
\ No newline at end of file
diff --git a/loadTemplate.jquery.json b/loadTemplate.jquery.json
index 1f52deb..3ff9610 100644
--- a/loadTemplate.jquery.json
+++ b/loadTemplate.jquery.json
@@ -6,7 +6,7 @@
"templates",
"templating"
],
- "version": "1.4.4",
+ "version": "1.4.5",
"author": {
"name": "Paul Burgess and other contributors",
"url": "https://github.com/codepb/jquery-template"
diff --git a/readme.md b/readme.md
index 0b74f72..5267759 100644
--- a/readme.md
+++ b/readme.md
@@ -95,7 +95,8 @@ Formatters must be added before they are used else a template will not be able t
### Bindings
There are a number of different bindings and ways to bind the data. The following attributes are available:
-- "data-content" - binds the value supplied to the content of the element (uses $(elem).html(value))
+- "data-innerHTML" (<= 1.4.5) - binds the value supplied to the content (innerHTML) of the element (uses $(elem).html(value))
+- "data-content" - alias for the newer "data-innerHTML"
- "data-content-text" - binds the value supplied to the content of the element as text (uses $(elem).text(value))
- "data-content-append" - appends the value to the end of the element (uses $(elem).append(value))
- "data-content-prepend" - prepends the value to the beginning of the element (uses $(elem).prepend(value))
@@ -103,6 +104,7 @@ There are a number of different bindings and ways to bind the data. The followin
- "data-href" - sets the href value of the element to the value provided (uses $(elem).attr("href", value));
- "data-alt" - sets the alt value of the element to the value provided (uses $(elem).attr("alt", value));
- "data-value" - sets the value attribute of the element to the value provided (uses $(elem).val(value))
+- "data-class" - sets the class attribute of the element to the value provided (uses $(elem).class(value))
- "data-link" - sets the innerHtml of the element to be a link to the value provided (wraps the content in an <a> tag).
- "data-link-wrap" - wraps the element in a link to the value provided. Same as "data-link", but the <a> tag wraps the element as well as the content.
- "data-options" - adds options to a select box. The value for this should reference an array of strings, each option will be output as a separate option. The value will be the same as the displayed text for each option. For a more powerful version of this look at the data-template-bind option.
diff --git a/tests/index.html b/tests/index.html
index 3b986d9..e1d7e36 100644
--- a/tests/index.html
+++ b/tests/index.html
@@ -3,7 +3,7 @@
loadTemplate Test Suite
-
+
From 2ff396cd0cd838506f235e0678bef662cf98819c Mon Sep 17 00:00:00 2001
From: Paul Burgess
Date: Wed, 22 Oct 2014 11:47:50 +0100
Subject: [PATCH 44/71] adding npm package.json file
---
Package.json | 21 +++++++++++++++++++++
1 file changed, 21 insertions(+)
create mode 100644 Package.json
diff --git a/Package.json b/Package.json
new file mode 100644
index 0000000..84b6879
--- /dev/null
+++ b/Package.json
@@ -0,0 +1,21 @@
+{
+ "name": "jquery.loadtemplate",
+ "version": "1.4.5",
+ "author": "Paul Burgess",
+ "description": "jQuery plugin for loading and using templates. The plugin is designed to be simple yet powerful, and supports loading templates from within the page, or using AJAX to load html files.",
+ "homepage": "http://codepb.github.io/jquery-template/",
+ "keywords": [
+ "templates",
+ "templating",
+ "jquery-plugin"
+ ],
+ "bugs": "https://github.com/codepb/jquery-template/issues",
+ "license": "MIT",
+ "repository" : {
+ "type" : "git",
+ "url" : "https://github.com/codepb/jquery-template"
+ },
+ "dependencies" : {
+ "jquery": ">=1.8"
+ }
+}
From bc9632a97160b6a330da14b530c50d91c4596705 Mon Sep 17 00:00:00 2001
From: Vladimir Kalyuzhny
Date: Mon, 16 Feb 2015 10:16:17 +0200
Subject: [PATCH 45/71] Package.json -> package.json
npm http GET https://registry.npmjs.org/jquery.loadtemplate
npm http 304 https://registry.npmjs.org/jquery.loadtemplate
npm http GET https://registry.npmjs.org/jquery.loadtemplate/-/jquery.loadtemplate-1.4.5.tgz
npm http 200 https://registry.npmjs.org/jquery.loadtemplate/-/jquery.loadtemplate-1.4.5.tgz
npm ERR! Error: ENOENT, open '/home/user/tmp/npm-3110-yhl7Nl4j/1424074130295-0.633399919141084/package/package.json'
npm ERR! If you need help, you may report this log at:
npm ERR!
npm ERR! or email it to:
npm ERR!
package.json should be named in lower case.
---
Package.json => package.json | 0
1 file changed, 0 insertions(+), 0 deletions(-)
rename Package.json => package.json (100%)
diff --git a/Package.json b/package.json
similarity index 100%
rename from Package.json
rename to package.json
From bfa83fee4ab7ba78144a02ecf74aa38038866f49 Mon Sep 17 00:00:00 2001
From: Paul Burgess
Date: Sun, 1 Mar 2015 21:32:03 +0000
Subject: [PATCH 46/71] Adding bower.json
---
bower.json | 34 ++++++++++++++++++++++++++++++++++
1 file changed, 34 insertions(+)
create mode 100644 bower.json
diff --git a/bower.json b/bower.json
new file mode 100644
index 0000000..01af15b
--- /dev/null
+++ b/bower.json
@@ -0,0 +1,34 @@
+{
+ "name": "jquery-load-template",
+ "version": "1.4.5",
+ "authors": [
+ { "name": "Paul Burgess"}
+ ],
+ "homepage": "http://codepb.github.io/jquery-template/",
+ "repository": {
+ "type": "git",
+ "url": "git://github.com/codepb/jquery-template.git"
+ }
+ "description": "jQuery plugin for loading and using templates. The plugin is designed to be simple yet powerful, and supports loading templates from within the page, or using AJAX to load html files.",
+ "main": "jquery-loadTemplate/jquery.loadTemplate.js",
+ "ignore": [
+ "Examples",
+ "tests",
+ ".gitattributes",
+ ".gitignore",
+ ".travis.yml",
+ "bower.json",
+ "loadTemplate.jquery.json",
+ "MIT-LICENSE.txt",
+ "package.json",
+ "readme.md"
+ ]
+ "keywords": [
+ "templates",
+ "templating",
+ "jquery-plugin"
+ ],
+ "dependencies": {
+ "jquery": ">=1.8"
+ },
+}
From 5011b0dcc2c35a0213e0a15a2143d890d00e012a Mon Sep 17 00:00:00 2001
From: codepb
Date: Tue, 2 Jun 2015 08:59:10 +0100
Subject: [PATCH 47/71] Update readme.md to include documentation on async
---
readme.md | 1 +
1 file changed, 1 insertion(+)
diff --git a/readme.md b/readme.md
index 5267759..7ed4472 100644
--- a/readme.md
+++ b/readme.md
@@ -134,6 +134,7 @@ There are a number of options the plugin accepts. These can be set by passing an
The full list of options are:
- "overwriteCache" (default false) - Whether to ignore the cache and reload the template (if you've previously loaded the template, but it might have changed, you'll want to set this to true.
+- "async" (default true) - Whether to load templates asynchronously (if templates require an Ajax call)
- "complete" (default null) - Callback function to call on complete. Will always be called regardless of success or failure.
- "success" (default null) - Callback function to call on successful completion.
- "error" (default, outputting error message to template container) - Callback function to call on error.
From 312cc023d312081430c79ce63f26a59be39fcb63 Mon Sep 17 00:00:00 2001
From: Paul Burgess
Date: Thu, 3 Sep 2015 15:38:31 +0100
Subject: [PATCH 48/71] beforeInsert/afterInsert callbacks and error info
additions
Added the data to beforeInsert and afterInsert callbacks: fixes #69.
Updated the error callback to add in the error coming from the ajax
call. fixes #67.
---
Examples/SimpleExample/example.html | 2 +-
Examples/index.html | 2 +-
bower.json | 2 +-
.../jquery.loadTemplate-1.4.5.min.js | 1 -
...-1.4.5.js => jquery.loadTemplate-1.5.0.js} | 27 ++++++++++---------
.../jquery.loadTemplate-1.5.0.min.js | 1 +
loadTemplate.jquery.json | 2 +-
tests/index.html | 2 +-
8 files changed, 21 insertions(+), 18 deletions(-)
delete mode 100644 jquery-loadTemplate/jquery.loadTemplate-1.4.5.min.js
rename jquery-loadTemplate/{jquery.loadTemplate-1.4.5.js => jquery.loadTemplate-1.5.0.js} (97%)
create mode 100644 jquery-loadTemplate/jquery.loadTemplate-1.5.0.min.js
diff --git a/Examples/SimpleExample/example.html b/Examples/SimpleExample/example.html
index 6f77930..d5fc7a4 100644
--- a/Examples/SimpleExample/example.html
+++ b/Examples/SimpleExample/example.html
@@ -88,7 +88,7 @@
Example of loading a template from a script tag within the same document.
-
+
diff --git a/bower.json b/bower.json
index 01af15b..b33029b 100644
--- a/bower.json
+++ b/bower.json
@@ -1,6 +1,6 @@
{
"name": "jquery-load-template",
- "version": "1.4.5",
+ "version": "1.5.0",
"authors": [
{ "name": "Paul Burgess"}
],
diff --git a/jquery-loadTemplate/jquery.loadTemplate-1.4.5.min.js b/jquery-loadTemplate/jquery.loadTemplate-1.4.5.min.js
deleted file mode 100644
index 64dab52..0000000
--- a/jquery-loadTemplate/jquery.loadTemplate-1.4.5.min.js
+++ /dev/null
@@ -1 +0,0 @@
-(function(a){var v={},u={},h={};function n(F,B,D){var A=this,z,C,E;B=B||{};E=a.extend(true,{async:true,overwriteCache:false,complete:null,success:null,error:function(){a(this).each(function(){a(this).html(E.errorMessage)})},errorMessage:"There was an error loading the template.",paged:false,pageNo:1,elemPerPage:10,append:false,prepend:false,beforeInsert:null,afterInsert:null,bindingOptions:{ignoreUndefined:false,ignoreNull:false,ignoreEmptyString:false}},D);if(a.type(B)==="array"){return s.call(this,F,B,E)}if(!g(F)){z=a(F);if(typeof F==="string"&&F.indexOf("#")===0){E.isFile=false}}C=E.isFile||(typeof E.isFile==="undefined"&&(typeof z==="undefined"||z.length===0));if(C&&!E.overwriteCache&&v[F]){q(F,A,B,E)}else{if(C&&!E.overwriteCache&&v.hasOwnProperty(F)){c(F,A,B,E)}else{if(C){m(F,A,B,E)}else{o(z,A,B,E)}}}return this}function b(A,z){if(z){h[A]=z}else{h=a.extend(h,A)}}function g(z){return typeof z==="string"&&z.indexOf("/")>-1}function s(I,A,F){F=F||{};var z=this,J=A.length,C=F.prepend&&!F.append,B=0,H=0,D=false,E;if(F.paged){var G=(F.pageNo-1)*F.elemPerPage;A=A.slice(G,G+F.elemPerPage);J=A.length}E=a.extend({},F,{complete:function(){if(this.html){if(C){z.prepend(this.html())}else{z.append(this.html())}}B++;if(B===J||D){if(D&&F&&typeof F.error==="function"){F.error.call(z)}if(F&&typeof F.complete==="function"){F.complete()}}},success:function(){H++;if(H===J){if(F&&typeof F.success==="function"){F.success()}}},error:function(){D=true}});if(!F.append&&!F.prepend){z.html("")}if(C){A.reverse()}a(A).each(function(){var K=a("");n.call(K,I,this,E);if(D){return false}});return this}function c(C,A,z,B){if(u[C]){u[C].push({data:z,selection:A,settings:B})}else{u[C]=[{data:z,selection:A,settings:B}]}}function q(D,B,A,C){var z=v[D].clone();p.call(B,z,A,C);if(typeof C.success==="function"){C.success()}}function w(){return new Date().getTime()}function x(z){if(z.indexOf("?")!==-1){return z+"&_="+w()}else{return z+"?_="+w()}}function m(D,B,A,C){var z=a("");v[D]=null;var E=D;if(C.overwriteCache){E=x(E)}a.ajax({url:E,async:C.async,success:function(F){z.html(F);l(z,D,B,A,C)},error:function(){k(D,B,A,C)}})}function o(z,C,B,D){var A=a("");if(z.is("script")||z.is("template")){z=a.parseHTML(a.trim(z.html()))}A.html(z);p.call(C,A,B,D);if(typeof D.success==="function"){D.success()}}function p(B,z,A){f(B,z,A);a(this).each(function(){var C=a(B.html());if(A.beforeInsert){A.beforeInsert(C)}if(A.append){a(this).append(C)}else{if(A.prepend){a(this).prepend(C)}else{a(this).html(C)}}if(A.afterInsert){A.afterInsert(C)}});if(typeof A.complete==="function"){A.complete.call(a(this))}}function k(C,A,z,B){var D;if(typeof B.error==="function"){B.error.call(A)}a(u[C]).each(function(E,F){if(typeof F.settings.error==="function"){F.settings.error.call(F.selection)}});if(typeof B.complete==="function"){B.complete.call(A)}while(u[C]&&(D=u[C].shift())){if(typeof D.settings.complete==="function"){D.settings.complete.call(D.selection)}}if(typeof u[C]!=="undefined"&&u[C].length>0){u[C]=[]}}function l(z,D,B,A,C){var E;v[D]=z.clone();p.call(B,z,A,C);if(typeof C.success==="function"){C.success.call(B)}while(u[D]&&(E=u[D].shift())){p.call(E.selection,v[D].clone(),E.data,E.settings);if(typeof E.settings.success==="function"){E.settings.success.call(E.selection)}}}function f(B,z,A){z=z||{};t("data-content",B,z,A,function(C,D){C.html(e(C,D,"content",A))});t("data-content-append",B,z,A,function(C,D){C.append(e(C,D,"content",A))});t("data-content-prepend",B,z,A,function(C,D){C.prepend(e(C,D,"content",A))});t("data-content-text",B,z,A,function(C,D){C.text(e(C,D,"content",A))});t("data-innerHTML",B,z,A,function(C,D){C.html(e(C,D,"content",A))});t("data-src",B,z,A,function(C,D){C.attr("src",e(C,D,"src",A))},function(C){C.remove()});t("data-href",B,z,A,function(C,D){C.attr("href",e(C,D,"href",A))},function(C){C.remove()});t("data-alt",B,z,A,function(C,D){C.attr("alt",e(C,D,"alt",A))});t("data-id",B,z,A,function(C,D){C.attr("id",e(C,D,"id",A))});t("data-value",B,z,A,function(C,D){C.attr("value",e(C,D,"value",A))});t("data-class",B,z,A,function(C,D){C.addClass(e(C,D,"class",A))});t("data-link",B,z,A,function(C,E){var D=a("");D.attr("href",e(C,E,"link",A));D.html(C.html());C.html(D)});t("data-link-wrap",B,z,A,function(C,E){var D=a("");D.attr("href",e(C,E,"link-wrap",A));C.wrap(D)});t("data-options",B,z,A,function(C,D){a(D).each(function(){var E=a("");E.attr("value",this).text(this).appendTo(C)})});r(B,z,A)}function t(z,E,A,D,B,C){a("["+z+"]",E).each(function(){var F=a(this),G=F.attr(z),H=j(A,G);if(!y(F,H,D)){F.remove();return}F.removeAttr(z);if(typeof H!=="undefined"&&B){B(F,H)}else{if(C){C(F)}}});return}function y(A,C,B){var z=i(A,B);if(z.ignoreUndefined&&typeof C==="undefined"){return false}else{if(z.ignoreNull&&C===null){return false}else{if(z.ignoreEmptyString&&C===""){return false}else{return true}}}}function i(A,B){var z={};if(A instanceof jQuery&&A.attr("data-binding-options")){z=a.parseJSON(A.attr("data-binding-options"));A.removeAttr("data-binding-options")}else{if(typeof A==="object"&&A.hasOwnProperty("bindingOptions")){z=A.bindingOptions}}return a.extend({},B.bindingOptions,z)}function r(B,z,A){a("[data-template-bind]",B).each(function(){var C=a(this),D=a.parseJSON(C.attr("data-template-bind"));C.removeAttr("data-template-bind");a(D).each(function(){var F;if(typeof(this.value)==="object"){F=j(z,this.value.data)}else{F=j(z,this.value)}if(this.attribute){if(!y(this,F,A)){C.remove();return}switch(this.attribute){case"content":case"innerHTML":C.html(d(C,F,this));break;case"contentAppend":C.append(d(C,F,this));break;case"contentPrepend":C.prepend(d(C,F,this));break;case"contentText":C.text(d(C,F,this));break;case"options":var E=this;a(F).each(function(){var G=a("");G.attr("value",this[E.value.value]).text(d(C,this[E.value.content],E)).attr("selected",typeof this[E.value.selected]==undefined?false:this[E.value.selected]).appendTo(C)});break;default:C.attr(this.attribute,d(C,F,this))}}})})}function d(z,C,A,B){if(A.formatter&&h[A.formatter]){return(function(D){return h[A.formatter].call(z,C,A.formatOptions,D)})(B)}return C}function j(z,A){if(A==="this"){return z}var B=A.split("."),C,D=z;while((C=B.shift())&&typeof D!=="undefined"&&D!=null){D=D[C]}return D}function e(z,F,A,E){var D=z.attr("data-format-target"),C;if(D===A||(!D&&A==="content")){C=z.attr("data-format");if(C&&typeof h[C]==="function"){var B=z.attr("data-format-options");return(function(G){return h[C].call(z[0],F,B,a.extend({},G))})(E)}}return F}b("nestedTemplateFormatter",function(D,A,z){if(!A){return}if(typeof A==="string"&&A[0]==="{"){A=a.parseJSON(A)}var B=A.parentElement||"div";var C=A.template||A;if(A.parentElement){return a("<"+B+"/>").loadTemplate(C,D,z)}else{return a("<"+B+"/>").loadTemplate(C,D,z).children()}});a.fn.loadTemplate=n;a.addTemplateFormatter=b})(jQuery);
\ No newline at end of file
diff --git a/jquery-loadTemplate/jquery.loadTemplate-1.4.5.js b/jquery-loadTemplate/jquery.loadTemplate-1.5.0.js
similarity index 97%
rename from jquery-loadTemplate/jquery.loadTemplate-1.4.5.js
rename to jquery-loadTemplate/jquery.loadTemplate-1.5.0.js
index 46275a8..209cfa3 100644
--- a/jquery-loadTemplate/jquery.loadTemplate-1.4.5.js
+++ b/jquery-loadTemplate/jquery.loadTemplate-1.5.0.js
@@ -83,6 +83,7 @@
done = 0,
success = 0,
errored = false,
+ errorObjects = [],
newOptions;
if (settings.paged) {
@@ -95,6 +96,7 @@
{},
settings,
{
+ async: false,
complete: function () {
if (this.html) {
if (doPrepend) {
@@ -106,7 +108,7 @@
done++;
if (done === todo || errored) {
if (errored && settings && typeof settings.error === "function") {
- settings.error.call($that);
+ settings.error.call($that, errorObjects);
}
if (settings && typeof settings.complete === "function") {
settings.complete();
@@ -121,8 +123,9 @@
}
}
},
- error: function () {
+ error: function (e) {
errored = true;
+ errorObjects.push(e);
}
}
);
@@ -188,8 +191,8 @@
$templateContainer.html(templateContent);
handleTemplateLoadingSuccess($templateContainer, template, selection, data, settings);
},
- error: function () {
- handleTemplateLoadingError(template, selection, data, settings);
+ error: function (e) {
+ handleTemplateLoadingError(template, selection, data, settings, e);
}
});
}
@@ -215,7 +218,7 @@
$(this).each(function () {
var $templateHtml = $(template.html());
if (settings.beforeInsert) {
- settings.beforeInsert($templateHtml);
+ settings.beforeInsert($templateHtml, data);
}
if (settings.append) {
@@ -226,7 +229,7 @@
$(this).html($templateHtml);
}
if (settings.afterInsert) {
- settings.afterInsert($templateHtml);
+ settings.afterInsert($templateHtml, data);
}
});
@@ -235,16 +238,16 @@
}
}
- function handleTemplateLoadingError(template, selection, data, settings) {
+ function handleTemplateLoadingError(template, selection, data, settings, error) {
var value;
if (typeof settings.error === "function") {
- settings.error.call(selection);
+ settings.error.call(selection, error);
}
$(queue[template]).each(function (key, value) {
if (typeof value.settings.error === "function") {
- value.settings.error.call(value.selection);
+ value.settings.error.call(value.selection, error);
}
});
@@ -309,7 +312,7 @@
}, function ($elem) {
$elem.remove();
});
-
+
processElements("data-href", template, data, settings, function ($elem, value) {
$elem.attr("href", applyFormatters($elem, value, "href", settings));
}, function ($elem) {
@@ -520,9 +523,9 @@
var parentElement = options.parentElement || "div";
var template = options.template || options;
-
+
//If a parent is specified, return it; otherwise only return the generated children.
- if(options.parentElement)
+ if (options.parentElement)
return $("<" + parentElement + "/>").loadTemplate(template, value, internalSettings);
else
return $("<" + parentElement + "/>").loadTemplate(template, value, internalSettings).children();
diff --git a/jquery-loadTemplate/jquery.loadTemplate-1.5.0.min.js b/jquery-loadTemplate/jquery.loadTemplate-1.5.0.min.js
new file mode 100644
index 0000000..1333b7b
--- /dev/null
+++ b/jquery-loadTemplate/jquery.loadTemplate-1.5.0.min.js
@@ -0,0 +1 @@
+(function(a){var v={},u={},h={};function n(F,B,D){var A=this,z,C,E;B=B||{};E=a.extend(true,{async:true,overwriteCache:false,complete:null,success:null,error:function(){a(this).each(function(){a(this).html(E.errorMessage)})},errorMessage:"There was an error loading the template.",paged:false,pageNo:1,elemPerPage:10,append:false,prepend:false,beforeInsert:null,afterInsert:null,bindingOptions:{ignoreUndefined:false,ignoreNull:false,ignoreEmptyString:false}},D);if(a.type(B)==="array"){return s.call(this,F,B,E)}if(!g(F)){z=a(F);if(typeof F==="string"&&F.indexOf("#")===0){E.isFile=false}}C=E.isFile||(typeof E.isFile==="undefined"&&(typeof z==="undefined"||z.length===0));if(C&&!E.overwriteCache&&v[F]){q(F,A,B,E)}else{if(C&&!E.overwriteCache&&v.hasOwnProperty(F)){c(F,A,B,E)}else{if(C){m(F,A,B,E)}else{o(z,A,B,E)}}}return this}function b(A,z){if(z){h[A]=z}else{h=a.extend(h,A)}}function g(z){return typeof z==="string"&&z.indexOf("/")>-1}function s(J,A,G){G=G||{};var z=this,K=A.length,C=G.prepend&&!G.append,B=0,I=0,D=false,E=[],F;if(G.paged){var H=(G.pageNo-1)*G.elemPerPage;A=A.slice(H,H+G.elemPerPage);K=A.length}F=a.extend({},G,{async:false,complete:function(){if(this.html){if(C){z.prepend(this.html())}else{z.append(this.html())}}B++;if(B===K||D){if(D&&G&&typeof G.error==="function"){G.error.call(z,E)}if(G&&typeof G.complete==="function"){G.complete()}}},success:function(){I++;if(I===K){if(G&&typeof G.success==="function"){G.success()}}},error:function(L){D=true;E.push(L)}});if(!G.append&&!G.prepend){z.html("")}if(C){A.reverse()}a(A).each(function(){var L=a("");n.call(L,J,this,F);if(D){return false}});return this}function c(C,A,z,B){if(u[C]){u[C].push({data:z,selection:A,settings:B})}else{u[C]=[{data:z,selection:A,settings:B}]}}function q(D,B,A,C){var z=v[D].clone();p.call(B,z,A,C);if(typeof C.success==="function"){C.success()}}function w(){return new Date().getTime()}function x(z){if(z.indexOf("?")!==-1){return z+"&_="+w()}else{return z+"?_="+w()}}function m(D,B,A,C){var z=a("");v[D]=null;var E=D;if(C.overwriteCache){E=x(E)}a.ajax({url:E,async:C.async,success:function(F){z.html(F);l(z,D,B,A,C)},error:function(F){k(D,B,A,C,F)}})}function o(z,C,B,D){var A=a("");if(z.is("script")||z.is("template")){z=a.parseHTML(a.trim(z.html()))}A.html(z);p.call(C,A,B,D);if(typeof D.success==="function"){D.success()}}function p(B,z,A){f(B,z,A);a(this).each(function(){var C=a(B.html());if(A.beforeInsert){A.beforeInsert(C,z)}if(A.append){a(this).append(C)}else{if(A.prepend){a(this).prepend(C)}else{a(this).html(C)}}if(A.afterInsert){A.afterInsert(C,z)}});if(typeof A.complete==="function"){A.complete.call(a(this))}}function k(D,B,z,C,A){var E;if(typeof C.error==="function"){C.error.call(B,A)}a(u[D]).each(function(F,G){if(typeof G.settings.error==="function"){G.settings.error.call(G.selection,A)}});if(typeof C.complete==="function"){C.complete.call(B)}while(u[D]&&(E=u[D].shift())){if(typeof E.settings.complete==="function"){E.settings.complete.call(E.selection)}}if(typeof u[D]!=="undefined"&&u[D].length>0){u[D]=[]}}function l(z,D,B,A,C){var E;v[D]=z.clone();p.call(B,z,A,C);if(typeof C.success==="function"){C.success.call(B)}while(u[D]&&(E=u[D].shift())){p.call(E.selection,v[D].clone(),E.data,E.settings);if(typeof E.settings.success==="function"){E.settings.success.call(E.selection)}}}function f(B,z,A){z=z||{};t("data-content",B,z,A,function(C,D){C.html(e(C,D,"content",A))});t("data-content-append",B,z,A,function(C,D){C.append(e(C,D,"content",A))});t("data-content-prepend",B,z,A,function(C,D){C.prepend(e(C,D,"content",A))});t("data-content-text",B,z,A,function(C,D){C.text(e(C,D,"content",A))});t("data-innerHTML",B,z,A,function(C,D){C.html(e(C,D,"content",A))});t("data-src",B,z,A,function(C,D){C.attr("src",e(C,D,"src",A))},function(C){C.remove()});t("data-href",B,z,A,function(C,D){C.attr("href",e(C,D,"href",A))},function(C){C.remove()});t("data-alt",B,z,A,function(C,D){C.attr("alt",e(C,D,"alt",A))});t("data-id",B,z,A,function(C,D){C.attr("id",e(C,D,"id",A))});t("data-value",B,z,A,function(C,D){C.attr("value",e(C,D,"value",A))});t("data-class",B,z,A,function(C,D){C.addClass(e(C,D,"class",A))});t("data-link",B,z,A,function(C,E){var D=a("");D.attr("href",e(C,E,"link",A));D.html(C.html());C.html(D)});t("data-link-wrap",B,z,A,function(C,E){var D=a("");D.attr("href",e(C,E,"link-wrap",A));C.wrap(D)});t("data-options",B,z,A,function(C,D){a(D).each(function(){var E=a("");E.attr("value",this).text(this).appendTo(C)})});r(B,z,A)}function t(z,E,A,D,B,C){a("["+z+"]",E).each(function(){var F=a(this),G=F.attr(z),H=j(A,G);if(!y(F,H,D)){F.remove();return}F.removeAttr(z);if(typeof H!=="undefined"&&B){B(F,H)}else{if(C){C(F)}}});return}function y(A,C,B){var z=i(A,B);if(z.ignoreUndefined&&typeof C==="undefined"){return false}else{if(z.ignoreNull&&C===null){return false}else{if(z.ignoreEmptyString&&C===""){return false}else{return true}}}}function i(A,B){var z={};if(A instanceof jQuery&&A.attr("data-binding-options")){z=a.parseJSON(A.attr("data-binding-options"));A.removeAttr("data-binding-options")}else{if(typeof A==="object"&&A.hasOwnProperty("bindingOptions")){z=A.bindingOptions}}return a.extend({},B.bindingOptions,z)}function r(B,z,A){a("[data-template-bind]",B).each(function(){var C=a(this),D=a.parseJSON(C.attr("data-template-bind"));C.removeAttr("data-template-bind");a(D).each(function(){var F;if(typeof(this.value)==="object"){F=j(z,this.value.data)}else{F=j(z,this.value)}if(this.attribute){if(!y(this,F,A)){C.remove();return}switch(this.attribute){case"content":case"innerHTML":C.html(d(C,F,this));break;case"contentAppend":C.append(d(C,F,this));break;case"contentPrepend":C.prepend(d(C,F,this));break;case"contentText":C.text(d(C,F,this));break;case"options":var E=this;a(F).each(function(){var G=a("");G.attr("value",this[E.value.value]).text(d(C,this[E.value.content],E)).attr("selected",typeof this[E.value.selected]==undefined?false:this[E.value.selected]).appendTo(C)});break;default:C.attr(this.attribute,d(C,F,this))}}})})}function d(z,C,A,B){if(A.formatter&&h[A.formatter]){return(function(D){return h[A.formatter].call(z,C,A.formatOptions,D)})(B)}return C}function j(z,A){if(A==="this"){return z}var B=A.split("."),C,D=z;while((C=B.shift())&&typeof D!=="undefined"&&D!=null){D=D[C]}return D}function e(z,F,A,E){var D=z.attr("data-format-target"),C;if(D===A||(!D&&A==="content")){C=z.attr("data-format");if(C&&typeof h[C]==="function"){var B=z.attr("data-format-options");return(function(G){return h[C].call(z[0],F,B,a.extend({},G))})(E)}}return F}b("nestedTemplateFormatter",function(D,A,z){if(!A){return}if(typeof A==="string"&&A[0]==="{"){A=a.parseJSON(A)}var B=A.parentElement||"div";var C=A.template||A;if(A.parentElement){return a("<"+B+"/>").loadTemplate(C,D,z)}else{return a("<"+B+"/>").loadTemplate(C,D,z).children()}});a.fn.loadTemplate=n;a.addTemplateFormatter=b})(jQuery);
\ No newline at end of file
diff --git a/loadTemplate.jquery.json b/loadTemplate.jquery.json
index 3ff9610..383ad61 100644
--- a/loadTemplate.jquery.json
+++ b/loadTemplate.jquery.json
@@ -6,7 +6,7 @@
"templates",
"templating"
],
- "version": "1.4.5",
+ "version": "1.5.0",
"author": {
"name": "Paul Burgess and other contributors",
"url": "https://github.com/codepb/jquery-template"
diff --git a/tests/index.html b/tests/index.html
index e1d7e36..e70f28a 100644
--- a/tests/index.html
+++ b/tests/index.html
@@ -3,7 +3,7 @@
loadTemplate Test Suite
-
+
From 68a627762d2cc2ec50c0c08839d007f82ae1f831 Mon Sep 17 00:00:00 2001
From: Paul Burgess
Date: Thu, 3 Sep 2015 15:45:52 +0100
Subject: [PATCH 49/71] updating package.json
---
package.json | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/package.json b/package.json
index 84b6879..a1ac9c4 100644
--- a/package.json
+++ b/package.json
@@ -1,6 +1,6 @@
{
"name": "jquery.loadtemplate",
- "version": "1.4.5",
+ "version": "1.5.0",
"author": "Paul Burgess",
"description": "jQuery plugin for loading and using templates. The plugin is designed to be simple yet powerful, and supports loading templates from within the page, or using AJAX to load html files.",
"homepage": "http://codepb.github.io/jquery-template/",
From 5a34a469fed9195bf03450912827a75ba9daf69b Mon Sep 17 00:00:00 2001
From: Laurent
Date: Tue, 22 Sep 2015 14:33:20 +0200
Subject: [PATCH 50/71] bower.json fix
---
bower.json | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/bower.json b/bower.json
index b33029b..19cae22 100644
--- a/bower.json
+++ b/bower.json
@@ -8,7 +8,7 @@
"repository": {
"type": "git",
"url": "git://github.com/codepb/jquery-template.git"
- }
+ },
"description": "jQuery plugin for loading and using templates. The plugin is designed to be simple yet powerful, and supports loading templates from within the page, or using AJAX to load html files.",
"main": "jquery-loadTemplate/jquery.loadTemplate.js",
"ignore": [
@@ -22,7 +22,7 @@
"MIT-LICENSE.txt",
"package.json",
"readme.md"
- ]
+ ],
"keywords": [
"templates",
"templating",
@@ -30,5 +30,5 @@
],
"dependencies": {
"jquery": ">=1.8"
- },
+ }
}
From f2a788762d631076e086812e72fbbf9c50a6a09e Mon Sep 17 00:00:00 2001
From: codepb
Date: Mon, 30 Nov 2015 10:29:16 +0000
Subject: [PATCH 51/71] Update to include information about arrays
Fixes #78
---
readme.md | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)
diff --git a/readme.md b/readme.md
index 7ed4472..b8cb88b 100644
--- a/readme.md
+++ b/readme.md
@@ -58,6 +58,10 @@ Similarly the content of the template could be held in a separate html file with
The plugin has a number of data-... attributes that can be used to populate various attributes with the data. There is also the powerful data-template-bind attribute that accepts a JSON object, enabling binding to any attribute, or the content of the element.
+#### Arrays
+
+You can pass an array of objects instead of a single object and the template will be populated and added to the container for each item in the array. There are options built in that allow you to page the results from an array as well. See the options section below and the included examples.
+
### Data Formatters
It is also possible to define data formatters. These are assigned through the `$.addTemplateFormatter` method. This function either accepts a map of functions and the keys that they will be referenced by, or a single function with a single key as two separate parameters. Each formatter takes two values, the value being assigned, and a template to use to define how this data is displayed. The data-format-template may be empty. Example usage of this is below:
@@ -95,7 +99,7 @@ Formatters must be added before they are used else a template will not be able t
### Bindings
There are a number of different bindings and ways to bind the data. The following attributes are available:
-- "data-innerHTML" (<= 1.4.5) - binds the value supplied to the content (innerHTML) of the element (uses $(elem).html(value))
+- "data-innerHTML" (>= 1.4.5) - binds the value supplied to the content (innerHTML) of the element (uses $(elem).html(value))
- "data-content" - alias for the newer "data-innerHTML"
- "data-content-text" - binds the value supplied to the content of the element as text (uses $(elem).text(value))
- "data-content-append" - appends the value to the end of the element (uses $(elem).append(value))
From 8935e352a20f5838e3d5755b8b3927c2ef1e593b Mon Sep 17 00:00:00 2001
From: sorenwojo
Date: Thu, 21 Jan 2016 16:42:54 +0100
Subject: [PATCH 52/71] Fire afterInsert when item from array has been inserted
Added different handling of afterInsert event when data is an array.
When data is not an array event will be fired as before.
---
.../jquery.loadTemplate-1.5.0.js | 18 ++++++++++++------
1 file changed, 12 insertions(+), 6 deletions(-)
diff --git a/jquery-loadTemplate/jquery.loadTemplate-1.5.0.js b/jquery-loadTemplate/jquery.loadTemplate-1.5.0.js
index 209cfa3..d0f8954 100644
--- a/jquery-loadTemplate/jquery.loadTemplate-1.5.0.js
+++ b/jquery-loadTemplate/jquery.loadTemplate-1.5.0.js
@@ -2,7 +2,8 @@
"use strict";
var templates = {},
queue = {},
- formatters = {};
+ formatters = {},
+ isArray;
function loadTemplate(template, data, options) {
var $that = this,
@@ -39,6 +40,7 @@
}, options);
if ($.type(data) === "array") {
+ isArray = true;
return processArray.call(this, template, data, settings);
}
@@ -97,12 +99,16 @@
settings,
{
async: false,
- complete: function () {
+ complete: function (data) {
if (this.html) {
+ var insertedElement;
if (doPrepend) {
- $that.prepend(this.html());
+ insertedElement = $(this.html()).prependTo($that);
} else {
- $that.append(this.html());
+ insertedElement = $(this.html()).appendTo($that);
+ }
+ if (settings.afterInsert && data) {
+ settings.afterInsert(insertedElement, data);
}
}
done++;
@@ -228,13 +234,13 @@
} else {
$(this).html($templateHtml);
}
- if (settings.afterInsert) {
+ if (settings.afterInsert && !isArray) {
settings.afterInsert($templateHtml, data);
}
});
if (typeof settings.complete === "function") {
- settings.complete.call($(this));
+ settings.complete.call($(this), data);
}
}
From 501ce5b1c491a66c247866f3321c9416550e23ce Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?S=C3=B8ren=20J=C3=B8rgensen?=
Date: Fri, 29 Jan 2016 22:43:58 +0100
Subject: [PATCH 53/71] Fixed failing test
Moved incrementation of counter to before comparison as template now has been added when event is fired.
---
tests/files/callback.js | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/tests/files/callback.js b/tests/files/callback.js
index b9899d4..40abd43 100644
--- a/tests/files/callback.js
+++ b/tests/files/callback.js
@@ -49,12 +49,12 @@
afterInsert : function(elem){
sequence.push('after');
+ ++afterInsertCounter;
+
if ($('#render').children().length === afterInsertCounter) {
elemSequence.push(true);
}
-
- ++afterInsertCounter;
-
+
},
complete : function(){
sequence.push('complete');
From 3c0dadf03e6ef99940f41bcc27825bed982eed6f Mon Sep 17 00:00:00 2001
From: Paul Burgess
Date: Mon, 29 Feb 2016 09:54:13 +0000
Subject: [PATCH 54/71] Updating version
---
Examples/index.html | 2 +-
bower.json | 2 +-
jquery-loadTemplate/jquery.loadTemplate-1.5.0.min.js | 1 -
...query.loadTemplate-1.5.0.js => jquery.loadTemplate-1.5.1.js} | 0
jquery-loadTemplate/jquery.loadTemplate-1.5.1.min.js | 1 +
loadTemplate.jquery.json | 2 +-
package.json | 2 +-
tests/index.html | 2 +-
8 files changed, 6 insertions(+), 6 deletions(-)
delete mode 100644 jquery-loadTemplate/jquery.loadTemplate-1.5.0.min.js
rename jquery-loadTemplate/{jquery.loadTemplate-1.5.0.js => jquery.loadTemplate-1.5.1.js} (100%)
create mode 100644 jquery-loadTemplate/jquery.loadTemplate-1.5.1.min.js
diff --git a/Examples/index.html b/Examples/index.html
index d12c8a1..a5b2e3c 100644
--- a/Examples/index.html
+++ b/Examples/index.html
@@ -9,7 +9,7 @@
-
+
diff --git a/bower.json b/bower.json
index dda5299..6940479 100644
--- a/bower.json
+++ b/bower.json
@@ -1,16 +1,14 @@
{
"name": "jquery-load-template",
- "version": "1.5.1",
"authors": [
{ "name": "Paul Burgess"}
],
"homepage": "http://codepb.github.io/jquery-template/",
"repository": {
"type": "git",
- "url": "git://github.com/codepb/jquery-template.git"
+ "url": "https://github.com/codepb/jquery-template.git"
},
"description": "jQuery plugin for loading and using templates. The plugin is designed to be simple yet powerful, and supports loading templates from within the page, or using AJAX to load html files.",
- "main": "jquery-loadTemplate/jquery.loadTemplate.js",
"ignore": [
"Examples",
"tests",
diff --git a/jquery-loadTemplate/jquery.loadTemplate-1.5.1.js b/jquery-loadTemplate/jquery.loadTemplate-1.5.2.js
similarity index 100%
rename from jquery-loadTemplate/jquery.loadTemplate-1.5.1.js
rename to jquery-loadTemplate/jquery.loadTemplate-1.5.2.js
diff --git a/jquery-loadTemplate/jquery.loadTemplate-1.5.1.min.js b/jquery-loadTemplate/jquery.loadTemplate-1.5.2.min.js
similarity index 100%
rename from jquery-loadTemplate/jquery.loadTemplate-1.5.1.min.js
rename to jquery-loadTemplate/jquery.loadTemplate-1.5.2.min.js
diff --git a/loadTemplate.jquery.json b/loadTemplate.jquery.json
index be5219b..6ed8bf6 100644
--- a/loadTemplate.jquery.json
+++ b/loadTemplate.jquery.json
@@ -6,7 +6,7 @@
"templates",
"templating"
],
- "version": "1.5.1",
+ "version": "1.5.2",
"author": {
"name": "Paul Burgess and other contributors",
"url": "https://github.com/codepb/jquery-template"
diff --git a/package.json b/package.json
index b4133f8..15ab0af 100644
--- a/package.json
+++ b/package.json
@@ -1,6 +1,6 @@
{
"name": "jquery.loadtemplate",
- "version": "1.5.1",
+ "version": "1.5.2",
"author": "Paul Burgess",
"description": "jQuery plugin for loading and using templates. The plugin is designed to be simple yet powerful, and supports loading templates from within the page, or using AJAX to load html files.",
"homepage": "http://codepb.github.io/jquery-template/",
diff --git a/tests/index.html b/tests/index.html
index eda91b2..3c74f9e 100644
--- a/tests/index.html
+++ b/tests/index.html
@@ -3,7 +3,7 @@
loadTemplate Test Suite
-
+
From 538aad652d4e16eba1e88488e94980456df4d61c Mon Sep 17 00:00:00 2001
From: Paul Burgess
Date: Mon, 29 Feb 2016 11:12:34 +0000
Subject: [PATCH 56/71] Attempting to fix bower.json
---
Examples/index.html | 2 +-
bower.json | 19 ++++++++++---------
...-1.5.2.js => jquery.loadTemplate-1.5.3.js} | 0
...in.js => jquery.loadTemplate-1.5.3.min.js} | 0
loadTemplate.jquery.json | 2 +-
package.json | 2 +-
tests/index.html | 2 +-
7 files changed, 14 insertions(+), 13 deletions(-)
rename jquery-loadTemplate/{jquery.loadTemplate-1.5.2.js => jquery.loadTemplate-1.5.3.js} (100%)
rename jquery-loadTemplate/{jquery.loadTemplate-1.5.2.min.js => jquery.loadTemplate-1.5.3.min.js} (100%)
diff --git a/Examples/index.html b/Examples/index.html
index 4b46dbe..8303ace 100644
--- a/Examples/index.html
+++ b/Examples/index.html
@@ -9,7 +9,7 @@
-
+
diff --git a/bower.json b/bower.json
index 6940479..d90121b 100644
--- a/bower.json
+++ b/bower.json
@@ -1,31 +1,32 @@
{
"name": "jquery-load-template",
+ "homepage": "http://codepb.github.io/jquery-template/",
"authors": [
- { "name": "Paul Burgess"}
+ ["Paul Burgess "]
],
- "homepage": "http://codepb.github.io/jquery-template/",
+ "description": "jQuery plugin for loading and using templates. The plugin is designed to be simple yet powerful, and supports loading templates from within the page, or using AJAX to load html files.",
"repository": {
"type": "git",
"url": "https://github.com/codepb/jquery-template.git"
},
- "description": "jQuery plugin for loading and using templates. The plugin is designed to be simple yet powerful, and supports loading templates from within the page, or using AJAX to load html files.",
+ "main": "jquery-loadTemplate-1.5.3.js"
+ "keywords": [
+ "templates",
+ "templating",
+ "jquery-plugin"
+ ],
"ignore": [
"Examples",
"tests",
".gitattributes",
".gitignore",
".travis.yml",
- "bower.json",
"loadTemplate.jquery.json",
"MIT-LICENSE.txt",
"package.json",
"readme.md"
],
- "keywords": [
- "templates",
- "templating",
- "jquery-plugin"
- ],
+
"dependencies": {
"jquery": ">=1.8"
}
diff --git a/jquery-loadTemplate/jquery.loadTemplate-1.5.2.js b/jquery-loadTemplate/jquery.loadTemplate-1.5.3.js
similarity index 100%
rename from jquery-loadTemplate/jquery.loadTemplate-1.5.2.js
rename to jquery-loadTemplate/jquery.loadTemplate-1.5.3.js
diff --git a/jquery-loadTemplate/jquery.loadTemplate-1.5.2.min.js b/jquery-loadTemplate/jquery.loadTemplate-1.5.3.min.js
similarity index 100%
rename from jquery-loadTemplate/jquery.loadTemplate-1.5.2.min.js
rename to jquery-loadTemplate/jquery.loadTemplate-1.5.3.min.js
diff --git a/loadTemplate.jquery.json b/loadTemplate.jquery.json
index 6ed8bf6..6d5588b 100644
--- a/loadTemplate.jquery.json
+++ b/loadTemplate.jquery.json
@@ -6,7 +6,7 @@
"templates",
"templating"
],
- "version": "1.5.2",
+ "version": "1.5.3",
"author": {
"name": "Paul Burgess and other contributors",
"url": "https://github.com/codepb/jquery-template"
diff --git a/package.json b/package.json
index 15ab0af..04cc460 100644
--- a/package.json
+++ b/package.json
@@ -1,6 +1,6 @@
{
"name": "jquery.loadtemplate",
- "version": "1.5.2",
+ "version": "1.5.3",
"author": "Paul Burgess",
"description": "jQuery plugin for loading and using templates. The plugin is designed to be simple yet powerful, and supports loading templates from within the page, or using AJAX to load html files.",
"homepage": "http://codepb.github.io/jquery-template/",
diff --git a/tests/index.html b/tests/index.html
index 3c74f9e..005ff3b 100644
--- a/tests/index.html
+++ b/tests/index.html
@@ -3,7 +3,7 @@
loadTemplate Test Suite
-
+
From d32135f3bf98312bf139afb765abf07fb962a910 Mon Sep 17 00:00:00 2001
From: Paul Burgess
Date: Mon, 29 Feb 2016 11:15:49 +0000
Subject: [PATCH 57/71] Fixed issue with author tag in bower.json
---
Examples/index.html | 2 +-
bower.json | 7 +++----
....loadTemplate-1.5.3.js => jquery.loadTemplate-1.5.4.js} | 0
...plate-1.5.3.min.js => jquery.loadTemplate-1.5.4.min.js} | 0
loadTemplate.jquery.json | 2 +-
package.json | 2 +-
tests/index.html | 2 +-
7 files changed, 7 insertions(+), 8 deletions(-)
rename jquery-loadTemplate/{jquery.loadTemplate-1.5.3.js => jquery.loadTemplate-1.5.4.js} (100%)
rename jquery-loadTemplate/{jquery.loadTemplate-1.5.3.min.js => jquery.loadTemplate-1.5.4.min.js} (100%)
diff --git a/Examples/index.html b/Examples/index.html
index 8303ace..d0af2e8 100644
--- a/Examples/index.html
+++ b/Examples/index.html
@@ -9,7 +9,7 @@
-
+
diff --git a/bower.json b/bower.json
index d90121b..49b4d26 100644
--- a/bower.json
+++ b/bower.json
@@ -2,14 +2,14 @@
"name": "jquery-load-template",
"homepage": "http://codepb.github.io/jquery-template/",
"authors": [
- ["Paul Burgess "]
+ "Paul Burgess "
],
"description": "jQuery plugin for loading and using templates. The plugin is designed to be simple yet powerful, and supports loading templates from within the page, or using AJAX to load html files.",
"repository": {
"type": "git",
"url": "https://github.com/codepb/jquery-template.git"
},
- "main": "jquery-loadTemplate-1.5.3.js"
+ "main": "jquery.loadTemplate-1.5.4.js"
"keywords": [
"templates",
"templating",
@@ -25,8 +25,7 @@
"MIT-LICENSE.txt",
"package.json",
"readme.md"
- ],
-
+ ],
"dependencies": {
"jquery": ">=1.8"
}
diff --git a/jquery-loadTemplate/jquery.loadTemplate-1.5.3.js b/jquery-loadTemplate/jquery.loadTemplate-1.5.4.js
similarity index 100%
rename from jquery-loadTemplate/jquery.loadTemplate-1.5.3.js
rename to jquery-loadTemplate/jquery.loadTemplate-1.5.4.js
diff --git a/jquery-loadTemplate/jquery.loadTemplate-1.5.3.min.js b/jquery-loadTemplate/jquery.loadTemplate-1.5.4.min.js
similarity index 100%
rename from jquery-loadTemplate/jquery.loadTemplate-1.5.3.min.js
rename to jquery-loadTemplate/jquery.loadTemplate-1.5.4.min.js
diff --git a/loadTemplate.jquery.json b/loadTemplate.jquery.json
index 6d5588b..7183432 100644
--- a/loadTemplate.jquery.json
+++ b/loadTemplate.jquery.json
@@ -6,7 +6,7 @@
"templates",
"templating"
],
- "version": "1.5.3",
+ "version": "1.5.4",
"author": {
"name": "Paul Burgess and other contributors",
"url": "https://github.com/codepb/jquery-template"
diff --git a/package.json b/package.json
index 04cc460..7b1f717 100644
--- a/package.json
+++ b/package.json
@@ -1,6 +1,6 @@
{
"name": "jquery.loadtemplate",
- "version": "1.5.3",
+ "version": "1.5.4",
"author": "Paul Burgess",
"description": "jQuery plugin for loading and using templates. The plugin is designed to be simple yet powerful, and supports loading templates from within the page, or using AJAX to load html files.",
"homepage": "http://codepb.github.io/jquery-template/",
diff --git a/tests/index.html b/tests/index.html
index 005ff3b..2c10302 100644
--- a/tests/index.html
+++ b/tests/index.html
@@ -3,7 +3,7 @@
loadTemplate Test Suite
-
+
From ae7ffa01cfd399853923348b630180c116337e34 Mon Sep 17 00:00:00 2001
From: Paul Burgess
Date: Mon, 29 Feb 2016 11:19:06 +0000
Subject: [PATCH 58/71] fixed missing comma after main in bower.json
---
bower.json | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/bower.json b/bower.json
index 49b4d26..4b5dbb2 100644
--- a/bower.json
+++ b/bower.json
@@ -9,7 +9,7 @@
"type": "git",
"url": "https://github.com/codepb/jquery-template.git"
},
- "main": "jquery.loadTemplate-1.5.4.js"
+ "main": "jquery.loadTemplate-1.5.4.js",
"keywords": [
"templates",
"templating",
From 98b5eb84b4a948228b3bf4aa93160d44bcd5ff12 Mon Sep 17 00:00:00 2001
From: Paul Burgess
Date: Mon, 29 Feb 2016 11:20:30 +0000
Subject: [PATCH 59/71] Updating Version
---
Examples/index.html | 2 +-
bower.json | 2 +-
...query.loadTemplate-1.5.4.js => jquery.loadTemplate-1.5.5.js} | 0
...adTemplate-1.5.4.min.js => jquery.loadTemplate-1.5.5.min.js} | 0
loadTemplate.jquery.json | 2 +-
package.json | 2 +-
tests/index.html | 2 +-
7 files changed, 5 insertions(+), 5 deletions(-)
rename jquery-loadTemplate/{jquery.loadTemplate-1.5.4.js => jquery.loadTemplate-1.5.5.js} (100%)
rename jquery-loadTemplate/{jquery.loadTemplate-1.5.4.min.js => jquery.loadTemplate-1.5.5.min.js} (100%)
diff --git a/Examples/index.html b/Examples/index.html
index d0af2e8..f09337f 100644
--- a/Examples/index.html
+++ b/Examples/index.html
@@ -9,7 +9,7 @@
-
+
diff --git a/bower.json b/bower.json
index 4b5dbb2..e9ad1c0 100644
--- a/bower.json
+++ b/bower.json
@@ -9,7 +9,7 @@
"type": "git",
"url": "https://github.com/codepb/jquery-template.git"
},
- "main": "jquery.loadTemplate-1.5.4.js",
+ "main": "jquery.loadTemplate-1.5.5.js",
"keywords": [
"templates",
"templating",
diff --git a/jquery-loadTemplate/jquery.loadTemplate-1.5.4.js b/jquery-loadTemplate/jquery.loadTemplate-1.5.5.js
similarity index 100%
rename from jquery-loadTemplate/jquery.loadTemplate-1.5.4.js
rename to jquery-loadTemplate/jquery.loadTemplate-1.5.5.js
diff --git a/jquery-loadTemplate/jquery.loadTemplate-1.5.4.min.js b/jquery-loadTemplate/jquery.loadTemplate-1.5.5.min.js
similarity index 100%
rename from jquery-loadTemplate/jquery.loadTemplate-1.5.4.min.js
rename to jquery-loadTemplate/jquery.loadTemplate-1.5.5.min.js
diff --git a/loadTemplate.jquery.json b/loadTemplate.jquery.json
index 7183432..6f8ac34 100644
--- a/loadTemplate.jquery.json
+++ b/loadTemplate.jquery.json
@@ -6,7 +6,7 @@
"templates",
"templating"
],
- "version": "1.5.4",
+ "version": "1.5.5",
"author": {
"name": "Paul Burgess and other contributors",
"url": "https://github.com/codepb/jquery-template"
diff --git a/package.json b/package.json
index 7b1f717..ba1a933 100644
--- a/package.json
+++ b/package.json
@@ -1,6 +1,6 @@
{
"name": "jquery.loadtemplate",
- "version": "1.5.4",
+ "version": "1.5.5",
"author": "Paul Burgess",
"description": "jQuery plugin for loading and using templates. The plugin is designed to be simple yet powerful, and supports loading templates from within the page, or using AJAX to load html files.",
"homepage": "http://codepb.github.io/jquery-template/",
diff --git a/tests/index.html b/tests/index.html
index 2c10302..50e6ddf 100644
--- a/tests/index.html
+++ b/tests/index.html
@@ -3,7 +3,7 @@
loadTemplate Test Suite
-
+
From 54c882c2aefa361e6faa7cdfc6abcf8c68bd505b Mon Sep 17 00:00:00 2001
From: Paul Burgess
Date: Mon, 29 Feb 2016 11:31:33 +0000
Subject: [PATCH 60/71] moved to a new dist folder. New version
---
.gitignore | 1 -
Examples/index.html | 2 +-
bower.json | 2 +-
.../jquery.loadTemplate-1.5.6.js | 0
.../jquery.loadTemplate-1.5.6.min.js | 0
loadTemplate.jquery.json | 2 +-
package.json | 2 +-
tests/index.html | 2 +-
8 files changed, 5 insertions(+), 6 deletions(-)
rename jquery-loadTemplate/jquery.loadTemplate-1.5.5.js => dist/jquery.loadTemplate-1.5.6.js (100%)
rename jquery-loadTemplate/jquery.loadTemplate-1.5.5.min.js => dist/jquery.loadTemplate-1.5.6.min.js (100%)
diff --git a/.gitignore b/.gitignore
index b9d6bd9..38a363a 100644
--- a/.gitignore
+++ b/.gitignore
@@ -192,7 +192,6 @@ $RECYCLE.BIN/
# Packages
*.egg
*.egg-info
-dist/
build/
eggs/
parts/
diff --git a/Examples/index.html b/Examples/index.html
index f09337f..6d1388a 100644
--- a/Examples/index.html
+++ b/Examples/index.html
@@ -9,7 +9,7 @@
-
+
diff --git a/bower.json b/bower.json
index e9ad1c0..1c946fa 100644
--- a/bower.json
+++ b/bower.json
@@ -9,7 +9,7 @@
"type": "git",
"url": "https://github.com/codepb/jquery-template.git"
},
- "main": "jquery.loadTemplate-1.5.5.js",
+ "main": "dist/jquery.loadTemplate-1.5.6.js",
"keywords": [
"templates",
"templating",
diff --git a/jquery-loadTemplate/jquery.loadTemplate-1.5.5.js b/dist/jquery.loadTemplate-1.5.6.js
similarity index 100%
rename from jquery-loadTemplate/jquery.loadTemplate-1.5.5.js
rename to dist/jquery.loadTemplate-1.5.6.js
diff --git a/jquery-loadTemplate/jquery.loadTemplate-1.5.5.min.js b/dist/jquery.loadTemplate-1.5.6.min.js
similarity index 100%
rename from jquery-loadTemplate/jquery.loadTemplate-1.5.5.min.js
rename to dist/jquery.loadTemplate-1.5.6.min.js
diff --git a/loadTemplate.jquery.json b/loadTemplate.jquery.json
index 6f8ac34..d8a6eea 100644
--- a/loadTemplate.jquery.json
+++ b/loadTemplate.jquery.json
@@ -6,7 +6,7 @@
"templates",
"templating"
],
- "version": "1.5.5",
+ "version": "1.5.6",
"author": {
"name": "Paul Burgess and other contributors",
"url": "https://github.com/codepb/jquery-template"
diff --git a/package.json b/package.json
index ba1a933..a9339ae 100644
--- a/package.json
+++ b/package.json
@@ -1,6 +1,6 @@
{
"name": "jquery.loadtemplate",
- "version": "1.5.5",
+ "version": "1.5.6",
"author": "Paul Burgess",
"description": "jQuery plugin for loading and using templates. The plugin is designed to be simple yet powerful, and supports loading templates from within the page, or using AJAX to load html files.",
"homepage": "http://codepb.github.io/jquery-template/",
diff --git a/tests/index.html b/tests/index.html
index 50e6ddf..2b0a61d 100644
--- a/tests/index.html
+++ b/tests/index.html
@@ -3,7 +3,7 @@
loadTemplate Test Suite
-
+
From 6733ea1c0e05f421fe5e9c43bd2bb1df3e6fde27 Mon Sep 17 00:00:00 2001
From: codepb
Date: Tue, 8 Mar 2016 21:27:51 +0000
Subject: [PATCH 61/71] fixing reference to data-format-template
fixes #90
---
readme.md | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/readme.md b/readme.md
index b8cb88b..7a6d4bd 100644
--- a/readme.md
+++ b/readme.md
@@ -64,7 +64,7 @@ You can pass an array of objects instead of a single object and the template wil
### Data Formatters
-It is also possible to define data formatters. These are assigned through the `$.addTemplateFormatter` method. This function either accepts a map of functions and the keys that they will be referenced by, or a single function with a single key as two separate parameters. Each formatter takes two values, the value being assigned, and a template to use to define how this data is displayed. The data-format-template may be empty. Example usage of this is below:
+It is also possible to define data formatters. These are assigned through the `$.addTemplateFormatter` method. This function either accepts a map of functions and the keys that they will be referenced by, or a single function with a single key as two separate parameters. Each formatter takes two values, the value being assigned, and a template to use to define how this data is displayed. The data-format-options may be empty. Example usage of this is below:
$.addTemplateFormatter("UpperCaseFormatter",
function(value, template) {
From c57638100d464d9ecd33c4a53b2c80121daafc6a Mon Sep 17 00:00:00 2001
From: Michal Brauner
Date: Fri, 25 Mar 2016 19:42:35 +0100
Subject: [PATCH 62/71] fix package.json - missing "main" option
---
package.json | 1 +
1 file changed, 1 insertion(+)
diff --git a/package.json b/package.json
index a9339ae..ad8504e 100644
--- a/package.json
+++ b/package.json
@@ -1,6 +1,7 @@
{
"name": "jquery.loadtemplate",
"version": "1.5.6",
+ "main": "dist/jquery.loadTemplate-1.5.6.js",
"author": "Paul Burgess",
"description": "jQuery plugin for loading and using templates. The plugin is designed to be simple yet powerful, and supports loading templates from within the page, or using AJAX to load html files.",
"homepage": "http://codepb.github.io/jquery-template/",
From 62bb1f012f974b8961a73fe77784155b90806815 Mon Sep 17 00:00:00 2001
From: Paul Burgess
Date: Fri, 1 Apr 2016 16:24:21 +0100
Subject: [PATCH 63/71] Fixed issue with binding the value of selects
now uses .val to bind value. Fixed templates so the javascript
properties are also copied with the template into the dom
---
Examples/SimpleExample/Templates/simple.html | 2 +-
Examples/SimpleExample/example.html | 4 +++-
Examples/index.html | 4 ++--
bower.json | 2 +-
dist/jquery.loadTemplate-1.5.6.min.js | 1 -
...-1.5.6.js => jquery.loadTemplate-1.5.7.js} | 21 ++++++++++++-------
dist/jquery.loadTemplate-1.5.7.min.js | 1 +
loadTemplate.jquery.json | 2 +-
package.json | 4 ++--
tests/index.html | 2 +-
10 files changed, 26 insertions(+), 17 deletions(-)
delete mode 100644 dist/jquery.loadTemplate-1.5.6.min.js
rename dist/{jquery.loadTemplate-1.5.6.js => jquery.loadTemplate-1.5.7.js} (97%)
create mode 100644 dist/jquery.loadTemplate-1.5.7.min.js
diff --git a/Examples/SimpleExample/Templates/simple.html b/Examples/SimpleExample/Templates/simple.html
index c844792..2e75af5 100644
--- a/Examples/SimpleExample/Templates/simple.html
+++ b/Examples/SimpleExample/Templates/simple.html
@@ -3,7 +3,7 @@
-
+
Example of loading a template from a script tag within the same document.
-
+