开发者

Ok, can you spot a syntax error here?

Eclipse is givign me a syntax error along these lines but I don't see anything wrong there:

$('.addNewFolder').click(function() {
    showModal('modal_div', 'Nový adresár');
    var id = '<?php echo ToHtml($idFolder); ?>';
    $('.folders .trow1').each(function() {
        if ($(this).css('backgroundColor') == 'rgb(52, 108, 182)' || $(this).css('backgroundColor') == '#346cb6') {
            id = $(this).attr('rel');
        }
    });
    ajaxElementCall('modal_div', 'body/obsah/obrazy/folderAdd.php?idFolder='+id);
});

After PHP parsing:

$('.addNewFolder').click(function() {
    showModal('modal_div', 'Nový adresár');
    var id = '';
    $('.folders .trow1').each(function() {
        if ($(this).css('backgroundColor') == 'rgb(52, 108, 182)' || $(this).css('backgroundColor') == '#346cb6') {
            id = $(this).attr('rel');
        }
    });
    ajaxElementCall('modal_div', 'body/obsah/obrazy/folderAdd.php?idFolder='+id);
});

This is what IDE says:

Syntax error on token "}", invalid MethodHeaderName

I've been staring at that code for at least half an hour. I am either blind or going crazy.

EDIT:

The whole javascript on the page:

<script type="text/javascript">
    //<!--
