fixes for stemma retrieval and for relative paths in JS
[scpubgit/stemmatology.git] / stemmaweb / root / js / componentload.js
index c9e3175..8db28dd 100644 (file)
@@ -1,6 +1,10 @@
 function loadTradition( textid ) {
     // First insert the placeholder image
-    var imghtml = '<img src="/images/ajax-loader.gif" alt="Loading SVG..."/>'
+    var basepath = window.location.pathname
+    if( basepath.lastIndexOf('/') == basepath.length - 1 ) { 
+       basepath = basepath.slice( 0, basepath.length - 1) 
+    };
+    var imghtml = '<img src="' + basepath + '/images/ajax-loader.gif" alt="Loading SVG..."/>'
     $('#stemma_graph').empty();
     $('#variant_graph').empty();
     $('#stemma_graph').append( imghtml );
@@ -8,12 +12,12 @@ function loadTradition( textid ) {
     // Then get and load the actual content.
     // TODO: scale #stemma_grpah both horizontally and vertically
     // TODO: load svgs from SVG.Jquery (to make scaling react in Safari)
-       $('#stemma_graph').load( "stemma/" + textid , function() {
+       $('#stemma_graph').load( basepath + "/stemma/" + textid , function() {
        var stemma_svg_element = $('#stemma_graph svg').svg().svg('get').root();
        console.log( stemma_svg_element );
        stemma_svg_element.height.baseVal.value = $('#stemma_graph').height();
        });
-    $('#variant_graph').load( "variantgraph/" + textid , function() {
+    $('#variant_graph').load( basepath + "/variantgraph/" + textid , function() {
        var variant_svg_element = $('#variant_graph svg').svg().svg('get').root();
        var svg_height = variant_svg_element.height.baseVal.value;
        var svg_width = variant_svg_element.width.baseVal.value;