export default function TabSwitcher(tabBar, defaultView) { this.tabBar = tabBar; var defaultTab = $('
', { 'class': 'tab', text: '3D View' }); this.defaultViewHandle = new ViewHandle(defaultView, defaultTab); defaultTab.click(() => { this.defaultViewHandle.show(this); }); this.tabBar.append(defaultTab); this.markSelected(defaultTab); this.detachedViews = {}; } function idToName(id) { var match = /\$+$/.exec(id); if (match == null) return id; var beenCraftedTimes = match[0].length; function to27Base(n) { if (n == 0) return ""; var rad = n % 27; return to27Base(Math.floor(n / 27)) + String.fromCharCode(65 + rad); } return id.replace(/\$+$/, '') + to27Base(beenCraftedTimes); } TabSwitcher.prototype.showSketch = function(sketchURL, sketchId) { var tab = this.tabBar.find('[data-sketch-id="'+sketchId+'"]'); var detachedView = this.detachedViews[sketchId]; if (detachedView !== undefined) { if (!detachedView.closed) { detachedView.focus(); return; } else { delete this.detachedViews[sketchId]; } } if (tab.length == 0) { tab = $('
', {'class': 'tab', text : 'Sketch ' + idToName(sketchId)}) .append(' ') .append($('', {'class': 'fa fa-expand expand'})) .append(' ') .append($('', {'class': 'fa fa-close close'})); tab.attr('data-sketch-id', sketchId); var url = "sketcher.html#" + sketchURL; var view = $('
', {'class': 'app-tab-view'}) .append($('