$(document).ready(function() {

    function in_array (needle, haystack, argStrict) {
        var key = '', strict = !!argStrict; 
        if (strict) {
            for (key in haystack) {
                if (haystack[key] === needle) {
                    return true;            }
            }
        } else {
            for (key in haystack) {
                if (haystack[key] == needle) {
                    return true;
                }
            }
        }
         return false;
    }

    var openedFolders = new Array();
    <?php if (count($_SESSION['ECM']['openedSlideFolders']) > 0) : ?>
    <?php $i = 0; foreach ($_SESSION['ECM']['openedSlideFolders'] as $aVal): ?>
        <?php echo "openedFolders[$i] = '$aVal';\n"; ?>
    <?php ++$i; endforeach; ?>
    <?php endif; ?>

    var start = 0;
    var stop = 0;
    $('.drag').each(function() {
        var draggables = $(this).parents('table').find('.drag');
        var $next = draggables.filter(':gt(' + draggables.index(this) + ')').first();
        var width = $(this).css('width');
        var nextWidth = $next.css('width');
        if (nextWidth > width && 30 == parseInt(width)) {
            $(this).removeClass('ordinaryFolderClosed');
            $(this).removeClass('ordin开发者_JAVA百科aryFolderOpened');
            if (in_array($(this).attr('rel'), openedFolders)) {
                $(this).addClass('ordinaryFolderOpened');
            } else {
                $(this).addClass('ordinaryFolderClosed');
            }               
        }
        if (in_array($(this).attr('rel'), openedFolders)) {
            start = 1;
        }
        if (1 == start && stop < 2) {               
            if (30 == parseInt(width)) {
                stop++;
            }
        } else {
            start = 0;
            stop = 0;
            if (parseInt(width) > 30) {
                $(this).parent().parent().hide();
            }
        }
    });

    function dragDrop()
    {
        $('.folders .trow1').hover(
            function () {
                if ($(this).css('backgroundColor') != 'rgb(52, 108, 182)' && $(this).css('backgroundColor') != '#346cb6') {
                    $(this).css('background', "#C2E3EF");
                }
            },
            function () {
                if ($(this).css('backgroundColor') != 'rgb(52, 108, 182)' && $(this).css('backgroundColor') != '#346cb6') {
                    $(this).css('background', 'transparent');   
                }
            }
        );

        $('.drag').click(function() {
            var draggables = $(this).parents('table').find('.drag');
            var $next = draggables.filter(':gt(' + draggables.index(this) + ')').first();
            var width = $(this).css('width');
            var nextWidth = $next.css('width');
            if (nextWidth > width && 30 == parseInt(width)) {
                var isVisible = $next.is(':visible');
                if (isVisible) {
                    $(this).removeClass('ordinaryFolderClosed');
                    $(this).removeClass('ordinaryFolderOpened');
                    $(this).addClass('ordinaryFolderClosed');
                } else {
                    $(this).removeClass('ordinaryFolderClosed');
                    $(this).removeClass('ordinaryFolderOpened');
                    $(this).addClass('ordinaryFolderOpened');
                }
                clickedId = $(this).attr('rel');
                $.ajax({
                    type:    'POST',
                    url:     'body/obsah/obrazy/setOpenedFolder.php',
                    data:    'id='+clickedId,
                    success: function(msg){
                        //alert(msg);
                    }
                });
                var start = 0;
                var stop = 0;
                var i = 0;
                $('.drag').each(function() {
                    if (0 == start) {
                        iteratedId = $(this).attr('rel');
                        if (iteratedId == clickedId) {
                            start = 1;
                        }
                    }
                    if (1 == start && stop < 2) {
                        if ($(this).css('width') > width) {
                            if (isVisible) {
                                $(this).parent().parent().hide();
                            } else {
                                $(this).parent().parent().show();
                            }                           
                        } else {
                            stop++;
                        }
                    }
                    i++;
                });
            }
        }); 

        var dragId = 0;
        var dropId = 0;
        var isFile = false;

        $('.drag').mousedown(function() {
            if ($(this).attr('rel') !== undefined) {
                dragId = $(this).attr('rel');
                dragId = dragId.split(',');
                dragId = dragId[0];
            }
            isFile = false;
        });

        $('.drag2').mousedown(function() {
            if ($(this).attr('rel') !== undefined) {
                dragId = $(this).attr('rel');
                dragId = dragId.split(',');
                dragId = dragId[0];
            }
            isFile = true;
        }); 

        $('.drag').draggable({ 
            revert: true,
            cursorAt: {top: 0, left: 0}
        });

        $('.drag2').draggable({
            revert: true,
            cursorAt: {top: 0, left: 0}
        });


        $('.drop').droppable({
            tolerance: 'pointer',
            drop: function() {
                if ($(this).attr('rel') !== undefined) {
                    dropId = $(this).attr('rel');
                    dropId = dropId.split(',');
                    dropId = dropId[0];
                    if (dropId != dragId) {
                        if (false == isFile) {
                            $.ajax({
                                type:    'POST',
                                url:     'body/obsah/obrazy/folderMove.php',
                                data:    'nid='+dragId+'&pid='+dropId,
                                success: function(msg){
                                    <?php echo $aJsOnDrop; ?>;
                                    dragDrop();
                                }
                            });
                        } else if (true == isFile) {
                            $.ajax({
                                type:    'POST',
                                url:     'body/obsah/obrazy/slideMove.php',
                                data:    'fid='+dragId+'&did='+dropId,
                                success: function(msg){
                                    <?php echo $aJsOnDrop; ?>;
                                    dragDrop();
                                }
                            });
                        }
                    }
                }           
            }
        });

    }

    dragDrop();

    $('.folderListOnclick').click(function() {
        var append = 'idFolder='+$(this).attr('rel')+'&browse=<?php echo $browse; ?>';
        ajaxElementCall('obrazy_list', '<?php echo $dirPrefixBody; ?>/listBase.php?'+append);
        dragDrop();
        $('.trow1').css('background', 'transparent');
        $('.trow1').css('color', '#3e4245');
        $(this).parent().css('background', "#346cb6 url('img/menuButtonOver.png') left top repeat-x");
        $(this).parent().css('color', 'white');
    });

    $('.rootFolderListOnclick').click(function() {
        window.location = 'navigator.php?kam=obrazy';
        dragDrop();
    });

    $('.folderEditOnclick').click(function() {
        var append = 'idFolder='+$(this).attr('rel');
        showModal('modal_div', 'Editácia adresára'); 
        ajaxElementCall('modal_div', '<?php echo $dirPrefixBody; ?>/folderEdit.php?kam=edit1&'+append);
    });

    $('.folderDeleteOnclick').click(function() {
        var append = 'idFolder='+$(this).attr('rel');
        showModal('modal_div', 'Vymazanie adresára'); 
        // TODO 0 Nemam sajnu, aka chyba je tuna - Eclipse mi tu hadze syntax error
        ajaxElementCall('modal_div', '<?php echo $dirPrefixBody; ?>/folderDelete.php?kam=del1&'+append);
    });

    $('.addNewFolder').click(function() {
        showModal('modal_div', 'Nový adresár');
        var id = '<?php echo ToHtml($idFolder); ?>';
        $('.folders .trow1').each(function() {
            if ($(this).css('backgroundColor') == 'rgb(52, 108, 182)' || $(this).css('backgroundColor') == '#346cb6') {
                id = $(this).attr('rel');
            }
        });
        ajaxElementCall('modal_div', 'body/obsah/obrazy/folderAdd.php?idFolder='+id);
    });

});    //-->
</script>

