Bootstrap tabs not switching in Wordpress - wordpress

I am trying to use Bootstrap Tabs in my wordpress project. I can see the tabs in the browser window but the tabs are not switching.
Here is the code I am using. The tabs are basically the example from the Bootstrap docs which are repeated in many places in stackoverflow. However in my Wordpress project they still don't switch.
function jrtrs_add_bootstrap(){
$src = plugin_dir_url( __FILE__ ) . 'css/bootstrap.min.css';
wp_register_style('trs_bootstrap-style', $src);
wp_enqueue_style('trs_bootstrap-style');
}
// Add js scripts
function jrtrs_add_scripts(){
wp_enqueue_script('jquery');
wp_enqueue_script('nav-tabs', plugin_dir_url( __FILE__ ) . 'js/bootstrap-tab.js', array('jquery'));
wp_enqueue_script( 'tracking-settings-ajax-request', plugin_dir_url( __FILE__ ) . 'js/tracking-settings.js', array('jquery'));
}
add_action('wp_print_scripts', 'jrtrs_add_scripts');
add_shortcode('ms_betfair_plugin', 'jrtrs_display_form');
function jrtrs_display_form() {
jrtrs_add_bootstrap();
$htmlStr = <<<EOD
<!-------->
<div id="content">
<ul id="tabs" class="nav nav-tabs" data-tabs="tabs">
<li class="active">Red</li>
<li>Orange</li>
<li>Yellow</li>
<li>Green</li>
<li>Blue</li>
</ul>
<div id="my-tab-content" class="tab-content">
<div class="tab-pane active" id="red">
<h1>Reeeeeeeeed</h1>
<p>red red red red red red</p>
</div>
<div class="tab-pane" id="orange">
<h1>Orange</h1>
<p>orange orange orange orange orange</p>
</div>
<div class="tab-pane" id="yellow">
<h1>Yellow</h1>
<p>yellow yellow yellow yellow yellow</p>
</div>
<div class="tab-pane" id="green">
<h1>Green</h1>
<p>green green green green green</p>
</div>
<div class="tab-pane" id="blue">
<h1>Blue</h1>
<p>blue blue blue blue blue</p>
</div>
</div>
</div>
EOD;
return $htmlStr;
}
... and the JavaScript ....
jQuery(document).ready(function () {
jQuery('#tabs a').click(function (e) {
//alert("tab clicked");
e.preventDefault();
jQuery(this).tab('show');
})
});

I think you are misunderstanding something. You should not have to write any jQuery at all to make the bootstrap tabs work. It should work as soon as you drop in the html.
My best guess is that there is a javascript error.
As a trouble-shooting task, I would recommend downloading and including the full bootstrap.js rather than just bootstrap-tab.js.

Related

How to add forward back and refresh buttons for webviews in Electronjs?

I am displaying multiple webview contents using Electron Js.
part of index.html
<div class="contentArea">
<div id="mySidebar" class="leftMenu">
<ul id="myTab" class="nav nav-tabs">
<li class="nav-item">
Tab1
</li>
<li class="nav-item">
Tab2
</li>
<li class="nav-item">
Tab3
</li>
</ul>
</div>
<div class="contentPages tab-content">
<div class="tab-pane show active" id="webview1">
<webview src="link1" style="width:100%; height:100%" disablewebsecurity allowpopups></webview>
</div>
<div class="tab-pane" id="webview2">
<webview src="link2" style="width:100%; height:100%" disablewebsecurity allowpopups></webview>
</div>
<div class="tab-pane" id="webview3">
<webview src="link3" style="width:100%; height:100%" disablewebsecurity allowpopups></webview>
</div>
<script>
$(document).ready(function () {
$('a[data-toggle="tab"]').on('shown.bs.tab', function (e) {
var activeTab = $(e.target).text(); // Get the name of active tab
var previousTab = $(e.relatedTarget).text(); // Get the name of previous tab
$(".active-tab span").html(activeTab);
$(".previous-tab span").html(previousTab);
});
});
</script>
</div>
</div>
I used bootstrap and jquery for design.
Navigation between webviews works very nicely with jquery.
I'm trying to do. Creating forward, backward and refresh buttons for each webview.
It's like an internet browser.
I didn't manage to use the codes properly in ElectronJS.
Can anyone who knows about this please help?
It's Work.
$(document).on( 'click', '#back-button-id', function(){
if(webview-id.canGoToOffset(-1)){
webview-id.goBack();
} });
$(document).on( 'click', '#next-button-id', function(){
if(webview-id.canGoToOffset(+1)){
webview-id.goForward();
} });

