mirror of https://github.com/artf/grapesjs.git
2 changed files with 41 additions and 4 deletions
@ -1,9 +1,36 @@ |
|||
const Property = require('./Property'); |
|||
|
|||
module.exports = Property.extend({ |
|||
defaults: { |
|||
defaults: () => ({ |
|||
...Property.prototype.defaults, |
|||
// Array of options, eg. [{name: 'Label ', value: '100'}]
|
|||
options: [] |
|||
}), |
|||
|
|||
initialize(...args) { |
|||
Property.prototype.initialize.apply(this, args); |
|||
this.listenTo(this, 'change:options', this.onOptionChange); |
|||
}, |
|||
|
|||
onOptionChange() { |
|||
this.set('list', this.get('options')); |
|||
}, |
|||
|
|||
getOptions() { |
|||
const { options, list } = this.attributes; |
|||
return options && options.length ? options : list; |
|||
}, |
|||
|
|||
setOptions(opts = []) { |
|||
this.set('options', opts); |
|||
return this; |
|||
}, |
|||
|
|||
addOption(opt) { |
|||
if (opt) { |
|||
const opts = this.getOptions(); |
|||
this.setOptions([...opts, opt]); |
|||
} |
|||
return this; |
|||
} |
|||
}); |
|||
|
|||
Loading…
Reference in new issue