Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

height/contentHeight accept function for dynamic value #3040

Merged
merged 1 commit into from Jul 31, 2016

Conversation

aharpervc
Copy link
Contributor

this makes it a lot easier to size the control to its container. for example, implementations could do return container_el.clientHeight

this makes it a lot easier to size the control to its container. for example, implementations could do `return container_el.clientHeight`
@aharpervc
Copy link
Contributor Author

This is basically what I'm doing to solve #3039

@flick36
Copy link

flick36 commented Apr 24, 2016

+1

@arshaw
Copy link
Member

arshaw commented May 1, 2016

i agree that #2704 should still be implemented, but this could be cool as well. I'd prefer to see it as the existing height or contentHeight option that simply accepts a function

@arshaw arshaw changed the title Add a getContainerHeight option height/contentHeight accept function for dynamic value May 1, 2016
@arshaw
Copy link
Member

arshaw commented Jun 4, 2016

Philosophical question: how is this better than calling the height setter method?

I'd rather keep the setter method as the only way to dynamically set an explicit pixel value, and then introduce a height: 'parent' option as described in #2704

@aharpervc
Copy link
Contributor Author

It's a more elegant way to handle a dynamically changing container.

@arshaw
Copy link
Member

arshaw commented Jun 7, 2016

@aharpervc can you provide hypothetical code samples to show how it's more elegant the existing technique of using the setter methods?

@aharpervc
Copy link
Contributor Author

I'll give you my actual production code I'm running with this patch:

this.timeline = $(container_el).fullCalendar(_.extend({
    timezone: "utc",
    editable: false,
    aspectRatio: 1.8,

    getContainerHeight: function() {
        return container_el.clientHeight - 15;
    },
    // etc...

There's no extra state to track and no extra events to hook up. Whenever calcSize is called internally, the current container client height is used. Now fullcalendar can vertically fill its container both on init and when the browser is resized. There's a - 15 there because in my actual app, there's kind of a margin, but I didn't want to invent an extra container div to put fullcalendar inside of just for that.

Now, you could certainly re-implement this concept as a static property. However, you'd need to make assumptions on what is the appropriate container element (probably direct parent) and what is the appropriate margins (probably none). Those assumptions may or may not be true for all apps and isn't relevant to the fullcalendar itself. That's why it's more elegant to delegate the computation to the caller.

@arshaw
Copy link
Member

arshaw commented Jun 8, 2016

ah ok, this is more clear to me now.

how is the height-update initiated? are you manually calling the render method (which readjusts sizing) or are you merely waiting for the built-in window resize handler?

@aharpervc
Copy link
Contributor Author

I'm not explicitly calling render, but also I do have handleWindowResize turned on.

@arshaw
Copy link
Member

arshaw commented Jun 11, 2016

ok, this feature makes more sense to me now that i know you are leveraging window resize handling to adjust the height. thanks.

@@ -667,6 +667,10 @@ function Calendar_constructor(element, overrides) {


function _calcSize() { // assumes elementVisible
if (typeof options.getContainerHeight === 'function') {
suggestedViewHeight = options.getContainerHeight() - (headerElement ? headerElement.outerHeight(true) : 0);
return;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could you leverage the else if chain instead of doing a return?

@arshaw
Copy link
Member

arshaw commented Jun 11, 2016

would you be able to write tests for this feature? mandatory to ensure it doesn't break accidentally in the future.

https://github.com/fullcalendar/fullcalendar/wiki/Automated-Tests
https://github.com/fullcalendar/fullcalendar/tree/master/tests/automated

please let me know if i can give you any help/advice.

@aharpervc
Copy link
Contributor Author

I may be able to revisit this at some point, but I don't currently have your test environment set up, or much capacity to investigate it at the moment.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants