Forum closed. New forum available at http://community.wymeditor.org/

Creating a gallery inserting script

Support forum for WYMeditor.

Creating a gallery inserting script

Postby Pezmc on Wed Mar 11, 2009 2:23 pm

I am planning on writing a script that uses PHP and Javascript to insert images to WYMeditor. My plan is for the PHP to search in a preset folder for all images, display them in a table and have each of the images clickable to be inserted into WYMeditor. I am happy to make it public when finished. I am however stuck at how to get the links in the popup to insert images into WYMeditor (interact with the original window).

So far I have got (the \'s are as it is in PHP, just ignore them):
var html = '<li class=\"wym_tools_gallery\">'
+ '<a href=\"#\"'
+ ' title=\"Add image from gallery\"'
+ ' style=\"background-image:'
+ ' url(wymeditor/skins/default/icons.png)\">'
+ 'Add image from gallery'
+ '</a></li>';
jQuery(wym._box)
.find(wym._options.toolsSelector + wym._options.toolsListSelector)
.append(html);

jQuery(wym._box)
.find('li.wym_tools_gallery a').click(function() {
alert('Test');
g_window = window.open('gallery.php', 'filebrowser', 'height=600,width=840,resizable=yes,scrollbars=yes');
g_window.focus();
return(false);
});

Does anyone know with javascript how to get a link on the gallery.php page to close the window (gallery page) and insert content to wymeditor? I am stuck with the interacting through javascript.
Pezmc
 
Posts: 7
Joined: Fri Mar 06, 2009 6:23 pm

Re: Creating a gallery inserting script

Postby mr_lundis on Wed Mar 11, 2009 2:55 pm

Hi!

The method window.open() returns a reference to the window object for the newly created pop-up. This window object (the pop-up) has a property called opener, which points back to the window whom initially spawned the pop-up (the "parent").

An example:
Code: Select all
popup = window.open('gallery.php', 'filebrowser', 'height=600,width=840,resizable=yes,scrollbars=yes');

// Current window == window opener
document.window == popup.opener

// Same pop-up
popup == popup.opener.popup

From the pop-up's window object you can then modify it's content, populate/read any forms etc. And when you're done you can close the window by calling window.close() from inside the pop-up, or popup.close() from the parent window.

Cheers!
Jonatan Lundin - designer, developer and forum moderator. You should follow me on Twitter!
mr_lundis
 
Posts: 335
Joined: Sun Dec 02, 2007 10:59 am
Location: Sweden


Return to Support

Who is online

Users browsing this forum: No registered users and 2 guests