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