Difference between revisions of "GBrowse/AJAXhandlerScript"
From GMOD
m (→Changes to Bio::Graphics::Browser) |
(OK, that's enough now) |
||
Line 8: | Line 8: | ||
− | * A sticky balloon with contents generated from gbrowse-details (via an <iframe> element) and the '''''default''''' callback shown below. | + | * A sticky balloon with contents generated from gbrowse-details (via an <iframe> element) and the '''''default''''' callback shown below. |
[[Image:sample2b.png]] | [[Image:sample2b.png]] | ||
Line 18: | Line 18: | ||
* A response is triggered after the feature(s) are defined but before '''''PrintTop''''' is called. | * A response is triggered after the feature(s) are defined but before '''''PrintTop''''' is called. | ||
+ | <perl> | ||
if (defined $rmt) { | if (defined $rmt) { | ||
print header,start_html; | print header,start_html; | ||
Line 23: | Line 24: | ||
print end_html; | print end_html; | ||
exit 0; | exit 0; | ||
− | } | + | } |
+ | </perl> | ||
− | * The '''''remote_content''''' subroutine will get the text or coderef. It will return the text or execute the callback with user-defined arguments | + | * The '''''remote_content''''' subroutine will get the text or coderef. It will return the text or execute the callback with user-defined arguments |
− | # do something for popup balloons | + | <perl> |
+ | # do something for popup balloons | ||
sub remote_content { | sub remote_content { | ||
− | my $key = shift; # the key for the text or code-ref in the gbrowse config file | + | my $key = shift; # the key for the text or code-ref in the gbrowse config file |
my $feat = shift; | my $feat = shift; | ||
− | my $contents = $CONFIG->config->code_setting('TOOLTIPS',$key) or die "$key is empty"; | + | my $contents = $CONFIG->config->code_setting('TOOLTIPS',$key) or die "$key is empty"; |
my $coderef = (ref $contents||'') eq 'CODE'; | my $coderef = (ref $contents||'') eq 'CODE'; | ||
− | return $contents unless $coderef; | + | return $contents unless $coderef; |
− | # paranoia? | + | # paranoia? |
die "Error: $key is not a CODE-REF" if ref $contents && !$coderef; | die "Error: $key is not a CODE-REF" if ref $contents && !$coderef; | ||
− | # args are user-defined | + | # args are user-defined |
my %args = (feature => $feat) if $feat; | my %args = (feature => $feat) if $feat; | ||
for my $arg (param()) { | for my $arg (param()) { | ||
Line 44: | Line 47: | ||
return $contents->(\%args); | return $contents->(\%args); | ||
} | } | ||
+ | </perl> | ||
==Changes To Configuration File== | ==Changes To Configuration File== | ||
Line 58: | Line 62: | ||
[[Image:browsercode]] | [[Image:browsercode]] | ||
− | |||
[[Category:AJAX]] | [[Category:AJAX]] | ||
[[Category:GBrowse]] | [[Category:GBrowse]] |
Revision as of 14:28, 5 May 2011
Contents
Proposal to convert gbrowse_details to an AJAX request handler
A temporary page to describe a low-impact change to existing code to provide a built-in ajax handler for Gbrowse
Examples
- A balloon hover with contents generated using an AJAX call to gbrowse_details and the params callback shown below
- A sticky balloon with contents generated from gbrowse-details (via an <iframe> element) and the default callback shown below.
Changes to gbrowse_details
- A new CGI parameter to invoke the AJAX-handling behavior
my $rmt = param('remote');
- A response is triggered after the feature(s) are defined but before PrintTop is called.
<perl>
if (defined $rmt) { print header,start_html; print remote_content($rmt,$features[0]); print end_html; exit 0; }
</perl>
- The remote_content subroutine will get the text or coderef. It will return the text or execute the callback with user-defined arguments
<perl>
# do something for popup balloons sub remote_content { my $key = shift; # the key for the text or code-ref in the gbrowse config file my $feat = shift; my $contents = $CONFIG->config->code_setting('TOOLTIPS',$key) or die "$key is empty"; my $coderef = (ref $contents||'') eq 'CODE'; return $contents unless $coderef; # paranoia? die "Error: $key is not a CODE-REF" if ref $contents && !$coderef; # args are user-defined my %args = (feature => $feat) if $feat; for my $arg (param()) { my @vals = param($arg); my $val = @vals > 1 ? \@vals : $vals[0]; $args{$arg} = $val; } return $contents->(\%args); }
</perl>
Changes To Configuration File
- A new section [TOOLTIPS] that has all the named text sections or callbacks you need to access through gbrowse_details
- NOTE: This section must be placed at the end of the [GENERAL] section.
- The [ORF] configuration stanza used to generate the images above. The relevant section is highlighted
Changes to Bio::Graphics::Browser
- Minimal changes to balloons code. Width option introduced to allow custom width constraints. Setting the iframe width should hopefully make the contents stay inside the balloon boundaries.