Browse Source

Add `attributes` option to the Modal.open method. Closes #2592

pull/3073/head
Artur Arseniev 6 years ago
parent
commit
c430eef822
  1. 3
      src/modal_dialog/index.js
  2. 17
      src/modal_dialog/view/ModalView.js

3
src/modal_dialog/index.js

@ -87,12 +87,13 @@ export default () => {
* @param {Object} [opts={}] Options
* @param {String|HTMLElement} [opts.title] Title to set for the modal
* @param {String|HTMLElement} [opts.content] Content to set for the modal
* @param {Object} [opts.attributes] Updates the modal wrapper with custom attributes
* @return {this}
*/
open(opts = {}) {
opts.title && this.setTitle(opts.title);
opts.content && this.setContent(opts.content);
modal.show();
modal.show(opts);
return this;
},

17
src/modal_dialog/view/ModalView.js

@ -115,19 +115,28 @@ export default Backbone.View.extend({
* Show modal
* @private
* */
show() {
show(opts = {}) {
this.model.set('open', 1);
this.updateAttr(opts.attributes);
},
updateAttr(attr) {
const { pfx, $el, el } = this;
const currAttr = [].slice.call(el.attributes).map(i => i.name);
$el.removeAttr(currAttr.join(' '));
$el.attr({
...(attr || {}),
class: `${pfx}container ${(attr && attr.class) || ''}`.trim()
});
},
render() {
const el = this.$el;
const pfx = this.pfx;
const ppfx = this.ppfx;
const obj = this.model.toJSON();
obj.pfx = this.pfx;
obj.ppfx = this.ppfx;
el.html(this.template(obj));
el.attr('class', `${pfx}container`);
this.updateAttr();
this.updateOpen();
return this;
}

Loading…
Cancel
Save