Hi,

I've been trying to find a way to make Img_assist pass not just the src, size, alt, etc to tincyme but also the link to the original node. Like how img_assist would normally hyperlink an image to the node in a simple textarea. I've spent more time than I care to admit on this little project, and I'm completely stumped. Most likely my lack of understanding of javascript. My approach to learning a new language is to delete likely suspects until I find something that breaks. At the momment, I can't even figure out how img_assist is passing the src and size to tinymce. And then of course chaining this alltogether with tinymce, might be over my head. But I would welcome any hints or thoughts.

mitomac

CommentFileSizeAuthor
#4 tinymce_mitomac.patch822 bytesmitomac

Comments

matt westgate’s picture

When the img_assist 'Insert image' button is clicked the Javascript function insertImage(form) is called (line 90 of tinymce.module). This in turn calls tinyMCE.insertImage() which creates and inserts an image tag (line 1999 of tiny_mce_src.js).

Keep working on this. Maybe you find the exact command used to write regular HTML to the tinymce instance. From a quick scan of how the HTML table plugin works, it looks like mceInsertContent is the way to go:

var html = 'a bunch of html code';
tinyMCE.getInstanceById(editor_id).execCommand('mceInsertContent', false, html)
mitomac’s picture

Thanks Mathias,

I have it working now, after some initial trouble with tinymce clobbering the inserted urls. You were right on the money with the InsertContent command. I am going to push forward and see if I can get tinymce to use the image template from img_assist now. I will upload a small patch later.

mitomac

matt westgate’s picture

Excellent!

I look forward to the patch.

mitomac’s picture

StatusFileSize
new822 bytes

Hi,

Here is the small patch that changes tinymce module to use mceInsertContent to insert the html describing the image and its node etc. The caveats are 1) that after inserting the image the cursor is positioned before the image, and 2) the image template is hard coded. I couldn't find a good way to convert $img_template to a suitable format to insert the javascript variables in the placeholders. Maybe there is a clever way to do this in javascript? I probably could have come up with a nasty regexp to do the work, but it would likely be pretty ugly.

mitomac

matt westgate’s picture

I committed a modified version of this patch. Thanks!

mitomac’s picture

Great, I look forward to testing the new version and learning the proper way to do things. I've really enjoyed poking around in these two modules. I'm a biologist by training who tends to use perl to 'just get things done'. It really is nice to poke through a code base that is a) understandable and b) designed with thought and not just a quick hack.

Thanks,

mitomac

matt westgate’s picture

A great way to review changes to these files is by clicking the revision number to the right of each filename in the commit messages:

http://drupal.org/cvs?commit=15104
http://drupal.org/cvs?commit=15103

It's been fun for me as well. I haven't done much Javascripting in the past.

Anonymous’s picture