Skip to content

Commit

Permalink
fixes for non-image attachments, closes #45 (#46)
Browse files Browse the repository at this point in the history
followup fix for non-image uploads
  • Loading branch information
jywarren authored and bevacqua committed Sep 8, 2017
1 parent c1ac5f6 commit b58efb7
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 3 deletions.
13 changes: 13 additions & 0 deletions readme.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,19 @@ For more information on file uploads, see [`bureaucracy`](https://github.com/bev

Virtually the same as `images`, except an anchor `<a>` tag will be used instead of an image `<img>` tag.

To set the formatting of the inserted attachment link, set `options.mergeHtmlAndAttachment`; the default follows this format:

```js
function mergeHtmlAndAttachment (chunks, link) {
var linkText = chunks.selection || link.title;
return {
before: chunks.before,
selection: '<a href="' + link.href + '">' + linkText + '</a>',
after: chunks.after,
};
}
```

# `editor`

The `editor` API allows you to interact with `woofmark` editor instances. This is what you get back from `woofmark(textarea, options)` or `woofmark.find(textarea)`.
Expand Down
10 changes: 9 additions & 1 deletion src/bindCommands.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,14 +71,22 @@ function bindCommands (surface, options, editor) {
prompts: options.prompts,
upload: options[type + 's'],
classes: options.classes,
mergeHtmlAndAttachment: options.mergeHtmlAndAttachment,
mergeHtmlAndAttachment: options.mergeHtmlAndAttachment || mergeHtmlAndAttachment,
autoUpload: autoUpload
});
};
}
function bind (id, combo, fn) {
return editor.addCommandButton(id, combo, suppress(fn));
}
function mergeHtmlAndAttachment (chunks, link) {
var linkText = chunks.selection || link.title;
return {
before: chunks.before,
selection: '<a href="' + link.href + '">' + linkText + '</a>',
after: chunks.after,
};
}
function router (method) {
return function routed (mode, chunks) { commands[mode][method].call(this, chunks); };
}
Expand Down
2 changes: 1 addition & 1 deletion src/html/linkOrImageOrAttachment.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ function linkOrImageOrAttachment (chunks, options) {
var link = links[0];

if (type === 'attachment') {
parts = options.mergeHtmlAndAttachment(chunks.before + chunks.selection + chunks.after, link);
parts = options.mergeHtmlAndAttachment(chunks, link);
chunks.before = parts.before;
chunks.selection = parts.selection;
chunks.after = parts.after;
Expand Down
2 changes: 1 addition & 1 deletion src/prompts/prompt.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ function prompt (options, done) {
fieldKey: upload.fieldKey,
xhrOptions: upload.xhrOptions,
endpoint: upload.url,
validate: 'image'
validate: upload.validate || 'image'
});

bureaucrat.on('started', function () {
Expand Down

0 comments on commit b58efb7

Please sign in to comment.