Index: /gs3-extensions/structured-image/trunk/src/js/document_extra.js
===================================================================
--- /gs3-extensions/structured-image/trunk/src/js/document_extra.js	(revision 37708)
+++ /gs3-extensions/structured-image/trunk/src/js/document_extra.js	(revision 37709)
@@ -228,15 +228,25 @@
 function createMirador3Viewer()
 {
-    var doc_url = new URL(window.location);
-    var goto_page = doc_url.searchParams.get('gotoPage') || 1;
-
+    var doc_id = gs.cgiParams.d;
+    var opt_dot_pos = doc_id.indexOf(".");
+
+    var goto_page;
+    var doc_id_root;
+    
+    if (opt_dot_pos>=0) {
+	goto_page = doc_id.substring(opt_dot_pos+1);
+	doc_id_root = doc_id.substring(0,opt_dot_pos);
+    }
+    else {
+	var doc_url = new URL(window.location);
+	goto_page = doc_url.searchParams.get('gotoPage') || 1;
+	doc_id_root = doc_id;
+    }
+	
     var canvas_index = goto_page -1;
 
-    var httpDocument = gs.xsltParams.library_name + "/collection/" + gs.cgiParams.c + "/document/" + gs.cgiParams.d;
+    var httpDocument = gs.xsltParams.library_name + "/collection/" + gs.cgiParams.c + "/document/" + doc_id_root;
     var httpDocumentIIIFManifest = httpDocument + "?sa=iiif-manifest&ed=1&excerptid-text=iiif-manifest";
 
-    //const endpointUrl = 'https://intermuse.sowemustthink.space/simpleAnnotationStore/annotation';
-    //const endpointUrl = '/simpleAnnotationStore/annotation';
-    
     var mirador3_config = {
 	"manifests": {
@@ -278,5 +288,5 @@
     var includeFileAssocOpenAnnotations = gs.variables.optionIncludeFileAssocOpenAnnotations;
     var includeEditableOpenAnnotations  = gs.variables.optionIncludeEditableOpenAnnotations;
-
+    
     if ((includeFileAssocOpenAnnotations == 'true') || (includeEditableOpenAnnotations == 'true')) {
 	// Activate the annotations plugin
@@ -287,5 +297,22 @@
 	mirador3_config.window.sideBarOpenByDefault = true;	  
 
-	if (includeEditableOpenAnnotations == 'true') {
+	// In addition to the usual group checks, allow the user to edit annotations if they
+	// are in a group that matches site_name
+	
+	var logged_in_user_can_edit = false;
+	
+	if (gs.userInformation) {
+	    var userinfo_groups = gs.userInformation.groups;
+	    var site_name = gs.xsltParams.site_name;
+	    var coll_name = gs.cgiParams.c;
+	    if (userinfo_groups.includes("administrator")
+		|| userinfo_groups.includes("all-collections-editor")
+		|| userinfo_groups.includes(coll_name+"-collection-editor")
+		|| userinfo_groups.includes(site_name+"-editor")) {
+		logged_in_user_can_edit = true;
+	    }
+	}  
+	
+	if ((includeEditableOpenAnnotations == 'true') && (logged_in_user_can_edit)) {
 
 	    var endpointURL  = gs.variables.optionIncludeEditableOpenAnnotationsEndpointURL;
@@ -307,4 +334,6 @@
     
     var mirador3_viewer = mirador3WithAnnotations.initMirador3Viewer('mirador3-viewer',mirador3_config);
+
+    //setTimeout(function() { miradorSearch("MUSIC") }, 2000);
     
     return mirador3_viewer;
@@ -484,2 +513,51 @@
     return iiif_manifest;
 }
+
+
+// https://chuckconway.com/changing-a-react-input-value-from-vanilla-javascript/
+
+function setNativeValue(element, value) {
+    let lastValue = element.value;
+    element.value = value;
+    let event = new Event("input", { target: element, bubbles: true });
+    // React 15
+    event.simulated = true;
+    // React 16
+    let tracker = element._valueTracker;
+    if (tracker) {
+        tracker.setValue(lastValue);
+    }
+    element.dispatchEvent(event);
+}
+
+//var input = document.getElementById("ID OF ELEMENT");
+//setNativeValue(input, "VALUE YOU WANT TO SET");
+
+
+function miradorSearch(query_term)
+{
+    var $select_search_tab = $('button[aria-label="Search"]');
+    $select_search_tab.trigger("click");
+
+    // While triggering a vanilla Javascript "click" event happens synchronously,
+    // it would appear that things are more complex (obfuscated!) when React is involved
+    // and this being a synchronous call is no longer the case
+    //
+    // Because Jquery expects the call to be synchronous, it does not provide any
+    // way of attaching a callback
+    // => Need use setTimeout to cause a small delay
+    
+    setTimeout(function() {
+	
+	var $search_aside = $('aside[aria-label="Search"]');
+        
+	var search_input_text = $search_aside.find('input[type="text"]')[0];
+	
+	setNativeValue(search_input_text,query_term);
+	
+	var $search_button = $search_aside.find('button[aria-label="Submit search"]');
+	$search_button.trigger("click");
+    }, 500);    
+}
+
+    
