Please excuse me if I made mistakes but english isn't my mother tongueI'm also trying to use jQuery UI dialog with WYMeditor.
Since the last version of jQuery UI is not already stable, some bugs remain like allowing only a single dialog spawn per page refresh. It's a bit akward but I hope that will be fixed in the final release
- It may be already fixed in the last build, since many things seems to have been changed in the library I'm waiting for the final release to integrate it further -.
However, it's not my main problem.
Dialogs run succesfully to create links or images and to preview editor's content
- I don't use the table dialog - and fields are filled with the right values when editing one, but when I submit it again tu update link's or image's attributes, it ended with an NS_ERROR_NOT_IMPLEMENTED Exception in Firefox.
Did I miss something or is this a knowed bug of the current beta release ?
This is the source of my rewritted dialog function :
- Code: Select all
/* @name dialog
* @description Opens a dialog box
*/
WYMeditor.editor.prototype.dialog = function( dialogType, bodyHtml ) {
if(SBAjaxWrapper) {
var sBodyHtml = "";
var h = WYMeditor.Helper;
var wym = this;
var doc = SBAjaxWrapper.ajaxDialog; // This points to DOMElement use as jQuery UI Dialog box
var selected = wym.selected();
var sStamp = wym.uniqueStamp();
switch( dialogType ) {
case WYMeditor.DIALOG_LINK:
sBodyHtml = this._options.dialogLinkHtml;
break;
case WYMeditor.DIALOG_IMAGE:
sBodyHtml = this._options.dialogImageHtml;
break;
case WYMeditor.DIALOG_TABLE:
sBodyHtml = this._options.dialogTableHtml;
break;
case WYMeditor.DIALOG_PASTE:
sBodyHtml = this._options.dialogPasteHtml;
break;
case WYMeditor.PREVIEW:
sBodyHtml = this._options.dialogPreviewHtml;
break;
default:
sBodyHtml = bodyHtml;
}
//construct the dialog
var dialogHtml = h.replaceAll(this._options.dialogHtml, WYMeditor.DIALOG_BODY, sBodyHtml);
dialogHtml = jQuery(this.replaceStrings(dialogHtml));
switch( dialogType ) {
case WYMeditor.DIALOG_LINK:
okFunction = function() {
var sUrl = jQuery(wym._options.hrefSelector, doc).val();
if(sUrl.length > 0) {
wym._exec(WYMeditor.CREATE_LINK, sStamp);
jQuery("a[@href=" + sStamp + "]", wym._doc.body)
.attr(WYMeditor.HREF, sUrl)
.attr(WYMeditor.TITLE, jQuery(wym._options.titleSelector, doc).val());
}
}
break;
case WYMeditor.DIALOG_IMAGE:
okFunction = function() {
var sUrl = jQuery(wym._options.srcSelector, SBAjaxWrapper.ajaxDialog).val();
if(sUrl.length > 0) {
wym._exec(WYMeditor.INSERT_IMAGE, sStamp);
jQuery("img[@src=" + sStamp + "]", wym._doc.body)
.attr(WYMeditor.SRC, sUrl)
.attr(WYMeditor.TITLE, jQuery(wym._options.titleSelector, doc).val())
.attr(WYMeditor.ALT, jQuery(wym._options.altSelector, doc).val());
}
}
break;
case WYMeditor.DIALOG_TABLE:
okFunction = function() {
var iRows = jQuery(wym._options.rowsSelector, doc).val();
var iCols = jQuery(wym._options.colsSelector, doc).val();
if(iRows > 0 && iCols > 0) {
var table = wym._doc.createElement(WYMeditor.TABLE);
var newRow = null;
var newCol = null;
var sCaption = jQuery(wym._options.captionSelector, doc).val();
//we create the caption
var newCaption = table.createCaption();
newCaption.innerHTML = sCaption;
//we create the rows and cells
for(x=0; x<iRows; x++) {
newRow = table.insertRow(x);
for(y=0; y<iCols; y++) {newRow.insertCell(y);}
}
//set the summary attr
jQuery(table).attr('summary', jQuery(wym._options.summarySelector, doc).val());
//append the table after the selected container
var node = jQuery(wym.findUp(wym.container(), WYMeditor.MAIN_CONTAINERS)).get(0);
if(!node || !node.parentNode) jQuery(wym._doc.body).append(table);
else jQuery(node).after(table);
}
}
break;
case WYMeditor.DIALOG_PASTE:
okFunction = function() {
var sText = jQuery(wym._options.textSelector, doc).val();
wym.paste(sText);
}
break;
default:
okFunction = function() {}
break;
}
option = jQuery.extend(SBAjaxWrapper.option.dialogOption, {
buttons: {
'Ok': function() {
okFunction();
doc.dialog('close');
}
}
} );
doc.html(dialogHtml).dialog(option);
// init dialog
switch(dialogType) {
case WYMeditor.DIALOG_LINK:
//ensure that we select the link to populate the fields
if(selected && selected.tagName && selected.tagName.toLowerCase != WYMeditor.A)
selected = jQuery(selected).parentsOrSelf(WYMeditor.A);
//fix MSIE selection if link image has been clicked
if(!selected && wym._selected_image)
selected = jQuery(wym._selected_image).parentsOrSelf(WYMeditor.A);
break;
}
//pre-init functions
if(jQuery.isFunction(wym._options.preInitDialog))
wym._options.preInitDialog(wym, doc);
//auto populate fields if selected container (e.g. A)
if(selected) {
jQuery(wym._options.hrefSelector, doc).val(jQuery(selected).attr(WYMeditor.HREF));
jQuery(wym._options.srcSelector, doc).val(jQuery(selected).attr(WYMeditor.SRC));
jQuery(wym._options.titleSelector, doc).val(jQuery(selected).attr(WYMeditor.TITLE));
jQuery(wym._options.altSelector, doc).val(jQuery(selected).attr(WYMeditor.ALT));
}
//auto populate image fields if selected image
if(wym._selected_image) {
jQuery(wym._options.dialogImageSelector + " " + wym._options.srcSelector, doc)
.val(jQuery(wym._selected_image).attr(WYMeditor.SRC));
jQuery(wym._options.dialogImageSelector + " " + wym._options.titleSelector, doc)
.val(jQuery(wym._selected_image).attr(WYMeditor.TITLE));
jQuery(wym._options.dialogImageSelector + " " + wym._options.altSelector, doc)
.val(jQuery(wym._selected_image).attr(WYMeditor.ALT));
}
jQuery(wym._options.dialogPreviewSelector + " " + wym._options.previewSelector, doc).html(wym.xhtml());
//pre-init functions
if(jQuery.isFunction(wym._options.postInitDialog))
wym._options.postInitDialog(wym, doc);
}
};
I can't produce complete source code with dialog initialisation and Co for the moment, because WYMEditor, jQuery and JQuery UI are tightly integrated one with the others and with my own CMS. If people are interested, I will extract sort of WYMEditor plugin for UI dialog when all will be fixed.[Edit]
I've found this on Trac :
http://trac.wymeditor.org/trac/ticket/20It seems to be an old bug with firefox and link editing but what about images ?