From: Errietta Kostala <errietta@errietta.me>
Date: Tue, 12 May 2015 09:49:16 +0000 (+0000)
Subject: Pass on the text direction, scroll to end if RL
X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=89aae3eec7a0e23f314597cd09bd3ffc696c7412;p=scpubgit%2Fstemmaweb.git

Pass on the text direction, scroll to end if RL
---

diff --git a/lib/stemmaweb/Controller/Relation.pm b/lib/stemmaweb/Controller/Relation.pm
index 24d1de3..0a0579c 100644
--- a/lib/stemmaweb/Controller/Relation.pm
+++ b/lib/stemmaweb/Controller/Relation.pm
@@ -70,7 +70,10 @@ sub main :Chained('text') :PathPart('') :Args(0) {
 	my( $self, $c ) = @_;
 	my $tradition = delete $c->stash->{'tradition'};
 	my $collation = $tradition->collation;
-	
+
+	# Stash text direction to use in JS.
+	$c->stash->{'direction'} = $collation->direction;
+
 	# Stash the relationship definitions
 	$c->stash->{'relationship_scopes'} = 
 		to_json( find_type_constraint( 'RelationshipScope' )->values );
diff --git a/root/js/relationship.js b/root/js/relationship.js
index 495d28c..9a4a169 100644
--- a/root/js/relationship.js
+++ b/root/js/relationship.js
@@ -4,6 +4,7 @@ var svg_root_element = null;
 var start_element_height = 0;
 var reltypes = {};
 var readingdata = {};
+var text_direction = 'LR';
 
 jQuery.removeFromArray = function(value, arr) {
     return jQuery.grep(arr, function(elem, index) {
@@ -224,7 +225,10 @@ function svgEnlargementLoaded() {
     
     //initialize marquee
     marquee = new Marquee();
-    
+
+	if (text_direction == 'RL') {
+		scrollToEnd();
+	}
 }
 
 function add_relations( callback_fn ) {
@@ -981,6 +985,21 @@ function readings_equivalent( source, target ) {
 	return false;
 }
 
+function scrollToEnd() {
+	var stateTf = svg_root_element.getCTM().inverse();
+
+	var vbdim = svg_root.viewBox.baseVal;
+	var width = Math.floor(svg_root_element.getBoundingClientRect().width) - vbdim.width;
+
+	var p = svg_root.createSVGPoint();
+	p.x = width;
+	p.y = 0;
+	p = p.matrixTransform(stateTf);
+
+	var matrix = stateTf.inverse().translate(-p.x, -100);
+	var s = "matrix(" + matrix.a + "," + matrix.b + "," + matrix.c + "," + matrix.d + "," + matrix.e + "," + matrix.f + ")";
+	svg_root_element.setAttribute("transform", s);
+}
 
 $(document).ready(function () {
     
@@ -1468,7 +1487,9 @@ function expandFillPageClients() {
 	});
 }
 
-function loadSVG(svgData) {
+function loadSVG(svgData, direction) {
+	text_direction = direction;
+
 	var svgElement = $('#svgenlargement');
 
 	$(svgElement).svg('destroy');
diff --git a/root/src/relate.tt b/root/src/relate.tt
index e46c5de..4d9d4e4 100644
--- a/root/src/relate.tt
+++ b/root/src/relate.tt
@@ -24,7 +24,7 @@ var ternary_values = [% ternary_values %];
 [% END -%]
 
 $(document).ready(function () {
-  loadSVG('[% svg_string %]');
+  loadSVG('[% svg_string %]', '[% direction %]');
 });
 </script>
 [% END %]