My favorites | Sign in
Project Home Issues
New issue   Search
for
  Advanced search   Search tips   Subscriptions

Issue 388 attachment: history.js (2.6 KB)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
$(document).ready(function () {
var initialLoad = true;
var poppingState = false;

$('#calendar').fullCalendar({
theme: true,
header: {
left: 'prev,next today',
center: 'title',
right: 'month,agendaWeek,agendaDay'
},
//...,
defaultView: '', /* the default view passed from the original url */
year: /*the default year passed from the original url*/,
month: /*the default month passed from the original url*/,
date: /*the default date passed from the original url*/,
viewDisplay : function(view) {
if (Modernizr.history) { //this is a third party library that tests for browser compatibility, you can test in other fashions as well

//i'm doing a little bit of work here to make a pretty url
//the structure I'm using is like this:
// http://mysite.com/calendar/month/01-01-2010
// http://mysite.com/calendar/week/01-01-2010
// http://mysite.com/calendar/day/01-01-2010
if (view.name == 'month') {
var viewUrl = 'month';
} else if (view.name == 'agendaWeek') {
var viewUrl = 'week';
} else if (view.name == 'agendaDay') {
var viewUrl = 'day';
}

//I had to do a little bit of juggling to get it to only run items when necessary
//There might be a better way to do this but I couldn't find one
if (initialLoad) { //Replace the current state to set up state variables. URL should be identical
history.replaceState({ viewMode:view.name, start:view.start }, "Edit Calendar", "/calendar/" + viewUrl + "/" + $.fullCalendar.formatDate(view.start, 'MM-dd-yyyy'));
window.onpopstate = function(event) { //set up onpopstate handler
if (!initialLoad) { //the browser kept trying to pop the state on intial load
var start = event.state.start;
if (typeof(start) == 'string') { //even though i stored a date object, it was coming back as a string for some reason
start = $.fullCalendar.parseDate(start);
}
poppingState = true; //don't re-push state
$('#calendar').fullCalendar('gotoDate', start);
poppingState = true; //don't re-push state
$('#calendar').fullCalendar('changeView', event.state.viewMode);
}
initialLoad = false;
};
} else {
if (!poppingState) {
history.pushState({ viewMode:view.name, start:view.start }, "Edit Calendar", "/calendar/" + viewUrl + "/" + $.fullCalendar.formatDate(view.start, 'MM-dd-yyyy'));
} else {
poppingState = false;
}
}
}
}
});
});
Powered by Google Project Hosting