Ignore:
Timestamp:
2017-04-21T11:24:50+12:00 (7 years ago)
Author:
davidb
Message:

Changed to static home page with choice of DL to go to. Initial Google Scholar support added

File:
1 edited

Legend:

Unmodified
Added
Removed
  • other-projects/meddle/trunk/meddle-fixup.js

    r31612 r31627  
    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
     1// MEDDLE version 0.9
     2
     3
     4// Ligature lookup info:
     5//   https://en.wikipedia.org/wiki/List_of_precomposed_Latin_characters_in_Unicode
     6//   https://en.wikipedia.org/wiki/Typographic_ligature#Ligatures_in_Unicode_.28Latin_alphabets.29
    37
    48function trim(str)
     
    203207function meddleInfoBox() {
    204208
    205     $('#_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">MEDDLE Proxy: ModifiED Digital Library Proxy</font></b><br /><div id="dlcontext"></div><div id="dlcontextoptions"</div></td></tr></tbody></table></center></form>');
     209    $('#_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>');
    206210
    207211    // Icon image
    208212    // By VistaICO.com (VistaICO Toolbar Icons) [CC BY 3.0 ]
    209213
    210     // if (window.location.matches(/^h
    211214
    212215    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>';
     
    243246
    244247
    245 
    246 //var acmdl_fixup_div = document.getElementById("acmdl-fixup");
    247 
    248 
    249 //window.onload = function(e) {
    250 
    251248function acmdlFixupInit() {
    252249
    253250    console.log("amc-dl-fixup initiated");
    254 
    255     meddleInfoBox();
    256251
    257252    var query_form = document.getElementsByName("qiksearch")[0];
     
    260255    }
    261256
    262     //query_form.setAttribute("onsubmit", "encodeInput(this) ; _proxy_jslib_flush_write_buffers();");
    263 
    264257/*
    265     var query_box_val = query_form.elements['query'].value;
    266 
    267     //var ft_regex = /content.ftsec:\(\+(.*?)\)/g;
    268     //var match = ft_regex.exec(query_box_val);
    269 
    270     query_form.value = query_box_val.replace(/content.ftsec:\(\+(.*)\)/g,"$1");
    271 
    272258    //var query_box = document.getElementsByName("query")[0];
    273259    //var query_box_val = query_box.getAttribute("value");
     
    292278
    293279
     280function fixupGScholarSubmit(evt) {
     281    //alert("Bar");
     282    console.log( "gscholar-dl-fixup fixupEncodeInput(form) called" );
     283
     284    var event = evt || window.event;
     285    form = event.target.id;
     286
     287    event.preventDefault(); // to stop the form from submitting
     288
     289    if (ligature_re === null) {
     290        var ligature_str = Object.keys(ligature_map).join("|");
     291        ligature_re = new RegExp(ligature_str);
     292    }
     293
     294    //console.log("*** ligature_str = " + ligature_str);
     295
     296    //var query_box_val = form.elements['q'].value;
     297    var query_box = document.getElementById("gs_hp_tsi");
     298    var query_box_val = query_box.value;
     299
     300    var detected_ligatures = ligature_re.test(query_box_val);
     301    if (detected_ligatures) {
     302    //var do_replacement = confirm("Detected ligatures in query. Replace with individual characters?");
     303    var do_replacement = $('#meddle-lig').is(":checked");
     304
     305    if (do_replacement) {
     306            var query_chars = query_box_val.split("");
     307            var query_chars_fixed = [];
     308       
     309            for (var i=0; i<query_chars.length; i++) {
     310        var c = query_chars[i];
     311        if (ligature_map[c]) {
     312            c = ligature_map[c];
     313        }
     314        query_chars_fixed.push(c);
     315            }
     316            query_box_val = query_chars_fixed.join("");
     317    }
     318    }
     319
     320    var do_accent_replacement = $('#meddle-acc').is(":checked");
     321    if (do_accent_replacement) {
     322    query_box_val = accent_fold(query_box_val);
     323    }
     324
     325
     326    //form.elements['q'].value = query_box_val;
     327    query_box.value = query_box_val;
     328
     329    _proxy_jslib_flush_write_buffers();
     330
     331    var query_form = document.getElementsByName("f")[0];
     332    query_form.submit();
     333    //form.submit();
     334}
     335
     336function gscholarFixupInit() {
     337
     338    console.log("gscholar-fixup initiated");
     339
     340    var query_form = document.getElementsByName("f")[0];
     341    if (query_form) {
     342    //query_form.setAttribute("onsubmit", "fixupGScholarSubmit(this) ; _proxy_jslib_flush_write_buffers();");
     343    //query_form.setAttribute("onsubmit", fixupGScholarSubmit);
     344    //query_form.setAttribute("onsubmit", 'function(evt) { fixupGoogleSubmit(evt,this) }');
     345
     346    query_form.onsubmit = fixupGScholarSubmit;
     347/*
     348function(evt)  {
     349            var event = evt || window.event;
     350        fixupGScholarSubmit(event,event.target.id);
     351
     352            //console.log(event.target.id); // myform
     353       
     354    }
     355*/
     356
     357    }
     358
     359
     360
     361/*
     362    //var query_box = document.getElementsByName("query")[0];
     363    //var query_box_val = query_box.getAttribute("value");
     364    //query_box.setAttribute("value", "Foo");
     365*/
     366    console.log("gscholar DOM tweaks done");
     367}
     368
     369
     370// Google Scholar
     371// <input class="gs_in_txt" name="q" value="" data-iq="" id="gs_hp_tsi" size="57" maxlength="256" autocapitalize="off" autocomplete="off" aria-label="Search" dir="ltr" type="text">
     372
    294373$(document).ready(function() {
    295374  console.log( "jquery DOM ready" );
     375  meddleInfoBox();
     376
    296377  acmdlFixupInit()
     378  gscholarFixupInit()
     379
    297380});
    298381
Note: See TracChangeset for help on using the changeset viewer.