Skip to content

Commit

Permalink
Merge branch 'master' of github.com:ThemeFuse/Unyson-PageBuilder-Exte…
Browse files Browse the repository at this point in the history
…nsion
  • Loading branch information
GheorgheP committed May 26, 2017
2 parents 064408e + a2e43e7 commit 1b3ef88
Showing 1 changed file with 34 additions and 9 deletions.
43 changes: 34 additions & 9 deletions includes/page-builder/static/js/modal-save-all.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,34 @@
modalChain: [],
resetChain: function (modal) {
_.each(this.modalChain, this.removeButton, this);

this.modalChain = [modal];

fwEvents.off(null, null, this);
this.detachEvents();

fwEvents.on(
'fw:options-modal:open',
function(data){ inst.pushChain(data.modal); },
this
this.modalOpenListener
);

fwEvents.on(
'fw:options-modal:close',
function(data){ inst.popChain(); },
this
this.modalCloseListener
);
},

detachEvents: function () {
fwEvents.off(
'fw:options-modal:open',
this.modalOpenListener
);

fwEvents.off(
'fw:options-modal:close',
this.modalCloseListener
);
},

pushChain: function (modal) {
if (!this.modalChain.length) {
return;
Expand All @@ -32,8 +46,8 @@

if (!modal) {
return console.warn('Logic error');
} else if (!this.modalChain.length) {
fwEvents.off(null, null, this);
} else if (! this.modalChain.length) {
this.detachEvents();
}

this.removeButton(modal);
Expand All @@ -53,14 +67,17 @@
return modal.frame.views.get(modal.frame.toolbar.selector)[0].$el.find('.media-toolbar-primary:first');
},
addButton: function (modal) {
this.removeButton(modal);

var $toolbar = this.$getToolbar(modal);

$toolbar.append(
$('<button type="button" class="button media-button button-large"></button>')
.addClass(this.btnClass)
.text($toolbar.find('.button-primary:first').text() + l10n.btn_text_suffix)
.on('click', _.bind(function (e) {
e.preventDefault();
fwEvents.off(null, null, this);
this.detachEvents();
this.saveChain();
}, this))
);
Expand All @@ -70,6 +87,14 @@
}
};

inst.modalOpenListener = _.bind(function (data) {
inst.pushChain(data.modal);
}, inst);

inst.modalCloseListener = _.bind(function (data) {
inst.popChain();
}, inst);

fwEvents.on(
['simple', 'column', 'section']
.map(function(item){
Expand All @@ -78,4 +103,4 @@
.join(' '),
function (data) { inst.resetChain(data.modal); }
);
})(jQuery, _fw_page_builder_modal_save_all);
})(jQuery, _fw_page_builder_modal_save_all);

0 comments on commit 1b3ef88

Please sign in to comment.