Constrain dates #26

Merged
merged 5 commits into from Apr 2, 2014

Projects

None yet

4 participants

@pirxpilot
Components member

As promised: rebased and refactored, should take care of #7
Adds min/max functions to set up the valid date range. Supports reverted ranges (where everything outside of the max-min is valid).
Examples added (in example.html) and documentation updated (in Readme.md).

@tj
Components member
tj commented Mar 13, 2013

sweet! I'll take a look

@tj tj and 1 other commented on an outdated diff Mar 13, 2013
lib/dayrange.js
+
+function compare(a, b) {
+ return date(a).getTime() - date(b).getTime();
+}
+
+function distance(a, b) {
+ return Math.abs(compare(a, b));
+}
+
+function DayRange(min, max) {
+ Bounds(this);
+ this.compare(compare);
+ this.distance(distance);
+ this.min(min).max(max);
+ return this;
+}
@tj
tj Mar 13, 2013

the rest is good i find this part weird though, can we mixin Bounds() to the prototype instead and "configure" it just the one time?

@pirxpilot
pirxpilot Mar 13, 2013

Makes sense. I'll try to fix it.

@tj
tj Mar 13, 2013

like if you have to redefine those methods anyway maybe they should just be regular .prototype.compare = f methods, haven't looked at the bounds code, this will be great functionality to have! thanks man

@pirxpilot
pirxpilot Mar 13, 2013

Yup. I guess I just got fixated on Bounds being a mixin (like Enumerable) rather than something you inherit from. I pushed a new commit. Let me know what you think.

@pirxpilot
Components member

rebased against latest master, merges without issues and... still works ;-)

@Swatinem Swatinem commented on an outdated diff Apr 2, 2014
@@ -56,6 +56,14 @@ cal.el.appendTo('body');
Show the next view (month).
+### Calendar#mix()
@Swatinem Swatinem commented on an outdated diff Apr 2, 2014
@@ -62,16 +77,30 @@
large.select(newDate);
});
- document.body.appendChild(one.el);
+ var container = document.querySelector('#standard');
@Swatinem
Swatinem Apr 2, 2014

You have mixed indentation here

@Swatinem
Components member

Without having too much knowledge about the code, this looks good.
You might want to ask @jonathanong to add you to the component maintainers.

pirxpilot added some commits Feb 17, 2013
@pirxpilot pirxpilot Implement dates restriction
Calendar has new `min` and `max` functions to define inclusive range of
valid dates.

Range checking is performed by DayRange implemented using Bounds.
When rendering calendar dates ourside of the range are rendered with
`invalid` CSS class, so that can they be styled differently from valid
dates.

Days will not fire 'change' event for invalid (out-of-range) dates.
Calendar ignores attempts to select invalid date, although is allows to
show it.
073d5d7
@pirxpilot pirxpilot Document new `min` and `max` methods 5f6e4ab
@pirxpilot pirxpilot DayRange fixes: inherit from Bounds 683b3e2
@pirxpilot
Components member

...or I can just haunt you to take all my patches and then complain bitterly about the changelogs ;-)
Fixed typo and intendation. Thank you.

Seriously though: @jonathanong - I've been contributing to component for more than a year now and several core components have my patches in. I use components in Liftie(source) and Furkot. I also maintain several code42day components and component related tools. If you think I can help, I'll be happy to chip in.

@Swatinem Swatinem merged commit 128e9c9 into component:master Apr 2, 2014
@pirxpilot pirxpilot referenced this pull request Apr 2, 2014
Closed

disabling ranges #7

@jonathanong

added both of you to owners!

@pirxpilot
Components member

Cool, thanks! I'll review the issues and release the component/calendar when I have a moment.

@jonathanong

feel free to help maintain other components. a lot need love ~_~

@pirxpilot pirxpilot deleted the code42day:constrain-dates-bounds branch Apr 26, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment