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