Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var app = app || {};
- (function() {
- function DynamicTab(el) {
- this.createBounds();
- this.el = el;
- this.homeDiscoverTab = this.el.find('.discover-nav-list');
- this.homeDiscoverTabNavHover = this.el.find('.nbm-item');
- this.homeDiscoverTabNav = this.homeDiscoverTab.find('li');
- this.homeDiscoverDynamic = this.el.find('.dynamic-content');
- this.init();
- }
- DynamicTab.prototype.init = function () {
- var that = this;
- this.homeDiscoverTabNav.on('click', function (e) {
- e.preventDefault();
- var elem = $(this);
- that.homeDiscoverTabNavHover.removeClass('selected');
- that.homeDiscoverTab.not(this).removeClass('selected');
- that.homeDiscoverTabNavHover.eq(elem.index()).addClass('selected');
- elem.addClass('selected');
- that.getHomeDiscoverData(elem);
- })
- }
- DynamicTab.prototype.getHomeDiscoverData = function (el) {
- var that = this;
- var formData = new FormData();
- formData.set('action', 'tab_discover_home');
- formData.set('post_type', el.data('posttype'));
- formData.set('post_id', el.parent().data('postid'));
- axios({
- method: 'post',
- url: crowdAjax,
- data: formData,
- config: {headers: {'Content-Type': 'multipart/form-data'}}
- }).then(function (response) {
- that.homeDiscoverDynamic.html(response.data);
- }).catch(function (response) {
- console.log('Error Home Discover tab:' + response);
- });
- }
- DynamicTab.prototype.destroy = function () {
- //destroy events
- this.homeDiscoverTabNav.off('click');
- }
- DynamicTab.prototype.createBounds = function () {
- var that = this;
- ['init', 'destroy', 'getHomeDiscoverData']
- .forEach(function (fn) {
- that[fn] = that[fn].bind(that)
- });
- }
- app.DynamicTab = DynamicTab;
- })();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement