Closed (fixed)
Project:
BUEditor
Version:
7.x-1.x-dev
Component:
Documentation
Priority:
Normal
Category:
Support request
Assigned:
Unassigned
Reporter:
Created:
4 Apr 2011 at 07:00 UTC
Updated:
2 Mar 2012 at 12:33 UTC
Here is a button for inserting images with imce using drupal core image styles (equivalent of imagecache in drupal 6).
This code was adapted from #651794-1: Imagecache Button update help. for drupal 6 + imce + imagecache.
There is some room for improvement though as this is currently hard coded for a public file system.
php:
if (!function_exists('image_styles')) return;
$filepath = url(variable_get('file_public_path', conf_path() . '/files'));
$styles = array('' => '');
foreach (image_styles() as $style) {
$styles[$style['name']] = $style['name'];
}
$styles = drupal_json_encode($styles);
return "js:
var form = [
{name: 'src', title: 'Image URL', suffix: E.imce.button('attr_src'), required: 1},
{name: 'style', title: 'Image style', type: 'select', options: $styles},
{name: 'alt', title: 'Alternative text', required: 1}
];
// Open dialog.
E.tagDialog('img', form, {title: 'Image', submit: function(tag, form) {
var st = form.elements.attr_style;
var url = form.elements.attr_src;
var fp = '$filepath';
if (st.value) {
if (url.value.indexOf(fp) == 0) {
url.value = fp + '/styles/' + st.value + '/public' + url.value.substr(fp.length);
}
st.value = '';
}
E.tgdSubmit(tag, form);
}});
// Update fields.
var el = $('form', E.dialog)[0].elements;
var url = el.attr_src.value;
var i = url.indexOf('/styles/');
if (i > -1) {
url = url.substr(i + 8);
i = url.indexOf('/');
el.attr_src.value = '$filepath' + url.substr(i);
el.attr_style.value = url.substr(0, i);
}
";
Comments
Comment #1
agileware commentedComment #2
ufku commented