为什么这个脚本不能与wordpress一起使用?

时间:2011-10-08 19:21:03

标签: javascript jquery wordpress

有人能告诉我为什么当我把这个脚本放在wordpress网站上时,脚本不再起作用了吗?这适用于wordpress之外的标准文件。我假设它存在格式问题。

以为我是根据这篇文章得到的:jquery not working in wordpress

    jQuery(document).ready(function($) {

    //Zoomable Hovers
    $('img.zoomable').live('mouseover',function(){ $(this).addClass('hover'); } )
                     .live('mouseout' ,function(){ $(this).removeClass('hover'); } );
    //ZoomMap Plugin
    $('#map').zoommap({
        // Width and Height of the Map Area
        width: '550px',
        height: '450px',

        //Misc Settings
        blankImage: 'blank.gif',
        loadingImage: 'loading.gif',
        fadeDuration: 50,
        zoomDuration: 200,

        //ids and classes
        zoomClass: 'zoomable',
        popupSelector: 'div.popup',
        popupCloseSelector: 'a.close',

        //Return to Parent Map Link
        showReturnLink: true,
        returnId: 'returnlink',
        returnText: 'Return to map',

                //Initial Region to be shown
        map: {
            id: 'region',
            title: 'Regions',
            image: '../images/map/map.jpg',
            maps: [
            {
                id: 'englewood',
                title: 'Englewood Region',
                parent: 'region',
                image: '../images/map/regions/englewood.jpg',
                data: 'data/englewood.html',
                width: '86px',
                height: '56px',
                top: '139px',
                left: '251px'
            },
                    {
                id: 'glenwood',
                title: 'West Region',
                parent: 'region',
                image: '../images/map/regions/glenwood.jpg',
                data: 'data/glenwood.html',
                width: '250px',
                height: '171px',
                top: '139px',
                left: '0px'
            },
            ]
        }
    });

});





$.fn.zoommap = function(settings) {
    var map = $(this);
    $(this).data('currentId', '');

    /******* Show Map by ID ************/
    $(this).bind('showMap', function(e, id, value){
        alert(id);
        showMapById(id);        
        //return this?
    });
    function showMapById(id){
        var region = findRegion(settings.map, id);
        if(region != -1){
            displayMap(region);
        }
    }

    // recursive id find
    function findRegion(root, id){
        if(root.id == id){
            return root;
        }else{
            if(root.maps != undefined){
                for(var i=0; i<root.maps.length; i++){
                    return findRegion(root.maps[i], id);
                }
            }
        }
        return -1;
    }

    // region is a map
    // This gets called every time we zoom
    function displayMap(region){
        //Set Current Region Id
        $(this).data('currentId', region.id);

        //Clear the Map and Set the Background Image
        map.empty().css({
            backgroundImage: 'url(' + region.image + ')',
            width: settings.width,
            height: settings.height
        });

        //Show Bullets
        if(region.data != undefined){
            loadBullets(region.data);
        }

        //Set up each submap as an item to click
        if(region.maps != undefined){
            for(var i=0; i<region.maps.length; i++){
                addZoom(region.maps[i]);
            }
        }

        //Create Return Link
        if(settings.showReturnLink && region.parent != undefined){
            showReturnLink(region);
        }
    }
    /************************************************************************************/

    //Show Return Link
    function showReturnLink(region){
        map.after('<a href="javascript:void(0);" id="' + settings.returnId + '">' + settings.returnText + '</a>');
        $('#' + settings.returnId).hide().fadeIn().click(function(){
            showMapById(region.parent);
            $(this).remove();
        });
    }


    //Load the Bullets 
    function loadBullets(url){
        map.load(url, {}, function(){
            //place bullets
            $(this).children('a.bullet').each(function(){
                var coords = $(this).attr('rel').split('-');
                $(this).css({left: addpx(coords[0]), top: addpx(coords[1])})
                       .hide()
                       .click(function(){showPopup($(this).attr('id'));})
                       .fadeIn('fast');
            });
        });
    }

    function showPopup(id, leftbul, topbul){
        map.find(settings.popupSelector).fadeOut(); 
        var boxid = '#' + id + '-box';

        $(boxid).fadeIn();
        $(settings.popupCloseSelector).click(function(){
            $(this).parent().fadeOut();
        });
    }

    //add a clickable image for a region on the current map
    function addZoom(region){
        $('<img />').addClass(settings.zoomClass)
            .attr({
                src: settings.blankImage,
                id: region.id
            }).css({
                position: 'absolute',
                width: region.width,
                height: region.height,
                top: region.top,
                left: region.left,
                cursor: 'pointer'
            }).appendTo(map).click(function(){
                //hide neighboring bullets and zoomables
                var width = settings.width;
                var height = settings.height;
                if(region.scan){
                    width = region.scanwidth;
                    height = region.scanheight;
                }
                $(this).siblings().fadeOut();
                $(this).hide()
                       .attr('src', region.image)
                       .fadeIn('slow')
                       .animate({
                            width: width,
                            height: height,
                            top: '0px',
                            left: '0px'
                        }, settings.zoomDuration, '', function(){
                            displayMap(region);
                        });
            });
    }

    function rempx(string){
        return Number(string.substring(0, (string.length - 2)));
    }

    function addpx(string){
        return (Number(string) - 26) + 'px';
    }

    function showHash(string){
        string = string.replace('#', '');
        showMapById(string);
    }

    //initialize map
    var hash = self.document.location.hash;
    if(hash.length > 0)
        showHash(hash);
    else{
        displayMap(settings.map);
    }

    return this;
};

0 个答案:

没有答案