How to make iDangerous Swiper works on Wordpress

I'm learning to use Swiper Sldier in a website using wordpress and Divi theme. I also try to follow a previous thread as a guide.
After following the instruction, the slider does not work, the imgage stuck at the left screen and it does not move as I drag them.
Here is the code on functions.php
/** Function SSwiper **/
function swiper_magic() {
wp_enqueue_script('swiper','https://cdnjs.cloudflare.com/ajax/libs/Swiper/4.5.0/js/swiper.min.js', array ('jquery'));
}
add_action( 'wp_enqueue_scripts', 'my_scripts_method' );
add_action( 'wp_enqueue_scripts', 'swiper_magic' );
On my header:
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/Swiper/4.5.0/css/swiper.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/Swiper/4.5.0/css/swiper.min.css">
<script src="https://cdnjs.cloudflare.com/ajax/libs/Swiper/4.5.0/js/swiper.min.js"></script>
<script>
$(document).ready(function(){
var mySwiper = new Swiper('.swiper-container',{
pagination: '.pagination',
loop:true,
grabCursor: true,
paginationClickable: true
})
jQuery('.arrow-left').on('click', function(e){
e.preventDefault()
mySwiper.swipePrev()
})
jQuery('.arrow-right').on('click', function(e){
e.preventDefault()
mySwiper.swipeNext()
})
})
</script>
And this is my HTML
<div class="device">
<a class="arrow-left" href="#"></a>
<a class="arrow-right" href="#"></a>
<div class="swiper-container">
<div class="swiper-wrapper">
<div class="swiper-slide"> <img src="/images/slider1-1.png"> </div>
<div class="swiper-slide"> <img src="/images/slider1-2.png"> </div>
<div class="swiper-slide">
<div class="content-slide">
<p class="title">Slide with HTML</p>
<p>You can put any HTML inside of slide with any layout, not only images, even another Swiper!</p>
</div>
</div>
</div>
</div>
<div class="pagination"></div>
</div>
I don't know why it did not work.
Any help or general suggestions would be greatly appreciated...
Base on swiper demos, I suggest to put your script at the bottom. To work with swiper arrow button the easiest way are:
var swiper = new Swiper('.swiper-container', {
navigation: {
nextEl: '.swiper-button-next',
prevEl: '.swiper-button-prev',
},
pagination: {
el: '.swiper-pagination',
},
});
And your html would be:
<div class="swiper-container">
<div class="swiper-wrapper">
<div class="swiper-slide">Slide 1</div>
<div class="swiper-slide">Slide 2</div>
<div class="swiper-slide">Slide 3</div>
</div>
<!-- Add Arrows -->
<div class="swiper-button-next"></div>
<div class="swiper-button-prev"></div>
<!-- Add Pagination -->
<div class="swiper-pagination"></div>
</div>
Then, if you want to run the callback. Simply use:
swiper.on('slideChange', function () {
console.log('slide changed');
});
slideChange are the event depend how do you want to run the callback. See full swiper event and method
Use this for your php function
function swiper_magic() {
wp_enqueue_script('swiper','https://cdnjs.cloudflare.com/ajax/libs/Swiper/4.5.0/js/swiper.min.js', array ('jquery'), true); // true to load at the bottom after jquery
}
add_action( 'wp_enqueue_scripts', 'swiper_magic' );
Hope this help! ;)

Foundation 6 Wordpress theme

I am trying to add some animation to the mobile navigation to drop down slowly rather than have the page jumping. I am using the foundationpress theme. I can't seem to make it work with data-animate. This is my code snippet:
<div class="title-bar" data-responsive-toggle="site-navigation">
<button class="menu-icon" data-toggle="panel" type="button" data-toggle="mobile-menu"></button>
<div class="title-bar-title">
<div class="mini-logo">
<img class="mini-logo-img" src="/wp-content/uploads/2016/11/coc-logo.png" alt="Mountain View" style="width:4rem;height:auto;">
</div>
<!--<?php bloginfo( 'name' ); ?>-->
</div>
</div>
<!--<nav id="site-navigation" class="main-navigation nav-area" role="navigation" style="width:100%" >-->
<div class="top-bar-left">
<ul class="menu">
<li class="co-logo-top"></li>
<!--<li class="home"><?php bloginfo( 'name' ); ?></li>-->
</ul>
</div>
<div class="top-bar-right" >
<?php foundationpress_top_bar_r(); ?>
<?php if ( ! get_theme_mod( 'wpt_mobile_menu_layout' ) || get_theme_mod( 'wpt_mobile_menu_layout' ) === 'topbar' ) : ?>
<?php get_template_part( 'template-parts/mobile-top-bar' ); ?>
<?php endif; ?>
</div>
</nav>
I'm not seeing the actual '#mobile-menu' component in your code snippet, so not 100% sure what's happening here, but the thing to be aware of is that you need to have the data-animate attribute on the same element as you have your data-toggler attribute (which in this case is the thing being toggled, or '#mobile-menu'). See the example here: http://foundation.zurb.com/sites/docs/toggler.html#toggle-with-animation
have you tried triggering it with jquery/js? see this thread: https://github.com/olefredrik/FoundationPress/issues/772.
also check that you have added the data-toggler attribute to the element

