зеркало из https://github.com/mozilla/gecko-dev.git
Changes to editor XUL dialogs to accomodate new window-as-box changes
This commit is contained in:
Родитель
f84be079ba
Коммит
7e87a94450
|
@ -4439,6 +4439,14 @@ nsresult nsEditor::EndUpdateViewBatch()
|
|||
return NS_OK;
|
||||
}
|
||||
|
||||
#if 0
|
||||
nsresult nsEditor::OpenDialog(const nsString &url)
|
||||
{
|
||||
// Get the content window as the parent for the dialog
|
||||
//nsWebShellWindow that lets you retrieve this. GetContentWebShell
|
||||
}
|
||||
#endif
|
||||
|
||||
/******************************************************************************
|
||||
* nsAutoSelectionReset
|
||||
*****************************************************************************/
|
||||
|
|
|
@ -1954,6 +1954,8 @@ nsHTMLEditor::GetSelectedElement(const nsString& aTagName, nsIDOMElement** aRetu
|
|||
if (NS_SUCCEEDED(anchor->GetName(tmpText)) && tmpText.GetUnicode() && tmpText.Length() != 0)
|
||||
bNodeFound = PR_TRUE;
|
||||
}
|
||||
#if 0
|
||||
// Not sure if this kind of logic should be here or in JavaScript
|
||||
} else if (TagName == "href")
|
||||
{
|
||||
// Check for a single image is inside a link
|
||||
|
@ -1989,6 +1991,7 @@ nsHTMLEditor::GetSelectedElement(const nsString& aTagName, nsIDOMElement** aRetu
|
|||
current = parent;
|
||||
} while (notDone);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
} else if (TagName == domTagName) { // All other tag names are handled here
|
||||
bNodeFound = PR_TRUE;
|
||||
|
@ -2155,9 +2158,7 @@ nsHTMLEditor::InsertElement(nsIDOMElement* aElement, PRBool aDeleteSelection)
|
|||
nsCOMPtr<nsIDOMSelection>selection;
|
||||
res = nsEditor::GetSelection(getter_AddRefs(selection));
|
||||
if (NS_SUCCEEDED(res) && selection)
|
||||
{
|
||||
selection->ClearSelection();
|
||||
}
|
||||
}
|
||||
PRBool isInline;
|
||||
|
||||
|
@ -2171,6 +2172,8 @@ nsHTMLEditor::InsertElement(nsIDOMElement* aElement, PRBool aDeleteSelection)
|
|||
{
|
||||
// The simple case of an inline node
|
||||
res = InsertNode(aElement, parentSelectedNode, offsetOfNewNode);
|
||||
if( NS_SUCCEEDED(res))
|
||||
SetCaretAfterElement(aElement);
|
||||
}
|
||||
}
|
||||
return res;
|
||||
|
|
|
@ -4439,6 +4439,14 @@ nsresult nsEditor::EndUpdateViewBatch()
|
|||
return NS_OK;
|
||||
}
|
||||
|
||||
#if 0
|
||||
nsresult nsEditor::OpenDialog(const nsString &url)
|
||||
{
|
||||
// Get the content window as the parent for the dialog
|
||||
//nsWebShellWindow that lets you retrieve this. GetContentWebShell
|
||||
}
|
||||
#endif
|
||||
|
||||
/******************************************************************************
|
||||
* nsAutoSelectionReset
|
||||
*****************************************************************************/
|
||||
|
|
|
@ -1954,6 +1954,8 @@ nsHTMLEditor::GetSelectedElement(const nsString& aTagName, nsIDOMElement** aRetu
|
|||
if (NS_SUCCEEDED(anchor->GetName(tmpText)) && tmpText.GetUnicode() && tmpText.Length() != 0)
|
||||
bNodeFound = PR_TRUE;
|
||||
}
|
||||
#if 0
|
||||
// Not sure if this kind of logic should be here or in JavaScript
|
||||
} else if (TagName == "href")
|
||||
{
|
||||
// Check for a single image is inside a link
|
||||
|
@ -1989,6 +1991,7 @@ nsHTMLEditor::GetSelectedElement(const nsString& aTagName, nsIDOMElement** aRetu
|
|||
current = parent;
|
||||
} while (notDone);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
} else if (TagName == domTagName) { // All other tag names are handled here
|
||||
bNodeFound = PR_TRUE;
|
||||
|
@ -2155,9 +2158,7 @@ nsHTMLEditor::InsertElement(nsIDOMElement* aElement, PRBool aDeleteSelection)
|
|||
nsCOMPtr<nsIDOMSelection>selection;
|
||||
res = nsEditor::GetSelection(getter_AddRefs(selection));
|
||||
if (NS_SUCCEEDED(res) && selection)
|
||||
{
|
||||
selection->ClearSelection();
|
||||
}
|
||||
}
|
||||
PRBool isInline;
|
||||
|
||||
|
@ -2171,6 +2172,8 @@ nsHTMLEditor::InsertElement(nsIDOMElement* aElement, PRBool aDeleteSelection)
|
|||
{
|
||||
// The simple case of an inline node
|
||||
res = InsertNode(aElement, parentSelectedNode, offsetOfNewNode);
|
||||
if( NS_SUCCEEDED(res))
|
||||
SetCaretAfterElement(aElement);
|
||||
}
|
||||
}
|
||||
return res;
|
||||
|
|
|
@ -469,13 +469,13 @@
|
|||
</popup>
|
||||
|
||||
<popup id="AlignmentWindow" oncreate="OnCreateAlignmentPopup()">
|
||||
<window class="popup" xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul" width="75" height="100">
|
||||
<!-- <box align="vertical" style="width: 100%; height: 100%"> -->
|
||||
<window class="popup" xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul" align="vertical" width="80" height="100">
|
||||
<html:div flex="100%">
|
||||
<titledbutton class="AlignButton" id="LeftAlign" value="Left" align="right" onclick="opener.EditorAlign('left'); window.close();"/><html:br/>
|
||||
<titledbutton class="AlignButton" id="CenterAlign" value="Center" align="right" onclick="opener.EditorAlign('center'); window.close();"/><html:br/>
|
||||
<titledbutton class="AlignButton" id="RightAlign" value="Right" align="right" onclick="opener.EditorAlign('right'); window.close();"/><html:br/>
|
||||
<titledbutton class="AlignButton" id="JustifyAlign" value="Justify" align="right" onclick="opener.EditorAlign('justify'); window.close();"/><html:br/>
|
||||
<!-- </box> -->
|
||||
</html:div>
|
||||
</window>
|
||||
</popup>
|
||||
|
||||
|
|
|
@ -54,12 +54,9 @@ function EditorStartup(editorType)
|
|||
SetupToolbarElements();
|
||||
|
||||
// Set focus to the edit window
|
||||
// (A bug currently prevents this from working,
|
||||
// the actual edit window is a child of the webshell window
|
||||
// designated as the contentWindow)
|
||||
dump("Setting focus to content window\n");
|
||||
// This still doesn't work!
|
||||
// It works after using a toolbar button, however!
|
||||
contentWindow.focus();
|
||||
window.frames[0].focus();
|
||||
}
|
||||
|
||||
function SetupToolbarElements()
|
||||
|
|
|
@ -1,39 +0,0 @@
|
|||
// OnOK(), Undo(), and Cancel() are in EdDialogCommon.js
|
||||
// applyChanges() must be implemented here
|
||||
|
||||
// dialog initialization code
|
||||
var appCore;
|
||||
var toolkitCore;
|
||||
var insertNew = true;
|
||||
var selectionIsCollapsed = false;
|
||||
var undoCount = 0;
|
||||
|
||||
function Startup()
|
||||
{
|
||||
dump("Doing Character Props Startup...\n");
|
||||
toolkitCore = XPAppCoresManager.Find("ToolkitCore");
|
||||
if (!toolkitCore) {
|
||||
toolkitCore = new ToolkitCore();
|
||||
if (toolkitCore)
|
||||
toolkitCore.Init("ToolkitCore");
|
||||
}
|
||||
if(!toolkitCore) {
|
||||
dump("toolkitCore not found!!! And we can't close the dialog!\n");
|
||||
}
|
||||
|
||||
// temporary while this window is opend with ShowWindowWithArgs
|
||||
dump("Getting parent appcore\n");
|
||||
var editorName = document.getElementById("args").getAttribute("value");
|
||||
dump("Got editorAppCore called " + editorName + "\n");
|
||||
|
||||
// NEVER create an appcore here - we must find parent editor's
|
||||
appCore = XPAppCoresManager.Find(editorName);
|
||||
if(!appCore || !toolkitCore) {
|
||||
dump("EditorAppCore not found!!!\n");
|
||||
toolkitCore.CloseWindow(window);
|
||||
}
|
||||
}
|
||||
|
||||
function applyChanges()
|
||||
{
|
||||
}
|
|
@ -1,18 +0,0 @@
|
|||
<?xml version="1.0"?>
|
||||
<?xml-stylesheet href="xul.css" type="text/css"?>
|
||||
<!DOCTYPE window>
|
||||
<!-- dialog containing a control requiring initial setup -->
|
||||
<xul:window
|
||||
xmlns:html="http://www.w3.org/TR/REC-html40"
|
||||
xmlns:xul ="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
|
||||
onload = "Startup()">
|
||||
|
||||
<!-- Methods common to all editor dialogs -->
|
||||
<script language="JavaScript" src="chrome://editordlgs/content/EdDialogCommon.js">
|
||||
</script>
|
||||
<html:script language="JavaScript" src="chrome://editordlgs/content/EdCharacterProps.js">
|
||||
</html:script>
|
||||
|
||||
<xul:broadcaster id="args" value=""/>
|
||||
|
||||
</xul:window>
|
|
@ -38,6 +38,128 @@ function ValidateNumberString(value, minValue, maxValue)
|
|||
return "";
|
||||
}
|
||||
|
||||
|
||||
function TrimStringLeft(string)
|
||||
{
|
||||
firstCharIndex = 0;
|
||||
len = string.length;
|
||||
var result;
|
||||
|
||||
while (firstCharIndex < len) {
|
||||
if (!IsWhitespace(string.charAt(firstCharIndex))) break;
|
||||
firstCharIndex = firstCharIndex + 1;
|
||||
}
|
||||
if (firstCharIndex > len) {
|
||||
string = "";
|
||||
} else {
|
||||
string = string.slice(firstCharIndex);
|
||||
}
|
||||
return string;
|
||||
}
|
||||
|
||||
function TrimStringRight(string)
|
||||
{
|
||||
len = string.length;
|
||||
if (len > 0 ) {
|
||||
lastCharIndex = string.length-1;
|
||||
var result;
|
||||
|
||||
while (lastCharIndex > 0) {
|
||||
// Find the last non-whitespace char
|
||||
if (!IsWhitespace(string.charAt(lastCharIndex))) break;
|
||||
lastCharIndex = lastCharIndex - 1;
|
||||
}
|
||||
if (lastCharIndex == 0) {
|
||||
string = "";
|
||||
} else {
|
||||
string = string.slice(0, lastCharIndex+1);
|
||||
}
|
||||
}
|
||||
return string;
|
||||
}
|
||||
|
||||
// Remove whitespace from both ends of a string
|
||||
function TrimString(string)
|
||||
{
|
||||
return TrimStringRight(TrimStringLeft(string));
|
||||
}
|
||||
|
||||
function IsWhitespace(character)
|
||||
{
|
||||
result = character.match(/\s/);
|
||||
if (result == null)
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
function TruncateStringAtWordEnd(string, maxLength, addEllipses)
|
||||
{
|
||||
// We assume they probably don't want whitespace at the beginning
|
||||
string = TrimStringLeft(string);
|
||||
|
||||
len = string.length;
|
||||
if (len > maxLength) {
|
||||
// We need to truncate the string
|
||||
var max;
|
||||
if (addEllipses) {
|
||||
// Make room for ellipses
|
||||
max = maxLength - 3;
|
||||
} else {
|
||||
max = maxLength;
|
||||
}
|
||||
var lastCharIndex = 0;
|
||||
|
||||
// Start search just past max if there's enough characters
|
||||
if (len >= (max+1)) {
|
||||
lastCharIndex = max;
|
||||
} else {
|
||||
lastCharIndex = len-1;
|
||||
}
|
||||
dump("Len="+len+" lastCharIndex="+lastCharIndex+" max="+max+"\n");
|
||||
|
||||
// Find the last whitespace char from the end
|
||||
dump("Skip to first whitspace from end: ");
|
||||
|
||||
while (lastCharIndex > 0) {
|
||||
lastChar = string.charAt(lastCharIndex);
|
||||
dump(lastChar);
|
||||
if (IsWhitespace(lastChar)) break;
|
||||
lastCharIndex = lastCharIndex -1;
|
||||
}
|
||||
dump("[space found]\nlastCharIndex="+lastCharIndex+"\nSkip over whitespace:");
|
||||
|
||||
while (lastCharIndex > 0) {
|
||||
// Find the last non-whitespace char
|
||||
lastChar = string.charAt(lastCharIndex);
|
||||
dump(lastChar);
|
||||
if (!IsWhitespace(lastChar)) break;
|
||||
lastCharIndex = lastCharIndex -1;
|
||||
}
|
||||
dump("[non-space found]\nlastCharIndex="+lastCharIndex+"\n");
|
||||
|
||||
string = string.slice(0, lastCharIndex+1);
|
||||
if (addEllipses) {
|
||||
string = string+"...";
|
||||
dump(string+"\n");
|
||||
}
|
||||
}
|
||||
return string;
|
||||
}
|
||||
|
||||
// Replace all whitespace characters with supplied character
|
||||
// E.g.: Use charReplace = " ", to "unwrap" the string by removing line-end chars
|
||||
// Use charReplace = "_" when you don't want spaces (like in a URL)
|
||||
function ReplaceWhitespace(string, charReplace) {
|
||||
if (string.length > 0 )
|
||||
{
|
||||
string = TrimString(string);
|
||||
// This replaces a run of whitespace with just one character
|
||||
string = string.replace(/\s+/g, charReplace);
|
||||
}
|
||||
dump(string+"\n");
|
||||
return string;
|
||||
}
|
||||
|
||||
// this function takes an elementID and a flag
|
||||
// if the element can be found by ID, then it is either enabled (by removing "disabled" attr)
|
||||
// or disabled (setAttribute) as specified in the "doEnable" parameter
|
||||
|
|
|
@ -3,10 +3,12 @@
|
|||
<?xml-stylesheet href="chrome://editordlgs/skin/EditorDialog.css" type="text/css"?>
|
||||
<!DOCTYPE window>
|
||||
<!-- dialog containing a control requiring initial setup -->
|
||||
<xul:window width="380" height="205" title="PUT TITLE HERE"
|
||||
<!-- WE SHOULD NOT USE ABSOLUTE WITH AND HEIGHT - USE BOXES INSTEAD? -->
|
||||
<xul:window width="???" height="???" title="PUT TITLE HERE"
|
||||
xmlns:xul ="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
|
||||
xmlns="http://www.w3.org/TR/REC-html40"
|
||||
onload = "Startup()">
|
||||
onload = "Startup()"
|
||||
align="vertical" flex="100%">
|
||||
|
||||
<!-- Methods common to all editor dialogs -->
|
||||
<script language="JavaScript" src="chrome://editordlgs/content/EdDialogCommon.js">
|
||||
|
@ -15,18 +17,19 @@
|
|||
</script>
|
||||
|
||||
<xul:broadcaster id="args" value=""/>
|
||||
|
||||
<div flex="100%">
|
||||
<table>
|
||||
<tr>
|
||||
<td>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<!-- THIS SHOULD BE A XUL FRAGMENT -->
|
||||
<td align = "right">
|
||||
<button class="spaced" id="OK" onclick="onOK()">OK</button>
|
||||
<button class="spaced" id="Cancel" onclick="onCancel()">Cancel</button>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
<!-- THIS SHOULD BE A XUL FRAGMENT -->
|
||||
<td align = "right">
|
||||
<button class="spaced" id="OK" onclick="onOK()">OK</button>
|
||||
<button class="spaced" id="Cancel" onclick="onCancel()">Cancel</button>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
</div>
|
||||
</xul:window>
|
||||
|
|
|
@ -125,7 +125,7 @@ function ValidateData(setAttributes)
|
|||
if (setAttributes) {
|
||||
hLineElement.setAttribute("size", height);
|
||||
} else {
|
||||
hLineElement.setAttribute("size", height);
|
||||
tempLineElement.setAttribute("size", height);
|
||||
}
|
||||
|
||||
var maxLimit;
|
||||
|
|
|
@ -3,17 +3,20 @@
|
|||
<?xml-stylesheet href="chrome://editordlgs/skin/EditorDialog.css" type="text/css"?>
|
||||
<!DOCTYPE window>
|
||||
<!-- dialog containing a control requiring initial setup -->
|
||||
<xul:window width="250" height="275" title="Horizontal Line Properties"
|
||||
<xul:window title="Horizontal Line Properties"
|
||||
xmlns:xul ="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
|
||||
xmlns="http://www.w3.org/TR/REC-html40"
|
||||
onload = "Startup()">
|
||||
onload = "Startup()"
|
||||
width="250" height="275"
|
||||
align="vertical" flex="100%">
|
||||
|
||||
<!-- Methods common to all editor dialogs -->
|
||||
<script language="JavaScript" src="chrome://editordlgs/content/EdDialogCommon.js">
|
||||
</script>
|
||||
<script language="JavaScript" src="chrome://editordlgs/content/EdHLineProps.js">
|
||||
</script>
|
||||
<table width="95%"> <!-- WIDTH SHOULD BE 100%, BUT BUG PREVENTS THAT -->
|
||||
<div flex="100%">
|
||||
<table width="100%">
|
||||
<tr>
|
||||
<td colspan="2">
|
||||
<fieldset><legend align="left">Dimensions</legend>
|
||||
|
@ -34,7 +37,7 @@
|
|||
<input type="text" id="width" size="4" maxlength="4"/>
|
||||
</td>
|
||||
<td>
|
||||
<xul:titledbutton class="popup PixelOrPercent" id="pixelOrPercentButton" value="percent" align="left" popup="PixelOrPercentMenu" />
|
||||
<xul:titledbutton class="popup PixelOrPercent" id="pixelOrPercentButton" value="percent" align="left" popup="PixelOrPercentMenu" popupanchor="bottomleft"/>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
|
@ -55,7 +58,7 @@
|
|||
<label><input type="checkbox" id="3dShading"/>3-D Shading</label>
|
||||
</td>
|
||||
<td align="right">
|
||||
<button id="SaveDefault" onclick="onSaveDefault()">Save settings</button>
|
||||
<button class="spaced" id="SaveDefault" onclick="onSaveDefault()">Save settings</button>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
|
@ -71,6 +74,7 @@
|
|||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
</div>
|
||||
|
||||
<xul:popup id="PixelOrPercentMenu">
|
||||
<xul:menu>
|
||||
|
|
|
@ -4,10 +4,12 @@
|
|||
<!DOCTYPE window>
|
||||
|
||||
<!-- dialog containing a control requiring initial setup -->
|
||||
<xul:window width="420" height="375" title="Image Properties"
|
||||
<xul:window title="Image Properties"
|
||||
xmlns:xul ="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
|
||||
xmlns="http://www.w3.org/TR/REC-html40"
|
||||
onload = "Startup()">
|
||||
onload = "Startup()"
|
||||
width="420" height="375"
|
||||
align="vertical" flex="100%">
|
||||
|
||||
<!-- Methods common to all editor dialogs -->
|
||||
<script language="JavaScript" src="chrome://editordlgs/content/EdDialogCommon.js">
|
||||
|
@ -16,7 +18,7 @@
|
|||
</script>
|
||||
|
||||
<xul:broadcaster id="args" value=""/>
|
||||
|
||||
<div flex="100%">
|
||||
<table>
|
||||
<tr>
|
||||
<td colspan="2">
|
||||
|
@ -166,13 +168,14 @@
|
|||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td colspan="2" align="right">
|
||||
<button class="spaced" id="OK" onclick="onOK()" width="50">OK</button>
|
||||
<button class="spaced" id="Cancel" onclick="onCancel()" width="50">Cancel</button>
|
||||
</td>
|
||||
<td/>
|
||||
</tr>
|
||||
</table>
|
||||
<td colspan="2" align="right">
|
||||
<button class="spaced" id="OK" onclick="onOK()" width="50">OK</button>
|
||||
<button class="spaced" id="Cancel" onclick="onCancel()" width="50">Cancel</button>
|
||||
</td>
|
||||
<td/>
|
||||
</tr>
|
||||
</table>
|
||||
</div>
|
||||
|
||||
<xul:popup id="PixelOrPercentMenu1">
|
||||
<xul:menu>
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
<xul:window width="320" height="255" title="Insert HTML"
|
||||
xmlns:xul ="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
|
||||
xmlns="http://www.w3.org/TR/REC-html40"
|
||||
onload = "Startup()">
|
||||
onload = "Startup()" align="vertical" flex="100%">
|
||||
|
||||
<!-- Methods common to all editor dialogs -->
|
||||
<script language="JavaScript" src="chrome://editordlgs/content/EdDialogCommon.js">
|
||||
|
@ -15,7 +15,7 @@
|
|||
</script>
|
||||
|
||||
<xul:broadcaster id="args" value=""/>
|
||||
|
||||
<div flex="100%>
|
||||
<table>
|
||||
<tr>
|
||||
<td>
|
||||
|
@ -35,4 +35,5 @@
|
|||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
</div>
|
||||
</xul:window>
|
||||
|
|
|
@ -1,13 +1,14 @@
|
|||
var editorShell;
|
||||
var anchorElement = null;
|
||||
var imageElement = null;
|
||||
var insertNew = true;
|
||||
var needLinkText = false;
|
||||
var selection;
|
||||
var insertLinkAroundSelection = false;
|
||||
|
||||
// NOTE: Use "HREF" instead of "A" to distinguish from Named Anchor
|
||||
// The returned node is has an "A" tagName
|
||||
var tagName = "HREF";
|
||||
// NOTE: Use "href" instead of "a" to distinguish from Named Anchor
|
||||
// The returned node is has an "a" tagName
|
||||
var tagName = "href";
|
||||
var dialog;
|
||||
|
||||
// dialog initialization code
|
||||
|
@ -79,29 +80,49 @@ function initDialog()
|
|||
// We found an element and don't need to insert one
|
||||
insertNew = false;
|
||||
} else {
|
||||
// We don't have an element selected,
|
||||
// so create one with default attributes
|
||||
dump("Element not selected - calling createElementWithDefaults\n");
|
||||
anchorElement = editorShell.CreateElementWithDefaults(tagName);
|
||||
// See if we have a selected image instead of text
|
||||
imageElement = editorShell.GetSelectedElement("img");
|
||||
if (imageElement) {
|
||||
// See if the image is a child of a link
|
||||
dump("Image element found - check if its a link...\n");
|
||||
dump("Image Parent="+parent);
|
||||
parent = imageElement.parentNode;
|
||||
dump("Parent="+parent+" nodeName="+parent.nodeName+"\n");
|
||||
if (parent) {
|
||||
anchorElement = parent;
|
||||
insertNew = false;
|
||||
// Link source string is the source URL of image
|
||||
// TODO: THIS STILL DOESN'T HANDLE MULTIPLE SELECTED IMAGES!
|
||||
dialog.linkMessage.data = imageElement.getAttribute("src");;
|
||||
}
|
||||
} else {
|
||||
// We don't have an element selected,
|
||||
// so create one with default attributes
|
||||
dump("Element not selected - calling createElementWithDefaults\n");
|
||||
anchorElement = editorShell.CreateElementWithDefaults(tagName);
|
||||
|
||||
// We will insert a new link at caret location if there's no selection
|
||||
// TODO: This isn't entirely correct. If selection doesn't have any text
|
||||
// or an image, then shouldn't we clear the selection and insert new text?
|
||||
insertNew = selection.isCollapsed;
|
||||
dump("insertNew is " + insertNew + "\n");
|
||||
// We will insert a new link at caret location if there's no selection
|
||||
// TODO: This isn't entirely correct. If selection doesn't have any text
|
||||
// or an image, then shouldn't we clear the selection and insert new text?
|
||||
insertNew = selection.isCollapsed;
|
||||
dump("insertNew is " + insertNew + "\n");
|
||||
}
|
||||
}
|
||||
if(!anchorElement)
|
||||
{
|
||||
dump("Failed to get selected element or create a new one!\n");
|
||||
window.close();
|
||||
} else if (!insertNew) {
|
||||
dump("Need to get selected text\n");
|
||||
} else if (!insertNew && !imageElement) {
|
||||
|
||||
// Replace the link message with the link source string
|
||||
// TODO: Get the text of the selection WHAT ABOUT IMAGES?
|
||||
// Maybe have a special method "GetLinkSource" that resolves images as
|
||||
// their URL? E.g.: "Link source [image:http://myimage.gif]"
|
||||
dialog.linkMessage.data = "[Link source text or image URL goes here]";
|
||||
selectedText = editorShell.selectionAsText;
|
||||
if (selectedText.length > 0) {
|
||||
// Use just the first 50 characters and add "..."
|
||||
selectedText = TruncateStringAtWordEnd(selectedText, 50, true);
|
||||
} else {
|
||||
dump("Selected text for link source not found. Non-text elements selected?\n");
|
||||
}
|
||||
dialog.linkMessage.data = selectedText;
|
||||
}
|
||||
|
||||
if (!selection.isCollapsed)
|
||||
|
|
|
@ -3,10 +3,11 @@
|
|||
<?xml-stylesheet href="chrome://editordlgs/skin/EditorDialog.css" type="text/css"?>
|
||||
<!DOCTYPE window>
|
||||
|
||||
<xul:window width="320" height="255" title="Link Properties"
|
||||
<xul:window width="320" min-height="255" title="Link Properties"
|
||||
xmlns:xul ="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
|
||||
xmlns="http://www.w3.org/TR/REC-html40"
|
||||
onload = "Startup()">
|
||||
onload = "Startup()"
|
||||
align="vertical" flex="100%">
|
||||
|
||||
<!-- Methods common to all editor dialogs -->
|
||||
<script language="JavaScript" src="chrome://editordlgs/content/EdDialogCommon.js">
|
||||
|
@ -15,7 +16,7 @@
|
|||
</script>
|
||||
|
||||
<xul:broadcaster id="args" value=""/>
|
||||
|
||||
<div flex="100%">
|
||||
<table>
|
||||
<tr>
|
||||
<td>
|
||||
|
@ -41,4 +42,5 @@
|
|||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
</div>
|
||||
</xul:window>
|
||||
|
|
|
@ -2,7 +2,8 @@
|
|||
var editorShell;
|
||||
var insertNew = true;
|
||||
var inserted = false;
|
||||
var tagname = "TAG NAME"
|
||||
var tagName = "anchor"
|
||||
var anchorElement = null;
|
||||
|
||||
// dialog initialization code
|
||||
function Startup()
|
||||
|
@ -20,58 +21,66 @@ function Startup()
|
|||
// Create dialog object to store controls for easy access
|
||||
dialog = new Object;
|
||||
// GET EACH CONTROL -- E.G.:
|
||||
//dialog.editBox = document.getElementById("editBox");
|
||||
dialog.nameInput = document.getElementById("name");
|
||||
|
||||
initDialog();
|
||||
|
||||
// SET FOCUS TO FIRST CONTROL
|
||||
//dialog.editBox.focus();
|
||||
}
|
||||
|
||||
function initDialog() {
|
||||
// Get a single selected element of the desired type
|
||||
element = editorShell.GetSelectedElement(tagName);
|
||||
anchorElement = editorShell.GetSelectedElement(tagName);
|
||||
|
||||
if (element) {
|
||||
if (anchorElement) {
|
||||
// We found an element and don't need to insert one
|
||||
insertNew = false;
|
||||
dump("Found existing image\n");
|
||||
dump("Found existing anchor\n");
|
||||
dialog.nameInput.value = anchorElement.getAttribute("name");
|
||||
} else {
|
||||
insertNew = true;
|
||||
// We don't have an element selected,
|
||||
// so create one with default attributes
|
||||
dump("Element not selected - calling createElementWithDefaults\n");
|
||||
element = appCore.createElementWithDefaults(tagName);
|
||||
anchorElement = editorShell.CreateElementWithDefaults(tagName);
|
||||
// Use the current selection as suggested name
|
||||
name = editorShell.selectionAsText;
|
||||
// Get 40 characters of the selected text and don't add "..."
|
||||
name = TruncateStringAtWordEnd(name, 40, false);
|
||||
// Replace whitespace with "_"
|
||||
name = ReplaceWhitespace(name, "_");
|
||||
dialog.nameInput.value = name;
|
||||
}
|
||||
|
||||
if(!element)
|
||||
if(!anchorElement)
|
||||
{
|
||||
dump("Failed to get selected element or create a new one!\n");
|
||||
window.close();
|
||||
}
|
||||
}
|
||||
function CreatePixelOrPercentMenu()
|
||||
{
|
||||
dump("Creating PixelOrPercent popup menu\n");
|
||||
|
||||
dialog.nameInput.focus();
|
||||
}
|
||||
|
||||
function onOK()
|
||||
{
|
||||
// Set attribute example:
|
||||
// imageElement.setAttribute("src",dialog.srcInput.value);
|
||||
if (insertNew) {
|
||||
editorShell.InsertElement(element, true);
|
||||
// Select the newly-inserted image
|
||||
editorShell.SelectElement(element);
|
||||
// Mark that we inserted so we can collapse the selection
|
||||
// when dialog closes
|
||||
inserted = true;
|
||||
}
|
||||
name = dialog.nameInput.value;
|
||||
name = TrimString(name);
|
||||
if (name.length == 0) {
|
||||
dump("EMPTY ANCHOR STRING\n");
|
||||
//TODO: POPUP ERROR DIALOG HERE
|
||||
} else {
|
||||
// Replace spaces with "_" else it causes trouble in URL parsing
|
||||
name = ReplaceWhitespace(name, "_");
|
||||
imageElement.setAttribute("name",name);
|
||||
if (insertNew) {
|
||||
// Don't delete selected text when inserting
|
||||
editorShell.InsertElement(element, false);
|
||||
// Select the newly-inserted image
|
||||
editorShell.SelectElement(element);
|
||||
// Mark that we inserted so we can collapse the selection
|
||||
// when dialog closes
|
||||
inserted = true;
|
||||
}
|
||||
|
||||
if (inserted) {
|
||||
// We selected the object, undo it by
|
||||
// setting caret to just after the inserted element
|
||||
editorShell.SetSelectionAfterElement(imageElement);
|
||||
if (inserted) {
|
||||
// We selected the object, undo it by
|
||||
// setting caret to just after the inserted element
|
||||
editorShell.SetSelectionAfterElement(imageElement);
|
||||
}
|
||||
window.close();
|
||||
}
|
||||
window.close();
|
||||
}
|
||||
|
|
|
@ -2,11 +2,12 @@
|
|||
<?xml-stylesheet href="chrome://global/skin/xul.css" type="text/css"?>
|
||||
<?xml-stylesheet href="chrome://editordlgs/skin/EditorDialog.css" type="text/css"?>
|
||||
<!DOCTYPE window>
|
||||
<!-- dialog containing a control requiring initial setup -->
|
||||
<xul:window width="260" height="140" title="Target Properties"
|
||||
<xul:window class="dialog" title="Target Properties"
|
||||
xmlns:xul ="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
|
||||
xmlns="http://www.w3.org/TR/REC-html40"
|
||||
onload = "Startup()">
|
||||
onload = "Startup()"
|
||||
width="260" height="140"
|
||||
align="vertical" flex="100%">
|
||||
|
||||
<!-- Methods common to all editor dialogs -->
|
||||
<script language="JavaScript" src="chrome://editordlgs/content/EdDialogCommon.js">
|
||||
|
@ -15,25 +16,30 @@
|
|||
</script>
|
||||
|
||||
<xul:broadcaster id="args" value=""/>
|
||||
|
||||
<div flex="100%">
|
||||
<table>
|
||||
<tr>
|
||||
<td>
|
||||
Enter a name for this target:<br/>
|
||||
<div class="spacedtext">
|
||||
Enter a name for this target:
|
||||
</div>
|
||||
<input type="text" id="name" size="30"/>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<!-- THIS SHOULD BE A XUL FRAGMENT -->
|
||||
<td align = "right">
|
||||
<hr width="100%"/>
|
||||
<xul:box align="horizontal" id="status-bar" width="100%">
|
||||
<button class="spaced" id="Advanced" onclick="onAdvanced()">Advanced Attributes</button>
|
||||
<xul:spring flex="100%"/>
|
||||
<button class="spaced" id="OK" onclick="onOK()">OK</button>
|
||||
<button class="spaced" id="Cancel" onclick="onCancel()">Cancel</button>
|
||||
</xul:box>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
<!-- THIS SHOULD BE A XUL FRAGMENT -->
|
||||
<td align = "right">
|
||||
<hr width="100%"/>
|
||||
<!-- This box doesn't work inside a table cell,
|
||||
but putting outside the table is real wacked -->
|
||||
<xul:box align="horizontal" width="100%">
|
||||
<button class="spaced" id="Advanced" onclick="onAdvanced()">More Attributes...</button>
|
||||
<xul:spring flex="100%"/>
|
||||
<button class="spaced" id="OK" onclick="onOK()">OK</button>
|
||||
<button class="spaced" id="Cancel" onclick="onCancel()">Cancel</button>
|
||||
</xul:box>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
</div>
|
||||
</xul:window>
|
||||
|
|
|
@ -3,10 +3,12 @@
|
|||
<?xml-stylesheet href="chrome://editordlgs/skin/EditorDialog.css" type="text/css"?>
|
||||
<!DOCTYPE window>
|
||||
<!-- dialog containing a control requiring initial setup -->
|
||||
<xul:window width="380" height="265" title="Check Spelling"
|
||||
<xul:window title="Check Spelling"
|
||||
xmlns:xul ="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
|
||||
xmlns="http://www.w3.org/TR/REC-html40"
|
||||
onload = "Startup()">
|
||||
onload = "Startup()"
|
||||
width="380" height="265"
|
||||
align="vertical" flex="100%">
|
||||
|
||||
<script language="JavaScript" src="chrome://editordlgs/content/EdDialogCommon.js">
|
||||
</script>
|
||||
|
@ -14,7 +16,7 @@
|
|||
</script>
|
||||
<!-- The argument to ShowWindowWithArgs (the editor appCore name) is placed here -->
|
||||
<xul:broadcaster id="args" value=""/>
|
||||
|
||||
<div flex="100%">
|
||||
<table>
|
||||
<tr>
|
||||
<td colspan="3">
|
||||
|
@ -94,4 +96,5 @@
|
|||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
</div>
|
||||
</xul:window>
|
||||
|
|
|
@ -1,13 +1,4 @@
|
|||
/* XUL ELEMENTS */
|
||||
window, WINDOW {
|
||||
display: block;
|
||||
width: 100%;
|
||||
background: silver;
|
||||
background-color: #CCCCCC; /* not working on Macintosh */
|
||||
padding: 5px;
|
||||
font-family: Sans-Serif;
|
||||
font-size: 8pt;
|
||||
}
|
||||
|
||||
/* values = margin, padding. Padding doesn't work yet */
|
||||
checkbox { margin: 5px 3px }
|
||||
|
|
Загрузка…
Ссылка в новой задаче