Панель инструментов редактора отсутствует из-за пользовательского файла JS - PullRequest
0 голосов
/ 11 мая 2018

Я добавил собственный файл js cr-scroll.js для карусели на домашней странице.после добавления панель инструментов редактора страницы пропала.Если я удаляю этот js-файл, то все работает нормально.

В чем проблема с этим js-файлом?Любая помощь будет оценена.Заранее спасибо.

РЕДАКТИРОВАТЬ:

Я добавил скрипт с этим кодом:

wp_register_script('java1', get_template_directory_uri() . '/js/cr-scroll.js?version=4.2', array( 'jquery' ));
wp_enqueue_script( 'java1' );

Мой CS-scroll.js:

var $k = jQuery.noConflict();
(function($k){
$k(document).ready(function($k) {
 $k.fn.make_carousel = function() {
    var speed = 0;
    var scroll = 0;
    var con = $k(this);
    var con_w = con.width();
    var max_scroll = con[0].scrollWidth - con.outerWidth();
    var prev_frame = new Date().getTime();
    con.on('mousemove', function(e) {
        var mouse_x = e.pageX - con.offset().left;
        var mouseperc = 100 * mouse_x / con_w;
        speed = mouseperc - 50;
    }).on ( 'mouseleave', function() {
        speed = 0;
    });

    function updatescroll() {
        var cur_frame = new Date().getTime();
        var time_elapsed = cur_frame - prev_frame;
        prev_frame = cur_frame;
        if (speed !== 0) {
            scroll += speed * time_elapsed / 50;
            if (scroll < 0) scroll = 0;
            if (scroll > max_scroll) scroll = max_scroll;
            con.scrollLeft(scroll);
        }
        window.requestAnimationFrame(updatescroll);
    }
    window.requestAnimationFrame(updatescroll);
}

$k("#carousel1").make_carousel();
$k("#carousel2").make_carousel();

function reset(){
    $k('.maincontent').find('*').removeAttr('class');
    document.getElementById('step1').setAttribute("class", "visible");
}
function back(){
    var previous_class = $k('.visible').data('previous');
    if(previous_class != ''){
        var current_class = $k('.visible').attr('id');
        document.getElementById(current_class).setAttribute("class","");
        document.getElementById(previous_class).setAttribute("class","visible");
    }
}
function show_next(current,next) {
    document.getElementById(current).setAttribute("class", "hidden");
    document.getElementById(next).setAttribute("class", "visible");
}

function show_hide(show_ele,hide_ele) {
    document.getElementById(show_ele).style.display = "block";
    document.getElementById(hide_ele).style.display = "none";
}
function load_after_sec(id) {
    count = 0;
    wordsArray = ["5", "4", "3", "2", "1"];
    var timerID = setInterval(function () {
        count++;
        if(count == 5){
            $k("#"+id).show();
            $k("#seconds_counter").hide();
            clearInterval(timerID);
        } else {
            $k("#num_sec").fadeOut(400, function () {
                $k(this).text(wordsArray[count % wordsArray.length]).fadeIn(400);
            });
        }                               
    }, 2000);
}
function showButton(){
    document.getElementById("btn_repeat").style.display='block';
}
});
})(jQuery);

Этот раздел имеет полную ширину, но после включения js он входит во внутренний класс с определенной шириной.

1 Ответ

0 голосов
/ 11 мая 2018

кажется, вы не использовали wp_enqueue_scripts.добавьте этот код в functions.php и попробуйте.

    function custom_scripts() {
        wp_register_script('java1', get_template_directory_uri() . '/js/cr-scroll.js', array( 'jquery' ));
        wp_enqueue_script( 'java1' );
    }
    add_action( 'wp_enqueue_scripts', 'custom_scripts' );
...