plandem / lwrte

Export from Google Code. Lightweight Rich Text Editor (RTE / WYSIWYG) for jQuery
https://code.google.com/p/lwrte/
0 stars 0 forks source link

Linking selected text safari 3.2.1 not working #7

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. Select some thext
2. Open link button
3. Enter some link
4. Text disaper

Original issue reported on code.google.com by jor...@gmail.com on 29 Jan 2009 at 10:38

GoogleCodeExporter commented 9 years ago
Doing a little debuging seems that the trouble is in this function:

lwRTE.prototype.selection_replace_with = function(html) {
    var rng = this.get_selection_range();
    var iframe_window = this.iframe.contentWindow;

    if(!rng)
        return;

    this.editor_cmd('removeFormat'); // we must remove formating or we will get empty format tags!

    if(iframe_window.getSelection) {

                rng.deleteContents();
                 // safari dosen't support it?
        rng.insertNode(rng.createContextualFragment(html));
        this.editor_cmd('delete');
    } else {
        this.editor_cmd('delete');
        rng.pasteHTML(html);
    }
}

Original comment by jor...@gmail.com on 29 Jan 2009 at 11:59

GoogleCodeExporter commented 9 years ago
Is it Safari problem only? never test in it, actually. Will try to dig, 
although that
function officially is supported by Safari :(

Original comment by plandem on 31 Jan 2009 at 10:15

GoogleCodeExporter commented 9 years ago
[deleted comment]
GoogleCodeExporter commented 9 years ago
I have patched the two files to work with safari 3.
First I have changed the click a button! Now it's ok! But works different!
I have patched the replace_selected... this time works with safari and firefox 
... I don't know if it works on 
explorer ...

Original comment by jor...@gmail.com on 1 Feb 2009 at 12:25

Attachments:

GoogleCodeExporter commented 9 years ago
Well, your  'rng.insertNode(html)' is not forking at firefox + firebug, btw. 
text
disappears.

Original comment by plandem on 5 Mar 2009 at 10:57

GoogleCodeExporter commented 9 years ago
uoops! I don't know what you are saying .... I have integrated the editor 
inside my test cms, but now I have many 
work and I can dedicate a lot of time to it. But I'm very interested in working 
within this editor an making it 
powerfull and simple! If you need something, ask please!

Original comment by jor...@gmail.com on 8 Mar 2009 at 8:26

GoogleCodeExporter commented 9 years ago
your patch is not working at my Firefox at Windows :( 

Original comment by plandem on 8 Mar 2009 at 8:51

GoogleCodeExporter commented 9 years ago
[deleted comment]
GoogleCodeExporter commented 9 years ago
[deleted comment]
GoogleCodeExporter commented 9 years ago
I did some modifications to the script and then tested with IE, FF and Safari 
and it 
works just fine. Please see below:

#### ON jquery.rte.js REPLACE THE OLD selection_replace_with FUNCTION WITH THE 
FOLLOWING ####

lwRTE.prototype.selection_replace_with = function(html) {
    var rng = this.get_selection_range();
    var iframe_window = this.iframe.contentWindow;

    if(!rng)
        return;

    this.editor_cmd('removeFormat'); // we must remove formating or we will get 
empty format tags!

    if(iframe_window.getSelection) {
        rng.deleteContents();

        if ($.browser.safari) {
            rng.insertNode(html);
        }

        rng.insertNode(rng.createContextualFragment(html));
        this.editor_cmd('delete');
    } else {
        this.editor_cmd('delete');
        rng.pasteHTML(html);
    }
}

#### ON jquery.rte.tb.js REPLACE THE OLD $("#ok").clic() event INSIDE THE 
lwrte_link 
FUNCTION WITH THE FOLLOWING ####

$('#ok', panel).click( 
        function() {
            var url = $('#url', panel).val();
            var target = $('#target', panel).val();
            var title = $('#title', panel).val();

            if(self.get_selected_text().length <= 0) {
                alert('Select the text you wish to link!');
                return false;
            }

            panel.remove(); 

            if(url.length <= 0)
                return false;

            self.editor_cmd('unlink');

            // we wanna well-formed linkage (<p>,<h1> and other block 
types can't be inside of link due to WC3)
            if ($.browser.safari) {
                var html = '<a href="' + url + '" target="_blank" 
title="'+title+'" />' + self.get_selected_text() + '</a>';

                self.editor_cmd("insertHTML", html)
            } else {
                self.editor_cmd('createLink', rte_tag);
                var tmp = $('<span></span>').append($.trim
(self.get_selected_html()));

                if(target.length > 0)
                    $('a[href*="' + rte_tag + '"]', tmp).attr
('target', target);

                if(title.length > 0)
                    $('a[href*="' + rte_tag + '"]', tmp).attr
('title', title);

                $('a[href*="' + rte_tag + '"]', tmp).attr('href', 
url);

                //self.selection_replace_with(tmp.html());
            }

            self.set_content($.trim(self.get_content()));
            return false;
        }
    );

I hope this works for you guys just like it worked for me.

Original comment by Grace.Ba...@gmail.com on 16 Jun 2009 at 3:57

GoogleCodeExporter commented 9 years ago
That last edit works great in the most current version of Safari. Thank-you!

Original comment by jasonros...@gmail.com on 8 Jul 2009 at 4:52

GoogleCodeExporter commented 9 years ago
[deleted comment]
GoogleCodeExporter commented 9 years ago
Thank you   Grace.Ba...@gmail.com, it's works great!

Original comment by p.kupt...@giftec.ru on 12 Nov 2012 at 11:37