After PHP parsing:

<script type="text/javascript">
    //<!--
$(document).ready(function() {

    function in_array (needle, haystack, argStrict) {
        var key = '', strict = !!argStrict; 
        if (strict) {
            for (key in haystack) {
                if (haystack[key] === needle) {
                    return true;            }
            }
        } else {
            for (key in haystack) {
                if (haystack[key] == needle) {
                    return true;
                }
            }
        }
         return false;
    }

    var openedFolders = new Array();
                openedFolders[0] = '3';

    var start = 0;
    var stop = 0;
    $('.drag').each(function() {
        var draggables = $(this).parents('table').find('.drag');
        var $next = draggables.filter(':gt(' + draggables.index(this) + ')').first();
        var width = $(this).css('width');
        var nextWidth = $next.css('width');
        if (nextWidth > width && 30 == parseInt(width)) {
            $(this).removeClass('ordinaryFolderClosed');
            $(this).removeClass('ordinaryFolderOpened');
            if (in_array($(this).attr('rel'), openedFolders)) {
                $(this).addClass('ordinaryFolderOpened');
            } else {
                $(this).addClass('ordinaryFolderClosed');
            }               
        }
        if (in_array($(this).attr('rel'), openedFolders)) {
            start = 1;
        }
        if (1 == start && stop < 2) {               
            if (30 == parseInt(width)) {
                stop++;
            }
        } else {
            start = 0;
            stop = 0;
            if (parseInt(width) > 30) {
                $(this).parent().parent().hide();
            }
        }
    });

    function dragDrop()
    {
        $('.folders .trow1').hover(
            function () {
                if ($(this).css('backgroundColor') != 'rgb(52, 108, 182)' && $(this).css('backgroundColor') != '#346cb6') {
                    $(this).css('background', "#C2E3EF");
                }
            },
            function () {
                if ($(this).css('backgroundColor') != 'rgb(52, 108, 182)' && $(this).css('backgroundColor') != '#346cb6') {
                    $(this).css('background', 'transparent');   
                }
            }
        );

        $('.drag').click(function() {
            var draggables = $(this).parents('table').find('.drag');
            var $next = draggables.filter(':gt(' + draggables.index(this) + ')').first();
            var width = $(this).css('width');
            var nextWidth = $next.css('width');
            if (nextWidth > width && 30 == parseInt(width)) {
                var isVisible = $next.is(':visible');
                if (isVisible) {
                    $(this).removeClass('ordinaryFolderClosed');
                    $(this).removeClass('ordinaryFolderOpened');
                    $(this).addClass('ordinaryFolderClosed');
                } else {
                    $(this).removeClass('ordinaryFolderClosed');
                    $(this).removeClass('ordinaryFolderOpened');
                    $(this).addClass('ordinaryFolderOpened');
                }
                clickedId = $(this).attr('rel');
                $.ajax({
                    type:    'POST',
                    url:     'body/obsah/obrazy/setOpenedFolder.php',
                    data:    'id='+clickedId,
                    success: function(msg){
                        //alert(msg);
                    }
                });
                var start = 0;
                var stop = 0;
                var i = 0;
                $('.drag').each(function() {
                    if (0 == start) {
                        iteratedId = $(this).attr('rel');
                        if (iteratedId == clickedId) {
                            start = 1;
                        }
                    }
                    if (1 == start && stop < 2) {
                        if ($(this).css('width') > width) {
                            if (isVisible) {
                                $(this).parent().parent().hide();
                            } else {
                                $(this).parent().parent().show();
                            }                           
                        } else {
                            stop++;
                        }
                    }
                    i++;
                });
            }
        }); 

        var dragId = 0;
        var dropId = 0;
        var isFile = false;

        $('.drag').mousedown(function() {
            if ($(this).attr('rel') !== undefined) {
                dragId = $(this).attr('rel');
                dragId = dragId.split(',');
                dragId = dragId[0];
            }
            isFile = false;
        });

        $('.drag2').mousedown(function() {
            if ($(this).attr('rel') !== undefined) {
                dragId = $(this).attr('rel');
                dragId = dragId.split(',');
                dragId = dragId[0];
            }
            isFile = true;
        }); 

        $('.drag').draggable({ 
            revert: true,
            cursorAt: {top: 0, left: 0}
        });

        $('.drag2').draggable({
            revert: true,
            cursorAt: {top: 0, left: 0}
        });


        $('.drop').droppable({
            tolerance: 'pointer',
            drop: function() {
                if ($(this).attr('rel') !== undefined) {
                    dropId = $(this).attr('rel');
                    dropId = dropId.split(',');
                    dropId = dropId[0];
                    if (dropId != dragId) {
                        if (false == isFile) {
                            $.ajax({
                                type:    'POST',
                                url:     'body/obsah/obrazy/folderMove.php',
                                data:    'nid='+dragId+'&pid='+dropId,
                                success: function(msg){
                                    ajaxElementCall('__folderList', 'body/obsah/obrazy/folders.php?browse=0&idFolder=', 'obrazy_list', 'body/obsah/obrazy/listBase.php?browse=0&idFolder=');
                                    dragDrop();
                                }
                            });
                        } else if (true == isFile) {
                            $.ajax({
                                type:    'POST',
                                url:     'body/obsah/obrazy/slideMove.php',
                                data:    'fid='+dragId+'&did='+dropId,
                                success: function(msg){
                                    ajaxElementCall('__folderList', 'body/obsah/obrazy/folders.php?browse=0&idFolder=', 'obrazy_list', 'body/obsah/obrazy/listBase.php?browse=0&idFolder=');
                                    dragDrop();
                                }
                            });
                        }
                    }
                }           
            }
        });

    }

    dragDrop();

    $('.folderListOnclick').click(function() {
        var append = 'idFolder='+$(this).attr('rel')+'&browse=0';
        ajaxElementCall('obrazy_list', 'body/obsah/obrazy/listBase.php?'+append);
        dragDrop();
        $('.trow1').css('background', 'transparent');
        $('.trow1').css('color', '#3e4245');
        $(this).parent().css('background', "#346cb6 url('img/menuButtonOver.png') left top repeat-x");
        $(this).parent().css('color', 'white');
    });

    $('.rootFolderListOnclick').click(function() {
        window.location = 'navigator.php?kam=obrazy';
        dragDrop();
    });

    $('.folderEditOnclick').click(function() {
        var append = 'idFolder='+$(this).attr('rel');
        showModal('modal_div', 'Editácia adresára'); 
        ajaxElementCall('modal_div', 'body/obsah/obrazy/folderEdit.php?kam=edit1&'+append);
    });

    $('.folderDeleteOnclick').click(function() {
        var append = 'idFolder='+$(this).attr('rel');
        showModal('modal_div', 'Vymazanie adresára'); 
        // TODO 0 Nemam sajnu, aka chyba je tuna - Eclipse mi tu hadze syntax error
        ajaxElementCall('modal_div', 'body/obsah/obrazy/folderDelete.php?kam=del1&'+append);
    });

    $('.addNewFolder').click(function() {
        showModal('modal_div', 'Nový adresár');
        var id = '';
        $('.folders .trow1').each(function() {
            if ($(this).css('backgroundColor') == 'rgb(52, 108, 182)' || $(this).css('backgroundColor') == '#346cb6') {
                id = $(this).attr('rel');
            }
        });
        ajaxElementCall('modal_div', 'body/obsah/obrazy/folderAdd.php?idFolder='+id);
    });

});    //-->
</script>


Having looked at the whole code (and pasted it, minus the PHP content, into The Online Lint), I'd still say that there's no syntax error in the Javascript, and that if that if Eclipse is telling you that there is, then Eclipse is wrong. Sometimes tools aren't perfect.

Does the code run, in different browsers? Chances are relatively good that if it does, then there's not actually a syntax error there.

(Posted as answer as requested. Ta.)


Try removing the accented characters in your quotes, you can still output accents, but use the corresponding HTML code.

A list of accented characters' HTML codes are found here:

http://www.w3schools.com/tags/ref_entities.asp

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