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

window.opener question

Support forum for WYMeditor.

window.opener question

Postby n0ise on Mon May 05, 2008 7:53 pm

Hey ppl...

Here is what i did:
- I created a custom button that opens a new_window...
- In this new_window I have a list of pictures user can click on.
- Once user has clicked on an image -> window.opener is called...

This is where it stops. I can't get any further. If it's not obvious, I am trying to update the editor area from the child window.
I guess I'm not sure how to access the wym object from the child window...

Thanks in advance!
n0ise
 
Posts: 5
Joined: Sun May 04, 2008 10:10 pm

Re: window.opener question

Postby mr_lundis on Tue May 06, 2008 8:23 am

Take a look in the dialogue handling part of the WYM source to see how WYM handles dialogues internally. It might give you some hints!
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

Re: window.opener question

Postby n0ise on Tue May 06, 2008 3:32 pm

I'm looking at it and I just can't get it to work - feels like I have tryed everything. Google can't help me either since the editor is still not spread out...

Anyone has any idea here?
n0ise
 
Posts: 5
Joined: Sun May 04, 2008 10:10 pm

Re: window.opener question

Postby mr_lundis on Tue May 06, 2008 4:02 pm

You will find the dialogue handling here:
http://trac.wymeditor.org/trac/browser/ ... r.js#L1347

And here you have the image specific part:
http://trac.wymeditor.org/trac/browser/ ... r.js#L1423
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

Re: window.opener question

Postby n0ise on Tue May 06, 2008 6:07 pm

Thanks!
I'm not sure how to use that tho.

I made it work... kinda...

This is in the child window:
Code: Select all
var wym = window.opener.WYM_INSTANCES[0];
wym.paste('<img alt="test alt" title="test title" src="http://localhost/s/public/img/contents/logo.png" />');


It is working! Problem is that it does'nt place the image where i selected it... just makes a new paragraph. Is there any way to place the image in the right spot?
n0ise
 
Posts: 5
Joined: Sun May 04, 2008 10:10 pm

Re: window.opener question

Postby mr_lundis on Wed May 07, 2008 12:09 pm

This code should do the trick (I got most of it from the WYM source), but it's untested so I won't guarantee anything...

Code: Select all
var image,
    imageUrl = 'your/image.url',  // Replace these with our own
    imageTitle = 'imageTitle',
    imageAlt = 'imageAlt';
var wym = window.opener.WYM_INSTANCES[0];
var stamp = wym.uniqueStamp();

wym._exec(WYMeditor.INSERT_IMAGE, stamp);
image = jQuery(wym._doc.body).find("img[@src=" + stamp + "]");  // This should work using jQuery 1.2 and above
if(image) {
    image.attr(WYMeditor.SRC, imageUrl);
    image.attr(WYMeditor.TITLE, imageTitle);
    image.attr(WYMeditor.ALT, imageAlt);
}
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

Re: window.opener question

Postby n0ise on Sat May 10, 2008 5:54 am

Hi,

This looks promissing, but I'm getting an error on this line:
Code: Select all
wym._exec(WYMeditor.INSERT_IMAGE, stamp);
//Error: WYMeditor is not defined
n0ise
 
Posts: 5
Joined: Sun May 04, 2008 10:10 pm

Re: window.opener question

Postby n0ise on Sat May 10, 2008 6:33 am

Thanks man! Made it work with some minor changes... In case it can help someone, here is it:

Code: Select all
      var image,
         imageUrl = 'http://www.example.com/yoursite/img/logo.png',  // Replace these with our own
         imageTitle = 'imageTitle',
         imageAlt = 'imageAlt';
      var wym = window.opener.WYM_INSTANCES[0];
      var sStamp = wym.uniqueStamp();
      
      wym._exec(WYM_INSERT_IMAGE, sStamp);
      image = jQuery(wym._doc.body).find("img[@src=" + sStamp + "]");  // This should work using jQuery 1.2 and above

      if(image) {
         image.attr(WYM_SRC, imageUrl);
         image.attr(WYM_TITLE, imageTitle);
         image.attr(WYM_ALT, imageAlt);
      }
n0ise
 
Posts: 5
Joined: Sun May 04, 2008 10:10 pm

Re: window.opener question

Postby mr_lundis on Sat May 10, 2008 10:25 am

Oh, sorry! I forgot to mention that the code I posted above uses the new WYMeditor namespace, i.e. it won't work with a WYMeditor version lower than 0.5.
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