bgneal@312: /** bgneal@312: * mctabs.js bgneal@312: * bgneal@312: * Copyright 2009, Moxiecode Systems AB bgneal@312: * Released under LGPL License. bgneal@312: * bgneal@312: * License: http://tinymce.moxiecode.com/license bgneal@312: * Contributing: http://tinymce.moxiecode.com/contributing bgneal@312: */ bgneal@312: bgneal@312: function MCTabs() { bgneal@312: this.settings = []; bgneal@312: }; bgneal@312: bgneal@312: MCTabs.prototype.init = function(settings) { bgneal@312: this.settings = settings; bgneal@312: }; bgneal@312: bgneal@312: MCTabs.prototype.getParam = function(name, default_value) { bgneal@312: var value = null; bgneal@312: bgneal@312: value = (typeof(this.settings[name]) == "undefined") ? default_value : this.settings[name]; bgneal@312: bgneal@312: // Fix bool values bgneal@312: if (value == "true" || value == "false") bgneal@312: return (value == "true"); bgneal@312: bgneal@312: return value; bgneal@312: }; bgneal@312: bgneal@312: MCTabs.prototype.displayTab = function(tab_id, panel_id) { bgneal@312: var panelElm, panelContainerElm, tabElm, tabContainerElm, selectionClass, nodes, i; bgneal@312: bgneal@312: panelElm= document.getElementById(panel_id); bgneal@312: panelContainerElm = panelElm ? panelElm.parentNode : null; bgneal@312: tabElm = document.getElementById(tab_id); bgneal@312: tabContainerElm = tabElm ? tabElm.parentNode : null; bgneal@312: selectionClass = this.getParam('selection_class', 'current'); bgneal@312: bgneal@312: if (tabElm && tabContainerElm) { bgneal@312: nodes = tabContainerElm.childNodes; bgneal@312: bgneal@312: // Hide all other tabs bgneal@312: for (i = 0; i < nodes.length; i++) { bgneal@312: if (nodes[i].nodeName == "LI") bgneal@312: nodes[i].className = ''; bgneal@312: } bgneal@312: bgneal@312: // Show selected tab bgneal@312: tabElm.className = 'current'; bgneal@312: } bgneal@312: bgneal@312: if (panelElm && panelContainerElm) { bgneal@312: nodes = panelContainerElm.childNodes; bgneal@312: bgneal@312: // Hide all other panels bgneal@312: for (i = 0; i < nodes.length; i++) { bgneal@312: if (nodes[i].nodeName == "DIV") bgneal@312: nodes[i].className = 'panel'; bgneal@312: } bgneal@312: bgneal@312: // Show selected panel bgneal@312: panelElm.className = 'current'; bgneal@312: } bgneal@312: }; bgneal@312: bgneal@312: MCTabs.prototype.getAnchor = function() { bgneal@312: var pos, url = document.location.href; bgneal@312: bgneal@312: if ((pos = url.lastIndexOf('#')) != -1) bgneal@312: return url.substring(pos + 1); bgneal@312: bgneal@312: return ""; bgneal@312: }; bgneal@312: bgneal@312: // Global instance bgneal@312: var mcTabs = new MCTabs();