/[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.5 - (hide annotations) (download)
Thu Jun 3 06:38:49 2004 UTC (20 years, 5 months ago) by wakaba
Branch: MAIN
CVS Tags: release-3-0-0
Changes since 1.4: +109 -15 lines
Static output of stylesheet implemented; Use of simple HTML serializer (new to manakai) if text/html output

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

admin@suikawiki.org
ViewVC Help
Powered by ViewVC 1.1.24