⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ocmsimage.js

📁 找了很久才找到到源代码
💻 JS
📖 第 1 页 / 共 2 页
字号:
/*
 * FCKeditor - The text editor for internet
 * Copyright (C) 2003-2006 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/
 * 
 * "Support Open Source software. What about a donation today?"
 * 
 * File Name: fck_image.js
 * 	Scripts related to the Image dialog window (see fck_image.html).
 * 
 * File Authors:
 * 		Frederico Caldeira Knabben (fredck@fckeditor.net)
 *              modified and enhanced by Andreas Zahner
 */

var oEditor		= window.parent.InnerDialogLoaded() ;
var FCK			= oEditor.FCK ;
var FCKLang		= oEditor.FCKLang ;
var FCKConfig		= oEditor.FCKConfig ;
var FCKDebug		= oEditor.FCKDebug ;
var FCKBrowserInfo	= oEditor.FCKBrowserInfo;

/* Enables or disables the enhanced image dialog options */
var showEnhancedOptions = false;

var bImageButton = ( document.location.search.length > 0 && document.location.search.substr(1) == 'ImageButton' ) ;

//#### Dialog Tabs

// Set the dialog tabs.
window.parent.AddTab( 'Info', FCKLang.DlgImgInfoTab ) ;
window.parent.AddTab( 'Gallery', FCKLang.DlgImgGalleryTab ) ;

if ( !bImageButton && !FCKConfig.ImageDlgHideLink )
	window.parent.AddTab( 'Link', FCKLang.DlgImgLinkTab ) ;

if ( FCKConfig.ImageUpload )
	window.parent.AddTab( 'Upload', FCKLang.DlgLnkUpload ) ;

if ( !FCKConfig.ImageDlgHideAdvanced )
	window.parent.AddTab( 'Advanced', FCKLang.DlgAdvancedTag ) ;

// Function called when a dialog tag is selected.
function OnDialogTabChange( tabCode )
{
	ShowE('divInfo'		, ( tabCode == 'Info' ) ) ;
	ShowE('divGallery'	, ( tabCode == 'Gallery' ) ) ;
	ShowE('divLink'		, ( tabCode == 'Link' ) ) ;
	ShowE('divUpload'	, ( tabCode == 'Upload' ) ) ;
	ShowE('divAdvanced'	, ( tabCode == 'Advanced' ) ) ;
}

// Get the selected image (if available).
var oImage = FCK.Selection.GetSelectedElement() ;

if ( oImage && oImage.tagName != 'IMG' && oImage.tagName != 'SPAN' && !( oImage.tagName == 'INPUT' && oImage.type == 'image' ) ) {
	oImage = null ;
}


// Get the active link.
var oLink = FCK.Selection.MoveToAncestorNode("A");

// get the table around the image, if present
var oTable = null;

var oImageOriginal ;

function UpdateOriginal( resetSize )
{
	if ( !eImgPreview )
		return ;
	
	if ( GetE('txtUrl').value.length == 0 )
	{
		oImageOriginal = null ;
		return ;
	}
		
	oImageOriginal = document.createElement( 'IMG' ) ;	// new Image() ;

	if ( resetSize )
	{
		oImageOriginal.onload = function()
		{
			this.onload = null ;
			ResetSizes(true) ;
		}
	}

	oImageOriginal.src = eImgPreview.src ;
}

var bPreviewInitialized ;

window.onload = function()
{
	// Translate the dialog box texts.
	oEditor.FCKLanguageManager.TranslatePage(document) ;

	GetE('btnLockSizes').title = FCKLang.DlgImgLockRatio ;
	GetE('btnResetSize').title = FCKLang.DlgBtnResetSize ;

	// Load the selected element information (if any).
	LoadSelection() ;

	// Show/Hide the "Browse Server" button.
	GetE('tdBrowse').style.display				= FCKConfig.ImageBrowser	? '' : 'none' ;
	GetE('divLnkBrowseServer').style.display	= FCKConfig.LinkBrowser		? '' : 'none' ;

	if (showEnhancedOptions) {
		GetE("enhAltCheck").style.display = "";
		GetE("enhAltBt").style.display = "";
		GetE("enhCopy").style.display = "";
		GetE("enhOrig").style.display = "";
	}

	UpdateOriginal() ;

	// Set the actual uploader URL.
	if ( FCKConfig.ImageUpload )
		GetE('frmUpload').action = FCKConfig.ImageUploadURL ;

	window.parent.SetAutoSize( true ) ;

	// Activate the "OK" button.
	window.parent.SetOkButton( true ) ;

	// initialize the OpenCms image gallery
	setTimeout("showGallerySelectBox()", 200);
	setTimeout("showGalleryItems()", 400);
}

