Browse Source

[svn r11091] clean import image popup in WCAG editor

Patrick Vandermaesen 18 years ago
parent
commit
008426999a

+ 217 - 0
main/inc/lib/fckeditor/editor/plugins/ImageManagerStandalone/genericManager.js

@@ -0,0 +1,217 @@
+/**
+ * Functions for the ImageManager, used by manager.php only	
+ * @author $Author: Wei Zhuo $
+ * @version $Id: manager.js 26 2004-03-31 02:35:21Z Wei Zhuo $
+ * @package ImageManager
+ */
+	
+	//set the alignment options
+	function setAlign(align) 
+	{
+		var selection = document.getElementById('f_align');
+		for(var i = 0; i < selection.length; i++)
+		{
+			if(selection.options[i].value == align)
+			{
+				selection.selectedIndex = i;
+				break;
+			}
+		}
+	}
+
+	//initialise the form
+	init = function () 
+	{
+		__dlg_init();
+
+		var uploadForm = document.getElementById('uploadForm');
+		if(uploadForm) uploadForm.target = 'imgManager';
+
+		var param = window.dialogArguments;
+		if (param) 
+		{
+			// strip the extra url details off the passed url. make sure the url still starts with a /
+			param["f_url"] = stripBaseURL(param["f_url"]);
+			if (param["f_url"].indexOf("/") != 0) param["f_url"] = '/'+param["f_url"];
+
+			document.getElementById("f_url").value = param["f_url"];
+			document.getElementById("f_alt").value = param["f_alt"];
+			setAlign(param["f_align"]);
+		}
+
+		document.getElementById("f_url").focus();
+	}
+
+	// Need to strip the base url (and any appended http://... stuff if editing an image
+    function stripBaseURL (string) {
+		// strip off the server name if it exists
+		if (base_url.indexOf('://') == -1) {
+			string = string.replace('https://'+server_name,'');
+			string = string.replace('http://'+server_name,'');
+		}
+
+        // strip off the base url if it exists
+        string = string.replace(base_url, '');
+		return string;
+    
+	};
+
+	//similar to the Files::makeFile() in Files.php
+	function makeURL(pathA, pathB) 
+	{
+		if(pathA.substring(pathA.length-1) != '/')
+			pathA += '/';
+
+		if(pathB.charAt(0) == '/');	
+			pathB = pathB.substring(1);
+
+		return pathA+pathB;
+	}
+
+
+	function updateDir(selection) 
+	{
+		var newDir = selection.options[selection.selectedIndex].value;
+		changeDir(newDir);
+	}
+
+	function goUpDir() 
+	{
+		var selection = document.getElementById('dirPath');
+		var currentDir = selection.options[selection.selectedIndex].text;
+		if(currentDir.length < 2)
+			return false;
+		var dirs = currentDir.split('/');
+		
+		var search = '';
+
+		for(var i = 0; i < dirs.length - 2; i++)
+		{
+			search += dirs[i]+'/';
+		}
+
+		for(var i = 0; i < selection.length; i++)
+		{
+			var thisDir = selection.options[i].text;
+			if(thisDir == search)
+			{
+				selection.selectedIndex = i;
+				var newDir = selection.options[i].value;
+				changeDir(newDir);
+				break;
+			}
+		}
+	}
+
+	function changeDir(newDir) 
+	{
+		if(typeof imgManager != 'undefined')
+			imgManager.changeDir(newDir);
+	}
+
+	function toggleConstrains(constrains) 
+	{
+		var lockImage = document.getElementById('imgLock');
+		var constrains = document.getElementById('constrain_prop');
+
+		if(constrains.checked) 
+		{
+			lockImage.src = "img/locked.gif";	
+			checkConstrains('width') 
+		}
+		else
+		{
+			lockImage.src = "img/unlocked.gif";	
+		}
+	}
+
+	function checkConstrains(changed) 
+	{
+		//alert(document.form1.constrain_prop);
+		var constrains = document.getElementById('constrain_prop');
+		
+		if(constrains.checked) 
+		{
+			var obj = document.getElementById('orginal_width');
+			var orginal_width = parseInt(obj.value);
+			var obj = document.getElementById('orginal_height');
+			var orginal_height = parseInt(obj.value);
+
+			var widthObj = document.getElementById('f_width');
+			var heightObj = document.getElementById('f_height');
+			
+			var width = parseInt(widthObj.value);
+			var height = parseInt(heightObj.value);
+
+			if(orginal_width > 0 && orginal_height > 0) 
+			{
+				if(changed == 'width' && width > 0) {
+					heightObj.value = parseInt((width/orginal_width)*orginal_height);
+				}
+
+				if(changed == 'height' && height > 0) {
+					widthObj.value = parseInt((height/orginal_height)*orginal_width);
+				}
+			}			
+		}
+	}
+
+	function showMessage(newMessage) 
+	{
+		var message = document.getElementById('message');
+		var messages = document.getElementById('messages');
+		if(message.firstChild)
+			message.removeChild(message.firstChild);
+
+		message.appendChild(document.createTextNode(i18n(newMessage)));
+		
+		messages.style.display = "block";
+	}
+
+	function addEvent(obj, evType, fn)
+	{ 
+		if (obj.addEventListener) { obj.addEventListener(evType, fn, true); return true; } 
+		else if (obj.attachEvent) {  var r = obj.attachEvent("on"+evType, fn);  return r;  } 
+		else {  return false; } 
+	} 
+
+	function doUpload() 
+	{
+		
+		var uploadForm = document.getElementById('uploadForm');
+		if(uploadForm)
+			showMessage('Uploading');
+	}
+
+	function refresh()
+	{
+		var selection = document.getElementById('dirPath');
+		updateDir(selection);
+	}
+
+
+	function newFolder() 
+	{
+		var selection = document.getElementById('dirPath');
+		var dir = selection.options[selection.selectedIndex].value;
+
+		Dialog("newFolder.html", function(param) 
+		{
+			if (!param) // user must have pressed Cancel
+				return false;
+			else
+			{
+				var folder = param['f_foldername'];
+				if(folder == thumbdir)
+				{
+					alert(i18n('Invalid folder name, please choose another folder name.'));
+					return false;
+				}
+
+				if (folder && folder != '' && typeof imgManager != 'undefined') 
+					imgManager.newFolder(dir, encodeURI(folder)); 
+			}
+		}, null);
+	}
+
+	addEvent(window, 'load', init);

