Viewing 8 posts - 1 through 8 (of 8 total)
  • Author
    Posts
  • #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’ );`

    #675705

    Hey 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,
    Yigit

    #676503

    Still no luck – here’s what the FTP dir looks like

    #676508

    Hi!

    File still cannot be found. Do you mind posting FTP and WP admin logins here privately so we can look into it?

    Best regards,
    Yigit

    #676533

    FTP is tricky for a number of reasons, but see below

    #676555

    Hey!

    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,
    Yigit

    #676565

    That’s it! Thank you – I will have to look closely to see what was missed, much appreciated :)

    #676580

    Hey!

    You are welcome! Let us know if you have any other questions or issues.

    Regards,
    Yigit

Viewing 8 posts - 1 through 8 (of 8 total)
  • The topic ‘adding new script’ is closed to new replies.