Skip to content

Commit f7b3ea6

Browse files
author
jralph
committed
Added complete callback option.
1 parent 7d5173f commit f7b3ea6

File tree

2 files changed

+40
-7
lines changed

2 files changed

+40
-7
lines changed

README.md

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,10 @@ Below you will find a list of the available settings for the plugin.
9494
inAnimation: 'show',
9595
outAnimation: 'hide',
9696
speed: 200,
97-
activeClass: 'tab-active'
97+
activeClass: 'tab-active',
98+
complete: function(element, tab) {
99+
// code to run on tab click complete
100+
}
98101
}
99102
```
100103

@@ -122,6 +125,15 @@ The class to add to the currently active tab link. This should not contain a `.`
122125

123126
This could be set to `active`, `current-tab`, or any other class of your choice.
124127

128+
### complete ###
129+
130+
The callback function to run just after a tab link has been clicked and the tab loaded. This should always be a function, and the function can accept the paramaters
131+
of `element` and `tab`.
132+
133+
The `element` is the link element that was clicked on.
134+
135+
The `tab` is the tab element that has been shown.
136+
125137
Setting Example
126138
---------------
127139

@@ -167,7 +179,11 @@ even a data attribute, such as data-tabs.
167179
inAnimation: 'fadeIn',
168180
outAnimation: 'fadeOut',
169181
speed: 250,
170-
activeClass: 'current-tab'
182+
activeClass: 'current-tab',
183+
complete: function(element, tab) {
184+
console.log(element); // Would output the jQuery element for the data-tab clicked.
185+
console.log(tab); // Would output the jQuery element for the data-tab-content shown.
186+
}
171187
});
172188
});
173189
</script>
@@ -180,7 +196,5 @@ Future Additions
180196
----------------
181197

182198
- ~~Addd `active` or `tab-active` class to currently open tab link and tab.~~
183-
- Add oncomplete callback option.
184-
- Add `on` option to set what to open the tab on. (eg, click, mouseover, custom event ect.)
199+
- ~~Add oncomplete callback option.~~
185200
- ~~Add `minified` version of `tabs.js`~~
186-
- Add `on` delay time. (eg, delay for 200ms before loading new tab on hover.)

tabs.js

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,10 @@
3131
inAnimation: 'show',
3232
outAnimation: 'hide',
3333
speed: 200,
34-
activeClass: 'tab-active'
34+
activeClass: 'tab-active',
35+
complete: function(element, tab) {
36+
37+
}
3538
};
3639

3740
/**
@@ -110,12 +113,26 @@
110113
var _this = this;
111114
$(this.element).each(function() {
112115
$(this).click(function() {
113-
_this.runClick(this);
116+
var tab = _this.runClick(this);
117+
_this.runComplete(this, tab);
114118
return false;
115119
});
116120
});
117121
};
118122

123+
/**
124+
* Run the complete callback when a click has been registered and the
125+
* tab has been shown.
126+
* @param {object} element The element clicked on.
127+
* @param {object} tab The tab being loaded.
128+
* @return {void}
129+
*/
130+
tabs.prototype.runComplete = function(element, tab) {
131+
if (jQuery.isFunction(this.options.complete)) {
132+
this.options.complete(element, tab);
133+
}
134+
};
135+
119136
/**
120137
* Method to run when the click event is fired.
121138
* @param {object} element The element clicked on.
@@ -129,6 +146,8 @@
129146

130147
this.hideOpen(tab);
131148
this.showTab(tab);
149+
150+
return tab;
132151
};
133152

134153
/**

0 commit comments

Comments
 (0)