fullcalendar - resize calendar on window resize - javascript

I am using fullcalendar (fullcalendar by adam shaw)
I am wondering what I would need to do so that my fullcalendar dynamically changes size depending on the size of the browser window? I have looked into his 'render' function a little bit but have been having trouble figuring this out.
(ie, when a user resizes their window I would like fullcalendar to readjust it's width and height to a proper aspect ratio)

It's all documented.
Let's see, try something along this lines:
//function to calculate window height
function get_calendar_height() {
return $(window).height() - 30;
}
//attacht resize event to window and set fullcalendar height property
$(document).ready(function() {
$(window).resize(function() {
$('#calendar').fullCalendar('option', 'height', get_calendar_height());
});
//set fullcalendar height property
$('#calendar').fullCalendar({
//options
height: get_calendar_height
});
});
Apply similar to width.
Or you could place calendar in div and do manipulations that way.

For width, we made the calendar flexible, to adjust along with the responsive design, and it worked quite well on larger displays:
#calendar {
width: 100%;
margin: 0 auto;
}
For any other customization (changing height or default view), use the built-in windowResize event for FullCalendar. The downside to the accepted answer is that the function will run WHILE the window is being resized, for every pixel change. Conversely, the windowResize event fires AFTER the resizing is complete.
Now, the problem with a responsive calendar is that you're still at the mercy of the table - a terrible place to be on a small mobile screen.
For our project, we choose to force the day view if a user was on a screen smaller than 769px. You can see our method in this example. If it doesn't work for you, at least it will give you some direction on how to implement a solution that does.
$(function(){
var $calendar = $('#calendar');
$calendar.fullCalendar({
windowResize: function() {
var ww = $(window).width();
var view = (ww <= 768) ? 'basicDay' : 'month';
var currentView = $('#calendar').fullCalendar('getView');
if(view != currentView){
$calendar.fullCalendar('changeView',view);
}
if(ww <= 768){
$calendar.find('.fc-header-right .fc-button').hide();
}else{
$calendar.find('.fc-header-right .fc-button').show();
}
}
});
});

Since the current view is passed in the windowResize callback.
One could simply manage a responsive behavior with:
$('#calendar').fullCalendar({
# ...
windowResize: function (view) {
var current_view = view['name'];
var expected_view = $(window).width() > 576 ? 'agendaWeek' : 'agendaDay';
if (current_view !== expected_view) {
$('#calendar').fullCalendar('changeView', expected_view);
}
}
})
Also, one should make sure handleWindowResize is set to true (which is the default)

I googled "responsive calendar", because that is what you wanted I just think you didn't know how to word it. I believe the links I provided you should get you on your way. I am assuming you wanted to do this using javascript/jquery because of your tags. If the links are useful, that is also fine because now you know what to search for, Good Luck!
Responsive Calendar Demos:
http://dbushell.com/demos/calendar/v1_03-01-12.html
http://www.manystrands.com/projects/calendar.html (Changes to agenda view after a certain extent.)
More Info:
http://dbushell.com/2012/01/04/responsive-calendar-demo/

Related

Get live width and collapse an menu

i am in a difficult time for 2 days with a code for collapsing a menu . I'm trying really hard to realize what am i doing Wrong.
The problem with this code is that when you resize the browser it won't work again.
If someone could help me , i would appreciate it very much.
$(document).ready(function(){
function jqUpdateSize(){
// Get the dimensions of the viewport
var width = $(window).width();
if(width<=768){
$('.toggle-nav-this-site').css("display","block");
$('.toggle-nav-this-site .button-this-tg').click( function(){
$('.aside-menu > ul').toggle('showElem');
});
}else{
$('.toggle-nav-this-site').css("display","none");
$('.aside-menu > ul').show();
}
$('#jqWidth').html(width); // Display the width
};
$(document).ready(jqUpdateSize); // When the page first loads
$(window).resize(jqUpdateSize); // When the browser changes size
});
I've never used jQuery, but with plain JS you first have to add an EventListener:
window.addEventListener('resize', functionname);
This called function has to change all variables.
You can get the window-Size by: window.innerHeight, window.innerWidth

orientation change VS jquery events

The website: http://negativgraffiti.hu/uj/
If you jumps from one page to another, every page has a different height, but they are all in one div, just they are not visible all the time.
I'm resizing the parent div everytime to the current page's height (not the full code, just a sample):
var magassag = jQuery("#post-5");
var egymagas = jQuery(".elsofo").height();
if (i == 1) {
magassag.animate({
height: egymagas
}, 100 );
}
it's working fine, but when i test it on tablet/mobile the height is ruins when i change the orientation, and i don't know why.
Use $(window).on('resize', fn) to detect window resizing.
$(window).on('resize', function() {
// re-animate the height for the current page
});
Although this works fine for tablet resizing, it will be very inefficient for desktop users who are resizing the window with their mouse. It is good to throttle the resize callback for that reason.
// Use `throttle` from any of the various throttle libraries available.
$(window).on('resize', throttle(function() {
// re-animate the height for the current page
}));

