-
AuthorPosts
-
August 18, 2016 at 9:19 pm #674355
Still no word on my other ticket (https://kriesi.at/support/topic/issues-with-css-class-targeting-in-firefox-and-edge/)
– I wonder with 45 copies of this theme if there is any premium support options?Anyway, I was wondering if you could investigate why the following isn’t working. I’m trying to use a combination of Javascript and CSS to achieve tabs. In the child theme directory I created a new folder called ‘js’ and in that folder a script called tabs.js with the following code…
var tabs = document.getElementById('tabs'); var ps = tabs.getElementsByTagName('p'); var p; var spans; var span; var w; var wTab = 180; for (var i = 0; i < ps.length; i++) { p = ps.item(i); spans = p.getElementsByTagName('span'); for (var j = 0; j < spans.length - 1; j++) { span = spans.item(j); w = span.offsetWidth; w = Math.ceil(w / wTab) * wTab - w; span.style.paddingRight = w + 'px'; } }
In the functions.php file I added…
wp_register_script( 'tabs', $template_url.'./js/tabs.js', 'jquery', "1", true); wp_enqueue_script( 'tabs' );
and then in the page I added in a text block…
<div id="tabs"> <p><span>Date 1</span><span>Event</span></p> <p><span>Date 2</span><span>Event</span></p> <p><span>Date 3</span><span>Event</span></p> </div>' Because the editor kept removing the span tags I also added the following to the bottom of the <strong>functions.php</strong> file...
function myextensionTinyMCE($init) {
// Command separated string of extended elements
$ext = ‘span[id|name|class|style]’;// Add to extended_valid_elements if it alreay exists
if ( isset( $init[‘extended_valid_elements’] ) ) {
$init[‘extended_valid_elements’] .= ‘,’ . $ext;
} else {
$init[‘extended_valid_elements’] = $ext;
}// Super important: return $init!
return $init;
}add_filter(‘tiny_mce_before_init’, ‘myextensionTinyMCE’ );`
August 22, 2016 at 1:29 pm #675705Hey lzevon,
Sorry for the late reply!
Josue already replied to your other thread.
Please change following code
to following one
function avia_enqueue_custom_js_file() { wp_enqueue_script( 'tabs', get_template_directory_uri() . '/js/tabs.js', 'jquery', '1', true ); } add_action( 'wp_enqueue_scripts', 'avia_enqueue_custom_js_file' );
Currently your file cannot be found
Best regards,
YigitAugust 23, 2016 at 4:14 pm #676503Still no luck – here’s what the FTP dir looks like
August 23, 2016 at 4:18 pm #676508Hi!
File still cannot be found. Do you mind posting FTP and WP admin logins here privately so we can look into it?
Best regards,
YigitAugust 23, 2016 at 4:42 pm #676533FTP is tricky for a number of reasons, but see below
August 23, 2016 at 5:10 pm #676555Hey!
I changed the code to following one
// Tabbed layout function avia_enqueue_custom_js_file() { wp_enqueue_script( 'tabs', get_stylesheet_directory_uri() . '/js/tabs.js', 'jquery', '1', true ); } add_action( 'wp_enqueue_scripts', 'avia_enqueue_custom_js_file' );
Now there is no error in console. Can you please check your website now
Best regards,
YigitAugust 23, 2016 at 5:27 pm #676565That’s it! Thank you – I will have to look closely to see what was missed, much appreciated :)
August 23, 2016 at 5:48 pm #676580 -
AuthorPosts
- The topic ‘adding new script’ is closed to new replies.