Sha256: 09c7042f7c341e299422d2bf11031381ba633e13e696506e9f25f21aa857eedb

Contents?: true

Size: 1.51 KB

Versions: 2

Compression:

Stored size: 1.51 KB

Contents

// Simple, unobtrusive tab widget
// Written by Daniel Mendler
(function($) {
    $.fn.tabWidget = function(options) {
        var store = options && options.store;
	var selected = null;

        // Handle tab clicks
	$("> a[href^='#']", this).click(function() {
	    if (selected.data('tab') == $(this).data('tab')) {
		return false;
	    }
	    if (!selected.data('tab').confirmUnsaved()) {
		return false;
	    }
	    selected.data('tab').hide();
	    selected.parent().removeClass('selected');
	    selected = $(this);
	    selected.data('tab').show();
	    selected.parent().addClass('selected');
	    if (store) {
		$.storage.set(store, selected.data('tab').attr('id'));
	    }
	    return false;
	});

        // Get selected tab from store
	if (store) {
	    var name = $.storage.get(store);
	    if (name) {
                selected = $("> a[href='#" + name + "']", this);
	    }
	}

        // Get selected tab by class
	if (!selected || selected.size() === 0) {
            selected = $(this).filter('.selected').find("> a[href^='#']");
	}

        // Select first tab
        if (!selected || selected.size() === 0) {
            selected = $(this).filter(':first').find("> a[href^='#']");
	}

        // Find all tabs and hide them
	$("> a[href^='#']", this).each(function() {
	    var tab = $(this.href.match(/(#.*)$/)[1]);
	    tab.hide();
	    $(this).data('tab', tab);
	});

	// Show initially selected tab
	this.removeClass('selected');
	selected.parent().addClass('selected');
	selected.data('tab').show();
    };
})(jQuery);

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
olelo-0.9.5 static/script/14-olelo.tabwidget.js
olelo-0.9.4 static/script/13-olelo.tabwidget.js