From a92780d770e3263a0f611c1bc0aa606bd6dbe2f8 Mon Sep 17 00:00:00 2001 From: "brade%netscape.com" Date: Tue, 1 Aug 2000 14:31:26 +0000 Subject: [PATCH] changes submitted by Dan Haddix (dan6992@hotmail.com); bug #37788 git-svn-id: svn://10.0.0.236/trunk@75321 18797224-902f-48f8-a5cc-f745e15eee43 --- .../editor/ui/dialogs/content/EdImageMap.js | 34 +++++++++++++++++-- .../ui/dialogs/content/EdImageMapShapes.js | 13 +++---- 2 files changed, 39 insertions(+), 8 deletions(-) diff --git a/mozilla/editor/ui/dialogs/content/EdImageMap.js b/mozilla/editor/ui/dialogs/content/EdImageMap.js index 724be49ebcb..6be3f8d39e4 100644 --- a/mozilla/editor/ui/dialogs/content/EdImageMap.js +++ b/mozilla/editor/ui/dialogs/content/EdImageMap.js @@ -28,6 +28,7 @@ var imageElement = null; var mapName = ''; var imageMap = null; var imageEl; +var srcInputValue = null; function Startup(){ if (!InitEditorShell()) @@ -53,6 +54,30 @@ function initDialog(){ heightInput = window.opener.document.getElementById("heightInput"); borderInput = window.opener.document.getElementById("border"); + //check for relative url + if (!((srcInput.value.indexOf("http://") != -1) || (srcInput.value.indexOf("file://") != -1))){ + if (editorShell.editorDocument.location == "about:blank"){ + alert("Relative URLs can only be used on documents which have been saved"); + window.close(); + //TODO: add option to save document now + } + else{ + edDoc = new String(editorShell.editorDocument.location); + imgDoc = new String(srcInput.value); + imgDoc = imgDoc.split("../"); + len = imgDoc.length; + for (i=0; i (String(editorShell.editorDocument.location.protocol).length+2)) + edDoc = edDoc.substring(0, edDoc.lastIndexOf("/")); + } + imgDoc = edDoc+"/"+imgDoc[imgDoc.length-1]; + srcInputValue = imgDoc; + } + } + else{ + srcInputValue = srcInput.value; + } + //Set iframe pointer frameDoc = window.frames[0].document; @@ -77,20 +102,25 @@ function initDialog(){ //Place Image var newImg = frameDoc.createElement("img"); if ( newImg ) { - newImg.setAttribute("src", srcInput.value); + newImg.setAttribute("src", srcInputValue); if (parseInt(widthInput.value) > 0) newImg.setAttribute("width", widthInput.value); if (parseInt(heightInput.value) > 0) newImg.setAttribute("height", heightInput.value); newImg.setAttribute("id", "mainImg"); imageEl = frameDoc.getElementById("bgDiv").appendChild(newImg); + imageEl.addEventListener("error", imgError, false); } //Resize background DIV to fit image fixBgDiv(); //Recreate Image Map if it exists - recreateMap(); + recreateMap(); +} + +function imgError(){ + alert("Error loading image "+srcInputValue+"\nPlease check the URL and try again"); } function fixBgDiv(){ diff --git a/mozilla/editor/ui/dialogs/content/EdImageMapShapes.js b/mozilla/editor/ui/dialogs/content/EdImageMapShapes.js index e88d34d1480..eb699b1c758 100644 --- a/mozilla/editor/ui/dialogs/content/EdImageMapShapes.js +++ b/mozilla/editor/ui/dialogs/content/EdImageMapShapes.js @@ -744,18 +744,19 @@ function zoom(direction, ratio){ } imgEl = frameDoc.getElementById("mainImg"); + bgDiv = frameDoc.getElementById("bgDiv"); dump(imgEl.getAttribute("width")+'\n'); if (ratio > currentZoom){ imgEl.setAttribute("width", (parseInt(imgEl.offsetWidth)*(ratio/currentZoom))); - imgEl.setAttribute("height", (parseInt(imgEl.offsetHeight)*(ratio/currentZoom))); - frameDoc.getElementById("bgDiv").style.width = imgEl.getAttribute("width"); - frameDoc.getElementById("bgDiv").style.height = imgEl.getAttribute("height"); + //imgEl.setAttribute("height", (parseInt(imgEl.offsetHeight)*(ratio/currentZoom)); + bgDiv.style.width = imgEl.offsetWidth; + bgDiv.style.height = imgEl.offsetHeight; } else{ imgEl.setAttribute("width", (parseInt(imgEl.offsetWidth)/(currentZoom/ratio))); - imgEl.setAttribute("height", (parseInt(imgEl.offsetHeight)/(currentZoom/ratio))); - frameDoc.getElementById("bgDiv").style.width = imgEl.getAttribute("width"); - frameDoc.getElementById("bgDiv").style.height = imgEl.getAttribute("height"); + //imgEl.setAttribute("height", (parseInt(imgEl.offsetHeight)/(currentZoom/ratio))); + bgDiv.style.width = imgEl.offsetWidth; + bgDiv.style.height = imgEl.offsetHeight; } currentZoom = ratio; }