<!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>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<link type="text/css" rel="stylesheet" href="css/note-ui.css"/>
<script type="text/javascript" src="tinymce.js"></script>
<script type="text/javascript" src="locale.js"></script>
<script type="text/javascript">
	tinymce.init({
		body_id: "zotero-tinymce-note",
		content_css: "css/note-content.css",
		
		browser_spellcheck: true,
		convert_urls: false,
		entity_encoding: 'raw',
		fix_list_elements: true,
		paste_retain_style_properties: 'all',
		paste_data_images: true,
		
		plugins: "autolink,code,contextmenu,directionality,link,lists,paste,searchreplace,textcolor",
		
		toolbar1: "bold italic underline strikethrough | subscript superscript | forecolor backcolor | blockquote link | removeformat",
		toolbar2: "formatselect | alignleft aligncenter alignright | bullist numlist outdent indent |  %DIR% | searchreplace",
		toolbar_items_size: 'small',
		menubar: false,
		resize: false,
		statusbar: false,
		
		contextmenu: "link | dir | code",
		
		link_context_toolbar: true,
		link_assume_external_targets: true,
		
		target_list: false,
		
		setup: function (ed) {
			setLocale(ed);
			
			// Set text direction
			var dir = window.location.href.match(/dir=(ltr|rtl)/)[1];
			var opDir = dir.split("").reverse().join("");
			ed.settings.directionality = dir;
			ed.addMenuItem('dir', {
				icon: opDir,
				// TODO: Show correct label based on current line
				text: opDir == 'rtl' ? "Right to left" : "Left to right",
				onclick: function () {
					ed.execCommand('mceDirection' + opDir.toUpperCase());
				},
				context: 'insert',
				prependToContext: true
			});
		},
		
		init_instance_callback: function (ed) {
			zoteroInit(ed);
			
			['Change', 'KeyDown', 'KeyPress', 'Undo', 'Redo'].forEach(eventName =>
				ed.on(eventName, event => zoteroHandleEvent(event))
			);
			
			["Cut", "Copy", "Paste"].forEach(function (command) {
				let cmd = command;
				ed.addCommand(command, function (ui, value) {
					zoteroExecCommand(ed.getDoc(), cmd, ui, value);
				});
			});
			
			["ZoteroLinkClick"].forEach(function (command) {
				ed.addCommand(command, function (ui, value) {
					zoteroHandleEvent({
						type: command,
						value
					});
				});
			});
		}
	});
	tinymce.execCommand("mceAddEditor", true, "tinymce");
</script>
</head>
<body>
<div id="tinymce"></div>
</body>
</html>