From 8b866e09e4d994af7d212f16f27b071083a4068c Mon Sep 17 00:00:00 2001 From: Ivan Perevernyhata Date: Wed, 18 May 2016 14:02:48 +0300 Subject: [PATCH 1/2] - implemented templating support for rel property on href schema # Conflicts: # dist/jsoneditor.js.map --- dist/jsoneditor.js | 12 ++++++++---- src/editor.js | 12 ++++++++---- 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/dist/jsoneditor.js b/dist/jsoneditor.js index 1d0cf7556..ecbd1abd9 100644 --- a/dist/jsoneditor.js +++ b/dist/jsoneditor.js @@ -1553,7 +1553,8 @@ JSONEditor.AbstractEditor = Class.extend({ // Template to generate the link href var href = this.jsoneditor.compileTemplate(data.href,this.template_engine); - + var relTemplate = this.jsoneditor.compileTemplate(data.rel,this.template_engine); + // Template to generate the link's download attribute var download = null; if(data.download) download = data.download; @@ -1574,8 +1575,9 @@ JSONEditor.AbstractEditor = Class.extend({ // When a watched field changes, update the url this.link_watchers.push(function(vars) { var url = href(vars); + var rel = relTemplate(vars); link.setAttribute('href',url); - link.setAttribute('title',data.rel || url); + link.setAttribute('title',rel || url); image.setAttribute('src',url); }); } @@ -1594,8 +1596,9 @@ JSONEditor.AbstractEditor = Class.extend({ // When a watched field changes, update the url this.link_watchers.push(function(vars) { var url = href(vars); + var rel = relTemplate(vars); link.setAttribute('href',url); - link.textContent = data.rel || url; + link.textContent = rel || url; media.setAttribute('src',url); }); } @@ -1608,8 +1611,9 @@ JSONEditor.AbstractEditor = Class.extend({ // When a watched field changes, update the url this.link_watchers.push(function(vars) { var url = href(vars); + var rel = relTemplate(vars); holder.setAttribute('href',url); - holder.textContent = data.rel || url; + holder.textContent = rel || url; }); } diff --git a/src/editor.js b/src/editor.js index 3ca319d2e..2d72ae8b6 100644 --- a/src/editor.js +++ b/src/editor.js @@ -177,7 +177,8 @@ JSONEditor.AbstractEditor = Class.extend({ // Template to generate the link href var href = this.jsoneditor.compileTemplate(data.href,this.template_engine); - + var relTemplate = this.jsoneditor.compileTemplate(data.rel,this.template_engine); + // Template to generate the link's download attribute var download = null; if(data.download) download = data.download; @@ -198,8 +199,9 @@ JSONEditor.AbstractEditor = Class.extend({ // When a watched field changes, update the url this.link_watchers.push(function(vars) { var url = href(vars); + var rel = relTemplate(vars); link.setAttribute('href',url); - link.setAttribute('title',data.rel || url); + link.setAttribute('title',rel || url); image.setAttribute('src',url); }); } @@ -218,8 +220,9 @@ JSONEditor.AbstractEditor = Class.extend({ // When a watched field changes, update the url this.link_watchers.push(function(vars) { var url = href(vars); + var rel = relTemplate(vars); link.setAttribute('href',url); - link.textContent = data.rel || url; + link.textContent = rel || url; media.setAttribute('src',url); }); } @@ -232,8 +235,9 @@ JSONEditor.AbstractEditor = Class.extend({ // When a watched field changes, update the url this.link_watchers.push(function(vars) { var url = href(vars); + var rel = relTemplate(vars); holder.setAttribute('href',url); - holder.textContent = data.rel || url; + holder.textContent = rel || url; }); } From a556da1921b8076067661d9d1b338e391ebe194c Mon Sep 17 00:00:00 2001 From: Ivan Perevernyhata Date: Wed, 18 May 2016 15:16:24 +0300 Subject: [PATCH 2/2] - fixed exception when 'rel' is not defined --- src/editor.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/editor.js b/src/editor.js index 2d72ae8b6..b3f87b113 100644 --- a/src/editor.js +++ b/src/editor.js @@ -177,7 +177,7 @@ JSONEditor.AbstractEditor = Class.extend({ // Template to generate the link href var href = this.jsoneditor.compileTemplate(data.href,this.template_engine); - var relTemplate = this.jsoneditor.compileTemplate(data.rel,this.template_engine); + var relTemplate = this.jsoneditor.compileTemplate(data.rel ? data.rel : data.href,this.template_engine); // Template to generate the link's download attribute var download = null;