Giter Site home page Giter Site logo

Comments (6)

kylestetz avatar kylestetz commented on May 4, 2024

I am not 100% sure I understand what the end result should be, but let me toss out an idea– if the calendar didn't refresh when you added a new event, would that solve your problem?

Here's the source code to the addEvents method:

Clndr.prototype.addEvents = function(events) {
  // go through each event and add a moment object
  if(this.options.multiDayEvents) {
    this.options.events = $.merge(this.options.events, this.addMultiDayMomentObjectsToEvents(events));
  } else {
    this.options.events = $.merge(this.options.events, this.addMomentObjectToEvents(events));
  }

  this.render();
  return this;
};

For the purposes of your code, you can get away with only calling

this.options.events = $.merge(this.options.events, this.addMomentObjectToEvents(events));

if you aren't using multiday events. This would bypass the render function and allow you to handle things a little more naturally.

If I'm totally off here and that's not the issue, would you mind telling me a bit more about your calendar and what the effect of this code should be?

from clndr.

Padam87 avatar Padam87 commented on May 4, 2024

A 4th option would be to just update the existing DOM elements instead of replacing.

IMO that is the best solution if you think globally. It should be fairly easy to add a refresh method to the prototype.

from clndr.

piuccio avatar piuccio commented on May 4, 2024

I need the call to this.render() to add the event class to the date I clicked.

Fourth solutions looks like this

this.options.events = $.merge(this.options.events, this.addMomentObjectToEvents(events));
target.element.addClass("event");

But that feels like reinventing the wheel, and touching the calendar internals might not be future compatible.

I'm now using this if

if (target.parents(".dropdown-container").length || target.parents("body").length === 0) {
    return;
}

so if I click on a detached node nothing happens.

Feel free to close this issue if you think there's no need to pass the original event to click callbacks.

from clndr.

kylestetz avatar kylestetz commented on May 4, 2024

Okay I think I understand what you're going for now. I'm hesitant to add the click event to the API because I haven't seen any other use cases for it, and in your case there are other changes you could make to avoid dealing with event propagation.

Rather than checking (".dropdown-container").length, which is too closely coupled to the render mechanism of clndr, could you just make a boolean variable that you modify from inside the click handler?

For example, in clndr:

clickEvents: {
    click: function (target) {
        eventWasAdded = true;
        this.addEvents([{
            date: target.date
        }]);
    }
}

in your body click handler:

$("body").click(function (event) {
    var target = $(event.target);
    if (target.parents(".dropdown-container").length || eventWasAdded) {
        eventWasAdded = false;
        return;
    }
    $(".active").removeClass("active");
});

That click handler now covers both use cases: either the click handler caught a click inside of the clndr instance (so the length of the selector is > 0) or you just added an event, in which case we know the click was on the clndr.

from clndr.

kylestetz avatar kylestetz commented on May 4, 2024

Hey @piuccio, just wondering if you got this working.

from clndr.

piuccio avatar piuccio commented on May 4, 2024

Oh yes, I added some extra logic in my click callback.

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.