We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 19889
    • 616 Posts
    Hello

    I’m looking for some help from a FCKeditor guru - I’m having problems to get the editor instance into my plugin script - while the same script works with tinyMCE, Xinha, SPAW, and HTMLarea, it doesn’t work in FCKeditor.

    Could anybody please help and let me know what’s wrong?

    
    	//-------------------------------------------------------------------------
    	// tinyMCE editor - open iBrowser
    	var FCKibrowser = function(name) { ?
    		this.Name = name;		
    	} ?
    	// manage the plugins' button behavior ?
    	FCKibrowser.prototype.GetState = function() { ?
    		return FCK_TRISTATE_OFF; ?
    	} ?
    	 
    	FCKCommands.RegisterCommand('ibrowser', new FCKibrowser('ibrowser')) ; ?
    	 
    	// Create the toolbar button. 
    	var oibrowserItem = new FCKToolbarButton( 'ibrowser', "ibrowser", null, null, false, true ) ; 
    	//oiBrowserItem.IconPath = FCKConfig.PluginsPath + 'ibrowser/images/ibrowser.gif' ;
    	oibrowserItem.IconPath = '/dev/wysiwyg/plugins/ibrowser/images/ibrowser.gif' ; 
    	FCKToolbarItems.RegisterItem( 'ibrowser', oibrowserItem ) ; ? 
    	FCKibrowser.prototype.Execute = function() { ?
    		iBrowser_click(FCK,null)	
    	}
    	//-------------------------------------------------------------------------
    	// global variables
    	var ib = new Object;
    	//-------------------------------------------------------------------------
    	// tinyMCE editor - init iBrowser
    	function iBrowser_click(editor) {
    		ib.isMSIE = (navigator.appName == 'Microsoft Internet Explorer');
    		ib.isGecko = navigator.userAgent.indexOf('Gecko') != -1;
    		//DumpObject(window.frames['eEditorArea']);
    		ib.oEditor = window.frames['eEditorArea'];
    		DumpObject(ib.oEditor);
    		ib.editor = editor;		
    		ib.selectedElement = getSelectedElement();
    		ib.baseURL = '/dev/wysiwyg/plugins/ibrowser/ibrowser.php';
    		iBrowser_open(); // starting iBrowser
    	}
    	//-------------------------------------------------------------------------
    	// open iBrowser
    	function iBrowser_open() {		
    		ib.oEditor.contentWindow.focus();
    		var wArgs = {};
    		var elm = ib.selectedElement;
    		if (elm != null) { // if element
    			if (elm.nodeName.toLowerCase() == 'img') { // selected object is image				
    				var oImageElement ? = elm;
    				var oLinkElement ? ?= oImageElement.parentNode.nodeName.toLowerCase() == 'a' ? oImageElement.parentNode : null;
    				var oCaptionElement = oImageElement.nextSibling ? (oImageElement.nextSibling.nodeType == 3 ? oImageElement.nextSibling.parentNode : oImageElement.nextSibling) : null;
    				getImgParam(oImageElement, wArgs); // set image parameters				)
    				if (oLinkElement) { // set popup parameters					
    					var oCaptionElement = oLinkElement.nextSibling ? (oLinkElement.nextSibling.nodeType == 3 ? oLinkElement.nextSibling.parentNode : oLinkElement.nextSibling) : null;
    					getLinkParam(oLinkElement, wArgs);
    				}				
    			} else if (elm.nodeName.toLowerCase() == 'a') { // selected object is link
    				var oLinkElement ? ?= elm;
    				var oImageElement ? = oLinkElement.childNodes[0].nodeName.toLowerCase() == 'img' ? oLinkElement.childNodes[0] : null;
    				var oCaptionElement = oLinkElement.nextSibling ? (oLinkElement.nextSibling.nodeType == 3 ? oLinkElement.nextSibling.parentNode : oLinkElement.nextSibling) : null;
    				getLinkParam(oLinkElement, wArgs); // set popup parameters
    				if (oImageElement) { // if first child is image					
    					getImgParam(oImageElement, wArgs); // set image parameters
    				}
    			} else if (elm.nodeName.toLowerCase() == 'div') { // selected element is div				
    				var oCaptionElement = elm.lastChild ? (elm.lastChild.nodeType == 3 ? elm.lastChild.parentNode : elm.lastChild) : null;
    				if (isCaption(oCaptionElement)) { // check to see whether it is a caption element					
    					if (elm.childNodes[0].nodeName.toLowerCase() == 'img') {
    						var oImageElement = elm.childNodes[0];
    						getImgParam(oImageElement, wArgs);
    					} else if (elm.childNodes[0].nodeName.toLowerCase() == 'a') {
    						var oLinkElement ?= elm.childNodes[0];
    						var oImageElement = oLinkElement.childNodes[0].nodeName.toLowerCase() == 'img' ? oLinkElement.childNodes[0] : null;
    						getLinkParam(oLinkElement, wArgs); // set popup parameters
    						if (oImageElement) { // if first child is image							
    							getImgParam(oImageElement, wArgs); // set image parameters	
    						}
    					}					
    				}
    			// selected element is paragraph			
    			} else if (elm.nodeName.toLowerCase() == 'p') {	
    				var oCaptionElement = elm ? (elm.nodeType == 3 ? elm.parentNode : elm) : null;				
    				if (isCaption(oCaptionElement)) { // check to see whether it is a caption element				
    					if (oCaptionElement.previousSibling.nodeName.toLowerCase() == 'img') {						
    						var oImageElement = oCaptionElement.previousSibling;						
    						getImgParam(oImageElement, wArgs);
    					} else if (oCaptionElement.previousSibling.nodeName.toLowerCase() == 'a') {
    						var oLinkElement = oCaptionElement.previousSibling;
    						var oImageElement = oLinkElement.childNodes[0].nodeName.toLowerCase() == 'img' ? oLinkElement.childNodes[0] : null;
    						getLinkParam(oLinkElement, wArgs); // set popup parameters
    						if (oImageElement) { // if first child is image						
    							getImgParam(oImageElement, wArgs); // set image parameters					
    						}
    					}
    				}
    			}
    			//-------------------------------------------------------------------------
    			// set caption argument				
    			isCaption(oCaptionElement) ? wArgs.caption = 1 : '';
    		}		
    		//-------------------------------------------------------------------------
    		// open iBrowser dialog		
    		if (ib.isMSIE) { // IE
    			var rArgs = showModalDialog(ib.baseURL, wArgs, 'dialogHeight:500px; dialogWidth:580px; scrollbars: no; menubar: no; toolbar: no; resizable: no; status: no;'); ?
    			if (rArgs) { // returning from iBrowser (IE) and calling callback function				
    				iBrowser_callback('','',rArgs);
    			}
    		} else if (ib.isGecko) { // Gecko 
    			var wnd = window.open(ib.baseURL + '?editor=' + ib.editor + '&callback=iBrowser_callback', 'ibrowser', 'status=no, modal=yes, width=625, height=530');
    			wnd.dialogArguments = wArgs;
    		}
    	}
    	//-------------------------------------------------------------------------
    	// iBrowser callback
    	function iBrowser_callback(editor, sender, iArgs) {		
    		if (iArgs) { // IE			
    			var rArgs = iArgs;
    		} else { // Gecko
    			var rArgs = sender.returnValue;
    		}
    		ib.oEditor.contentWindow.focus();
    		var elm = ib.selectedElement;	
    		if (elm != null) {
    			if (elm.nodeName.toLowerCase() == 'img') { // is current cell a image ?
    				var oImageElement = elm;
    			}
    			if (elm.nodeName.toLowerCase() == 'a') { // is current cell a link ?
    				var oLinkElement = elm;
    			}
    			if (elm.nodeName.toLowerCase() == 'div') { // is current cell a div ?
    				if (elm.childNodes[0].nodeName.toLowerCase() == 'img') {				
    					var oImageElement = elm.childNodes[0];					
    				}
    			}
    			if (elm.nodeName.toLowerCase() == 'p' && elm.getAttribute('class') == 'caption') { // is current cell a div ?
    				if (elm.previousSibling.nodeName.toLowerCase() == 'img') {				
    					var oImageElement = elm.previousSibling;					
    				}
    			}
    		}
    		
    		if (rArgs) {
    			if (!rArgs.action) { // no action set - image				
    				if (!oImageElement) { // new image// no image - create new image
    					//ib.oEditor.document.execCommand('insertimage', false, rArgs.src);
    					ib.oEditor.contentWindow.document.execCommand('insertimage', false, rArgs.src);
    					oImageElement = getElementByAttributeValue(ib.oEditor.contentWindow.document, 'img', 'src', rArgs.src);		
    				}
    				
    				// set image attributes
    				setAttrib(oImageElement, 'src', rArgs.src, true);				
    				setAttrib(oImageElement, 'alt', rArgs.alt, true);
    				setAttrib(oImageElement, 'title', rArgs.title, true);
    				setAttrib(oImageElement, 'align', rArgs.align, true);
    				setAttrib(oImageElement, 'border', rArgs.border);
    				setAttrib(oImageElement, 'hspace', rArgs.hspace);
    				setAttrib(oImageElement, 'vspace', rArgs.vspace);
    				setAttrib(oImageElement, 'width', rArgs.width);
    				setAttrib(oImageElement, 'height', rArgs.height);				
    				ib.isMSIE ? setAttrib(oImageElement, 'className', rArgs.className, true) : setAttrib(oImageElement, 'class', rArgs.className, true);
    				
    				// set caption
    				if (oImageElement.parentNode.nodeName.toLowerCase() == 'a') { // popup image
    					var oLinkElement = oImageElement.parentNode;
    					setCaption(oLinkElement,rArgs.caption,oImageElement.getAttribute('title'));
    				} else {
    					setCaption(oImageElement,rArgs.caption,oImageElement.getAttribute('title'));
    				} 
    			} else if (rArgs.action == 1) { // action set - image popup								
    				if (oLinkElement) { // edit exiting popup link								
    					a.href ? ? ? ?= "javascript:void(0);";
    					rArgs.popSrc ?= escape(rArgs.popSrc);					
    					setAttrib(oLinkElement, 'title', rArgs.popTitle, true);
    					setAttrib(oLinkElement, 'className', rArgs.popClassName, true);						
     ? ? ? 				setAttrib(oLinkElement, 'onclick', "window.open('" + rArgs.popUrl + "?url=" + rArgs.popSrc + '&clTxt=' + rArgs.popTxt + "','Image', 'width=500, height=300, scrollbars=no, toolbar=no, location=no, status=no, resizable=yes, screenX=100, screenY=100'); return false;", true);
    
    				} else { // create new popup link		
    					var oLinkElement = ib.oEditor.contentWindow.document.createElement('A');
    					oLinkElement.href = "javascript:void(0)";
    					rArgs.popSrc ?= escape(rArgs.popSrc);				
    					setAttrib(oLinkElement, 'title', rArgs.popTitle, true);
    					ib.isMSIE ? setAttrib(oLinkElement, 'className', rArgs.popClassName, true) : setAttrib(oLinkElement, 'class', rArgs.popClassName, true);										
    					setAttrib(oLinkElement, 'onclick', "window.open('" + rArgs.popUrl + "?url=" + rArgs.popSrc + '&clTxt=' + rArgs.popTxt + "','Image', 'width=500, height=300, scrollbars=no, toolbar=no, location=no, status=no, resizable=yes, screenX=100, screenY=100'); return false;", true);
    					
    					if (ib.isMSIE) { // IE
    						 if (elm.nodeName.toLowerCase() == 'div' || elm.nodeName.toLowerCase() == 'img' || elm.nodeName.toLowerCase() == 'p') {								
    							if (elm.lastChild && elm.lastChild.className == 'caption') {
    								oLinkElement.innerHTML = elm.firstChild.outerHTML;
    								elm.firstChild.outerHTML = oLinkElement.outerHTML;
    							} else if (elm.nodeName.toLowerCase() == 'img') {
    								oLinkElement.innerHTML = elm.outerHTML;
    								elm.outerHTML = oLinkElement.outerHTML;
    							} else if (elm.nodeName.toLowerCase() == 'p' && elm.className == 'caption') {
    								elm = elm.previousSibling;
    								oLinkElement.innerHTML = elm.outerHTML;
    								elm.outerHTML = oLinkElement.outerHTML;
    							}
    						} else {
    							var rng = this.selectedInstance.contentDocument.selection.createRange();
    							if (rng.text == '') {								
    								oLinkElement.innerHTML = '#';
    							} else {
    								oLinkElement.innerHTML = rng.htmlText;								
    							}
     ? ? ? ? ? ? ? ? ? ? ?		rng.pasteHTML(oLinkElement.outerHTML);							
    						}
    					} else if (ib.isGecko) { // Gecko
    						var sel = ib.oEditor.contentWindow.getSelection();						
    						if (sel.rangeCount > 0 && sel.getRangeAt(0).startOffset != sel.getRangeAt(0).endOffset) {
    							oLinkElement.appendChild(sel.getRangeAt(0).cloneContents());
    						} else {							
    							oLinkElement.innerHTML = '#';
    						} ? ? ? ?
    						insertNodeAtSelection(ib.oEditor.contentWindow, oLinkElement);
    					}
    				}
    			//-------------------------------------------------------------------------
    			} else if (rArgs.action == 2) { // action set - delete popup link				
    				this.selectedInstance.contentDocument.execCommand('Unlink');								
    			}
    		}
    		//tinyMCE.triggerNodeChange();
    		return;
     ?	}	
    	//-------------------------------------------------------------------------
    	// set image attributes
    	function getImgParam(oImageElement, wArgs) {
    		var tsrc = oImageElement.src;
    		if (tsrc.lastIndexOf('?') >= 0) { // dynamic thumbnail or random image				
    			var str = tsrc.substring(tsrc.lastIndexOf('?')+1, tsrc.length);
    			firstIndexOf ? 	= str.indexOf('&');
    			if (tsrc.lastIndexOf('?src') >= 0) {
    				wArgs.src ?	= str.substring(4, firstIndexOf); // image part of src
    				wArgs.tsrc 	= tsrc; // full src incl. dynamic parameters
    			} else if (tsrc.lastIndexOf('?dir') >= 0) { // random image				
    				wArgs.rsrc 	= tsrc; // full url
    				wArgs.rlib 	= str.substring(4,firstIndexOf); // image library for random picture
    				wArgs.rset 	= str.substring(firstIndexOf, str.lenght); // random parameter string
    			}
    		} else { // regular image
    			wArgs.src = tsrc;
    		}
    		
    		wArgs.alt 			= oImageElement.alt;
    		wArgs.title 		= oImageElement.title;
    		if (!wArgs.rsrc) { // if not random picture
    			wArgs.width 	= oImageElement.style.width ?? oImageElement.style.width ?: oImageElement.width;
    			wArgs.height 	= oImageElement.style.height ? oImageElement.style.height : oImageElement.height;
    		}
    		wArgs.border 		= oImageElement.border;
    		wArgs.align 		= oImageElement.align;
    		if (oImageElement.hspace >= 0) { // (-1 when not set under gecko for some reason)
    			wArgs.hspace ? ?= oImageElement.attributes['hspace'].nodeValue;
    		}
    		if (oImageElement.vspace >= 0) { // // (-1 when not set under gecko for some reason)
    			wArgs.vspace ? ?= oImageElement.attributes['vspace'].nodeValue;
    		}	
    		wArgs.className 	= oImageElement.className;	
    		return wArgs;		
    	}
    	//-------------------------------------------------------------------------
    	// set popup link attributes
    	function getLinkParam(oLinkElement, wArgs) {		
    		wArgs.a = oLinkElement;
    		var str = oLinkElement.getAttribute('onclick') ? oLinkElement.attributes['onclick'].value : oLinkElement.attributes['mce_onclick'].value;		
    		wArgs.popSrc = unescape(str.substring(str.indexOf('?url=')+5, str.indexOf('&')));	// popup image src			
    		wArgs.popTitle ? ? = oLinkElement.title;
    		wArgs.popClassName = oLinkElement.className;
    		return wArgs;
    	}
    	//-------------------------------------------------------------------------
    	// set image caption
    	function setCaption(elm,chkCaption, caption) {
    		if (chkCaption == 1) { // set caption
    			var doc = ib.oEditor.contentWindow.document;
    			if (elm.nextSibling && elm.nextSibling.getAttribute('class') == 'caption') { // existing caption
    				var newtext = elm.nextSibling.firstChild.nodeValue.replace(elm.nextSibling.firstChild.nodeValue,caption);
    				elm.nextSibling.firstChild.nodeValue = newtext;
    			} else { // new caption
    				var capDiv = doc.createElement('div');
    				ib.isMSIE ? setAttrib(capDiv, 'className', 'capDiv', true) : setAttrib(capDiv, 'class', 'capDiv', true);				
    				var capText = doc.createElement('p');
    				ib.isMSIE ? setAttrib(capText, 'className', 'caption', true) : setAttrib(capText, 'class', 'caption', true);
    				capText.appendChild(doc.createTextNode(caption));
    				capDiv.appendChild(capText); ? ? ? ? ? ? ? ? ? ? ? ?
    				elm.parentNode.appendChild(capDiv);
    				capDiv.insertBefore(elm, capDiv.firstChild);
    			}
    		} else { // no caption set - if caption, remove it ? ? ? ?
    			if (elm.nextSibling && elm.nextSibling.className == 'caption') { ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?
    				var parent = elm.parentNode; ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?
    				parent.parentNode.replaceChild(elm, elm.parentNode); ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?
    			};
    		}
    	}
    	//-------------------------------------------------------------------------
    	// check if caption
    	function isCaption(elm) {
    		if (elm && elm.className == 'caption') {
    			return true;
    		}
    		return false;
    	}
    	//-------------------------------------------------------------------------
    	// get selected element (focus element)
    	function getSelectedElement() {		
    		if (ib.isMSIE) {
    			var sel = ib.oEditor.contentWindow.document.selection;
    			var rng = sel.createRange();		
    			if (sel.type != "Control") {
    				return (rng.parentElement());
    			} else {
    				return (rng(0)); ? ?
    			}
    		} else if (ib.isGecko) {
    			var elm = null;
    			var sel = ib.oEditor.contentWindow.getSelection();		
    			if (sel && sel.rangeCount > 0) {
    				var rng = sel.getRangeAt(0);
    				elm = rng.startContainer;
    				if (elm.nodeType != 1) {
    					elm = elm.parentNode;
    				}
    			}
    			return elm;
    		}
    	}
    	//-------------------------------------------------------------------------
    	// get element by attribute value
    	function getElementByAttributeValue(node, element_name, attrib, value) {
    		var elements = getElementsByAttributeValue(node, element_name, attrib, value);
    		if (elements.length == 0) {
    			return null;
    		}
    		return elements[0];
    	};
    	//-------------------------------------------------------------------------
    	// get elements by attribute value
    	function getElementsByAttributeValue(node, element_name, attrib, value) {
    		var elements = new Array();
    		if (node && node.nodeName.toLowerCase() == element_name) {
    			if (node.getAttribute(attrib) && node.getAttribute(attrib).indexOf(value) != -1) {
    				elements[elements.length] = node;
    			}
    		}
    	
    		if (node.hasChildNodes) {
    			for (var x=0, n=node.childNodes.length; x<n; x++) {
    				var childElements = getElementsByAttributeValue(node.childNodes[x], element_name, attrib, value);
    				for (var i=0, m=childElements.length; i<m; i++) {
    					elements[elements.length] = childElements[i];
    				}
    			}
    		}
    		return elements;
    	};
    	//-------------------------------------------------------------------------
    	// set attributes
    	function setAttrib(element, name, value, fixval) {
    		if (!fixval && value != null) {
    			var re = new RegExp('[^0-9%]', 'g');
    			value = value.replace(re, '');
    		}
    		if (value != null && value != '') {
    			element.setAttribute(name, value);
    		} else {
    			element.removeAttribute(name);
    		}
    	}
    	//-------------------------------------------------------------------------
    	
    	function DumpObject(obj) {
     ? ? var s = '';
     ? ? for (var i in obj) {
     ? ? ? ? ?s += i +': '+obj[i]+"\n";
     ? ? }
     ? ? alert(s);
     }
    
    
      • 34162
      • 1 Posts
      I’m sorry Idont have an answer for your question.

      I really like fck editor the best but it is very finicky and loads very funny in firefox and is affected by the extensions your have installed. For thsi reason for now I’m sticking with tinymce. You mention that you have thsi working with tiny mce. Do you happen ot have the plugin anyplace. I have downloaded the imanager and ibrowser from your site do those work by jsut droping them into the tinymce plugins folder?
        • 19889
        • 616 Posts
        the two plugins basically work just by dropping them into a subdir - give it a try - installation should be fairly easy.

        As to FCKeditor, I think I got a little closer - getting the editor like this: ib.oEditor = document.getElementById(’eEditorArea’); seems to work - if anybody has a better way, please let me know.