You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by dk...@apache.org on 2019/04/15 12:21:14 UTC
[sling-org-apache-sling-app-cms] branch master updated: Updated to
use a modal in the calling frame rather than the current frame when
browsing a pathfield within a component editor
This is an automated email from the ASF dual-hosted git repository.
dklco pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-app-cms.git
The following commit(s) were added to refs/heads/master by this push:
new d410278 Updated to use a modal in the calling frame rather than the current frame when browsing a pathfield within a component editor
d410278 is described below
commit d410278d53f545c8a03cf97ca240c8a69cbf700e
Author: Dan Klco <dk...@apache.org>
AuthorDate: Mon Apr 15 08:21:07 2019 -0400
Updated to use a modal in the calling frame rather than the current frame when browsing a pathfield within a component editor
---
ui/src/main/frontend/src/js/cms.modal.js | 76 ++++++++++++++++++++--------
ui/src/main/frontend/src/js/cms.pathfield.js | 21 ++++++--
ui/src/main/frontend/src/js/editor.js | 2 +-
3 files changed, 75 insertions(+), 24 deletions(-)
diff --git a/ui/src/main/frontend/src/js/cms.modal.js b/ui/src/main/frontend/src/js/cms.modal.js
index 6925959..171519c 100644
--- a/ui/src/main/frontend/src/js/cms.modal.js
+++ b/ui/src/main/frontend/src/js/cms.modal.js
@@ -30,28 +30,37 @@
},
methods: {
getModal: function (title, link, button) {
- var modal = Sling.CMS.ui.loaderModal(),
- request = new XMLHttpRequest();
- request.open('GET', link, true);
- request.onload = function () {
- if (this.status === 500 || this.status === 404) {
- Sling.CMS.ui.confirmMessage(request.statusText, request.statusText, function(){
- Sling.CMS.ui.reloadContext();
- });
- } else {
- button.removeAttribute("disabled");
- if (request.responseURL.indexOf('/system/sling/form/login?resource=') !== -1) {
- window.location.reload();
+ if(window.parent && window.parent.parent) {
+ window.parent.parent.postMessage({
+ "action": "slingcms.openmodal",
+ "url": link,
+ "title": title
+ }, window.location.origin);
+ button.removeAttribute('disabled');
+ } else {
+ var modal = Sling.CMS.ui.loaderModal(),
+ request = new XMLHttpRequest();
+ request.open('GET', link, true);
+ request.onload = function () {
+ if (this.status === 500 || this.status === 404) {
+ Sling.CMS.ui.confirmMessage(request.statusText, request.statusText, function(){
+ Sling.CMS.ui.reloadContext();
+ });
} else {
- modal.innerHTML = request.responseText;
+ button.removeAttribute("disabled");
+ if (request.responseURL.indexOf('/system/sling/form/login?resource=') !== -1) {
+ window.location.reload();
+ } else {
+ modal.innerHTML = request.responseText;
+ }
}
- }
- };
- modal.querySelector('.modal-background').addEventListener('click', function () {
- request.abort();
- button.removeAttribute('disabled');
- });
- request.send();
+ };
+ modal.querySelector('.modal-background').addEventListener('click', function () {
+ request.abort();
+ button.removeAttribute('disabled');
+ });
+ request.send();
+ }
}
}
});
@@ -65,5 +74,32 @@
}
}
});
+
+ window.addEventListener("message", function(event){
+ if(event.data.action === 'slingcms.openmodal'){
+ Sling.CMS.pathfield = event.source;
+ var modal = Sling.CMS.ui.loaderModal(),
+ request = new XMLHttpRequest();
+ request.open('GET', event.data.url, true);
+ request.onload = function () {
+ if (this.status === 500 || this.status === 404) {
+ Sling.CMS.ui.confirmMessage(request.statusText, request.statusText, function(){
+ Sling.CMS.ui.reloadContext();
+ });
+ } else {
+ if (request.responseURL.indexOf('/system/sling/form/login?resource=') !== -1) {
+ window.location.reload();
+ } else {
+ modal.innerHTML = request.responseText;
+ }
+ }
+ };
+ modal.querySelector('.modal-background').addEventListener('click', function () {
+ request.abort();
+ });
+ request.send();
+ }
+
+ }, false);
}(window.rava = window.rava || {}, window.Sling = window.Sling || {}));
\ No newline at end of file
diff --git a/ui/src/main/frontend/src/js/cms.pathfield.js b/ui/src/main/frontend/src/js/cms.pathfield.js
index 81091eb..a0617da 100644
--- a/ui/src/main/frontend/src/js/cms.pathfield.js
+++ b/ui/src/main/frontend/src/js/cms.pathfield.js
@@ -19,7 +19,7 @@
/* eslint-env browser, es6 */
(function (rava, Sling) {
'use strict';
- var pathfield = null;
+ Sling.CMS.pathfield = null;
rava.bind("input.pathfield", {
callbacks: {
created : function () {
@@ -32,17 +32,32 @@
rava.bind('.search-button', {
events: {
click: function () {
- pathfield = this.closest('.field').querySelector('.pathfield');
+ Sling.CMS.pathfield = this.closest('.field').querySelector('.pathfield');
}
}
});
rava.bind('.search-select-button', {
events: {
click : function () {
- pathfield.value = this.dataset.path;
+ var path = this.dataset.path;
+ if(Sling.CMS.pathfield instanceof HTMLInputElement){
+ Sling.CMS.pathfield.value = this.dataset.path;
+ } else {
+ Sling.CMS.pathfield.postMessage({
+ "action": "slingcms.setpath",
+ "path": path
+ }, window.location.origin);
+ }
this.closest('.modal').remove();
}
}
});
+
+ window.addEventListener("message", function(event){
+ if(event.data.action === 'slingcms.setpath'){
+ Sling.CMS.pathfield.value = event.data.path;
+ }
+ }, false);
+
}(window.rava = window.rava || {}, window.Sling = window.Sling || {}));
\ No newline at end of file
diff --git a/ui/src/main/frontend/src/js/editor.js b/ui/src/main/frontend/src/js/editor.js
index f454c8b..2148a6f 100644
--- a/ui/src/main/frontend/src/js/editor.js
+++ b/ui/src/main/frontend/src/js/editor.js
@@ -40,7 +40,7 @@
CMSEditor.draggable = element;
var mouseDown = false, elementX = 0, elementY = 0;
- // mouse button down over the element
+ // mouse button down over the element
CMSEditor.draggable.addEventListener('mousedown', function (evt) {
if (!evt.target.matches('.modal-title, .modal-title *')) {
return;