warning, WALL OF TEXT AHEAD.
first of, I wasn't sure where to put this but I wanted to share so I hope this is the right place, and second I take no responsibility for anything that results from things I mention in this post
backup your files before editing anything, and don't try this in a production environment
Here's my scenario, I'm setting up a small community/blogging site for friends and family members, and not all of them are technically inclined so I wanted to make it simple to use yet have powerful features.
there are mainly three things I set out to accomplish:
* I wanted rich text editing
* I wanted to support inline images in said rich text box easily
* I wanted to prevent images from overflowing the theme.
what follows is how I accomplished all that and some more.
The Module versions I have:
Drupal 6.4
fckeditor-6.x-1.x-dev (Sep 17 12:05) with FCKeditor_2.6.3
imce-6.x-1.1
lightbox2-6.x-1.8
Rich Text Editing.
This was the easy part. I tried out various modules that offer it but it in the end FCKEditor was the one to suit my needs.
Installing that and tweaking is very simple, just follow the documentation. The only tweaks I did with FCKEditor was to add 2 new toolbar presets for users and anonymous.
but that was done with editing
{basedir}/sites/all/modules/fckeditor/fckeditor.config.js
and I added these two entries
FCKConfig.ToolbarSets["customUsers"] = [
['Bold','Italic','Underline','StrikeThrough','FontSize','-','TextColor','-','OrderedList','UnorderedList','-','Link','Unlink','-','Image','Flash','RemoveFormat']
];
FCKConfig.ToolbarSets["customAnon"] = [
['Bold','Italic','Underline','StrikeThrough','-','OrderedList','UnorderedList','-','Link','Unlink','RemoveFormat']
];and then I selected the new toolbars in the profiles for anonymous and logged in users and gave each role permission to use FCKEditor, voíla Rich Text Editing done.
Image functionality
This was the tricky part, and definitely the most time consuming.
Here's some of the things I wanted to do on the image front:
* browser can click on resized images to see the fullsize image
* users can upload images from their computer
* users can insert uploaded images into their text
* users can easily see where the picture is in their text
* users can adjust size of picture
The rest though not so simple, I think I looked at every possibility for this already out here and either they provided the function I needed but they didn't work for drupal 6.4 or FCKEditor or both, or they were just too troublesome and made things too complex.
In the end I decided to go with IMCE, it offered everything I needed although it isn't very simple to use for the less technically inclined, in addition it's hard to accomplish simple things you want to do and it's user interface is terribly cluttered, but outof all the other solutions it was the most straightforward method for the users; They just click the image icon in the Rich Text Editor, get an image dialog and then press "browse server" to get to the image browser where they can upload images and then select them and send back and then press OK.
but this combination only provided what I needed by requiring the user to make "complicated" changes, Like selecting a link url and typing in the custom class in the "Stylesheet Classes" box under "advanced". Things I didn't want the user to be required to do, so I decided to change the behavior of IMCE and FCKEditor to suit my needs.
But in order to do that I needed to pry into their source codes and take a look into their inner workings and do some modification.
I'm not an expert programmer, more like a novice one so there are probably much better ways to accomplish what I did, but at the least my changes can hopefully be of help to someone out there who is looking for similar solution to which I was looking for and if anyone can use this as a reference to make the functionality into features in respected modules, by all means do so.
There is a known problem with IMCE + FCKEditor + some version of drupal and firefox, where the IMCE browser doesnt show up and it's just a blank page. Unfortunately I don't remember exactly how i fixed it but if that problem happens to you just search the drupal site for the solution, thats how I fixed it. Just remember to clear your cache everytime you make a change to some code. I've cleared my cache so often I have ctrl-shift-delete (clear cache hotkey in firefox) in my muscle memory.
Modifying the source : Getting Lightbox to work automatically
Lets begin with the easiest one, getting images to work with Lightbox without the need to type anything in.
FCKEditor has a field where you can specify a custom class to use with an image, to use it you have to go to "advanced" tab and type the class into the "Stylesheet Classes" field. Now this isn't really helpful to the average user and FCKEditor doesn't offer any way (that I found) to have a default value in there. So we need to change that.
But first, define a custom class that triggers Lightbox, this is done in the admin page for Lightbox under the "automatic image handling" and then under "Custom Class Images", define a class to use, such as "myclass" or something. (Make sure you use plain text input box when defining it, otherwise it will be read as <p>text</p> if you use FCKEditor).
Then we need to do some modification to the source of FCKEditor.
open the "sites/all/modules/fckeditor/fckeditor/editor/dialog/fck_image.html" file and look for
<span fcklang="DlgGenClass">Stylesheet Classes</span><br />
<input id="txtAttClasses" style="width: 100%" type="text" />
You need to add a default value in the input box, so we add "value=""" somewhere in there, like this :
<span fcklang="DlgGenClass">Stylesheet Classes</span><br />
<input id="txtAttClasses" style="width: 100%" value="<CustomClassName>" type="text" />
Now everytime you press the image button, FCKEditor will already have placed your custom lightbox triggering class in the required field.
You should try it out, add a picture which has a link to an image set, and see if lightbox doesnt kick in. If it doesn't, make sure your class is the same as defined in Lightbox, and check how the code looks like in the "simple view", or otherwise just follow Lightbox troubleshooting lines.
Easiest part done, now for the more difficult things.
FCKEditor and IMCE : How on earth do they work together??
Since I didn't come anywhere near the development of either FCKEditor or IMCE I have no idea how they work, I had to do all my work by looking at the code and working backwards through it to find what made it tick. So I'm going to briefly explain my findings to you, so you have at least some understanding of what is going on. Which is better than to just blindly follow my guide.
IMCE Browser works by checking the variables which are used to launch it, and from them it knows what to do.
This is passed in the form of "app=applicationName|fileProperty1@FieldId1|fileProperty2@FieldId2 ... etc" Where app is the name of the application which is launching IMCE.
The File Properties that work in IMCE are :
* url
* name
* size(formatted)
* width
* height
* date(formatted)
* bytes(integer size in bytes)
* time(integer date timestamp)
And FCKEditor call IMCE with this string " ?q=imce&app=FCKEditor|url@txtUrl|width@txtWidth|height@txtHeight';\n"
I'll dissect this string.
-> app=FCKEditor -> Send data to this application (I have no idea how an application is designed and I didn't have a need to find out since my modification doesn't require it)
-> url@txtUrl -> This sends the url of the image to the form field called "txtUrl"
-> width@txtWidth -> This sends the width of the image to the form field called "txtWidth"
-> height@txtHeight -> This sends the height of the image to the form field "txtHeight"
Now, just by knowing this then shouldn't it be simple to fill out the link field automatically? by passing the url file property to the form field called txtLnkUrl. I wish it was that simple. IMCE can only send each property of the file ONCE to a field, so we can't for example use "|url@txtUrl|url@txtLnkUrl|" as an easy fix.
So, this is the very basics of how IMCE interacts with FCKEditor, Now... how do we make this work?.
Modifying the source : Changes to the FCKEditor module
First of all, we need a way to pass the "url" property to both the image url (txtUrl) and the link url (txtLnkUrl) form fields. I looked at many possibilities on how to accomplish this, like call IMCE with url@txtUrl+txtLnkUrl , url@txtUrl|url@txt-Url and some other. In the end I decided to go this way url@txtUrl|url2@txtLnkUrl|width ...etc .
The only thing we need to change with FCKEditor is how it calls IMCE, this is done in the sites/all/modules/fckeditor/fckeditor.module file in the line
$js .= $js_id .".Config['ImageBrowserURL']= '". $host ."?q=imce&app=FCKEditor|url@txtUrl|width@txtWidth|height@txtHeight';\n";
we just change this to
$js .= $js_id .".Config['ImageBrowserURL']= '". $host ."?q=imce&app=FCKEditor|url@txtUrl|url2@txtLnkUrl|width@txtWidth|height@txtHeight';\n";
and that's it, This is the only change required for FCKEditor itself, the rest is all done in IMCE.
Modifying the source : Changes to the IMCE module
Some information you require for my changes to work for you.
*I have 2 thumbnail presets. a 100x100 with the Suffix "_thumb" and another 400x400 with the suffix "_preview".
*I do not want to show pictures that are larger than 500x700 pixels so they won't mess with the theme.
We only need to do changes to one file in the IMCE Module, although they are some heavy changes.
I think it will just be easier if I just paste the entire modified code here with good comments that you can run through to see what I'm doing.
But here is an overview of what I'm doing:
* IMCE doesn't include a definition for url2 so it doesn't really know what to do with it and thus it is useless by itself. Fortunately IMCE parses all variables passed to it, so we just need to make url2 a copy of url, but send the data to the different form field.
* But I dont just want a simple link to the same image, if we are inserting a thumbnail or a preview I want the link to point to the full size image, So we are doing changes to the fileproperty for url2 to remove the _thumb and _preview suffixes.
* If a user selects the full size image, and it is bigger than 500x700 pixels I wan't to automatically resize it down to fit the 500x700 maximum dimension (while keeping aspect ratio)
My resize method is just really simple and I know it's not nearly perfect, but it does the job for me. It is not generating a new image. So if you have a picture that is 2000x2000 then it's size parameters are just changed to 500x500ish. I am told that imagecache will dynamically generate new pictures so that might be a better option to use, but there are some problems with imagecache and views so I can't use them and I dont have time to wait for fix and dont have the skills to fix it myself.
But on to my code, I am only commenting on changes that I made, I'm not adding comments to the original code.
The only file that needs editing is "sites/all/modules/imce/js/imce_set_app.js"
// $Id:imce_set_app.js,v 1.3.2.3 2008/07/13 11:23:51 ufku Exp $
//When imce url contains &app=appName|fileProperty1@correspondingFieldId1|fileProperty2@correspondingFieldId2|...
//the specified fields are filled with the specified properties of the selected file.
var appFields = {};
var strUrl;
// Lets define the maximum dimension an image can have
var strMaxHeight = 700;
var strMaxWidth = 500;
// to store the difference between actual size and maximum
var strHeightDifference;
var strWidthDifference;
// variables to check if an image is higher or wider than allowed
var isHigher;
var isWider;
// To know wether we should resize the image based on Height or Width
var isHeightBigger;
// How much should we shrink the image
var strResizeFactor;
// Should we do a resize
var doResize = 0;
//execute when imce loads.
imce.hooks.load.push(function(win) {
var data = decodeURIComponent(location.href.substr(location.href.lastIndexOf('app=')+4)).split('|');
var appname = data.shift();
for (var i in data) {
var arr = data[i].split('@');
appFields[arr[0]] = arr[1];
}
//set send to
imce.setSendTo(Drupal.t('Send to @app', {'@app': appname}), appFinish);
//highlight file
if (appFields['url']) {
var filename = $('#'+ appFields['url'], (top.appiFrm||win).opener.document).val();
imce.highlight(filename.substr(filename.lastIndexOf('/')+1));
}
});
//sendTo function
var appFinish = function(file, win) {
var win = top.appiFrm||win, doc = $(win.opener.document);
// Lets find out if the image is higher than allowed
if(file['height'] > strMaxHeight)
{
// Image is higher than allowed
isHigher = 1;
// Calculate difference
strHeightDifference = file['height'] - strMaxHeight;
// We need to resize image
doResize = 1;
// Debug alert ignore
// alert("height - strMaxHeight : "+strHeightDifference);
}
else
{
// Image is not higher
isHigher = 0;
}
// Let's find out if image is wider than allowed
if(file['width'] > strMaxWidth)
{
// Image is wider
isWider = 1;
// Calculate the difference
strWidthDifference = file['width'] - strMaxWidth;
// We need to resize image
doResize = 1;
// Debug alert ignore this
// alert("width - strMaxWidth: "+strWidthDifference);
}
else
{
// Image is not wider
isWider = 0;
}
// Debug alert ignore
// alert(" isHigher="+isHigher+" og isWider="+isWider);
// We need to calculate the resize factor
if(isHigher == 1 && isWider == 1)
{
// Both height and width are bigger than maximum allowed
// If image is both higher and wider than allowed we need to check
// Which difference is bigger so we can calculate the resize factor
// so that the aspect ratio is correct
// Debug alert ignore
// alert("Both are bigger");
// Let's check if Height difference is bigger than width difference
if(strHeightDifference > strWidthDifference)
{
// Height difference is bigger, so we need to calculate the resize
// Factor in relation to height
isHeightBigger = 1;
strResizeFactor = strMaxHeight / file['height'];
// Round the resizefactor to 1 decimal
strResizeFactor = Math.round(strResizeFactor*10)/10;
// Debug alert ignore
// alert("Height is bigger than width, resizefactor :"+strResizeFactor);
}
else
{
// Height difference is not bigger, so we need to calculate the resize
// Factor in relation to width
isHeightBigger = 0;
strResizeFactor = strMaxWidth / file['width'];
strResizeFactor = Math.round(strResizeFactor*10)/10;
// Debug alert ignore
// alert("Height is smaller than width , resize factor :"+strResizeFactor);
}
}
else if(isHigher == 1 && isWider == 0)
{
// If image is only higher than allowed we need to calculate
// the resize factor in relation to the height
strResizeFactor = strMaxHeight / file['height'];
strResizeFactor = Math.round(strResizeFactor*10)/10;
// Debug alert ignore
// alert("Height is only an issue ; /r/n resize factor :"+strResizeFactor);
}
else if(isHigher == 0 && isWider ==1)
{
// If image is only wider than allowed we need to calculate
// the resize factor in relation to the width
strResizeFactor = strMaxWidth / file['width'];
strResizeFactor = Math.round(strResizeFactor*10)/10;
// Debug alert ignore
// alert("Width is only an issue ; \r\n resize factor :"+strResizeFactor);
}
for (var i in appFields) {
// if we are parsing the 'url' property field, we need to make a duplicate of the
// url in the strUrl variable so we can use it with the url2 property field
if(i == 'url')
{
strUrl = file[i];
}
// If we are working with the 'url2' property field, we need to remove the
// _thumb and _preview suffixes to point the link to the original image
if(i == 'url2')
{
// Lets check to see if there is "_thumb" in the url
if(strUrl.indexOf("_thumb") > 0)
{
// Yup, this is a thumbnail so we need to remove "_thumb" from the url
strUrl = strUrl.replace("_thumb", "");
file[i] = strUrl;
// Debug alert ignore
// alert("image is thumbnail | new url:"+strUrl);
}
// let's check to see if there is a "_preview" in the url
else if(strUrl.indexOf("_preview") > 0)
{
// Yup, this is a preview, so we need to remove the _preview from the url
strUrl = strUrl.replace("_preview", "");
file[i] = strUrl;
// Debug alert ignore
// alert("image is preview | new url:"+strUrl);
}
else
{
// this is neither a thumbnail nor a preview, so we dont need to edit the url
file[i] = strUrl;
}
}
// Let's check to see if there is a need to change the size
if(i == 'width' && doResize == 1)
{
// we are working with the 'width' file property, and we need to change it
var newWidth = file[i] * strResizeFactor;
// Let's round it down so we don't end up with i.e. 120.23 and instead just get 120
newWidth = Math.round(newWidth);
// Debug alert ignore
// alert("old width="+file[i]+" | New width="+newWidth);
//
// Let's pass the new width to the form field instead of the old one
doc.find('#'+ appFields[i]).val(newWidth);
}
else if(i == 'height' && doResize ==1)
{
// we are working with the 'height' file property and we need to change it
var newHeight = file[i] * strResizeFactor;
// Let's round it down so we don't end up with i.e. 120.23 and instead just get 120
newHeight = Math.round(newHeight);
// Debug alert ignore
// alert("old height="+file[i]+" | new height="+newHeight);
//
// Let's pass the new width to the form field instead of the old one
doc.find('#'+ appFields[i]).val(newHeight);
}
else
{
// We are working with some other file property so we don't need to do anything
// Debug alert ignore
// alert("I'm doing this "+appFields[i]+" => "+file[i]);
doc.find('#'+ appFields[i]).val(file[i]);
}
// Originally the doc.find statement was outside the if statement, just leaving it commented out
// for future reference
// doc.find('#'+ appFields[i]).val(file[i]);
}
if (appFields['url']) {
try{doc.find('#'+ appFields['url']).blur().change().focus()}catch(e){};
try{doc.find('#'+ appFields['url']).trigger('onblur').trigger('onchange').trigger('onfocus')}catch(e){};//inline events
}
// I'm not sure exactly why this is needed, but this triggers some javascript events on the 'url2' form field,
// which in our case is the txtLnkUrl field, this is just a direct copy from the 'url' one except 'url'->'url2'
if (appFields['url2']) {
try{doc.find('#'+ appFields['url2']).blur().change().focus()}catch(e){};
try{doc.find('#'+ appFields['url2']).trigger('onblur').trigger('onchange').trigger('onfocus')}catch(e){};//inline events
}
win.opener.focus();
win.close();
};
There you have it.
Now the only thing users need to do to insert images is click the image button -> Browse server -> find or upload an image -> send it to FCKEditor and then press ok. Everything else is done automatically for them. Simple and efficient.
I just hope I didn't leave anything out in my guide, I've been doing this over a timespan of few days so it would be typical if I forgot something that makes this entire thing not work.
Comments
changes to the thumbnail generator
Also, I found that the default IMCE thumbnail generator is kinda messed up in Drupal 6,
so I used the code fix found in http://drupal.org/node/264382#comment-956604 to make it a little better.
It's not a perfect resolution to the thumbnail issue but close enough and it works for me.
just in case the link doesn't work, the code fix is basicly this.
find this string in the sites/all/modules/imce/inc/page.inc file
function imce_resize_image($filename, &$imce, $width, $height, $copy = TRUE, $dest = FALSE, $op = 'resize') {
then add the following code ABOVE the "//create file object" comment :
<?
if (substr($op, 0, 5) == 'scale') {
$aspect = $img['height'] / $img['width'];
if ($aspect < $img['height'] / $width) {
$width = (int)min($width, $img['width']);
$height = (int)round($width * $aspect);
}
else {
$height = (int)min($height, $img['height']);
$width = (int)round($height / $aspect);
}
}
?>
- Laxdal -
You are amazing :) Thank you
You are amazing :) Thank you very much for figuring this out. Hopefully the changes can be adapted into the modules themselves (lack of automatic lightbox ability has always been one disadvantage to IMCE, which like you I think is the "easiest to understand" tool for clients at the moment... I've had to settle for Image Assist for clients though since they love/must have the lightbox, but the moment I start talking about "just pasting in a class name here" their eyes glaze over... it's easier for them to endure the tedious too-much-info upload process and UI of Image Assist).
Again thanks! I'll try out your suggestions as soon as I get a chance. I'm trying to come up with a similar solution with BUEditor + IMCE... which I use for myself, since a little HTML's good for the soul haha :P
-- David
absolutecross.com
[new guide/lesson in progress: Creating a CCK and Views powered Drupal site - feedback welcome]
I've added a link to this
I've added a link to this page on http://drupal.org/node/252153 - the Lightbox2 documentation page on how to use Lightbox2 with FCKEditor and TinyMCE. Thanks for a great write-up.
Cheers,
Stella
If anybody has followed my
If anybody has followed my guide I'd like some comments on how it worked out for you.
thank you
- Laxdal -
I haven't followed your
I haven't followed your tutorial because I don't want to hack any modules.
But I'll comment on this:
> getting images to work with Lightbox without the need to type anything in...
> FCKEditor has a field where you can specify a custom class to use with an image,
> to use it you have to go to "advanced" tab and type the class into the "Stylesheet
> Classes" field. Now this isn't really helpful to the average user and FCKEditor doesn't
> offer any way (that I found) to have a default value in there
First I edited fckeditor.config.js to add the 'Style' dropdown to the interface.
This is really useful anyway- I managed to get rid of several buttons by making
styles for them instead, which means my toolbar only takes up one line now.
Then I copied fckstyles.xml to my theme folder. This over-rides the module's own one.
I added a lightbox style:
'lightbox' is setup as a custom trigger in the lightbox module settings.
So when a (small) image is inserted and then aligned left or right using
the style dropdown, the lightbox class is automatically applied.
IMO, if an author can't manually do the next stage (linking the small image
to the original larger image), then they have no business using the lightbox
feature anyway. I'm certainly not going to hack modules just to save users
from simply copy/pasting a url and deleting the -th postfix.
My main issue is how to get rid of all the other unnecessary advanced
tabs and options in the fckeditor. IMO, they are far more confusing.
Why force them to do it when you dont have to?
>IMO, if an author can't manually do the next stage (linking the small image
>to the original larger image), then they have no business using the lightbox
>feature anyway. I'm certainly not going to hack modules just to save users
>from simply copy/pasting a url and deleting the -th postfix.
Why force them to do it when you dont have to?
It's much more userfriendly if it's done automatically. :P
- Laxdal -
> Why force them to do it
> Why force them to do it when you dont have to?
> It's much more user friendly if it's done automatically. :P
The automatic method might suit some people; I'm not saying don't do it.
But it does cause an extra headache every time imce/fck modules are updated.
If we hacked even just a few of our add on modules like this, we'd soon be in deep
water trying to re-apply all our hacks during updating, trying to figure out whether
the old hack still works with the upgraded module.
Plus, usually small images accompanying content are quite generic snapshots - not
usually 'arty' enough to be worth viewing in full size. The automatic lightbox method
means users will have to go to the 'link' field to delete the url of many images that
they *don't* want lightboxed.
The most difficult part of the process, IMO, is trying to get users to understand why they
need to type 'lightbox' into the advanced -> stylesheet class field. By making that part
automatic when the image is aligned, then it is much easier for users to just link their
small image to a large image if they then want it lightboxed.
I posted the info just so that people who didn't want to hack the modules could at least
get halfway, and because the OP said they didn't know how to get the lightbox trigger
class into the stylesheet field without typing it or hacking the module.
All (accurate) information is good! It increases peoples' choices.
I have a problem with imce_set_app.js
This is a terrific post and just what I have been trying to achieve for a while now. I have spent sometime trying to implement what you have described and all goes well until I replace the code in imce_set_app.js with the code in your post. The Send to FCKEditor button is missing from the Browser window and when I select an image and then click on it in the IMCE Browser it opens a browser tab and displays the image in a browser tab.
I have worked and reworked this and I am unable to understand where I have gone wrong.
I would appreciate it if you could perhaps give me some pointers on where I could start looking for the cause of my problem.
I have a question as well - I can see that your changes will cope with the display of a single image in Lightbox but does it also allow for grouped images or a slideshow?
Regards
Martin Fuggle
> The Send to FCKEditor
> The Send to FCKEditor button is missing from the Browser window and when I select an
> image and then click on it in the IMCE Browser it opens a browser tab and displays the
> image in a browser tab.
This is a wide-spread issue with IMCE. You'll find it documented on the 'fckeditor' and
'IMCE cck image' module project pages, as well as in the IMCE project page itself.
No-one seems to know the cause, and the IMCE developer is no longer maintaining the
module, but has said they'll be back sometime in 2009.
The issue seems to be 'triggered' by different things. For instance:
· installing modules which interact with IMCE, such as fckeditor, tinymce, or 'IMCE cck image'
· upgrading your browser
· updating IMCE
· drupal cache/performance settings
But no-one has pin-pointed the problem yet, or the solution.
In my case, I had the symptoms you describe for a week in all my browsers, until one day it
started working again for 'no apparent reason', except in Opera, where the problem persists.
Thanks for the
Thanks for the information.
I'll see if there is anyway that I can diagnose the problem. If I could get it to work I could then make changes until it stops working and that may give us a lead into the cause. Problem is I can't get it to work at the moment!
Regards
Martin Fuggle
>I have spent sometime
>I have spent sometime trying to implement what you have described and all goes well until I replace the code in imce_set_app.js
>with the code in your post.
So IMCE + FCKEditor work when you use imce_set_app.js unmodified?
>The Send to FCKEditor button is missing from the Browser window
I didn't run into this issue.
> and when I select an image and then click on it in the IMCE Browser it opens a browser tab and displays the image in a browser tab.
I however ran into this problem, or a similiar problem. This happened when there was some error in my code, so check to see if everything is identical
Or you can simply download my imce_set_app.js file and replace it entirely.
http://dev.laxdal.org/stuff/imce_set_app.js
Also make sure your using the same version of the modules as I am :)
- Laxdal -
Thanks for the replies. Yes
Thanks for the replies.
Yes IMCE + FCKEdtor work fine when I use imce_set_app.js unmodified. The problem only starts when I use the modified code.
I'll download the latest code and compare with what I am using and see if that resolves the issue.
Regards
Martin Fuggle
Everything works now that I
Everything works now that I have downloaded the version of imce_set_app.js in your latest post. I haven't tried to see what the diffs are - after all it now works!
Cheers
Martin Fuggle
compared them both
I've compared both editions and I can't see where it should be wrong.
Althou I do see that I have <? and ?> in the post, but these are not in the original. I think placed those in there to get the fancy colouring effects,
could it be that you added those in your code the first time?
- Laxdal -
different approach
This was a very interesting approach, thank you for sharing! I may combine some of those tricks with what I did to address this...
FWIW, I took a different route. I saw my standard usage scenario as: "User uploaded photos to Picasa or Photobucket or Flickr. (Could also upload with IMCE.) Task is to generate alt text & caption & enter two image URLs (thumbnail and target) and open in Lightbox." I also set the lightbox "group" to "page" for all lightboxes, so by default you step through all lightboxed images on the page, regardless of what form you're viewing comments / posts in. (So, page + all visible comments, or all lightboxes in a page of "Recent comments", or...)
I did this by modifying the FCKEditor "Image Insert/Edit" dialog & code.
I'm not so up on how to cleanly modify a module, and this change spanned several files (js, html). If anyone's interested, a zip kit is at: http://gingerbooth.com/ginger/ftp/fckeditorLightbox.zip
And my site using this system is : http://aerogardenmastery.com (need to register to add comments, though.)
What version of FCKeditor?
What version of FCKeditor was your modification for? I am using v2.5.1, but the editor window would not appear.
What version of FCKeditor
I have FCKeditor_2.6.3 and fckeditor-6.x1.3-rc3.
Sorry for the slow response!
Hi, if you don't already
Hi, if you don't already perhaps you should consider requesting to join documentation team. (http://drupal.org/node/23367). That is, if this isn't already apart of any handbook.
Stuff like that would be very helpful
Brilliant - thanks. one problem though (lightbox popup)
Thanks for this guide - it is exactly what I needed and is much appreciated.
I have an issue though - everything works as advertised except if I add a thumbnail through fckeditor and publish the post/page, clicking the thumbnail triggers the lightbox, but populates it with the same thumbnail. I have tried inserting other sizes and the lightbox always shows the same dimension. choosing "view image details" works fine, however.
I can live with this, but am wondering where I may have missed something.
my modules are all the same versions as the guide, but I am on Drupal 6.6. Also, I had to use the provided .js file from the comments as the cut and paste didn't work for me either.
Thanks in advance, and great work!
I would love this
I would love this
Adding Lightbox to my IMCE + FCKEDITOR
Only problem....and a big one Updating is almost a daily thing.
The interest in Drupal is growing very fast.
I make it a point now to search module projects by date, because so much new stuff is coming out daily.
I would have a site full of problems in short order, if I started hacking my module code.
Currently, I have nine Drupal sites and several others planned.
I really do appreciate the effort put into this hack, since I use IMCE on all sites.
I'll have to wait until someone decides to take this as a project for a module.
The mod could have double duty as well.
The new image browser module works similar to IMCE with FCKeditor when you click on thumbnail it has choices for full views, but no lightbox.
I now only use completed modules.
If I have to use any code hack I keep a document folder with the installation carefully explaining any small code changes.
Site preservation I call it. I really don't mind it either, there is so much good stuff coming our way daily... I'm thrilled there is so much interest in Drupal.
My sites are more full featured and users love'em.
Thanks to all
it works for me but I had
it works for me but I had trouble b/c I forgot to remove the php tags lol.
However, does anyone know how to modify the imce code to set the checkboxes for thumbnail and preview to be default turned on?
Very interesting, but i have
Very interesting, but i have decided to use a different method (which gives a result not so bad...)
On the fckeditor website, i have found that there's a patch allowing us to add the rel attribute (aka Link Relationship) to the fckeditor advanced tab.
It is just the modification of 2 files of the fckeditor (just a few lines).
You can simply put there the rel attribute you want (lightbox....) and everything works fine.
Anyway, here is the link to the patch : http://dev.fckeditor.net/attachment/ticket/2627/fck-rel.patch
I hope it helps some of you
Regards
I recently upgraded one of my
I recently upgraded one of my sites to Drupal 6.9 and updated the modules related to this little hack to :
FCKeditor - WYSIWYG HTML editor 6.x-1.x-dev (2009-Feb-20)
IMCE 6.x-1.2
Lightbox2 6.x-1.9
And reapplied my hack. The steps are still the same for Lightbox/FCKEditor but there are some changes required for the IMCE part.
You still need to edit the same file as before, or : sites/all/modules/imce/js/imce_set_app.js
I'll just paste the entire content of the changed file here, since It's probably easier to use than me telling you what to paste and where to paste it :)
and for conveniance I commented where the changed code begins and ends.
I hope this can help somebody who was using my hack and was wanting to upgrade.
// Let the Pasting begin
// $Id: imce_set_app.js,v 1.3.2.6 2009/02/20 21:17:25 ufku Exp $
//When imce url contains &app=appName|fileProperty1@correspondingFieldId1|fileProperty2@correspondingFieldId2|...
//the specified fields are filled with the specified properties of the selected file.
var appFields = {}, appWindow = (top.appiFrm||window).opener;
// CUSTOM CHANGE BEGINS
var strUrl;
// Lets define the maximum dimension an image can have
var strMaxHeight = 700;
var strMaxWidth = 500;
// to store the difference between actual size and maximum
var strHeightDifference;
var strWidthDifference;
// variables to check if an image is higher or wider than allowed
var isHigher;
var isWider;
// To know wether we should resize the image based on Height or Width
var isHeightBigger;
// How much should we shrink the image
var strResizeFactor;
// Should we do a resize
var doResize = 0;
var strWidth;
var strHeight;
// CUSTOM CHANGE ENDS
//execute when imce loads.
imce.hooks.load.push(function(win) {
var data = decodeURIComponent(location.href.substr(location.href.lastIndexOf('app=')+4)).split('|');
var appName = data.shift();
//extract fields
for (var i in data) {
var arr = data[i].split('@');
appFields[arr[0]] = arr[1];
}
//run custom onload function if available.
if (appFields['onload'] && $.isFunction(appWindow[appFields['onload']])) {
appWindow[appFields['onload']](win);
delete appFields['onload'];
}
//set custom sendto function. appFinish is the default.
var sendtoFunc = appFields['url'] ? appFinish : false;
//check sendto@funcName syntax in URL
if (appFields['sendto'] && $.isFunction(appWindow[appFields['sendto']])) {
sendtoFunc = appWindow[appFields['sendto']];
delete appFields['sendto'];
}
//check windowname+ImceFinish. old method
else if (win.name && $.isFunction(appWindow[win.name +'ImceFinish'])) {
sendtoFunc = appWindow[win.name +'ImceFinish'];
}
//highlight file
if (appFields['url']) {
if (appFields['url'].indexOf(',') > -1) {//support multiple url fields url@field1,field2..
var arr = appFields['url'].split(',');
for (var i in arr) {
if ($('#'+ arr[i], appWindow.document).size()) {
appFields['url'] = arr[i];
break;
}
}
}
var filename = $('#'+ appFields['url'], appWindow.document).val();
imce.highlight(filename.substr(filename.lastIndexOf('/')+1));
}
//set send to
if (sendtoFunc) {
imce.setSendTo(Drupal.t('Send to @app', {'@app': appName}), sendtoFunc);
}
});
//sendTo function
var appFinish = function(file, win) {
var doc = $(appWindow.document);
// CUSTOM CHANGE START
// Loop through the values to place them in variables
for (var i in appFields) {
if(appFields[i] == 'txtUrl'){
strUrl = file[i];
}else if(appFields[i] == 'txtWidth'){
strWidth = file[i];
}else if(appFields[i] == 'txtHeight'){
strHeight = file[i];
}
}
// Let's begin by constructing the url2 url, by stripping the _thumb and preview from it
if(strUrl.indexOf("_thumb") > 0){
strUrl = strUrl.replace("_thumb", "");
}else if(strUrl.indexOf("_preview") > 0){
strUrl = strUrl.replace("_preview", "");
}
// Change the url2 url to the new value
file['url2'] = strUrl;
//----------------
// IF YOU DON'T WANT THE CSS SIZE CHANGE SKIP THIS STEP
//----------------
// Lets find out if the image is higher than allowed
if(strHeight > strMaxHeight)
{
// Image is taller than allowed
isHigher = 1;
// Calculate difference
strHeightDifference = strHeight - strMaxHeight;
// We need to resize image
doResize = 1;
// Debug alert ignore
alert("height - strMaxHeight : "+strHeightDifference);
}
else
{
// Image is not higher
isHigher = 0;
}
// Let's find out if image is wider than allowed
if(strWidth > strMaxWidth)
{
// Image is wider
isWider = 1;
// Calculate the difference
strWidthDifference = strWidth - strMaxWidth;
// We need to resize image
doResize = 1;
// Debug alert ignore this
// alert("width - strMaxWidth: "+strWidthDifference);
}
else
{
// Image is not wider
isWider = 0;
}
// Debug Alert - ignore this
//alert("higher : " + isHigher);
//alert("wider : "+ isWider);
// We need to calculate the resize factor
if(isHigher == 1 && isWider == 1)
{
// Both height and width are bigger than maximum allowed
// If image is both higher and wider than allowed we need to check
// Which difference is bigger so we can calculate the resize factor
// so that the aspect ratio is correct
// Debug alert ignore
// alert("Both are bigger");
// Let's check if Height difference is bigger than width difference
if(strHeightDifference > strWidthDifference)
{
// Height difference is bigger, so we need to calculate the resize
// Factor in relation to height
isHeightBigger = 1;
strResizeFactor = strMaxHeight / strHeight;
// Round the resizefactor to 1 decimal
strResizeFactor = Math.round(strResizeFactor*10)/10;
// Debug alert ignore
// alert("Height is bigger than width, resizefactor :"+strResizeFactor);
}
else
{
// Height difference is not bigger, so we need to calculate the resize
// Factor in relation to width
isHeightBigger = 0;
strResizeFactor = strMaxWidth / strWidth;
strResizeFactor = Math.round(strResizeFactor*10)/10;
// Debug alert ignore
// alert("Height is smaller than width , resize factor :"+strResizeFactor);
}
}
else if(isHigher == 1 && isWider == 0)
{
// If image is only higher than allowed we need to calculate
// the resize factor in relation to the height
strResizeFactor = strMaxHeight / strHeight;
strResizeFactor = Math.round(strResizeFactor*10)/10;
// Debug alert ignore
// alert("Height is only an issue ; /r/n resize factor :"+strResizeFactor);
}
else if(isHigher == 0 && isWider ==1)
{
// If image is only wider than allowed we need to calculate
// the resize factor in relation to the width
strResizeFactor = strMaxWidth / strWidth;
strResizeFactor = Math.round(strResizeFactor*10)/10;
// Debug alert ignore
// alert("Width is only an issue ; \r\n resize factor :"+strResizeFactor);
}
if(doResize == 1){
alert("Old width: "+ strWidth);
strWidth = strWidth * strResizeFactor;
strWidth = Math.round(strWidth);
alert("New width: "+strWidth);
alert("Old Height: "+strHeight);
strHeight = strHeight * strResizeFactor;
strHeight = Math.round(strHeight);
alert("New height: "+strHeight);
file["width"] = strWidth;
file["height"] = strHeight;
}
//----------------
// CUSTOM CHANGE ENDS
for (var i in appFields) {
doc.find('#'+ appFields[i]).val(file[i]);
// alert("i : "+i+" | AppFields[i] : "+appFields[i]+" | file[i] : "+file[i]);
}
if (appFields['url']) {
try{doc.find('#'+ appFields['url']).blur().change().focus()}catch(e){};
try{doc.find('#'+ appFields['url']).trigger('onblur').trigger('onchange').trigger('onfocus')}catch(e){};//inline events
}
appWindow.focus();
win.close();
};
wow! thank you very much!!!
wow! thank you very much!!! :D
I've only commented some alerts:
alert("Old width: "+ strWidth);
alert("New width: "+strWidth);
alert("Old Height: "+strHeight);
alert("New height: "+strHeight);
ah snap..
looks like I forgot to comment out those debug alerts :)
No fckeditor.module with Wysiwyg
Warning: this is my first post here and I'm a newbie so be gentle...
I had been working to get lightbox to work with IMCE and TinyMCE when I came across this excellent solution...exactly what I wanted to accomplish. Since it seems you have updated to Wysiwyg with FCKeditor, I decided to start with your updated version of the IMCE hack. I have made all the changes except I cannot find fckeditor.module in the Wysiwyg version. My versions seem to match yours but I may be missing something here.
Should this work with the versions I have? If so, where do I place changes to FCKeditor Module? Or should I abandon Wysiwyg and stick with FCKeditor?
Drupal 6.9
Wysiwyg 6.x-1.1
FCKeditor 2.6.4
IMCE 6.x-1.2
IMCE Wysiwyg API bridge 6.x-1.0
Lightbox2 6.x-1.9
Many, many thanks for your work on this...I gotta make it work!
Warren
wow, thank you!
wow, thank you!
It seems to not work anymore
It seems to not work anymore with the actual versions of FCKeditor / IMCE / Drupal...
Did anyone succeeded to do it ?
EDIT : ok sorry, it works... it was just a problem with the cache ;) Thanks !
That's what I needed! Thank
That's what I needed!
Thank you so much.
how to delete image properly
Hi,
markup in the 'source' of the wysiwig. Has anyone experienced the same problem? thanks!
Using this method, if you delete an image there is some residual
Put this in module?
Is it possible to make a new module for imce, that will make this functionality ?
Also i heard that it is possible to creat a newfile.js with this hack code instead of hacking imce file. If this is true? than it would be a great choice.
How I got CKEditor + IMCE + Lightbox + WYSIWYG to "just work"
http://drupal.org/node/1002110#comment-4112474