source: other-projects/meddle/trunk/meddle-fixup.js@ 31607

Last change on this file since 31607 was 31607, checked in by davidb, 7 years ago

Support JS file for nph-proxy-meddle.cgi

File size: 4.9 KB
Line 
1// https://en.wikipedia.org/wiki/List_of_precomposed_Latin_characters_in_Unicode
2// https://en.wikipedia.org/wiki/Typographic_ligature#Ligatures_in_Unicode_.28Latin_alphabets.29
3
4var ligature_map = {
5
6 "\uA732": "AA" ,
7 "\uA733": "aa" ,
8 "\u00C6": "AE" ,
9 "\u00E6": "ae" ,
10 "\uA734": "AO" ,
11 "\uA735": "ao" ,
12 "\uA736": "AU" ,
13 "\uA737": "au" ,
14 "\uA738": "AV" ,
15 "\uA739": "av" ,
16 // as above but with bar
17 "\uA73A": "AV" ,
18 "\uA73B": "av" ,
19 "\uA73C": "AY" ,
20 "\uA73D": "ay" ,
21 "\u1F670": "et" ,
22 "\uFB00": "ff" ,
23 "\uFB03": "ffi" ,
24 "\uFB04": "ffl" ,
25 "\uFB01": "fi" ,
26 "\uFB02": "fl" ,
27 "\u0152": "OE" ,
28 "\u0153": "oe" ,
29 "\uA74E": "OO" ,
30 "\uA74F": "oo" ,
31 "\u00DF": "Å¿s" ,
32 "\u00DF": "Å¿z" ,
33 "\uFB06": "st" ,
34 "\uFB05": "Å¿t" ,
35 "\uA728": "TZ" ,
36 "\uA729": "tz" ,
37 "\u1D6B": "ue" ,
38 "\uAB50": "ui" ,
39 "\uA760": "VY" ,
40 "\uA761": "vy"
41};
42
43var ligature_re = null;
44
45function fixupEncodeInput(form) {
46 console.log( "amcm-dl-fixup fixupEncodeInput(form) called" );
47
48 if (ligature_re === null) {
49 var ligature_str = Object.keys(ligature_map).join("|");
50 ligature_re = new RegExp(ligature_str);
51 }
52
53 //console.log("*** ligature_str = " + ligature_str);
54
55 var query_box_val = form.elements['query'].value;
56
57 var detected_ligatures = ligature_re.test(query_box_val);
58 if (detected_ligatures) {
59 var do_replacement = confirm("Detected ligatures in query. Replace with individual characters?");
60 if (do_replacement) {
61 var query_chars = query_box_val.split("");
62 var query_chars_fixed = [];
63
64 for (var i=0; i<query_chars.length; i++) {
65 var c = query_chars[i];
66 if (ligature_map[c]) {
67 c = ligature_map[c];
68 }
69 query_chars_fixed.push(c);
70 }
71 query_box_val = query_chars_fixed.join("");
72 }
73 }
74
75 // e.g., content.ftsec:(+capisco)
76
77 var query_box_val = query_box_val.replace(/^\s+/,"");
78 var query_box_words = query_box_val.split(/\s+/);
79
80 var query_box_val_plus = "";
81 var query_box_val_double = "";
82
83 for (var i=0; i<query_box_words.length; i++) {
84 if (i>0) {
85 query_box_val_plus += " ";
86 }
87 query_box_val_plus += "+" + query_box_words[i];
88
89 if (i>0) {
90 query_box_val_double += " " + query_box_words[i-1]+query_box_words[i];
91 }
92 }
93
94
95 form.elements['query'].value = "content.ftsec:(" + query_box_val_plus + query_box_val_double + ")";
96
97 return encodeInput(form);
98}
99
100function fixupSubmitIt() {
101 var search_where = $("#fld0 option:selected").text();
102 console.log("**** search_where = " + search_where);
103 var x = 0;
104 var search_select = $("#fld"+x+" option:selected");
105 var search_where = search_select.text();
106
107 while (search_where) {
108 if (search_where == "Any field") {
109 //var sel_val = document.getElementById("fld" + x).selectedIndex].value;
110
111 //var thisField = document.getElementById("fld" + x).options[document.getElementById("fld" + x).selectedIndex].value;
112
113 $("#fld"+x).val('content.ftsec:');
114 //$("#fld0 option[value='content.ftsec:']").prop('selected', true);
115 //alert("changed menu");
116 }
117 x = x + 1;
118 search_select = $("#fld"+x+" option:selected");
119 search_where = search_select.text();
120 //console.log("*** search select = " + search_select.text());
121 //alert("ddd");
122 }
123 buildQuery();
124
125 return submitIt();
126}
127
128//var acmdl_fixup_div = document.getElementById("acmdl-fixup");
129
130
131//window.onload = function(e) {
132
133function acmdlFixupInit() {
134
135 console.log("amc-dl-fixup initiated");
136
137 var query_form = document.getElementsByName("qiksearch")[0];
138 if (query_form) {
139 query_form.setAttribute("onsubmit", "fixupEncodeInput(this) ; _proxy_jslib_flush_write_buffers();");
140 }
141
142 //query_form.setAttribute("onsubmit", "encodeInput(this) ; _proxy_jslib_flush_write_buffers();");
143
144/*
145 var query_box_val = query_form.elements['query'].value;
146
147 //var ft_regex = /content.ftsec:\(\+(.*?)\)/g;
148 //var match = ft_regex.exec(query_box_val);
149
150 query_form.value = query_box_val.replace(/content.ftsec:\(\+(.*)\)/g,"$1");
151
152 //var query_box = document.getElementsByName("query")[0];
153 //var query_box_val = query_box.getAttribute("value");
154 //query_box.setAttribute("value", "Foo");
155*/
156 var adv_query_form = document.getElementById("theform");
157 if (adv_query_form) {
158 // javascript:submitIt();
159 // javascript:; _proxy_jslib_proxify_html(submitIt())[0]
160
161 adv_query_form.setAttribute("action","javascript:fixupSubmitIt();");
162 }
163
164 var query_box = document.getElementsByName("query")[0];
165 if (query_box) {
166 var query_box_val = query_box.getAttribute("value");
167 query_box.setAttribute("value", query_box_val.replace(/content\.ftsec:\(\+(.*)\)/g,"$1"));
168 }
169
170 console.log("acm-dl-fixup DOM tweaks done");
171}
172
173
174$(document).ready(function() {
175 console.log( "jquery DOM ready" );
176 acmdlFixupInit()
177});
178
Note: See TracBrowser for help on using the repository browser.