Index: other-projects/meddle/trunk/meddle-fixup.js
===================================================================
--- other-projects/meddle/trunk/meddle-fixup.js	(revision 31683)
+++ other-projects/meddle/trunk/meddle-fixup.js	(revision 31684)
@@ -1,3 +1,24 @@
-// MEDDLE version 0.9
+/**
+ *    MEDDLE version 0.9
+ *    Copyright (C) 2017 New Zealand Digital Library, http://www.nzdl.org
+ *
+ *    This program is free software: you can redistribute it and/or modify
+ *    it under the terms of the GNU General Public License as published by
+ *    the Free Software Foundation, either version 3 of the License, or
+ *    (at your option) any later version.
+ *
+ *    This program is distributed in the hope that it will be useful,
+ *    but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *    GNU General Public License for more details.
+ *
+ *    You should have received a copy of the GNU General Public License
+ *    along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+function trim(str)
+{
+    return str.replace(/^\s\s*/, '').replace(/\s\s*$/, '');
+}
 
 
@@ -6,8 +27,4 @@
 //   https://en.wikipedia.org/wiki/Typographic_ligature#Ligatures_in_Unicode_.28Latin_alphabets.29
 
-function trim(str)
-{
-    return str.replace(/^\s\s*/, '').replace(/\s\s*$/, '');
-}
 
 var ligature_map = {
@@ -122,6 +139,4 @@
     }
 
-    //console.log("*** ligature_str = " + ligature_str);
-
     var detected_ligatures = ligature_re.test(query_box_val);
     var do_replacement = $('#meddle-lig').is(":checked");
@@ -167,35 +182,170 @@
     console.log( "amcm-dl-fixup fixupEncodeInput(form) called" );
 
-    //if (ligature_re === null) {
-     //   var ligature_str = Object.keys(ligature_map).join("|");
-      //  ligature_re = new RegExp(ligature_str);
-    //}
-
-    //console.log("*** ligature_str = " + ligature_str);
-
     var query_box_val = form.elements['query'].value;
     query_box_val = opt_ligature_replacement(query_box_val);
 
