I am trying to fix some relative linking prior to the form submission. Here is my code:
The alert shows the new_html repaired but I can't seem to get the fix to "stick." I have read that there is a hidden value that is created on submission. Am I updating the wrong object? Is SetData irrelevant on form submission? Please nudge me in the correct direction.
Thank you,
Matt
function FCKeditor_OnComplete( editorInstance ){ editorInstance.LinkedField.form.onsubmit = function(){ html_content = editorInstance.GetHTML(); new_html = html_content.replace(/..\/..\/..\/..\//, './'); //alert(new_html); editorInstance.SetData(new_html); }; }
The alert shows the new_html repaired but I can't seem to get the fix to "stick." I have read that there is a hidden value that is created on submission. Am I updating the wrong object? Is SetData irrelevant on form submission? Please nudge me in the correct direction.
Thank you,
Matt
Re: Updating value post submit
The SetHTML and SetData do not seem to work for me. I have also tried this:
This works when you paste via CTRL-V but drag and drop is not considered pasting.
Re: Updating value post submit
Found out this code works if you submit in Source mode but not in WYSIWYG mode.
Edit: not posting as bug. I don't know why this even works so I can't adequately describe it.
This jquery works as well if committed in Source mode:
Re: Updating value post submit
Quick notes:
The return false lets me view the source after the submit. Finding are below. Also, I have found my jquery submit check runs prior to the "OnAfterLinkedFieldUpdate" event, not after. I have tried using UpdateLinkedField() after SetData thinking it might update the hidden value posted to next page. It does not.
So if I submit in editor mode, the iframe containing the fckeditor contains the fixed text. If you click "Source Mode", this iframe is dropped and turned into an empty textarea with class "SourceField". Below it is the html textarea.
Note the
I added this because the page source showed the html textarea as unaltered. I figured it may explain the difference between editor and source submit. It does not. No matter what this area says, source view submission are fixed and editor view submissions are not.
When preventing the submission BOTH the editor view and source view reflect the text change. The editor view shows a broken image (because the image pathing is not relative) and the source has the new directory designation.
So, I don't know if this is a bug or not. The editor and source views both reflect the fix. They just don't get passed on to the next page unless in source mode.
BTW these tests were run in Firefox 3.0.4.
Update: One last note. When dragging and dropping links to local files, the script worked in both cases (editor and source). Only images directories don't make it to the result in the editor.