+ 141 - 0
main/inc/lib/fckeditor/editor/plugins/ImageManagerStandalone/genericManager.php

@@ -0,0 +1,141 @@
+<?php
+/**
+ * The main GUI for the ImageManager.
+ * @author $Author: Wei Zhuo $
+ * @package ImageManager
+ */
+
+require_once('../ImageManager/config.inc.php');
+require_once('../ImageManager/Classes/ImageManager.php');
+
+$manager = new ImageManager($IMConfig);
+$dirs = $manager->getDirs();
+
+?>
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+
+<html>
+<head>
+<title>Insert Image</title>
+<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
+<link href="../ImageManager/assets/manager.css" rel="stylesheet" type="text/css" />	
+
+<script type="text/javascript">
+
+
+	var thumbdir = "<?php echo $IMConfig['thumbnail_dir']; ?>";
+	var base_url = "<?php echo $manager->getBaseURL(); ?>";
+	var server_name = "<?php echo $IMConfig['server_name']; ?>";
+	
+	<?php
+	//It's a teacher
+		if(api_is_allowed_to_edit()){
+			echo "window.resizeTo(600, 430);";
+		}
+		else{
+			echo "window.resizeTo(600, 125);";
+		}
+	?>
+	
+</script>
+
+<script type="text/javascript">
+
+	// Generic Manager function
+	
+	function onLoad() {
+		var imageFileParent = window.opener.document.getElementsByName("imagefile")[0];
+		var imageFile = window.document.getElementById("f_url");
+		imageFile.value = imageFileParent.value; 
+		var imageLabelParent = window.opener.document.getElementsByName("imageLabel")[0];
+		var imageLabel = window.document.getElementById("f_alt");
+		imageLabel.value = imageLabelParent.value;
+		document.getElementById('advanced_settings').style.display='block';
+	}
+	
+	 function onOKLocal() {
+		var imageFileParent = window.opener.document.getElementsByName("imagefile")[0];
+		var imageFile = window.document.getElementById("f_url");
+		if(imageFile.value.indexOf('://') < 0 ) {
+			imageFileParent.value = makeURL( base_url, imageFile.value );		
+		} else {
+			imageFileParent.value = imageFile.value;
+		}
+		
+		var imageLabelParent = window.opener.document.getElementsByName("imageLabel")[0];
+		var imageLabel = window.document.getElementById("f_alt");
+		imageLabelParent.value = imageLabel.value;
+		
+		window.close();
+	 }
+	 
+	 function onCancelLocal() {
+	 	window.close();
+	 }
+	 
+	 //similar to the Files::makeFile() in Files.php
+	function makeURL(pathA, pathB) 
+	{
+		if(pathA.substring(pathA.length-1) != '/')
+			pathA += '/';
+
+		if(pathB.charAt(0) == '/');	
+			pathB = pathB.substring(1);
+
+		return pathA+pathB;
+	}
+
+
+</script>
+
+<script type="text/javascript" src="../ImageManager/assets/popup.js"></script>
+<script type="text/javascript" src="../ImageManager/assets/dialog.js"></script>
+<script type="text/javascript" src="genericManager.js"></script>
+
+</head>
+
+<body onload="onLoad();">
+<div class="title">Insert Image</div>
+<form action="../ImageManager/images.php<?php if(isset($_GET['uploadPath']) && $_GET['uploadPath']!="") echo "?uploadPath=".$_GET['uploadPath']; ?>" id="uploadForm" method="post" enctype="multipart/form-data">
+
+<fieldset <?php if(!api_is_allowed_to_edit()) echo "style='display: none;'"; ?>><legend>Image Manager</legend>
+<div class="dirs">
+	<label for="dirPath">Directory</label>
+	<select name="dir" class="dirWidth" id="dirPath" onchange="updateDir(this)">
+	<option value="/">/</option>
+<?php foreach($dirs as $relative=>$fullpath) { ?>
+		<option value="<?php echo rawurlencode($relative); ?>"><?php echo $relative; ?></option>
+<?php } ?>
+	</select>
+	<a href="#" onclick="javascript: goUpDir();" title="Directory Up"><img src="img/btnFolderUp.gif" height="15" width="15" alt="Directory Up" /></a>
+<?php if($IMConfig['safe_mode'] == false && $IMConfig['allow_new_dir']) { ?>
+	<a href="#" onclick="newFolder();" title="New Folder"><img src="img/btnFolderNew.gif" height="15" width="15" alt="New Folder" /></a>
+<?php } ?>
+	<div id="messages" style="display: none;"><span id="message"></span><img SRC="img/dots.gif" width="22" height="12" alt="..." /></div>
+	<iframe src="../ImageManager/images.php<?php if(isset($_GET['uploadPath']) && $_GET['uploadPath']!="") echo "?uploadPath=".$_GET['uploadPath']; ?>" name="imgManager" id="imgManager" class="imageFrame" scrolling="auto" title="Image Selection" frameborder="0"></iframe>
+</div>
+</fieldset>
+
+
+<!-- image properties -->
+<input type="file" name="upload" id="upload"/>&nbsp;<button type="submit" name="submit" onclick="doUpload();"/>Upload</button>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
+		  <button type="button" class="buttons" onclick="return refresh();" style="display: none">Refresh</button>
+          <button type="button" class="buttons" onclick="return onOKLocal();">OK</button>
+          <button type="button" class="buttons" onclick="return onCancelLocal();">Cancel</button>
+	<table class="inputTable" style="display: none" id="advanced_settings">
+		<tr>
+			<td align="right"><label for="f_url">Image File</label></td>
+			<td><input type="text" id="f_url" class="largelWidth" value="" /></td>
+			<td rowspan="3" align="right">&nbsp;</td>
+		</tr>
+		<tr>
+			<td align="right"><label for="f_alt">Alt</label></td>
+			<td><input type="text" id="f_alt" class="largelWidth" value="" /></td>
+		</tr>
+
+	</table>
+
+	<input type="hidden" id="f_file" name="f_file" />
+</form>
+</body>
+</html>

+ 12 - 0
main/inc/lib/fckeditor/editor/plugins/ImageManagerStandalone/generic_dialog_common.js

@@ -0,0 +1,12 @@
+/**
+ * @author Patrick Vandermaesen
+ */
+function OpenFileBrowser( url, width, height )
+{
+
+	var sOptions = "toolbar=no,status=no,resizable=yes,dependent=yes" ;
+	sOptions += ",width=" + width ;
+	sOptions += ",height=" + height ;
+
+	window.open( url, 'FCKBrowseWindow', sOptions ) ;
+}