You are not logged in.
Pages: 1
Hello
I was wondering whether there is anybody who as a few minutes to take a look at a plugin script - Have been working on it for hours but cannot get it to work.
any help is appreciated.
can't get anywhere - this really drives me nuts!
This is what I came up so far:
function ibrowser(editor) {
this.editor = editor;
var cfg = editor.config;
var self = this;
cfg.registerButton ({
id : "ibrowser",
tooltip : "iBrowser",
image : _editor_url + 'plugins/ibrowser/images/ibrowser.gif',
textMode : false,
action : function(editor) {
self.buttonPress(editor);
}
})
cfg.addToolbarElement("ibrowser", "inserthorizontalrule", 1);
};
ibrowser._pluginInfo = {
name : "ibrowser",
version : "1.1",
developer : "Marco M. Jaeger",
developer_url : "http://net4visions.com/",
license : "GPL"
};
ibrowser.prototype.buttonPress = function(editor) {
var editor = this; // for nested functions
//-------------------------------------------------------------------------
var wArgs = {};
var str;
if (editor.selectedElement != null) {
if(editor.selectedElement.nodeName.toLowerCase() == 'img') { // selected object is image
if(editor.selectedElement.parentNode.nodeName.toLowerCase() == 'a') {
var a = editor.selectedElement.parentNode;
} else {
var im = editor.selectedElement;
}
} else if (editor.selectedElement.nodeName.toLowerCase() == 'a') { // selected object is link
var a = editorselectedElement;
}
}
//-------------------------------------------------------------------------
if (a) { // selected object is link
wArgs.a = a;
if (HTMLArea.is_ie) { // IE
str = a.outerHTML;
} else if (HTMLArea.is_gecko) { // Gecko
//get outerHTML
var str = "<a";
for (var i = 0; i < a.attributes.length; i++) {
if (a.attributes[i].specified)
str += " " + editor.convertStringToXML(a.attributes[i].name) + '="' + editor.convertStringToXML(a.attributes[i].value) + '"';
}
str += ">" + a.innerHTML + "</a>";
}
str = str.substring(str.indexOf('?'), str.indexOf(',') -1);
str = str.substring(str.indexOf('=') +1, str.length);
str = unescape(str);
firstIndexOf = str.indexOf('=');
if (firstIndexOf >= 0) {
str = str.substring(firstIndexOf +1, str.indexOf('&'));
}
wArgs.popSrc = str; // popup image src
wArgs.popTitle = a.title;
wArgs.popClassName = a.className;
// set image popup properties
children = (a.childNodes);
for (var i = 0; i < children.length; i++) {
if (children[i].tagName == 'IMG') {
wArgs.src = children[i].src;
wArgs.alt = children[i].alt;
wArgs.title = children[i].title;
wArgs.width = children[i].style.width ? children[i].style.width : children[i].width;
wArgs.height = children[i].style.height ? children[i].style.height : children[i].height;
wArgs.border = children[i].border;
wArgs.align = children[i].align;
wArgs.hspace = children[i].hspace;
wArgs.vspace = children[i].vspace;
wArgs.className = children[i].className;
}
}
//-------------------------------------------------------------------------
} else if (im) { // selected object is image
wArgs.src = im.src;
wArgs.alt = im.alt;
wArgs.title = im.title;
wArgs.width = im.style.width ? im.style.width : im.width;
wArgs.height = im.style.height ? im.style.height : im.height;
wArgs.border = im.border;
wArgs.align = im.align;
wArgs.className = im.className;
if (im.hspace >= 0) {
// (-1 when not set under gecko for some reason)
wArgs.hspace = im.attributes['hspace'].nodeValue;
}
if (im.vspace >= 0) {
// (-1 when not set under gecko for some reason)
wArgs.vspace = im.attributes['vspace'].nodeValue;
}
}
//-------------------------------------------------------------------------
// open iBrowser dialog
if (HTMLArea.is_ie) { // IE
var rArgs = showModalDialog(_editor_url + '/plugins/ibrowser/ibrowser.php', wArgs, 'dialogHeight:500px; dialogWidth:580px; scrollbars: no; menubar: no; toolbar: no; resizable: no; status: no;');
//-------------------------------------------------------------------------
// returning from iBrowser (IE) and calling callback function
if (rArgs) {
iBrowser_callback(editor, null, rArgs);
}
} else if (HTMLArea.is_gecko) { // Gecko
var wnd = window.open(_editor_url + '/plugins/ibrowser/ibrowser.php' + '?editor=' + editor + '&callback=iBrowser_callback', 'ibrowser', 'status=no, modal=yes, width=625, height=530');
wnd.dialogArguments = wArgs;
}
//-------------------------------------------------------------------------
// iBrowser callback
function iBrowser_callback(editor, sender, iArgs) {
var ed = editor._doc;
ed.contentWindow.focus();
if (iArgs) { // IE
var rArgs = iArgs;
} else { // Gecko
var rArgs = sender.returnValue;
}
if (editor.selectedElement != null && editor.selectedElement.nodeName.toLowerCase() == 'img') { // is current cell a image ?
var im = editor.selectedElement;
}
if (HTMLArea.selectedElement != null && HTMLArea.selectedElement.nodeName.toLowerCase() == 'a') { // is current cell a link ?
var a = editor.selectedElement;
}
if (rArgs) {
if (!rArgs.action) { // no action set - image
if (!im) { // new image// no image - create new image
this.selectedElement = getFocusElement(editor, sender);
this.selectedInstance = ed;
this.selectedInstance.contentDocument.execCommand('insertimage', false, rArgs.src);
im = this.getElementByAttributeValue(this.selectedInstance.contentDocument.body, 'img', 'src', rArgs.src);
}
// set image attributes
setAttrib(im, 'src', rArgs.src, true);
setAttrib(im, 'alt', rArgs.alt, true);
setAttrib(im, 'title', rArgs.title, true);
setAttrib(im, 'align', rArgs.align, true);
setAttrib(im, 'border', rArgs.border);
setAttrib(im, 'hspace', rArgs.hspace);
setAttrib(im, 'vspace', rArgs.vspace);
setAttrib(im, 'width', rArgs.width);
setAttrib(im, 'height', rArgs.height);
setAttrib(im, 'className', rArgs.className, true);
} else if (rArgs.action == 1) { // action set - image popup
if (a) { // edit popup
a.href = "javascript:void(0);";
rArgs.popSrc = escape(rArgs.popSrc);
setAttrib(a, 'title', rArgs.popTitle, true);
setAttrib(a, 'className', rArgs.popClassName, true);
if (HTMLArea.is_ie) { // IE
a.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;";
} else if (HTMLArea.is_gecko) { // Gecko
a.setAttribute("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;");
}
} else { // create new popup
var a;
a = document.createElement('A');
a.href = "javascript:void(0)";
rArgs.popSrc = escape(rArgs.popSrc);
setAttrib(a, 'title', rArgs.popTitle, true);
setAttrib(a, 'className', rArgs.popClassName, true);
if (HTMLArea.is_ie) { // IE
a.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;";
if (ed.contentWindow.document.selection.type == 'Control') {
var selection = ed.contentWindow.document.selection.createRange();
a.innerHTML = selection(0).outerHTML;
selection(0).outerHTML = a.outerHTML;
} else {
var selection = ed.contentWindow.document.selection.createRange();
if (selection.text == '') {
a.innerHTML = '#';
} else {
a.innerHTML = selection.htmlText;
selection.pasteHTML(a.outerHTML);
}
selection.pasteHTML(a.outerHTML);
}
} else if (HTMLArea.is_gecko) { // Gecko
a.setAttribute("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;");
if (ed.contentWindow.getSelection().rangeCount > 0 && ed.contentWindow.getSelection().getRangeAt(0).startOffset != ed.contentWindow.getSelection().getRangeAt(0).endOffset) {
a.appendChild(ed.contentWindow.getSelection().getRangeAt(0).cloneContents());
} else {
a.innerHTML = '#';
}
insertNodeAtSelection(ed.contentWindow, a);
}
}
//-------------------------------------------------------------------------
} else if (rArgs.action == 2) { // action set - delete popup link
ed.contentDocument.execCommand('Unlink');
}
}
return;
}
//-------------------------------------------------------------------------
function getFocusElement(editor, sender) {
var ed = editor._doc;
var sel = '' + (window.getSelection ? ed.contentWindow.getSelection() : document.getSelection ? ed.contentWindow.document.getSelection() : ed.contentWindow.document.selection.createRange().text);
var elm = (sel && sel.anchorNode) ? sel.anchorNode : null;
if (ed.selectedElement != null && ed.selectedElement.nodeName.toLowerCase() == "img") {
elm = ed.selectedElement;
}
return elm;
}
//-------------------------------------------------------------------------
HTMLArea.prototype.getInstanceById = function(editor_id) {
var inst = this.instances[editor_id];
alert(inst);
if (!inst) {
for (var instanceName in HTMLArea.instances) {
var instance = HTMLArea.instances[instanceName];
if (instance.formTargetElementId == editor_id) {
inst = instance;
break;
}
}
}
return inst;
};
}
Last edited by mmjaeger (2005-05-14 01:56:41)
Offline
post your code here, i can take a look at it and others perhaps too
Niko
Offline
anybody helping?
Offline
Pages: 1