Hello again ufku!

I've been trying without success to make the Imagecache button from the bueditor site at: http://ufku.com/drupal/bueditor/contributions/imagecache compatible with version 2.x.

The first think that happens is I receive a warning that eDefForm is undefined, from what I understand from the Readme.txt this is a deprecated function... Also the use of php inside the button is also deprecated. The code for this button (I believe) dates to Drupal 5.x, I'm guessing it needs alot of work!

so... How do I get this:

php:
$imce_url = url('imce');
$filepath = url(file_directory_path());

return "js:
var B = eDefBrowseButton('$imce_url', 'attr_src', 'Browse', 'image');
var form = [
{name: 'src', title: 'Image URL', suffix: B},
{name: 'preset', type: 'select', options: {'': '', set1: 'set1', set2: 'set2'}},
{name: 'alt', title: 'Alternative text'}
];
eDefTagDialog('img', form, 'Image Cache', 'OK', 'imageCacheProcess');

imageCacheProcess = function (tag, form) {
  var ps = form.elements['attr_preset'];
  var url = form.elements['attr_src'];
  if (ps.value) {
    url.value = '$filepath/imagecache/'+ ps.value + url.value;
    ps.value = '';
  }
  eDefTagInsert(tag, form);
}

var el = document.forms['eDefForm'].elements, url = el['attr_src'].value, i = url.indexOf('/imagecache/');
if (i != -1) {
  url = url.substr(i+12);
  i = url.indexOf('/');
  el['attr_src'].value = url.substr(i);
  el['attr_preset'].value = url.substr(0, i);
}
";

to be compatible with version 2.x?

Thanks in advance for any help you can give me!

Comments

ufku’s picture

Changing "eDefForm" to "bue_tgd_form" would be sufficient, however there is a better code for 6.x-2.x.

php:
$filepath = url(file_directory_path());
$presets = array('' => '');
foreach (imagecache_presets() as $preset) {
  $presets[$preset['presetname']]= $preset['presetname'];
}
$presets = drupal_to_js($presets);

return "js:
var form = [
  {name: 'src', title: 'Image URL', suffix: E.imce.button('attr_src'), required: 1},
  {name: 'preset', type: 'select', options: $presets},
  {name: 'alt', title: 'Alternative text', required: 1}
];

E.tagDialog('img', form, {title: 'Image Cache', submit: function(tag, form) {
  var ps = form.elements['attr_preset'];
  var url = form.elements['attr_src'];
  var fp = '$filepath';
  if (ps.value) {
    url.value = fp +'/imagecache/'+ ps.value + url.value.substr(fp.length);
    ps.value = '';
  }
  E.tgdSubmit(tag, form);
}});

var el = \$('form', E.dialog)[0].elements, url = el['attr_src'].value, i = url.indexOf('/imagecache/');
if (i > -1) {
  url = url.substr(i+12);
  i = url.indexOf('/');
  el['attr_src'].value = '$filepath'+ url.substr(i);
  el['attr_preset'].value = url.substr(0, i);
}
";

Presets are automatically loaded. You may change the way $presets array is created.
This one creates shorter URLs by removing the unnecessary filepath string after the preset name.

jolidog’s picture

Status: Active » Fixed

Thank you!

I was no my way to leave a comment at http://ufku.com/drupal/bueditor/contributions/imagecache with the update version, but you beat me to it ;)

Marking this as fixed.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.