Opened 13 years ago

Closed 13 years ago

Last modified 12 years ago

#1153 closed enhancement (fixed)

[patch][need cla] Editor / Editor 2: new createlink features (modify links and status on toolbar)

Reported by: bruce dot webster dot ac dot nz Owned by: liucougar
Priority: high Milestone:
Component: Widgets Version: 0.3
Keywords: Cc:
Blocked By: Blocking:

Description

To get status of createlinkButton (ie highlighting of toolbar icon when you're inside a link), add this line as the first line of queryCommandState function in 'RichText?.js':

//logically, if you can unlink, you're inside a link, and createlink status should be hilighted.
if(command=="createlink") {return(this.queryCommandEnabled("unlink"));}

Editor 2: To conform to [command_name]Button syntax, linkButton should be called 'createlinkButton'. This will make status work.

To allow modification of existing links, replace the toolbarWidget.createlinkButton onclick event function with this:

				dojo.lang.hitch(this, function(){
					var rangelen=0;
					var url='http://';
					var node = null;

					if(this.document.selection){	
						var selection = this.document.selection;
						range=selection.createRange();
						if(range.text) rangelen = range.text.toString().length;
						switch (selection.type) {
							case "Text": case "None": node = range.parentElement();break;
							case "Control":	node= range.item(0);break;
							default: node=this.document.body;
						}

					} else if(dojo.render.html.mozilla){
						var selection = this.window.getSelection();
						range=selection.getRangeAt(0);
						rangelen = selection.toString().length;
						try {
							node = range.commonAncestorContainer;
							// this next wacky line is from HTMLArea.  Gets link from child of range if necessary.
							if (!range.collapsed && range.startContainer == range.endContainer && range.startOffset - range.endOffset <= 1 && range.startContainer.hasChildNodes())
								node = range.startContainer.childNodes[range.startOffset];
							while (node.nodeType == 3) {node = node.parentNode;} // TEXTNODEs
						} catch (e) {}
					}

					//Check if node already linked in parent...
					if(node.parentNode.nodeName=="A") node = node.parentNode;

					if(node.nodeName == "A") {
						url=node.href;
						if(dojo.render.html.mozilla) {
							// need to set selection to the link for mozilla
							var range = document.createRange();
							range.selectNode(node);
							selection.removeAllRanges();
							selection.addRange(range);
						}
					}

					if(node.nodeName == "A"||node.nodeName == "IMG"||rangelen) {
						if(url=prompt("Please enter the URL of the link:", url)){
							this.toolbarWidget.exec("createlink", url);
						} else {focusFunc();}
					}else{
						alert("Please select text to link");focusFunc();
					}
				})

This functin can also be put into the Editor widget if you replace 'this.document' with 'this._richText.document'. To get status working in Editor.js, add this extra case line (about line 132):

			case "createlink":props.toggleItem = true;break;

Change History (5)

comment:1 Changed 13 years ago by bruce dot webster at cce dot ac dot nz

Summary: new createlink features (modify links and status on toolbar)Editor / Editor 2: new createlink features (modify links and status on toolbar)

comment:2 Changed 13 years ago by dylan

Owner: changed from bill to liucougar
Summary: Editor / Editor 2: new createlink features (modify links and status on toolbar)[patch] Editor / Editor 2: new createlink features (modify links and status on toolbar)

need to verify that we have a CLA on file, http://dojotoolkit.org/foundation/

comment:3 Changed 13 years ago by dylan

Summary: [patch] Editor / Editor 2: new createlink features (modify links and status on toolbar)[patch][need cla] Editor / Editor 2: new createlink features (modify links and status on toolbar)

Bruce, any chance we can get a CLA for this one? http://dojotoolkit.org/foundation/

comment:4 Changed 13 years ago by liucougar

Resolution: fixed
Status: newclosed

this is already fixed in the new editor2

comment:5 Changed 12 years ago by (none)

Milestone: 0.4

Milestone 0.4 deleted

Note: See TracTickets for help on using tickets.