Index: openacs-4/packages/xowiki/www/resources/wymeditor/jquery.wymeditor.js =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/xowiki/www/resources/wymeditor/jquery.wymeditor.js,v diff -u -r1.1 -r1.2 --- openacs-4/packages/xowiki/www/resources/wymeditor/jquery.wymeditor.js 15 Jul 2007 16:07:45 -0000 1.1 +++ openacs-4/packages/xowiki/www/resources/wymeditor/jquery.wymeditor.js 27 Jul 2007 01:15:20 -0000 1.2 @@ -211,8 +211,8 @@ /********** CONSTANTS **********/ - var $j = jQuery.noConflict(); + var WYM_INSTANCES = new Array(); var WYM_NAME = "name"; var WYM_INDEX = "{Wym_Index}"; @@ -316,7 +316,7 @@ /** * Replace an HTML element by WYMeditor * - * @example $j(".wymeditor").wymeditor( + * @example jQuery(".wymeditor").wymeditor( * { * * } @@ -333,9 +333,9 @@ * @cat Plugins/WYMeditor * @author Jean-Francois Hovinne */ -$j.fn.wymeditor = function(options) { +jQuery.fn.wymeditor = function(options) { - options = $j.extend({ + options = jQuery.extend({ html: "", @@ -376,7 +376,7 @@ + "src='" + WYM_IFRAME_BASE_PATH + "wymiframe.html' " - + "onload='window.parent.WYM_INSTANCES[" + + "onload='this.contentWindow.parent.WYM_INSTANCES[" + WYM_INDEX + "].initIframe(this)' " + ">" + "", @@ -659,14 +659,14 @@ return this.each(function(i) { - new Wymeditor($j(this),i,options); + new Wymeditor(jQuery(this),i,options); }); }; /* @name extend * @description Returns the WYMeditor instance based on its index */ -$j.extend({ +jQuery.extend({ wymeditors: function(i) { return (WYM_INSTANCES[i]); }, @@ -688,7 +688,7 @@ this._element = elem; this._index = index; this._options = options; - this._html = $j(elem).val(); + this._html = jQuery(elem).val(); if(this._options.html) this._html = this._options.html; this._options.basePath = this._options.basePath @@ -711,24 +711,24 @@ //load subclass - browser specific //unsupported browsers: do nothing - if ($j.browser.msie) { + if (jQuery.browser.msie) { var WymClass = new WymClassExplorer(this); } - else if ($j.browser.mozilla) { + else if (jQuery.browser.mozilla) { var WymClass = new WymClassMozilla(this); } - else if ($j.browser.opera) { + else if (jQuery.browser.opera) { var WymClass = new WymClassOpera(this); } - else if ($j.browser.safari) { + else if (jQuery.browser.safari) { //commented until supported //var WymClass = new WymClassSafari(this); + var WymClass = new WymClassOpera(this); } - if(WymClass) { - if($j.isFunction(this._options.preInit)) this._options.preInit(this); + if(jQuery.isFunction(this._options.preInit)) this._options.preInit(this); this.loadXhtmlParser(WymClass); @@ -739,10 +739,10 @@ this.helper = new XmlHelper(); //extend the Wymeditor object - $j.extend(this, WymClass); + jQuery.extend(this, WymClass); //load wymbox - this._box = $j(this._element).hide().after(this._options.boxHtml).next(); + this._box = jQuery(this._element).hide().after(this._options.boxHtml).next(); //construct the iframe var iframeHtml = this._options.iframeHtml; @@ -751,7 +751,7 @@ .replaceAll(WYM_IFRAME_BASE_PATH, this._options.iframeBasePath); //construct wymbox - var boxHtml = $j(this._box).html(); + var boxHtml = jQuery(this._box).html(); boxHtml = boxHtml.replaceAll(WYM_TOOLS, this._options.toolsHtml); boxHtml = boxHtml.replaceAll(WYM_CONTAINERS,this._options.containersHtml); @@ -814,10 +814,10 @@ boxHtml = this.replaceStrings(boxHtml); //load html in wymbox - $j(this._box).html(boxHtml); + jQuery(this._box).html(boxHtml); //hide the html value - $j(this._box).find(this._options.htmlSelector).hide(); + jQuery(this._box).find(this._options.htmlSelector).hide(); //enable the skin this.skin(); @@ -831,27 +831,27 @@ var wym = this; //handle click event on tools buttons - $j(this._box).find(this._options.toolSelector).click(function() { - wym.exec($j(this).attr(WYM_NAME)); + jQuery(this._box).find(this._options.toolSelector).click(function() { + wym.exec(jQuery(this).attr(WYM_NAME)); return(false); }); //handle click event on containers buttons - $j(this._box).find(this._options.containerSelector).click(function() { - wym.container($j(this).attr(WYM_NAME)); + jQuery(this._box).find(this._options.containerSelector).click(function() { + wym.container(jQuery(this).attr(WYM_NAME)); return(false); }); //handle keyup event on html value: set the editor value - $j(this._box).find(this._options.htmlValSelector).keyup(function() { - $j(wym._doc.body).html($j(this).val()); + jQuery(this._box).find(this._options.htmlValSelector).keyup(function() { + jQuery(wym._doc.body).html(jQuery(this).val()); }); //handle click event on classes buttons - $j(this._box).find(this._options.classSelector).click(function() { + jQuery(this._box).find(this._options.classSelector).click(function() { var aClasses = eval(wym._options.classesItems); - var sName = $j(this).attr(WYM_NAME); + var sName = jQuery(this).attr(WYM_NAME); var oClass = aClasses.findByName(sName); @@ -863,7 +863,7 @@ }); //handle event on update element - $j(this._options.updateSelector) + jQuery(this._options.updateSelector) .bind(this._options.updateEvent, function() { wym.update(); }); @@ -888,8 +888,8 @@ */ Wymeditor.prototype.html = function(html) { - if(html) $j(this._doc.body).html(html); - else return($j(this._doc.body).html()); + if(html) jQuery(this._doc.body).html(html); + else return(jQuery(this._doc.body).html()); }; /* @name xhtml @@ -1024,11 +1024,11 @@ var container = (this._selected_image ? this._selected_image - : $j(this.selected())); - container = $j(container).parentsOrSelf(jqexpr); - $j(container).toggleClass(sClass); + : jQuery(this.selected())); + container = jQuery(container).parentsOrSelf(jqexpr); + jQuery(container).toggleClass(sClass); - if(!$j(container).attr(WYM_CLASS)) $j(container).removeAttr(this._class); + if(!jQuery(container).attr(WYM_CLASS)) jQuery(container).removeAttr(this._class); }; @@ -1081,9 +1081,9 @@ Wymeditor.prototype.switchTo = function(node,sType) { var newNode = this._doc.createElement(sType); - var html = $j(node).html(); + var html = jQuery(node).html(); node.parentNode.replaceChild(newNode,node); - $j(newNode).html(html); + jQuery(newNode).html(html); this.setFocusToNode(newNode); }; @@ -1109,7 +1109,7 @@ Wymeditor.prototype.status = function(sMessage) { //print status message - $j(this._box).find(this._options.statusSelector).html(sMessage); + jQuery(this._box).find(this._options.statusSelector).html(sMessage); }; /* @name update @@ -1118,8 +1118,8 @@ Wymeditor.prototype.update = function() { var html = this.xhtml(); - $j(this._element).val(html); - $j(this._box).find(this._options.htmlValSelector).val(html); + jQuery(this._element).val(html); + jQuery(this._box).find(this._options.htmlValSelector).val(html); }; /* @name dialog @@ -1177,7 +1177,7 @@ * @description Shows/Hides the HTML */ Wymeditor.prototype.toggleHtml = function() { - $j(this._box).find(this._options.htmlSelector).toggle(); + jQuery(this._box).find(this._options.htmlSelector).toggle(); }; Wymeditor.prototype.uniqueStamp = function() { @@ -1200,14 +1200,14 @@ sTmp = aP[x]; //simple newlines are replaced by a break sTmp = sTmp.replace(rExp, "
"); - $j(container).after("

" + sTmp + "

"); + jQuery(container).after("

" + sTmp + "

"); } } else { for(x = 0; x < aP.length; x++) { sTmp = aP[x]; //simple newlines are replaced by a break sTmp = sTmp.replace(rExp, "
"); - $j(this._doc.body).append("

" + sTmp + "

"); + jQuery(this._doc.body).append("

" + sTmp + "

"); } } @@ -1226,27 +1226,27 @@ /********** CONFIGURATION **********/ Wymeditor.prototype.computeBasePath = function() { - return $j($j.grep($j('script'), function(s){ + return jQuery(jQuery.grep(jQuery('script'), function(s){ return (s.src && s.src.match(/jquery\.wymeditor\.js(\?.*)?$/ )) })).attr('src').replace(/jquery\.wymeditor\.js(\?.*)?$/, ''); }; Wymeditor.prototype.computeJqueryPath = function() { - return $j($j.grep($j('script'), function(s){ + return jQuery(jQuery.grep(jQuery('script'), function(s){ return (s.src && s.src.match(/jquery\.js(\?.*)?$/ )) })).attr('src'); }; Wymeditor.prototype.computeCssPath = function() { - return $j($j.grep($j('link'), function(s){ + return jQuery(jQuery.grep(jQuery('link'), function(s){ return (s.href && s.href.match(/wymeditor\/skins\/(.*)screen\.css(\?.*)?$/ )) })).attr('href'); }; Wymeditor.prototype.loadXhtmlParser = function(WymClass) { if(typeof XhtmlSaxListener != 'function'){ // This is the only way to get loaded functions in the global scope until jQuery.globalEval works in safari - eval($j.ajax({url:this._options.basePath+'xhtml_parser.js',async:false}).responseText); + eval(jQuery.ajax({url:this._options.basePath+'xhtml_parser.js',async:false}).responseText); window.XmlHelper = XmlHelper; window.XhtmlValidator = XhtmlValidator; window.ParallelRegex = ParallelRegex; @@ -1264,16 +1264,16 @@ Wymeditor.prototype.configureEditorUsingRawCss = function() { if(typeof WymCssParser != 'function'){ - eval($j.ajax({url:this._options.basePath+'wym_css_parser.js',async:false}).responseText); + eval(jQuery.ajax({url:this._options.basePath+'wym_css_parser.js',async:false}).responseText); window.WymCssLexer = WymCssLexer; window.WymCssParser = WymCssParser; } var CssParser = new WymCssParser(); if(this._options.stylesheet){ - CssParser.parse($j.ajax({url: this._options.stylesheet,async:false}).responseText); + CssParser.parse(jQuery.ajax({url: this._options.stylesheet,async:false}).responseText); }else{ CssParser.parse(this._options.styles, false); - } + } if(this._options.classesItems.length == 0) { this._options.classesItems = CssParser.css_settings.classesItems; @@ -1292,12 +1292,12 @@ //don't use jQuery.find() on the iframe body //because of MSIE + jQuery + expando issue (#JQ1143) - //$j(this._doc.body).find("*").bind("mouseup", this.mouseup); + //jQuery(this._doc.body).find("*").bind("mouseup", this.mouseup); - $j(this._doc.body).bind("mouseup", this.mouseup); + jQuery(this._doc.body).bind("mouseup", this.mouseup); var images = this._doc.body.getElementsByTagName("img"); for(var i=0; i < images.length; i++) { - $j(images[i]).bind("mouseup", this.mouseup); + jQuery(images[i]).bind("mouseup", this.mouseup); } }; @@ -1318,41 +1318,41 @@ case WYM_DEFAULT_SKIN: - $j(this._box).addClass("wym_skin_default"); + jQuery(this._box).addClass("wym_skin_default"); //render following sections as panels - $j(this._box).find(this._options.classesSelector) + jQuery(this._box).find(this._options.classesSelector) .addClass("wym_panel"); //render following sections as buttons - $j(this._box).find(this._options.toolsSelector) + jQuery(this._box).find(this._options.toolsSelector) .addClass("wym_buttons"); //render following sections as dropdown menus - $j(this._box).find(this._options.containersSelector) + jQuery(this._box).find(this._options.containersSelector) .addClass("wym_dropdown") .find(WYM_H2) .append(" >"); // auto add some margin to the main area sides if left area // or right area are not empty (if they contain sections) - $j(this._box).find("div.wym_area_right ul") + jQuery(this._box).find("div.wym_area_right ul") .parents("div.wym_area_right").show() .parents(this._options.boxSelector) .find("div.wym_area_main") .css({"margin-right": "155px"}); - $j(this._box).find("div.wym_area_left ul") + jQuery(this._box).find("div.wym_area_left ul") .parents("div.wym_area_left").show() .parents(this._options.boxSelector) .find("div.wym_area_main") .css({"margin-left": "155px"}); //make hover work under IE < 7 - $j(this._box).find(".wym_section").hover(function(){ - $j(this).addClass("hover"); + jQuery(this._box).find(".wym_section").hover(function(){ + jQuery(this).addClass("hover"); },function(){ - $j(this).removeClass("hover"); + jQuery(this).removeClass("hover"); }); break; @@ -1372,11 +1372,11 @@ //fix MSIE selection if link image has been clicked if(!selected && wym._selected_image) { - selected = $j(wym._selected_image).parentsOrSelf(WYM_A); + selected = jQuery(wym._selected_image).parentsOrSelf(WYM_A); } //pre-init functions - if($j.isFunction(wym._options.preInitDialog)) + if(jQuery.isFunction(wym._options.preInitDialog)) wym._options.preInitDialog(wym,window); //add css rules from options @@ -1387,84 +1387,84 @@ //auto populate fields if selected container (e.g. A) if(selected) { - $j(wym._options.hrefSelector).val($j(selected).attr(WYM_HREF)); - $j(wym._options.srcSelector).val($j(selected).attr(WYM_SRC)); - $j(wym._options.titleSelector).val($j(selected).attr(WYM_TITLE)); - $j(wym._options.altSelector).val($j(selected).attr(WYM_ALT)); + jQuery(wym._options.hrefSelector).val(jQuery(selected).attr(WYM_HREF)); + jQuery(wym._options.srcSelector).val(jQuery(selected).attr(WYM_SRC)); + jQuery(wym._options.titleSelector).val(jQuery(selected).attr(WYM_TITLE)); + jQuery(wym._options.altSelector).val(jQuery(selected).attr(WYM_ALT)); } //auto populate image fields if selected image if(wym._selected_image) { - $j(wym._options.dialogImageSelector + " " + wym._options.srcSelector) - .val($j(wym._selected_image).attr(WYM_SRC)); - $j(wym._options.dialogImageSelector + " " + wym._options.titleSelector) - .val($j(wym._selected_image).attr(WYM_TITLE)); - $j(wym._options.dialogImageSelector + " " + wym._options.altSelector) - .val($j(wym._selected_image).attr(WYM_ALT)); + jQuery(wym._options.dialogImageSelector + " " + wym._options.srcSelector) + .val(jQuery(wym._selected_image).attr(WYM_SRC)); + jQuery(wym._options.dialogImageSelector + " " + wym._options.titleSelector) + .val(jQuery(wym._selected_image).attr(WYM_TITLE)); + jQuery(wym._options.dialogImageSelector + " " + wym._options.altSelector) + .val(jQuery(wym._selected_image).attr(WYM_ALT)); } - $j(wym._options.dialogLinkSelector + " " + jQuery(wym._options.dialogLinkSelector + " " + wym._options.submitSelector).click(function() { - var sUrl = $j(wym._options.hrefSelector).val(); + var sUrl = jQuery(wym._options.hrefSelector).val(); if(sUrl.length > 0) { wym._exec(WYM_CREATE_LINK, sStamp); //don't use jQuery.find() see #JQ1143 - //var link = $j(wym._doc.body).find("a[@href=" + sStamp + "]"); + //var link = jQuery(wym._doc.body).find("a[@href=" + sStamp + "]"); var link = null; var nodes = wym._doc.body.getElementsByTagName(WYM_A); for(var i=0; i < nodes.length; i++) { - if($j(nodes[i]).attr(WYM_HREF) == sStamp) { - link = $j(nodes[i]); + if(jQuery(nodes[i]).attr(WYM_HREF) == sStamp) { + link = jQuery(nodes[i]); break; } } if(link) { link.attr(WYM_HREF, sUrl); - link.attr(WYM_TITLE, $j(wym._options.titleSelector).val()); + link.attr(WYM_TITLE, jQuery(wym._options.titleSelector).val()); } } window.close(); }); - $j(wym._options.dialogImageSelector + " " + jQuery(wym._options.dialogImageSelector + " " + wym._options.submitSelector).click(function() { - var sUrl = $j(wym._options.srcSelector).val(); + var sUrl = jQuery(wym._options.srcSelector).val(); if(sUrl.length > 0) { wym._exec(WYM_INSERT_IMAGE, sStamp); //don't use jQuery.find() see #JQ1143 - //var image = $j(wym._doc.body).find("img[@src=" + sStamp + "]"); + //var image = jQuery(wym._doc.body).find("img[@src=" + sStamp + "]"); var image = null; var nodes = wym._doc.body.getElementsByTagName(WYM_IMG); for(var i=0; i < nodes.length; i++) { - if($j(nodes[i]).attr(WYM_SRC) == sStamp) { - image = $j(nodes[i]); + if(jQuery(nodes[i]).attr(WYM_SRC) == sStamp) { + image = jQuery(nodes[i]); break; } } if(image) { image.attr(WYM_SRC, sUrl); - image.attr(WYM_TITLE, $j(wym._options.titleSelector).val()); - image.attr(WYM_ALT, $j(wym._options.altSelector).val()); + image.attr(WYM_TITLE, jQuery(wym._options.titleSelector).val()); + image.attr(WYM_ALT, jQuery(wym._options.altSelector).val()); } } window.close(); }); - $j(wym._options.dialogTableSelector + " " + jQuery(wym._options.dialogTableSelector + " " + wym._options.submitSelector).click(function() { - var iRows = $j(wym._options.rowsSelector).val(); - var iCols = $j(wym._options.colsSelector).val(); + var iRows = jQuery(wym._options.rowsSelector).val(); + var iCols = jQuery(wym._options.colsSelector).val(); if(iRows > 0 && iCols > 0) { var table = wym._doc.createElement(WYM_TABLE); var newRow = null; var newCol = null; - var sCaption = $j(wym._options.captionSelector).val(); + var sCaption = jQuery(wym._options.captionSelector).val(); //we create the caption var newCaption = table.createCaption(); @@ -1477,40 +1477,40 @@ } //append the table after the selected container - var node = $j(wym.findUp(wym.container(),WYM_MAIN_CONTAINERS)).get(0); - if(!node || !node.parentNode) $j(wym._doc.body).append(table); - else $j(node).after(table); + var node = jQuery(wym.findUp(wym.container(),WYM_MAIN_CONTAINERS)).get(0); + if(!node || !node.parentNode) jQuery(wym._doc.body).append(table); + else jQuery(node).after(table); } window.close(); }); - $j(wym._options.dialogPasteSelector + " " + jQuery(wym._options.dialogPasteSelector + " " + wym._options.submitSelector).click(function() { - var sText = $j(wym._options.textSelector).val(); + var sText = jQuery(wym._options.textSelector).val(); wym.paste(sText); window.close(); }); - $j(wym._options.dialogPreviewSelector + " " + jQuery(wym._options.dialogPreviewSelector + " " + wym._options.previewSelector) .html(wym.xhtml()); //cancel button - $j(wym._options.cancelSelector).mousedown(function() { + jQuery(wym._options.cancelSelector).mousedown(function() { window.close(); }); //pre-init functions - if($j.isFunction(wym._options.postInitDialog)) + if(jQuery.isFunction(wym._options.postInitDialog)) wym._options.postInitDialog(wym,window); }; /********** HELPERS **********/ // Returns true if it is a text node with whitespaces only -$j.fn.isPhantomNode = function() { +jQuery.fn.isPhantomNode = function() { if (this[0].nodeType == 3) return !(/[^\t\n\r ]/.test(this[0].data)); @@ -1526,7 +1526,7 @@ // Returns the Parents or the node itself // jqexpr = a jQuery expression -$j.fn.parentsOrSelf = function(jqexpr) { +jQuery.fn.parentsOrSelf = function(jqexpr) { var n = this; if (n[0].nodeType == 3) @@ -1628,7 +1628,7 @@ this._doc.title = this._wym._index; //init html value - $j(this._doc.body).html(this._wym._html); + jQuery(this._doc.body).html(this._wym._html); //handle events var wym = this; @@ -1655,13 +1655,13 @@ if(this._initialized) { //pre-bind functions - if($j.isFunction(this._options.preBind)) this._options.preBind(this); + if(jQuery.isFunction(this._options.preBind)) this._options.preBind(this); //bind external events this._wym.bindEvents(); //post-init functions - if($j.isFunction(this._options.postInit)) this._options.postInit(this); + if(jQuery.isFunction(this._options.postInit)) this._options.postInit(this); //add event listeners to doc elements, e.g. images this.listen(); @@ -1775,22 +1775,22 @@ this.enableDesignMode(); //pre-bind functions - if($j.isFunction(this._options.preBind)) this._options.preBind(this); + if(jQuery.isFunction(this._options.preBind)) this._options.preBind(this); //bind external events this._wym.bindEvents(); //bind editor keydown events - $j(this._doc).bind("keydown", this.keydown); + jQuery(this._doc).bind("keydown", this.keydown); //bind editor keyup events - $j(this._doc).bind("keyup", this.keyup); + jQuery(this._doc).bind("keyup", this.keyup); //bind editor focus events (used to reset designmode - Gecko bug) - $j(this._doc).bind("focus", this.enableDesignMode); + jQuery(this._doc).bind("focus", this.enableDesignMode); //post-init functions - if($j.isFunction(this._options.postInit)) this._options.postInit(this); + if(jQuery.isFunction(this._options.postInit)) this._options.postInit(this); //add event listeners to doc elements, e.g. images this.listen(); @@ -1814,16 +1814,18 @@ .replace(/<\/strong>/gi, ""); //update the html body - $j(this._doc.body).html(html); + jQuery(this._doc.body).html(html); //re-init designMode this.enableDesignMode(); } - else return($j(this._doc.body).html()); + else return(jQuery(this._doc.body).html()); }; WymClassMozilla.prototype._exec = function(cmd,param) { + if(!this.selected()) return(false); + switch(cmd) { case WYM_INDENT: case WYM_OUTDENT: @@ -1917,7 +1919,7 @@ //RETURN key //cleanup

between paragraphs - $j(wym._doc.body).children(WYM_BR).remove(); + jQuery(wym._doc.body).children(WYM_BR).remove(); } else if(evt.keyCode != 8 @@ -1991,12 +1993,12 @@ this.output += this.helper.tag(tag, attributes, true); }; - -WymClassMozilla.prototype.closeBlockTag = function(tag) -{ - this.output = this.output.replace(/
$/, '')+this._getClosingTagContent('before', tag)+""+this._getClosingTagContent('after', tag); -}; +WymClassMozilla.prototype.closeBlockTag = function(tag) +{ + this.output = this.output.replace(/
$/, '')+this._getClosingTagContent('before', tag)+""+this._getClosingTagContent('after', tag); +}; + WymClassMozilla.prototype.getTagForStyle = function(style) { if(/bold/.test(style)) return 'strong'; @@ -2050,22 +2052,22 @@ this.html(this._wym._html); //pre-bind functions - if($j.isFunction(this._options.preBind)) this._options.preBind(this); + if(jQuery.isFunction(this._options.preBind)) this._options.preBind(this); //hide indent and outdent until supported - $j(this._box).find(this._options.toolSelector + jQuery(this._box).find(this._options.toolSelector + '[@name=' + WYM_INDENT +']').hide(); - $j(this._box).find(this._options.toolSelector + jQuery(this._box).find(this._options.toolSelector + '[@name=' + WYM_OUTDENT +']').hide(); //bind external events this._wym.bindEvents(); //bind editor events - $j(this._doc).bind("keyup", this.keyup); + jQuery(this._doc).bind("keyup", this.keyup); //post-init functions - if($j.isFunction(this._options.postInit)) this._options.postInit(this); + if(jQuery.isFunction(this._options.postInit)) this._options.postInit(this); //add event listeners to doc elements, e.g. images this.listen();