|
37 | 37 | {% endblock %} |
38 | 38 |
|
39 | 39 | {% 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 | + |
40 | 85 | <div class="row" ng-controller="rnaSequenceController"> |
41 | 86 | <div ng-if="fetchRnaError" class="col-md-12"> |
42 | 87 | <div class="alert alert-danger"> |
@@ -111,6 +156,15 @@ <h2> |
111 | 156 | </div> |
112 | 157 | {% endif %} |
113 | 158 |
|
| 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 | + |
114 | 168 | <div class="tabbable"> |
115 | 169 |
|
116 | 170 | <uib-tabset class="tab-animation" active="{{ context.active_tab }}"> |
@@ -321,20 +375,19 @@ <h2>Molecular Relationships</h2> |
321 | 375 | </uib-tab> |
322 | 376 |
|
323 | 377 | {% 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"> |
325 | 379 | <uib-tab-heading> |
326 | 380 | 2D structure |
327 | 381 | </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> |
338 | 391 | </uib-tab> |
339 | 392 | {% endif %} |
340 | 393 |
|
|
0 commit comments