Comments (6)
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.
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.
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.
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.
Hey @piuccio, just wondering if you got this working.
from clndr.
Oh yes, I added some extra logic in my click callback.
from clndr.
Related Issues (20)
- It's possible to move self.options.clickEvents.click.apply(self, [target]); after setting the selected date? HOT 2
- Previous and Next months appear. I just want to show the current month. HOT 5
- how can i translate month into chinese?
- Have multiple classes for an events such as a class for a bank holiday and school holiday class HOT 2
- Feature Request: Multi-day select HOT 1
- set month and year same time HOT 2
- "Na" being displayed instead of previous month's dates HOT 3
- Destroy Clndr In Internet Explorer IE 11 HOT 1
- Generating `daysOfTheWeek` array with only first character HOT 11
- Styling/CSS Not showing HOT 3
- Can I have the mini-calendar without the full calendar?
- Get clicked date in calander
- Drop jQuery dependency HOT 1
- How can I show current month in number?
- how can I stay the same month when returning back to this page HOT 1
- Usage docs should explain how to use eventsThisInterval HOT 1
- hi If I wants to change the calendar start day order from Sunday to Monday how can I change it HOT 2
- Improper translations with the localization features
- Initialization intervalEnd error with more than one month
- CLNDR2 released
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
π Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google β€οΈ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from clndr.