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