SHARE
TWEET

Untitled

a guest Jun 18th, 2019 51 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. var app = app || {};
  2.  
  3. (function() {
  4.     function DynamicTab(el) {
  5.         this.createBounds();
  6.         this.el = el;
  7.         this.homeDiscoverTab = this.el.find('.discover-nav-list');
  8.         this.homeDiscoverTabNavHover = this.el.find('.nbm-item');
  9.         this.homeDiscoverTabNav = this.homeDiscoverTab.find('li');
  10.         this.homeDiscoverDynamic = this.el.find('.dynamic-content');
  11.  
  12.         this.init();
  13.     }
  14.  
  15.     DynamicTab.prototype.init = function () {
  16.         var that = this;
  17.  
  18.         this.homeDiscoverTabNav.on('click', function (e) {
  19.             e.preventDefault();
  20.             var elem = $(this);
  21.  
  22.             that.homeDiscoverTabNavHover.removeClass('selected');
  23.             that.homeDiscoverTab.not(this).removeClass('selected');
  24.  
  25.             that.homeDiscoverTabNavHover.eq(elem.index()).addClass('selected');
  26.             elem.addClass('selected');
  27.  
  28.             that.getHomeDiscoverData(elem);
  29.         })
  30.     }
  31.  
  32.     DynamicTab.prototype.getHomeDiscoverData = function (el) {
  33.         var that = this;
  34.  
  35.         var formData = new FormData();
  36.         formData.set('action', 'tab_discover_home');
  37.         formData.set('post_type', el.data('posttype'));
  38.         formData.set('post_id', el.parent().data('postid'));
  39.  
  40.         axios({
  41.             method: 'post',
  42.             url: crowdAjax,
  43.             data: formData,
  44.             config: {headers: {'Content-Type': 'multipart/form-data'}}
  45.         }).then(function (response) {
  46.             that.homeDiscoverDynamic.html(response.data);
  47.         }).catch(function (response) {
  48.             console.log('Error Home Discover tab:' + response);
  49.         });
  50.     }
  51.  
  52.     DynamicTab.prototype.destroy = function () {
  53.         //destroy events
  54.         this.homeDiscoverTabNav.off('click');
  55.     }
  56.  
  57.     DynamicTab.prototype.createBounds = function () {
  58.         var that = this;
  59.         ['init', 'destroy', 'getHomeDiscoverData']
  60.             .forEach(function (fn) {
  61.                 that[fn] = that[fn].bind(that)
  62.             });
  63.     }
  64.  
  65.     app.DynamicTab = DynamicTab;
  66. })();
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top