リビジョン | 81f97796e37ccac655be04bfed1faa11647b0556 (tree) |
---|---|
日時 | 2017-09-27 04:53:51 |
作者 | umorigu <umorigu@gmai...> |
コミッター | umorigu |
Improve encode_hint handling
@@ -206,7 +206,7 @@ function get_html_scripting_data() | ||
206 | 206 | if (!isset($ticket_link_sites) || !is_array($ticket_link_sites)) { |
207 | 207 | return ''; |
208 | 208 | } |
209 | - $is_utf8 = SOURCE_ENCODING === 'UTF-8'; | |
209 | + $is_utf8 = (bool)defined('PKWK_UTF8_ENABLE'); | |
210 | 210 | // Require: PHP 5.4+ |
211 | 211 | $json_enabled = defined('JSON_UNESCAPED_UNICODE'); |
212 | 212 | if (!$json_enabled) { |
@@ -218,7 +218,7 @@ EOD; | ||
218 | 218 | <noscript> |
219 | 219 | <p>$_msg_unsupported_webbrowser $alt_msg</p> |
220 | 220 | </noscript> |
221 | -<p class="_plugin_search2_nosupport_message" style="display:block;"> | |
221 | +<p class="_plugin_search2_nosupport_message" style="display:none;"> | |
222 | 222 | $_msg_unsupported_webbrowser $alt_msg |
223 | 223 | </p> |
224 | 224 | <form action="$script" method="GET" class="_plugin_search2_form"> |
@@ -304,7 +304,7 @@ window.addEventListener && window.addEventListener('DOMContentLoaded', function( | ||
304 | 304 | // Remove this line from search target |
305 | 305 | continue; |
306 | 306 | } else if (line.match(/^#freeze(\W|$)/)) { |
307 | - // Stil in header | |
307 | + // Still in header | |
308 | 308 | } else { |
309 | 309 | // Already in body |
310 | 310 | isInAuthorHeader = false; |
@@ -343,7 +343,6 @@ window.addEventListener && window.addEventListener('DOMContentLoaded', function( | ||
343 | 343 | } |
344 | 344 | } |
345 | 345 | return blocks; |
346 | - //return foundLines.join('\n'); | |
347 | 346 | } |
348 | 347 | function getSummary(bodyText, searchRegex) { |
349 | 348 | return getTargetLines(bodyText, searchRegex); |
@@ -392,10 +391,17 @@ window.addEventListener && window.addEventListener('DOMContentLoaded', function( | ||
392 | 391 | return summary.join(' ').substring(0, 150); |
393 | 392 | } |
394 | 393 | function removeEncodeHint() { |
395 | - var form = document.querySelector('form'); | |
396 | - if (form && form.encode_hint && (typeof form.encode_hint.removeAttribute === 'function')) { | |
397 | - form.encode_hint.removeAttribute('name'); | |
398 | - } | |
394 | + // Remove 'encode_hint' if site charset is UTF-8 | |
395 | + var props = getSiteProps(); | |
396 | + if (!props.is_utf8) return; | |
397 | + var forms = document.querySelectorAll('form'); | |
398 | + forEach(forms, function(form){ | |
399 | + if (form.cmd && form.cmd.value === 'search2') { | |
400 | + if (form.encode_hint && (typeof form.encode_hint.removeAttribute === 'function')) { | |
401 | + form.encode_hint.removeAttribute('name'); | |
402 | + } | |
403 | + } | |
404 | + }); | |
399 | 405 | } |
400 | 406 | function kickFirstSearch() { |
401 | 407 | var form = document.querySelector('._plugin_search2_form'); |
@@ -436,12 +442,18 @@ window.addEventListener && window.addEventListener('DOMContentLoaded', function( | ||
436 | 442 | forEach(f.querySelectorAll('input[name="base"]'), function(radio){ |
437 | 443 | if (radio.checked) base = radio.value; |
438 | 444 | }); |
445 | + var props = getSiteProps(); | |
439 | 446 | var loc = document.location; |
440 | - var url = loc.protocol + '//' + loc.host + loc.pathname + | |
441 | - '?cmd=search2' + | |
447 | + var baseUri = loc.protocol + '//' + loc.host + loc.pathname; | |
448 | + if (props.base_uri_pathname) { | |
449 | + baseUri = props.base_uri_pathname; | |
450 | + } | |
451 | + var url = baseUri + '?' + | |
452 | + (props.is_utf8 ? '' : 'encode_hint=\u3077' + '&') + | |
453 | + 'cmd=search2' + | |
442 | 454 | '&q=' + encodeSearchText(q) + |
443 | 455 | (base ? '&base=' + encodeURIComponent(base) : ''); |
444 | - e.preventDefault(); | |
456 | + e.preventDefault(); | |
445 | 457 | setTimeout(function() { |
446 | 458 | location.href = url; |
447 | 459 | }, 1); |
@@ -567,13 +579,18 @@ window.addEventListener && window.addEventListener('DOMContentLoaded', function( | ||
567 | 579 | return false; |
568 | 580 | } |
569 | 581 | function isEnableServerFunctions() { |
582 | + var props = getSiteProps(); | |
583 | + if (props.json_enabled) return true; | |
584 | + return false; | |
585 | + } | |
586 | + function getSiteProps() { | |
587 | + var empty = {}; | |
570 | 588 | var propsDiv = document.getElementById('pukiwiki-site-properties'); |
571 | - if (!propsDiv) return false; | |
589 | + if (!propsDiv) return empty; | |
572 | 590 | var jsonE = propsDiv.querySelector('div[data-key="site-props"]'); |
573 | - if (!jsonE) return false; | |
591 | + if (!jsonE) return emptry; | |
574 | 592 | var props = JSON.parse(jsonE.getAttribute('data-value')); |
575 | - if (props.json_enabled) return true; | |
576 | - return false; | |
593 | + return props || empty; | |
577 | 594 | } |
578 | 595 | colorSearchTextInBody(); |
579 | 596 | if (! isEnabledFetchFunctions()) { |