I'm looking for some advice to put this perfect module to good use on a project.
See attached image. The picture shows a block view, with images from nodes on the site. I want to be able to click "Insert" button and the active wysiwyg/textarea gets an appropriate image.
I had a look at the Drupal.behaviours.insert code, and at insert_process($element) and it seems I'm not going to be able to reuse these functions.
I've considered writing a custom formatter (even just site-specific), but even then I feel I'll miss all the neat features of insert and insert_image_filter unless I make it a massive clone of what your module does.
Any suggestions before I commit to a path?
Comments
Comment #1
simeTook me a while, but I worked out a very light way to do it. This will work ok for my current project, but it's not anything to write home about.
Steps...
1) In the view, I add a field which is the image that would be inserted. I don't display it.
2) I then create a global custom field in the view and I wrap some html around the image.
3) But I then hide the image with css.
4) Then I add this javascript to add click events to my inserts.
@quicksketch I'll leave this as Needs Review because I'm interested in your feedback still. Please close anytime.
Comment #2
quicksketchThis seems like something that definitely could benefit from having better access to Insert's existing JavaScript. I think it'd make a lot of sense if we made both the insert function and the current textarea tracker available at the global scope (under the Drupal variable of course), so you could just do something like this:
Then you wouldn't have to assume support for WYSIWYG or other solutions, instead you could just use Insert's tracking. It'd also make your code work with multiple textareas/WYSIWYGs.
I'm moving this to a feature request, since it'd be an obvious improvement without requiring any new code, we just need to rearrange things a bit.
Comment #3
simeBrilliant.
Comment #4
quicksketchI've added the attached patch which adds two public API functions:
Drupal.insert.insertAtCursor(editor, content): Used for insert text into textareas.
Drupal.insert.insertIntoActiveEditor(content): Generic function that will insert into the active (or last active) editor at the cursor position. Should work for most WYSIWYGs and textareas alike.