/** * cbpViewModeSwitch.js v1.0.0 * http://www.codrops.com * * Licensed under the MIT license. * http://www.opensource.org/licenses/mit-license.php * * Copyright 2013, Codrops * http://www.codrops.com */ (function() { var container = $('#cbp-vm'), optionSwitch = $('div.cbp-vm-options > a' ); function init() { optionSwitch.on('click', function(e){ e.preventDefault(); _switch($(this)); }); /* optionSwitch.each( function(i) { $(this).on('click', function(e){ e.preventDefault(); _switch(this); }); } ); */ } function _switch( opt ) { // remove other view classes and any any selected option optionSwitch.each(function() { container.removeClass($(this).attr('data-view')); $(this).removeClass('cbp-vm-selected'); }); // add the view class for this option container.addClass(opt.attr('data-view')); // this option stays selected opt.addClass('cbp-vm-selected'); $(window).resize(); } init(); })();