I've made button to upload and insert images using Upload & Imagecache modules. As a result I've got this: Screenshot
Here is the working code:
<?php
php:
global $base_url;
$file_path = $base_url . url(file_directory_path());
// preset for preview
$preview_preset = "bueditor-previews";
// preset for inline inserted photo
$inline_preset = "inline-inserted-photo";
// preset for linked original photo
$original_preset = "original-photo";
drupal_add_js(array('myBueImage' => array(
'file_path' => "$file_path/",
'preview_path' => "$file_path/imagecache/$preview_preset/",
'inline_path' => "$file_path/imagecache/$inline_preset/",
'original_path' => "$file_path/imagecache/$original_preset/"
)), 'setting');
return 'js:
var $output = \'<div style="width:280px;text-align:center">\';
$("table#upload-attachments small:contains("+ Drupal.settings.myBueImage.file_path +")").each(function(){
var $filename = $(this).text().split("/").reverse()[0];
var $preview = \'<img src="\'+ Drupal.settings.myBueImage.preview_path + $filename +\'" style="margin:0 4px 0 0;padding:2px;border:1px solid #ccc;cursor:pointer" class="bueditor-photo-preview" id="\'+ $filename +\'" />\';
$output += $preview;
});
$output += \'</div>\';
$output += \'<div style="width:280px;margin-top:4px;padding-top:2px;padding-left:4px;border-top:1px solid #ccc;"><label for="bueditor-photo-align">Align: </label><select name="bueditor-photo-align" class="form-select" id="bueditor-photo-align"><option value="nolalign"><none></option><option value="sinistra">Left</option><option value="destra">Right</option></select></div>\';
E.dialog.open("Users", $output);
$("img.bueditor-photo-preview").click(function() {
var $filename = $(this).attr("id");
var $txt = \'<a href="\'+ Drupal.settings.myBueImage.original_path + $filename +\'" target="_blank" rel="thickbox"><img src="\'+ Drupal.settings.myBueImage.inline_path + $filename +\'" class="\'+ $("select#bueditor-photo-align").val() +\'" /></a>\';
E.replaceSelection($txt).dialog.closenfocus();
return false;
});
';
?>
Can anyone help me with optimizing code? I'm asking help because my knowledge of JavaScript is not well as the developers of this module. :) Thnks
Comments
Comment #1
janis_lv commentedhey, this is what I've always missed in BUEditor :)
great job, I do hope someone helps you :D