Changeset 12335
- Timestamp:
- 02/09/08 21:53:48 (10 months ago)
- Location:
- dijit/trunk
- Files:
-
- 4 modified
-
Editor.js (modified) (2 diffs)
-
tests/test_Editor.html (modified) (2 diffs)
-
_editor/nls/LinkDialog.js (modified) (1 diff)
-
_editor/plugins/LinkDialog.js (modified) (6 diffs)
Legend:
- Unmodified
- Added
- Removed
-
dijit/trunk/Editor.js
r12207 r12335 364 364 p = new _p({ button: new dijit.ToolbarSeparator() }); 365 365 break; 366 case "createLink": 367 // dojo['require']('dijit._editor.plugins.LinkDialog'); 366 case "createLink": case "insertImage": 368 367 p = new dijit._editor.plugins.LinkDialog({ command: name }); 369 368 break; … … 374 373 p = new dijit._editor.plugins.FontChoice({ command: name }); 375 374 break; 376 case "toggleDir" :375 case "toggleDir": 377 376 p = new dijit._editor.plugins.ToggleDir({ command: name}); 378 377 } -
dijit/trunk/tests/test_Editor.html
r11801 r12335 18 18 dojo.require("dijit._editor.plugins.AlwaysShowToolbar"); 19 19 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' 21 21 dojo.require("dijit._editor.plugins.TextColor"); 22 22 dojo.require("dijit._editor.plugins.LinkDialog"); … … 62 62 <h3><label for="blah">blah entry</label></h3> 63 63 <textarea dojoType="dijit.Editor" 64 plugins="['bold','italic','|','createLink','foreColor','hiliteColor' ]"64 plugins="['bold','italic','|','createLink','foreColor','hiliteColor','fontName','fontSize','insertImage']" 65 65 styleSheets="../../dojo/resources/dojo.css" id="blah"> 66 66 This instance includes optional toolbar buttons which pull in additional ui (dijit) code. -
dijit/trunk/_editor/nls/LinkDialog.js
r10008 r12335 1 1 ({ 2 title: "Link URL", 2 createLinkTitle: "Link Properties", 3 insertImageTitle: "Image Properties", 3 4 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" 7 7 }) -
dijit/trunk/_editor/plugins/LinkDialog.js
r12285 r12335 11 11 dojo.requireLocalization("dijit._editor", "LinkDialog"); 12 12 13 dojo.declare("dijit._editor.plugins.UrlTextBox",14 dijit.form.ValidationTextBox,15 {16 // summary: the URL input box we use in our dialog17 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 37 13 dojo.declare("dijit._editor.plugins.LinkDialog", 38 14 dijit._editor._Plugin, … … 40 16 buttonClass: dijit.form.DropDownButton, 41 17 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|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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.:-]*)?)?", 43 19 linkDialogTemplate: [ 44 20 "<table><tr><td>", 45 21 "<label for='urlInput'>${url}</label>", 46 22 "</td><td>", 47 "<input dojoType= dijit._editor.plugins.UrlTextBoxname='urlInput'>",23 "<input dojoType='dijit.form.ValidationTextBox' regExp='${urlRegExp}' required='true' name='urlInput'>", 48 24 "</td></tr><tr><td>", 49 25 "<label for='textInput'>${text}</label>", 50 26 "</td><td>", 51 "<input dojoType= dijit.form.TextBoxname='textInput'>",27 "<input dojoType='dijit.form.ValidationTextBox' required='true' name='textInput'>", 52 28 "</td></tr><tr><td colspan='2'>", 53 "<button dojoType= dijit.form.Buttontype='submit'>${set}</button>",29 "<button dojoType='dijit.form.Button' type='submit'>${set}</button>", 54 30 "</td></tr></table>" 55 31 ].join(""), … … 57 33 constructor: function(){ 58 34 var _this = this; 35 this.tag = this.command == 'insertImage' ? 'img' : 'a'; 59 36 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"], 62 39 execute: dojo.hitch(this, "setValue"), 63 40 onOpen: function(){ … … 69 46 }, 70 47 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(); 74 52 }, 75 53 … … 79 57 this._onCloseDialog(); 80 58 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]); 82 60 if(a){ 83 dojo.withGlobal(this.editor.window, "selectElement", dijit._editor.selection, [a]);61 dojo.withGlobal(this.editor.window, "selectElement", dijit._editor.selection, [a]); 84 62 } 85 63 } 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)); 90 71 }, 91 72 92 // _savedSelection: null,93 73 _onCloseDialog: function(){ 94 74 // FIXME: IE is really messed up here!! 95 75 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; 99 79 this.editor.focus(); 100 80 var range = this.editor.document.selection.createRange(); … … 106 86 } 107 87 }, 88 108 89 _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; 111 92 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]); 115 96 }else{ 116 text =dojo.withGlobal(this.editor.window, dijit._editor.selection.getSelectedText);97 text = dojo.withGlobal(this.editor.window, dijit._editor.selection.getSelectedText); 117 98 } 118 99 // FIXME: IE is *really* b0rken 119 100 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(); 122 102 } 123 this.dropDown.setValues({ 'urlInput':url,'textInput':text});103 this.dropDown.setValues({urlInput: url || '', textInput: text || ''}); 124 104 //dijit.focus(this.urlInput); 125 } ,105 }/*, 126 106 107 //TODO we don't show this state anymore 127 108 updateState: function(){ 128 109 // summary: change shading on button if we are over a link (or not) 129 110 130 111 var _e = this.editor; 131 if(!_e){ return; } 132 if(!_e.isLoaded){ return; } 112 if(!_e || !_e.isLoaded){ return; } 133 113 if(this.button){ 134 114 // 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]); 136 116 this.button.setAttribute('checked', hasA); 137 117 } 138 118 } 119 */ 139 120 } 140 121 );