bgneal@312
|
1 /**
|
bgneal@312
|
2 * mctabs.js
|
bgneal@312
|
3 *
|
bgneal@312
|
4 * Copyright 2009, Moxiecode Systems AB
|
bgneal@312
|
5 * Released under LGPL License.
|
bgneal@312
|
6 *
|
bgneal@312
|
7 * License: http://tinymce.moxiecode.com/license
|
bgneal@312
|
8 * Contributing: http://tinymce.moxiecode.com/contributing
|
bgneal@312
|
9 */
|
bgneal@312
|
10
|
bgneal@312
|
11 function MCTabs() {
|
bgneal@312
|
12 this.settings = [];
|
bgneal@312
|
13 };
|
bgneal@312
|
14
|
bgneal@312
|
15 MCTabs.prototype.init = function(settings) {
|
bgneal@312
|
16 this.settings = settings;
|
bgneal@312
|
17 };
|
bgneal@312
|
18
|
bgneal@312
|
19 MCTabs.prototype.getParam = function(name, default_value) {
|
bgneal@312
|
20 var value = null;
|
bgneal@312
|
21
|
bgneal@312
|
22 value = (typeof(this.settings[name]) == "undefined") ? default_value : this.settings[name];
|
bgneal@312
|
23
|
bgneal@312
|
24 // Fix bool values
|
bgneal@312
|
25 if (value == "true" || value == "false")
|
bgneal@312
|
26 return (value == "true");
|
bgneal@312
|
27
|
bgneal@312
|
28 return value;
|
bgneal@312
|
29 };
|
bgneal@312
|
30
|
bgneal@312
|
31 MCTabs.prototype.displayTab = function(tab_id, panel_id) {
|
bgneal@312
|
32 var panelElm, panelContainerElm, tabElm, tabContainerElm, selectionClass, nodes, i;
|
bgneal@312
|
33
|
bgneal@312
|
34 panelElm= document.getElementById(panel_id);
|
bgneal@312
|
35 panelContainerElm = panelElm ? panelElm.parentNode : null;
|
bgneal@312
|
36 tabElm = document.getElementById(tab_id);
|
bgneal@312
|
37 tabContainerElm = tabElm ? tabElm.parentNode : null;
|
bgneal@312
|
38 selectionClass = this.getParam('selection_class', 'current');
|
bgneal@312
|
39
|
bgneal@312
|
40 if (tabElm && tabContainerElm) {
|
bgneal@312
|
41 nodes = tabContainerElm.childNodes;
|
bgneal@312
|
42
|
bgneal@312
|
43 // Hide all other tabs
|
bgneal@312
|
44 for (i = 0; i < nodes.length; i++) {
|
bgneal@312
|
45 if (nodes[i].nodeName == "LI")
|
bgneal@312
|
46 nodes[i].className = '';
|
bgneal@312
|
47 }
|
bgneal@312
|
48
|
bgneal@312
|
49 // Show selected tab
|
bgneal@312
|
50 tabElm.className = 'current';
|
bgneal@312
|
51 }
|
bgneal@312
|
52
|
bgneal@312
|
53 if (panelElm && panelContainerElm) {
|
bgneal@312
|
54 nodes = panelContainerElm.childNodes;
|
bgneal@312
|
55
|
bgneal@312
|
56 // Hide all other panels
|
bgneal@312
|
57 for (i = 0; i < nodes.length; i++) {
|
bgneal@312
|
58 if (nodes[i].nodeName == "DIV")
|
bgneal@312
|
59 nodes[i].className = 'panel';
|
bgneal@312
|
60 }
|
bgneal@312
|
61
|
bgneal@312
|
62 // Show selected panel
|
bgneal@312
|
63 panelElm.className = 'current';
|
bgneal@312
|
64 }
|
bgneal@312
|
65 };
|
bgneal@312
|
66
|
bgneal@312
|
67 MCTabs.prototype.getAnchor = function() {
|
bgneal@312
|
68 var pos, url = document.location.href;
|
bgneal@312
|
69
|
bgneal@312
|
70 if ((pos = url.lastIndexOf('#')) != -1)
|
bgneal@312
|
71 return url.substring(pos + 1);
|
bgneal@312
|
72
|
bgneal@312
|
73 return "";
|
bgneal@312
|
74 };
|
bgneal@312
|
75
|
bgneal@312
|
76 // Global instance
|
bgneal@312
|
77 var mcTabs = new MCTabs();
|