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

Get HTML of Selection? Or HTML with Selection marked?

Discuss features, code, contributions, ideas, suggestions, ...
For bugs, patches and feature requests, please post on the Trac:
http://trac.wymeditor.org/

Get HTML of Selection? Or HTML with Selection marked?

Postby ithoughts_de on Fri May 22, 2009 2:49 pm

Is it in any way possible to get the selection including HTML?

OR BETTER

It there a way of getting the content of the editor with all HTML formatting and the selection wrapped by some HTML-Tag like span oder a? Something like <a class"selected">selected content from the <strong>WYMeditor</strong> area</a> .... this would make it easy to change content using jQuery. I need this for integrating RDFa - please help :-)
ithoughts_de
 
Posts: 4
Joined: Tue Apr 28, 2009 2:30 pm

Re: Get HTML of Selection? Or HTML with Selection marked?

Postby ithoughts_de on Wed May 27, 2009 12:42 am

Solved the problem this way for the gecko-engine (for my work it just needs to be fine in one browser after all):

Code: Select all
// get Selection
var sel = wym._iframe.contentWindow.getSelection();
// do we have a selection?
if (sel.focusNode != null){
    var range = sel.getRangeAt(0);
    var container = range.commonAncestorContainer; //for example <p> or <h1>
    var span = document.createElement('span');
    // make all kinds of AJAX-weirdness and put superb rdfa-attributes on the span
    range.surroundContents(span);
}


This would also greatly increase the wrap-function and many other stuff ... even though I think it might not be crossbrowser. Hope jQuery simplifies selections and ranges some day ;-)
ithoughts_de
 
Posts: 4
Joined: Tue Apr 28, 2009 2:30 pm

Re: Get HTML of Selection? Or HTML with Selection marked?

Postby mr_lundis on Tue Jun 02, 2009 10:57 am

Hi!
I fail to see how the span-wraper code you posted is any different than the wrap-method already in WYMeditor. The following snippet of code would achieve the same result (and work cross-browser).

Code: Select all
wym.wrap('<span>',</span>');

Have I missed something?

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: Get HTML of Selection? Or HTML with Selection marked?

Postby Nico on Mon Jul 27, 2009 7:19 pm

Hi,

I made some changes on the wrap method.
I don't remember exactly what was the problem, but the original one wasn't doing what I was expecting. So I changed it, and this way it works pretty well.

Code: Select all
   WYMeditor.editor.prototype.wrap = function(left, right) {
      // Do we have a selection?
      if (this._iframe.contentWindow.getSelection().focusNode != null) {
         // generate a unique stamp
         var sStamp = this.uniqueStamp();
         // Wrap selection with a link
         this._exec(WYMeditor.CREATE_LINK, sStamp);
         // Remove the link, replace with wraping content
         $('a[href=' + sStamp + ']', this._doc.body)
            .each(function() {
               $(this)
                  .after(left + $(this).html() + right)
                  .remove();
            });
      }
   };


I think the way I do it is not really very nice. But I couldn't find any nicer way to do it.

Nico
Nico
 
Posts: 19
Joined: Tue Jun 23, 2009 6:49 pm


Return to Developers

Who is online

Users browsing this forum: No registered users and 1 guest

cron