]> CyberLeo.Net >> Repos - SourceForge/phpwiki.git/blob - lib/WysiwygEdit/htmlarea3.php
rcs_id no longer makes sense with Subversion global version number
[SourceForge/phpwiki.git] / lib / WysiwygEdit / htmlarea3.php
1 <?php
2 // rcs_id('$Id$');
3 /**
4  * requires installation into themes/default/htmlarea3/
5  * MSIE => 5.5,  Mozilla >= 1.3
6  *
7  * @package WysiwygEdit
8  * @author Reini Urban
9  */
10
11 require_once("lib/WysiwygEdit.php");
12
13 class WysiwygEdit_htmlarea3 extends WysiwygEdit {
14
15     function Head($name='edit[content]') {
16         global $WikiTheme;
17         $WikiTheme->addMoreAttr('body'," onload='initEditor()'");
18         //Todo: language selection from available lang/*.js files
19         return new RawXml('
20 <script type="text/javascript" src="'.DATA_PATH.'/themes/default/htmlarea3/htmlarea.js"></script>
21 <script type="text/javascript" src="'.DATA_PATH.'/themes/default/htmlarea3/lang/en.js"></script>
22 <script type="text/javascript" src="'.DATA_PATH.'/themes/default/htmlarea3/dialog.js"></script> 
23 <style type="text/css">
24 @import url('.DATA_PATH.'/themes/default/htmlarea3/htmlarea.css);
25 </style>
26 <script type="text/javascript">
27 _editor_url = "'.DATA_PATH.'/themes/default/htmlarea3/";
28 var editor = null;
29 function initEditor() {
30   editor = new HTMLArea("'.$name.'");
31
32   // comment the following two lines to see how customization works
33   editor.generate();
34   return false;
35   
36   // BEGIN: code that adds custom buttons
37   var cfg = editor.config; // this is the default configuration
38   function clickHandler(editor, buttonId) {
39     switch (buttonId) {
40       case "my-toc":
41         editor.insertHTML("<?plugin CreateToc ?>");
42         break;
43       case "my-date":
44         editor.insertHTML((new Date()).toString());
45         break;
46       case "my-bold-em":
47         editor.execCommand("bold");
48         editor.execCommand("italic");
49         break;
50       case "my-hilite":
51         editor.surroundHTML("<span class=\"hilite\">", "</span>");
52         break;
53     }
54   };
55   cfg.registerButton("my-toc",  "Insert TOC", _editor_url+"ed_custom.gif", false, clickHandler);
56   cfg.registerButton("my-date", "Insert date/time", _editor_url+"ed_custom.gif", false, clickHandler);
57   cfg.registerButton("my-bold-em", "Toggle bold/italic", _editor_url+"ed_custom.gif", false, clickHandler);
58   cfg.registerButton("my-hilite", "Hilite selection", _editor_url+"ed_custom.gif", false, clickHandler);
59   
60   cfg.registerButton("my-sample", "Class: sample", _editor_url+"ed_custom.gif", false,
61     function(editor) {
62       if (HTMLArea.is_ie) {
63         editor.insertHTML("<span class=\"sample\">&nbsp;&nbsp;</span>");
64         var r = editor._doc.selection.createRange();
65         r.move("character", -2);
66         r.moveEnd("character", 2);
67         r.select();
68       } else { // Gecko/W3C compliant
69         var n = editor._doc.createElement("span");
70         n.className = "sample";
71         editor.insertNodeAtSelection(n);
72         var sel = editor._iframe.contentWindow.getSelection();
73         sel.removeAllRanges();
74         var r = editor._doc.createRange();
75         r.setStart(n, 0);
76         r.setEnd(n, 0);
77         sel.addRange(r);
78       }
79     }
80   );
81   
82   //cfg.pageStyle = "body { background-color: #efd; } .hilite { background-color: yellow; } "+
83   //                ".sample { color: green; font-family: monospace; }";
84   // add the new button to the toolbar
85   //cfg.toolbar.push(["linebreak", "my-toc", "my-date", "my-bold-em", "my-hilite", "my-sample"]); 
86   // END: code that adds custom buttons
87
88   editor.generate();
89 }
90 function insertHTML() {
91   var html = prompt("Enter some HTML code here");
92   if (html) {
93     editor.insertHTML(html);
94   }
95 }
96 function highlight() {
97   editor.surroundHTML(\'<span style="background-color: yellow">\', \'</span>\');
98 }
99 </script>
100  ');
101     }
102
103     function Textarea($textarea,$wikitext,$name='edit[content]') {
104         $out = HTML($textarea,HTML::div(array("id"=>"editareawiki",'style'=>'display:none'),$wikitext),"\n");
105         //TODO: maybe some more custom links
106         return $out;
107     }
108 }
109
110 // Local Variables:
111 // mode: php
112 // tab-width: 8
113 // c-basic-offset: 4
114 // c-hanging-comment-ender-p: nil
115 // indent-tabs-mode: nil
116 // End:
117 ?>