ltl2tgba.html: Scroll to result. (Suggested by Thomas Badie.)

* wrap/python/ajax/ltl2tgba.html: Scroll the the results the first
time a formula is submitted, and anytime a formula is submitted with
'enter'.  Also do not animate the settings of panels when reloading
the page from a hash fragment.
This commit is contained in:
Alexandre Duret-Lutz 2012-03-18 22:35:34 +01:00
parent 3fb29ce1be
commit 862c248a41

View file

@ -14,7 +14,8 @@
<script type="text/javascript" src="js/jquery.ba-bbq.min.js"></script> <script type="text/javascript" src="js/jquery.ba-bbq.min.js"></script>
<script type="text/javascript"> <script type="text/javascript">
jQuery(document).ready(function(){ jQuery(document).ready(function(){
$.spotvars = { autoupdate: 0 } $.spotvars = { autoupdate: 0,
scrolldown: 1 };
$(".tabs").tabs(); $(".tabs").tabs();
$("#send").button(); $("#send").button();
$("#results").hide(); $("#results").hide();
@ -41,30 +42,31 @@
content: "<b>Click<\/b> to fold/unfold." content: "<b>Click<\/b> to fold/unfold."
}); });
function hideOrShowPanels(output) { function hideOrShowPanels(output, duration) {
switch (output) switch (output)
{ {
case 'f': case 'f':
$('#translator-tabs,#autsimp-tabs,#run-tabs').hide('fast'); $('#translator-tabs,#autsimp-tabs,#run-tabs').hide(duration);
break; break;
case 'm': case 'm':
$('#autsimp-tabs,#run-tabs').hide('fast'); $('#autsimp-tabs,#run-tabs').hide(duration);
$('#translator-tabs').show('fast'); $('#translator-tabs').show(duration);
break; break;
case 'a': case 'a':
$('#translator-tabs,#autsimp-tabs').show('fast'); $('#translator-tabs,#autsimp-tabs').show(duration);
$('#run-tabs').hide('fast'); $('#run-tabs').hide(duration);
break; break;
case 'r': case 'r':
$('#translator-tabs,#autsimp-tabs,#run-tabs').show('fast'); $('#translator-tabs,#autsimp-tabs,#run-tabs').show(duration);
break; break;
} }
} }
function updateFormFromHash() { function updateFormFromHash(duration) {
var hashparam = jQuery.deparam.fragment(); var hashparam = jQuery.deparam.fragment();
if (jQuery.isEmptyObject(hashparam)) if (jQuery.isEmptyObject(hashparam))
return; return;
if ($.spotvars.autoupdate == 0)
$("input,select", "#trform").each(function() { $("input,select", "#trform").each(function() {
var name = this.name; var name = this.name;
var value = []; var value = [];
@ -94,15 +96,16 @@
this.value=value.join(','); this.value=value.join(',');
} }
}); });
updateResults(); $.spotvars.autoupdate = 1;
var o = $('input[name="o"]').val(); var o = $('input[name="o"]').val();
hideOrShowPanels(o, duration);
$("#output-tabs").tabs("select", "#tabs-o" + o); $("#output-tabs").tabs("select", "#tabs-o" + o);
hideOrShowPanels(o);
var t = $('input[name="t"]').val(); var t = $('input[name="t"]').val();
$("#translator-tabs").tabs('select', '#tabs-t' + t); $("#translator-tabs").tabs('select', '#tabs-t' + t);
updateResults();
} }
$(window).bind('hashchange', function(e) { updateFormFromHash() }); $(window).bind('hashchange', function(e) { updateFormFromHash('fast') });
$.get("/cgi-bin/spot.py", "o=v", function(data) { $.get("/cgi-bin/spot.py", "o=v", function(data) {
$("#spottip").attr("title", "This page uses <b>" + data + "<\/b> to process LTL formulas and automata. Please download the <b>Spot<\/b> library and install it on your computer if you want to do the same from the command line, or from another program.") $("#spottip").attr("title", "This page uses <b>" + data + "<\/b> to process LTL formulas and automata. Please download the <b>Spot<\/b> library and install it on your computer if you want to do the same from the command line, or from another program.")
@ -111,11 +114,11 @@
defaultPosition: "right"}); defaultPosition: "right"});
}); });
function fold(ui) { function fold(ui, callback) {
var icon = ui.children(".ui-icon"); var icon = ui.children(".ui-icon");
icon.removeClass("ui-icon-circle-arrow-n") icon.removeClass("ui-icon-circle-arrow-n")
.addClass("ui-icon-circle-arrow-s"); .addClass("ui-icon-circle-arrow-s");
ui.siblings('[class!="dontcollapse"]').hide('fast'); ui.siblings('[class!="dontcollapse"]').hide('fast', callback);
} }
function unfold(ui) { function unfold(ui) {
var icon = ui.children(".ui-icon"); var icon = ui.children(".ui-icon");
@ -149,7 +152,6 @@
// it has been %-decoded by firefox, which // it has been %-decoded by firefox, which
// cause problems when formulae include '&'. // cause problems when formulae include '&'.
var fragment = location.href.replace(/^[^#]*#?(.*)$/, '$1'); var fragment = location.href.replace(/^[^#]*#?(.*)$/, '$1');
$.spotvars.autoupdate = 1;
$("#results-body") $("#results-body")
.load("/cgi-bin/spot.py", .load("/cgi-bin/spot.py",
fragment, fragment,
@ -160,8 +162,12 @@
+ xhr.statusText); + xhr.statusText);
} }
$("#results").show(); $("#results").show();
fold($("#ltl-head"));
unfold($("#results-head")); unfold($("#results-head"));
fold($("#ltl-head"), function() {
if ($.spotvars.scrolldown)
$('html,body').animate({scrollTop: $("#results-head").offset().top}, 'slow');
$.spotvars.scrolldown = 0;
});
return true; return true;
}); });
} }
@ -176,8 +182,10 @@
$("input,select").change(autoUpdate); $("input,select").change(autoUpdate);
$('input[name="f"]').attr('spellcheck', false).focus() $('input[name="f"]').attr('spellcheck', false).focus()
.keydown(function(e){ .keydown(function(e){
if (e.keyCode == 13) if (e.keyCode == 13) {
$.spotvars.scrolldown = 1;
updateHash(); updateHash();
}
}); });
$('.collapsible .head').click(function(e) { $('.collapsible .head').click(function(e) {
if (e.ctrlKey) { if (e.ctrlKey) {
@ -192,7 +200,7 @@
var v = ui.panel.id[6]; // 'tabs-om' => 'm'. var v = ui.panel.id[6]; // 'tabs-om' => 'm'.
$('input[name="o"]').val(v) $('input[name="o"]').val(v)
if (!autoUpdate()) if (!autoUpdate())
hideOrShowPanels(v) hideOrShowPanels(v, 'fast')
return true; return true;
}); });
$('#output-tabs').tabs('select', '#tabs-oa'); $('#output-tabs').tabs('select', '#tabs-oa');
@ -203,7 +211,7 @@
}); });
// Update the form from the hash value // Update the form from the hash value
updateFormFromHash(); updateFormFromHash(0);
}); });
</script> </script>
</head> </head>