Hi there,

It could be great if bueEditor support imagecache.

for example, when you want to add a picture and imagecache is enabled, to add a list of imagecache available preset and choose one...

thanks

zmove

Comments

sime’s picture

I'm not much of js coder, so I'll describe my solution for the record but its not that pretty.

1. I created a new module to insert an extra js function. This function is a hack of eDefTagInsert with the only difference being it looks for a 'display' attribute and modifies the image path to be an imagecache image instead. Below is the contents of the js, I then obviously add it with drupal_add_js().

function imagecacheInsert(tag, form) {try {

  form.elements['attr_src'].value = '/sites/default/files/imagecache/'+ form.elements['attr_display'].value +  form.elements['attr_src'].value

  
  var name, el, obj = eDefParseTag(editor.active.getSelection(), tag)||{attributes: []};
  for (var i=0; el = form.elements[i]; i++) {
    if (el.name.substr(0, 5) == 'attr_') {
      name = el.name.substr(5);
      obj.attributes[name] = el.value == '' ? (tag == 'img' && editor.inArray(name, ['src', 'alt']) ? '' : null) : el.value;
    }
  }
  editor.dialog.close();
  if (typeof(obj.innerHTML) == 'string' || editor.inArray(tag, ['img', 'input', 'hr', 'br'])) {
    editor.active.replaceSelection(eDefHTML(tag, obj.innerHTML, obj.attributes));
  }
  else {
    var txt = eDefHTML(tag, '', obj.attributes);
    editor.active.tagSelection(txt.substr(0, txt.length-tag.length-3), '</'+ tag +'>');
  }
} catch(e){}}

Then my button is pretty simple. You can see where I've hard-coded the desire imagecache presets. options: {medium: 'medium', wide: 'wide'}

php:
$imce_url = function_exists('imce_menu') && user_access('access imce') ? url('imce/browse') : '';

return "js:
var B = eDefBrowseButton('$imce_url', 'attr_src', 'Browse', 'image');
var form = [
 {name: 'src', title: 'Image URL', suffix: B},
 {name: 'display', title: 'Display', type: 'select', options: {medium: 'medium', wide: 'wide'}},
 {name: 'alt', title: 'Alternative text'}
];
eDefTagDialog('img', form, 'Insert/edit image', 'OK', 'imagecacheInsert');

";

Now this works, but it's not robust. I post it here for collaboration purposes, not as a solution that you should use live unless you know what you're doing. Thanks

ufku’s picture

hi simon,
thanks for your contribution :). If you dont mind i want to add my 2 cents.

you may consider shortening the imagecacheInsert code by writing "eDefTagInsert(tag, form)" instead of the whole code after the attr_src manipulation.

function imagecacheInsert(tag, form) {
  form.elements['attr_src'].value = '/sites/default/files/imagecache/'+ form.elements['attr_display'].value +  form.elements['attr_src'].value;
  eDefTagInsert(tag, form);
}

It should work if the replaced code is completely the same as eDefTagInsert code.

I don't know if the display atrribute (which is non-standard) is necessary but you can delete it before sending the form to eDefTagInsert.
delete form.elements['attr_display'];

sime’s picture

Much neater!!

You're right, the 'display' attribute is just used to alter the image path. Imagecache module handles the rest. So I will certainly be using the delete form.elements['attr_display']; line.

I was also trying to include my custom function inside the button code - directly after:
return "js:
But I was getting the error that 'imagecacheInsert' was not a valid function. Is there a way to achieve this? (It would be great to avoid making a separate .js file.)

ufku’s picture

Status: Active » Fixed

yes, it is possible to make the function global.
define it in this format:
imagecacheInsert = function(tag, form) {...}

Note:
function imagecacheInsert(tag, form){}
is the same as
var imagecacheInsert = function(tag, form){}
in which the "var" keyword makes it local. Excluding the "var" makes it global.

Marking this issue as fixed to make it a reference for imagecache-bueditor integration.

sime’s picture

awesome - thanks for the follow up!

Anonymous’s picture

Status: Fixed » Closed (fixed)

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