function LoadSelection()
{
	if ( ! oImage ) {
		GetE("txtImageBorder").checked = true;
		setImageBorder();
		GetE('cmbAlign').value = "left";
		return ;
	}

	var altText = "";
	var copyText = "";
	var imgBorder = false;
	var imgHSp = "";
	var imgVSp = "";
	if (FCK.Selection.HasAncestorNode("TABLE")) {
		oTable = FCK.Selection.MoveToAncestorNode("TABLE");
		try {
			var idPart = oTable.getAttribute("id").substring(1);
			if (idPart == oImage.getAttribute("id").substring(1)) {

				var altElem = oEditor.FCK.EditorDocument.getElementById("s" + idPart);
				if (altElem) {
					altText = altElem.firstChild.data;
				}

				var cpElem = oEditor.FCK.EditorDocument.getElementById("c" + idPart);
				if (cpElem) {
					copyText = cpElem.firstChild.data;
				}
				imgHSp = oTable.style.marginLeft;
				imgVSp = oTable.style.marginTop;
				if (imgHSp.indexOf("px") != -1) {	
					imgHSp = imgHSp.substring(0, imgHSp.length - 2);
				}
				if (imgVSp.indexOf("px") != -1) {	
					imgVSp = imgVSp.substring(0, imgVSp.length - 2);
				}
			}
		} catch (e) {}
	} else {
		imgHSp = GetAttribute( oImage, 'hspace', '' );
		imgVSp = GetAttribute( oImage, 'vspace', '' );
	}
	if (altText == "") {
		altText = GetAttribute( oImage, 'alt', '' ) ;
	}

	var sUrl = oImage.getAttribute( '_fcksavedurl' ) ;
	if ( sUrl == null )
		sUrl = GetAttribute( oImage, 'src', '' ) ;

	var paramIndex = sUrl.indexOf("?" + paramScale);
	if (paramIndex != -1) {
		var scaler = createScaler(sUrl.substring(paramIndex + 1));
		sUrl = sUrl.substring(0, paramIndex);
	}

	GetE('txtUrl').value    	= sUrl ;
	GetE('txtAlt').value    	= altText ;
	if (copyText != "") {
		GetE("txtCopyrightText").value = copyText;
	}

	if (imgHSp != "" || imgVSp != "") {
		imgBorder = true;
	}
	
	if (imgBorder) {
		GetE('txtVSpace').value	= imgVSp;
		GetE('txtHSpace').value	= imgHSp;
		GetE("txtImageBorder").checked = true;
	}
	
	GetE('txtBorder').value		= GetAttribute( oImage, 'border', '' ) ;
	GetE('cmbAlign').value		= GetAttribute( oImage, 'align', '' ) ;

	var iWidth, iHeight ;

	var regexSize = /^\s*(\d+)px\s*$/i ;
	
	if ( oImage.style.width )
	{
		var aMatch  = oImage.style.width.match( regexSize ) ;
		if ( aMatch )
		{
			iWidth = aMatch[1] ;
			oImage.style.width = '' ;
		}
	}

	if ( oImage.style.height )
	{
		var aMatch  = oImage.style.height.match( regexSize ) ;
		if ( aMatch )
		{
			iHeight = aMatch[1] ;
			oImage.style.height = '' ;
		}
	}

	GetE('txtWidth').value	= iWidth ? iWidth : GetAttribute( oImage, "width", '' ) ;
	GetE('txtHeight').value	= iHeight ? iHeight : GetAttribute( oImage, "height", '' ) ;

	// Get Advanced Attributes
	GetE('txtAttId').value			= oImage.id ;
	GetE('cmbAttLangDir').value		= oImage.dir ;
	GetE('txtAttLangCode').value	= oImage.lang ;
	GetE('txtAttTitle').value		= oImage.title ;
	GetE('txtAttClasses').value		= oImage.getAttribute('class',2) || '' ;
	GetE('txtLongDesc').value		= oImage.longDesc ;

	if ( oEditor.FCKBrowserInfo.IsIE )
		GetE('txtAttStyle').value	= oImage.style.cssText ;
	else
		GetE('txtAttStyle').value	= oImage.getAttribute('style',2) ;

	if ( oLink )
	{
		var sUrl = oLink.getAttribute( '_fcksavedurl' ) ;
		if ( sUrl == null )
			sUrl = oLink.getAttribute('href',2) ;
	
		GetE('txtLnkUrl').value		= sUrl ;
		GetE('cmbLnkTarget').value	= oLink.target ;
	}

	UpdatePreview(true) ;
}

