зеркало из https://github.com/mozilla/gecko-dev.git
Fixed all property dialogs to use global onAdvancedEdit() feature. Moved lots of JS strings into string bundle file.
This commit is contained in:
Родитель
cf36828223
Коммит
dd1fea4e79
|
@ -23,5 +23,11 @@ SaveFileFailed=Saving file failed!
|
|||
DocumentTitle=Document Title
|
||||
NeedDocTitle=Document does not have a title.
|
||||
AttributesFor=Current attributes for:
|
||||
|
||||
|
||||
MissingImageError=Please enter or choose an image\nof type gif, jpg or png.
|
||||
EmptyHREFError=You must enter or choose\na location (URL) to create a new link.
|
||||
EmptyLinkTextError=You must enter some text for this link.
|
||||
ValidateNumber1=The number you entered (
|
||||
ValidateNumber2=) is outside of allowed range.\nPlease enter a number between
|
||||
ValidateNumber3=and
|
||||
MissingAnchorNameError=You must enter a name for this anchor.
|
||||
DuplicateAnchorNameError=already exists in this page.\nPlease enter a different name.
|
||||
|
|
|
@ -122,3 +122,5 @@ titledbutton#SaveButton[dirty="true"] {
|
|||
list-style-image:url(chrome://editor/skin/images/ED_SaveMod.gif);
|
||||
}
|
||||
|
||||
// Override the browser's pointer cursor over links
|
||||
a { cursor: default; }
|
||||
|
|
|
@ -54,7 +54,7 @@ function Startup()
|
|||
// TODO: REMOVE THIS WHEN WE CAN RESIZE DIALOG AFTER CREATION
|
||||
msgParent.removeChild(msgParent.firstChild);
|
||||
|
||||
var msg = editorShell.GetString("AttributesFor");
|
||||
var msg = GetString("AttributesFor");
|
||||
dump("Tagname Msg = "+msg+"\n");
|
||||
msg +=(" "+element.nodeName);
|
||||
dump("Tagname Msg = "+msg+"\n");
|
||||
|
|
|
@ -134,7 +134,7 @@ function ValidateNumberString(value, minValue, maxValue)
|
|||
return number + "";
|
||||
}
|
||||
}
|
||||
message = "The number you entered ("+number+") is outside of allowed range.\nPlease enter a number between "+minValue+" and "+maxValue;
|
||||
message = GetString("ValidateNumber1")+number+GetString("ValidateNumber2")+" "+minValue+" "+GetString("ValidateNumber3")+" "+maxValue;
|
||||
ShowInputErrorMessage(message);
|
||||
|
||||
// Return an empty string to indicate error
|
||||
|
@ -147,6 +147,11 @@ function ShowInputErrorMessage(message)
|
|||
window.openDialog("chrome://editor/content/EdMessage.xul", "MsgDlg", "chrome,close,titlebar,modal", "", message, "Input Error");
|
||||
}
|
||||
|
||||
function GetString(name)
|
||||
{
|
||||
return editorShell.GetString(name);
|
||||
}
|
||||
|
||||
function TrimStringLeft(string)
|
||||
{
|
||||
if(!StringExists(string))
|
||||
|
@ -396,7 +401,32 @@ function forceInteger(elementID)
|
|||
}
|
||||
}
|
||||
|
||||
// All dialogs share this simple method
|
||||
|
||||
function onAdvancedEdit()
|
||||
{
|
||||
// First validate data from widgets in the "simpler" property dialog
|
||||
if (ValidateData()) {
|
||||
// Set true if OK is clicked in the Advanced Edit dialog
|
||||
window.AdvancedEditOK = false;
|
||||
// Open the AdvancedEdit dialog, passing in the element to be edited
|
||||
// (the copy named "globalElement")
|
||||
window.openDialog("chrome://editor/content/EdAdvancedEdit.xul", "AdvancedEdit", "chrome,close,titlebar,modal", "", globalElement);
|
||||
if (window.AdvancedEditOK) {
|
||||
dump("Advanced Dialog closed with OK\n");
|
||||
// Copy edited attributes to the dialog widgets:
|
||||
// to setup for validation
|
||||
InitDialog();
|
||||
// Try to just close the parent dialog as well,
|
||||
// but this will do validation first
|
||||
if (onOK()) {
|
||||
// I'm not sure why, but calling onOK() from JS doesn't trigger closing
|
||||
// automatically as it does when you click on the OK button!
|
||||
window.close();
|
||||
}
|
||||
}
|
||||
// Should we Cancel the parent dialog if user Cancels in AdvancedEdit?
|
||||
}
|
||||
}
|
||||
|
||||
function onCancel()
|
||||
{
|
||||
|
|
|
@ -2,6 +2,28 @@
|
|||
|
||||
<!DOCTYPE window SYSTEM "chrome://editor/locale/EdDialogOverlay.dtd">
|
||||
|
||||
<!--
|
||||
- The contents of this file are subject to the Netscape Public
|
||||
- License Version 1.1 (the "License"); you may not use this file
|
||||
- except in compliance with the License. You may obtain a copy of
|
||||
- the License at http://www.mozilla.org/NPL/
|
||||
-
|
||||
- Software distributed under the License is distributed on an "AS
|
||||
- IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||
- implied. See the License for the specific language governing
|
||||
- rights and limitations under the License.
|
||||
-
|
||||
- The Original Code is Mozilla Communicator client code, released
|
||||
- March 31, 1998.
|
||||
-
|
||||
- The Initial Developer of the Original Code is Netscape
|
||||
- Communications Corporation. Portions created by Netscape are
|
||||
- Copyright (C) 1998-1999 Netscape Communications Corporation. All
|
||||
- Rights Reserved.
|
||||
-
|
||||
- Contributor(s):
|
||||
-->
|
||||
|
||||
<overlay id="EdDialogOverlay"
|
||||
xmlns:html="http://www.w3.org/TR/REC-html40"
|
||||
xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
|
||||
|
|
|
@ -66,6 +66,9 @@ function Startup()
|
|||
dialog.heightInput.focus();
|
||||
}
|
||||
|
||||
// Set dialog widgets with attribute data
|
||||
// We get them from globalElement copy so this can be used
|
||||
// by AdvancedEdit(), which is shared by all property dialogs
|
||||
function InitDialog()
|
||||
{
|
||||
// Just to be confusing, "size" is used instead of height
|
||||
|
@ -137,23 +140,8 @@ function onSaveDefault()
|
|||
}
|
||||
}
|
||||
|
||||
function onAdvancedEdit()
|
||||
{
|
||||
if (ValidateData()) {
|
||||
// Set true if OK is clicked in the Advanced Edit dialog
|
||||
window.AdvancedEditOK = false;
|
||||
window.openDialog("chrome://editor/content/EdAdvancedEdit.xul", "AdvancedEdit", "chrome,close,titlebar,modal", "", globalElement);
|
||||
if (window.AdvancedEditOK) {
|
||||
dump("OK was pressed in AdvancedEdit Dialog\n");
|
||||
// Copy edited attributes to the dialog widgets:
|
||||
// Note that we still don't want
|
||||
InitDialog();
|
||||
} else {
|
||||
dump("OK was NOT pressed in AdvancedEdit Dialog\n");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Get and validate data from widgets.
|
||||
// Set attributes on globalElement so they can be accessed by AdvancedEdit()
|
||||
function ValidateData()
|
||||
{
|
||||
// Height is always pixels
|
||||
|
|
|
@ -100,6 +100,9 @@ function Startup()
|
|||
window.close();
|
||||
}
|
||||
}
|
||||
|
||||
// Make a copy to use for AdvancedEdit
|
||||
globalElement = imageElement.cloneNode(false);
|
||||
|
||||
// Initialize all widgets with image attributes
|
||||
InitDialog();
|
||||
|
@ -107,11 +110,14 @@ function Startup()
|
|||
dialog.srcInput.focus();
|
||||
}
|
||||
|
||||
// Set dialog widgets with attribute data
|
||||
// We get them from globalElement copy so this can be used
|
||||
// by AdvancedEdit(), which is shared by all property dialogs
|
||||
function InitDialog() {
|
||||
|
||||
// Set the controls to the image's attributes
|
||||
|
||||
str = imageElement.getAttribute("src");
|
||||
str = globalElement.getAttribute("src");
|
||||
if ( str == "null" )
|
||||
{
|
||||
str = "";
|
||||
|
@ -119,7 +125,7 @@ function InitDialog() {
|
|||
|
||||
dialog.srcInput.value = str;
|
||||
|
||||
str = imageElement.getAttribute("alt");
|
||||
str = globalElement.getAttribute("alt");
|
||||
|
||||
if ( str == "null" )
|
||||
{
|
||||
|
@ -134,7 +140,7 @@ function InitDialog() {
|
|||
// set height and width
|
||||
// note: need to set actual image size if no attributes
|
||||
|
||||
dimvalue = imageElement.getAttribute("width");
|
||||
dimvalue = globalElement.getAttribute("width");
|
||||
|
||||
if ( dimvalue == "null" )
|
||||
{
|
||||
|
@ -142,7 +148,7 @@ function InitDialog() {
|
|||
}
|
||||
dialog.imagewidthInput.value = dimvalue;
|
||||
|
||||
dimvalue = imageElement.getAttribute("height");
|
||||
dimvalue = globalElement.getAttribute("height");
|
||||
if ( dimvalue == "null" )
|
||||
{
|
||||
dimvalue = "";
|
||||
|
@ -154,8 +160,8 @@ function InitDialog() {
|
|||
if (insertNew == false)
|
||||
{
|
||||
|
||||
var wdh = imageElement.getAttribute("width");
|
||||
var hgt = imageElement.getAttribute("height");
|
||||
var wdh = globalElement.getAttribute("width");
|
||||
var hgt = globalElement.getAttribute("height");
|
||||
ispercentw = wdh.substr(wdh.length-1, 1);
|
||||
ispercenth = hgt.substr(hgt.length-1, 1);
|
||||
|
||||
|
@ -181,7 +187,7 @@ function InitDialog() {
|
|||
|
||||
if ( alignpopup )
|
||||
{
|
||||
alignvalue = imageElement.getAttribute("align");
|
||||
alignvalue = globalElement.getAttribute("align");
|
||||
|
||||
if ( alignvalue == "" )
|
||||
{
|
||||
|
@ -198,13 +204,13 @@ function InitDialog() {
|
|||
|
||||
// set spacing editfields
|
||||
|
||||
sizevalue = imageElement.getAttribute("hspace");
|
||||
sizevalue = globalElement.getAttribute("hspace");
|
||||
dialog.imagelrInput.value = sizevalue;
|
||||
|
||||
sizevalue = imageElement.getAttribute("vspace");
|
||||
sizevalue = globalElement.getAttribute("vspace");
|
||||
dialog.imagetbInput.value = sizevalue;
|
||||
|
||||
sizevalue = imageElement.getAttribute("border");
|
||||
sizevalue = globalElement.getAttribute("border");
|
||||
dialog.imageborderInput.value = sizevalue;
|
||||
|
||||
// force wasEnableAll to be different so everything gets updated
|
||||
|
@ -493,28 +499,25 @@ function constrainProportions( srcID, destID )
|
|||
oldSourceInt = srcElement.value;
|
||||
}
|
||||
|
||||
function onAdvancedEdit()
|
||||
// Get data from widgets, validate, and set for the global element
|
||||
// accessible to AdvancedEdit() [in EdDialogCommon.js]
|
||||
function ValidateData()
|
||||
{
|
||||
dump("\n\n Need to write onAdvancedEdit for Image dialog\n\n");
|
||||
}
|
||||
|
||||
function onOK()
|
||||
{
|
||||
if ( !imageType ) {
|
||||
dump("alert *** please choose an image of typ gif, jpg or png.\n\n");
|
||||
return false;
|
||||
if ( !imageType ) {
|
||||
ShowInputErrorMessage(GetString("MissingImageError"));
|
||||
return false;
|
||||
}
|
||||
|
||||
imageElement.setAttribute("src",dialog.srcInput.value);
|
||||
|
||||
// We must convert to "file:///" format else image doesn't load!
|
||||
//TODO: WE NEED TO DO SOME URL VALIDATION HERE, E.G.:
|
||||
// We must convert to "file:///" or "http://" format else image doesn't load!
|
||||
globalElement.setAttribute("src",dialog.srcInput.value);
|
||||
|
||||
// TODO: we should confirm with user if no alt tag
|
||||
|
||||
imageElement.setAttribute("alt", dialog.altTextInput.value);
|
||||
// TODO: Should we confirm with user if no alt tag? Or just set to empty string?
|
||||
globalElement.setAttribute("alt", dialog.altTextInput.value);
|
||||
|
||||
// set width if custom size and width is greater than 0
|
||||
|
||||
// Note: This accepts and empty string as meaning "don't set
|
||||
// BUT IT ALSO ACCEPTS 0. Should use ValidateNumberString() to tell user proper range
|
||||
if ( dialog.customsizeRadio.checked
|
||||
&& ( dialog.imagewidthInput.value.length > 0 )
|
||||
&& ( dialog.imageheightInput.value.length > 0 ) )
|
||||
|
@ -523,62 +526,73 @@ function onOK()
|
|||
}
|
||||
else
|
||||
{
|
||||
imageElement.removeAttribute( "width" );
|
||||
imageElement.removeAttribute( "height" );
|
||||
//TODO: WE SHOULD ALWAYS SET WIDTH AND HEIGHT FOR FASTER IMAGE LAYOUT
|
||||
// IF USER DOESN'T SET IT, WE NEED TO GET VALUE FROM ORIGINAL IMAGE
|
||||
globalElement.removeAttribute( "width" );
|
||||
globalElement.removeAttribute( "height" );
|
||||
}
|
||||
|
||||
// spacing attributes
|
||||
|
||||
// All of these should use ValidateNumberString() to
|
||||
// ensure value is within acceptable range
|
||||
if ( dialog.imagelrInput.value.length > 0 )
|
||||
imageElement.setAttribute( "hspace", dialog.imagelrInput.value );
|
||||
globalElement.setAttribute( "hspace", dialog.imagelrInput.value );
|
||||
else
|
||||
imageElement.removeAttribute( "hspace" );
|
||||
globalElement.removeAttribute( "hspace" );
|
||||
|
||||
if ( dialog.imagetbInput.value.length > 0 )
|
||||
imageElement.setAttribute( "vspace", dialog.imagetbInput.value );
|
||||
globalElement.setAttribute( "vspace", dialog.imagetbInput.value );
|
||||
else
|
||||
imageElement.removeAttribute( "vspace" );
|
||||
globalElement.removeAttribute( "vspace" );
|
||||
|
||||
// note this is deprecated and should be converted to stylesheets
|
||||
|
||||
if ( dialog.imageborderInput.value.length > 0 )
|
||||
imageElement.setAttribute( "border", dialog.imageborderInput.value );
|
||||
globalElement.setAttribute( "border", dialog.imageborderInput.value );
|
||||
else
|
||||
imageElement.removeAttribute( "border" );
|
||||
globalElement.removeAttribute( "border" );
|
||||
|
||||
// This currently triggers a "Not implemented" assertion, preventing inserting an image
|
||||
// TODO: FIX THIS!
|
||||
/*
|
||||
alignpopup = document.getElementById("image.alignType");
|
||||
if ( alignpopup )
|
||||
{
|
||||
alignpopup.getAttribute( "value", alignvalue );
|
||||
dump( "popup value = " + alignvalue + "\n" );
|
||||
// TODO: FIX THIS!
|
||||
// NO! DON'T DEPEND ON ENGLISH STRINGS
|
||||
if ( alignvalue == "at the bottom" )
|
||||
imageElement.removeAttribute("align");
|
||||
globalElement.removeAttribute("align");
|
||||
else
|
||||
imageElement.setAttribute("align", alignvalue );
|
||||
globalElement.setAttribute("align", alignvalue );
|
||||
}
|
||||
*/
|
||||
// handle insertion of new image
|
||||
|
||||
if (insertNew)
|
||||
{
|
||||
// 'true' means delete the selection before inserting
|
||||
|
||||
editorShell.InsertElement(imageElement, true);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
function onOK()
|
||||
{
|
||||
// handle insertion of new image
|
||||
if (ValidateData())
|
||||
{
|
||||
// All values are valid - copy to actual element in doc or
|
||||
// element created to insert
|
||||
editorShell.CloneAttributes(imageElement, globalElement);
|
||||
if (insertNew)
|
||||
{
|
||||
// 'true' means delete the selection before inserting
|
||||
editorShell.InsertElement(imageElement, true);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
// setDimensions()
|
||||
// sets height and width attributes to inserted image
|
||||
// Brian King - XML Workshop
|
||||
// TODO: THIS NEEDS TO BE MODIFIED TO USE LOCALIZED STRING BUNDLE,
|
||||
// e.g., this assumes "% of"
|
||||
// Use editorShell.GetString("name") to get a string and
|
||||
// define those strings in editor\ui\dialogs\content\editor.properties
|
||||
// Note that using localized strings will break assumption about location of "% of"
|
||||
|
||||
function setDimensions()
|
||||
{
|
||||
|
||||
|
@ -586,22 +600,24 @@ function setDimensions()
|
|||
var htype = dialog.imageheightSelect.getAttribute("value");
|
||||
|
||||
// width
|
||||
// NO! this is not the way to do it! Depends on english strings
|
||||
// Instead, store which index is selected when popup "pixel" or "percent of..." is used
|
||||
if (wtype.substr(0,4) == "% of")
|
||||
{
|
||||
//var Iwidth = eval("dialog.imagewidthInput.value + '%';");
|
||||
imageElement.setAttribute("width", dialog.imagewidthInput.value + "%");
|
||||
globalElement.setAttribute("width", dialog.imagewidthInput.value + "%");
|
||||
}
|
||||
else
|
||||
imageElement.setAttribute("width", dialog.imagewidthInput.value);
|
||||
globalElement.setAttribute("width", dialog.imagewidthInput.value);
|
||||
|
||||
//height
|
||||
if (htype.substr(0,4) == "% of")
|
||||
{
|
||||
//var Iheight = eval("dialog.imageheightInput.value + '%';");
|
||||
imageElement.setAttribute("height", dialog.imageheightInput.value + "%");
|
||||
globalElement.setAttribute("height", dialog.imageheightInput.value + "%");
|
||||
}
|
||||
else
|
||||
imageElement.setAttribute("height", dialog.imageheightInput.value);
|
||||
globalElement.setAttribute("height", dialog.imageheightInput.value);
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -29,6 +29,8 @@ var maxRows = 10000;
|
|||
var maxColumns = 10000;
|
||||
var percentChar = "";
|
||||
var maxPixels = 10000;
|
||||
var rows;
|
||||
var columns;
|
||||
|
||||
// dialog initialization code
|
||||
function Startup()
|
||||
|
@ -53,25 +55,34 @@ function Startup()
|
|||
dialog.widthInput = document.getElementById("width");
|
||||
dialog.borderInput = document.getElementById("border");
|
||||
|
||||
// Make a copy to use for AdvancedEdit
|
||||
globalElement = tableElement.cloneNode(false);
|
||||
|
||||
// Initialize all widgets with image attributes
|
||||
InitDialog();
|
||||
|
||||
dialog.rowsInput.focus();
|
||||
}
|
||||
|
||||
// Set dialog widgets with attribute data
|
||||
// We get them from globalElement copy so this can be used
|
||||
// by AdvancedEdit(), which is shared by all property dialogs
|
||||
function InitData()
|
||||
{
|
||||
// Get default attributes set on the created table:
|
||||
// Get the width attribute of the element, stripping out "%"
|
||||
// This sets contents of button text and "percentChar" variable
|
||||
dialog.widthInput.value = InitPixelOrPercentPopupButton(tableElement, "width", "pixelOrPercentButton");
|
||||
dialog.borderInput.value = tableElement.getAttribute("border");
|
||||
dialog.widthInput.value = InitPixelOrPercentPopupButton(globalElement, "width", "pixelOrPercentButton");
|
||||
dialog.borderInput.value = globalElement.getAttribute("border");
|
||||
|
||||
// Set default number to 1 row, 2 columns:
|
||||
dialog.rowsInput.value = 1;
|
||||
dialog.columnsInput.value = 2;
|
||||
|
||||
dialog.rowsInput.focus();
|
||||
}
|
||||
|
||||
function onAdvancedEdit()
|
||||
{
|
||||
dump("\n\n Need to write onAdvancedEdit for Insert Table dialog\n\n");
|
||||
}
|
||||
|
||||
function onOK()
|
||||
// Get and validate data from widgets.
|
||||
// Set attributes on globalElement so they can be accessed by AdvancedEdit()
|
||||
function ValidateData()
|
||||
{
|
||||
rows = ValidateNumberString(dialog.rowsInput.value, 1, maxRows);
|
||||
if (rows == "") {
|
||||
|
@ -86,29 +97,13 @@ function onOK()
|
|||
dialog.columnsInput.focus();
|
||||
return false;
|
||||
}
|
||||
dump("Rows = "+rows+" Columns = "+columns+"\n");
|
||||
for (i = 0; i < rows; i++)
|
||||
{
|
||||
newRow = editorShell.CreateElementWithDefaults("tr");
|
||||
if (newRow)
|
||||
{
|
||||
tableElement.appendChild(newRow);
|
||||
for (j = 0; j < columns; j++)
|
||||
{
|
||||
newCell = editorShell.CreateElementWithDefaults("td");
|
||||
if (newCell)
|
||||
{
|
||||
newRow.appendChild(newCell);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Set attributes: these may be empty strings
|
||||
borderText = TrimString(dialog.borderInput.value);
|
||||
if (StringExists(borderText)) {
|
||||
// Set the other attributes on the table
|
||||
if (ValidateNumberString(borderText, 0, maxPixels))
|
||||
tableElement.setAttribute("border", borderText);
|
||||
globalElement.setAttribute("border", borderText);
|
||||
}
|
||||
|
||||
widthText = TrimString(dialog.widthInput.value);
|
||||
|
@ -125,7 +120,36 @@ function onOK()
|
|||
if (widthText != "") {
|
||||
widthText += percentChar;
|
||||
dump("Table Width="+widthText+"\n");
|
||||
tableElement.setAttribute("width", widthText);
|
||||
globalElement.setAttribute("width", widthText);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
function onOK()
|
||||
{
|
||||
if (ValidateData())
|
||||
{
|
||||
editorShell.CloneAttributes(tableElement, globalElement);
|
||||
|
||||
// Create necessary rows and cells for the table
|
||||
dump("Rows = "+rows+" Columns = "+columns+"\n");
|
||||
for (i = 0; i < rows; i++)
|
||||
{
|
||||
newRow = editorShell.CreateElementWithDefaults("tr");
|
||||
if (newRow)
|
||||
{
|
||||
tableElement.appendChild(newRow);
|
||||
for (j = 0; j < columns; j++)
|
||||
{
|
||||
newCell = editorShell.CreateElementWithDefaults("td");
|
||||
if (newCell)
|
||||
{
|
||||
newRow.appendChild(newCell);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -28,6 +28,8 @@ var insertLinkAroundSelection = false;
|
|||
var linkTextInput;
|
||||
var hrefInput;
|
||||
var linkMessage;
|
||||
var href;
|
||||
var newLinkText;
|
||||
|
||||
// NOTE: Use "href" instead of "a" to distinguish from Named Anchor
|
||||
// The returned node is has an "a" tagName
|
||||
|
@ -76,9 +78,6 @@ function Startup()
|
|||
editorShell.SelectElement(anchorElement);
|
||||
selection = editorShell.editorSelection;
|
||||
|
||||
// Moved to InitDialog()
|
||||
// hrefInput.value = anchorElement.getAttribute("href");
|
||||
// dump("Current HREF: "+hrefInput.value+"\n");
|
||||
} else {
|
||||
// See if we have a selected image instead of text
|
||||
imageElement = editorShell.GetSelectedElement("img");
|
||||
|
@ -91,7 +90,7 @@ function Startup()
|
|||
if (parent) {
|
||||
anchorElement = parent;
|
||||
insertNew = false;
|
||||
linkCaption.data = editorShell.GetString("LinkImage");
|
||||
linkCaption.data = GetString("LinkImage");
|
||||
// Link source string is the source URL of image
|
||||
// TODO: THIS STILL DOESN'T HANDLE MULTIPLE SELECTED IMAGES!
|
||||
linkMessage.data = imageElement.getAttribute("src");;
|
||||
|
@ -142,6 +141,9 @@ function Startup()
|
|||
dump("insertLinkAroundSelection is TRUE\n");
|
||||
}
|
||||
|
||||
// Make a copy to use for AdvancedEdit and onSaveDefault
|
||||
globalElement = anchorElement.cloneNode(false);
|
||||
|
||||
// Set data for the dialog controls
|
||||
InitDialog();
|
||||
|
||||
|
@ -164,9 +166,12 @@ function Startup()
|
|||
}
|
||||
}
|
||||
|
||||
// Set dialog widgets with attribute data
|
||||
// We get them from globalElement copy so this can be used
|
||||
// by AdvancedEdit(), which is shared by all property dialogs
|
||||
function InitDialog()
|
||||
{
|
||||
hrefInput.value = anchorElement.getAttribute("href");
|
||||
hrefInput.value = globalElement.getAttribute("href");
|
||||
dump("Current HREF: "+hrefInput.value+"\n");
|
||||
}
|
||||
|
||||
|
@ -187,55 +192,70 @@ function RemoveLink()
|
|||
hrefInput.value = "";
|
||||
}
|
||||
|
||||
function onAdvancedEdit()
|
||||
// Get and validate data from widgets.
|
||||
// Set attributes on globalElement so they can be accessed by AdvancedEdit()
|
||||
function ValidateData()
|
||||
{
|
||||
dump("\n\n Need to write onAdvancedEdit for Link dialog\n\n");
|
||||
}
|
||||
|
||||
function onOK()
|
||||
{
|
||||
dump("***** Clicked OK in link props dialog\n");
|
||||
// TODO: VALIDATE FIELDS BEFORE COMMITING CHANGES
|
||||
|
||||
href = TrimString(hrefInput.value);
|
||||
if (href.length > 0) {
|
||||
// Coalesce into one undo transaction
|
||||
editorShell.BeginBatchChanges();
|
||||
|
||||
// Set the HREF directly on the editor document's anchor node
|
||||
// or on the newly-created node if insertNew is true
|
||||
anchorElement.setAttribute("href",href);
|
||||
|
||||
// Get text to use for a new link
|
||||
if (insertNew) {
|
||||
// Append the link text as the last child node
|
||||
// of the anchor node
|
||||
dump("Creating text node\n");
|
||||
newText = TrimString(linkTextInput.value);
|
||||
if (newText.length == 0) {
|
||||
ShowInputErrorMessage("You must enter some text for this link.");
|
||||
linkTextInput.focus();
|
||||
return false;
|
||||
}
|
||||
textNode = editorShell.editorDocument.createTextNode(newText);
|
||||
if (textNode) {
|
||||
anchorElement.appendChild(textNode);
|
||||
}
|
||||
dump("Inserting\n");
|
||||
editorShell.InsertElement(anchorElement, false);
|
||||
} else if (insertLinkAroundSelection) {
|
||||
// Text was supplied by the selection,
|
||||
// so insert a link node as parent of this text
|
||||
dump("Setting link around selected text\n");
|
||||
editorShell.InsertLinkAroundSelection(anchorElement);
|
||||
}
|
||||
editorShell.EndBatchChanges();
|
||||
} else if (!insertNew) {
|
||||
// We already had a link, but empty HREF means remove it
|
||||
editorShell.RemoveTextProperty("a", "");
|
||||
globalElement.setAttribute("href",href);
|
||||
} else if (insertNew) {
|
||||
// We must have a URL to insert a new link
|
||||
//NOTE: WE ACCEPT AN EMPTY HREF TO ALLOW REMOVING AN EXISTING LINK,
|
||||
ShowInputErrorMessage(GetString("EmptyHREFError"));
|
||||
return false;
|
||||
}
|
||||
if (linkTextInput) {
|
||||
// The text we will insert isn't really an attribute,
|
||||
// but it makes sense to validate it
|
||||
newLinkText = TrimString(linkTextInput.value);
|
||||
if (newLinkText.length == 0) {
|
||||
ShowInputErrorMessage(GetString("GetInputError"));
|
||||
linkTextInput.focus();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
// Note: if HREF is empty and we were inserting a new link, do nothing
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
function onOK()
|
||||
{
|
||||
if (ValidateData())
|
||||
{
|
||||
if (href.length > 0) {
|
||||
// Copy attributes to element we are changing or inserting
|
||||
editorShell.CloneAttributes(anchorElement, globalElement);
|
||||
|
||||
// Coalesce into one undo transaction
|
||||
editorShell.BeginBatchChanges();
|
||||
|
||||
// Get text to use for a new link
|
||||
if (insertNew) {
|
||||
// Append the link text as the last child node
|
||||
// of the anchor node
|
||||
dump("Creating text node\n");
|
||||
textNode = editorShell.editorDocument.createTextNode(newLinkText);
|
||||
if (textNode) {
|
||||
anchorElement.appendChild(textNode);
|
||||
}
|
||||
dump("Inserting\n");
|
||||
editorShell.InsertElement(anchorElement, false);
|
||||
} else if (insertLinkAroundSelection) {
|
||||
// Text was supplied by the selection,
|
||||
// so insert a link node as parent of this text
|
||||
dump("Setting link around selected text\n");
|
||||
editorShell.InsertLinkAroundSelection(anchorElement);
|
||||
}
|
||||
editorShell.EndBatchChanges();
|
||||
} else if (!insertNew) {
|
||||
// We already had a link, but empty HREF means remove it
|
||||
editorShell.RemoveTextProperty("a", "");
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
|
@ -24,7 +24,6 @@ var insertNew = true;
|
|||
var tagName = "anchor";
|
||||
var anchorElement = null;
|
||||
var nameInput;
|
||||
var name;
|
||||
|
||||
// dialog initialization code
|
||||
function Startup()
|
||||
|
@ -45,7 +44,6 @@ function Startup()
|
|||
// We found an element and don't need to insert one
|
||||
insertNew = false;
|
||||
dump("Found existing anchor\n");
|
||||
name = anchorElement.getAttribute("name");
|
||||
} else {
|
||||
insertNew = true;
|
||||
// We don't have an element selected,
|
||||
|
@ -53,7 +51,7 @@ function Startup()
|
|||
dump("Element not selected - calling createElementWithDefaults\n");
|
||||
anchorElement = editorShell.CreateElementWithDefaults(tagName);
|
||||
// Use the current selection as suggested name
|
||||
name = GetSelectionAsText();
|
||||
var name = GetSelectionAsText();
|
||||
// Get 40 characters of the selected text and don't add "..."
|
||||
name = TruncateStringAtWordEnd(name, 40, false);
|
||||
// Replace whitespace with "_"
|
||||
|
@ -62,6 +60,8 @@ function Startup()
|
|||
//Be sure the name is unique to the document
|
||||
if (AnchorNameExists(name))
|
||||
name += "_"
|
||||
|
||||
anchorElement.setAttribute("name",name);
|
||||
}
|
||||
|
||||
if(!anchorElement)
|
||||
|
@ -69,8 +69,9 @@ function Startup()
|
|||
dump("Failed to get selected element or create a new one!\n");
|
||||
window.close();
|
||||
}
|
||||
|
||||
// Make a copy to use for AdvancedEdit
|
||||
globalElement = anchorElement.cloneNode;
|
||||
globalElement = anchorElement.cloneNode(false);
|
||||
|
||||
InitDialog();
|
||||
|
||||
|
@ -79,7 +80,7 @@ function Startup()
|
|||
|
||||
function InitDialog()
|
||||
{
|
||||
nameInput.value = name;
|
||||
nameInput.value = globalElement.getAttribute("name");
|
||||
}
|
||||
|
||||
function AnchorNameExists(name)
|
||||
|
@ -96,34 +97,40 @@ function AnchorNameExists(name)
|
|||
return false;
|
||||
}
|
||||
|
||||
function onAdvancedEdit()
|
||||
// Get and validate data from widgets.
|
||||
// Set attributes on globalElement so they can be accessed by AdvancedEdit()
|
||||
function ValidateData()
|
||||
{
|
||||
dump("\n\n Need to write onAdvancedEdit for Named Anchor dialog\n\n");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
function onOK()
|
||||
{
|
||||
name = nameInput.value;
|
||||
name = TrimString(name);
|
||||
var name = TrimString(nameInput.value);
|
||||
if (name.length == 0) {
|
||||
ShowInputErrorMessage("You must enter a name for this anchor.");
|
||||
ShowInputErrorMessage(GetString("MissingAnchorNameError"));
|
||||
nameInput.focus();
|
||||
return false;
|
||||
} else {
|
||||
// Replace spaces with "_" else it causes trouble in URL parsing
|
||||
name = ReplaceWhitespace(name, "_");
|
||||
if (AnchorNameExists(name)) {
|
||||
ShowInputErrorMessage("\""+name+"\" already exists in this page.\nPlease enter a different name.");
|
||||
ShowInputErrorMessage("\""+name+"\" "+GetString("DuplicateAnchorNameError"));
|
||||
nameInput.focus();
|
||||
return false;
|
||||
}
|
||||
anchorElement.setAttribute("name",name);
|
||||
globalElement.setAttribute("name",name);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
function onOK()
|
||||
{
|
||||
if (ValidateData())
|
||||
{
|
||||
// Copy attributes to element we are changing or inserting
|
||||
editorShell.CloneAttributes(anchorElement, globalElement);
|
||||
|
||||
if (insertNew) {
|
||||
// Don't delete selected text when inserting
|
||||
editorShell.InsertElement(anchorElement, false);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
|
|
@ -43,18 +43,11 @@
|
|||
</script>
|
||||
<script language="JavaScript" src="chrome://global/content/dialogOverlay.js" />
|
||||
|
||||
<xul:broadcaster id="args" value=""/>
|
||||
<table>
|
||||
<tr>
|
||||
<td>
|
||||
<label class="spacedtext" for="nameInput"> &anchorNameEditField.label; </label><br/>
|
||||
<input type="text" id="nameInput" size="30" maxlength="255" />
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
<label class="spacedtext" for="nameInput"> &anchorNameEditField.label; </label>
|
||||
<input type="text" id="nameInput" size="30" maxlength="255" />
|
||||
<!-- from EdDialogOverlay -->
|
||||
<xul:box id="advancedEditButton"/>
|
||||
<!-- from global dialogOverlay -->
|
||||
<xul:box id="okCancelButtons"/>
|
||||
<xul:box id="okCancelButtons"/>
|
||||
|
||||
</xul:window>
|
||||
|
|
|
@ -100,7 +100,7 @@ function CheckWord()
|
|||
FillSuggestedList();
|
||||
} else {
|
||||
ClearList(dialog.suggestedList);
|
||||
AppendStringToList(dialog.suggestedList, editorShell.GetString("CorrectSpelling"));
|
||||
AppendStringToList(dialog.suggestedList, GetString("CorrectSpelling"));
|
||||
// Suppress being able to select the message text
|
||||
allowSelectWord = false;
|
||||
}
|
||||
|
@ -199,7 +199,7 @@ function FillSuggestedList(firstWord)
|
|||
} while (word != "");
|
||||
if (list.length == 0) {
|
||||
// No suggestions - show a message but don't let user select it
|
||||
AppendStringToList(list, editorShell.GetString("NoSuggestedWords"));
|
||||
AppendStringToList(list, GetString("NoSuggestedWords"));
|
||||
allowSelectWord = false;
|
||||
} else {
|
||||
allowSelectWord = true;
|
||||
|
|
|
@ -631,3 +631,6 @@ spring.bigspacer {
|
|||
width: 10px;
|
||||
height: 10px;
|
||||
}
|
||||
|
||||
// Override any I-Beam cursors in text
|
||||
div, p, br, label, box, td { cursor: default; }
|
||||
|
|
Загрузка…
Ссылка в новой задаче