Created
September 14, 2011 18:55
-
-
Save fat/1217433 to your computer and use it in GitHub Desktop.
tabs with history support
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* ======================================================== | |
* bootstrap-tabs.js v1.3.0 | |
* http://twitter.github.com/bootstrap/javascript.html#tabs | |
* ======================================================== | |
* Copyright 2011 Twitter, Inc. | |
* | |
* Licensed under the Apache License, Version 2.0 (the "License"); | |
* you may not use this file except in compliance with the License. | |
* You may obtain a copy of the License at | |
* | |
* http://www.apache.org/licenses/LICENSE-2.0 | |
* | |
* Unless required by applicable law or agreed to in writing, software | |
* distributed under the License is distributed on an "AS IS" BASIS, | |
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
* See the License for the specific language governing permissions and | |
* limitations under the License. | |
* ======================================================== */ | |
(function( $ ){ | |
function activate ( element, container ) { | |
container.find('.active').removeClass('active') | |
element.addClass('active') | |
} | |
function tab( e ) { | |
var $this = $(this) | |
, href = $this.attr('href') | |
, $ul = $(e.liveFired) | |
, $controlled | |
if (/^#\w+/.test(href)) { | |
e.preventDefault() | |
location.href = location.href.replace(/#.*/,'') + href | |
if ($this.hasClass('active')) { | |
return | |
} | |
$href = $(href) | |
activate($this.parent(), $ul) | |
activate($href, $href.parent()) | |
} | |
} | |
/* TABS/PILLS PLUGIN DEFINITION | |
* ============================ */ | |
$.fn.tabs = $.fn.pills = function ( selector ) { | |
return this.each(function () { | |
$(this).delegate(selector || '.tabs li > a, .pills > li > a', 'click', tab) | |
}) | |
} | |
$(function () { | |
$('body').tabs('ul[data-tabs] li > a, ul[data-pills] > li > a') | |
}) | |
// Hashchange support for all modern browsers, and ie8+ | |
// Integrate Ben Alman's hashchange plugin for ie6-7 support | |
// http://goo.gl/7ezFB | |
var url = location.href | |
$(window).bind('load hashchange', function () { | |
var $target = $(".tab-content :target, .pill-content :target") | |
, $tab | |
, href | |
if ($target.length) { | |
href = '#' + $target.attr('id') | |
$tab = $('.tabs a[href=' + href + '], .pills a[herf=' + href + ']') | |
activate($tab.parent(), $tab.parents('ul:first')) | |
activate($target, $target.parent()) | |
} else if (url == location.href){ | |
activate($('.tabs li:first, .pills li:first'), $('.tabs, .pills')) | |
activate($('.tab-content :first, .pill-content :first'), $('.tab-content, .pill-content')) | |
} | |
}) | |
})( jQuery || ender ) |
ender build jquery ;)
also, we do support $.fn - https://github.com/ender-js/ender-js/blob/master/ender.js#L63
edit -- not sure if that works actually ...
i know we have $.fn
-- i added it :p. the purpose was so that Ender modules could have jQuery compat without having to define the fn
object. and usually at the end of your method you would say something like....
$.ender($.fn, true)
did you see my pull request? that seems easier
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This will only work with jQuery since ender doesnt support the
$.fn
syntax, nor the$(fn)
style of domReady