2004-09-20 22:40:50 +02:00
|
|
|
/**************************************************************************\
|
2004-09-28 23:06:25 +02:00
|
|
|
* eGroupWare - UploadImage-plugin for htmlArea in eGroupWare *
|
|
|
|
* http://www.eGroupWare.org *
|
|
|
|
* Written and (c) by Xiang Wei ZHUO <wei@zhuo.org> *
|
|
|
|
* Used code fragments from plugins by Mihai Bazon *
|
|
|
|
* Modified for eGW by and (c) by Pim Snel <pim@lingewoud.nl> *
|
|
|
|
* -------------------------------------------- *
|
|
|
|
* This program is free software; you can redistribute it and/or modify it *
|
|
|
|
* under the terms of the GNU General Public License as published by the *
|
|
|
|
* Free Software Foundation; version 2 of the License. *
|
|
|
|
\**************************************************************************/
|
|
|
|
|
|
|
|
// $Id$
|
2004-09-20 22:40:50 +02:00
|
|
|
|
|
|
|
// FIXME: clean up code
|
2004-04-21 21:52:49 +02:00
|
|
|
|
|
|
|
function UploadImage(editor) {
|
|
|
|
this.editor = editor;
|
|
|
|
|
|
|
|
var cfg = editor.config;
|
2004-09-28 23:06:25 +02:00
|
|
|
// cfg.fullPage = true;
|
2004-04-21 21:52:49 +02:00
|
|
|
var tt = UploadImage.I18N;
|
|
|
|
var self = this;
|
|
|
|
|
2004-09-28 23:06:25 +02:00
|
|
|
/* cfg.registerButton("UploadImage", tt["Upload Image"], editor.imgURL("up_image.gif", "UploadImage"), false,
|
|
|
|
function(editor, id) {
|
2004-06-15 02:27:03 +02:00
|
|
|
self.buttonPress(editor, id);
|
2004-09-28 23:06:25 +02:00
|
|
|
});
|
|
|
|
*/
|
2004-06-15 02:27:03 +02:00
|
|
|
cfg.registerButton("UploadImage", tt["Upload Image"], editor.imgURL("up_image.gif", "UploadImage"), false,
|
2004-09-28 23:06:25 +02:00
|
|
|
function(editor, id) {
|
|
|
|
self.buttonPress();
|
|
|
|
});
|
2004-04-21 21:52:49 +02:00
|
|
|
|
|
|
|
// add a new line in the toolbar
|
2004-06-15 02:27:03 +02:00
|
|
|
cfg.toolbar[0].splice(29, 0, "separator");
|
|
|
|
cfg.toolbar[0].splice(30, 0, "UploadImage");
|
2004-04-21 21:52:49 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
UploadImage._pluginInfo = {
|
2004-09-28 23:06:25 +02:00
|
|
|
name : "UploadImage for eGroupWare",
|
|
|
|
version : "1.0",
|
|
|
|
developer : "Pim Snel",
|
|
|
|
developer_url : "http://lingewoud.com",
|
|
|
|
c_owner : "Pim Snel, Xiang Wei ZHUO, Mihai Bazon",
|
|
|
|
sponsor : "Lingewoud bv., Netherlands",
|
|
|
|
sponsor_url : "http://lingewoud.com",
|
|
|
|
license : "GPL"
|
2004-04-21 21:52:49 +02:00
|
|
|
};
|
|
|
|
|
2004-09-28 23:06:25 +02:00
|
|
|
/*UploadImage.prototype.zzzbuttonPress = function(editor, id)
|
|
|
|
{
|
|
|
|
var self = this;
|
|
|
|
switch (id)
|
|
|
|
{
|
|
|
|
case "UploadImage":
|
|
|
|
var doc = editor._doc;
|
|
|
|
var links = doc.getElementsByTagName("link");
|
|
|
|
var style1 = '';
|
|
|
|
var style2 = '';
|
|
|
|
for (var i = links.length; --i >= 0;)
|
|
|
|
{
|
|
|
|
var link = links[i];
|
|
|
|
if (/stylesheet/i.test(link.rel))
|
|
|
|
{
|
|
|
|
if (/alternate/i.test(link.rel))
|
|
|
|
style2 = link.href;
|
|
|
|
else
|
|
|
|
style1 = link.href;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
var title = doc.getElementsByTagName("title")[0];
|
|
|
|
title = title ? title.innerHTML : '';
|
|
|
|
|
|
|
|
var init =
|
|
|
|
{
|
|
|
|
f_doctype : editor.doctype,
|
|
|
|
f_title : title,
|
|
|
|
f_body_bgcolor : HTMLArea._colorToRgb(doc.body.style.backgroundColor),
|
|
|
|
f_body_fgcolor : HTMLArea._colorToRgb(doc.body.style.color),
|
|
|
|
f_base_style : style1,
|
|
|
|
f_alt_style : style2,
|
|
|
|
|
|
|
|
editor : editor
|
|
|
|
};
|
2004-06-15 02:27:03 +02:00
|
|
|
|
2004-09-28 23:06:25 +02:00
|
|
|
Dialog(_editor_url+"plugins/UploadImage/popups/insert_image.php", function(image)
|
|
|
|
{
|
|
|
|
self._insertImage(image);
|
2004-06-15 02:27:03 +02:00
|
|
|
// self.setDocProp(params);
|
|
|
|
// alert(params[1]);
|
2004-09-28 23:06:25 +02:00
|
|
|
}, init);
|
2004-04-21 21:52:49 +02:00
|
|
|
|
|
|
|
/* editor._popupDialog("plugin://UploadImage/insert_image.php", function(params) {
|
2004-09-28 23:06:25 +02:00
|
|
|
self.setDocProp(params);
|
|
|
|
}, init);*/
|
2004-04-21 21:52:49 +02:00
|
|
|
|
2004-09-28 23:06:25 +02:00
|
|
|
/*break;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
*/
|
2004-06-15 02:27:03 +02:00
|
|
|
|
|
|
|
|
|
|
|
// Called when the user clicks on "InsertImage" button. If an image is already
|
|
|
|
// there, it will just modify it's properties.
|
2004-09-28 23:06:25 +02:00
|
|
|
UploadImage.prototype.buttonPress = function(image)
|
|
|
|
{
|
|
|
|
//var doc = editor._doc;
|
|
|
|
//var editor = this; // for nested functions
|
2004-06-15 02:27:03 +02:00
|
|
|
var outparam = null;
|
|
|
|
|
2004-09-28 23:06:25 +02:00
|
|
|
/* var init =
|
2004-06-15 02:27:03 +02:00
|
|
|
{
|
|
|
|
f_doctype : editor.doctype,
|
|
|
|
editor : editor
|
|
|
|
};
|
2004-09-28 23:06:25 +02:00
|
|
|
*/
|
|
|
|
/* if (typeof image == "undefined")
|
|
|
|
{
|
2004-06-15 02:27:03 +02:00
|
|
|
image = editor.getParentElement();
|
|
|
|
if (image && !/^img$/i.test(image.tagName))
|
|
|
|
image = null;
|
|
|
|
}
|
2004-09-28 23:06:25 +02:00
|
|
|
*/
|
|
|
|
Dialog(_editor_url+"plugins/UploadImage/popups/insert_image.php", function(param)
|
|
|
|
{
|
|
|
|
|
|
|
|
if (!param)
|
|
|
|
{
|
|
|
|
// user must have pressed Cancel
|
|
|
|
return false;
|
|
|
|
}
|
2004-06-15 02:27:03 +02:00
|
|
|
|
2004-09-28 23:06:25 +02:00
|
|
|
var img = image;
|
|
|
|
if (!img) {
|
2004-06-15 02:27:03 +02:00
|
|
|
var sel = editor._getSelection();
|
|
|
|
var range = editor._createRange(sel);
|
|
|
|
editor._doc.execCommand("insertimage", false, param.f_url);
|
2004-09-28 23:06:25 +02:00
|
|
|
|
2004-06-15 02:27:03 +02:00
|
|
|
if (HTMLArea.is_ie) {
|
2004-09-28 23:06:25 +02:00
|
|
|
img = range.parentElement();
|
|
|
|
|
|
|
|
// wonder if this works...
|
|
|
|
if (img.tagName.toLowerCase() != "img") {
|
|
|
|
img = img.previousSibling;
|
2004-06-15 02:27:03 +02:00
|
|
|
}
|
2004-09-28 23:06:25 +02:00
|
|
|
} else {
|
|
|
|
img = range.startContainer.previousSibling;
|
2004-06-15 02:27:03 +02:00
|
|
|
}
|
2004-09-28 23:06:25 +02:00
|
|
|
} else {
|
|
|
|
img.src = param.f_url;
|
2004-06-15 02:27:03 +02:00
|
|
|
}
|
2004-09-28 23:06:25 +02:00
|
|
|
for (field in param) {
|
|
|
|
var value = param[field];
|
|
|
|
switch (field) {
|
|
|
|
case "f_alt" : img.alt = value; break;
|
|
|
|
case "f_border" : img.border = parseInt(value || "0"); break;
|
|
|
|
case "f_align" : img.align = value; break;
|
|
|
|
case "f_vert" : img.vspace = parseInt(value || "0"); break;
|
|
|
|
case "f_horiz" : img.hspace = parseInt(value || "0"); break;
|
|
|
|
}
|
2004-06-15 02:27:03 +02:00
|
|
|
}
|
2004-09-28 23:06:25 +02:00
|
|
|
// alert('');
|
2004-06-15 02:27:03 +02:00
|
|
|
|
2004-09-28 23:06:25 +02:00
|
|
|
}, outparam);
|
2004-04-21 21:52:49 +02:00
|
|
|
};
|