e881f840f4f1e61dd04479b243f42cb1f1b676e1
[scpubgit/stemmatology.git] / stemmaweb / root / js / componentload.js
1 function loadTradition( textid, textname ) {
2     // First insert the placeholder image
3     var basepath = window.location.pathname
4     if( basepath.lastIndexOf('/') == basepath.length - 1 ) { 
5         basepath = basepath.slice( 0, basepath.length - 1) 
6     };
7     var imghtml = '<img src="' + basepath + '/images/ajax-loader.gif" alt="Loading SVG..."/>'
8     $('#stemma_graph').empty();
9     $('#variant_graph').empty();
10     $('#stemma_graph').append( imghtml );
11     $('#variant_graph').append( imghtml );
12     // Then get and load the actual content.
13     // TODO: scale #stemma_grpah both horizontally and vertically
14     // TODO: load svgs from SVG.Jquery (to make scaling react in Safari)
15         $('#stemma_graph').load( basepath + "/stemma/" + textid );
16     $('#variant_graph').load( basepath + "/variantgraph/" + textid , function() {
17         var variant_svg_element = $('#variant_graph svg').svg().svg('get').root();
18         var svg_height = variant_svg_element.height.baseVal.value;
19         var svg_width = variant_svg_element.width.baseVal.value;
20         var container_height = $('#variant_graph').height();
21         variant_svg_element.height.baseVal.value = container_height;
22         variant_svg_element.width.baseVal.value = (svg_width/svg_height * container_height);
23         });
24         
25         // Then populate the various elements with the right text name/ID.
26         // Stemma and variant graph titles
27         $('.texttitle').empty();
28         $('.texttitle').append( textname );
29         // Stexaminer submit action
30         $('#run_stexaminer').attr( 'action', basepath + "/stexaminer/" + textid );
31         // Relationship mapper submit action
32         $('#run_relater').attr( 'action', basepath + "/relation/" + textid );
33 }