forked from WPPlugins/wp-chinese-conversion
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsearch-variant.js
executable file
·23 lines (18 loc) · 1.01 KB
/
search-variant.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
/*
Powered by WP Chinese Conversion Plugin ( https://oogami.name/project/wpcc/ )
Search Variant JS
This JS try to get your blog's search form element , and append a '<input type="hidden" name="variant" value="VALUE" />' child to this element . So If you run a search , browser will submit the "variant" var to server , the "variant" 's value is set by your current Chinese Language ( 'zh-hans' for Chinese Simplfied or 'zh-hant' for Chinese Traditional etc...)
If you are in a page with no chinese conversion, this file will not be loaded .
*/
window.addEventListener('load', function() {
if(typeof wpcc_target_lang == 'undefined') return;
var theTextNode = document.querySelector('input[name="s"]');
if (theTextNode) {
var wpcc_input_variant = document.createElement("input");
wpcc_input_variant.id = 'wpcc_input_variant';
wpcc_input_variant.type = 'hidden';
wpcc_input_variant.name = 'variant';
wpcc_input_variant.value = wpcc_target_lang;
theTextNode.parentNode.appendChild(wpcc_input_variant);
}
});