From 8ae3975377b4ae89f6542021b8701c0b798378dd Mon Sep 17 00:00:00 2001 From: hecforga Date: Tue, 7 Jun 2016 15:17:23 +0200 Subject: [PATCH 1/2] Add buttons for trying the example in the editor --- js/app.js | 11 +++++++++++ partials/examples.html | 5 +++++ partials/landing.html | 11 ++++++++--- 3 files changed, 24 insertions(+), 3 deletions(-) diff --git a/js/app.js b/js/app.js index 626d75bae2..a0faaa3310 100644 --- a/js/app.js +++ b/js/app.js @@ -352,6 +352,17 @@ angular.module('jsonforms-website', [ return false; }; + vm.openEditorInNewTab = function () { + vm.reparseStatic(); + var tab = window.open('http://jsonformseditor.herokuapp.com/#/demo'); + setTimeout(function() { + tab.postMessage({ + dataSchema: vm.localStaticModelObject, + uiSchema: vm.localStaticViewObject + }, '*'); + }, 14000); // heroku needs 12 secs. aprox. to build the editor + }; + vm.staticDataProvider = StaticData; vm.dynamicDataProvider = DynamicData; diff --git a/partials/examples.html b/partials/examples.html index b13740c1fc..9bbdbc75d2 100644 --- a/partials/examples.html +++ b/partials/examples.html @@ -22,5 +22,10 @@

EXAMPLES

+
+ Try in the Editor +
\ No newline at end of file diff --git a/partials/landing.html b/partials/landing.html index 60c6c8a6c2..8bd009f4f5 100644 --- a/partials/landing.html +++ b/partials/landing.html @@ -76,9 +76,14 @@

U
- More examples +
+ More examples + Try in the Editor +
\ No newline at end of file From c5713fd1c49d4b2e047a73c622a532202dbb5cad Mon Sep 17 00:00:00 2001 From: hecforga Date: Fri, 10 Jun 2016 14:09:17 +0200 Subject: [PATCH 2/2] Send message to editor tab every second until ack received --- js/app.js | 30 ++++++++++++++++++++++++------ 1 file changed, 24 insertions(+), 6 deletions(-) diff --git a/js/app.js b/js/app.js index a0faaa3310..048fca4df7 100644 --- a/js/app.js +++ b/js/app.js @@ -354,13 +354,31 @@ angular.module('jsonforms-website', [ vm.openEditorInNewTab = function () { vm.reparseStatic(); + var tab = window.open('http://jsonformseditor.herokuapp.com/#/demo'); - setTimeout(function() { - tab.postMessage({ - dataSchema: vm.localStaticModelObject, - uiSchema: vm.localStaticViewObject - }, '*'); - }, 14000); // heroku needs 12 secs. aprox. to build the editor + var data = { + dataSchema: vm.localStaticModelObject, + uiSchema: vm.localStaticViewObject + }; + var passedByReference = { ackReceived: false }; + + window.addEventListener('message', function(event) { + if (event.data == 'ACK') { + window.removeEventListener('message', function() {}, false); + passedByReference.ackReceived = true; + } + }, false); + + vm.postMessagetoTab(tab, data, passedByReference); + }; + + vm.postMessagetoTab = function(tab, data, passedByReference) { + setTimeout(function () { + tab.postMessage(data, '*'); + if (!passedByReference.ackReceived) { + vm.postMessagetoTab(tab, data, passedByReference); + } + }, 1000); }; vm.staticDataProvider = StaticData;