Hi, I'm not sure if this is the right place to post, I'm quite new to drupal.
Searching on the net I've seen that placing images in wysiwyg is quite an issue for drupal. After reading some documentation I've stitched togeter a solution, that seems quite natural for me - use the very nice (AHAH) imagefield forms to upload the images (and keep them attached to the content they belong to), and then use TinyMCE to place them in the text.
The idea is to add an array item for each admin preview (thumbnail) somewhere to the DOM and then pick the array up in popup image dialog of TinyMCE (it already has a feature called 'image list').
Altogether this is 6 lines of new code, four in imagefield.module, function theme_imagefield_widget_preview($item = NULL):
$script = '<script type="text/javascript">';
$script .= 'if (!window.tinyMCEImageList) tinyMCEImageList = new Array();';
$script .= 'tinyMCEImageList.push(' . drupal_to_js(array($item['filename'], file_create_url($item['filepath']))) . ');';
$script .= '</script>';
return $script . '<div class="imagefield-preview">' . theme('imagefield_admin_thumbnail', $item) . '</div>';
(and one line changed, to return the results;)
and in tinymce/jscripts/tiny_mce/themes/advanced/js/image.js add those two lines to the end of preInit : function():
var parent = tinyMCEPopup.getWin();
if(parent && parent.tinyMCEImageList) window.tinyMCEImageList = parent.tinyMCEImageList;
Now each time you click the image tool in tinyMCE, you can choose from the images attached in imagefields associated with current content.
This is quite a hack now, and I'm not sure if it doesn't break any drupal principles, but it works.
Please tell me what do you think about it, whether it's worth some more work..
Thanks
Comments
Comment #1
quicksketchWow this is a neat trick, though I'm not sure if it's something that should be included in ImageField. Thanks for sharing, I'll leave this open until we decide what to do with it.
Comment #2
quicksketchMoving this over to TinyMCE, since I don't think we can include such editor-specific code in ImageField.
Comment #3
nicoloye commented