/[webpac2]/Webpacus/root/editor/editor.js
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Contents of /Webpacus/root/editor/editor.js

Parent Directory Parent Directory | Revision Log Revision Log


Revision 175 - (show annotations)
Sun Nov 27 04:45:56 2005 UTC (18 years, 5 months ago) by dpavlin
File MIME type: application/javascript
File size: 4658 byte(s)
 r11186@llin:  dpavlin | 2005-11-27 05:48:19 +0100
 first try at implementing decent text-only editor, based on quicktags
 added tab support and dynamic creation of toolbars

1 /*
2 Webpacus template editor
3 */
4
5 var rec = null;
6 var url = null;
7 var template_filename = null;
8
9 var pending_js = null;
10
11 var css_rnd = 0;
12
13 function _ts(text) {
14 var el = $('div_template_status');
15 if (el) el.innerHTML = text;
16 }
17
18 function _cs(text) {
19 var el = $('div_css_status');
20 if (el) el.innerHTML = text;
21 }
22
23 function load_rec(nr) {
24 Logger.debug('load_rec '+nr);
25
26 if (loading.record) {
27 Logger.info('loading of record '+nr+' skipped, load in progress');
28 return;
29 }
30
31 show_working();
32 $('record_nr').disabled = 'true';
33
34 if (nr == 1) {
35 Element.addClassName('a_left_arr', 'nav_disable');
36 } else {
37 Element.removeClassName('a_left_arr', 'nav_disable');
38 }
39
40 var args = '?mfn='+nr+'&template_filename='+template_filename;
41
42 new Ajax.Updater( 'div_record', url+'record'+args, {
43 asynchronous: 1,
44 onLoading: function(request) {
45 loading.record = 1;
46 Logger.info('load_rec.onLoading: '+nr);
47 },
48 onLoaded: function(request) {
49 loading.record = 0;
50 hide_working();
51 $('record_nr').value = nr;
52 $('record_nr').disabled = '';
53 rec = nr;
54 Logger.info('load_rec.onLoaded: '+nr);
55 }
56 } ) ;
57
58 }
59
60 function inc_rec() {
61 show_working();
62 rec++;
63 load_rec(rec);
64 hide_working();
65 return false;
66 }
67
68 function dec_rec() {
69 if (rec > 1) {
70 show_working();
71 rec--;
72 load_rec(rec);
73 hide_working();
74 }
75 return false;
76 }
77
78 function reload_rec() {
79 show_working();
80 load_rec(rec);
81 hide_working();
82 return false;
83 }
84
85 var current_edit = '';
86
87 function edit_template() {
88 $('div_css').style.visibility = "hidden";
89 $('div_css').style.zIndex = 1;
90 Element.removeClassName('a_css', 'tab_selected');
91 Element.addClassName('a_template', 'tab_selected');
92 $('div_template').style.visibility = "visible";
93 $('div_template').style.zIndex = 2;
94 Logger.debug("switched to template editor");
95 var c = $('template_content');
96 if (c) c.focus();
97 Logger.debug('zIndex template:'+$('div_template').style.zIndex+' css:'+$('div_css').style.zIndex);
98 return false;
99 }
100
101 function edit_css() {
102 $('div_template').style.visibility = "hidden";
103 $('div_template').style.zIndex = 1;
104 Element.removeClassName('a_template', 'tab_selected');
105 Element.addClassName('a_css', 'tab_selected');
106 $('div_css').style.visibility = "visible";
107 $('div_css').style.zIndex = 2;
108 Logger.debug("switched to CSS editor");
109 var c = $('css_content');
110 if (c) c.focus();
111 Logger.debug('zIndex template:'+$('div_template').style.zIndex+' css:'+$('div_css').style.zIndex);
112 return false;
113 }
114
115 function switch_template(new_template_filename) {
116
117 Logger.info('switch_template to '+new_template_filename);
118 show_working();
119
120 Logger.debug('load template editor');
121 template_filename = new_template_filename;
122 load_template(new_template_filename);
123
124 Logger.debug('refresh record');
125 load_rec(rec);
126
127 edKill('template_content');
128
129 hide_working();
130
131 return false;
132 }
133
134 var loading = {
135 template: 0,
136 css: 0,
137 record: 0
138 };
139
140 function load_template( template_filename ) {
141
142 if (loading.template) {
143 Logger.info('loading of template '+template_filename+' skipped, load in progress');
144 return;
145 }
146
147 show_working();
148
149 var args = '?template_filename='+template_filename;
150
151 new Ajax.Updater( 'div_template', url+'template'+args, {
152 asynchronous: 1,
153 onLoading: function(request) {
154 loading.template = 1;
155 Logger.info('load_template.onLoading: '+template_filename);
156 },
157 onLoaded: function(request) {
158 loading.template = 0;
159 Position.clone('div_template', 'div_css');
160 hide_working();
161 Logger.info('load_template.onLoaded: '+template_filename);
162 }
163 } ) ;
164 }
165
166 function load_css(css_filename) {
167
168 if (loading.css) {
169 Logger.info('loading of css '+css_filename+' skipped, load in progress');
170 return;
171 }
172
173 show_working();
174
175 new Ajax.Updater( 'div_css', url+'css', {
176 asynchronous: 1,
177 onLoading: function(request) {
178 loading.css = 1;
179 Logger.info('load_css.onLoading: '+css_filename);
180 },
181 onLoaded: function(request) {
182 loading.css = 0;
183 hide_working();
184 Logger.info('load_css.onLoaded: '+css_filename);
185 }
186 } ) ;
187 };
188
189 function reload_css() {
190
191 css_rnd++;
192 Logger.info('loading user.css?'+css_rnd);
193 $('user_css_link').href = 'css/user.css?'+css_rnd;
194
195 return false;
196 }
197
198 var working_count = 0;
199
200 function show_working() {
201 working_count++;
202 if (working_count > 1) Element.show('working');
203 Logger.debug('show_working, count = '+working_count);
204 }
205
206 function hide_working() {
207 working_count--;
208 if (working_count < 1) Element.hide('working');
209 Logger.debug('hide_working, count = '+working_count);
210 }
211
212 function init_page() {
213
214 show_working();
215
216 edit_template();
217
218 // load css editor
219 load_css();
220
221 // load template editor and record
222 switch_template(template_filename);
223
224 hide_working();
225
226 }
227

  ViewVC Help
Powered by ViewVC 1.1.26