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 = { |
|||
run(editor, sender, opts = {}) { |
|||
const modal = editor.Modal; |
|||
const am = editor.AssetManager; |
|||
const config = am.getConfig(); |
|||
const amContainer = am.getContainer(); |
|||
const title = opts.modalTitle || config.modalTitle || ''; |
|||
var types = opts.types; |
|||
var accept = opts.accept; |
|||
const types = opts.types; |
|||
const accept = opts.accept; |
|||
|
|||
am.setTarget(opts.target); |
|||
am.onClick(opts.onClick); |
|||
am.onDblClick(opts.onDblClick); |
|||
am.onSelect(opts.onSelect); |
|||
|
|||
if (!this.rendered || types || accept) { |
|||
var $html; |
|||
var assets; |
|||
if (!this.rendered || types) { |
|||
let assets = am.getAll(); |
|||
|
|||
if (types) { |
|||
assets = am.getAll().filter(asset => { |
|||
return types.indexOf(asset.get('type')) != -1 |
|||
}); |
|||
} else { |
|||
assets = am.getAll(); |
|||
assets = assets.filter(a => types.indexOf(a.get('type')) !== -1); |
|||
} |
|||
|
|||
$html = $(am.render(assets)); |
|||
|
|||
if (accept) $html.find(`input#${config.stylePrefix}uploadFile`).attr('accept', accept); |
|||
|
|||
am.render(assets); |
|||
this.rendered = 1; |
|||
} |
|||
|
|||
if (accept) { |
|||
const uploadEl = amContainer.querySelector( |
|||
`input#${config.stylePrefix}uploadFile` |
|||
); |
|||
uploadEl && uploadEl.setAttribute('accept', accept); |
|||
} |
|||
|
|||
modal.setTitle(title); |
|||
modal.setContent(am.getContainer()); |
|||
modal.setContent(amContainer); |
|||
modal.open(); |
|||
} |
|||
}; |
|||
|
|||
Loading…
Reference in new issue