FCKEditor and Radiant: Adjusting the Link Target According to Link Type
3
In one of my projects at eSpace, I was building a site using Radiant CMS. I decided toput FCKEditor as the rich text editor to be used by the site administrator. FCKEditor is one of the great text editors available; using it you can add links to the page content and decide whether those links open in the same window or in new window. The default for the link is to open in the same window, but we decided that any external links must open by default in a new window and any internal links (links to site pages) must open by default in the same window.
So, to do that you need first to configure the FCKEditor to set the default target for any new link to be "_blank" for a new window. You have two ways to do that:
- Edit the HTML for the add link dialog. This can be done through two steps:
- Open file "<SITE_ROOT>\public\javascripts\fckeditor\editor\dialog\fck_link.html". Search for the select input with name "cmbTarget" and remove the "selected='selected'" from the option "DlgGenNotSet" and put it in the option"DlgLnkTargetBlank":
<select id="cmbTarget" onchange="SetTarget(this.value);">
...
<option value="" fckLang="DlgGenNotSet"><not set></option>
<option value="_blank" fckLang="DlgLnkTargetBlank" selected="selected">New Window (_blank)</option>
...
</select> - In the same file, search for input "txtTargetFrame" and change its value to be "value='_blank'":
<input id="txtTargetFrame" style="WIDTH: 100%" type="text" onkeyup="OnTargetNameChange();" onchange="OnTargetNameChange();" value="_blank"/>
- Open file "<SITE_ROOT>\public\javascripts\fckeditor\editor\dialog\fck_link.html". Search for the select input with name "cmbTarget" and remove the "selected='selected'" from the option "DlgGenNotSet" and put it in the option"DlgLnkTargetBlank":
- The other easier way is to configure the FCKEditor for that. Open the file "<SITE_ROOT>\vendor\extensions\fckeditor\app\views\fckeditor\config.js.erb" and add the configuration line:
FCKConfig.DefaultLinkTarget = "_blank";
Now, any new link inside the page content will be opened in a new window without manually changing the link target in the add link dialog.
The second step is to distinguish between internal links and external links in order for them to open in a new window or in the same window.
Links to internal site pages can be added through the link dialog by selecting "others" in link protocol combo-box. This way you can depend on the protocol value to make this distiniction.
- Create a javascript function in the file "<SITE_ROOT>\public\javascripts\fckeditor\editor\dialog\fck_link\fck_link.js" to adjust the link target automatically according to the protocol value:
function adjustTarget(protocolValue){
if (protocolValue == ""){
GetE('cmbTarget').value = "";
GetE('txtTargetFrame').value = "";
}else{
GetE('cmbTarget').value = "_blank";
GetE('txtTargetFrame').value = "_blank";
}
} - Call this function from the "onchange" method of the input with id "cmbLinkProtocol". You can find this input in the file "<SITE_ROOT>\public\javascripts\fckeditor\editor\dialog\fck_link.html". Once the user changes the protocol, it will adjust the link target automatically:
<select id="cmbLinkProtocol" onchange="adjustTarget(this.value);">
Now, you have edited the FCKEditor to have this nice functionality, opening internal links internally and open external links externally.
Written By:
Wael Shaban (wshaban.blogspot.com)
Comments
Post a Comment
eSpace podcast Prodcast
Archive
- September 2011
- April 2011
- March 2011
- December 2010
- November 2010
- September 2010
- August 2010
- July 2010
- June 2010
- April 2010
- March 2010
- November 2009
- October 2009
- September 2009
- July 2009
- June 2009
- May 2009
- April 2009
- March 2009
- February 2009
- January 2009
- November 2008
- October 2008
- September 2008
- July 2008
- June 2008
- May 2008
- April 2008
- March 2008
- January 2008
- April 2007
- March 2007
Latest Comments
- SpectraMind Commented on Egypt Wins UK's National Outsourcing Association Award
- Rofaida Awad Commented on Go Egypt Go!
- Different Mike Commented on Only idiots change their iPhone root password!
- Mike Commented on Only idiots change their iPhone root password!
- smile Commented on Only idiots change their iPhone root password!