Bootstrap 2 accordion menu collapse

I'm using bootstrap 2 to build a wordpress theme with a collapsable menu, and everything works fine, however the open item doesn't close when I click a new item in the menu. any idea?
The php can be disregarded :) Thanks.
PS: When I tested with pure html it worked just fine
<div class="accordion-group">
<div class="accordion-heading"><?=$catItem->name;?></div>
<div id="<?=$catItem->slug;?>" class="accordion-body collapse">
<div class="accordion-inner">
<div id="<?=$generalActiveMenu;?>1" class="accordion">
<? $subCategory = new $Category();
$subCategory->getCategoryList($catItem->term_id); /* get sub category of each product */
foreach($subCategory->catList as $key => $subCatItem) {
?><div class="accordion-group">
<div class="accordion-heading">
<?=$subCatItem->name;?>
</div>
<div id="<?=$subCatItem->slug;?>" class="accordion-body collapse">
<? if(get_posts('category_name='.$subCatItem->slug)) {
?><div class="accordion-inner">
<ul class="nav nav-list">
<? $Post->postCat = $subCatItem->term_id;
$Post->getPostList();
foreach ($Post->postList as $key => $postItem) {
?><li id="<?=$postItem->post_name;?>"><?=$postItem->post_title;?></li><?
} ?>
</ul>
</div><?
} ?>
</div>
</div><?
}
?>
</div>
</div>
</div>
</div>
I may be wrong but you could try:
$('#myAccordianTab').collapse({
toggle: true
})
Take a look at this link for more info:
http://getbootstrap.com/2.3.2/javascript.html#collapse
This should help you build up correctly and and explains the toggle(or collapsing) function

Slider won't work in IE8

I'm currently building a website but I noticed the slider doesn't work in IE8. When I click on the compatibility mode button it does work.
It shows some strangely misplaced divs when I viewed in IE8. I recently built in Pie for the rounded corners to work in IE8; maybe that's the problem with the slider?
Is there anyone that can help me?
Here's the code :)
<div class="slider-container">
<div id="slideshow">
<div>
<div class="caption rc">
<div class="caption-text">
<?php perch_content('tekst slide 1'); ?>
</div>
</div>
<img src="img/slider.jpg" alt="Slide">
</div>
<div>
<div class="caption rc">
<div class="caption-text">
<?php perch_content('tekst slide 2'); ?>
</div>
</div>
<img src="img/slider-2.jpg" alt="Slide">
</div>
<div>
<div class="caption rc">
<div class="caption-text">
<?php perch_content('tekst slide 3'); ?>
</div>
</div>
<img src="img/slider-3.jpg" alt="Slide">
</div>
<div>
<div class="caption rc">
<div class="caption-text">
<?php perch_content('tekst slide 4'); ?>
</div>
</div>
<img src="img/slider-4.jpg" alt="Slide">
</div>
</div>
</div>
And here:
$(function() {
$("#slideshow > div:gt(0)").hide();
setInterval(function() {
$('#slideshow > div:first')
.fadeOut(1000)
.next()
.fadeIn(1000)
.end()
.appendTo('#slideshow');
}, 6000);
});
The strange thing is that it will work in compatibility mode, but not in normal mode, in IE8 and in Firefox, Chrome, and Safari it's working fine.
You are using a cdn, sometimes there is trouble loading cdn files...
Try adding a fallback script to load jquery from your local server.
Add this after your jquery script from google cdn in the header and modify your path.
<script type="text/javascript">
if (typeof jQuery == 'undefined') {
document.write(unescape("%3Cscript src='path to jquery libary' type='text/javascript'%3E%3C/script%3E"));
}
</script>
Hope this helps
regards

Resources