Labels

accessibility (2) ADF (1) archiver (3) cmu (1) contributor (13) cookie (1) DAM (3) date (3) download (3) dynamic list (4) ephox (5) fatwire (1) fck (1) filters (1) folders (4) headers (2) IBR (3) ImageAlchemy (3) java (4) javascript (2) layout/template (4) link (6) locale (2) multilingual (1) rendition (3) replicator (4) rules (1) schema (1) search (11) sites (1) sitestudio (24) ssp/sspu (5) SSUrlFieldName (2) stellent (4) timezone (1) urm (1) weblogic (1) workflow (2)

Wednesday 15 October 2008

correcting links with a validation script

Ok, my personal war on dodgy UCM links continues... had a win when our Oracle consultant visited last week (I know he's reading this :)) and showed me some new tricks with validation scripts.

A validation script is just a bit of JavaScript that can be executed when a contributor tries to save their changes. There is no documentation on validation scripts so I never tried to use them myself... but all they do is run a defined function and throw an alert if the function does not return true. Well our mate suggested we just implement a script that silently rewrites dodgy UCM links and return true.

It's so simple and yet so liberating! Thankyou James.

7 comments:

  1. If only James was able to visit us here in Perth ...

    ReplyDelete
  2. Do you have a small sample of the code you used for the validation script?

    I want to place some text as well, but I'm not sure how to return the modified string.

    For example, here's my simple validation script function:

    function fnModifyWysiwyg(oContent) {
    var strTextContent = fnSSGetTextContent(oContent);

    strTextContent = "this is a test";

    return true;
    }

    Does this make sense? In other words, how do I return the modified content back?

    ReplyDelete
  3. How do you want it returned? If you just want to replace the existing text, just update the oContent variable. When you're done, return true and it saves/closes. Return false (or a string) and it throws a javascript alert, preventing the save/close. For your example, you've extracted text from oContent, so you need to inject the new text without damaging the original structure. For example:

    if (typeof oContent.innerText == 'string') oContent.innerText = strTextContent;

    Look at the fnSSGetTextContent() function for the rest of the code you need.

    ReplyDelete
  4. I can't get it to just do a simple replace of everything - just to test. I'm missing something...

    function fnSSVDefaultWysiwygValidation1(oContent)
    {
    var strTextContent = 'this is a test';

    if (typeof oContent == 'string')
    oContent = strTextContent;
    else if (typeof oContent.innerText == 'string')
    oContent.innerText = strTextContent;
    else if (typeof oContent.textContent == 'string')
    oContent.textContent = strTextContent;

    return true;

    }

    For testing, I'm just trying to replace everything with "this is a test". That way I can see if it's working or not.

    Ultimately what I want to do is find every img tag in the element's content and add a specific width and height into them. If there's already width and height attributes then update them.

    ReplyDelete
  5. This comment has been removed by the author.

    ReplyDelete
  6. This comment has been removed by the author.

    ReplyDelete