зеркало из https://github.com/mozilla/pjs.git
Added callback functions for style and dirty state changes. Also added EditorToggleStyle() call.
This commit is contained in:
Родитель
c3dba557f6
Коммит
76b8ccdb57
|
@ -22,6 +22,30 @@ var toolbar;
|
||||||
var documentModified;
|
var documentModified;
|
||||||
var EditorDisplayStyle = true;
|
var EditorDisplayStyle = true;
|
||||||
|
|
||||||
|
var gTagToFormat = {
|
||||||
|
"P" : "Normal", // these should really be entities. Not sure how to do that from JS
|
||||||
|
"H1" : "Heading 1",
|
||||||
|
"H2" : "Header 2",
|
||||||
|
"H3" : "Header 3",
|
||||||
|
"H4" : "Header 4",
|
||||||
|
"H5" : "Header 5",
|
||||||
|
"H6" : "Header 6",
|
||||||
|
"BLOCKQUOTE" : "Blockquote",
|
||||||
|
"ADDRESS" : "Address",
|
||||||
|
"PRE" : "Preformatted",
|
||||||
|
"LI" : "List Item",
|
||||||
|
"DT" : "Definition Term",
|
||||||
|
"DD" : "Definition Description"
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
var gStyleTags = {
|
||||||
|
"bold" : "b",
|
||||||
|
"italic" : "i",
|
||||||
|
"underline" : "u"
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
function EditorStartup(editorType)
|
function EditorStartup(editorType)
|
||||||
{
|
{
|
||||||
dump("Doing Startup...\n");
|
dump("Doing Startup...\n");
|
||||||
|
@ -299,19 +323,41 @@ function EditorSetBackgroundColor(color)
|
||||||
contentWindow.focus();
|
contentWindow.focus();
|
||||||
}
|
}
|
||||||
|
|
||||||
function EditorApplyStyle(styleName)
|
function EditorApplyStyle(tagName)
|
||||||
{
|
{
|
||||||
dump("applying style\n");
|
dump("applying style\n");
|
||||||
editorShell.SetTextProperty(styleName, "", "");
|
editorShell.SetTextProperty(tagName, "", "");
|
||||||
contentWindow.focus();
|
contentWindow.focus();
|
||||||
}
|
}
|
||||||
|
|
||||||
function EditorRemoveStyle(styleName)
|
function EditorRemoveStyle(tagName)
|
||||||
{
|
{
|
||||||
editorShell.RemoveTextProperty(styleName, "");
|
editorShell.RemoveTextProperty(tagName, "");
|
||||||
contentWindow.focus();
|
contentWindow.focus();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function EditorToggleStyle(styleName)
|
||||||
|
{
|
||||||
|
// see if the style is already set by looking at the observer node,
|
||||||
|
// which is the appropriate button
|
||||||
|
var theButton = document.getElementById(styleName + "Button");
|
||||||
|
|
||||||
|
if (theButton)
|
||||||
|
{
|
||||||
|
var isOn = theButton.getAttribute(styleName);
|
||||||
|
if (isOn == "true")
|
||||||
|
editorShell.RemoveTextProperty(gStyleTags[styleName], "", "");
|
||||||
|
else
|
||||||
|
editorShell.SetTextProperty(gStyleTags[styleName], "", "");
|
||||||
|
|
||||||
|
contentWindow.focus();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
dump("No button found for the " + styleName + " style");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function EditorRemoveLinks()
|
function EditorRemoveLinks()
|
||||||
{
|
{
|
||||||
editorShell.RemoveTextProperty("a", "");
|
editorShell.RemoveTextProperty("a", "");
|
||||||
|
@ -591,7 +637,7 @@ function EditorDocumentLoaded()
|
||||||
|
|
||||||
function UpdateSaveButton(modified)
|
function UpdateSaveButton(modified)
|
||||||
{
|
{
|
||||||
var saveButton = document.getElementById("saveButton");
|
var saveButton = document.getElementById("SaveButton");
|
||||||
if (saveButton)
|
if (saveButton)
|
||||||
{
|
{
|
||||||
if (modified) {
|
if (modified) {
|
||||||
|
@ -634,10 +680,6 @@ function EditorReflectDocState()
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
function EditorDocStateChanged()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
function EditorGetNodeFromOffsets(offsets)
|
function EditorGetNodeFromOffsets(offsets)
|
||||||
{
|
{
|
||||||
var node = null;
|
var node = null;
|
||||||
|
@ -774,18 +816,42 @@ function OpenFile(url)
|
||||||
}
|
}
|
||||||
|
|
||||||
// --------------------------- Status calls ---------------------------
|
// --------------------------- Status calls ---------------------------
|
||||||
function onBoldChange()
|
function onStyleChange(theStyle)
|
||||||
{
|
{
|
||||||
var boldButton = document.getElementByID("BoldButton");
|
var theButton = document.getElementById(theStyle + "Button");
|
||||||
if (boldButton)
|
if (theButton)
|
||||||
{
|
{
|
||||||
bold = boldButton.getAttribute("bold");
|
var isOn = theButton.getAttribute(theStyle);
|
||||||
if ( bold == "true" ) {
|
if (isOn == "true") {
|
||||||
boldButton.setAttribute( "disabled", false );
|
theButton.setAttribute("toggled", 1);
|
||||||
} else {
|
} else {
|
||||||
boldButton.setAttribute( "disabled", true );
|
theButton.setAttribute("toggled", 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
dump(" Bold state changed\n");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function onDirtyChange()
|
||||||
|
{
|
||||||
|
// this should happen through style, but that doesn't seem to work.
|
||||||
|
var theButton = document.getElementById("SaveButton");
|
||||||
|
if (theButton)
|
||||||
|
{
|
||||||
|
var isDirty = theButton.getAttribute("dirty");
|
||||||
|
if (isDirty == "true") {
|
||||||
|
theButton.setAttribute("src", "chrome://editor/skin/images/ED_SaveMod.gif");
|
||||||
|
} else {
|
||||||
|
theButton.setAttribute("src", "chrome://editor/skin/images/ED_SaveFile.gif");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function onParagraphFormatChange()
|
||||||
|
{
|
||||||
|
var theButton = document.getElementById("ParagraphPopup");
|
||||||
|
if (theButton)
|
||||||
|
{
|
||||||
|
var theFormat = theButton.getAttribute("format");
|
||||||
|
theButton.setAttribute("value", gTagToFormat[theFormat]);
|
||||||
|
dump("Setting value\n");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Загрузка…
Ссылка в новой задаче