Bind function to custom condition

Note: I rarely use JS and jQuery so please excuse if the question is odd.
I am trying to add a div to my page (to a menu specifically) but only if the page is smaller than a certain width. Basically I need an event handler that allows me to wait for that condition to be met and run a function once it is (similar to how you would do with on.("click")) but I have no idea how to accomplish that.
Any help would be greatly appreciated!
have a look at the following code:
var $myDiv = $("<div class='myDiv'></div>");
$(window).resize(function () {
var windowWidth = $(this).width();
if (windowWidth < 200) {
$("body").append($myDiv);
} else {
$myDiv.remove();
}
});
we monitor the window resize event, and append/remove the div as per your condition.
Live Example
play around with the bottom right side of the fiddle (the result pane) and resize it to see what happens.
This is without the event handler, but you can add it in a resize event handler:
if (window.matchMedia("(min-width:700px)").matches) {
// viewport width is at least 700px
} else {
// viewport is smaller than 700px
}

JQuery - Test window has been resizes over a threshold

hope you can help
My current project requires me to recall a set of functions on window resize so that I can keep the responsive nature correct. However the code I am using is rather twitchy as it calls the functions even if the window is resized by 1px.
I am relatively new to jQuery but learning more and more every day, but this is something I'm struggling to find a way to do.
In an ideal world I would like to call the functions when the window has been resized over a breaking point at anytime, for example:
say the breaking point is 500px, the initial load size is 400px the user resizes to 600px, so over the threshold so call the functions again.
It would also need to work in reverse... so window (or load) size 600px, breaking point 500px, resize to 400px call functions.
Here's the code I'm currently:
var windowWidth = $(window).width();
var resizing = !1;
$(window).resize(function(a) {
!1 !== resizing && clearTimeout(resizing);
resizing = setTimeout(doResize, 200);
});
function doResize() {
call_these_functions();
}
Cheers for the help guys
Thanks for the reply Zze
I am using something similar to what you've put, but I have it based within the start of my functions to filter what each thing does based on the window size. My problem is that these are getting called far too often and causing issues / twitchy behaviour.
For example I'm having issues on a tablet I'm testing on, when you scroll down, the scrollbar that appears on the right seems to trigger the window resize... causing functions to be called again that automatically accordion up or .hide() elements to their initial loaded state.
So my thinking is if I can test it's actually broken a set threshold rather than just what size the window is then it will be far more reliable.
There are some really handy jQuery functions available and it looks like you are very close to cracking this yourself. Hope this helps though.
$(window).resize(ResizeCode); // called on window resize
$(document).ready(function(e) { ResizeCode(); }); // called once document is ready to resize content immediatly
function ResizeCode()
{
if ($(window).width() < 500){
//insertCode
}
else if($(window).width() >= 500){
//insertCode
}
}
Update
If we are looking to 'restrict' the call time of this function, then you could add an interval which updates a bool every time it ticks, and then check this bool in the previous code:
var ready = true;
setInterval(function(){ready = true;}, 3000);
function ResizeCode()
{
if (ready)
{
// run code
ready = false;
}
}
But i would suggest storing the width and height of the window in a var and then comparing the current window with the var when the window is resized, that way you can tell if the window has actually been resized over 'x' amount or if it is that weird bug you've found.
Looks like i've found a solution that's going to do what i need with a little work (fingers crossed as i'm currently working on it), from http://xoxco.com/projects/code/breakpoints/
Thanks for the help Zze

Call or Uncall function after resize or orientation changee

I'm working on a mobile web project that goes between a two column or single column view based on screen size. For some device sizes, changing from portrait to landscape switches you between the single and double column. Across the bottom of the page there are three feature images that are side by side for two column view, but we want to turn into a content slider in single column.
My issue:
The javascript conditional I have calls the function when the width of the screen is below a certain width. However if you change the orientation/size of the screen, it doesn't recall the function or re-evaluate the screen width.
What I have:
if( $(window).width() < 570) {
$(window).load(function() {
$('.flexslider').flexslider();
});
}
What is the best way to watch for resize and call/recall the function after the resize event?
Use jQuery resize event on window. jsfiddle
$(window).resize(function(){
//your code
});
To follow on from what Shusl said, you need to create the functions within $(window).resize();
What I would do is create the function and be sure to trigger it too. So it would be something like -
$(window)resize(function() {
winWidth = $(window).width();
winHeight = $(window).height();
if (winWidth < 570) {
$(window).load(function() { $('.flexslider').flexslider(); });
}
else {
// do something else
}
}).trigger("resize");

Categories

Resources