-/*
-    var detected_ligatures = ligature_re.test(query_box_val);
-    if (detected_ligatures) {
-	//var do_replacement = confirm("Detected ligatures in query. Replace with individual characters?");
-	var do_replacement = $('#meddle-lig').is(":checked");
-
-	if (do_replacement) {
-            var query_chars = query_box_val.split("");
-            var query_chars_fixed = [];
+
+    query_box_val = opt_accent_fold(query_box_val);
+
+    // e.g., content.ftsec:(+capisco) 
+
+    var query_box_val = query_box_val.replace(/^\s+/,"");
+    var query_box_words = query_box_val.split(/\s+/);
+    
+    var query_box_val_plus = "";
+    var query_box_val_double = "";
+    
+    for (var i=0; i<query_box_words.length; i++) {
+	if (i>0) {
+	    query_box_val_plus += " ";
+	}
+	query_box_val_plus += "+" + query_box_words[i];
+	
+	if (i>0) {
+	    query_box_val_double += " " + query_box_words[i-1]+query_box_words[i];
+	}
+    }
+
+
+    form.elements['query'].value = "content.ftsec:(" + query_box_val_plus + query_box_val_double + ")";
+
+
+    return encodeInput(form);
+}
+
+function fixupSubmitIt() {
+    var search_where = $("#fld0 option:selected").text();
+    var x = 0;
+    var search_select = $("#fld"+x+" option:selected");
+    var search_where = search_select.text();    
+
+    while (search_where) {
+	if (search_where == "Any field") {
 	    
-            for (var i=0; i<query_chars.length; i++) {
-		var c = query_chars[i];
-		if (ligature_map[c]) {
-		    c = ligature_map[c];
-		}
-		query_chars_fixed.push(c);
-            }
-            query_box_val = query_chars_fixed.join("");
-	}
-    }
-*/
+	    $("#fld"+x).val('content.ftsec:');
+	}
+	x = x + 1;
+	search_select = $("#fld"+x+" option:selected");    
+	search_where = search_select.text();
+    }
+    buildQuery();
+
+    return submitIt();
+}
+
+function meddleInfoBox() {
+
+    // Icon image
+    // By VistaICO.com (VistaICO Toolbar Icons) [CC BY 3.0 ]
+
+
+    var dlcontextoptions = '<input id="meddle-lig" name="meddle-lig" type="checkbox"><label for="meddle-lig" style="display: inline">&nbsp;Ligature&nbsp;expansion</label>&nbsp;&nbsp;<input id="meddle-acc" name="meddle-acc" type="checkbox"><label for="meddle-acc" style="display: inline">&nbsp;Accent&nbsp;folding</label>';
+
+
+   //console.log("*** location = " + window.location.pathname);
+    var detected_dl = "";
+
+    var domain_match = window.location.pathname.match(/nph-proxy-meddle.cgi\/.*?https?\/(.*)$/);
+
+    if (domain_match.length>1) {
+	var real_domain = domain_match[1];
+
+	if (real_domain.match(/^dl\.acm\.org\//)) {
+	    detected_dl = "ACM DL (Meddled with to provide: full-text quicksearch, word-wrap protection)";
+	}
+	else if (real_domain.match(/^scholar\.google\.[a-z]+/)) {
+	    detected_dl = "Google Scholar";
+	}
+	else if (real_domain.match(/^www.springer\.com/)) {
+	    detected_dl = "Springer";
+	}
+	else if (real_domain.match(/^ieeexplore\.ieee\.org\//)) {
+	    detected_dl = "IEEE Xplore";
+	}
+    }
+
+    if (detected_dl !== "") {
+	$('#dlcontext').html("<i>Detected:" + detected_dl + "</i>");
+    }
+
+    $('#dlcontextoptions').html('<font size="-1">'+dlcontextoptions+'</font>');
+
+    return detected_dl;
+}
+
+
+function acmdlFixupInit() {
+
+    console.log("amc-dl-fixup initiated");
+
+    var query_form = document.getElementsByName("qiksearch")[0];
+    if (query_form) {
+	query_form.setAttribute("onsubmit", "fixupEncodeInput(this) ; _proxy_jslib_flush_write_buffers();");
+    }
+
+    var adv_query_form = document.getElementById("theform");
+    if (adv_query_form) {
+	// javascript:submitIt();
+	// javascript:; _proxy_jslib_proxify_html(submitIt())[0]
+
+	adv_query_form.setAttribute("action","javascript:fixupSubmitIt();");
+    }
+
+    var query_box = document.getElementsByName("query")[0];
+    if (query_box) {
+	var query_box_val = query_box.getAttribute("value");
+	query_box.setAttribute("value", query_box_val.replace(/content\.ftsec:\(\+(.*)\)/g,"$1"));
+    }
+    
+    console.log("acm-dl-fixup DOM tweaks done");
+}
+
+
+function fixupGScholarSubmit(evt) {
+    console.log( "gscholar-dl-fixup fixupGScholarSubmit(form) called" );
+
+    var event = evt || window.event;
+    form = event.target.id;
+
+    event.preventDefault(); // to stop the form from submitting
+
+    var query_box = document.getElementById("gs_hp_tsi");
+    var query_box_val = query_box.value;
+
+    query_box_val = opt_ligature_replacement(query_box_val);
+
+    query_box_val = opt_accent_fold(query_box_val);
+
+    query_box.value = query_box_val;
+
+    _proxy_jslib_flush_write_buffers();
+
+    var query_form = document.getElementsByName("f")[0];
+    query_form.submit();
+}
+
+function gscholarFixupInit() {
+
+    console.log("gscholar-fixup initiated");
+
+    var query_form = document.getElementsByName("f")[0];
+    if (query_form) {
+
+	query_form.onsubmit = fixupGScholarSubmit;
+
+    }
+}
+
+
+function fixupXploreSubmit(evt) {
+    console.log( "xplore-dl-fixup fixupXploreSubmit(evt) called" );
+
+    var event = evt || window.event;
+    event.preventDefault(); // to stop the form from submitting
+
+    var query_box = document.getElementById("input-basic");
+    var query_box_val = query_box.value;
+
+    query_box_val = opt_ligature_replacement(query_box_val);
 
 /*
@@ -208,243 +358,4 @@
     query_box_val = opt_accent_fold(query_box_val);
 
-    // e.g., content.ftsec:(+capisco) 
-
-    var query_box_val = query_box_val.replace(/^\s+/,"");
-    var query_box_words = query_box_val.split(/\s+/);
-    
-    var query_box_val_plus = "";
-    var query_box_val_double = "";
-    
-    for (var i=0; i<query_box_words.length; i++) {
-	if (i>0) {
-	    query_box_val_plus += " ";
-	}
-	query_box_val_plus += "+" + query_box_words[i];
-	
-	if (i>0) {
-	    query_box_val_double += " " + query_box_words[i-1]+query_box_words[i];
-	}
-    }
-
-
-    form.elements['query'].value = "content.ftsec:(" + query_box_val_plus + query_box_val_double + ")";
-
-
-    return encodeInput(form);
-}
-
-function fixupSubmitIt() {
-    var search_where = $("#fld0 option:selected").text();
-    //console.log("**** search_where = " + search_where);
-    var x = 0;
-    var search_select = $("#fld"+x+" option:selected");
-    var search_where = search_select.text();    
-
-    while (search_where) {
-	if (search_where == "Any field") {
-	    //var sel_val = document.getElementById("fld" + x).selectedIndex].value;
-	    
-	    //var thisField = document.getElementById("fld" + x).options[document.getElementById("fld" + x).selectedIndex].value;
-	    
-	    $("#fld"+x).val('content.ftsec:');
-	    //$("#fld0 option[value='content.ftsec:']").prop('selected', true);
-	    //alert("changed menu");
-	}
-	x = x + 1;
-	search_select = $("#fld"+x+" option:selected");    
-	search_where = search_select.text();
-	//console.log("*** search select = " + search_select.text());
-	//alert("ddd");
-    }
-    buildQuery();
-
-    return submitIt();
-}
-
-function meddleInfoBox() {
-
-    //$('#_proxy_css_top_insertion').append('<form name="MeddleForm" style="padding-bottom: 20px;"><center><table cellpadding="5" border="1"><tbody><tr><td align="center"><img src="http://bedrock.resnet.cms.waikato.ac.nz/meddle/meddle-icon-large.png" width="64" height="64" /></td><td><b><font size="+1"><a href="https://bedrock.resnet.cms.waikato.ac.nz/meddle/">MEDDLE Proxy: ModifiED Digital Library Proxy</a></font></b><br /><div id="dlcontext"></div><div id="dlcontextoptions"</div></td></tr></tbody></table></center></form>');
-
-    // Icon image
-    // By VistaICO.com (VistaICO Toolbar Icons) [CC BY 3.0 ]
-
-
-    var dlcontextoptions = '<input id="meddle-lig" name="meddle-lig" type="checkbox"><label for="meddle-lig" style="display: inline">&nbsp;Ligature&nbsp;expansion</label>&nbsp;&nbsp;<input id="meddle-acc" name="meddle-acc" type="checkbox"><label for="meddle-acc" style="display: inline">&nbsp;Accent&nbsp;folding</label>';
-
-
-   //console.log("*** location = " + window.location.pathname);
-    var detected_dl = "";
-
-    var domain_match = window.location.pathname.match(/nph-proxy-meddle.cgi\/.*?https?\/(.*)$/);
-
-    if (domain_match.length>1) {
-	var real_domain = domain_match[1];
-	//console.log("*** real domain = " + real_domain);
-
-	if (real_domain.match(/^dl\.acm\.org\//)) {
-	    detected_dl = "ACM DL (Meddled with to provide: full-text quicksearch, word-wrap protection)";
-	    //dlcontextoptions += "&nbsp;&nbsp;Also ";
-	}
-	else if (real_domain.match(/^scholar\.google\.[a-z]+/)) {
-	    detected_dl = "Google Scholar";
-	}
-	else if (real_domain.match(/^www.springer\.com/)) {
-	    detected_dl = "Springer";
-	}
-	else if (real_domain.match(/^ieeexplore\.ieee\.org\//)) {
-	    detected_dl = "IEEE Xplore";
-	}
-    }
-
-    if (detected_dl !== "") {
-	$('#dlcontext').html("<i>Detected:" + detected_dl + "</i>");
-    }
-
-    $('#dlcontextoptions').html('<font size="-1">'+dlcontextoptions+'</font>');
-
-    return detected_dl;
-}
-
-
-function acmdlFixupInit() {
-
-    console.log("amc-dl-fixup initiated");
-
-    var query_form = document.getElementsByName("qiksearch")[0];
-    if (query_form) {
-	query_form.setAttribute("onsubmit", "fixupEncodeInput(this) ; _proxy_jslib_flush_write_buffers();");
-    }
-
-/*
-    //var query_box = document.getElementsByName("query")[0];
-    //var query_box_val = query_box.getAttribute("value");
-    //query_box.setAttribute("value", "Foo");
-*/
-    var adv_query_form = document.getElementById("theform");
-    if (adv_query_form) {
-	// javascript:submitIt();
-	// javascript:; _proxy_jslib_proxify_html(submitIt())[0]
-
-	adv_query_form.setAttribute("action","javascript:fixupSubmitIt();");
-    }
-
-    var query_box = document.getElementsByName("query")[0];
-    if (query_box) {
-	var query_box_val = query_box.getAttribute("value");
-	query_box.setAttribute("value", query_box_val.replace(/content\.ftsec:\(\+(.*)\)/g,"$1"));
-    }
-    
-    console.log("acm-dl-fixup DOM tweaks done");
-}
-
-
-function fixupGScholarSubmit(evt) {
-    console.log( "gscholar-dl-fixup fixupGScholarSubmit(form) called" );
-
-    var event = evt || window.event;
-    form = event.target.id;
-
-    event.preventDefault(); // to stop the form from submitting
-
-/*
-    if (ligature_re === null) {
-        var ligature_str = Object.keys(ligature_map).join("|");
-        ligature_re = new RegExp(ligature_str);
-    }
-*/
-
-    //console.log("*** ligature_str = " + ligature_str);
-
-    //var query_box_val = form.elements['q'].value;
-    var query_box = document.getElementById("gs_hp_tsi");
-    var query_box_val = query_box.value;
-
-    query_box_val = opt_ligature_replacement(query_box_val);
-/*
-    var detected_ligatures = ligature_re.test(query_box_val);
-    if (detected_ligatures) {
-	//var do_replacement = confirm("Detected ligatures in query. Replace with individual characters?");
-	var do_replacement = $('#meddle-lig').is(":checked");
-
-	if (do_replacement) {
-            var query_chars = query_box_val.split("");
-            var query_chars_fixed = [];
-	    
-            for (var i=0; i<query_chars.length; i++) {
-		var c = query_chars[i];
-		if (ligature_map[c]) {
-		    c = ligature_map[c];
-		}
-		query_chars_fixed.push(c);
-            }
-            query_box_val = query_chars_fixed.join("");
-	}
-    }
-*/
-
-/*
-    var do_accent_replacement = $('#meddle-acc').is(":checked");
-    if (do_accent_replacement) {
-	query_box_val = accent_fold(query_box_val);
-    }
-*/
-
-    query_box_val = opt_accent_fold(query_box_val);
-
-    //form.elements['q'].value = query_box_val;
-    query_box.value = query_box_val;
-
-    _proxy_jslib_flush_write_buffers();
-
-    var query_form = document.getElementsByName("f")[0];
-    query_form.submit();
-    //form.submit(); 
-}
-
-function gscholarFixupInit() {
-
-    console.log("gscholar-fixup initiated");
-
-    var query_form = document.getElementsByName("f")[0];
-    if (query_form) {
-	//query_form.setAttribute("onsubmit", "fixupGScholarSubmit(this) ; _proxy_jslib_flush_write_buffers();");
-	//query_form.setAttribute("onsubmit", fixupGScholarSubmit);
-	//query_form.setAttribute("onsubmit", 'function(evt) { fixupGoogleSubmit(evt,this) }');
-
-	query_form.onsubmit = fixupGScholarSubmit;
-/*
-function(evt)  {
-            var event = evt || window.event;
-	    fixupGScholarSubmit(event,event.target.id);
-
-            //console.log(event.target.id); // myform
-	    
-	}
-*/
-
-    }
-}
-
-
-function fixupXploreSubmit(evt) {
-    console.log( "xplore-dl-fixup fixupXploreSubmit(evt) called" );
-
-    var event = evt || window.event;
-    event.preventDefault(); // to stop the form from submitting
-
-    var query_box = document.getElementById("input-basic");
-    var query_box_val = query_box.value;
-
-    query_box_val = opt_ligature_replacement(query_box_val);
-
-/*
-    var do_accent_replacement = $('#meddle-acc').is(":checked");
-    if (do_accent_replacement) {
-	query_box_val = accent_fold(query_box_val);
-    }
-*/
-
-    query_box_val = opt_accent_fold(query_box_val);
-
     query_box.value = query_box_val;
 
@@ -484,5 +395,4 @@
 
     query_box_val = opt_accent_fold(query_box_val);
-    //alert("*** q = " + query_box_val);
 
     query_box.value = query_box_val;
@@ -491,9 +401,5 @@
 
     _proxy_jslib_flush_write_buffers(); // is this needed?
-    //query_form.submit();
     document.createElement('form').submit.call(query_form);
-
-    //var $query_form = $("#global-search");
-    //$query_form.submit();
 
 }
