Why is my Javascript function only working a few times?

My sandbox is here: http://9.latest.truxmap.appspot.com/

First click on the marker on the map (if not, when the page loads, check the box next to "Soon to be sold by trucks" in the navigation widgets). Then go to the Reviews tab.

In GWT, every time I open a marker, I call the javascript function resizeReviewTab (), which fixes the styling problem that arises because the content on the status and overview tabs is dynamic. If Javascript worked, you’ll see STARS, not radio buttons, floating directly above the text area on the Reviews tab. Otherwise, you will see simple switches.

I cannot understand what happens when the DOESNT token opens correctly. How could he work once, and then again, and then work again after several different markers? Here's a function called:

function resizeReviewTab(){ 

    $('#content').text(""); 

    $('.statusWindowB').css('height', $('.statusWindowA').css('height'));                   

    $('.name-sliding').focus(function() {

        $('.name-label-sliding').animate({ marginLeft: "133px" }, "fast");

            if($(this).val() == "name")
                $(this).val() == "";

        }).blur(function() {

            if($(this).val() == "") {
                $(this).val() == "name";
                $('.name-label-sliding').animate({ marginLeft: "12px" }, "fast");
            }
        });     

    $('.content-sliding').focus(function() {
            $('.content-label-sliding').fadeOut("slow");
    });

    starify();  
} 

starify () is javascript for the jquery.stars jQuery plugin with a few changes visible here: http://9.latest.truxmap.appspot.com/lib/jquery.rating.js

I need to call this function, because if I just load it at the beginning of the html document, none of the information windows created by clicking on the map will ever have their own switches in the stars.

This is pretty annoying, I look forward to your answers. Thank!

+3
source share
3

, @amurra @meouw, . , OP, , GWT SelectionChangedHandler TWICE, , - , , , . javascript , , . !

+1

if($(this).val() == "name")
    // next line is checking whether val equals ""
    // we already know it equals "name"
    // so it returns false(which is discarded)
    $(this).val() == ""; "name" ,

if($(this).val() == "") {
    // next line is checking whether val equals "name"
    // we already know it equals ""
    // so it returns false(which is discarded)
    $(this).val() == "name";
    $('.name-label-sliding').animate({ marginLeft: "12px" }, "fast");
}

,

if($(this).val() == "name")
    $(this).val(''); // sets val to nothing

if($(this).val() == "") {
    $(this).val("name"); // sets val to "name"
    $('.name-label-sliding').animate({ marginLeft: "12px" }, "fast");
}
+2

, , . , .

function resizeReviewTab(){ 

$('#content').text(""); 

$('.statusWindowB').css('height',$('.statusWindowA').css('height'));                   

$('.name-sliding').unbind("focus").focus(function() {

    $('.name-label-sliding').animate({ marginLeft: "133px" }, "fast");

        if($(this).val() == "name")
            $(this).val() == "";

    }).unbind("blur").blur(function() {

        if($(this).val() == "") {
            $(this).val() == "name";
            $('.name-label-sliding').animate({ marginLeft: "12px" }, "fast");
        }
    });     

$('.content-sliding').unbind("focus").focus(function() {
        $('.content-label-sliding').fadeOut("slow");
});

starify();  

}

0
source

Source: https://habr.com/ru/post/1765084/


All Articles