Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3788040
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T11:56:08+00:00 2026-05-19T11:56:08+00:00

I have a plugin I am writing that accepts options. It looks something like

  • 0

I have a plugin I am writing that accepts options. It looks something like this.

$('#myObject').myPlugin({
    option1: someValue
});

Where somevalue can either be a value, a control id, or a function.

I have a default settings defined like this

var settings = {
    option1: null
};

Then, inside my plugin I use this to merge what the user passes in with my empty settings object

if (options) {
    $.extend(settings, options);
}

This works fine when the option is a control ID or value.

My first issue is when I use a function like this

$('#myObject').myPlugin({
    option1: function(){ return doStuff(); }
});

$.extend() seems to ignore the function in this case. The default value from settings is always passed into my parser. I’m also having a problem when I pass in a value instead of a control id. I parse the settings to get the value like this

function parseValue(value, defaultValue) {
    if ($.isFunction(value))
        return value();

    if (!value)
        return defaultValue ? defaultValue : '';

    if ($('#' + value))
        return $('#' + value).val();

    return value;
};

if I pass in a date or a decimal, $('#' + value) evaluates to true.

Any ideas on how I make this work?

EDIT:

This may be wrong, but this is how I defined my plugin. It’s actually a collection of plugins

(function ($) {

    //shared methods here
    function parseValue(value, defaultValue) { /*...*/ }

    $.fn.myplugin = function (options) {
        var settings = { };

        $(this).live("submit", function (event) {
            //NEVER EVER EVER allow the form to submit to the server
            event.preventDefault();

            //logic for "posting" cross domain
        });
    };

    $.fn.myplugin2 = function (options) {
        var settings = { };

        $(this).live("submit", function (event) {
            //NEVER EVER EVER allow the form to submit to the server
            event.preventDefault();

            //logic for "posting" cross domain
        });
    };

})(jQuery);

The plugins hijack a form and make it submit cross domain through a jsonp get request. Each plugin submits different data to a different url, but the overall logic is the same.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-19T11:56:09+00:00Added an answer on May 19, 2026 at 11:56 am

    I found out what I was doing wrong.

    The selector test I was doing was always returning false because jquery doesn’t return undefined if nothing was found. So, I changed my parser to look like this:

    function parseValue(value, defaultValue) {
        if ($.isFunction(value))
            return value();
    
        if (!value)
            return defaultValue;
    
        if ($.type(value) === 'string' && $(value).length)
            return $(value).val();
    
        return value;
    };
    

    and my code now looks something like this

    $.fn.myPlugin= function (options) {
    
        var settings = {
            setting1: undefined
        }
    
        $(this).live('click', function{
            var setting = parseValue(settings.setting1, '');
        });
    }
    

    and now all three types (value, selector, or function) can be passed in as my query options.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a C++ Windows application that can be extended by writing C++ plugins,
I'm writing a plugin that is reliant on CSS3 gradient background properties. I have
I'm writing project in CI and I have winamp plugin that pass values to
I'm writing a web application that will have plugins. The plugins will be .DLL
I have a plugin for an RCP app that uses BIRT. I have a
I have an ActiveX plugin that we need (if possible) to run in Firefox.
I'd like to have my Eclipse plugin cause a URL to be opened by
I have been writing some code that creates a generic blog. Its features are
I'm writing a plugin that adds a page with a tag [deposit_page]; that tag
I am writing a plugin that provides drafting for models. A delete action is

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.