2 /*******************************************************************************
3 * Copyright (c) 2012-2013 University of Stuttgart.
4 * All rights reserved. This program and the accompanying materials
5 * are made available under the terms of the Eclipse Public License v1.0
6 * and the Apache License 2.0 which both accompany this distribution,
7 * and are available at http://www.eclipse.org/legal/epl-v10.html
8 * and http://www.apache.org/licenses/LICENSE-2.0
11 * Oliver Kopp - initial API and implementation and/or initial documentation
12 *******************************************************************************/
15 function switchStyledTabSelection(element, onSuccess) {
16 target = element.attr("href");
17 target = target.replace('#','');
19 $(".styledTabMenuButton2ndlevel").removeClass("selected");
20 element.addClass("selected");
21 $("#ccontainer").html('<div id="loading" style="display:none;">loading...</div>');
22 $("#loading").fadeIn(3000);
23 $("#ccontainer").load(target, function(response, status, xhr) {
24 if (status == "error") {
25 vShowError("Could not load tab content: " + xhr.status + " " + xhr.statusText);
35 * @param onSuccess called if subTabs are available and the super tab could be loaded
37 function doTheTabSelection(onSuccess) {
38 var hash = window.location.hash;
40 // get rid of ";" additions
41 var posColon = hash.indexOf(";");
44 subTab = hash.substr(posColon + 1);
45 hash = hash.substr(0, posColon);
48 if ($.inArray(hash, ${param.validpages}) == -1) {
49 hash = "${param.defaultpage}";
52 var callBack = onSuccess;
54 var posColon = subTab.indexOf(";");
56 // more information added, for instance xmltree data
57 // the first part is the subtab
58 subTab = subTab.substr(0, posColon);
60 callBack = function () {
61 $('#myTab a[href="#' + subTab + '"]').tab('show');
68 switchStyledTabSelection($(".styledTabMenuButton2ndlevel[href='" + hash + "']"), callBack);
71 // Firefox does not fire the "popstate" event at the first load,
73 // Because of Firefox, we have to call the refresh here
76 // see http://blog.mgm-tp.com/2011/10/must-know-url-hashtechniques-for-ajax-applications/ for a broad discussion
77 $(window).on("hashchange", function(e) {
78 if (internalHashChange) {
80 internalHashChange = false;
82 // we have to check whether only additional data changed and thus no real change is required
83 var oldURL = e.originalEvent.oldURL;
84 var idx = oldURL.indexOf("#");
86 var oldHash = oldURL.substr(idx);
87 var newURL = e.originalEvent.newURL;
88 // get the hash value only
89 idx = newURL.indexOf("#");
91 var newHash = newURL.substr(idx);
92 // search for the first ";"
93 idx = oldHash.indexOf(";");
95 // search for the second ";"
96 idx = oldHash.indexOf(";", idx+1);
98 // The new hash is only a refinement of the old hash:
99 // Only a new ";" has been added
100 // We do not need to reload
103 if (oldHash.substr(0, idx) == newHash.substr(0, idx)) {
104 // the two hashes equal until the second ";"
105 // we don't have to do any reload
113 // switch to the new tab
118 var internalHashChange = false;
120 $(document).on('shown.bs.tab', "ul.nav-tabs > li > a", function (e) {
121 var id = $(e.target).attr("href").substr(1);
122 var hash = window.location.hash;
123 var additionalData = "";
124 var posColon = hash.indexOf(";");
126 // search for additionalData
127 secondColon = hash.indexOf(";", posColon+1);
128 if (secondColon > 0) {
129 // include the ";" in the additional data
130 additionalData = hash.substr(secondColon);
133 // wipe everything after the colon
134 hash = hash.substr(0, posColon);
136 hash = hash + ";" + id + additionalData;
137 internalHashChange = true;
138 window.location.hash = hash;