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

How to insert an image _without_ being wrapped in a <p>?

Support forum for WYMeditor.

How to insert an image _without_ being wrapped in a <p>?

Postby tilzinger on Mon Apr 12, 2010 12:49 am

I'm adding a custom image browser, and everything is working great, but when the image is inserted back into the editor, it's always wrapped with a <p> tag. Anyone know how to disable this?
tilzinger
 
Posts: 10
Joined: Fri Mar 26, 2010 7:36 pm

Re: How to insert an image _without_ being wrapped in a <p>?

Postby mr_lundis on Mon Apr 12, 2010 5:30 pm

You can append or prepend it to the body or insert it before or after the element which the cursor/caret's in - the currently "selected" element:
Code: Select all
var wym = $.wymeditors(0);

// After the selected element
var elem = wym.selected();
$('<img>', wym._doc).insertAfter(elem);

// or appending to the body
$('<img>', wym._doc).appendTo(wym._doc.body);


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

Re: How to insert an image _without_ being wrapped in a <p>?

Postby tilzinger on Wed Apr 14, 2010 1:31 am

Thanks. It works, but as soon as I hit Enter to go to the next line, thus creating a new <p>, it wraps the image in a <p> automatically. Anyway to avoid this?
tilzinger
 
Posts: 10
Joined: Fri Mar 26, 2010 7:36 pm

Re: How to insert an image _without_ being wrapped in a <p>?

Postby christracy123 on Wed Apr 21, 2010 6:05 am

When adding an image to the page from the file browser it automatically gets wrapped in "<p>" tags. I think you cant avoid it
Being stressed out and overweight may not be YOUR fault! It's true, a mysterious condition might be to blame. An estimated 70-80% are suffering from this condition, and don't even know it!

http://www.howtocurecandida.com/survey/
christracy123
 
Posts: 6
Joined: Sat Jan 23, 2010 6:04 am

Re: How to insert an image _without_ being wrapped in a <p>?

Postby mr_lundis on Wed Apr 21, 2010 4:41 pm

tilzinger wrote:Thanks. It works, but as soon as I hit Enter to go to the next line, thus creating a new <p>, it wraps the image in a <p> automatically. Anyway to avoid this?

I'll need to look into this, I don't have any obvious solution...
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: How to insert an image _without_ being wrapped in a <p>?

Postby tilzinger on Sat Apr 24, 2010 10:43 pm

Is there part of the code in which this auto wrapping of <p> tags happens? I've been through the source, but I couldn't find what was causing this. If you can point me in the right direction, I can possible figure it out.
tilzinger
 
Posts: 10
Joined: Fri Mar 26, 2010 7:36 pm

Re: How to insert an image _without_ being wrapped in a <p>?

Postby mr_lundis on Sun Apr 25, 2010 1:09 pm

Tilzinger, take a look at the keydown/-up handler in each of the different browser classes. It's the wym._exec(WYMeditor.FORMAT_BLOCK, WYMeditor.P)-part that wraps everything up in paragraphs.

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