Forum OpenACS Development: Re: xowiki javascript "function calc_image_tags_to_wiki_image_links" doesn't do what you'd expect...

I have fixed the wiki_link references on my system so that they point to the images uploaded using xowikiimages by adding :

window.location.pathname.split('/').splice(-1) + '/' +

to the javascript function that generates the wiki_links as follows:

function calc_image_tags_to_wiki_image_links (form) {
    var calc = function() {
      var wiki_link = window.location.pathname.split('/').splice(-1) + '/' + $(this).attr('alt');
      $(this).replaceWith('[['+wiki_link+']]');
    }

This is in:

richtext::ckeditor instproc js_image_helper

The image links now work and display the uploaded image when the page is viewed.

Regards
Richard

....and I have also had to modify the following lines of the calc_wiki_image_links_to_image_tags function that converts the [[my_page/image:my_photo_ext]] link back into an <img> tag so that the editor window can retrieve and display the image in WSIWYG fashion:

    var regex_wikilink = new RegExp('(\\[\\[.*/image:)(.*)(\\]\\])', 'g');
    data = data.replace(regex_wikilink,'<img src="'+pathname+'/file:$2?m=download"  alt="image:$2" type="wikilink"  />');

In context the complete function with adjusted lines is:

function calc_wiki_image_links_to_image_tags (data) {
    var pathname = window.location.pathname;
    pathname = pathname.substr(pathname.lastIndexOf("/")+1,pathname.length)
    console.log('pathname' + pathname);
    pathname = pathname.replace(/:/ig,"%3a");
    var regex_wikilink = new RegExp('(\\[\\[.*/image:)(.*)(\\]\\])', 'g');
    data = data.replace(regex_wikilink,'<img src="'+pathname+'/file:$2?m=download"  alt="image:$2" type="wikilink"  />');
    console.log('data' + data);
    return data
}

It was as if someone had modified the code to create filenames with the page name prefixed to them, but did not adjust the javascript helper functions to match.

It is certainly very helpful that the xowikiimage selector/uploader only displays images that have been uploaded for the specific page you are working on.  Otherwise the number of images in the selector would rapidly become unmanageable.  It may simply be that the Javascript functions were not updated after this refinement was added.

Regards
Richard