How do I place all properties of Javascript object into another object?

77 Views Asked by At

I'm using a customized JQuery Bootstrap Wizard of Porto and I was requested that when using a link, that it will go on the relevant tab of the wizard.

The only thing that I need is to retrieve all the properties from the following object variable:

$('#w3').bootstrapWizard({
    tabClass: 'wizard-steps',
    nextSelector: 'ul.pager li.next',
    previousSelector: 'ul.pager li.previous',
    previousLinkSelector: 'ul.pager li.finish a.previous-link',
    firstSelector: null,
    lastSelector: null,
    onNext: function (tab, navigation, index, newindex) {
        var validated = $('#w3 form').valid();
        if (!validated) {
            $w3validator.focusInvalid();
            return false;
        }
    },
    onTabClick: function (tab, navigation, index, newindex) {
        if (newindex == index + 1) {
            return this.onNext(tab, navigation, index, newindex);
        } else if (newindex > index + 1) {
            return false;
        } else {
            return true;
        }
    },
    onTabChange: function (tab, navigation, index, newindex) {
        var $total = navigation.find('li').size() - 1;
        $w3finish[newindex != $total ? 'addClass' : 'removeClass']('hidden');
        $('#w3').find(this.nextSelector)[newindex == $total ? 'addClass' : 'removeClass']('hidden');
    },
    onTabShow: function (tab, navigation, index) {
        var $total = navigation.find('li').length - 1;
        var $current = index;
        var $percent = Math.floor(($current / $total) * 100);
        $('#w3').find('.progress-indicator').css({ 'width': $percent + '%' });
        tab.prevAll().addClass('completed');
        tab.nextAll().removeClass('completed');
    }
});

I need to put it in a global variable so I can use all the properties (especially the onTabClick property).

I've tried to do it the following way:

var $mainSettings = $.fn.bootstrapWizard;

The issue is that $mainSettings includes only the function declaration.

What's the correct way to get all properties from $.fn.bootstrapWizard; ?

1

There are 1 best solutions below

0
On

It depends how this jquery plugin exposes the configuration it receives. If it does not expose this, then you're out of luck. You can, however, just assign the config to a variable and pass that variable to the jquery plugin.

var $mainSettings = {
    tabClass: 'wizard-steps',
    nextSelector: 'ul.pager li.next',
    previousSelector: 'ul.pager li.previous',
    previousLinkSelector: 'ul.pager li.finish a.previous-link',
    firstSelector: null,
    lastSelector: null,
    onNext: function (tab, navigation, index, newindex) {
        var validated = $('#w3 form').valid();
        if (!validated) {
            $w3validator.focusInvalid();
            return false;
        }
    },
    onTabClick: function (tab, navigation, index, newindex) {
        if (newindex == index + 1) {
            return this.onNext(tab, navigation, index, newindex);
        } else if (newindex > index + 1) {
            return false;
        } else {
            return true;
        }
    },
    onTabChange: function (tab, navigation, index, newindex) {
        var $total = navigation.find('li').size() - 1;
        $w3finish[newindex != $total ? 'addClass' : 'removeClass']('hidden');
        $('#w3').find(this.nextSelector)[newindex == $total ? 'addClass' : 'removeClass']('hidden');
    },
    onTabShow: function (tab, navigation, index) {
        var $total = navigation.find('li').length - 1;
        var $current = index;
        var $percent = Math.floor(($current / $total) * 100);
        $('#w3').find('.progress-indicator').css({ 'width': $percent + '%' });
        tab.prevAll().addClass('completed');
        tab.nextAll().removeClass('completed');
    }
};

$('#w3').bootstrapWizard($mainSettings);