source: trunk/examples/ext_example-body.html @ 353

Last change on this file since 353 was 353, checked in by gocher, 14 years ago

javascript error handler for ext_example, and two little mistakes

File size: 8.6 KB
Line 
1<!DOCTYPE BHTML PUBLIC "-//BC//DTD BHTML 3.2 Final//EN">
2<html>
3<head>
4
5  <!-- ---------------------------------------------------------------------
6    --  $HeadURL: http://svn.xinha.python-hosting.com/trunk/examples/ext_example-body.html $
7    --  $LastChangedDate: 2005-07-27 16:43:19 +0200 (Mi, 27 Jul 2005) $
8    --  $LastChangedRevision: 287 $
9    --  $LastChangedBy: gocher $
10    ------------------------------------------------------------------------ -->
11
12  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
13  <title>Example of Xinha</title>
14  <link rel="stylesheet" href="full_example.css" />
15
16  <script type="text/javascript">
17    function showError( sMsg, sUrl, sLine){
18      document.getElementById('errors').value += 'Error: ' + sMsg + '\n' +
19                                                 'Source File: ' + sUrl + '\n' +
20                                                 'Line: ' + sLine + '\n';
21      return false;
22    }
23    window.onerror = showError;
24    document.onerror = showError;
25
26    var f = window.parent.menu.document.forms[0];
27    // You must set _editor_url to the URL (including trailing slash) where
28    // where xinha is installed, it's highly recommended to use an absolute URL
29    //  eg: _editor_url = "/path/to/xinha/";
30    // You may try a relative URL if you wish]
31    //  eg: _editor_url = "../";
32    // in this example we do a little regular expression to find the absolute path.
33    _editor_url  = document.location.href.replace(/examples\/ext_example-body\.html.*/, '')
34    _editor_lang = f.lang.value; // And the language we need to use in the editor.
35    _editor_skin = f.skin.value; // the skin we use in the editor
36  </script>
37
38  <!-- Load up the actual editor core -->
39  <script type="text/javascript" src="../htmlarea.js"></script>
40
41  <script type="text/javascript">
42    xinha_editors = null;
43    xinha_init    = null;
44    xinha_config  = null;
45    xinha_plugins = null;
46   
47    xinha_init = xinha_init ? xinha_init : function() {
48      var f = window.parent.menu.document.forms[0];
49// What are the plugins you will be using in the editors on this page.
50// List all the plugins you will need, even if not all the editors will use all the plugins.
51      xinha_plugins = [ ];
52      for(var x = 0; x < f.plugins.length; x++) {
53        if(f.plugins[x].checked) xinha_plugins.push(f.plugins[x].value);
54      }
55
56      // THIS BIT OF JAVASCRIPT LOADS THE PLUGINS, NO TOUCHING  :)
57      if(!HTMLArea.loadPlugins(xinha_plugins, xinha_init)) return;
58
59// What are the names of the textareas you will be turning into editors?
60      var num = 1;
61      num = parseInt(f.num.value);
62      if(isNaN(num)) {
63        num = 1;
64        f.num.value = 1;
65      }
66      var b = document.forms[0];
67      var lipsum = window.parent.menu.document.getElementById('myTextarea0').value;
68
69      xinha_editors = [ ]
70      for(var x = 0; x < num; x++) {
71        var ta = 'myTextarea' + x;
72        xinha_editors.push(ta);
73       
74        var div = document.createElement('div');
75        div.className = 'area_holder';
76
77        var txta = document.createElement('textarea');
78        txta.id   = ta;
79        txta.name = ta;
80        txta.value = lipsum;
81        txta.style.width="100%";
82        txta.style.height="420px";
83
84        div.appendChild(txta);
85        b.appendChild(div);
86      }
87
88// Create a default configuration to be used by all the editors.
89      xinha_config = new HTMLArea.Config();
90      if (f.width) xinha_config.width = f.width.value;
91      if (f.height) xinha_config.height = f.height.value;
92      if (f.sizeIncludesBars) xinha_config.sizeIncludesBars = f.sizeIncludesBars.value;
93      if (f.statusBar) xinha_config.statusBar = f.statusBar.value;
94      if (f.mozParaHandler) xinha_config.mozParaHandler = f.mozParaHandler.value;
95      if (f.undoSteps) xinha_config.undoSteps = f.undoSteps.value;
96      if (f.baseHref) xinha_config.baseHref = f.baseHref.value;
97      if (f.stripBaseHref) xinha_config.stripBaseHref = f.stripBaseHref.value;
98      if (f.stripSelfNamedAnchors) xinha_config.stripSelfNamedAnchors = f.stripSelfNamedAnchors.value;
99      if (f.only7BitPrintablesInURLs) xinha_config.only7BitPrintablesInURLs = f.only7BitPrintablesInURLs.value;
100      if (f.sevenBitClean) xinha_config.sevenBitClean = f.sevenBitClean.value;
101      if (f.killWordOnPaste) xinha_config.killWordOnPaste = f.killWordOnPaste.value;
102      if (f.flowToolbars) xinha_config.flowToolbars = f.flowToolbars.value;
103      if ((typeof CharacterMap != 'undefined') && (f.CharacterMapMode)) xinha_config.CharacterMap.mode = f.CharacterMapMode.value;
104      if ((typeof ListType != 'undefined') && (f.ListTypeMode)) xinha_config.ListType.mode = f.ListTypeMode.value;
105
106      if(typeof CSS != 'undefined') {
107        xinha_config.pageStyle = "@import url(custom.css);";
108      }
109
110      if(typeof Stylist != 'undefined') {
111        // We can load an external stylesheet like this - NOTE : YOU MUST GIVE AN ABSOLUTE URL
112        //  otherwise it won't work!
113        xinha_config.stylistLoadStylesheet(document.location.href.replace(/[^\/]*\.html/, 'stylist.css'));
114
115        // Or we can load styles directly
116        xinha_config.stylistLoadStyles('p.red_text { color:red }');
117
118        // If you want to provide "friendly" names you can do so like
119        // (you can do this for stylistLoadStylesheet as well)
120        xinha_config.stylistLoadStyles('p.pink_text { color:pink }', {'p.pink_text' : 'Pretty Pink'});
121      }
122
123      if(typeof DynamicCSS != 'undefined') {
124        xinha_config.pageStyle = "@import url(dynamic.css);";
125      }
126
127      if(typeof InsertWords != 'undefined') {
128        // Register the keyword/replacement list
129        var keywrds1 = new Object();
130        var keywrds2 = new Object();
131
132        keywrds1['-- Dropdown Label --'] = '';
133        keywrds1['onekey'] = 'onevalue';
134        keywrds1['twokey'] = 'twovalue';
135        keywrds1['threekey'] = 'threevalue';
136
137        keywrds2['-- Insert Keyword --'] = '';
138        keywrds2['Username'] = '%user%';
139        keywrds2['Last login date'] = '%last_login%';
140        xinha_config.InsertWords = {
141          combos : [ { options: keywrds1, context: "body" },
142                     { options: keywrds2, context: "li" } ]
143        }
144      }
145
146      if(typeof InsertPicture != 'undefined') {
147        // Path for InsertPicture plugin
148        InsertPicture.PicturePath = '/schmal/pictures/';
149      }
150
151// First create editors for the textareas.
152// You can do this in two ways, either
153//   xinha_editors   = HTMLArea.makeEditors(xinha_editors, xinha_config, xinha_plugins);
154// if you want all the editor objects to use the same set of plugins, OR;
155//   xinha_editors = HTMLArea.makeEditors(xinha_editors, xinha_config);
156//   xinha_editors['myTextArea'].registerPlugins(['Stylist','FullScreen']);
157//   xinha_editors['anotherOne'].registerPlugins(['CSS','SuperClean']);
158// if you want to use a different set of plugins for one or more of the editors.
159      xinha_editors = HTMLArea.makeEditors(xinha_editors, xinha_config, xinha_plugins);
160
161// If you want to change the configuration variables of any of the editors, 
162// this is the place to do that, for example you might want to
163// change the width and height of one of the editors, like this...
164//   xinha_editors.myTextArea.config.width  = '640px';
165//   xinha_editors.myTextArea.config.height = '480px';
166
167// Finally we "start" the editors, this turns the textareas into Xinha editors.
168      HTMLArea.startEditors(xinha_editors);
169   
170      //check submitted values
171      var submit = document.createElement('button');
172      submit.setAttribute('type', 'submit'); //submit.type = "submit";
173      submit.innerHTML = "Submit";
174      b.appendChild(submit);
175    }
176
177    window.onload = xinha_init;
178  </script>
179</head>
180
181<body>
182  <form id="editors_here" method="post" action="ext_example-dest.php">
183  <!-- <textarea id="errors" style="width:100%; height:100px; background:silver;display:none;"></textarea> -->
184  </form>
185  <textarea id="errors" style="width:100%; height:100px; background:silver;"></textarea>
186<script type="text/javascript">
187    var _oldSubmitHandler = null;
188    if (document.forms[0].onsubmit != null) {
189      _oldSubmitHandler = document.forms[0].onsubmit;
190    }
191    function frame_onSubmit(){
192      document.getElementById('myTextarea0').value = document.getElementById('myTextarea0').value.replace(/^[\r\n]+|\s+$/, '')
193      window.parent.menu.document.getElementById('myTextarea0').value = document.getElementById('myTextarea0').value;
194      if (_oldSubmitHandler != null) {
195        _oldSubmitHandler();
196      }
197    }
198    document.forms[0].onsubmit = frame_onSubmit;
199</script>
200</body>
201</html>
Note: See TracBrowser for help on using the repository browser.