如何从外部函数更改Jquery配置对象值

时间:2014-09-17 15:01:03

标签: jquery

我有一个包含对象的jquery变量,我想在调用函数时将safetySlide值重置为1。目前它不起作用..我希望你们能帮助我。

这是我的配置

var PROFILE = {

config: {
    studySlide: 1,
    safetySlide: 1//the current slide in the study design subpage
},
init: function () {
    this.bindHandlers();
    //set active submenu item and open the menu
    (function () {

        if ($('div.submenupage').is(':visible')){
            var activeId = $('#profiles div.submenupage').filter(':visible').attr('id');
            $('div.sub_menu div.sub_btn a').removeClass('active');
            $('div.sub_menu div.' + activeId.replace('-','_') + '_btn a').addClass('active');
        }

        //alert(activeId);
    }());
    this.handlers.secondaryNavSlideOut();
    //set study slide state based on studySlide
    this.handlers.carouselControls.setSlide();

    if($('#profiles.study-design').length > 0){
        $('body').removeClass('study-design_2').removeClass('study-design_3');
        $('body').addClass('study-design_1');
    }

    $('.study_design_btn').on('click', function(){
        $('body').removeClass('study-design_2').removeClass('study-design_3');
        $('body').addClass('study-design_1');

        setTimeout(function(){
            addStudyDesignClass();  
        }, 100)
    });

    this.RESET.attachRESETOverlay();
},
RESET: {
    overlay: {}, //overlay, uses jQuery Tools overlay
    attachRESETOverlay: function () {
        //configure ISI overlay
        this.overlay = $('#openResetBox').overlay({
            top: "center",
            speed: "fast",
            closeOnClick: false,
            closeOnEsc: false,
            onBeforeLoad: function(){
                resetBox("", "", "check" );
                $('nav.left').css('z-index','0');
                $('nav.global').css('z-index','0');
                $('.isi').css('z-index','0');

            },
            onClose: function(){
                $('nav.left').css('z-index','600');
                $('nav.global').css('z-index','600');
                $('.isi').css('z-index','600');
            }
        }).data("overlay");

        //console.log(this.overlay);
    }
},
bindHandlers: function () {
    $('div.sub_menu .info_btn_wrapper a').on('click',this.handlers.secondaryNavSlideOut);
    $('div.sub_menu .info_close_btn a').on('click',this.handlers.secondaryNavSlideIn);
    $('div.sub_menu .sub_btn a').on('click',this.handlers.setSecondaryNavActive);
    $('div.carousel-controls li.left-arrow a').on('click',this.handlers.carouselControls.goLeft);
    $('div.carousel-controls li.right-arrow a').on('click',this.handlers.carouselControls.goRight);
    $('.reset_question_btn a').on('click', this.handlers.openRESET);
    $('.resetclosebtn a').on('click', this.handlers.closeRESET);
    $('div.reset_submit_button').on('click', this.handlers.submitRESET);
},
handlers: {
    secondaryNavSlideOut: function (e) {
        if (e !== undefined) {
            e.preventDefault();
        }
        $(this).addClass('active');
        setTimeout(function() {
            $('div.sub_menu .info_btn_wrapper').hide();
        }, 100);
        setTimeout(function() {
            $('div.sub_menu .info_sub_menu').show();
            $('div.sub_menu .info_btn_wrapper a').removeClass('active');
        }, 100);

    },
    secondaryNavSlideIn: function (e) {
        if (e !== undefined) {
            e.preventDefault();
        }
        var $this = $(this);
        $this.addClass('active');
        setTimeout(function() {
            $('div.sub_menu .info_sub_menu').hide();

        },100);

        setTimeout(function() {
            $('div.sub_menu .info_btn_wrapper').show();
            $('div.sub_menu .info_btn a').removeClass('active');
            $this.removeClass('active');
        },100);
    },
    setSecondaryNavActive: function () {
        $this = $(this);
        if ($this.parent('div.sub_btn').hasClass('info_close_btn') == false) {
            $('div.sub_menu div.sub_btn a').removeClass('active');
            $this.addClass('active');
        }

        $('nav.global a.profiles').attr('href',"javascript:goToSlide('profiles', 'profiles1')");
    },
    openRESET: function (e) {
        //load ISI overlay
        PROFILE.RESET.overlay.load();
    },
    closeRESET: function (e) {
        //accept the ISI and close overlay
        PROFILE.RESET.overlay.close();
    },
    submitRESET: function (e) {
        resetBox("", "", "", 'action' );
        PROFILE.RESET.overlay.close();
        setTimeout(function(){
            questionOneAnswers("", "", "check", "");
        },200);
    },
    carouselControls: {
        goLeft: function (e) {
            if (e !== undefined) {
                e.preventDefault();
            }
            $this = $(this);
            if ($this.hasClass('active') == true) {
                if (PROFILE.config.studySlide > 1) {
                    PROFILE.config.studySlide -= 1;
                    PROFILE.handlers.carouselControls.setSlide();
                }

                if (PROFILE.config.safetySlide > 1) {
                    PROFILE.config.safetySlide -= 1;
                    PROFILE.handlers.carouselControls.setSlide();
                }
            }
        },
        goRight: function (e) {
            if (e !== undefined) {
                e.preventDefault();
            }
            $this = $(this);
            if ($this.hasClass('active') == true) {
                if ($this.hasClass('active') == true) {
                    if (PROFILE.config.studySlide < 3) {
                        PROFILE.config.studySlide += 1;
                        PROFILE.handlers.carouselControls.setSlide();
                    }
                }

                if ($this.hasClass('active') == true) {
                    if (PROFILE.config.safetySlide < 3) {
                        PROFILE.config.safetySlide += 1;
                        PROFILE.handlers.carouselControls.setSlide();
                    }
                }
            }
        },
        setSlide: function (e) {
            //go to the study slide noted in
            //PROFILE.config.studySlide
            if (e !== undefined) {
                e.preventDefault();
            }
            var currentSlide = PROFILE.config.studySlide;
            $('#study-design div.slide').removeClass('active');
            $('#study-design div.slide' + currentSlide).addClass('active');

            var currentSafetySlide = PROFILE.config.safetySlide;
            $('#safety-data div.slide').removeClass('active');
            $('#safety-data div.slide' + currentSlide).addClass('active');

            //set arrow states
            $leftArrow = $('div.carousel-controls li.left-arrow a');
            $rightArrow = $('div.carousel-controls li.right-arrow a');
            if (currentSlide == 3) {
                $leftArrow.addClass('active');
                $rightArrow.removeClass('active');

                if($('#profiles.study-design').length > 0){
                    $('body').removeClass('study-design_1').removeClass('study-design_2');
                    $('body').addClass('study-design_3');
                }


            } else if (currentSlide == 1) {
                $leftArrow.removeClass('active');
                $rightArrow.addClass('active');

                if($('#profiles.study-design').length > 0){
                    $('body').removeClass('study-design_2').removeClass('study-design_3');
                    $('body').addClass('study-design_1');
                }

            } else {
                $leftArrow.addClass('active');
                $rightArrow.addClass('active');

                if($('#profiles.study-design').length > 0){
                    $('body').removeClass('study-design_1').removeClass('study-design_3');
                    $('body').addClass('study-design_2');
                }
            }
            //set circles
            $('div.carousel-controls li.circle a').removeClass('active');
            $('div.carousel-controls li.circle:nth-child(' + (currentSlide + 1) + ') a').addClass('active');
        }
    }
}

}

这是我想要如何改变价值。因此,如果safetySlide的值大于1.将值恢复为1.

$(document).ready(function(){

    PROFILE.init();

    function resetValue(){ 
        if( PROFILE.config.safetySlide > 1 ){ PROFILE.config.safetySlide = 1; }
    }
});

我希望有人可以帮助我。

提前感谢。

0 个答案:

没有答案