Giter Site home page Giter Site logo

Scope of callbacks about clndr HOT 3 CLOSED

kylestetz avatar kylestetz commented on May 5, 2024
Scope of callbacks

from clndr.

Comments (3)

kylestetz avatar kylestetz commented on May 5, 2024

Great idea! I can set it up to bind the scope to the calendar instance, that shouldn't be too tricky. I'm interested to know what sort of set up you're creating that requires this (just curious!).

from clndr.

piuccio avatar piuccio commented on May 5, 2024

Well my setup doesn't strictly require this, I've implemented it through closures, but having the scope in the callback would make things simpler.

I've created a wrapper around clndr, in this calendar a click on a date adds or removes an event, this means that an XHR request is sent to the server.
In the page there are multiple calendar that all make the same request, but each calendar has to specify a different request parameter, the calendar type a value stored in extras.
So in clickEvents I need to access calendar.options.extras.type.

Once again, I've solved it with closures, but I'd prefer to access this.options.extras.type

It looks somehow like this

(function( $ ) {

    $.fn.myPlugin = function() {

        return this.each(function() {
            var calendar;
            var container = $( this );
            var options = {
                clickEvents: {
                    click: function ( target ) {
                        // Here I need to access the calendar and the options
                        $.fn.myPlugin.addEvent( target.date, options.extras.type );
                    }
                },
                extras: container.data( "type" )
            };
            calendar = container.clndr( options );
        });

    };

    $.fn.myPlugin.addEvent = function ( date, type ) {
        // Implemented by users
    }

}( jQuery ));

from clndr.

kylestetz avatar kylestetz commented on May 5, 2024

Done.

from clndr.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.