//#### The OK button was hit.
function Ok()
{
	if ( GetE('txtUrl').value.length == 0 )
	{
		window.parent.SetSelectedTab( 'Info' ) ;
		GetE('txtUrl').focus() ;

		alert( FCKLang.DlgImgAlertUrl ) ;

		return false ;
	}

	var bHasImage = ( oImage != null ) ;

	if ( bHasImage && bImageButton && oImage.tagName == 'IMG' )
	{
		if ( confirm( 'Do you want to transform the selected image on a image button?' ) )
			oImage = null ;
	}
	else if ( bHasImage && !bImageButton && oImage.tagName == 'INPUT' )
	{
		if ( confirm( 'Do you want to transform the selected image button on a simple image?' ) )
			oImage = null ;
	}

	var imgCreated = false;
	
	if ( !bHasImage )
	{
		if ( bImageButton )
		{
			oImage = FCK.EditorDocument.createElement( 'INPUT' ) ;
			oImage.type = 'image' ;
			oImage = FCK.InsertElementAndGetIt( oImage ) ;
		}
		else {
			oImage = FCK.CreateElement( 'IMG' ) ;
			// set flag that image is newly created
			imgCreated = true;
		}
	}
	else
		oEditor.FCKUndo.SaveUndoStep() ;
		
	UpdateImage( oImage, false, true ) ;

	// now its getting difficult, be careful when modifying anything below this comment...

	if (showEnhancedOptions && oLink && (insertSubTitle() || insertCopyright())) {
		// original link has to be removed if a table is created in enhanced options
		FCK.Selection.SelectNode(oLink);
		FCK.ExecuteNamedCommand( 'Unlink' ) ;
	}

	// now we set the image object either to the image or in case of enhanced options to a table element
	oImage = createEnhancedImage();

	if (showEnhancedOptions && oTable != null && oTable.id.substring(0, 5) == "timg_") {
		// table is already present, select it
		FCK.Selection.SelectNode(oTable);
		
	}

	if (!imgCreated) {
		// delete the selection (either the image or the complete table) if the image was not freshly created
		FCK.Selection.Delete();
		// now insert the new element
		oImage = oEditor.FCK.InsertElementAndGetIt(oImage);
	} else {
		// this handles the initial creation of an image, might be buggy...
		if (!oEditor.FCKBrowserInfo.IsIE) {
			// we have to differ here, otherwise the stupid IE creates the image twice!
			oImage = oEditor.FCK.InsertElementAndGetIt(oImage);
		} else if (isTablePreview()) {
			// in IE... insert the new element to make sure the table is inserted
			oImage = oEditor.FCK.InsertElementAndGetIt(oImage);
		}
	}

	
	if (oImage.tagName != "TABLE") {
		// the object to insert is a simple image, check the link to set
		FCK.Selection.SelectNode(oImage);

		oLink = FCK.Selection.MoveToAncestorNode("A");


		var sLnkUrl = GetE('txtLnkUrl').value.Trim();
		var linkOri = "";

 		if (insertLinkToOriginal()) {
			sLnkUrl = "#";
			linkOri = getLinkToOriginal();
		} else if (sLnkUrl == "#") {
			sLnkUrl = "";
		}
	
		if ( sLnkUrl.length == 0 )
		{
			if ( oLink )
				FCK.ExecuteNamedCommand( 'Unlink' ) ;
		}
			else
		{
			if ( oLink ) {	
				// remove an existent link and create it newly, because otherwise the "onclick" attribute does not vanish in Mozilla
				FCK.ExecuteNamedCommand( 'Unlink' ) ;
				oLink = oEditor.FCK.CreateLink( sLnkUrl ) ;
			}
			else			// Creating a new link.
			{
				if ( !bHasImage )
					oEditor.FCKSelection.SelectNode( oImage ) ;

				oLink = oEditor.FCK.CreateLink( sLnkUrl ) ;	

				if ( !bHasImage )
				{
					oEditor.FCKSelection.SelectNode( oLink ) ;
					oEditor.FCKSelection.Collapse( false ) ;
				}
			}

			if (linkOri != "") {
				// set the necessary attributes for the link to original image
				try {
					oLink.setAttribute("id", "limg_" + activeImage.hashCode);
					oLink.setAttribute("onclick", linkOri);
					if (GetE('txtBorder').value == "") {
						oImage.setAttribute("border", "0");
					}
				} catch (e) {}
			}
			try {
				SetAttribute( oLink, '_fcksavedurl', sLnkUrl ) ;
				SetAttribute( oLink, 'target', GetE('cmbLnkTarget').value ) ;
			} catch (e) {}
		}

	} // end simple image tag

	return true;
}

function createEnhancedImage() {
	if (isTablePreview()) {

		var oNewTable= oEditor.FCK.EditorDocument.createElement("TABLE");
		// now set the table attributes		
		var st = "width: " + GetE("txtWidth").value + "px;";
		var al = GetE("cmbAlign").value;
		if (al == "left" || al == "right") {
			st += " float: " + al + ";";
		}
		var imgVSp = GetE('txtVSpace').value;
		var imgHSp = GetE('txtHSpace').value;
		if (imgVSp != "" || imgHSp != "") {
			if (imgVSp == "") {
				imgVSp = "0";
			}
			if (imgHSp == "") {
				imgHSp = "0";
			}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -