WordPress core jQuery messes UI tabs
-
Hello!
I’m developing a WordPress based page, running X-Theme. On my page I have jQuery-UI tabs that are misbehaving badly on mobile devices. On desktop browsers I’ve noticed only one problem. Selecting a tab would scroll the page to the tab content. This problem was solved by:
$('#tabs').click('tabsselect', function (event, ui) { $('html, body').stop(); });
However, on mobile devices problems were:
– tapping on active tab would still scroll to content
– almost impossible to select another tab (I had to tap more times in order to find where on tab it accepts a touch)
– tapping on disabled tab would scroll the page a bit (more like stutter)I thought there was a problem in my code so I tried to test it on a clean page, tabs only. Everything worked fine. I’ve tested all the logic for disable/enable tabs also, everything I’ve used in original code. Then it hits me that this new page is not made in WordPress and that I’ve loaded jQuery from Google’s CDN (jQuery UI as well).
Then I decided to test original site in WP, but this time with jQuery from Google CDN. In my child theme functions.php I’ve removed original jQuery (used someone’s suggestion form stackoverflow, can’t remember which post):
function load_jquery() { if ( ! is_admin() ) { wp_deregister_script('jquery'); wp_register_script('jquery', '', FALSE, '1.11.3'); wp_enqueue_script('jquery'); } } add_action('template_redirect', 'load_jquery');
and loaded CDN version in my template:
wp_register_script( 'jquery-custom-core', '//ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js', false ); wp_enqueue_script( 'jquery-custom-core' );
Also had to register jquery-migrate.min.js. I’ve tested this on mobile and it worked! Tabs are behaving as expected.
Now, my questions are:
1. Why this happens with WP core jQuery (I did read somewhere that WP-jQuery has some changes compared to source jQuery)?
2. What impact will my solution have on whole page (plugins, theme, etc.)? I can see that X-theme is loading 2 scripts that are dependent on jQuery before jQuery loads, but I will deal with this further if there is no other workaround for this topics problem.
3. Is there a better way to solve this problem?
- The topic ‘WordPress core jQuery messes UI tabs’ is closed to new replies.