/[pub]/suikawiki/script/misc/plugins/view/stylesheet.wp2
Suika

Contents of /suikawiki/script/misc/plugins/view/stylesheet.wp2

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.7 - (show annotations) (download)
Sun Aug 8 08:11:06 2004 UTC (20 years, 2 months ago) by wakaba
Branch: MAIN
Changes since 1.6: +2 -1 lines
SuikaWiki/0.10 added

1 #?SuikaWikiConfig/2.0
2
3 Plugin:
4 @Name: StyleSheet
5 @Description:
6 @@@: Stylesheet support
7 @@lang:en
8 @License: %%Perl%%
9 @Author:
10 @@Name:
11 @@@@: Wakaba
12 @@@lang:ja
13 @@@script:Latn
14 @@Mail[list]: w@suika.fam.cx
15 @Date.RCS:
16 $Date: 2004/07/25 06:54:29 $
17 @RequiredPlugin[list]:
18 Error
19 HTML
20 @RequiredModule[list]:
21 URI
22 @Use:
23 use URI;
24 use Message::Util::Error;
25 my $WIKIRESOURCE;
26 @Namespace:
27 @@ss:
28 http://suika.fam.cx/~wakaba/archive/2004/05/sw-stylesheet#
29 @@media-type:
30 http://suika.fam.cx/~wakaba/-temp/2004/04/24/mt#
31 @@edit:
32 http://suika.fam.cx/~wakaba/-temp/2004/7/25/sw-edit#
33
34 PluginConst:
35 @NS_XHTML1:
36 http://www.w3.org/1999/xhtml
37 @WIKIRESOURCE:
38 {($WIKIRESOURCE ||= SuikaWiki::Plugin->module_package ('WikiResource'))}
39
40 Format:
41 @ModuleName:
42 StyleSheet::CSS
43
44 @Name: CSS
45 @Type: text/css
46 @Description:
47 @@@: Cascading Style Sheets (CSS)
48 @@lang: en
49
50 @Use:
51 use Message::Markup::XML::QName qw(NS_xml_URI);
52
53 @Converter:
54 @@Type: text/css
55 @@Description:
56 @@@: CSS -> CSS (no convertion)
57 @@lang: en
58 @@ToString:
59 return $$source;
60 ## BUG: Insecure specification MUST be removed
61
62 @Converter:
63 @@Type: text/html
64 @@IsFragment: 1
65 @@Description:
66 @@@: CSS with some decoration, marked-up in HTML
67 @@lang: en
68 @@Main:
69 my $node = $opt->{-parent}->append_new_node
70 (type => '#element',
71 namespace_uri => $NS_XHTML1,
72 local_name => 'pre');
73 $node->set_attribute (class => 'text-css');
74 $node->set_attribute (space => 'preserve', namespace_uri => NS_xml_URI);
75 $node->append_text ($$source);
76 return $node;
77
78 @content_written:
79 @@Main:
80 if ($opt{wiki}->{config}->{<Q:ss:use-static>}) {
81 $opt{wiki}->{db}->set (static__css => $opt{page} => ${$opt{new_content}});
82 }
83
84 @content_removed:
85 @@Main:
86 if ($opt{wiki}->{config}->{<Q:ss:use-static>}) {
87 $opt{wiki}->{db}->delete (static__css => $opt{page});
88 }
89
90 @content_type_changed_from:
91 @@Main:
92 if ($opt{wiki}->{config}->{<Q:ss:use-static>}) {
93 $opt{wiki}->{db}->delete (static__css => $opt{page});
94 }
95
96 @Prop:
97 @@edit:new-mode--edit: edit
98 @@edit:new-mode--adminedit: adminedit
99
100 ViewDefinition:
101 @Mode: css
102 @Condition:
103 @@http-method[list]:
104 GET
105 HEAD
106 POST
107 @Description:
108 @@@: CSS Style Sheet
109 @@lang: en
110 @template:
111 @@http-status-code: 200
112 @@media-type: text/css
113 @@use-media-type-charset: 1
114 @@expires: %%stylesheet%%
115 @@body:
116 %read (Type => {text/css}, return-type => {ToString},
117 when-no-converter => 406);
118
119 FormattingRule:
120 @Category[list]:
121 view
122 view-resource
123 @Name: styles-wiki-html
124 @Description:
125 @@@:
126 Stylesheet list as HTML (link element)
127 @@lang: en
128 @Paramater:
129 @@Name: page
130 @@Type: WikiName
131 @@Default: (auto)
132 @@Description:
133 @@@@: WikiPage in which stylesheet list is defined
134 @@@lang: en
135 @Formatting:
136 my $list = __FUNCPACK__->_get_stylelist_definition_page
137 (page => $o->{wiki}->name
138 ($p->{page} ||
139 $o->{wiki}->{config}->{page}
140 ->{'StyleSheetList(text/html)'} ||
141 [qw!Wiki Style List text/html!]),
142 o => $o, wiki => $o->{wiki});
143 return unless $list;
144 my $parent = $p->{-parent};
145
146 my $ua_apply;
147 my $dg = $o->{wiki}->{var}->{client}->{downgrade};
148 if ($dg->{stylesheet_non_standard}) {
149 $ua_apply = $dg->{ua_netscape4} ? 'Netscape4'
150 : $dg->{ua_winie60} ? 'WinIE6.0'
151 : $dg->{ua_winie55} ? 'WinIE5.5'
152 : $dg->{ua_winie50} ? 'WinIE5.0'
153 : $dg->{ua_winie40} ? 'WinIE4.0'
154 : $dg->{ua_winie30} ? 'WinIE3.0'
155 : 1;
156 }
157
158 my $mkuri = $o->{wiki}->{config}->{<Q:ss:wikiname-to-uri>} ||
159 \ \&__FUNCPACK__::generate_uri;
160
161 for my $set (@{$list->child_nodes}) {
162 if ($set->local_name eq 'StyleSet') {
163 my $type = {
164 map {$_ => 1}
165 map {ref $_ ? @$_ : [$_]}
166 $set->get_attribute_value ('Apply', default => ['alternate'])
167 };
168 next if $ua_apply and not $type->{$ua_apply};
169 my $rel = $type->{alternate} ? 'alternate stylesheet' : 'stylesheet';
170 my $title = __FUNCPACK__->_get_styleset_title
171 (StyleSet => $set, o => $o,
172 type => $type);
173 for my $sheet (@{$set->child_nodes}) {
174 if ($sheet->local_name eq 'StyleSheet') {
175 my $link = $parent->append_new_node
176 (type => '#element',
177 namespace_uri => $NS_XHTML1,
178 local_name => 'link');
179 $link->option (use_EmptyElemTag => 1);
180 $link->set_attribute (rel => $rel);
181 $link->set_attribute (title => $title) unless $type->{persistent};
182 my $media_type = $sheet->get_attribute_value
183 ('Type', default => 'text/css');
184 ## TODO: parameter
185 $link->set_attribute (type => $media_type);
186 unless ($dg->{html_link_no_media}) {
187 my $media_descriptor = $sheet->get_attribute_value ('Media');
188 $link->set_attribute (media => $media_descriptor || 'all');
189 }
190 my $uri = $mkuri->(undef, o => $o, wiki => $o->{wiki},
191 wikiname => $o->{wiki}->name
192 ($sheet->get_attribute_value
193 ('WikiPage', default => '')),
194 mode => 'css'); ## ISSUE: Make this media-type independent!
195 $link->set_attribute (href => $uri);
196 $parent->append_text ("\n");
197 }
198 }
199
200 }
201 }
202
203 FormattingRule:
204 @Category[list]:
205 view
206 view-resource
207 @Name: styles-wiki-xml
208 @Description:
209 @@@:
210 Stylesheet list in xml-stylesheet processing instructions
211 @@lang: en
212 @Parameter:
213 @@Name: downgrade-html
214 @@Type: boolean
215 @@Default: "0"
216 @@Description:
217 @@@@:
218 HTML downgrade mode. PIs are not outputed if User-Agent does not
219 support PIs (eg. Classic Mozilla).
220 @@lang: en
221 @Paramater:
222 @@Name: page
223 @@Type: WikiName
224 @@Default: (auto)
225 @@Description:
226 @@@@: WikiPage in which stylesheet list is defined
227 @@@lang: en
228 @Formatting:
229 __ATTRTEXT:%downgrade_html__;
230 if ($p->{downgrade_html}) {
231 return if $o->{wiki}->{var}->{client}->{downgrade}->{html_no_pi};
232 }
233 my $list = __FUNCPACK__->_get_stylelist_definition_page
234 (page => $o->{wiki}->name
235 ($p->{page} ||
236 $o->{wiki}->{config}->{page}
237 ->{'StyleSheetList(text/html)'} ||
238 [qw!Wiki Style List text/html!]),
239 o => $o, wiki => $o->{wiki});
240 return unless $list;
241 my $parent = $p->{-parent};
242
243 my $mkuri = $o->{wiki}->{config}->{<Q:ss:wikiname-to-uri>} ||
244 \ \&__FUNCPACK__::generate_uri;
245
246 for my $set (@{$list->child_nodes}) {
247 if ($set->local_name eq 'StyleSet') {
248 my $type = {map {$_ => 1}
249 @{
250 $set->get_attribute_value ('Apply', default => ['alternate'])
251 }};
252 my $rel = $type->{alternate} ? 'alternate stylesheet' : 'stylesheet';
253 my $title = __FUNCPACK__->_get_styleset_title
254 (StyleSet => $set, o => $o,
255 type => $type);
256 for my $sheet (@{$set->child_nodes}) {
257 if ($sheet->local_name eq 'StyleSheet') {
258 my $link = $parent->append_new_node
259 (type => '#pi',
260 local_name => 'xml-stylesheet');
261 $link->set_attribute (alternate => $type->{preferred} ? 'no'
262 : 'yes')
263 unless $type->{persistent};
264 $link->set_attribute (title => $title) unless $type->{persistent};
265 my $media_type = $sheet->get_attribute_value
266 ('Type', default => 'text/css');
267 ## TODO: parameter
268 $link->set_attribute (type => $media_type);
269 unless ($o->{wiki}->{var}->{client}->{downgrade}
270 ->{html_link_no_media}) {
271 my $media_descriptor = $sheet->get_attribute_value ('Media');
272 $link->set_attribute (media => $media_descriptor || 'all');
273 }
274 my $uri = $mkuri->(undef, o => $o, wiki => $o->{wiki},
275 wikiname => $o->{wiki}->name
276 ($sheet->get_attribute_value
277 ('WikiPage', default => '')),
278 lm => time, ## TODO: Should be last-modified
279 mode => 'css'); ## ISSUE: Make this media-type independent!
280 $link->set_attribute (href => $uri);
281 $parent->append_text ("\n");
282 }
283 }
284 }
285 }
286
287 Function:
288 @Name: generate_uri
289 @Description:
290 @@@: Default generator for stylesheet URI
291 @@lang: en
292 @Main:
293 my (undef, %opt) = @_;
294 return $opt{wiki}->uri_reference
295 (page => $opt{wikiname},
296 mode => $opt{mode},
297 with_lm => 1, base => 1);
298
299 ViewDefinition:
300 @Mode: ss--no-static
301 @Condition:
302 @@http-method[list]:
303 GET
304 HEAD
305 POST
306 @Description:
307 @@@: Generate static version
308 @@lang: en
309 @method:
310 @@Name: main
311 @@@:
312 require SuikaWiki::Output::HTTP;
313 my $wiki = $self->{view}->{wiki};
314 $wiki->init_db;
315
316 GENSTATIC: {
317 last GENSTATIC unless ref $wiki->{config}->{<Q:ss:uri-to-wikiname>} and
318 $wiki->{config}->{<Q:ss:use-static>} and
319 $wiki->{db} and $wiki->{input};
320 my $uri = $wiki->{input}->meta_variable ('REDIRECT_URL');
321 last GENSTATIC unless $uri;
322 my $wn = $wiki->{config}->{<Q:ss:uri-to-wikiname>}
323 ->(undef, wiki => $wiki,
324 uri => URI->new ($uri));
325
326 my $prop = $wiki->{db}->get (content_prop => $wn);
327 my $mt = $prop->get_attribute_value (<Q:media-type:media-type>,
328 default => '--');
329 last GENSTATIC unless $mt eq 'IMT:text/css##';
330
331 $wiki->{db}->set (static__css => $wn =>
332 $wiki->{db}->get (content => $wn));
333
334 $uri = $wiki->{config}->{<Q:ss:wikiname-to-uri>}
335 ->(undef, wiki => $wiki,
336 wikiname => $wn);
337 $uri = $uri->abs ($wiki->uri_reference);
338 $uri->query (time);
339
340 my $output = new SuikaWiki::Output::HTTP (wiki => $wiki);
341 $output->set_redirect (uri => $uri, status_code => 303,
342 status_phrase => 'Created');
343 $output->output (output => 'http-cgi');
344
345 return;
346 }
347 my $output = new SuikaWiki::Output::HTTP (wiki => $wiki);
348 $output->{status_code} = 404;
349 $output->{entity}->{media_type} = 'text/plain';
350 $output->{entity}->{body} = '404';
351 $output->output (output => 'http-cgi');
352
353 FormattingRule:
354 @Category[list]:
355 view
356 view-resource
357 form-input
358 @Name: select-user-preferred-style
359 @Description:
360 @@@:
361 Select user preferred style
362 @@lang: en
363 @Paramater:
364 @@Name: page
365 @@Type: WikiName
366 @@Default: (auto)
367 @@Description:
368 @@@@: WikiPage in which stylesheet list is defined
369 @@@lang: en
370 @Formatting:
371 __ATTRTEXT:%page__;
372 my $list = __FUNCPACK__->_get_stylelist_definition_page
373 (page => $o->{wiki}->name
374 ($p->{page} ||
375 $o->{wiki}->{config}->{page}
376 ->{'StyleSheetList(text/html)'} ||
377 [qw!Wiki Style List text/html!]),
378 o => $o, wiki => $o->{wiki});
379 return unless $list;
380 my $form = $p->{-parent}->append_new_node
381 (type => '#element',
382 namespace_uri => $NS_XHTML1,
383 local_name => 'form');
384 my $id = SuikaWiki::Plugin->module_package ('WikiFormCore')
385 ->control_id ($o,
386 local_id => 'style-selector',
387 require_local_id => 1);
388 $form->set_attribute (id => $id->{global_id});
389 my $div = $form->append_new_node
390 (type => '#element',
391 namespace_uri => $NS_XHTML1,
392 local_name => 'div');
393 my $parent = $div->append_new_node
394 (type => '#element',
395 namespace_uri => $NS_XHTML1,
396 local_name => 'select');
397 $parent->set_attribute (id => $id->{global_id}.'-list');
398
399 my $default = $parent->append_new_node
400 (type => '#element',
401 namespace_uri => $NS_XHTML1,
402 local_name => 'option');
403 $default->set_attribute (value => 'no-style');
404 $default->append_text ($WIKIRESOURCE->get (name => 'Style:Default',
405 o => $o, wiki => $o->{wiki}));
406 my $selected = 0;
407
408 for my $set (@{$list->child_nodes}) {
409 if ($set->local_name eq 'StyleSet') {
410 my $type = {map {$_ => 1}
411 @{
412 $set->get_attribute_value ('Apply', default => ['alternate'])
413 }};
414 next unless $type->{preferred} or $type->{alternate};
415 my $title = __FUNCPACK__->_get_styleset_title
416 (StyleSet => $set, o => $o,
417 type => $type);
418 my $link = $parent->append_new_node
419 (type => '#element',
420 namespace_uri => $NS_XHTML1,
421 local_name => 'option');
422 $link->set_attribute (selected => 'selected'), $selected = 1
423 if $type->{preferred};
424 $link->set_attribute (value => $title);
425 $link->append_text ($title);
426 $parent->append_text ("\n");
427 }
428 }
429
430 $default->set_attribute (selected => 'selected') unless $selected;
431
432 for ($div->append_new_node (type => '#element',
433 namespace_uri => $NS_XHTML1,
434 local_name => 'input')) {
435 $_->set_attribute (type => 'button');
436 $_->set_attribute (id => $id->{global_id}.'-save');
437 $_->set_attribute (value => $WIKIRESOURCE->get
438 (name => 'Style:Save',
439 o => $o, wiki => $o->{wiki}));
440 $_->set_attribute (class => 'save');
441 $_->option (use_EmptyElemTag => 1);
442 }
443 for ($div->append_new_node (type => '#element',
444 namespace_uri => $NS_XHTML1,
445 local_name => 'input')) {
446 $_->set_attribute (type => 'reset');
447 $_->set_attribute (id => $id->{global_id}.'-reset');
448 $_->set_attribute (value => $WIKIRESOURCE->get
449 (name => 'Style:Reset',
450 o => $o, wiki => $o->{wiki}));
451 $_->set_attribute (class => 'reset');
452 $_->option (use_EmptyElemTag => 1);
453 }
454
455 __ATTRTEXT:%expires__;
456 my $cookie_path = $o->{wiki}->uri_reference->path;
457 for ($div->append_new_node (type => '#element',
458 namespace_uri => $NS_XHTML1,
459 local_name => 'script')) {
460 $_->set_attribute (type => $o->{wiki}->{var}->{client}->{downgrade}
461 ->{media_type_no_app_js}
462 ? 'text/javascript'
463 : 'application/x-javascript');
464 $_->set_attribute (defer => 'defer');
465 ## Gecko assumes <script> content as CDATA even if it is XHTML,
466 ## when it is labeled as text/html. (Pseudo) comment declaration
467 ## nor CDATA marked section can be used to keep compatibility and
468 ## well-formedness. Use #xml type, instead of #text, not to escape
469 ## GREATER-THAN SIGN.
470 $_->append_new_node (type => '#xml', value => <<EOH);
471
472 function getCookieValue (name) {
473 var c = document.cookie.split(';');
474 for (var i = 0; c.length > i; i++) {
475 var v = c[i].split('=');
476 if (v[0].replace(/^\\s+/,'').replace(/\\s+\$/,'') == name) {
477 return decodeURIComponent (v[1].replace(/^\\s+/,'')
478 .replace(/\\s+\$/,''));
479 }
480 }
481 return '';
482 }
483 var selectList = document.getElementById('$id->{global_id}-list');
484 selectList.value = getCookieValue('Selected');
485 selectList.onchange = function () {
486 var selectList = document.getElementById('$id->{global_id}-list');
487 for (var i = 0; document.styleSheets.length > i; i++) {
488 var s = document.styleSheets.item(i);
489 if (s.href != document.URL) {
490 if (s.title)
491 s.disabled = (s.title != selectList.value);
492 }
493 }
494 }
495 document.getElementById('$id->{global_id}-save').onclick = function () {
496 var selectList = document.getElementById('$id->{global_id}-list');
497 var expires = new Date();
498 expires.setTime (expires.getTime()
499 + 1000*3600*24*@{[$p->{expires}||365]});
500 document.cookie = 'Selected=' + encodeURIComponent(selectList.value)
501 + ';path=$cookie_path;expires='+expires.toGMTString();
502 }
503 document.getElementById('$id->{global_id}-reset').onclick = function () {
504 var expires = new Date();
505 expires.setTime (expires.getTime() - 3600);
506 document.cookie = 'Selected=;path=$cookie_path;expires='
507 + expires.toGMTString();
508 }
509
510 EOH
511 }
512
513 FormattingRule:
514 @Category[list]:
515 view
516 view-resource
517 form-input
518 @Name: apply-user-preferred-style
519 @Description:
520 @@@:
521 Applying user preferred style
522 @@lang: en
523 @Formatting:
524 for ($p->{-parent}->append_new_node
525 (type => '#element',
526 namespace_uri => $NS_XHTML1,
527 local_name => 'script')) {
528 $_->set_attribute (type => $o->{wiki}->{var}->{client}->{downgrade}
529 ->{media_type_no_app_js}
530 ? 'text/javascript'
531 : 'application/x-javascript');
532 $_->set_attribute (defer => 'defer');
533 ## TODO: Some mechanism to prevent multiple outputing of same functions
534 ## required.
535 $_->append_new_node (type => '#xml', value => <<EOH);
536
537 function getCookieValue (name) {
538 var c = document.cookie.split(';');
539 for (var i = 0; c.length > i; i++) {
540 var v = c[i].split('=');
541 if (v[0].replace(/^\\s+/,'').replace(/\\s+\$/,'') == name) {
542 return decodeURIComponent (v[1].replace(/^\\s+/,'')
543 .replace(/\\s+\$/,''));
544 }
545 }
546 return '';
547 }
548
549 var styleName = getCookieValue('Selected');
550 if (styleName) {
551 for (var i = 0; document.styleSheets.length > i; i++) {
552 var s = document.styleSheets.item(i);
553 if (s.href != document.URL) {
554 if (s.title)
555 s.disabled = (s.title != styleName) ? true : false;
556 }
557 }
558 }
559
560 EOH
561 }
562
563 Function:
564 @Name: _get_stylelist_definition_page
565 @Main:
566 my (undef, %opt) = @_;
567 my $content;
568 my $content_prop;
569 if ($opt{wiki}->{db}) {
570 try {
571 $content = $opt{wiki}->{db}->get (content => $opt{page});
572 $content_prop = $opt{wiki}->{db}->get (content_prop => $opt{page});
573 } catch SuikaWiki::DB::Util::Error with {
574 my $err = shift;
575 $err->throw if $err->{-type} eq 'ERROR_REPORTED';
576 $content = undef;
577 };
578 }
579 my $format = SuikaWiki::Plugin->module_package ('WikiFormat')
580 ->handler (\$content,
581 content_prop => $content_prop,
582 o => $opt{o},
583 wiki => $opt{o}->{wiki});
584 my $cfg;
585 try {
586 $cfg = $format->convert (\$content,
587 Type => 'application/x.suikawiki.config',
588 Type_param => {version => '2.0'},
589 o => $opt{o}, page => $opt{page});
590 } catch SuikaWiki::Format::Definition::error with {
591 my $err = shift;
592 if ($err->{-type} eq 'CONVERTER_NOT_FOUND') {
593 SuikaWiki::Plugin->module_package ('Error')
594 ->report_error_simple
595 ($opt{o}->{wiki},
596 'Condition' => $err->stringify);
597 } else {
598 $err->throw;
599 }
600 };
601 $cfg;
602
603 Function:
604 @Name: _get_styleset_title
605 @Description:
606 @@@: Get "title" of the styleset
607 @@lang: en
608 @Main:
609 my (undef, %opt) = @_;
610 my $title;
611 if (not $opt{type}->{persistent}) {
612 $title = $opt{StyleSet}->get_attribute_value
613 ('DisplayName', default => '');
614 if (length $title) {
615 try {
616 $title = SuikaWiki::Plugin->formatter ('view_resource')
617 ->replace ($title,
618 param => $opt{o})
619 ->inner_text;
620 } catch Message::Util::Formatter::error with {
621 my $err = shift;
622 if ($err->{-object}->{-category_name} eq 'view_resource') {
623 my $wiki = $err->{option}->{param}->{wiki};
624 SuikaWiki::Plugin->module_package ('Error')
625 ->reporting_formatting_template_error
626 ($err, $wiki,
627 template => $title);
628 } else {
629 $err->throw;
630 }
631 $title ||= $opt{StyleSet}->get_attribute_value
632 ('Name', default => '');
633 };
634 } else {
635 $title = $opt{StyleSet}->get_attribute_value ('Name', default => '');
636 }
637 }
638 return $title;
639
640 FormattingRule:
641 @Category[list]:
642 view
643 view-resource
644 form-input
645 @Name: select-user-preferred-mode
646 @Description:
647 @@@:
648 Select user preferred mode
649 @@lang: en
650 @Formatting:
651 my $list = [grep /^[0-9A-Za-z_]/, keys %{$o->{wiki}->{view}->{definition}}];
652 my $form = $p->{-parent}->append_new_node
653 (type => '#element',
654 namespace_uri => $NS_XHTML1,
655 local_name => 'form');
656 my $id = SuikaWiki::Plugin->module_package ('WikiFormCore')
657 ->control_id ($o,
658 local_id => 'spss--mode-selector',
659 require_local_id => 1);
660 $form->set_attribute (id => $id->{global_id});
661 my $div = $form->append_new_node
662 (type => '#element',
663 namespace_uri => $NS_XHTML1,
664 local_name => 'div');
665 my $parent = $div->append_new_node
666 (type => '#element',
667 namespace_uri => $NS_XHTML1,
668 local_name => 'select');
669 $parent->set_attribute (id => $id->{global_id}.'-list');
670
671 my $default = $parent->append_new_node
672 (type => '#element',
673 namespace_uri => $NS_XHTML1,
674 local_name => 'option');
675 $default->set_attribute (value => 'default');
676 $default->append_text ($WIKIRESOURCE->get (name => 'Mode:Default',
677 o => $o, wiki => $o->{wiki}));
678 $default->set_attribute (selected => 'selected');
679
680 for my $set (@$list) {
681 my $title = $WIKIRESOURCE->get (name => 'Mode:'.$set,
682 o => $o, wiki => $o->{wiki});
683 my $link = $parent->append_new_node
684 (type => '#element',
685 namespace_uri => $NS_XHTML1,
686 local_name => 'option');
687 $link->set_attribute (value => $set);
688 $link->append_text ($title);
689 $parent->append_text ("\n");
690 }
691
692 for ($div->append_new_node (type => '#element',
693 namespace_uri => $NS_XHTML1,
694 local_name => 'input')) {
695 $_->set_attribute (type => 'button');
696 $_->set_attribute (id => $id->{global_id}.'-save');
697 $_->set_attribute (value => $WIKIRESOURCE->get
698 (name => 'Mode:Save',
699 o => $o, wiki => $o->{wiki}));
700 $_->set_attribute (class => 'save');
701 $_->option (use_EmptyElemTag => 1);
702 }
703 for ($div->append_new_node (type => '#element',
704 namespace_uri => $NS_XHTML1,
705 local_name => 'input')) {
706 $_->set_attribute (type => 'reset');
707 $_->set_attribute (id => $id->{global_id}.'-reset');
708 $_->set_attribute (value => $WIKIRESOURCE->get
709 (name => 'Mode:Reset',
710 o => $o, wiki => $o->{wiki}));
711 $_->set_attribute (class => 'reset');
712 $_->option (use_EmptyElemTag => 1);
713 }
714
715 __ATTRTEXT:%expires__;
716 my $cookie_path = $o->{wiki}->uri_reference->path;
717 for ($div->append_new_node (type => '#element',
718 namespace_uri => $NS_XHTML1,
719 local_name => 'script')) {
720 $_->set_attribute (type => $o->{wiki}->{var}->{client}->{downgrade}
721 ->{media_type_no_app_js}
722 ? 'text/javascript'
723 : 'application/x-javascript');
724 $_->set_attribute (defer => 'defer');
725 $_->append_new_node (type => '#xml', value => <<EOH);
726
727 function getCookieValue (name) {
728 var c = document.cookie.split(';');
729 for (var i = 0; c.length > i; i++) {
730 var v = c[i].split('=');
731 if (v[0].replace(/^\\s+/,'').replace(/\\s+\$/,'') == name) {
732 return decodeURIComponent (v[1].replace(/^\\s+/,'')
733 .replace(/\\s+\$/,''));
734 }
735 }
736 return '';
737 }
738
739 document.getElementById ('$id->{global_id}-list').value
740 = getCookieValue('SelectedMode');
741 document.getElementById ('$id->{global_id}-save').onclick = function () {
742 var expires = new Date ();
743 expires.setTime (expires.getTime ()
744 + 1000*3600*24*@{[$p->{expires}||365]});
745 document.cookie = 'SelectedMode='
746 + encodeURIComponent
747 (document.getElementById('$id->{global_id}-list')
748 .value)
749 + ';path=$cookie_path;expires='
750 + expires.toGMTString ();
751 }
752 document.getElementById('$id->{global_id}-reset').onclick = function () {
753 var expires = new Date();
754 expires.setTime (expires.getTime() - 3600);
755 document.cookie = 'SelectedMode=;path=$cookie_path;expires='
756 + expires.toGMTString();
757 }
758
759 EOH
760 }
761
762 ViewFragment:
763 @Name: ht--stylesheets-html
764 @Order: 0
765 @Description:
766 @@@: Default stylesheets links
767 @@lang: en
768 @Formatting:
769 %styles-wiki-html;
770
771 ViewFragment:
772 @Name: ht--pre-element-content
773 @Order: 0
774 @Description:
775 @@@: Default stylesheets links (as xml-stylesheet PIs)
776 @@lang: en
777 @Formatting:
778 %styles-wiki-xml (downgrade-html);
779
780 ViewFragment:
781 @Name: ws--footer
782 @Order: 100000
783 @Description:
784 @@@: Apply user selected stylesheets
785 @@lang: en
786 @Formatting:
787 %apply-user-preferred-style;
788
789 Resource:
790 @Mode:css:
791 @@@: Cascading Style Sheet output
792 @@lang: en
793 @Mode:Default:
794 @@@:
795 Default
796 @@lang: en
797 @Mode:Reset:
798 @@@: Reset default mode selection
799 @@lang: en
800 @Mode:Save:
801 @@@: Save default mode selection
802 @@lang: en
803 @Style:Default:
804 @@@:
805 Basic Page Style
806 @@: lang: en
807 @Style:Reset:
808 @@@:
809 Reset style selection
810 @@lang: en
811 @Style:Save:
812 @@@:
813 Save style selection
814 @@lang: en
815 @WikiFormat:MediaType:Description:IMT:text/css##:
816 @@@: CSS (Cascading Style Sheets)
817 @@lang: en
818 @WikiFormat:MediaType:Label:IMT:text/css##:
819 @@@: CSS
820 @@lang: en
821
822

admin@suikawiki.org
ViewVC Help
Powered by ViewVC 1.1.24