mirror of https://github.com/artf/grapesjs.git
1 changed files with 15 additions and 17 deletions
@ -1,40 +1,38 @@ |
|||||
const $ = Backbone.$; |
|
||||
|
|
||||
module.exports = { |
module.exports = { |
||||
run(editor, sender, opts = {}) { |
run(editor, sender, opts = {}) { |
||||
const modal = editor.Modal; |
const modal = editor.Modal; |
||||
const am = editor.AssetManager; |
const am = editor.AssetManager; |
||||
const config = am.getConfig(); |
const config = am.getConfig(); |
||||
|
const amContainer = am.getContainer(); |
||||
const title = opts.modalTitle || config.modalTitle || ''; |
const title = opts.modalTitle || config.modalTitle || ''; |
||||
var types = opts.types; |
const types = opts.types; |
||||
var accept = opts.accept; |
const accept = opts.accept; |
||||
|
|
||||
am.setTarget(opts.target); |
am.setTarget(opts.target); |
||||
am.onClick(opts.onClick); |
am.onClick(opts.onClick); |
||||
am.onDblClick(opts.onDblClick); |
am.onDblClick(opts.onDblClick); |
||||
am.onSelect(opts.onSelect); |
am.onSelect(opts.onSelect); |
||||
|
|
||||
if (!this.rendered || types || accept) { |
if (!this.rendered || types) { |
||||
var $html; |
let assets = am.getAll(); |
||||
var assets; |
|
||||
|
|
||||
if (types) { |
if (types) { |
||||
assets = am.getAll().filter(asset => { |
assets = assets.filter(a => types.indexOf(a.get('type')) !== -1); |
||||
return types.indexOf(asset.get('type')) != -1 |
|
||||
}); |
|
||||
} else { |
|
||||
assets = am.getAll(); |
|
||||
} |
} |
||||
|
|
||||
$html = $(am.render(assets)); |
am.render(assets); |
||||
|
|
||||
if (accept) $html.find(`input#${config.stylePrefix}uploadFile`).attr('accept', accept); |
|
||||
|
|
||||
this.rendered = 1; |
this.rendered = 1; |
||||
} |
} |
||||
|
|
||||
|
if (accept) { |
||||
|
const uploadEl = amContainer.querySelector( |
||||
|
`input#${config.stylePrefix}uploadFile` |
||||
|
); |
||||
|
uploadEl && uploadEl.setAttribute('accept', accept); |
||||
|
} |
||||
|
|
||||
modal.setTitle(title); |
modal.setTitle(title); |
||||
modal.setContent(am.getContainer()); |
modal.setContent(amContainer); |
||||
modal.open(); |
modal.open(); |
||||
} |
} |
||||
}; |
}; |
||||
|
|||||
Loading…
Reference in new issue