Ignore:
Timestamp:
2024-04-23T18:59:30+12:00 (4 weeks ago)
Author:
anupama
Message:
  1. More streamlining of the XSL code for the GsdlCollage and Phind applets so its easier to add new parameters (don't need to keep checking where else to add them). 2. Minor corrections to the XSL to get GsdlCollageApplet to run as webswing application again too. Tested both GsdlCollage and Phind as webswing application and webswing applet. Both working. The way to swap between them is to make webswing.config.applet or webswing.config.application (in ext/webswing) the active webswing.config.in file in web/ext/webswing and then change the isWebswingRunAsApplet variable to true or false accordingly in both the webswing-collage.xsl and webswing-phind.xsl. If you forget one of these steps, it's not immediately apparent why the webswing application is not launching and you have to check the webswing log for how it's trying to launch it and make sure it makes sense for if you chose applet/application. 3. Allowed Phind run as application to work with width and height values passed in from the commandline. The fallback is still 500x500.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • main/trunk/greenstone3/web/interfaces/default/transform/layouts/webswing-collage.xsl

    r38946 r38948  
    7575       
    7676       if(!webswingInstance0.options.args) {
    77        webswingInstance0.options.args="";       
     77          webswingInstance0.options.args="";       
    7878       }
    7979
     
    8181       var appletEl = document.getElementById("collage-applet-element");
    8282       
    83     if(!appletEl) {
    84        
    85        if(verbosity >= 4) {
    86           console.log("No collage-applet-element on page. Reading in from pageResponse/XSLT.");
     83       // Fill up webswingParams JSON record with non-dynamic values and other vals
     84       // that may perhaps not be set on the applet element, to use as fallback
     85       var webswingParams = {
     86       //"webswing":1, // set in webswing.config.in to discourage editing
     87       "verbosity": verbosity,
     88       "gsdlversion":3,
     89       "maxDepth": 500,
     90       "maxDisplay": 25,
     91       "refreshDelay": 1500,
     92       "isJava2":"auto",
     93       "bgcolor":"#96c29a"
     94       };
     95       
     96       if(!appletEl && verbosity >= 4) {
     97          console.log("No collage-applet-element on page. Using webswing params vals from pageResponse/XSLT.");
    8798       }     
    8899     
     
    106117       var gs3CollBrowsePath = gs.xsltParams.library_name + "/collection/" + gs.cgiParams.c + "/browse/" + gs.cgiParams.cl; // cl is classifier, e.g "CL3"
    107118
    108        var gsdlversion = 3;
    109        var collection = gs.cgiParams.c;
    110        var library = gs.xsltParams.library_name;
    111        var documentroot = gs.xsltParams.servlet_context;
    112        var hrefMustHave = gs3CollBrowsePath;
    113        var imageMustNotHave = "interfaces/";
    114        var imageType = ".jpg%.png";
    115        var classifier = gs.cgiParams.cl + ".1";
    116 
    117        // non-dynamic values
    118        var maxDepth = 500;
    119        var maxDisplay = 25;
    120        var refreshDelay = 1500;
    121        var isJava2 = "auto";
    122        var bgcolor = "#96c29a";
    123 
    124        
    125        // Control the width and height of the Java application launched with webswing
    126        // by passing width and height params set to the attributes of the webswing element
    127        // https://stackoverflow.com/questions/21851633/get-height-from-style-attribute
    128        var w = document.getElementById("webswing-collage").style.width;
    129        var h = document.getElementById("webswing-collage").style.height;
    130        
    131     } else { // the applet element exists, get all webswing config settings from there
    132 
     119       webswingParams["baseurl"] = baseURL;
     120       webswingParams["collection"] = gs.cgiParams.c;
     121       webswingParams["library"] = gs.xsltParams.library_name;
     122       webswingParams["documentroot"] = gs.xsltParams.servlet_context;
     123       webswingParams["hrefMustHave"] = gs3CollBrowsePath;
     124       webswingParams["imageMustNotHave"] = "interfaces/";
     125       webswingParams["imageType"] = ".jpg%.png";
     126       webswingParams["classifier"] = gs.cgiParams.cl + ".1";
     127       
     128       
     129       
     130    if(appletEl) { // get all available webswing config settings from applet element
     131       if(verbosity >= 4) {
     132          console.log("collage-applet-element on page, using its params where available.");
     133       }
    133134       // If using the inactive/deprecated applet element as shim, instead of javascript
    134135       // working out the webswing config params from the pageRequest or XSLT variables:
     
    136137       // as a GS3 library designer may know to how to customize applet parameters
    137138       // better than they know javascript or how to construct webswing parameters.       
    138 
    139        // First (re)setting the verbosity variable already declared earlier
    140        var tmp_verbosity = appletEl.querySelector("param[name='verbosity']").value;
    141        if(tmp_verbosity) {
    142           verbosity = tmp_verbosity;
    143        }
    144        var baseURL = appletEl.querySelector("param[name='baseurl']").value;
    145        var gsdlversion = appletEl.querySelector("param[name='gsdlversion']").value;
    146        var collection = appletEl.querySelector("param[name='collection']").value;
    147        var library = appletEl.querySelector("param[name='library']").value;
    148        var documentroot = appletEl.querySelector("param[name='documentroot']").value;
    149        var hrefMustHave = appletEl.querySelector("param[name='hrefMustHave']").value;
    150        var imageMustNotHave = appletEl.querySelector("param[name='imageMustNotHave']").value;
    151        var imageType = appletEl.querySelector("param[name='imageType']").value;
    152        var classifier = appletEl.querySelector("param[name='classifier']").value;
    153        var maxDepth = appletEl.querySelector("param[name='maxDepth']").value;
    154        var maxDisplay = appletEl.querySelector("param[name='maxDisplay']").value;
    155        var refreshDelay = appletEl.querySelector("param[name='refreshDelay']").value;
    156        var isJava2 = appletEl.querySelector("param[name='isJava2']").value;
    157        var bgcolor = appletEl.querySelector("param[name='bgcolor']").value;
    158 
    159        var w = appletEl.width;
    160        var h = appletEl.height;
    161139             
     140       // Now get the param subelements of the applet element
     141       for (var webswingParam of Object.keys(webswingParams)) {
     142          var querySelectorStr = "param[name='"+webswingParam+"']";       
     143          var appletParam = appletEl.querySelector(querySelectorStr);
     144      if(appletParam) { // if this parameter was set on the applet
     145         webswingParams[webswingParam] = appletParam.value;
     146      } else {
     147         if(verbosity>=3) {
     148            console.log("Applet element doesn't supply param: " + webswingParam + ". Using fallback: " + webswingParams[webswingParam]);
     149         }
     150      }
     151       }
     152     
    162153    }
    163        
    164        webswingInstance0.options.args += "--baseurl \"" + baseURL + "\"";
    165        //webswingInstance0.options.args += " --webswing 1"; // set in webswing.config.in
    166        webswingInstance0.options.args += " --gsdlversion " + gsdlversion;
    167        webswingInstance0.options.args += " --collection " + collection;
    168        webswingInstance0.options.args += " --library " + library;
    169        webswingInstance0.options.args += " --documentroot " + documentroot;
    170        webswingInstance0.options.args += " --hrefMustHave " + hrefMustHave;
    171        webswingInstance0.options.args += " --imageMustNotHave \""+ imageMustNotHave+ "\"";
    172        webswingInstance0.options.args += " --verbosity " + verbosity;
    173        webswingInstance0.options.args += " --imageType \"" + imageType + "\"";
    174        webswingInstance0.options.args += " --classifier \"" + classifier + "\"";
    175        webswingInstance0.options.args += " --maxDepth " + maxDepth;
    176        webswingInstance0.options.args += " --maxDisplay " + maxDisplay;
    177        webswingInstance0.options.args += " --refreshDelay " + refreshDelay;
    178        webswingInstance0.options.args += " --isJava2 \""+ isJava2 +"\"";
    179        webswingInstance0.options.args += " --bgcolor \""+ bgcolor +"\"";
    180        
    181 
    182        // common code, regardless of whether we use the applet element as a shim or not
    183        var suffixIndex = 0;
    184        if(w) {       
    185           suffixIndex = w.indexOf("px");
    186           if(suffixIndex>0) {
    187              w = w.substring(0, suffixIndex);
    188           }
    189           webswingInstance0.options.args += " --width " + w;
    190        }       
    191        if(h) {
    192           suffixIndex = h.indexOf("px");
    193           if(suffixIndex>0) {
    194              h = h.substring(0, suffixIndex);
    195           }
    196           webswingInstance0.options.args += " --height " + h;
    197        }
    198 
     154
     155       // Special case: width and height are attributes of the applet tag not subelements
     156       // and may need parsing.
     157       // Control the width and height of the Java application launched with webswing by
     158       // passing the width and height params set on the webswing element, unless an applet
     159       // element is available. In that case try to get the dimensions from the applet tag.
     160       // https://stackoverflow.com/questions/21851633/get-height-from-style-attribute
     161       var w = appletEl ? appletEl.getAttribute("width") : document.getElementById("webswing-collage").style.width;
     162       var h = appletEl ? appletEl.getAttribute("height") : document.getElementById("webswing-collage").style.height;
     163       webswingParams["width"] = stripUnitOffAttribute("px", w);
     164       webswingParams["height"] = stripUnitOffAttribute("px", h);
     165
     166       
     167       // Having collected all the webswingParams, we can finally build up the single webswing customArgs string
     168       var _args = "";
     169       for (var webswingParam of Object.keys(webswingParams)) {
     170          _args += "--" + webswingParam + " \"" + webswingParams[webswingParam] + "\" "; // space at end to precede next arg
     171       }
     172       webswingInstance0.options.args += _args.substring(0, _args.length-1); // remove extra space at end
     173   
     174       
    199175       // Set to false if running the webswing instance as a webswing application. This has
    200176       // nothing to do with if the applet element exists on the page: it can be on the page
     
    238214        var results = new RegExp("[\\?&]" + name + "=([^&#]*)").exec(location.href);
    239215        return results == null ? null : decodeURIComponent(results[1]);
     216    }
     217
     218    function stripUnitOffAttribute(unit, attr) {
     219    // common code, regardless of whether we use the applet element as a shim or not
     220       var suffixIndex = 0;
     221       if(attr) {       
     222          suffixIndex = attr.indexOf(unit);
     223          if(suffixIndex>0) {
     224             attr = attr.substring(0, suffixIndex);
     225          }
     226       }       
     227       return attr;
    240228    }
    241229  </gsf:script>
Note: See TracChangeset for help on using the changeset viewer.