Re: Obtaining Selected Image HTML

  •  04-18-2011, 9:56 AM

    Re: Obtaining Selected Image HTML

    Kenneth,
     
    Thanks for your help.  I can now read the image src, display/edit in the dialogue and recreate the new image src.  Still have one final problem and that is getting it back in to the editor.  I have tried a lot of things, including modifying the code for getting the src in the first instance (see below).     If you cold help me out with this last thing it would be really great.
     

    function button_click() {
              
                var editor1 = Window_GetDialogArguments(window); ;
                var editwin = editor1.GetWindow();
                var editdoc = editor1.GetDocument();
                var rng = null;

                var ta = document.getElementById("latex").value;
                var src = "/Eq?$\\large " + escape(ta) + "$" + "";
                var html = "<img class='wikiEquation'  src='/Eq?$\\large " + escape(ta) + "$'/>" + "";

                    if (document.selection && document.selection.createRange) {
                    rng = editdoc.selection.createRange();
                    if (editdoc.selection.type == "Control") {
                        if (rng.length == 1) {
                            var element = rng.item(0);
                            if (element.tagName == 'IMG') {
                                element.src=src;
                                //get html code of img tag
                                //html=element.outerHTML;
                            }
                        }
                    } else {
                        rng.htmlText = html;
                    }
                } else if (window.getSelection) {
                    rng = editwin.getSelection();

                    if (rng.rangeCount > 0 && window.XMLSerializer) {
                        rng = rng.getRangeAt(0);
                        for (var i = 0; i < rng.startContainer.childNodes.length; i++) {
                            if (rng.startContainer.childNodes[i].tagName == "IMG") {

                                rng.startContainer.childNodes[i].src=src;
                            }

                        }
                    }
                }

               window.top.close();
            }

View Complete Thread