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