Skip to content

Commit bfc3269

Browse files
committed
updated so component only initialises when the tab is clicked
1 parent c4ff981 commit bfc3269

File tree

1 file changed

+64
-11
lines changed

1 file changed

+64
-11
lines changed

rnacentral/portal/templates/portal/sequence.html

Lines changed: 64 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,51 @@
3737
{% endblock %}
3838

3939
{% block content %}
40+
<script type="text/javascript">
41+
// Initialize 2D tab activation state - wait for Angular to load
42+
(function() {
43+
function initializeScope() {
44+
// Check if Angular is available
45+
if (typeof angular === 'undefined') {
46+
setTimeout(initializeScope, 50);
47+
return;
48+
}
49+
50+
var element = document.querySelector('[ng-controller="rnaSequenceController"]');
51+
if (!element) {
52+
setTimeout(initializeScope, 50);
53+
return;
54+
}
55+
56+
var scope = angular.element(element).scope();
57+
if (!scope) {
58+
setTimeout(initializeScope, 50);
59+
return;
60+
}
61+
62+
scope.$apply(function() {
63+
// Check if we're loading with tab=2d parameter
64+
// Check URL for tab parameter
65+
var urlParams = new URLSearchParams(window.location.search);
66+
var tabParam = urlParams.get('tab');
67+
scope.is2dTabActivated = (tabParam === '2d');
68+
69+
// Function to activate 2D tab
70+
scope.activate2dTab = function() {
71+
scope.is2dTabActivated = true;
72+
};
73+
});
74+
}
75+
76+
// Start trying to initialize when DOM is ready
77+
if (document.readyState === 'loading') {
78+
document.addEventListener('DOMContentLoaded', initializeScope);
79+
} else {
80+
initializeScope();
81+
}
82+
})();
83+
</script>
84+
4085
<div class="row" ng-controller="rnaSequenceController">
4186
<div ng-if="fetchRnaError" class="col-md-12">
4287
<div class="alert alert-danger">
@@ -111,6 +156,15 @@ <h2>
111156
</div>
112157
{% endif %}
113158

159+
{% if rna.has_secondary_structure %}
160+
<!-- Load r2dt-web script early to prevent rendering errors -->
161+
{% if request.get_host == 'test.rnacentral.org' or request.get_host == 'localhost:8000' %}
162+
<script type="text/javascript" src="{% static "r2dt-web/dist/r2dt-web.js" %}"></script>
163+
{% else %}
164+
<script type="text/javascript" src="https://rnacentral.github.io/r2dt-web/dist/r2dt-web.js"></script>
165+
{% endif %}
166+
{% endif %}
167+
114168
<div class="tabbable">
115169

116170
<uib-tabset class="tab-animation" active="{{ context.active_tab }}">
@@ -321,20 +375,19 @@ <h2>Molecular Relationships</h2>
321375
</uib-tab>
322376

323377
{% if rna.has_secondary_structure %}
324-
<uib-tab index="3" id="secondary-structures" deselect="checkTab($event, $selectedIndex)" ng-if="taxid">
378+
<uib-tab index="3" id="secondary-structures" select="activate2dTab()" deselect="checkTab($event, $selectedIndex)" ng-if="taxid">
325379
<uib-tab-heading>
326380
2D structure
327381
</uib-tab-heading>
328-
<r2dt-web
329-
search='{"urs": "{{ context.upi }}"}'
330-
customStyle='{"fixCss": "true", "titleColor": "#BF8E3E"}'
331-
/>
332-
333-
{% if request.get_host == 'test.rnacentral.org' or request.get_host == 'localhost:8000' %}
334-
<script type="text/javascript" src="{% static "r2dt-web/dist/r2dt-web.js" %}"></script>
335-
{% else %}
336-
<script type="text/javascript" src="https://rnacentral.github.io/r2dt-web/dist/r2dt-web.js"></script>
337-
{% endif %}
382+
<div ng-if="is2dTabActivated">
383+
<r2dt-web
384+
search='{"urs": "{{ context.upi }}"}'
385+
customStyle='{"fixCss": "true", "titleColor": "#BF8E3E"}'
386+
/>
387+
</div>
388+
<div ng-if="!is2dTabActivated">
389+
<p>Loading 2D structure...</p>
390+
</div>
338391
</uib-tab>
339392
{% endif %}
340393

0 commit comments

Comments
 (0)