Changeset 12335

Show
Ignore:
Timestamp:
02/09/08 21:53:48 (10 months ago)
Author:
peller
Message:

First stab at porting the old url 'insertImage' dialog feature from 0.4. Refs #2439 Uses same code as 'createLink' in LinkDialog? plugin. A fancy dojox.image plugin might extend this. Refs #5759. Also, cleanup code in LinkDialog?.js.

Location:
dijit/trunk
Files:
4 modified

Legend:

Unmodified
Added
Removed
  • dijit/trunk/Editor.js

    r12207 r12335  
    364364                        p = new _p({ button: new dijit.ToolbarSeparator() }); 
    365365                        break; 
    366                 case "createLink": 
    367 //                                      dojo['require']('dijit._editor.plugins.LinkDialog'); 
     366                case "createLink": case "insertImage": 
    368367                        p = new dijit._editor.plugins.LinkDialog({ command: name }); 
    369368                        break; 
     
    374373                        p = new dijit._editor.plugins.FontChoice({ command: name }); 
    375374                        break; 
    376                 case "toggleDir" : 
     375                case "toggleDir": 
    377376                        p = new dijit._editor.plugins.ToggleDir({ command: name}); 
    378377        } 
  • dijit/trunk/tests/test_Editor.html

    r11801 r12335  
    1818                dojo.require("dijit._editor.plugins.AlwaysShowToolbar"); 
    1919                dojo.require("dijit._editor.plugins.EnterKeyHandling"); 
    20 //              dojo.require("dijit._editor.plugins.FontChoice");  // 'fontName','fontSize','formatBlock' 
     20                dojo.require("dijit._editor.plugins.FontChoice");  // 'fontName','fontSize','formatBlock' 
    2121                dojo.require("dijit._editor.plugins.TextColor"); 
    2222                dojo.require("dijit._editor.plugins.LinkDialog"); 
     
    6262                <h3><label for="blah">blah entry</label></h3> 
    6363                <textarea dojoType="dijit.Editor" 
    64                         plugins="['bold','italic','|','createLink','foreColor','hiliteColor']" 
     64                        plugins="['bold','italic','|','createLink','foreColor','hiliteColor','fontName','fontSize','insertImage']" 
    6565                        styleSheets="../../dojo/resources/dojo.css" id="blah"> 
    6666                        This instance includes optional toolbar buttons which pull in additional ui (dijit) code. 
  • dijit/trunk/_editor/nls/LinkDialog.js

    r10008 r12335  
    11({ 
    2         title: "Link URL", 
     2        createLinkTitle: "Link Properties", 
     3        insertImageTitle: "Image Properties", 
    34        url: "URL:", 
    4         text: "Text:", 
    5         set: "Set", 
    6         urlInvalidMessage: "Invalid URL.  Enter a full URL like 'http://www.dojotoolkit.org'"    
     5        text: "Description:", 
     6        set: "Set" 
    77}) 
  • dijit/trunk/_editor/plugins/LinkDialog.js

    r12285 r12335  
    1111dojo.requireLocalization("dijit._editor", "LinkDialog"); 
    1212 
    13 dojo.declare("dijit._editor.plugins.UrlTextBox", 
    14         dijit.form.ValidationTextBox, 
    15         { 
    16                 // summary: the URL input box we use in our dialog 
    17  
    18                 // regular expression for URLs, see dojox.regexp.url() 
    19                 regExp: "((https?|ftps?)\\://|)(([0-9a-zA-Z]([-0-9a-zA-Z]{0,61}[0-9a-zA-Z])?\\.)+(arpa|aero|biz|com|coop|edu|gov|info|int|mil|museum|name|net|org|pro|travel|xxx|jobs|mobi|post|ac|ad|ae|af|ag|ai|al|am|an|ao|aq|ar|as|at|au|aw|az|ba|bb|bd|be|bf|bg|bh|bi|bj|bm|bn|bo|br|bs|bt|bv|bw|by|bz|ca|cc|cd|cf|cg|ch|ci|ck|cl|cm|cn|co|cr|cu|cv|cx|cy|cz|de|dj|dk|dm|do|dz|ec|ee|eg|er|eu|es|et|fi|fj|fk|fm|fo|fr|ga|gd|ge|gf|gg|gh|gi|gl|gm|gn|gp|gq|gr|gs|gt|gu|gw|gy|hk|hm|hn|hr|ht|hu|id|ie|il|im|in|io|ir|is|it|je|jm|jo|jp|ke|kg|kh|ki|km|kn|kr|kw|ky|kz|la|lb|lc|li|lk|lr|ls|lt|lu|lv|ly|ma|mc|md|mg|mh|mk|ml|mm|mn|mo|mp|mq|mr|ms|mt|mu|mv|mw|mx|my|mz|na|nc|ne|nf|ng|ni|nl|no|np|nr|nu|nz|om|pa|pe|pf|pg|ph|pk|pl|pm|pn|pr|ps|pt|pw|py|qa|re|ro|ru|rw|sa|sb|sc|sd|se|sg|sh|si|sk|sl|sm|sn|sr|st|su|sv|sy|sz|tc|td|tf|tg|th|tj|tk|tm|tn|to|tr|tt|tv|tw|tz|ua|ug|uk|us|uy|uz|va|vc|ve|vg|vi|vn|vu|wf|ws|ye|yt|yu|za|zm|zw)|(((\\d|[1-9]\\d|1\\d\\d|2[0-4]\\d|25[0-5])\\.){3}(\\d|[1-9]\\d|1\\d\\d|2[0-4]\\d|25[0-5])|(0[xX]0*[\\da-fA-F]?[\\da-fA-F]\\.){3}0[xX]0*[\\da-fA-F]?[\\da-fA-F]|(0+[0-3][0-7][0-7]\\.){3}0+[0-3][0-7][0-7]|(0|[1-9]\\d{0,8}|[1-3]\\d{9}|4[01]\\d{8}|42[0-8]\\d{7}|429[0-3]\\d{6}|4294[0-8]\\d{5}|42949[0-5]\\d{4}|429496[0-6]\\d{3}|4294967[01]\\d{2}|42949672[0-8]\\d|429496729[0-5])|0[xX]0*[\\da-fA-F]{1,8}|([\\da-fA-F]{1,4}\\:){7}[\\da-fA-F]{1,4}|([\\da-fA-F]{1,4}\\:){6}((\\d|[1-9]\\d|1\\d\\d|2[0-4]\\d|25[0-5])\\.){3}(\\d|[1-9]\\d|1\\d\\d|2[0-4]\\d|25[0-5])))(\\:(0|[1-9]\\d*))?(/([^?#\\s/]+/)*)?([^?#\\s/]+(\\?[^?#\\s/]*)?(#[A-Za-z][\\w.:-]*)?)?", 
    20  
    21                 required: true, 
    22  
    23                 postMixInProperties: function(){ 
    24                         this.inherited("postMixInProperties", arguments); 
    25                         this.invalidMessage = dojo.i18n.getLocalization("dijit._editor", "LinkDialog", this.lang).urlInvalidMessage; 
    26                 }, 
    27  
    28                 getValue: function(){ 
    29                         if(!/^(https?|ftps?)/.test(this.textbox.value)){ 
    30                                 this.textbox.value="http://"+this.textbox.value; 
    31                         } 
    32                         return this.textbox.value; 
    33                 } 
    34         } 
    35 ); 
    36  
    3713dojo.declare("dijit._editor.plugins.LinkDialog", 
    3814        dijit._editor._Plugin, 
     
    4016                buttonClass: dijit.form.DropDownButton, 
    4117                useDefaultCommand: false, 
    42                 command: "createLink", 
     18                urlRegExp: "((https?|ftps?)\\://|)(([0-9a-zA-Z]([-0-9a-zA-Z]{0,61}[0-9a-zA-Z])?\\.)+(arpa|aero|biz|com|coop|edu|gov|info|int|mil|museum|name|net|org|pro|travel|xxx|jobs|mobi|post|ac|ad|ae|af|ag|ai|al|am|an|ao|aq|ar|as|at|au|aw|az|ba|bb|bd|be|bf|bg|bh|bi|bj|bm|bn|bo|br|bs|bt|bv|bw|by|bz|ca|cc|cd|cf|cg|ch|ci|ck|cl|cm|cn|co|cr|cu|cv|cx|cy|cz|de|dj|dk|dm|do|dz|ec|ee|eg|er|eu|es|et|fi|fj|fk|fm|fo|fr|ga|gd|ge|gf|gg|gh|gi|gl|gm|gn|gp|gq|gr|gs|gt|gu|gw|gy|hk|hm|hn|hr|ht|hu|id|ie|il|im|in|io|ir|is|it|je|jm|jo|jp|ke|kg|kh|ki|km|kn|kr|kw|ky|kz|la|lb|lc|li|lk|lr|ls|lt|lu|lv|ly|ma|mc|md|mg|mh|mk|ml|mm|mn|mo|mp|mq|mr|ms|mt|mu|mv|mw|mx|my|mz|na|nc|ne|nf|ng|ni|nl|no|np|nr|nu|nz|om|pa|pe|pf|pg|ph|pk|pl|pm|pn|pr|ps|pt|pw|py|qa|re|ro|ru|rw|sa|sb|sc|sd|se|sg|sh|si|sk|sl|sm|sn|sr|st|su|sv|sy|sz|tc|td|tf|tg|th|tj|tk|tm|tn|to|tr|tt|tv|tw|tz|ua|ug|uk|us|uy|uz|va|vc|ve|vg|vi|vn|vu|wf|ws|ye|yt|yu|za|zm|zw)|(((\\d|[1-9]\\d|1\\d\\d|2[0-4]\\d|25[0-5])\\.){3}(\\d|[1-9]\\d|1\\d\\d|2[0-4]\\d|25[0-5])|(0[xX]0*[\\da-fA-F]?[\\da-fA-F]\\.){3}0[xX]0*[\\da-fA-F]?[\\da-fA-F]|(0+[0-3][0-7][0-7]\\.){3}0+[0-3][0-7][0-7]|(0|[1-9]\\d{0,8}|[1-3]\\d{9}|4[01]\\d{8}|42[0-8]\\d{7}|429[0-3]\\d{6}|4294[0-8]\\d{5}|42949[0-5]\\d{4}|429496[0-6]\\d{3}|4294967[01]\\d{2}|42949672[0-8]\\d|429496729[0-5])|0[xX]0*[\\da-fA-F]{1,8}|([\\da-fA-F]{1,4}\\:){7}[\\da-fA-F]{1,4}|([\\da-fA-F]{1,4}\\:){6}((\\d|[1-9]\\d|1\\d\\d|2[0-4]\\d|25[0-5])\\.){3}(\\d|[1-9]\\d|1\\d\\d|2[0-4]\\d|25[0-5])))(\\:(0|[1-9]\\d*))?(/([^?#\\s/]+/)*)?([^?#\\s/]+(\\?[^?#\\s/]*)?(#[A-Za-z][\\w.:-]*)?)?", 
    4319                linkDialogTemplate: [ 
    4420                        "<table><tr><td>", 
    4521                        "<label for='urlInput'>${url}</label>", 
    4622                        "</td><td>", 
    47                         "<input dojoType=dijit._editor.plugins.UrlTextBox name='urlInput'>", 
     23                        "<input dojoType='dijit.form.ValidationTextBox' regExp='${urlRegExp}' required='true' name='urlInput'>", 
    4824                        "</td></tr><tr><td>", 
    4925                        "<label for='textInput'>${text}</label>", 
    5026                        "</td><td>", 
    51                         "<input dojoType=dijit.form.TextBox name='textInput'>", 
     27                        "<input dojoType='dijit.form.ValidationTextBox' required='true' name='textInput'>", 
    5228                        "</td></tr><tr><td colspan='2'>", 
    53                         "<button dojoType=dijit.form.Button type='submit'>${set}</button>", 
     29                        "<button dojoType='dijit.form.Button' type='submit'>${set}</button>", 
    5430                        "</td></tr></table>" 
    5531                ].join(""), 
     
    5733                constructor: function(){ 
    5834                        var _this = this; 
     35                        this.tag = this.command == 'insertImage' ? 'img' : 'a'; 
    5936                        var messages = dojo.i18n.getLocalization("dijit._editor", "LinkDialog", this.lang); 
    60                         this.dropDown = new dijit.TooltipDialog({ 
    61                                 title: messages.title, 
     37                        var dropDown = (this.dropDown = new dijit.TooltipDialog({ 
     38                                title: messages[this.command + "Title"], 
    6239                                execute: dojo.hitch(this, "setValue"), 
    6340                                onOpen: function(){ 
     
    6946                                }, 
    7047                                onClose: dojo.hitch(this, "_onCloseDialog") 
    71                         }); 
    72                         this.dropDown.setContent(dojo.string.substitute(this.linkDialogTemplate, messages)); 
    73                         this.dropDown.startup(); 
     48                        })); 
     49                        messages.urlRegExp = this.urlRegExp; 
     50                        dropDown.setContent(dropDown.title + "<hr>" + dojo.string.substitute(this.linkDialogTemplate, messages)); 
     51                        dropDown.startup(); 
    7452                }, 
    7553 
     
    7957                        this._onCloseDialog(); 
    8058                        if(dojo.isIE){ //see #4151 
    81                                 var a = dojo.withGlobal(this.editor.window, "getAncestorElement",dijit._editor.selection, ['a']); 
     59                                var a = dojo.withGlobal(this.editor.window, "getAncestorElement", dijit._editor.selection, [this.tag]); 
    8260                                if(a){ 
    83                                         dojo.withGlobal(this.editor.window, "selectElement",dijit._editor.selection, [a]); 
     61                                        dojo.withGlobal(this.editor.window, "selectElement", dijit._editor.selection, [a]); 
    8462                                } 
    8563                        } 
    86                         var attstr='href="'+args.urlInput+'" _djrealurl="'+args.urlInput+'"'; 
    87 //                      console.log(args,this.editor,'<a '+attstr+'>'+args.textInput+'</a>'); 
    88                         this.editor.execCommand('inserthtml', '<a '+attstr+'>'+args.textInput+'</a>'); 
    89 //                      this.editor.execCommand(this.command, args.urlInput); 
     64                        args.tag = this.tag; 
     65                        args.refAttr = this.tag == 'img' ? 'src' : 'href'; 
     66                        //TODO: textInput should be formatted by escapeXml 
     67                        var template = "<${tag} ${refAttr}='${urlInput}' _djrealurl='${urlInput}'" + 
     68                                (args.tag == 'img' ? " alt='${textInput}'>" : ">${textInput}") + 
     69                                "</${tag}>"; 
     70                        this.editor.execCommand('inserthtml', dojo.string.substitute(template, args)); 
    9071                }, 
    9172 
    92 //              _savedSelection: null, 
    9373                _onCloseDialog: function(){ 
    9474                        // FIXME: IE is really messed up here!! 
    9575                        if(dojo.isIE){ 
    96                                 if(this._savedSelection){ 
    97                                         var b=this._savedSelection; 
    98                                         this._savedSelection=null; 
     76                                if("_savedSelection" in this){ 
     77                                        var b = this._savedSelection; 
     78                                        delete this._savedSelection; 
    9979                                        this.editor.focus(); 
    10080                                        var range = this.editor.document.selection.createRange(); 
     
    10686                        } 
    10787                }, 
     88 
    10889                _onOpenDialog: function(){ 
    109                         var a = dojo.withGlobal(this.editor.window, "getAncestorElement",dijit._editor.selection, ['a']); 
    110                         var url='',text=''; 
     90                        var a = dojo.withGlobal(this.editor.window, "getAncestorElement", dijit._editor.selection, [this.tag]); 
     91                        var url, text; 
    11192                        if(a){ 
    112                                 url=a.getAttribute('_djrealurl'); 
    113                                 text=a.textContent||a.innerText; 
    114                                 dojo.withGlobal(this.editor.window, "selectElement",dijit._editor.selection, [a,true]); 
     93                                url = a.getAttribute('_djrealurl'); 
     94                                text = this.tag == 'img' ? a.getAttribute('alt') : a.textContent || a.innerText; 
     95                                dojo.withGlobal(this.editor.window, "selectElement", dijit._editor.selection, [a, true]); 
    11596                        }else{ 
    116                                 text=dojo.withGlobal(this.editor.window, dijit._editor.selection.getSelectedText); 
     97                                text = dojo.withGlobal(this.editor.window, dijit._editor.selection.getSelectedText); 
    11798                        } 
    11899                        // FIXME: IE is *really* b0rken 
    119100                        if(dojo.isIE){ 
    120                                 var range = this.editor.document.selection.createRange(); 
    121                                 this._savedSelection = range.getBookmark(); 
     101                                this._savedSelection = this.editor.document.selection.createRange().getBookmark(); 
    122102                        } 
    123                         this.dropDown.setValues({'urlInput':url,'textInput':text}); 
     103                        this.dropDown.setValues({urlInput: url || '', textInput: text || ''}); 
    124104                        //dijit.focus(this.urlInput); 
    125                 }, 
     105                }/*, 
    126106 
     107//TODO we don't show this state anymore 
    127108                updateState: function(){ 
    128109                        // summary: change shading on button if we are over a link (or not) 
    129110 
    130111                        var _e = this.editor; 
    131                         if(!_e){ return; } 
    132                         if(!_e.isLoaded){ return; } 
     112                        if(!_e || !_e.isLoaded){ return; } 
    133113                        if(this.button){ 
    134114                                // display button differently if there is an existing link associated with the current selection 
    135                                 var hasA = dojo.withGlobal(this.editor.window, "hasAncestorElement",dijit._editor.selection, ['a']); 
     115                                var hasA = dojo.withGlobal(this.editor.window, "hasAncestorElement", dijit._editor.selection, [this.tag]); 
    136116                                this.button.setAttribute('checked', hasA); 
    137117                        } 
    138118                } 
     119*/ 
    139120        } 
    140121);