Ticket #1552: opencore.html

File opencore.html, 7.8 KB (added by guest, 9 years ago)

sample/test configuration using wicked_validator.js linkValidator

Line 
1<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
2<html>
3<head>
4<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
5<title>Simple example of Xinha</title>
6<script type="text/javascript">
7var _editor_url  = document.location.href.replace(/examples\/opencore\.html.*/, '')
8
9var _editor_lang = "en";
10</script>
11<!-- Load up the actual editor core -->
12<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4/jquery.min.js"></script> 
13
14<script type="text/javascript" src="../XinhaCore.js"></script>
15<script type="text/javascript" src="./wicked_validator.js"></script>
16<script type="text/javascript">
17
18var xinha_plugins =
19[
20// 'Linker'
21];
22var xinha_editors =
23[
24  'myTextArea',
25  'anotherOne'
26];
27
28function xinha_init()
29{
30  if(!Xinha.loadPlugins(xinha_plugins, xinha_init)) return;
31
32  var xinha_config = new Xinha.Config();
33  xinha_config.linkValidator = function(editor, a, _lc) {
34    var sel = editor.getSelectedHTML();
35    if( sel == "dolor" ) return _lc("You can't link dolor!");
36  };
37  xinha_config.linkValidator = checkWickedLinks;
38  xinha_editors = Xinha.makeEditors(xinha_editors, xinha_config, xinha_plugins);
39
40  Xinha.startEditors(xinha_editors);
41}
42Xinha.addOnloadHandler(xinha_init);
43</script>
44
45</head>
46
47<body>
48
49<form onsubmit="alert(this.myTextArea.value); return false;">
50<textarea id="myTextArea" name="myTextArea" rows="25" cols="80">
51&lt;p&gt;Lorem ipsum dolor sit amet, consectetuer adipiscing elit.
52Aliquam et tellus vitae justo varius placerat. Suspendisse iaculis
53velit semper <span id="dolor">dolor</span>.
54<span id="donec">((Donec)) gravida tincidunt mi.</span>
55Curabitur tristique
56<span id="3"> ante elementum turpis. ((Aliquam nisl. ((Nulla posuere)) neque non</span>
57tellus. Morbi vel nibh. Cum sociis natoque penatibus et magnis dis
58<span id="4">parturient montes, ((nascetur <span>ridiculus))</span> mus. Nam nec wisi. In wisi.</span>
59Curabitur pharetra bibendum lectus.&lt;/p&gt;
60</textarea>
61</form>
62
63<h3>
64  Test link button (in Chrome, at least)
65</h3>
66<pre style="float: right;" id="test_link_empty">
67var ed = Xinha.getEditor("myTextArea");
68var linkButton = ed.config.btnList.createlink[3];
69
70// make sure nothing is selected
71var sel = ed.getSelection();
72sel.removeAllRanges();
73
74// we can't make a link with no selection
75linkButton();
76</pre>
77
78<pre style="float: right;" id="test_link_word">
79var ed = Xinha.getEditor("myTextArea");
80var linkButton = ed.config.btnList.createlink[3];
81
82// let's select the word "dolor" now
83// our linkValidator function should prevent us
84var dolor = ed._doc.getElementById("dolor");
85ed.selectNodeContents(dolor);
86linkButton();
87</pre>
88
89<pre style="float: right;" id="test_link_wicked">
90var ed = Xinha.getEditor("myTextArea");
91var linkButton = ed.config.btnList.createlink[3];
92
93var node = ed._doc.getElementById("donec");
94var text = node.childNodes[0];
95
96ed.selectNodeContents(node);
97var sel = ed.getSelection();
98var range = ed.createRange(sel);
99
100// let's select the text "((Don"
101sel.removeAllRanges();
102range.setEnd(text, 5);
103sel.addRange(range);
104
105// now we can make a link
106linkButton();
107</pre>
108
109<pre style="float: right;" id="test_link_wicked2">
110var ed = Xinha.getEditor("myTextArea");
111var linkButton = ed.config.btnList.createlink[3];
112
113var node = ed._doc.getElementById("donec");
114var text = node.childNodes[0];
115
116ed.selectNodeContents(node);
117var sel = ed.getSelection();
118var range = ed.createRange(sel);
119
120// let's select the text "nec))"
121sel.removeAllRanges();
122range.setStart(text, 5);
123range.setEnd(text, 9);
124sel.addRange(range);
125
126// now we can make a link
127linkButton();
128</pre>
129
130<pre style="float: right;" id="test_link_wicked3">
131var ed = Xinha.getEditor("myTextArea");
132var linkButton = ed.config.btnList.createlink[3];
133
134var node = ed._doc.getElementById("donec");
135var text = node.childNodes[0];
136
137ed.selectNodeContents(node);
138var sel = ed.getSelection();
139var range = ed.createRange(sel);
140
141// let's select the word "Donec"
142sel.removeAllRanges();
143range.setStart(text, 2);
144range.setEnd(text, 7);
145sel.addRange(range);
146
147// now we can make a link
148linkButton();
149</pre>
150
151<pre style="float: right;" id="test_link_wicked4">
152var ed = Xinha.getEditor("myTextArea");
153var linkButton = ed.config.btnList.createlink[3];
154
155var node = ed._doc.getElementById("donec");
156var text = node.childNodes[0];
157
158ed.selectNodeContents(node);
159var sel = ed.getSelection();
160var range = ed.createRange(sel);
161
162// let's select the text "Donec)) grav"
163sel.removeAllRanges();
164range.setStart(text, 2);
165range.setEnd(text, 13);
166sel.addRange(range);
167
168// now we can make a link
169linkButton();
170</pre>
171
172<pre style="float: right;" id="test_link_wicked5">
173var ed = Xinha.getEditor("myTextArea");
174var linkButton = ed.config.btnList.createlink[3];
175
176var node = ed._doc.getElementById("donec");
177var text = node.childNodes[0];
178
179ed.selectNodeContents(node);
180var sel = ed.getSelection();
181var range = ed.createRange(sel);
182
183// let's select the text "((Donec)) grav"
184sel.removeAllRanges();
185range.setEnd(text, 13);
186sel.addRange(range);
187
188// now we can make a link
189linkButton();
190</pre>
191
192<pre style="float: right;" id="test_link_wicked6">
193var ed = Xinha.getEditor("myTextArea");
194var linkButton = ed.config.btnList.createlink[3];
195
196var node = ed._doc.getElementById("3");
197var text = node.childNodes[0];
198
199ed.selectNodeContents(node);
200var sel = ed.getSelection();
201var range = ed.createRange(sel);
202
203// let's select the text "((Aliquam nisl"
204sel.removeAllRanges();
205range.setStart(text, 24);
206range.setEnd(text, 30);
207sel.addRange(range);
208
209// now we can make a link
210linkButton();
211</pre>
212
213<pre style="float: right;" id="test_link_wicked7">
214var ed = Xinha.getEditor("myTextArea");
215var linkButton = ed.config.btnList.createlink[3];
216
217var node = ed._doc.getElementById("3");
218var text = node.childNodes[0];
219
220ed.selectNodeContents(node);
221var sel = ed.getSelection();
222var range = ed.createRange(sel);
223
224// let's select the text "((Nulla posuere"
225sel.removeAllRanges();
226range.setStart(text, 40);
227range.setEnd(text, 45);
228sel.addRange(range);
229
230// now we can make a link
231linkButton();
232</pre>
233
234<pre style="float: right;" id="test_link_wicked8">
235var ed = Xinha.getEditor("myTextArea");
236var linkButton = ed.config.btnList.createlink[3];
237
238var node = ed._doc.getElementById("4");
239var text = node.childNodes[0];
240
241ed.selectNodeContents(node);
242var sel = ed.getSelection();
243var range = ed.createRange(sel);
244
245// let's select the text "nascetur"
246sel.removeAllRanges();
247range.setStart(text, 19);
248range.setEnd(text, 24);
249sel.addRange(range);
250
251// now we can make a link
252linkButton();
253</pre>
254
255<pre style="float: right;" id="test_link_wicked9">
256var ed = Xinha.getEditor("myTextArea");
257var linkButton = ed.config.btnList.createlink[3];
258
259var node = ed._doc.getElementById("4");
260var text = node.childNodes[0];
261
262ed.selectNodeContents(node);
263var sel = ed.getSelection();
264var range = ed.createRange(sel);
265
266// let's select the text "ridiculus"
267sel.removeAllRanges();
268range.setEnd(text, 13);
269sel.addRange(range);
270
271// now we can make a link
272linkButton();
273</pre>
274
275<button onclick="eval(jQuery('#test_link_empty').text()); return false;">Test 1
276</button>
277
278<button onclick="eval(jQuery('#test_link_word').text()); return false;">Test 2
279</button>
280
281<button onclick="eval(jQuery('#test_link_wicked').text()); return false;">Test 3
282</button>
283
284<button onclick="eval(jQuery('#test_link_wicked2').text()); return false;">Test 3
285</button>
286
287<button onclick="eval(jQuery('#test_link_wicked3').text()); return false;">Test 3
288</button>
289
290<button onclick="eval(jQuery('#test_link_wicked4').text()); return false;">Test 3
291</button>
292
293<button onclick="eval(jQuery('#test_link_wicked5').text()); return false;">Test 3
294</button>
295
296<button onclick="eval(jQuery('#test_link_wicked6').text()); return false;">Test 3
297</button>
298
299<button onclick="eval(jQuery('#test_link_wicked7').text()); return false;">Test 3
300</button>
301
302<button onclick="eval(jQuery('#test_link_wicked8').text()); return false;">Test 3
303</button>
304
305<button onclick="eval(jQuery('#test_link_wicked9').text()); return false;">Test 3
306</button>
307
308</body>
309</html>