Index: trunk/admin/editor/cmseditor/editor/dialog/fck_link/fck_link.js =================================================================== diff -u -N --- trunk/admin/editor/cmseditor/editor/dialog/fck_link/fck_link.js (revision 7855) +++ trunk/admin/editor/cmseditor/editor/dialog/fck_link/fck_link.js (revision 0) @@ -1,735 +0,0 @@ -/* - * FCKeditor - The text editor for internet - * Copyright (C) 2003-2004 Frederico Caldeira Knabben - * - * Licensed under the terms of the GNU Lesser General Public License: - * http://www.opensource.org/licenses/lgpl-license.php - * - * For further information visit: - * http://www.fckeditor.net/ - * - * File Name: fck_link.js - * Scripts related to the Link dialog window (see fck_link.html). - * - * Version: 2.0 RC3 - * Modified: 2005-02-09 13:53:13 - * - * File Authors: - * Frederico Caldeira Knabben (fredck@fckeditor.net) - */ - -var oEditor = window.parent.InnerDialogLoaded() ; -var FCK = oEditor.FCK ; -var FCKLang = oEditor.FCKLang ; -var ServerPath = ''; -var from = ''; -var anchor_ = ''; -var links_path = new Array() - -//#### Dialog Tabs - -// Set the dialog tabs. -//window.parent.AddTab( 'Info', FCKLang.DlgLnkInfoTab ) ; -//window.parent.AddTab( 'Target', FCKLang.DlgLnkTargetTab, true ) ; -// TODO : Enable File Upload (1/3). -//window.parent.AddTab( 'Upload', 'Upload', true ) ; -//window.parent.AddTab( 'Advanced', FCKLang.DlgAdvancedTag ) ; - -// Function called when a dialog tag is selected. -function OnDialogTabChange( tabCode ) -{ -// ShowE('divInfo' , ( tabCode == 'Info' ) ) ; -// ShowE('divTarget' , ( tabCode == 'Target' ) ) ; -// TODO : Enable File Upload (2/3). -// ShowE('divUpload' , ( tabCode == 'Upload' ) ) ; -// ShowE('divAttribs' , ( tabCode == 'Advanced' ) ) ; -} - -//#### Regular Expressions library. -var oRegex = new Object() ; - -oRegex.UriProtocol = new RegExp('') ; -oRegex.UriProtocol.compile( '^(((http|https|ftp|news):\/\/)|mailto:)', 'gi' ) ; - -oRegex.UrlOnChangeProtocol = new RegExp('') ; -oRegex.UrlOnChangeProtocol.compile( '^(http|https|ftp|news)://(?=.)', 'gi' ) ; - -oRegex.UrlOnChangeTestOther = new RegExp('') ; -oRegex.UrlOnChangeTestOther.compile( '^(javascript:|#|/)', 'gi' ) ; - -oRegex.ReserveTarget = new RegExp('') ; -oRegex.ReserveTarget.compile( '^_(blank|self|top|parent)$', 'i' ) ; - -oRegex.PopupUri = new RegExp('') ; -//oRegex.PopupUri.compile( "^javascript:void\\(\\s*window.open\\(\\s*'([^']+)'\\s*,\\s*(?:'([^']*)'|null)\\s*,\\s*'([^']*)'\\s*\\)\\s*\\)\\s*$" ) ; -oRegex.PopupUri.compile( "^javascript:openwincms\\(\\s*'([^']+)'\\s*,\\s*(?:'([^']*)'|null)\\s*,\\s*([^']*)\\s*,\\s*([^']*)\\s*\\)$" ) ; - -oRegex.PopupFeatures = new RegExp('') ; -oRegex.PopupFeatures.compile( '(?:^|,)([^=]+)=(\\d+|yes|no)', 'gi' ) ; - -//#### Parser Functions - -var oParser = new Object() ; - -oParser.ParseEMailUrl = function( emailUrl ) -{ - // Initializes the EMailInfo object. - var oEMailInfo = new Object() ; - oEMailInfo.Address = '' ; - oEMailInfo.Subject = '' ; - oEMailInfo.Body = '' ; - - var oParts = emailUrl.match( /^([^\?]+)\??(.+)?/ ) ; - if ( oParts ) - { - // Set the e-mail address. - oEMailInfo.Address = oParts[1] ; - - // Look for the optional e-mail parameters. - if ( oParts[2] ) - { - var oMatch = oParts[2].match( /(^|&)subject=([^&]+)/i ) ; - if ( oMatch ) oEMailInfo.Subject = unescape( oMatch[2] ) ; - - oMatch = oParts[2].match( /(^|&)body=([^&]+)/i ) ; - if ( oMatch ) oEMailInfo.Body = unescape( oMatch[2] ) ; - } - } - - return oEMailInfo ; -} - -oParser.CreateEMailUri = function( address, subject, body ) -{ - var sBaseUri = 'mailto:' + address ; - - var sParams = '' ; - - if ( subject.length > 0 ) - sParams = '?subject=' + escape( subject ) ; - - if ( body.length > 0 ) - { - sParams += ( sParams.length == 0 ? '?' : '&' ) ; - sParams += 'body=' + escape( body ) ; - } - - return sBaseUri + sParams ; -} - -//#### Initialization Code - -// oLink: The actual selected link in the editor. -var oLink = FCK.Selection.MoveToAncestorNode( 'A' ) ; -if ( oLink ) { - FCK.Selection.MoveToNode( oLink ) ; - - //show_props(oLink.attributes, 'LINK: ') -} - -function OnDialogTabChange( tabCode ) -{ - if (tabCode == 'Info') { - updateDataArray(); - window.parent.document.getElementById('TitleArea').innerHTML = oEditor.FCKLang.DlgImgTitle; - } -} - -function updateDataArray() -{ - window.parent.parentData['linkTxtUrl'] = BuildUrlByType(); - if (window.parent.parentData['linkTxtUrl'].length > 2) { - if (GetE('txtAlt')) { - window.parent.parentData['linkTxtAlt'] = GetE('txtAlt').value; - window.parent.parentData['linkTxtTitle'] = GetE('txtAlt').value; - } - window.parent.parentData['linkCmbTarget'] = GetE('cmbTarget').value; - window.parent.parentData['linkType'] = GetE('cmbLinkType').value; - window.location.href='dialog/fck_image.html?from'; - } -} - -window.onload = function() -{ - CreateLinkTypes(); - oEditor.FCKLanguageManager.TranslatePage(document) ; - LoadSelection() ; - GetE('divInfo').style.display = '' ; - window.parent.SetOkButton( true ) ; -} - -var bHasAnchors ; - -function CreateLinkTypes() -{ - if (InternalLinksEsists() === true) - oEditor.FCKTools.AddSelectOption( document, GetE('cmbLinkType'), 'Internal Web Page', 'internal'); - oEditor.FCKTools.AddSelectOption( document, GetE('cmbLinkType'), 'External Web Page', 'external'); - oEditor.FCKTools.AddSelectOption( document, GetE('cmbLinkType'), 'E-mail', 'email'); - oEditor.FCKTools.AddSelectOption( document, GetE('cmbLinkType'), 'File', 'Doc'); -} - -function InternalLinksEsists() -{ - if (typeof(oEditor.FCKConfig.InternalLinksEsists) != 'undefined') - { - if (oEditor.FCKConfig.InternalLinksEsists != 'Off') - return true; - } else - return true; -} - -function LoadAnchorNamesAndIds() -{ - count_real_anchors = 0; - if (GetE('cmbLinkType').value != 'internal') { - ShowE( 'divNoAnchor' , 0 ) ; - return; - } - var aAnchors = window.frames["frmInternal"].document.anchors ; - if (aAnchors) { - bHasAnchors = ( aAnchors.length > 0) ; - if (GetE('cmbAnchorName').options.length > 0) { - GetE('cmbAnchorName').options.length = 0; - } - - oEditor.FCKTools.AddSelectOption( document, GetE('cmbAnchorName'), '', '' ) ; - for ( var i = 0 ; i < aAnchors.length ; i++ ) - { - var sName = aAnchors[i].name ; - if ( sName && sName.length > 0 ) { - count_real_anchors++; - oEditor.FCKTools.AddSelectOption( document, GetE('cmbAnchorName'), sName, sName ) ; - } - } - if (count_real_anchors > 0) bHasAnchors = true; - else bHasAnchors = false ; - ShowE( 'divSelAnchor' , bHasAnchors ) ; - ShowE( 'divNoAnchor' , !bHasAnchors ) ; - for ( var i = 0 ; i < GetE('cmbAnchorName').length ; i++ ) - { - if (anchor_ == GetE('cmbAnchorName').options[i].value) - GetE('cmbAnchorName').options[i].selected=1; - } - - } -} - -function LoadSelection() -{ - var sHRef = ''; - var sType = ''; - if (window.parent.parentData['linkTxtUrl']) - { - sHRef = window.parent.parentData['linkTxtUrl']; - if (window.parent.parentData['linkTxtAlt']) - GetE('txtAlt').value = window.parent.parentData['linkTxtAlt']; - sType = GetE('cmbLinkType').value = window.parent.parentData['linkType']; - var sTarget = window.parent.parentData['linkCmbTarget']; - //alert('href: ' + sHRef + '\n'+'txtAlt: '+ GetE('txtAlt').value+'\n'+'sType: ' + sType+'\n'+'sTarget: ' + sTarget); - } else if ( !oLink ) { - if (InternalLinksEsists() === true) - SetLinkType('internal'); - else - SetLinkType('external'); - return ; - } - if (sHRef.length == 0) - { - // Get the actual Link href. - var sHRef = oLink.getAttribute('href',2) + '' ; - if (oLink.getAttribute('alt',2)) { - if(oLink.getAttribute('alt',2).length > 0) - GetE('txtAlt').value = oLink.getAttribute('alt',2) + '' ; - else - GetE('txtAlt').value = ''; - } - // Look for a popup javascript link. - } - var oPopupMatch = oRegex.PopupUri.exec( sHRef ) ; - if( oPopupMatch ) - { - GetE('cmbTarget').value = 'popup' ; - sHRef = oPopupMatch[1] ; - GetE('txtPopupWidth').value = oPopupMatch[3]; - GetE('txtPopupHeight').value = oPopupMatch[4]; - SetTarget('popup'); - } - // Search for the protocol. - var sProtocol = oRegex.UriProtocol.exec( sHRef ) ; - if ( sProtocol ) - { - sProtocol = sProtocol[0].toLowerCase() ; - GetE('cmbLinkProtocol').value = sProtocol ; - - // Remove the protocol and get the remainig URL. - var sUrl = sHRef.replace( oRegex.UriProtocol, '' ) ; - - if ( sProtocol == 'mailto:' ) // It is an e-mail link. - { - sType = 'email' ; - var oEMailInfo = oParser.ParseEMailUrl( sUrl ) ; - GetE('txtEMailAddress').value = oEMailInfo.Address ; - GetE('txtEMailSubject').value = oEMailInfo.Subject ; - GetE('txtEMailBody').value = oEMailInfo.Body ; - } - else // It is a normal link. - GetE('txtUrl').value = sUrl ; - } - else // It is another type of link. - { - GetE('cmbLinkProtocol').value = '' ; - GetE('txtUrl').value = sHRef ; - } - - if (oLink) { - //if (!window.location.search) - if (sType.length == 0) - sType = GetAttribute( oLink, 'label', '' ); - if (sType.length == 0) - sType = 'external'; - } - - if (sType == 'Doc' && sHRef.length > 2) { - GetE('fileUrl').value = sHRef ; - } - - - if (sType == 'internal' && sHRef.length > 2 && sHRef.indexOf('#') > 0) { - anchor_ = sHRef.slice(sHRef.lastIndexOf('#')+1); - sHRef = sHRef.slice(0,sHRef.lastIndexOf('#')); - GetE('txtUrl').value = sHRef ; - } - - if ( !oPopupMatch ) - { - // Get the target. - if (oLink) - var sTarget = oLink.target; - else if (window.parent.parentData['linkCmbTarget']) - var sTarget = window.parent.parentData['linkCmbTarget']; - - if ( sTarget && sTarget.length > 0 ) - { - if ( oRegex.ReserveTarget.test( sTarget ) ) - { - sTarget = sTarget.toLowerCase() ; - GetE('cmbTarget').value = sTarget ; - } - else - GetE('cmbTarget').value = '' ; - } - } - GetE('cmbLinkType').value = sType ; - SetLinkType( sType ); -} - - -//#### Link type selection. -function SetLinkType( linkType ) -{ - if (linkType == 'email') { - ShowE('divNoMail1',0); - ShowE('divNoMail2',0); - ShowE('divNoMail3',0); - } else { - ShowE('divNoMail1',1); - ShowE('divNoMail2',1); - ShowE('divNoMail3',1); - } - if (linkType != 'internal') - ShowE( 'divNoAnchor' , 0 ) ; - - ShowE('divLinkTypeInternal' , (linkType == 'internal') ) ; - ShowE('divLinkTypeExternal' , (linkType == 'external') ) ; - ShowE('divLinkTypeEMail' , (linkType == 'email') ) ; - ShowE('divLinkTypeFile' , (linkType == 'Doc') ) ; - - if(GetE('cmbTarget')) { - if (GetE('cmbTarget').value == 'popup' ) { - ShowE('divPopupSize',1); - } else - ShowE('divPopupSize',0); - } else - ShowE('divPopupSize',0); - - if ( linkType == 'internal' ) - LoadResources(); - - if ( linkType == 'email') - window.parent.SetAutoSize( true ) ; -} - -function LoadResources() -{ - var oXML = new FCKXml() ; - var sConnUrl = 'filemanager/browser/default/connectors/php/connector.php?Command=GetCmsTree'; - sConnUrl = window.location.href.replace( /dialog.*$/, '' ) + sConnUrl ; - oXML.LoadUrl(sConnUrl, GetCmsTreeCallBack ) ; // Asynchronous load. -} - -function GetCmsTreeCallBack( fckXml ) -{ -// alert(show_props(fckXml, 'oNodes')); - var oNodes = fckXml.SelectNodes( 'Connector/CmsPages/CmsPage' ) ; - - for ( var i = 0 ; i < oNodes.length ; i++ ) - { - var sCmsPage = oNodes[i].attributes.getNamedItem('path').value ; - var sCmsId = oNodes[i].attributes.getNamedItem('st_id').value ; - - var real_url = false; - if (sCmsPage == '@@'+sCmsId+'@@') { - real_url = oNodes[i].attributes.getNamedItem('real_url').value ; - links_path[i] = real_url; - } - - var sTitle = oNodes[i].attributes.getNamedItem('title').value ; - ServerPath = oNodes[i].attributes.getNamedItem('serverpath').value; - if (LinkTypeID()) { - links_path[i] = sCmsPage; - GetE('cmbImternalPagName').options[i] = new Option(sTitle, SetIDtag(sCmsId)); - } - else - GetE('cmbImternalPagName').options[i] = new Option(sTitle, sCmsPage); - - if (GetE('txtUrl')) { - tmpUrl = GetE('txtUrl').value; - if (tmpUrl.length == 0 && i == 0) { - window.frames["frmInternal"].document.location.href = ServerPath + sCmsPage+GetAdmin(); - } - //alert(tmpUrl+' === '+sCmsPage); - if (LinkTypeID()) - { - if (EncodeHrefTag(tmpUrl) == SetIDtagEncode(sCmsId)) { - GetE('cmbImternalPagName').options[i].selected=1; - //alert(ServerPath+sCmsPage+GetAdmin()); - window.frames["frmInternal"].document.location.href = ServerPath+sCmsPage+GetAdmin(); - } - } else { - if (tmpUrl.match(sCmsPage+'$')) { - GetE('cmbImternalPagName').options[i].selected=1; - //alert(tmpUrl+GetAdmin()); - if (real_url) { - window.frames["frmInternal"].document.location.href = real_url; - } - else { - window.frames["frmInternal"].document.location.href = tmpUrl+GetAdmin(); - } - } - } - } - } -} - -function LinkTypeID() -{ - if (typeof(oEditor.FCKConfig.LocalLinkType) != 'undefined') - { - if (oEditor.FCKConfig.LocalLinkType == 'ID') - return true; - } - return false; -} - -function SetIDtagEncode(id) -{ - return "<%cms:GetBlockData id='"+id+"' field='href'%>"; -} - -function SetIDtagNoLtQt(id) -{ - return "<%cms:GetBlockData id='"+id+"' field='href'%>"; -} - -function SetIDtag(id) -{ - return "<%cms:GetBlockData id='"+id+"' field='href'%>"; -} -function SetIDtagAMP(id) -{ - return "&lt;%cms:GetBlockData id='"+id+"' field='href'%&gt;"; -} - -function ChangeInternalUrl(url,obj) -{ -// alert('ChangeInternalUrl '+ServerPath + url+GetAdmin()); - if( LinkTypeID() || url.match(/@@[0-9]+@@/) ) { -// alert('by Link ID') - for (var i=0; i < obj.options.length; i++) { - if (obj.options[i].value == url) { - url=links_path[i]; - window.frames["frmInternal"].document.location.href = ServerPath + url + GetAdmin(); - return; - } - } - } else { -// alert('no link ID'); - window.frames["frmInternal"].document.location.href = ServerPath + url+GetAdmin(); - } -} - -function EncodeHrefTag(text) -{ - if ( typeof( text ) != "string" ) - text = text.toString() ; - //alert(text); - text = text.replace(/&lt;/g, "<"); - text = text.replace(/</g, "<"); - text = text.replace(/&gt;/g, ">"); - text = text.replace(/>/g, ">"); - text = text.replace(/%27/g, "\'") ; - text = text.replace(/%3C/g, "<") ; - text = text.replace(/%3E/g, ">") ; - text = text.replace(/%&39/g, "\"") ; - //text = text.replace(/-/g, "-") ; - text = text.replace(/%20/g, " ") ; - return text ; -} - - - - -function GetAdmin() -{ - if (typeof(oEditor.FCKConfig.K4) && oEditor.FCKConfig.K4 ) { - return '?admin=1'; - } - if (typeof(oEditor.FCKConfig.Admin) != 'undefined' && oEditor.FCKConfig.Admin == 1) { - add_admin = '&admin=1&cmseditor=1'; - if (typeof(oEditor.FCKConfig.AdminSid) != 'undefined') { - add_admin+='&sid='+oEditor.FCKConfig.AdminSid; - } - if (oEditor.FCKConfig.Admin == 1) { - return add_admin; - } - else { - return ''; - } - } - else { - return ''; - } -} - - - - -function show_props(obj, objName) { - var result = ""; - for (var i in obj) { - alert( objName + "." + i + " = " + obj[i] + " \n" ); - } - } - -//#### Target type selection. -function SetTarget( targetType ) -{ - - switch ( targetType ) - { - case "_blank" : - case "_self" : - case "_parent" : - case "_top" : - GetE('cmbTarget').value = targetType ; - break ; - case "" : - GetE('cmbTarget').value = '' ; - break ; - } - - if ( targetType == 'popup' ) - { - ShowE('divPopupSize',1); - window.parent.SetAutoSize( true ) ; - if (!GetE('txtPopupWidth').value) - GetE('txtPopupWidth').value = 800; - if (!GetE('txtPopupHeight').value) - GetE('txtPopupHeight').value = 600; - } else - ShowE('divPopupSize',0); -} - -//#### Called while the user types the URL. -function OnUrlChange() -{ - //alert("OnUrlChange "+ sUrl); - var sUrl = GetE('txtUrl').value ; - var sProtocol = oRegex.UrlOnChangeProtocol.exec( sUrl ) ; - - if ( sProtocol ) - { - sUrl = sUrl.substr( sProtocol[0].length ) ; - GetE('txtUrl').value = sUrl ; - GetE('cmbLinkProtocol').value = sProtocol[0].toLowerCase() ; - } - else if ( oRegex.UrlOnChangeTestOther.test( sUrl ) ) - { - GetE('cmbLinkProtocol').value = '' ; - } -} - -//#### Called while the user types the target name. -function OnTargetNameChange() -{ -} - -//#### Builds the javascript URI to open a popup to the specified URI. -function BuildPopupUri( uri ) -{ - var ret = "javascript:openwincms('"+uri+"','popup',"+GetE('txtPopupWidth').value+","+GetE('txtPopupHeight').value+")"; - return ret; //void(window.open('" + uri + "'," + sWindowName + ",'" + sFeatures + "'))" ) ; -} - -//#### The OK button was hit. - -function BuildUrlByType() -{ - switch ( GetE('cmbLinkType').value ) - { - - case 'internal' : - if (LinkTypeID()) - sUri = GetE('cmbImternalPagName').value - else - sUri = ServerPath+GetE('cmbImternalPagName').value; - //sUri = GetE('cmbLinkProtocol').value + sUri ; - //alert(sUri); - var cmbAnchorName = GetE('cmbAnchorName').value - if (cmbAnchorName.length > 0) - sUri = sUri+'#'+cmbAnchorName - - if( GetE('cmbTarget').value == 'popup' ) - sUri = BuildPopupUri( sUri ) ; - break ; - - case 'Doc' : - sUri = GetE('fileUrl').value ; - - if ( sUri.length == 0 ) - { - alert( FCKLang.DlnLnkMsgNoUrl ) ; - return false ; - } - - //sUri = sUri ; - - if( GetE('cmbTarget').value == 'popup' ) - sUri = BuildPopupUri( sUri ) ; - - break ; - - case 'external' : - sUri = GetE('txtUrl').value ; - - if ( sUri.length == 0 ) - { - alert( FCKLang.DlnLnkMsgNoUrl ) ; - return false ; - } - - sUri = GetE('cmbLinkProtocol').value + sUri ; - - if( GetE('cmbTarget').value == 'popup' ) - sUri = BuildPopupUri( sUri ) ; - - break ; - - - case 'email' : - sUri = GetE('txtEMailAddress').value ; - - if ( sUri.length == 0 ) - { - alert( FCKLang.DlnLnkMsgNoEMail ) ; - return false ; - } - - sUri = oParser.CreateEMailUri( - sUri, - GetE('txtEMailSubject').value, - GetE('txtEMailBody').value ) ; - break ; - } - return sUri; -} - -function Ok() -{ - var sUri = BuildUrlByType(); - if (sUri == false) - return false; - - if (window.location.search.substr(1) == 'from') { - updateDataArray(); - window.location.href='dialog/fck_image.html?create'; - return ; - } - - if ( oLink ) - oLink.href = sUri ; - else - { - oLink = oEditor.FCK.CreateLink( sUri ) ; - if ( ! oLink ) - return true ; - } - - if( GetE('cmbTarget').value != 'popup' ) - SetAttribute( oLink, 'target', GetE('cmbTarget').value ) ; - else - SetAttribute( oLink, 'target', null ) ; - - if (GetE('txtAlt')) { - SetAttribute( oLink, 'alt', GetE('txtAlt').value) ; - SetAttribute( oLink, 'title', GetE('txtAlt').value) ; - } - SetAttribute( oLink, 'label', GetE('cmbLinkType').value) - /* - if ( oEditor.FCKBrowserInfo.IsIE ) - oLink.style.cssText = GetE('txtAttStyle').value ; - else - SetAttribute( oLink, 'style', GetE('txtAttStyle').value ) ; -*/ - return true ; -} - -function show_props(obj, objName) { - var result = ""; - for (var i in obj) { - result = objName + "." + i + " = " + obj[i] + " \n"; - alert(result); - } - //return result; - } - -function BrowseServer(field) -{ - // Set the browser window feature - urlField = field; - var iWidth = oEditor.FCKConfig.ImageBrowserWindowWidth ; - var iHeight = oEditor.FCKConfig.ImageBrowserWindowHeight ; - - - var iLeft = (screen.width - iWidth) / 2 ; - var iTop = (screen.height - iHeight) / 2 ; - - var sOptions = "toolbar=no,status=no,resizable=yes,dependent=yes" ; - sOptions += ",width=" + iWidth ; - sOptions += ",height=" + iHeight ; - sOptions += ",left=" + iLeft ; - sOptions += ",top=" + iTop ; - - // Open the browser window. - var oWindow = window.open( oEditor.FCKConfig.FilesBrowserURL, "FCKBrowseWindow", sOptions ) ; - -} - -function SetUrl( url, width, height, alt, fsize ) -{ - GetE(urlField).value = url ; - - if ( alt ) - GetE('txtAlt').value = alt; -} \ No newline at end of file