Skip to content

Commit

Permalink
fix: updated actions callback data object
Browse files Browse the repository at this point in the history
  • Loading branch information
frankpagan committed Jun 22, 2023
1 parent 9f4a4e7 commit 171a544
Showing 1 changed file with 76 additions and 76 deletions.
152 changes: 76 additions & 76 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,13 @@ function CoCreateModal(id) {
} else {
this.pageId = localStorage.getItem('pageId')
let viewPort = window.top.CoCreate.modal.viewPorts
if (viewPort)
if (viewPort)
viewPort.set(this.pageId, this)

// TODO: can be depreciated if we find a better way to pass rootid and parentid
this.parentId = localStorage.getItem('parentId')
this.rootId = window.top.CoCreate.modal.rootId
}
}

this._createViewPort();

Expand All @@ -38,48 +38,48 @@ function CoCreateModal(id) {
action.init({
name: "openModal",
endEvent: "openModal",
callback: (btn, data) => {
this.open(btn);
callback: (data) => {
this.open(data.element);
},
});

action.init({
name: "closeModal",
endEvent: "closeModal",
callback: (btn, data) => {
this.modalAction(btn, 'close');
callback: (data) => {
this.modalAction(data.element, 'close');
},
});

action.init({
name: "minMaxModal",
endEvent: "minMaxModal",
callback: (btn, data) => {
this.modalAction(btn, 'minMax');
callback: (data) => {
this.modalAction(data.element, 'minMax');
},
});

action.init({
name: "parkModal",
endEvent: "parkModal",
callback: (btn, data) => {
this.modalAction(btn, 'park');
callback: (data) => {
this.modalAction(data.element, 'park');
},
});

}

CoCreateModal.prototype = {
_checkRoot: function() {
_checkRoot: function () {
try {
return window === window.top;
} catch (e) {
return false;
}
},

_createViewPort: function() {
if (this.viewPort)
_createViewPort: function () {
if (this.viewPort)
return true;

let el = document.getElementById(this.id);
Expand All @@ -91,27 +91,27 @@ CoCreateModal.prototype = {
}
},

_initSocket: function() {
const self = this;
message.listen('modalAction', function(response) {
_initSocket: function () {
const self = this;
message.listen('modalAction', function (response) {
self.runModalAction(response.data)
})
},

open: function(aTag) {
open: function (aTag) {
let attributes = [];
for (let attribute of aTag.attributes)
attributes[attribute.name] = attribute.value

let data = {
src: aTag.getAttribute('modal-src'),
x: aTag.getAttribute('modal-x'),
y: aTag.getAttribute('modal-y'),
width: aTag.getAttribute('modal-width'),
src: aTag.getAttribute('modal-src'),
x: aTag.getAttribute('modal-x'),
y: aTag.getAttribute('modal-y'),
width: aTag.getAttribute('modal-width'),
height: aTag.getAttribute('modal-height'),
color: aTag.getAttribute('modal-color'),
header: aTag.getAttribute('modal-header'),
iframe: aTag.getAttribute('modal-iframe'),
color: aTag.getAttribute('modal-color'),
header: aTag.getAttribute('modal-header'),
iframe: aTag.getAttribute('modal-iframe'),
attributes: attributes
}

Expand All @@ -124,38 +124,38 @@ CoCreateModal.prototype = {
}

let openIn = aTag.getAttribute('modal-open') || 'root';

let openId;
switch (openIn) {
case 'parent':
openId = this.parentId;
break;
case 'page':
openId = this.pageId;
break;
case 'root':
openId = this.rootId;
break;
default:
openId = openIn;
break;
case 'parent':
openId = this.parentId;
break;
case 'page':
openId = this.pageId;
break;
case 'root':
openId = this.rootId;
break;
default:
openId = openIn;
break;
}

localStorage.setItem('parentId', openId)

data.type = 'open';
data.parentId = openId;

if (this.isRoot) {
if (this._createViewPort())
this.viewPort._createModal(data);
this.viewPort._createModal(data);
} else {
let viewPort = window.top.CoCreate.modal.viewPorts.get(openId);
if (viewPort.pageId == data.parentId) {
viewPort.viewPort._createModal(data);

document.dispatchEvent(new CustomEvent('openModal', {
detail: {}
detail: {}
}))

} else {
Expand All @@ -164,7 +164,7 @@ CoCreateModal.prototype = {
}
},

modalAction: function(btn, type, data) {
modalAction: function (btn, type, data) {
let json = {
key: CoCreateConfig.key,
organization_id: CoCreateConfig.organization_id,
Expand All @@ -178,57 +178,57 @@ CoCreateModal.prototype = {
} else {
let modalEl = btn.closest('.modal')

let modal
if (modalEl)
modal = this.viewPort.modals.get(modalEl.id || this.pageId)
if (!modal) {
modal = window.top.CoCreate.modal.modals.get(this.pageId);
}
json.data = {
parentId: this.parentId,
pageId: this.pageId,
modal,
type
}
let modal
if (modalEl)
modal = this.viewPort.modals.get(modalEl.id || this.pageId)
if (!modal) {
modal = window.top.CoCreate.modal.modals.get(this.pageId);
}
json.data = {
parentId: this.parentId,
pageId: this.pageId,
modal,
type
}

if (modal)
this.runModalAction(json.data)
else
message.send(json);
if (modal)
this.runModalAction(json.data)
else
message.send(json);
}
},

runModalAction: function(data) {
runModalAction: function (data) {
if (data.modal || data.parentId == this.pageId) {

let pageId = data.pageId;
let type = data.type;
let modal = data.modal

if (!modal)
modal = this.viewPort.modals.get(pageId);

if (modal) {
switch (type) {
case 'open':
if (data.parentId == this.pageId)
this.viewPort._createModal(data)
break;
case 'close':
modal.viewPort._removeModal(modal)
break;
case 'minMax':
modal.el.position.minMax();
break;
case 'park':
modal.togglePark();
break;
}
case 'open':
if (data.parentId == this.pageId)
this.viewPort._createModal(data)
break;
case 'close':
modal.viewPort._removeModal(modal)
break;
case 'minMax':
modal.el.position.minMax();
break;
case 'park':
modal.togglePark();
break;
}

document.dispatchEvent(new CustomEvent(`${type}Modal`, {
detail: {}
}))

}
}

Expand Down

0 comments on commit 171a544

Please sign in to comment.