You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hello,
Not going to make a pull request. This is the code which I use with webpack.
JquerySmartTab.ts (this is the original js file, adjusted to webpack/typsecript)
/** * @link http://www.techlaboratory.net/jquery-smarttab * @description the logic provided in here is the original logic taken from the plugin * however some changes were provided so that it can work with the webpack * */exportdefaultclassJquerySmartTab{// volmarg - fix adding logic to initial callprivateinitialCall: boolean=true;privatedefaults={selected: 0,// Initial selected tab, 0 = first tabtheme: 'default',// theme for the tab, related css need to include for other than default themeorientation: 'horizontal',// Nav menu orientation. horizontal/verticaljustified: true,// Nav menu justification. true/falseautoAdjustHeight: true,// Automatically adjust content heightbackButtonSupport: true,// Enable the back button supportenableURLhash: true,// Enable selection of the tab based on url hashtransition: {animation: 'none',// Effect on navigation, none/fade/slide-horizontal/slide-vertical/slide-swingspeed: '400',// Transion animation speedeasing: ''// Transition animation easing. Not supported without a jQuery easing plugin},autoProgress: {// Auto navigate tabs on intervalenabled: false,// Enable/Disable Auto navigationinterval: 3500,// Auto navigate Interval (used only if "autoProgress" is enabled)stopOnFocus: true// Stop auto navigation on focus and resume on outfocus},keyboardSettings: {keyNavigation: true,// Enable/Disable keyboard navigation(left and right keys are used if enabled)keyLeft: [37],// Left key codekeyRight: [39]// Right key code}};privateoptions;privatemain;privatenav;privatetabs;privatecontainer;privatepages;privatecurrent_index;privateautoProgressId;_typeof(obj){"@babel/helpers - typeof";if(typeofSymbol==="function"&&typeofSymbol.iterator==="symbol"){this._typeof=function_typeof(obj){returntypeofobj;};}else{this._typeof=function_typeof(obj){returnobj&&typeofSymbol==="function"&&obj.constructor===Symbol&&obj!==Symbol.prototype ? "symbol" : typeofobj;};}returnthis._typeof(obj);}_classCallCheck(instance,Constructor){if(!(instanceinstanceofConstructor)){thrownewTypeError("Cannot call a class as a function");}}_defineProperties(target,props){for(vari=0;i<props.length;i++){vardescriptor=props[i];descriptor.enumerable=descriptor.enumerable||false;descriptor.configurable=true;if("value"indescriptor)descriptor.writable=true;Object.defineProperty(target,descriptor.key,descriptor);}}_createClass(Constructor,protoProps,staticProps){if(protoProps)this._defineProperties(Constructor.prototype,protoProps);if(staticProps)this._defineProperties(Constructor,staticProps);returnConstructor;}publicinitForElementAndOptions(element,options){// this._classCallCheck(this, this.initForElementAndOptions);// Merge user settings with defaultthis.options=$.extend(true,{},this.defaults,options);// Main container elementthis.main=$(element);// Navigation bar elementthis.nav=this._getFirstDescendant('.nav');// Tab anchor elementsthis.tabs=this.nav.find('.nav-link');// Content containerthis.container=this._getFirstDescendant('.tab-content');// Content pagesthis.pages=this.container.children('.tab-pane');// Active Tab indexthis.current_index=null;// Autoprogress timer idthis.autoProgressId=null;// Assign optionsthis._initOptions();// Initial loadthis._initLoad();}// Initial Load Methodprivate_initLoad(){// Clean the elementsthis.pages.hide();this.tabs.removeClass('active');// Get the initial tab indexvaridx=this._getTabIndex();// Show the initial tabthis._showTab(idx);}// Initialize optionsprivate_initOptions(){// Set the elementsthis._setElements();// Assign plugin eventsthis._setEvents();}private_getFirstDescendant(selector){// Check for first level elementvarelm=this.main.children(selector);if(elm.length>0){returnelm;}// Check for second level elementthis.main.children().each(function(i,n){vartmp=$(n).children(selector);if(tmp.length>0){elm=tmp;returnfalse;}});if(elm.length>0){returnelm;}// Element not foundthis._showError("Element not found "+selector);returnfalse;}private_setElements(){// Set the main elementthis.main.addClass('st');if(this.options.justified===true){this.main.addClass('st-justified');}else{this.main.removeClass('st-justified');}this._setTheme(this.options.theme);this._setOrientation(this.options.orientation);}private_setEvents(){var_this=this;// Check if event handler already existsif(this.main.data('click-init')){returntrue;}// Flag item to prevent attaching handler againthis.main.data('click-init',true);// Anchor click event$(this.tabs).on("click",function(e){e.preventDefault();_this._showTab(_this.tabs.index(e.currentTarget));});// Keyboard navigation eventif(this.options.keyboardSettings.keyNavigation){$(document).keyup(function(e){_this._keyNav(e);});}// Back/forward browser button eventif(this.options.backButtonSupport){$(window).on('hashchange',function(e){varidx=_this._getURLHashIndex();if(idx!==false){e.preventDefault();_this._showTab(idx);}});}if(this.options.autoProgress.enabled&&this.options.autoProgress.stopOnFocus){$(this.main).on("mouseover",function(e){e.preventDefault();_this._stopAutoProgress();});$(this.main).on("mouseleave",function(e){e.preventDefault();_this._startAutoProgress();});}}private_showNext(){varsi=0;// Find the next showable stepfor(vari=this.current_index+1;i<this.tabs.length;i++){if(this._isShowable(i)){si=i;break;}}this._showTab(si);}private_showPrevious(){varsi=this.tabs.length-1;// Find the previous showable stepfor(vari=this.current_index-1;i>=0;i--){if(this._isShowable(i)){si=i;break;}}this._showTab(si);}private_isShowable(idx){if(this.tabs.eq(idx).hasClass('disabled')||this.tabs.eq(idx).hasClass('hidden')){returnfalse;}returntrue;}private_showTab(idx){// If current tab is requested again, skipif(idx==this.current_index){returnfalse;}// If tab not found, skipif(!this.tabs.eq(idx)){returnfalse;}// If it is a disabled tab, skipif(!this._isShowable(idx)){returnfalse;}// Load tab contentthis._loadTab(idx);}private_loadTab(idx){var_this2=this;// Get current tab elementvarcurTab=this._getAnchor(this.current_index);if(this.current_index!==null){// Trigger "leaveTab" eventif(this._triggerEvent("leaveTab",[curTab,this.current_index])===false){returnfalse;}}// Get next tab elementvarselTab=this._getAnchor(idx);// Get the content if usedvargetTabContent=this._triggerEvent("tabContent",[selTab,idx]);if(getTabContent){if(_this2._typeof(getTabContent)=="object"){getTabContent.then(function(res){_this2._setTabContent(idx,res);_this2._transitTab(idx);})["catch"](function(err){console.error(err);_this2._setTabContent(idx,err);_this2._transitTab(idx);});}elseif(typeofgetTabContent=="string"){this._setTabContent(idx,getTabContent);this._transitTab(idx);}else{this._transitTab(idx);}}else{this._transitTab(idx);}}private_getAnchor(idx){if(idx==null){returnnull;}returnthis.tabs.eq(idx);}private_getPage(idx){if(idx==null){returnnull;}varanchor=this._getAnchor(idx);returnanchor.length>0 ? this.main.find(anchor.attr("href")) : null;}private_setTabContent(idx,html){varpage=this._getPage(idx);if(page){page.html(html);}}private_transitTab(idx){var_this3=this;// Get tab to show elementvarselTab=this._getAnchor(idx);// Change the url hash to new tabthis._setURLHash(selTab.attr("href"));// Update controlsthis._setAnchor(idx);// Animate the tabthis._doTabAnimation(idx,function(){// Fix height with content_this3._fixHeight(idx);// Trigger "showTab" event_this3._triggerEvent("showTab",[selTab,_this3.current_index]);// Restart auto progress if enabled_this3._restartAutoProgress();});// Update the current indexthis.current_index=idx;}private_doTabAnimation(idx,callback){var_this4=this;// Get current tab elementvarcurPage=this._getPage(this.current_index);// Get next tab elementvarselPage=this._getPage(idx);// Get the transition effectvartransitionEffect=this.options.transition.animation.toLowerCase();// Complete any ongoing animationsthis._stopAnimations();switch(transitionEffect){case'slide-horizontal':
case'slide-h':
// horizontal slidevarcontainerWidth=this.container.width();varcurLastLeft=containerWidth;varnextFirstLeft=containerWidth*-2;// Forward directionif(idx>this.current_index){curLastLeft=containerWidth*-1;nextFirstLeft=containerWidth;}// First load set the container widthif(this.current_index==null){this.container.height(selPage.outerHeight());}varcss_pos,css_left;if(curPage){css_pos=curPage.css("position");css_left=curPage.css("left");curPage.css("position",'absolute').css("left",0).animate({left: curLastLeft},this.options.transition.speed,this.options.transition.easing,function(){$(this).hide();curPage.css("position",css_pos).css("left",css_left);});}css_pos=selPage.css("position");css_left=selPage.css("left");selPage.css("position",'absolute').css("left",nextFirstLeft).outerWidth(containerWidth).show().animate({left: 0},this.options.transition.speed,this.options.transition.easing,function(){selPage.css("position",css_pos).css("left",css_left);callback();});break;case'slide-vertical':
case'slide-v':
// vertical slidevarcontainerHeight=this.container.height();varcurLastTop=containerHeight;varnextFirstTop=containerHeight*-2;// Forward directionif(idx>this.current_index){curLastTop=containerHeight*-1;nextFirstTop=containerHeight;}varcss_vpos,css_vtop;if(curPage){css_vpos=curPage.css("position");css_vtop=curPage.css("top");curPage.css("position",'absolute').css("top",0).animate({top: curLastTop},this.options.transition.speed,this.options.transition.easing,function(){$(this).hide();curPage.css("position",css_vpos).css("top",css_vtop);});}css_vpos=selPage.css("position");css_vtop=selPage.css("top");selPage.css("position",'absolute').css("top",nextFirstTop).show().animate({top: 0},this.options.transition.speed,this.options.transition.easing,function(){selPage.css("position",css_vpos).css("top",css_vtop);callback();});break;case'slide-swing':
case'slide-s':
// normal slideif(curPage){curPage.slideUp('fast',this.options.transition.easing,function(){selPage.slideDown(_this4.options.transition.speed,_this4.options.transition.easing,function(){callback();});});}else{selPage.slideDown(this.options.transition.speed,this.options.transition.easing,function(){callback();});}break;case'fade':
// normal fadeif(curPage){curPage.fadeOut('fast',this.options.transition.easing,function(){selPage.fadeIn('fast',_this4.options.transition.easing,function(){callback();});});}else{selPage.fadeIn(this.options.transition.speed,this.options.transition.easing,function(){callback();});}break;default:
if(curPage){curPage.hide();}selPage.show();callback();break;}}private_stopAnimations(){this.pages.finish();this.container.finish();};private_setAnchor(idx){this.tabs.eq(this.current_index).removeClass("active");this.tabs.eq(idx).addClass("active");}private_getTabIndex(){// Get selected tab from the urlvaridx=this._getURLHashIndex();returnidx===false ? this.options.selected : idx;}/** * @description here is the logic for handling animated height for wrapper - works good for modals, * but the issue is that when modal is being hidden the panel height is initially 0 */public_fixHeight(idx){// volmarg - fix first tab not being active, add animation later on here// Auto adjust height of the container// if (this.options.autoAdjustHeight) {// var selPage = this._getPage(idx);// console.log(selPage.outerHeight());//// this.container.finish().animate({// height: selPage.outerHeight()// }, this.options.transition.speed);// }}private_setTheme(theme){this.main.removeClass(function(index,className){return(className.match(/(^|\s)st-theme-\S+/g)||[]).join(' ');}).addClass('st-theme-'+theme);}private_setOrientation(orientation){this.main.removeClass('st-vertical st-horizontal').addClass('st-'+orientation);}// HELPER FUNCTIONSprivate_keyNav(e){// Keyboard navigationif($.inArray(e.which,this.options.keyboardSettings.keyLeft)>-1){// leftthis._showPrevious();e.preventDefault();}elseif($.inArray(e.which,this.options.keyboardSettings.keyRight)>-1){// rightthis._showNext();e.preventDefault();}else{return;// exit this handler for other keys}}// Auto progressprivate_startAutoProgress(){var_this5=this;if(this.options.autoProgress.enabled&&!this.autoProgressId){this.autoProgressId=setInterval(function(){return_this5._showNext();},this.options.autoProgress.interval);}}private_stopAutoProgress(){if(this.autoProgressId){clearInterval(this.autoProgressId);this.autoProgressId=null;}}private_restartAutoProgress(){this._stopAutoProgress();this._startAutoProgress();}private_triggerEvent(name,params){// Trigger an eventvare=$.Event(name);this.main.trigger(e,params);if(e.isDefaultPrevented()){returnfalse;}//@ts-ignorereturne.result;}private_setURLHash(hash){if(this.options.enableURLhash&&window.location.hash!==hash){history.pushState(null,null,hash);}}private_getURLHashIndex(){if(this.options.enableURLhash){// Get tab number from url hash if availablevarhash=window.location.hash;if(hash.length>0){varelm=this.nav.find("a[href*='"+hash+"']");if(elm.length>0){returnthis.tabs.index(elm);}}}returnfalse;}private_loader(action){switch(action){case'show':
this.main.addClass('st-loading');break;case'hide':
this.main.removeClass('st-loading');break;default:
this.main.toggleClass('st-loading');}}private_showError(msg){console.error(msg);}// PUBLIC FUNCTIONSprivategoToTab(tabIndex){this._showTab(tabIndex);}publicsetOptions(options){this.options=$.extend(true,{},this.options,options);this._initOptions();}publicloader(state){if(state==="show"){this.main.addClass('st-loading');}else{this.main.removeClass('st-loading');}}}
SmartTab.ts (in this file I call the adjusted jquery-smarttab)
/** * @description will initialize the smart tab for given dom element * * @param htmlElement * @private */privateinitializeForHtmlElement(htmlElement: HTMLElement): void{let jquerySmartTab =newJquerySmartTab();let$element=$(htmlElement);jquerySmartTab.initForElementAndOptions($element,{selected : this.DEFAULT_ACTIVE_TAB,// Initial selected tab, 0 = first tab (self: note - not working, first tab is always active but that's fine),theme : 'github',// theme for the tab, related css need to include for other than default themeorientation : 'horizontal',// Nav menu orientation. horizontal/verticaljustified : true,// Nav menu justification. true/falseautoAdjustHeight : true,// Automatically adjust content heightbackButtonSupport : true,// Enable the back button supportenableURLhash : true,// Enable selection of the tab based on url hashtransition: {animation : 'none',// Effect on navigation, none/fade/slide-horizontal/slide-vertical/slide-swingspeed : '400',// Transion animation speedeasing :''// Transition animation easing. Not supported without a jQuery easing plugin},autoProgress: {// Auto navigate tabs on intervalenabled : false,// Enable/Disable Auto navigationinterval : 3500,// Auto navigate Interval (used only if "autoProgress" is set to true)stopOnFocus : true,// Stop auto navigation on focus and resume on outfocus},keyboardSettings: {keyNavigation : false,// Enable/Disable keyboard navigation(left and right keys are used if enabled)}});}
The text was updated successfully, but these errors were encountered:
Hello,
Not going to make a pull request. This is the code which I use with webpack.
JquerySmartTab.ts (this is the original js file, adjusted to webpack/typsecript)
SmartTab.ts (in this file I call the adjusted jquery-smarttab)
The text was updated successfully, but these errors were encountered: