Changeset 37709


Ignore:
Timestamp:
2023-04-23T23:03:30+12:00 (13 months ago)
Author:
davidb
Message:

Further coding developments; given that Mirdora3 has an API call for opening a document with search terms already active, it is likely that some of this code is now superfluous

File:
1 edited

Legend:

Unmodified
Added
Removed
  • gs3-extensions/structured-image/trunk/src/js/document_extra.js

    r37117 r37709  
    228228function createMirador3Viewer()
    229229{
    230     var doc_url = new URL(window.location);
    231     var goto_page = doc_url.searchParams.get('gotoPage') || 1;
    232 
     230    var doc_id = gs.cgiParams.d;
     231    var opt_dot_pos = doc_id.indexOf(".");
     232
     233    var goto_page;
     234    var doc_id_root;
     235   
     236    if (opt_dot_pos>=0) {
     237    goto_page = doc_id.substring(opt_dot_pos+1);
     238    doc_id_root = doc_id.substring(0,opt_dot_pos);
     239    }
     240    else {
     241    var doc_url = new URL(window.location);
     242    goto_page = doc_url.searchParams.get('gotoPage') || 1;
     243    doc_id_root = doc_id;
     244    }
     245   
    233246    var canvas_index = goto_page -1;
    234247
    235     var httpDocument = gs.xsltParams.library_name + "/collection/" + gs.cgiParams.c + "/document/" + gs.cgiParams.d;
     248    var httpDocument = gs.xsltParams.library_name + "/collection/" + gs.cgiParams.c + "/document/" + doc_id_root;
    236249    var httpDocumentIIIFManifest = httpDocument + "?sa=iiif-manifest&ed=1&excerptid-text=iiif-manifest";
    237250
    238     //const endpointUrl = 'https://intermuse.sowemustthink.space/simpleAnnotationStore/annotation';
    239     //const endpointUrl = '/simpleAnnotationStore/annotation';
    240    
    241251    var mirador3_config = {
    242252    "manifests": {
     
    278288    var includeFileAssocOpenAnnotations = gs.variables.optionIncludeFileAssocOpenAnnotations;
    279289    var includeEditableOpenAnnotations  = gs.variables.optionIncludeEditableOpenAnnotations;
    280 
     290   
    281291    if ((includeFileAssocOpenAnnotations == 'true') || (includeEditableOpenAnnotations == 'true')) {
    282292    // Activate the annotations plugin
     
    287297    mirador3_config.window.sideBarOpenByDefault = true;   
    288298
    289     if (includeEditableOpenAnnotations == 'true') {
     299    // In addition to the usual group checks, allow the user to edit annotations if they
     300    // are in a group that matches site_name
     301   
     302    var logged_in_user_can_edit = false;
     303   
     304    if (gs.userInformation) {
     305        var userinfo_groups = gs.userInformation.groups;
     306        var site_name = gs.xsltParams.site_name;
     307        var coll_name = gs.cgiParams.c;
     308        if (userinfo_groups.includes("administrator")
     309        || userinfo_groups.includes("all-collections-editor")
     310        || userinfo_groups.includes(coll_name+"-collection-editor")
     311        || userinfo_groups.includes(site_name+"-editor")) {
     312        logged_in_user_can_edit = true;
     313        }
     314    } 
     315   
     316    if ((includeEditableOpenAnnotations == 'true') && (logged_in_user_can_edit)) {
    290317
    291318        var endpointURL  = gs.variables.optionIncludeEditableOpenAnnotationsEndpointURL;
     
    307334   
    308335    var mirador3_viewer = mirador3WithAnnotations.initMirador3Viewer('mirador3-viewer',mirador3_config);
     336
     337    //setTimeout(function() { miradorSearch("MUSIC") }, 2000);
    309338   
    310339    return mirador3_viewer;
     
    484513    return iiif_manifest;
    485514}
     515
     516
     517// https://chuckconway.com/changing-a-react-input-value-from-vanilla-javascript/
     518
     519function setNativeValue(element, value) {
     520    let lastValue = element.value;
     521    element.value = value;
     522    let event = new Event("input", { target: element, bubbles: true });
     523    // React 15
     524    event.simulated = true;
     525    // React 16
     526    let tracker = element._valueTracker;
     527    if (tracker) {
     528        tracker.setValue(lastValue);
     529    }
     530    element.dispatchEvent(event);
     531}
     532
     533//var input = document.getElementById("ID OF ELEMENT");
     534//setNativeValue(input, "VALUE YOU WANT TO SET");
     535
     536
     537function miradorSearch(query_term)
     538{
     539    var $select_search_tab = $('button[aria-label="Search"]');
     540    $select_search_tab.trigger("click");
     541
     542    // While triggering a vanilla Javascript "click" event happens synchronously,
     543    // it would appear that things are more complex (obfuscated!) when React is involved
     544    // and this being a synchronous call is no longer the case
     545    //
     546    // Because Jquery expects the call to be synchronous, it does not provide any
     547    // way of attaching a callback
     548    // => Need use setTimeout to cause a small delay
     549   
     550    setTimeout(function() {
     551   
     552    var $search_aside = $('aside[aria-label="Search"]');
     553       
     554    var search_input_text = $search_aside.find('input[type="text"]')[0];
     555   
     556    setNativeValue(search_input_text,query_term);
     557   
     558    var $search_button = $search_aside.find('button[aria-label="Submit search"]');
     559    $search_button.trigger("click");
     560    }, 500);   
     561}
     562
     563   
Note: See TracChangeset for help on using the changeset viewer.