- Restored read-only mode for notes (using a separate HTML file, for lack of a better way)

- HTML file is now loaded on-demand the first time it's required
This commit is contained in:
Dan Stillman 2008-10-15 05:24:38 +00:00
parent 5e1ca7172a
commit 2bbf3d7c80
4 changed files with 141 additions and 72 deletions

View file

@ -28,6 +28,7 @@
xmlns:xul="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
<binding id="styled-textbox">
<implementation>
<field name="_editable"/>
<field name="_mode"/>
<field name="_format"/>
<field name="_loadHandler"/>
@ -63,11 +64,6 @@
// tables, which wouldn't work here.
'<span class="tab">&nbsp;</span>':"\t"
};
// not sure why an event is necessary here, but it is
var me = this;
this._loadHandler = function() {me._iframeLoaded()};
this._iframe.addEventListener("DOMContentLoaded", this._loadHandler, false);
]]></constructor>
<!-- Called when iframe browser is loaded. Until the browser is loaded, we can't do
@ -75,35 +71,6 @@
happen. -->
<method name="_iframeLoaded">
<body><![CDATA[
this._iframe.removeEventListener("DOMContentLoaded", this._loadHandler, false);
var ios = Components.classes["@mozilla.org/network/io-service;1"].
getService(Components.interfaces.nsIIOService);
var uri = ios.newURI("chrome://zotero/content/tinymce/" + this.mode + ".html", null, null);
var chromeReg = Components.classes["@mozilla.org/chrome/chrome-registry;1"].
getService(Components.interfaces.nsIChromeRegistry);
var fileURI = chromeReg.convertChromeURL(uri);
this._iframe.webNavigation.loadURI(fileURI.spec,
Components.interfaces.nsIWebNavigation.LOAD_FLAGS_BYPASS_HISTORY, null, null, null);
// Register handler for deferred setting of content
var me = this;
var listener = function() {
me._iframe.removeEventListener("DOMContentLoaded", listener, false);
var editor = me._iframe.contentWindow.wrappedJSObject.tinyMCE.get("tinymce");
editor.onInit.add(function() {
me._editor = editor;
if(me._value) me.value = me._value;
});
if (me._eventHandler) {
me._iframe.contentWindow.wrappedJSObject.handleEvent = me._eventHandler;
}
};
this._iframe.addEventListener("DOMContentLoaded", listener, false);
]]></body>
</method>
@ -214,8 +181,13 @@
}
if(!this._editor) {
// if not loaded, wait until it is to set
return this._value = val;
Zotero.debug('No editor yet');
this._value = val;
if (!this._loaded) {
this._load();
}
return ;
}
if (this.value == val) {
@ -270,6 +242,51 @@
<property name="timeout"
onset="this.setAttribute('timeout', val); return val;"
onget="return parseInt(this.getAttribute('timeout')) || 0;"/>
<field name="_loaded"/>
<method name="_load">
<body>
<![CDATA[
this._loaded = true;
// Unless we find a better way, use a separate HTML file
// for read-only mode
var htmlFile = this.mode + (this.getAttribute('readonly') != 'true' ? "" : "view");
var ios = Components.classes["@mozilla.org/network/io-service;1"].
getService(Components.interfaces.nsIIOService);
var uri = ios.newURI("chrome://zotero/content/tinymce/" + htmlFile + ".html", null, null);
var chromeReg = Components.classes["@mozilla.org/chrome/chrome-registry;1"].
getService(Components.interfaces.nsIChromeRegistry);
var fileURI = chromeReg.convertChromeURL(uri);
Zotero.debug("Loading " + fileURI.spec);
// Register handler for deferred setting of content
var self = this;
var listener = function() {
self._iframe.removeEventListener("DOMContentLoaded", listener, false);
var editor = self._iframe.contentWindow.wrappedJSObject.tinyMCE.get("tinymce");
editor.onInit.add(function() {
self._editor = editor;
if (self._value) {
self.value = self._value;
}
});
if (self._eventHandler) {
self._iframe.contentWindow.wrappedJSObject.handleEvent = self._eventHandler;
}
};
this._iframe.addEventListener("DOMContentLoaded", listener, false);
this._iframe.webNavigation.loadURI(fileURI.spec,
Components.interfaces.nsIWebNavigation.LOAD_FLAGS_BYPASS_HISTORY, null, null, null);
]]>
</body>
</method>
</implementation>
<content>

View file

@ -2,39 +2,7 @@
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>TinyMCE</title>
<style>
html, body {
height: 100%;
margin: 0;
}
#tinymce_parent {
display: block;
height: 100%;
}
#tinymce_tbl {
height: 100% !important;
width: 100% !important;
}
table.mceLayout > tbody > tr.mceLast {
position: absolute;
display: block;
top: 54px;
bottom: 2px;
left: 1px;
right: 1px;
}
td.mceIframeContainer {
display: block;
height: 100% !important;
width: 100% !important;
}
#tinymce_ifr {
height: 100% !important;
width: 100% !important;
}
</style>
<link type="text/css" rel="stylesheet" href="../../../skin/default/zotero/tinymce/note-ui.css"/>
<script type="text/javascript" src="tiny_mce.js"></script>
<script type="text/javascript">
tinyMCE.init({
@ -65,13 +33,11 @@ td.mceIframeContainer {
/*plugins : "xhtmlxtras",*/
// Theme options
theme_advanced_layout_manager : "SimpleLayout",
theme_advanced_buttons1 : "bold,italic,underline,strikethrough,|,sub,sup,|,forecolor,backcolor,|,blockquote,|,link,unlink",
theme_advanced_buttons2 : "formatselect,|,justifyleft,justifycenter,justifyright,|,bullist,numlist,outdent,indent,|,removeformat,code",
theme_advanced_buttons3 : "",
theme_advanced_toolbar_location : "top",
theme_advanced_toolbar_align : "left",
theme_advanced_resizing : true
theme_advanced_toolbar_align : "left"
});
tinyMCE.execCommand("mceAddControl", true, "tinymce");
</script>

View file

@ -0,0 +1,54 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>TinyMCE</title>
<link type="text/css" rel="stylesheet" href="../../../skin/default/zotero/tinymce/note-ui.css"/>
<style>
table.mceLayout > tbody > tr.mceLast {
top: 0;
}
</style>
<script type="text/javascript" src="tiny_mce.js"></script>
<script type="text/javascript">
tinyMCE.init({
// General options
mode : "none",
theme : "advanced",
content_css : "../../../skin/default/zotero/tinymce/note-content.css",
button_tile_map : true,
language : "en", // TODO: localize
entity_encoding : "raw",
gecko_spellcheck : true,
readonly : true,
handle_event_callback : function (event) {
if (handleEvent) {
handleEvent(event);
}
},
onchange_callback : function () {
var event = { type: 'change' };
if (handleEvent) {
handleEvent(event);
}
},
fix_list_elements : true,
fix_table_elements : true,
/*plugins : "xhtmlxtras",*/
// Theme options
theme_advanced_buttons1 : "",
theme_advanced_buttons2 : "",
theme_advanced_buttons3 : "",
theme_advanced_toolbar_location : "top",
theme_advanced_toolbar_align : "left"
});
tinyMCE.execCommand("mceAddControl", true, "tinymce");
</script>
</head>
<body>
<div id="tinymce"></div>
</body>
</html>

View file

@ -0,0 +1,32 @@
html, body {
height: 100%;
margin: 0;
}
#tinymce_parent {
display: block;
height: 100%;
}
#tinymce_tbl {
height: 100% !important;
width: 100% !important;
}
table.mceLayout > tbody > tr.mceLast {
position: absolute;
display: block;
top: 54px;
bottom: 2px;
left: 1px;
right: 1px;
}
td.mceIframeContainer {
display: block;
height: 100% !important;
width: 100% !important;
}
#tinymce_ifr {
height: 100% !important;
width: 100% !important;
}