/* Greenstone 3 'Client-side transformer' Performs client-side transformations of XSLT, using HTML5 local storage (simulated if the browser doesn't support it). Currently only supports Firefox 3 and greater, since it's the only browser (at the time of writing) that can do this properly. @author Steven McTainsh @author David Bainbridge @date 2011-2016 */ function isSupported() { // The whole script currently assumes SaxonCE is used to provide XSLT // which means it is always supported => return true // // Could consider testing for native XSLT (using simple // hardwired XML + XSL Tranform?) and using that // if successful (presumably faster) // // Or even try to transform the given transform natively, // and store 'isNativelySupported' as true/false in cookie // accordingly return true; } function notSupportedCookie() { document.cookie = 'supportsXSLT=false; expires=0; path=/'; } function notSupported() { notSupportedCookie(); // knock out 'client-' part from URL var location_href = window.location.href; var new_location_href = location_href.replace(/^(.*)\/(client-)?([^\?\#]+)(.*)$/,"$1/$3$4"); console.log("Client-side XSLT not supported. Redirecting to: " + new_location_href); window.location = new_location_href; } function getUrlParameterHashmap() { var sPageURL = decodeURIComponent(window.location.search.substring(1)); var sURLVariables = sPageURL.split('&'); var paramHashmap = {}; for (var i = 0; i < sURLVariables.length; i++) { var sParameterName = sURLVariables[i].split('='); paramHashmap[sParameterName[0]] = sParameterName[1]; } return paramHashmap; } // From: // http://stackoverflow.com/questions/298750/how-do-i-select-text-nodes-with-jquery function getTextNodesIn(node, includeWhitespaceNodes) { var textNodes = [], nonWhitespaceMatcher = /\S/; function getTextNodes(node) { if (node.nodeType == 3) { if (includeWhitespaceNodes || nonWhitespaceMatcher.test(node.nodeValue)) { textNodes.push(node); } } else { for (var i = 0, len = node.childNodes.length; i < len; ++i) { getTextNodes(node.childNodes[i]); } } } getTextNodes(node); return textNodes; } function applyDisableEscapingToTextNodes(elem) { var textNodes = getTextNodesIn(elem,false); // ignore whitespace for (var i=textNodes.length-1; i>=0; i--) { var text_node = textNodes[i]; var text = text_node.nodeValue; var html = $.parseHTML(text); $(text_node).replaceWith(html); } } var onSaxonLoad = function() { try { var paramHashmap = getUrlParameterHashmap(); var rooturl = window.location.pathname; var queryStr = window.location.search.substring(1); queryStr = queryStr.replace(/o=.*?(&|$)/g,""); if (queryStr != '') { queryStr += "&"; } queryStr += "o=clientside"; paramHashmap['o']="clientside"; //console.log("*** rooturl = " + rooturl); //console.log("*** queryStr = " + queryStr); var skindoc = ""; var xmldoc = ""; $.get(rooturl, paramHashmap, function(data) { var toplevel_children = $(data).children().eq(0).children(); var skindoc = toplevel_children[0]; var xmldoc = toplevel_children[1]; var library_name = $('xsltparams>param[name=library_name]', xmldoc).text(); var interface_name = $('xsltparams>param[name=interface_name]', xmldoc).text(); var site_name = $('xsltparams>param[name=site_name]', xmldoc).text(); var use_client_side_xslt = $('xsltparams>param[name=use_client_side_xslt]', xmldoc).text(); //// Convert temporarily to text here skindoc = convertToString(skindoc); xmldoc = convertToString(xmldoc); skindoc = skindoc.replace(/a.length?a.length-b*4E3:4E3),2592E3):m(y+b);b++}},f=k.localStorage={length:0,setItem:function(a,c){var b=i(),e=0,d=b.length,g=false;for(e=0;e