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 7721993
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T04:04:11+00:00 2026-06-01T04:04:11+00:00

I need your help again :) I’m trying to do a plugin with jQuery

  • 0

I need your help again 🙂

I’m trying to do a plugin with jQuery specifications.
So I started reading this: http://docs.jquery.com/Plugins/Authoring

The document is cool and give nice patterns to follow.

But i have a problem with my plugin.

My plugin appends a div and bind some events to diferents features.

Sometimes i need to accés to the options var but… the problem is, if i do the opt var global it take the last object created options.

And if i put it in the init method, i can’t use it in other actions.

I need each new object can acces only his own option set.

(function( $ ) {
//plugin methods
var methods = {
    init : function( options ) {


        //default options
        var opt = $.extend({
            'id'            : 'test',
            'title'         : 'Test window',
            'type'          : 'normal',
            'text'          : 'test test! <br/> 123',
            'shines'        : '',
            'head_shines'   : '',
            'body_shines'   : '',
            'bottom_bar'    : true
        }, options);

        //shine or not shine? that's the matter
        if (opt.shines != '') {
            opt.shines = "shiny";
            opt.head_shines = " shine_head";
            opt.body_shines = " shine_body";
        }

        //maintaining Chainability
        return this.each(function() {
            var $this = $(this); // $this is now JQuery object

            //creating the bottom bar
            if (opt.bottom_bar == true && $("#bottom_bar").length == 0) {
                $this.append('<div id="bottom_bar"></div>');
            }
            //creating the new window
            $this.append("<div style='display: none;' class='window "+opt.shines+"' id='"+opt.id+"'>...boring html...</div>");

            //append new window to the bar
            $("#bottom_bar").append("<div style='display: none' class='section' id='s_"+opt.id+"'>"+opt.title+"</div>");

            //get a object of the window to interact with
            var $window = $("#"+opt.id);

            //show the windows
            $window.fadeIn().draggable();
            $("#s_"+opt.id).fadeIn();

            //attach the events to the windows
            $window.find('.close').one('click.ventana', methods.close);

            $window.find('.max').on('click.ventana', methods.maximize);

            $window.find('.min').on('click.ventana', methods.minimize);
            $("#s_"+opt.id).on('click.ventana', methods.minimizeBar);
        });

    },
    close : function() {},
    maximize : function() {}, //i want acces my opts here!
    minimize : function() {},
    minimizeBar: function() {} //or here... etc
}; //end methods

//creating the plugin
$.fn.ventana = function( method ) {
    if ( methods[method] ) { //if we call a method...
        return methods[ method ].apply( this, Array.prototype.slice.call( arguments, 1 ) );
    } else if ( typeof method == 'object' || !method ) { //if not, we use init
        return methods.init.apply( this, arguments);
    } else { //method don't exists (console error)
        $.error( 'Method ' + method + ' does not exists in jQuery.ventana');
    }
};

}) ( jQuery );

The problem is, if i put where is the first comment:

//plugin methods

this:

//globals define
var opt;

I only get the last object opts…

Example creating new windows

$('body').ventana( {
    'id'    : 'master',
    'title' : 'Afegir Finestres',
    'text'  : 'test'
});
$('body').ventana( {
    'id'    : 'master1',
    'title' : 'Afegir Finestres1',
});

I just gonna get the master1 opts in both objects

  • 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-06-01T04:04:12+00:00Added an answer on June 1, 2026 at 4:04 am

    You could use data to store the options object to be retrieved later.

    // store it
    $this.data("options", opt);
    
    // ...
    
    // use it later
    var opt = $this.data("options");
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

ive being trying to cope with this problem but still. I need your help.
I need your help again. This should be a function for php. I've got
I need your help and advice yet again! I'm trying to do a website
i need again your help... I have this php code: <? if(isset($_POST['addnews'])){ $type =
I need your help with this one again. I want to send special characters
I really need your help for this. I am relatively new to programming and
I need your help. I need to create live wallpaper like this : Bikini
I need your help, i'm stacked on this project. When i run my applicaion
Hi everyone.. I need some help again. :) How to do this? When I
once again, i need your help to my kernel module. I have implemented an

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.