Skip to content

Adding a refresh function #130

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions examples/demo.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<title>EasyTabs Demo</title>
<script src="../vendor/jquery-1.7.1.min.js" type="text/javascript"></script>
<script src="../vendor/jquery.hashchange.min.js" type="text/javascript"></script>
<script src="../lib/jquery.easytabs.min.js" type="text/javascript"></script>
<script src="../lib/jquery.easytabs.js" type="text/javascript"></script>

<style>
/* Example Styles for Demo */
Expand Down Expand Up @@ -104,6 +104,14 @@ <h2>CSS Styles for these tabs</h2>
</div>
</div>
</div>

<button class='test'>Add a tab</button>
<script type='text/javascript'>
$(function() {
$("button").click(function() {
var newTab = $("<li class='tab'><a href='#tabs4-test'>New tab</a></li>").appendTo($(".etabs"));
var newTabPane = $("<div id='tabs4-test'>Test</div>").appendTo($(".panel-container"));
$("#tab-container").easytabs("refresh");
});
});</script>
</body>
</html>
23 changes: 19 additions & 4 deletions lib/jquery.easytabs.js
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,9 @@
halfSpeed: 0
};
};
plugin.destroy = function() {
plugin.tabs.children("a").unbind(settings.bind_str);
};

// Find and instantiate tabs and panels.
// Could be used to reset tab and panel collection if markup is
Expand All @@ -151,7 +154,7 @@
plugin.tabs = $container.find(settings.tabs),

// Instantiate panels as empty jquery object
plugin.panels = $(),
plugin.panels = plugin.panels || $(),

plugin.tabs.each(function(){
var $tab = $(this),
Expand All @@ -162,7 +165,7 @@
// `data-target` attribute for ajax tabs since the `href` is
// the ajax URL
targetId = $tab.children('a').data('target');

if ($tab.data("easytabs") !== undefined) return;
$tab.data('easytabs', {});

// If the tab has a `data-target` attribute, and is thus an ajax tab
Expand Down Expand Up @@ -344,6 +347,15 @@

// Convenient public methods
plugin.publicMethods = {
refresh: function() {
plugin.getTabs();
addClasses();

setDefaultTab();

bindToTabClicks();

},
select: function(tabSelector){
var $tab;

Expand Down Expand Up @@ -470,7 +482,9 @@
// Bind tab-select funtionality to namespaced click event, called by
// init
var bindToTabClicks = function() {
plugin.tabs.children("a").bind(settings.bind_str, function(e) {
plugin.tabs.children("a").each(function() {
if ($(this).data("easytab-cycled")) return;
$(this).bind(settings.bind_str, function(e) {

// Stop cycling when a tab is clicked
settings.cycle = false;
Expand All @@ -485,7 +499,8 @@
// Don't follow the link to the anchor
e.preventDefault ? e.preventDefault() : e.returnValue = false;
});
};
});
}

// Activate a given tab/panel, called from plugin.selectTab:
//
Expand Down