linkdialog.lzx

<!---
      @topic Incubator
      @subtopic Rich Text Editor
  -->
<library>

    
    <!-- dependencies  -->
    <!-- include href="../borderinput.lzx" /--> 
        
    <!---
    A dialog to let the user set a hyperlink on the currently selected text.
    @author ben 7.26.05
    -->
    <class name="linkdialog" width="${parent.toolbar.width}" height="${parent.toolbar.height}" bgcolor="0xD4D7E6" visible="false">
        
        <!--- Reference to the associated richtexteditor. (default: grte) --> 
        <attribute name="editor" value="${grte}"/>
        
        <attribute name="ystart" value="110"/>
        
        <!--- the start index of the text to mark as an url --> 
        <attribute name="ssel" value="0"/>
        <!--- the end index of the text to mark as an url --> 
        <attribute name="esel" value="0"/>

        
        <animator name="_animShow" attribute="y" to="0" from="${-parent.height}" duration="500" start="false" onstart="parent.setAttribute('visible', true)"/>
        
        <!--- Used to hide dialog.
            @keywords private -->
        <animator name="_animHide" attribute="y" from="0" to="${-parent.height}" duration="200" start="false" onstop="parent.setAttribute('visible', false)"/>
        
        <!--- show
            slides in the dialog. -->
        <method name="show">
            this.ssel = this.editor._ssel;
            this.esel = this.editor._esel; 
            this.urlfield.setAttribute('text', "http://");
            var ntextlength = this.urlfield.text.length;
            this.urlfield.setSelection(ntextlength,ntextlength);
            this._animShow.doStart();
        </method>
    
        <!--- hide
            slides out the dialog --> 
        <method name="hide">
            this._animHide.doStart();
        </method>
     
        
        <!--- makelink
            Assigns link and standard link formatting to text selected in the editor. --> 
        <method name="makelink">
            if (this.ssel == this.esel) {
                // it doesn't make sense to make a link to an empty selection, so, 
                // let's see if the editor has a more useful selection. 
                this.ssel = this.editor._ssel;
                this.esel = this.editor._esel; 
            }
        
            var url = this.urlfield.text;
            var fmt = this.editor.getTextFormat(this.ssel, this.esel); 
            fmt.url = url;
            fmt.color = 0x0000FF; 
            fmt.target = "_new"; 
            fmt.underline = true; 
            this.editor.setTextFormat(fmt, this.ssel, this.esel);
            var ncaratinsertpoint = this.editor._esel;

            // make sure that next onfocus, which will be triggered by doing setSelection here, is ignored by editor.
            this.editor._ignorenextfocus = true;
            this.editor.setSelection(ncaratinsertpoint,ncaratinsertpoint);

            this.hide();
        </method>
    
        <text name="linktolabel" y="4" x="5" fgcolor="0x40408B" font="Verdana, Arial, sans" fontsize="11" resize="true">Link to URL:</text>    
        <borderinput name="urlfield" width="${parent.width-150}" y="3"/>
    
        <view y="4" x="${parent.width-145}">
            <stylishbutton onclick="classroot.makelink()" width="70" text="Link">
                <tooltip>Make a link to this location</tooltip>
            </stylishbutton>
            
            <stylishbutton onclick="classroot.hide()" x="80" width="60" text="Cancel">
                <tooltip>Don't make a link</tooltip>
            </stylishbutton>
        </view>
    
    
    </class>
    
</library>
<!-- * X_LZ_COPYRIGHT_BEGIN ***************************************************
* Copyright 2006-2011 Laszlo Systems, Inc.  All Rights Reserved.              *
* Use is subject to license terms.                                            *
* X_LZ_COPYRIGHT_END ****************************************************** -->
<!-- @LZX_VERSION@                                                         -->

Cross References

Classes