1
0
Fork 0

update of fullcalender to v1.6.4

This commit is contained in:
hauke 2014-09-07 14:31:01 +02:00
commit bc8df42dcc
8 changed files with 2659 additions and 2157 deletions

View file

@ -1,278 +0,0 @@
GNU GENERAL PUBLIC LICENSE
Version 2, June 1991
Copyright (C) 1989, 1991 Free Software Foundation, Inc.
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed.
Preamble
The licenses for most software are designed to take away your
freedom to share and change it. By contrast, the GNU General Public
License is intended to guarantee your freedom to share and change free
software--to make sure the software is free for all its users. This
General Public License applies to most of the Free Software
Foundation's software and to any other program whose authors commit to
using it. (Some other Free Software Foundation software is covered by
the GNU Lesser General Public License instead.) You can apply it to
your programs, too.
When we speak of free software, we are referring to freedom, not
price. Our General Public Licenses are designed to make sure that you
have the freedom to distribute copies of free software (and charge for
this service if you wish), that you receive source code or can get it
if you want it, that you can change the software or use pieces of it
in new free programs; and that you know you can do these things.
To protect your rights, we need to make restrictions that forbid
anyone to deny you these rights or to ask you to surrender the rights.
These restrictions translate to certain responsibilities for you if you
distribute copies of the software, or if you modify it.
For example, if you distribute copies of such a program, whether
gratis or for a fee, you must give the recipients all the rights that
you have. You must make sure that they, too, receive or can get the
source code. And you must show them these terms so they know their
rights.
We protect your rights with two steps: (1) copyright the software, and
(2) offer you this license which gives you legal permission to copy,
distribute and/or modify the software.
Also, for each author's protection and ours, we want to make certain
that everyone understands that there is no warranty for this free
software. If the software is modified by someone else and passed on, we
want its recipients to know that what they have is not the original, so
that any problems introduced by others will not reflect on the original
authors' reputations.
Finally, any free program is threatened constantly by software
patents. We wish to avoid the danger that redistributors of a free
program will individually obtain patent licenses, in effect making the
program proprietary. To prevent this, we have made it clear that any
patent must be licensed for everyone's free use or not licensed at all.
The precise terms and conditions for copying, distribution and
modification follow.
GNU GENERAL PUBLIC LICENSE
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
0. This License applies to any program or other work which contains
a notice placed by the copyright holder saying it may be distributed
under the terms of this General Public License. The "Program", below,
refers to any such program or work, and a "work based on the Program"
means either the Program or any derivative work under copyright law:
that is to say, a work containing the Program or a portion of it,
either verbatim or with modifications and/or translated into another
language. (Hereinafter, translation is included without limitation in
the term "modification".) Each licensee is addressed as "you".
Activities other than copying, distribution and modification are not
covered by this License; they are outside its scope. The act of
running the Program is not restricted, and the output from the Program
is covered only if its contents constitute a work based on the
Program (independent of having been made by running the Program).
Whether that is true depends on what the Program does.
1. You may copy and distribute verbatim copies of the Program's
source code as you receive it, in any medium, provided that you
conspicuously and appropriately publish on each copy an appropriate
copyright notice and disclaimer of warranty; keep intact all the
notices that refer to this License and to the absence of any warranty;
and give any other recipients of the Program a copy of this License
along with the Program.
You may charge a fee for the physical act of transferring a copy, and
you may at your option offer warranty protection in exchange for a fee.
2. You may modify your copy or copies of the Program or any portion
of it, thus forming a work based on the Program, and copy and
distribute such modifications or work under the terms of Section 1
above, provided that you also meet all of these conditions:
a) You must cause the modified files to carry prominent notices
stating that you changed the files and the date of any change.
b) You must cause any work that you distribute or publish, that in
whole or in part contains or is derived from the Program or any
part thereof, to be licensed as a whole at no charge to all third
parties under the terms of this License.
c) If the modified program normally reads commands interactively
when run, you must cause it, when started running for such
interactive use in the most ordinary way, to print or display an
announcement including an appropriate copyright notice and a
notice that there is no warranty (or else, saying that you provide
a warranty) and that users may redistribute the program under
these conditions, and telling the user how to view a copy of this
License. (Exception: if the Program itself is interactive but
does not normally print such an announcement, your work based on
the Program is not required to print an announcement.)
These requirements apply to the modified work as a whole. If
identifiable sections of that work are not derived from the Program,
and can be reasonably considered independent and separate works in
themselves, then this License, and its terms, do not apply to those
sections when you distribute them as separate works. But when you
distribute the same sections as part of a whole which is a work based
on the Program, the distribution of the whole must be on the terms of
this License, whose permissions for other licensees extend to the
entire whole, and thus to each and every part regardless of who wrote it.
Thus, it is not the intent of this section to claim rights or contest
your rights to work written entirely by you; rather, the intent is to
exercise the right to control the distribution of derivative or
collective works based on the Program.
In addition, mere aggregation of another work not based on the Program
with the Program (or with a work based on the Program) on a volume of
a storage or distribution medium does not bring the other work under
the scope of this License.
3. You may copy and distribute the Program (or a work based on it,
under Section 2) in object code or executable form under the terms of
Sections 1 and 2 above provided that you also do one of the following:
a) Accompany it with the complete corresponding machine-readable
source code, which must be distributed under the terms of Sections
1 and 2 above on a medium customarily used for software interchange; or,
b) Accompany it with a written offer, valid for at least three
years, to give any third party, for a charge no more than your
cost of physically performing source distribution, a complete
machine-readable copy of the corresponding source code, to be
distributed under the terms of Sections 1 and 2 above on a medium
customarily used for software interchange; or,
c) Accompany it with the information you received as to the offer
to distribute corresponding source code. (This alternative is
allowed only for noncommercial distribution and only if you
received the program in object code or executable form with such
an offer, in accord with Subsection b above.)
The source code for a work means the preferred form of the work for
making modifications to it. For an executable work, complete source
code means all the source code for all modules it contains, plus any
associated interface definition files, plus the scripts used to
control compilation and installation of the executable. However, as a
special exception, the source code distributed need not include
anything that is normally distributed (in either source or binary
form) with the major components (compiler, kernel, and so on) of the
operating system on which the executable runs, unless that component
itself accompanies the executable.
If distribution of executable or object code is made by offering
access to copy from a designated place, then offering equivalent
access to copy the source code from the same place counts as
distribution of the source code, even though third parties are not
compelled to copy the source along with the object code.
4. You may not copy, modify, sublicense, or distribute the Program
except as expressly provided under this License. Any attempt
otherwise to copy, modify, sublicense or distribute the Program is
void, and will automatically terminate your rights under this License.
However, parties who have received copies, or rights, from you under
this License will not have their licenses terminated so long as such
parties remain in full compliance.
5. You are not required to accept this License, since you have not
signed it. However, nothing else grants you permission to modify or
distribute the Program or its derivative works. These actions are
prohibited by law if you do not accept this License. Therefore, by
modifying or distributing the Program (or any work based on the
Program), you indicate your acceptance of this License to do so, and
all its terms and conditions for copying, distributing or modifying
the Program or works based on it.
6. Each time you redistribute the Program (or any work based on the
Program), the recipient automatically receives a license from the
original licensor to copy, distribute or modify the Program subject to
these terms and conditions. You may not impose any further
restrictions on the recipients' exercise of the rights granted herein.
You are not responsible for enforcing compliance by third parties to
this License.
7. If, as a consequence of a court judgment or allegation of patent
infringement or for any other reason (not limited to patent issues),
conditions are imposed on you (whether by court order, agreement or
otherwise) that contradict the conditions of this License, they do not
excuse you from the conditions of this License. If you cannot
distribute so as to satisfy simultaneously your obligations under this
License and any other pertinent obligations, then as a consequence you
may not distribute the Program at all. For example, if a patent
license would not permit royalty-free redistribution of the Program by
all those who receive copies directly or indirectly through you, then
the only way you could satisfy both it and this License would be to
refrain entirely from distribution of the Program.
If any portion of this section is held invalid or unenforceable under
any particular circumstance, the balance of the section is intended to
apply and the section as a whole is intended to apply in other
circumstances.
It is not the purpose of this section to induce you to infringe any
patents or other property right claims or to contest validity of any
such claims; this section has the sole purpose of protecting the
integrity of the free software distribution system, which is
implemented by public license practices. Many people have made
generous contributions to the wide range of software distributed
through that system in reliance on consistent application of that
system; it is up to the author/donor to decide if he or she is willing
to distribute software through any other system and a licensee cannot
impose that choice.
This section is intended to make thoroughly clear what is believed to
be a consequence of the rest of this License.
8. If the distribution and/or use of the Program is restricted in
certain countries either by patents or by copyrighted interfaces, the
original copyright holder who places the Program under this License
may add an explicit geographical distribution limitation excluding
those countries, so that distribution is permitted only in or among
countries not thus excluded. In such case, this License incorporates
the limitation as if written in the body of this License.
9. The Free Software Foundation may publish revised and/or new versions
of the General Public License from time to time. Such new versions will
be similar in spirit to the present version, but may differ in detail to
address new problems or concerns.
Each version is given a distinguishing version number. If the Program
specifies a version number of this License which applies to it and "any
later version", you have the option of following the terms and conditions
either of that version or of any later version published by the Free
Software Foundation. If the Program does not specify a version number of
this License, you may choose any version ever published by the Free Software
Foundation.
10. If you wish to incorporate parts of the Program into other free
programs whose distribution conditions are different, write to the author
to ask for permission. For software which is copyrighted by the Free
Software Foundation, write to the Free Software Foundation; we sometimes
make exceptions for this. Our decision will be guided by the two goals
of preserving the free status of all derivatives of our free software and
of promoting the sharing and reuse of software generally.
NO WARRANTY
11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
REPAIR OR CORRECTION.
12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
POSSIBILITY OF SUCH DAMAGES.

View file

@ -1,4 +1,68 @@
version 1.6.4 (9/1/13)
- better algorithm for positioning timed agenda events (issue 1115)
- `slotEventOverlap` option to tweak timed agenda event overlapping (issue 218)
- selection bug when slot height is customized (issue 1035)
- supply view argument in `loading` callback (issue 1018)
- fixed week number not displaying in agenda views (issue 1951)
- fixed fullCalendar not initializing with no options (issue 1356)
- NPM's package.json, no more warnings or errors (issue 1762)
- building the bower component should output bower.json instead of component.json (PR 125)
- use bower internally for fetching new versions of jQuery and jQuery UI
version 1.6.3 (8/10/13)
- viewRender callback (PR 15)
- viewDestroy callback (PR 15)
- eventDestroy callback (PR 111)
- handleWindowResize option (PR 54)
- eventStartEditable/startEditable options (PR 49)
- eventDurationEditable/durationEditable options (PR 49)
- specify function for $.ajax `data` parameter for JSON event sources (PR 59)
- fixed bug with agenda event dropping in wrong column (PR 55)
- easier event element z-index customization (PR 58)
- classNames on past/future days (PR 88)
- allow null/undefined event titles (PR 84)
- small optimize for agenda event rendering (PR 56)
- deprecated:
- viewDisplay
- disableDragging
- disableResizing
- bundled with latest jQuery (1.10.2) and jQuery UI (1.10.3)
version 1.6.2 (7/18/13)
- hiddenDays option (issue 686)
- bugfix: when eventRender returns false, incorrect stacking of events (issue 762)
- bugfix: couldn't change event.backgroundImage when calling updateEvent (thx stephenharris)
version 1.6.1 (4/14/13)
- fixed event inner content overflow bug (issue 1783)
- fixed table header className bug (1772)
- removed text-shadow on events (better for general use, thx tkrotoff)
version 1.6.0 (3/18/13)
- visual facelift, with bootstrap-inspired buttons and colors
- simplified HTML/CSS for events and buttons
- dayRender, for modifying a day cell (issue 191, thx althaus)
- week numbers on side of calendar (issue 295)
- weekNumber
- weekNumberCalculation
- weekNumberTitle
- "W" formatting variable
- finer snapping granularity for agenda view events (issue 495, thx ms-doodle-com)
- eventAfterAllRender (issue 753, thx pdrakeweb)
- eventDataTransform (thx joeyspo)
- data-date attributes on cells (thx Jae)
- expose $.fullCalendar.dateFormatters
- when clicking fast on buttons, prevent text selection
- bundled with latest jQuery (1.9.1) and jQuery UI (1.10.2)
- Grunt/Lumbar build system for internal development
- build for Bower package manager
- build for jQuery plugin site
version 1.5.4 (9/5/12)
- made compatible with jQuery 1.8.* (thx archaeron)
- bundled with jQuery 1.8.1 and jQuery UI 1.8.23
version 1.5.3 (2/6/12) version 1.5.3 (2/6/12)
- fixed dragging issue with jQuery UI 1.8.16 (issue 1168) - fixed dragging issue with jQuery UI 1.8.16 (issue 1168)
- bundled with jQuery 1.7.1 and jQuery UI 1.8.17 - bundled with jQuery 1.7.1 and jQuery UI 1.8.17

View file

@ -1,12 +1,7 @@
/* /*!
* FullCalendar v1.5.3 Stylesheet * FullCalendar v1.6.4 Stylesheet
* * Docs & License: http://arshaw.com/fullcalendar/
* Copyright (c) 2011 Adam Shaw * (c) 2013 Adam Shaw
* Dual licensed under the MIT and GPL licenses, located in
* MIT-LICENSE.txt and GPL-LICENSE.txt respectively.
*
* Date: Mon Feb 6 22:40:40 2012 -0800
*
*/ */
@ -79,11 +74,8 @@ html .fc,
margin-right: -1px; margin-right: -1px;
} }
.fc-header .fc-corner-right { .fc-header .fc-corner-right, /* non-theme */
margin-right: 1px; /* back to normal */ .fc-header .ui-corner-right { /* theme */
}
.fc-header .ui-corner-right {
margin-right: 0; /* back to normal */ margin-right: 0; /* back to normal */
} }
@ -110,10 +102,11 @@ html .fc,
.fc-content { .fc-content {
clear: both; clear: both;
zoom: 1; /* for IE7, gives accurate coordinates for [un]freezeContentHeight */
} }
.fc-view { .fc-view {
width: 100%; /* needed for view switching (when view is absolute) */ width: 100%;
overflow: hidden; overflow: hidden;
} }
@ -124,17 +117,17 @@ html .fc,
.fc-widget-header, /* <th>, usually */ .fc-widget-header, /* <th>, usually */
.fc-widget-content { /* <td>, usually */ .fc-widget-content { /* <td>, usually */
border: 1px solid #ccc; border: 1px solid #ddd;
} }
.fc-state-highlight { /* <td> today cell */ /* TODO: add .fc-today to <th> */ .fc-state-highlight { /* <td> today cell */ /* TODO: add .fc-today to <th> */
background: #ffc; background: #fcf8e3;
} }
.fc-cell-overlay { /* semi-transparent rectangle while dragging */ .fc-cell-overlay { /* semi-transparent rectangle while dragging */
background: #9cf; background: #bce8f1;
opacity: .2; opacity: .3;
filter: alpha(opacity=20); /* for IE */ filter: alpha(opacity=30); /* for IE */
} }
@ -145,43 +138,54 @@ html .fc,
.fc-button { .fc-button {
position: relative; position: relative;
display: inline-block; display: inline-block;
padding: 0 .6em;
overflow: hidden;
height: 1.9em;
line-height: 1.9em;
white-space: nowrap;
cursor: pointer; cursor: pointer;
} }
.fc-state-default { /* non-theme */ .fc-state-default { /* non-theme */
border-style: solid; border: 1px solid;
border-width: 1px 0;
} }
.fc-button-inner { .fc-state-default.fc-corner-left { /* non-theme */
position: relative; border-top-left-radius: 4px;
float: left; border-bottom-left-radius: 4px;
overflow: hidden;
} }
.fc-state-default .fc-button-inner { /* non-theme */ .fc-state-default.fc-corner-right { /* non-theme */
border-style: solid; border-top-right-radius: 4px;
border-width: 0 1px; border-bottom-right-radius: 4px;
} }
.fc-button-content { /*
position: relative; Our default prev/next buttons use HTML entities like &lsaquo; &rsaquo; &laquo; &raquo;
float: left; and we'll try to make them look good cross-browser.
height: 1.9em; */
line-height: 1.9em;
padding: 0 .6em; .fc-text-arrow {
white-space: nowrap; margin: 0 .1em;
font-size: 2em;
font-family: "Courier New", Courier, monospace;
vertical-align: baseline; /* for IE7 */
}
.fc-button-prev .fc-text-arrow,
.fc-button-next .fc-text-arrow { /* for &lsaquo; &rsaquo; */
font-weight: bold;
} }
/* icon (for jquery ui) */ /* icon (for jquery ui) */
.fc-button-content .fc-icon-wrap { .fc-button .fc-icon-wrap {
position: relative; position: relative;
float: left; float: left;
top: 50%; top: 50%;
} }
.fc-button-content .ui-icon { .fc-button .ui-icon {
position: relative; position: relative;
float: left; float: left;
margin-top: -50%; margin-top: -50%;
@ -189,107 +193,98 @@ html .fc,
*top: -50%; *top: -50%;
} }
/* gloss effect */ /*
button states
.fc-state-default .fc-button-effect { borrowed from twitter bootstrap (http://twitter.github.com/bootstrap/)
position: absolute; */
top: 50%;
left: 0; .fc-state-default {
background-color: #f5f5f5;
background-image: -moz-linear-gradient(top, #ffffff, #e6e6e6);
background-image: -webkit-gradient(linear, 0 0, 0 100%, from(#ffffff), to(#e6e6e6));
background-image: -webkit-linear-gradient(top, #ffffff, #e6e6e6);
background-image: -o-linear-gradient(top, #ffffff, #e6e6e6);
background-image: linear-gradient(to bottom, #ffffff, #e6e6e6);
background-repeat: repeat-x;
border-color: #e6e6e6 #e6e6e6 #bfbfbf;
border-color: rgba(0, 0, 0, 0.1) rgba(0, 0, 0, 0.1) rgba(0, 0, 0, 0.25);
color: #333;
text-shadow: 0 1px 1px rgba(255, 255, 255, 0.75);
box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.2), 0 1px 2px rgba(0, 0, 0, 0.05);
} }
.fc-state-default .fc-button-effect span {
position: absolute;
top: -100px;
left: 0;
width: 500px;
height: 100px;
border-width: 100px 0 0 1px;
border-style: solid;
border-color: #fff;
background: #444;
opacity: .09;
filter: alpha(opacity=9);
}
/* button states (determines colors) */
.fc-state-default,
.fc-state-default .fc-button-inner {
border-style: solid;
border-color: #ccc #bbb #aaa;
background: #F3F3F3;
color: #000;
}
.fc-state-hover, .fc-state-hover,
.fc-state-hover .fc-button-inner {
border-color: #999;
}
.fc-state-down, .fc-state-down,
.fc-state-down .fc-button-inner {
border-color: #555;
background: #777;
}
.fc-state-active, .fc-state-active,
.fc-state-active .fc-button-inner { .fc-state-disabled {
border-color: #555; color: #333333;
background: #777; background-color: #e6e6e6;
color: #fff;
} }
.fc-state-disabled, .fc-state-hover {
.fc-state-disabled .fc-button-inner { color: #333333;
color: #999; text-decoration: none;
border-color: #ddd; background-position: 0 -15px;
-webkit-transition: background-position 0.1s linear;
-moz-transition: background-position 0.1s linear;
-o-transition: background-position 0.1s linear;
transition: background-position 0.1s linear;
} }
.fc-state-down,
.fc-state-active {
background-color: #cccccc;
background-image: none;
outline: 0;
box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.15), 0 1px 2px rgba(0, 0, 0, 0.05);
}
.fc-state-disabled { .fc-state-disabled {
cursor: default; cursor: default;
background-image: none;
opacity: 0.65;
filter: alpha(opacity=65);
box-shadow: none;
} }
.fc-state-disabled .fc-button-effect {
display: none;
}
/* Global Event Styles /* Global Event Styles
------------------------------------------------------------------------*/ ------------------------------------------------------------------------*/
.fc-event-container > * {
z-index: 8;
}
.fc-event-container > .ui-draggable-dragging,
.fc-event-container > .ui-resizable-resizing {
z-index: 9;
}
.fc-event { .fc-event {
border-style: solid; border: 1px solid #3a87ad; /* default BORDER color */
border-width: 0; background-color: #3a87ad; /* default BACKGROUND color */
color: #fff; /* default TEXT color */
font-size: .85em; font-size: .85em;
cursor: default; cursor: default;
} }
a.fc-event {
text-decoration: none;
}
a.fc-event, a.fc-event,
.fc-event-draggable { .fc-event-draggable {
cursor: pointer; cursor: pointer;
} }
a.fc-event {
text-decoration: none;
}
.fc-rtl .fc-event { .fc-rtl .fc-event {
text-align: right; text-align: right;
} }
.fc-event-skin {
border-color: #36c; /* default BORDER color */
background-color: #36c; /* default BACKGROUND color */
color: #fff; /* default TEXT color */
}
.fc-event-inner { .fc-event-inner {
position: relative;
width: 100%; width: 100%;
height: 100%; height: 100%;
border-style: solid;
border-width: 0;
overflow: hidden; overflow: hidden;
} }
@ -298,7 +293,7 @@ a.fc-event {
padding: 0 1px; padding: 0 1px;
} }
.fc .ui-resizable-handle { /*** TODO: don't use ui-resizable anymore, change class ***/ .fc .ui-resizable-handle {
display: block; display: block;
position: absolute; position: absolute;
z-index: 99999; z-index: 99999;
@ -316,6 +311,20 @@ a.fc-event {
border-width: 1px 0; border-width: 1px 0;
margin-bottom: 1px; margin-bottom: 1px;
} }
.fc-ltr .fc-event-hori.fc-event-start,
.fc-rtl .fc-event-hori.fc-event-end {
border-left-width: 1px;
border-top-left-radius: 3px;
border-bottom-left-radius: 3px;
}
.fc-ltr .fc-event-hori.fc-event-end,
.fc-rtl .fc-event-hori.fc-event-start {
border-right-width: 1px;
border-top-right-radius: 3px;
border-bottom-right-radius: 3px;
}
/* resizable */ /* resizable */
@ -341,66 +350,6 @@ a.fc-event {
/* Fake Rounded Corners (for buttons and events)
------------------------------------------------------------*/
.fc-corner-left {
margin-left: 1px;
}
.fc-corner-left .fc-button-inner,
.fc-corner-left .fc-event-inner {
margin-left: -1px;
}
.fc-corner-right {
margin-right: 1px;
}
.fc-corner-right .fc-button-inner,
.fc-corner-right .fc-event-inner {
margin-right: -1px;
}
.fc-corner-top {
margin-top: 1px;
}
.fc-corner-top .fc-event-inner {
margin-top: -1px;
}
.fc-corner-bottom {
margin-bottom: 1px;
}
.fc-corner-bottom .fc-event-inner {
margin-bottom: -1px;
}
/* Fake Rounded Corners SPECIFICALLY FOR EVENTS
-----------------------------------------------------------------*/
.fc-corner-left .fc-event-inner {
border-left-width: 1px;
}
.fc-corner-right .fc-event-inner {
border-right-width: 1px;
}
.fc-corner-top .fc-event-inner {
border-top-width: 1px;
}
.fc-corner-bottom .fc-event-inner {
border-bottom-width: 1px;
}
/* Reusable Separate-border Table /* Reusable Separate-border Table
------------------------------------------------------------*/ ------------------------------------------------------------*/
@ -436,6 +385,15 @@ table.fc-border-separate {
.fc-grid th { .fc-grid th {
text-align: center; text-align: center;
} }
.fc .fc-week-number {
width: 22px;
text-align: center;
}
.fc .fc-week-number div {
padding: 0 2px;
}
.fc-grid .fc-day-number { .fc-grid .fc-day-number {
float: right; float: right;
@ -492,6 +450,10 @@ table.fc-border-separate {
white-space: nowrap; white-space: nowrap;
font-weight: normal; font-weight: normal;
} }
.fc-agenda .fc-week-number {
font-weight: bold;
}
.fc-agenda .fc-day-content { .fc-agenda .fc-day-content {
padding: 2px 2px 1px; padding: 2px 2px 1px;
@ -566,19 +528,28 @@ table.fc-border-separate {
.fc-event-vert { .fc-event-vert {
border-width: 0 1px; border-width: 0 1px;
} }
.fc-event-vert .fc-event-head, .fc-event-vert.fc-event-start {
.fc-event-vert .fc-event-content { border-top-width: 1px;
position: relative; border-top-left-radius: 3px;
z-index: 2; border-top-right-radius: 3px;
width: 100%; }
overflow: hidden;
.fc-event-vert.fc-event-end {
border-bottom-width: 1px;
border-bottom-left-radius: 3px;
border-bottom-right-radius: 3px;
} }
.fc-event-vert .fc-event-time { .fc-event-vert .fc-event-time {
white-space: nowrap; white-space: nowrap;
font-size: 10px; font-size: 10px;
} }
.fc-event-vert .fc-event-inner {
position: relative;
z-index: 2;
}
.fc-event-vert .fc-event-bg { /* makes the event lighter w/ a semi-transparent overlay */ .fc-event-vert .fc-event-bg { /* makes the event lighter w/ a semi-transparent overlay */
position: absolute; position: absolute;
@ -588,8 +559,8 @@ table.fc-border-separate {
width: 100%; width: 100%;
height: 100%; height: 100%;
background: #fff; background: #fff;
opacity: .3; opacity: .25;
filter: alpha(opacity=30); filter: alpha(opacity=25);
} }
.fc .ui-draggable-dragging .fc-event-bg, /* TODO: something nicer like .fc-opacity */ .fc .ui-draggable-dragging .fc-event-bg, /* TODO: something nicer like .fc-opacity */

View file

@ -1,23 +1,20 @@
/** /*!
* @preserve * FullCalendar v1.6.4
* FullCalendar v1.5.3 * Docs & License: http://arshaw.com/fullcalendar/
* http://arshaw.com/fullcalendar/ * (c) 2013 Adam Shaw
* */
/*
* Use fullcalendar.css for basic styling. * Use fullcalendar.css for basic styling.
* For event drag & drop, requires jQuery UI draggable. * For event drag & drop, requires jQuery UI draggable.
* For event resizing, requires jQuery UI resizable. * For event resizing, requires jQuery UI resizable.
*
* Copyright (c) 2011 Adam Shaw
* Dual licensed under the MIT and GPL licenses, located in
* MIT-LICENSE.txt and GPL-LICENSE.txt respectively.
*
* Date: Mon Feb 6 22:40:40 2012 -0800
*
*/ */
(function($, undefined) { (function($, undefined) {
;;
var defaults = { var defaults = {
// display // display
@ -29,6 +26,9 @@ var defaults = {
right: 'today prev,next' right: 'today prev,next'
}, },
weekends: true, weekends: true,
weekNumbers: false,
weekNumberCalculation: 'iso',
weekNumberTitle: 'W',
// editing // editing
//editable: false, //editable: false,
@ -66,10 +66,10 @@ var defaults = {
dayNames: ['Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday'], dayNames: ['Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday'],
dayNamesShort: ['Sun','Mon','Tue','Wed','Thu','Fri','Sat'], dayNamesShort: ['Sun','Mon','Tue','Wed','Thu','Fri','Sat'],
buttonText: { buttonText: {
prev: '&nbsp;&#9668;&nbsp;', prev: "<span class='fc-text-arrow'>&lsaquo;</span>",
next: '&nbsp;&#9658;&nbsp;', next: "<span class='fc-text-arrow'>&rsaquo;</span>",
prevYear: '&nbsp;&lt;&lt;&nbsp;', prevYear: "<span class='fc-text-arrow'>&laquo;</span>",
nextYear: '&nbsp;&gt;&gt;&nbsp;', nextYear: "<span class='fc-text-arrow'>&raquo;</span>",
today: 'today', today: 'today',
month: 'month', month: 'month',
week: 'week', week: 'week',
@ -86,7 +86,9 @@ var defaults = {
//selectable: false, //selectable: false,
unselectAuto: true, unselectAuto: true,
dropAccept: '*' dropAccept: '*',
handleWindowResize: true
}; };
@ -98,10 +100,10 @@ var rtlDefaults = {
right: 'title' right: 'title'
}, },
buttonText: { buttonText: {
prev: '&nbsp;&#9658;&nbsp;', prev: "<span class='fc-text-arrow'>&rsaquo;</span>",
next: '&nbsp;&#9668;&nbsp;', next: "<span class='fc-text-arrow'>&lsaquo;</span>",
prevYear: '&nbsp;&gt;&gt;&nbsp;', prevYear: "<span class='fc-text-arrow'>&raquo;</span>",
nextYear: '&nbsp;&lt;&lt;&nbsp;' nextYear: "<span class='fc-text-arrow'>&laquo;</span>"
}, },
buttonIcons: { buttonIcons: {
prev: 'circle-triangle-e', prev: 'circle-triangle-e',
@ -111,7 +113,9 @@ var rtlDefaults = {
var fc = $.fullCalendar = { version: "1.5.3" }; ;;
var fc = $.fullCalendar = { version: "1.6.4" };
var fcViews = fc.views = {}; var fcViews = fc.views = {};
@ -139,7 +143,8 @@ $.fn.fullCalendar = function(options) {
} }
return this; return this;
} }
options = options || {};
// would like to have this logic in EventManager, but needs to happen before options are recursively extended // would like to have this logic in EventManager, but needs to happen before options are recursively extended
var eventSources = options.eventSources || []; var eventSources = options.eventSources || [];
@ -177,6 +182,8 @@ function setDefaults(d) {
;;
function Calendar(element, options, eventSources) { function Calendar(element, options, eventSources) {
var t = this; var t = this;
@ -221,10 +228,8 @@ function Calendar(element, options, eventSources) {
var content; var content;
var tm; // for making theme classes var tm; // for making theme classes
var currentView; var currentView;
var viewInstances = {};
var elementOuterWidth; var elementOuterWidth;
var suggestedViewHeight; var suggestedViewHeight;
var absoluteViewElement;
var resizeUID = 0; var resizeUID = 0;
var ignoreWindowResize = 0; var ignoreWindowResize = 0;
var date = new Date(); var date = new Date();
@ -243,11 +248,11 @@ function Calendar(element, options, eventSources) {
function render(inc) { function render(inc) {
if (!content) { if (!content) {
initialRender(); initialRender();
}else{ }
else if (elementVisible()) {
// mainly for the public API
calcSize(); calcSize();
markSizesDirty(); _renderView(inc);
markEventsDirty();
renderView(inc);
} }
} }
@ -258,18 +263,28 @@ function Calendar(element, options, eventSources) {
if (options.isRTL) { if (options.isRTL) {
element.addClass('fc-rtl'); element.addClass('fc-rtl');
} }
else {
element.addClass('fc-ltr');
}
if (options.theme) { if (options.theme) {
element.addClass('ui-widget'); element.addClass('ui-widget');
} }
content = $("<div class='fc-content' style='position:relative'/>") content = $("<div class='fc-content' style='position:relative'/>")
.prependTo(element); .prependTo(element);
header = new Header(t, options); header = new Header(t, options);
headerElement = header.render(); headerElement = header.render();
if (headerElement) { if (headerElement) {
element.prepend(headerElement); element.prepend(headerElement);
} }
changeView(options.defaultView); changeView(options.defaultView);
$(window).resize(windowResize);
if (options.handleWindowResize) {
$(window).resize(windowResize);
}
// needed for IE in a 0x0 iframe, b/c when it is resized, never triggers a windowResize // needed for IE in a 0x0 iframe, b/c when it is resized, never triggers a windowResize
if (!bodyVisible()) { if (!bodyVisible()) {
lateRender(); lateRender();
@ -289,21 +304,27 @@ function Calendar(element, options, eventSources) {
function destroy() { function destroy() {
if (currentView) {
trigger('viewDestroy', currentView, currentView, currentView.element);
currentView.triggerEventDestroy();
}
$(window).unbind('resize', windowResize); $(window).unbind('resize', windowResize);
header.destroy(); header.destroy();
content.remove(); content.remove();
element.removeClass('fc fc-rtl ui-widget'); element.removeClass('fc fc-rtl ui-widget');
} }
function elementVisible() { function elementVisible() {
return _element.offsetWidth !== 0; return element.is(':visible');
} }
function bodyVisible() { function bodyVisible() {
return $('body')[0].offsetWidth !== 0; return $('body').is(':visible');
} }
@ -311,133 +332,97 @@ function Calendar(element, options, eventSources) {
/* View Rendering /* View Rendering
-----------------------------------------------------------------------------*/ -----------------------------------------------------------------------------*/
// TODO: improve view switching (still weird transition in IE, and FF has whiteout problem)
function changeView(newViewName) { function changeView(newViewName) {
if (!currentView || newViewName != currentView.name) { if (!currentView || newViewName != currentView.name) {
ignoreWindowResize++; // because setMinHeight might change the height before render (and subsequently setSize) is reached _changeView(newViewName);
unselect();
var oldView = currentView;
var newViewElement;
if (oldView) {
(oldView.beforeHide || noop)(); // called before changing min-height. if called after, scroll state is reset (in Opera)
setMinHeight(content, content.height());
oldView.element.hide();
}else{
setMinHeight(content, 1); // needs to be 1 (not 0) for IE7, or else view dimensions miscalculated
}
content.css('overflow', 'hidden');
currentView = viewInstances[newViewName];
if (currentView) {
currentView.element.show();
}else{
currentView = viewInstances[newViewName] = new fcViews[newViewName](
newViewElement = absoluteViewElement =
$("<div class='fc-view fc-view-" + newViewName + "' style='position:absolute'/>")
.appendTo(content),
t // the calendar object
);
}
if (oldView) {
header.deactivateButton(oldView.name);
}
header.activateButton(newViewName);
renderView(); // after height has been set, will make absoluteViewElement's position=relative, then set to null
content.css('overflow', '');
if (oldView) {
setMinHeight(content, 1);
}
if (!newViewElement) {
(currentView.afterShow || noop)(); // called after setting min-height/overflow, so in final scroll state (for Opera)
}
ignoreWindowResize--;
} }
} }
function _changeView(newViewName) {
ignoreWindowResize++;
if (currentView) {
trigger('viewDestroy', currentView, currentView, currentView.element);
unselect();
currentView.triggerEventDestroy(); // trigger 'eventDestroy' for each event
freezeContentHeight();
currentView.element.remove();
header.deactivateButton(currentView.name);
}
header.activateButton(newViewName);
currentView = new fcViews[newViewName](
$("<div class='fc-view fc-view-" + newViewName + "' style='position:relative'/>")
.appendTo(content),
t // the calendar object
);
renderView();
unfreezeContentHeight();
ignoreWindowResize--;
}
function renderView(inc) { function renderView(inc) {
if (elementVisible()) { if (
ignoreWindowResize++; // because renderEvents might temporarily change the height before setSize is reached !currentView.start || // never rendered before
inc || date < currentView.start || date >= currentView.end // or new date range
unselect(); ) {
if (elementVisible()) {
if (suggestedViewHeight === undefined) { _renderView(inc);
calcSize();
} }
var forceEventRender = false;
if (!currentView.start || inc || date < currentView.start || date >= currentView.end) {
// view must render an entire new date range (and refetch/render events)
currentView.render(date, inc || 0); // responsible for clearing events
setSize(true);
forceEventRender = true;
}
else if (currentView.sizeDirty) {
// view must resize (and rerender events)
currentView.clearEvents();
setSize();
forceEventRender = true;
}
else if (currentView.eventsDirty) {
currentView.clearEvents();
forceEventRender = true;
}
currentView.sizeDirty = false;
currentView.eventsDirty = false;
updateEvents(forceEventRender);
elementOuterWidth = element.outerWidth();
header.updateTitle(currentView.title);
var today = new Date();
if (today >= currentView.start && today < currentView.end) {
header.disableButton('today');
}else{
header.enableButton('today');
}
ignoreWindowResize--;
currentView.trigger('viewDisplay', _element);
} }
} }
function _renderView(inc) { // assumes elementVisible
ignoreWindowResize++;
if (currentView.start) { // already been rendered?
trigger('viewDestroy', currentView, currentView, currentView.element);
unselect();
clearEvents();
}
freezeContentHeight();
currentView.render(date, inc || 0); // the view's render method ONLY renders the skeleton, nothing else
setSize();
unfreezeContentHeight();
(currentView.afterRender || noop)();
updateTitle();
updateTodayButton();
trigger('viewRender', currentView, currentView, currentView.element);
currentView.trigger('viewDisplay', _element); // deprecated
ignoreWindowResize--;
getAndRenderEvents();
}
/* Resizing /* Resizing
-----------------------------------------------------------------------------*/ -----------------------------------------------------------------------------*/
function updateSize() { function updateSize() {
markSizesDirty();
if (elementVisible()) { if (elementVisible()) {
unselect();
clearEvents();
calcSize(); calcSize();
setSize(); setSize();
unselect(); renderEvents();
currentView.clearEvents();
currentView.renderEvents(events);
currentView.sizeDirty = false;
} }
} }
function markSizesDirty() { function calcSize() { // assumes elementVisible
$.each(viewInstances, function(i, inst) {
inst.sizeDirty = true;
});
}
function calcSize() {
if (options.contentHeight) { if (options.contentHeight) {
suggestedViewHeight = options.contentHeight; suggestedViewHeight = options.contentHeight;
} }
@ -450,15 +435,20 @@ function Calendar(element, options, eventSources) {
} }
function setSize(dateChanged) { // todo: dateChanged? function setSize() { // assumes elementVisible
ignoreWindowResize++;
currentView.setHeight(suggestedViewHeight, dateChanged); if (suggestedViewHeight === undefined) {
if (absoluteViewElement) { calcSize(); // for first time
absoluteViewElement.css('position', 'relative'); // NOTE: we don't want to recalculate on every renderView because
absoluteViewElement = null; // it could result in oscillating heights due to scrollbars.
} }
currentView.setWidth(content.width(), dateChanged);
ignoreWindowResize++;
currentView.setHeight(suggestedViewHeight);
currentView.setWidth(content.width());
ignoreWindowResize--; ignoreWindowResize--;
elementOuterWidth = element.outerWidth();
} }
@ -487,52 +477,85 @@ function Calendar(element, options, eventSources) {
/* Event Fetching/Rendering /* Event Fetching/Rendering
-----------------------------------------------------------------------------*/ -----------------------------------------------------------------------------*/
// TODO: going forward, most of this stuff should be directly handled by the view
function refetchEvents() { // can be called as an API method
clearEvents();
fetchAndRenderEvents();
}
function rerenderEvents(modifiedEventID) { // can be called as an API method
clearEvents();
renderEvents(modifiedEventID);
}
function renderEvents(modifiedEventID) { // TODO: remove modifiedEventID hack
if (elementVisible()) {
currentView.setEventData(events); // for View.js, TODO: unify with renderEvents
currentView.renderEvents(events, modifiedEventID); // actually render the DOM elements
currentView.trigger('eventAfterAllRender');
}
}
function clearEvents() {
currentView.triggerEventDestroy(); // trigger 'eventDestroy' for each event
currentView.clearEvents(); // actually remove the DOM elements
currentView.clearEventData(); // for View.js, TODO: unify with clearEvents
}
// fetches events if necessary, rerenders events if necessary (or if forced) function getAndRenderEvents() {
function updateEvents(forceRender) {
if (!options.lazyFetching || isFetchNeeded(currentView.visStart, currentView.visEnd)) { if (!options.lazyFetching || isFetchNeeded(currentView.visStart, currentView.visEnd)) {
refetchEvents(); fetchAndRenderEvents();
} }
else if (forceRender) { else {
rerenderEvents(); renderEvents();
} }
} }
function refetchEvents() { function fetchAndRenderEvents() {
fetchEvents(currentView.visStart, currentView.visEnd); // will call reportEvents fetchEvents(currentView.visStart, currentView.visEnd);
// ... will call reportEvents
// ... which will call renderEvents
} }
// called when event data arrives // called when event data arrives
function reportEvents(_events) { function reportEvents(_events) {
events = _events; events = _events;
rerenderEvents(); renderEvents();
} }
// called when a single event's data has been changed // called when a single event's data has been changed
function reportEventChange(eventID) { function reportEventChange(eventID) {
rerenderEvents(eventID); rerenderEvents(eventID);
} }
// attempts to rerenderEvents
function rerenderEvents(modifiedEventID) { /* Header Updating
markEventsDirty(); -----------------------------------------------------------------------------*/
if (elementVisible()) {
currentView.clearEvents();
currentView.renderEvents(events, modifiedEventID); function updateTitle() {
currentView.eventsDirty = false; header.updateTitle(currentView.title);
}
} }
function markEventsDirty() { function updateTodayButton() {
$.each(viewInstances, function(i, inst) { var today = new Date();
inst.eventsDirty = true; if (today >= currentView.start && today < currentView.end) {
}); header.disableButton('today');
}
else {
header.enableButton('today');
}
} }
@ -613,6 +636,29 @@ function Calendar(element, options, eventSources) {
function getDate() { function getDate() {
return cloneDate(date); return cloneDate(date);
} }
/* Height "Freezing"
-----------------------------------------------------------------------------*/
function freezeContentHeight() {
content.css({
width: '100%',
height: content.height(),
overflow: 'hidden'
});
}
function unfreezeContentHeight() {
content.css({
width: '',
height: '',
overflow: ''
});
}
@ -674,6 +720,8 @@ function Calendar(element, options, eventSources) {
} }
;;
function Header(calendar, options) { function Header(calendar, options) {
var t = this; var t = this;
@ -747,54 +795,47 @@ function Header(calendar, options) {
var text = smartProperty(options.buttonText, buttonName); // why are we using smartProperty here? var text = smartProperty(options.buttonText, buttonName); // why are we using smartProperty here?
var button = $( var button = $(
"<span class='fc-button fc-button-" + buttonName + " " + tm + "-state-default'>" + "<span class='fc-button fc-button-" + buttonName + " " + tm + "-state-default'>" +
"<span class='fc-button-inner'>" + (icon ?
"<span class='fc-button-content'>" + "<span class='fc-icon-wrap'>" +
(icon ? "<span class='ui-icon ui-icon-" + icon + "'/>" +
"<span class='fc-icon-wrap'>" + "</span>" :
"<span class='ui-icon ui-icon-" + icon + "'/>" + text
"</span>" : ) +
text
) +
"</span>" +
"<span class='fc-button-effect'><span></span></span>" +
"</span>" +
"</span>" "</span>"
); )
if (button) { .click(function() {
button if (!button.hasClass(tm + '-state-disabled')) {
.click(function() { buttonClick();
if (!button.hasClass(tm + '-state-disabled')) { }
buttonClick(); })
} .mousedown(function() {
}) button
.mousedown(function() { .not('.' + tm + '-state-active')
.not('.' + tm + '-state-disabled')
.addClass(tm + '-state-down');
})
.mouseup(function() {
button.removeClass(tm + '-state-down');
})
.hover(
function() {
button button
.not('.' + tm + '-state-active') .not('.' + tm + '-state-active')
.not('.' + tm + '-state-disabled') .not('.' + tm + '-state-disabled')
.addClass(tm + '-state-down'); .addClass(tm + '-state-hover');
}) },
.mouseup(function() { function() {
button.removeClass(tm + '-state-down'); button
}) .removeClass(tm + '-state-hover')
.hover( .removeClass(tm + '-state-down');
function() { }
button )
.not('.' + tm + '-state-active') .appendTo(e);
.not('.' + tm + '-state-disabled') disableTextSelection(button);
.addClass(tm + '-state-hover'); if (!prevButton) {
}, button.addClass(tm + '-corner-left');
function() {
button
.removeClass(tm + '-state-hover')
.removeClass(tm + '-state-down');
}
)
.appendTo(e);
if (!prevButton) {
button.addClass(tm + '-corner-left');
}
prevButton = button;
} }
prevButton = button;
} }
} }
}); });
@ -839,6 +880,8 @@ function Header(calendar, options) {
} }
;;
fc.sourceNormalizers = []; fc.sourceNormalizers = [];
fc.sourceFetchers = []; fc.sourceFetchers = [];
@ -914,6 +957,16 @@ function EventManager(options, _sources) {
_fetchEventSource(source, function(events) { _fetchEventSource(source, function(events) {
if (fetchID == currentFetchID) { if (fetchID == currentFetchID) {
if (events) { if (events) {
if (options.eventDataTransform) {
events = $.map(events, options.eventDataTransform);
}
if (source.eventDataTransform) {
events = $.map(events, source.eventDataTransform);
}
// TODO: this technique is not ideal for static array event sources.
// For arrays, we'll want to process all events right in the beginning, then never again.
for (var i=0; i<events.length; i++) { for (var i=0; i<events.length; i++) {
events[i].source = source; events[i].source = source;
normalizeEvent(events[i]); normalizeEvent(events[i]);
@ -966,7 +1019,22 @@ function EventManager(options, _sources) {
var success = source.success; var success = source.success;
var error = source.error; var error = source.error;
var complete = source.complete; var complete = source.complete;
var data = $.extend({}, source.data || {});
// retrieve any outbound GET/POST $.ajax data from the options
var customData;
if ($.isFunction(source.data)) {
// supplied as a function that returns a key/value object
customData = source.data();
}
else {
// supplied as a straight key/value object
customData = source.data;
}
// use a copy of the custom data so we can modify the parameters
// and not affect the passed-in object.
var data = $.extend({}, customData || {});
var startParam = firstDefined(source.startParam, options.startParam); var startParam = firstDefined(source.startParam, options.startParam);
var endParam = firstDefined(source.endParam, options.endParam); var endParam = firstDefined(source.endParam, options.endParam);
if (startParam) { if (startParam) {
@ -975,6 +1043,7 @@ function EventManager(options, _sources) {
if (endParam) { if (endParam) {
data[endParam] = Math.round(+rangeEnd / 1000); data[endParam] = Math.round(+rangeEnd / 1000);
} }
pushLoading(); pushLoading();
$.ajax($.extend({}, ajaxDefaults, source, { $.ajax($.extend({}, ajaxDefaults, source, {
data: data, data: data,
@ -1074,7 +1143,7 @@ function EventManager(options, _sources) {
e.className = event.className; e.className = event.className;
e.editable = event.editable; e.editable = event.editable;
e.color = event.color; e.color = event.color;
e.backgroudColor = event.backgroudColor; e.backgroundColor = event.backgroundColor;
e.borderColor = event.borderColor; e.borderColor = event.borderColor;
e.textColor = event.textColor; e.textColor = event.textColor;
normalizeEvent(e); normalizeEvent(e);
@ -1147,14 +1216,14 @@ function EventManager(options, _sources) {
function pushLoading() { function pushLoading() {
if (!loadingLevel++) { if (!loadingLevel++) {
trigger('loading', null, true); trigger('loading', null, true, getView());
} }
} }
function popLoading() { function popLoading() {
if (!--loadingLevel) { if (!--loadingLevel) {
trigger('loading', null, false); trigger('loading', null, false, getView());
} }
} }
@ -1227,6 +1296,8 @@ function EventManager(options, _sources) {
} }
;;
fc.addDays = addDays; fc.addDays = addDays;
fc.cloneDate = cloneDate; fc.cloneDate = cloneDate;
@ -1331,15 +1402,6 @@ function zeroDate() { // returns a Date with time 00:00:00 and dateOfMonth=1
} }
function skipWeekend(date, inc, excl) {
inc = inc || 1;
while (!date.getDay() || (excl && date.getDay()==1 || !excl && date.getDay()==6)) {
addDays(date, inc);
}
return date;
}
function dayDiff(d1, d2) { // d1 - d2 function dayDiff(d1, d2) { // d1 - d2
return Math.round((cloneDate(d1, true) - cloneDate(d2, true)) / DAY_MS); return Math.round((cloneDate(d1, true) - cloneDate(d2, true)) / DAY_MS);
} }
@ -1581,10 +1643,38 @@ var dateFormatters = {
return 'th'; return 'th';
} }
return ['st', 'nd', 'rd'][date%10-1] || 'th'; return ['st', 'nd', 'rd'][date%10-1] || 'th';
},
w : function(d, o) { // local
return o.weekNumberCalculation(d);
},
W : function(d) { // ISO
return iso8601Week(d);
} }
}; };
fc.dateFormatters = dateFormatters;
/* thanks jQuery UI (https://github.com/jquery/jquery-ui/blob/master/ui/jquery.ui.datepicker.js)
*
* Set as calculateWeek to determine the week of the year based on the ISO 8601 definition.
* `date` - the date to get the week for
* `number` - the number of the week within the year that contains this date
*/
function iso8601Week(date) {
var time;
var checkDate = new Date(date.getTime());
// Find Thursday of this week starting on Monday
checkDate.setDate(checkDate.getDate() + 4 - (checkDate.getDay() || 7));
time = checkDate.getTime();
checkDate.setMonth(0); // Compare with Jan 1
checkDate.setDate(1);
return Math.floor(Math.round((time - checkDate) / 86400000) / 7) + 1;
}
;;
fc.applyAll = applyAll; fc.applyAll = applyAll;
@ -1605,95 +1695,7 @@ function exclEndDay(event) {
function _exclEndDay(end, allDay) { function _exclEndDay(end, allDay) {
end = cloneDate(end); end = cloneDate(end);
return allDay || end.getHours() || end.getMinutes() ? addDays(end, 1) : clearTime(end); return allDay || end.getHours() || end.getMinutes() ? addDays(end, 1) : clearTime(end);
} // why don't we check for seconds/ms too?
function segCmp(a, b) {
return (b.msLength - a.msLength) * 100 + (a.event.start - b.event.start);
}
function segsCollide(seg1, seg2) {
return seg1.end > seg2.start && seg1.start < seg2.end;
}
/* Event Sorting
-----------------------------------------------------------------------------*/
// event rendering utilities
function sliceSegs(events, visEventEnds, start, end) {
var segs = [],
i, len=events.length, event,
eventStart, eventEnd,
segStart, segEnd,
isStart, isEnd;
for (i=0; i<len; i++) {
event = events[i];
eventStart = event.start;
eventEnd = visEventEnds[i];
if (eventEnd > start && eventStart < end) {
if (eventStart < start) {
segStart = cloneDate(start);
isStart = false;
}else{
segStart = eventStart;
isStart = true;
}
if (eventEnd > end) {
segEnd = cloneDate(end);
isEnd = false;
}else{
segEnd = eventEnd;
isEnd = true;
}
segs.push({
event: event,
start: segStart,
end: segEnd,
isStart: isStart,
isEnd: isEnd,
msLength: segEnd - segStart
});
}
}
return segs.sort(segCmp);
}
// event rendering calculation utilities
function stackSegs(segs) {
var levels = [],
i, len = segs.length, seg,
j, collide, k;
for (i=0; i<len; i++) {
seg = segs[i];
j = 0; // the level index where seg should belong
while (true) {
collide = false;
if (levels[j]) {
for (k=0; k<levels[j].length; k++) {
if (segsCollide(levels[j][k], seg)) {
collide = true;
break;
}
}
}
if (collide) {
j++;
}else{
break;
}
}
if (levels[j]) {
levels[j].push(seg);
}else{
levels[j] = [seg];
}
}
return levels;
} }
@ -1742,29 +1744,26 @@ function setOuterHeight(element, height, includeMargins) {
} }
// TODO: curCSS has been deprecated (jQuery 1.4.3 - 10/16/2010)
function hsides(element, includeMargins) { function hsides(element, includeMargins) {
return hpadding(element) + hborders(element) + (includeMargins ? hmargins(element) : 0); return hpadding(element) + hborders(element) + (includeMargins ? hmargins(element) : 0);
} }
function hpadding(element) { function hpadding(element) {
return (parseFloat($.curCSS(element[0], 'paddingLeft', true)) || 0) + return (parseFloat($.css(element[0], 'paddingLeft', true)) || 0) +
(parseFloat($.curCSS(element[0], 'paddingRight', true)) || 0); (parseFloat($.css(element[0], 'paddingRight', true)) || 0);
} }
function hmargins(element) { function hmargins(element) {
return (parseFloat($.curCSS(element[0], 'marginLeft', true)) || 0) + return (parseFloat($.css(element[0], 'marginLeft', true)) || 0) +
(parseFloat($.curCSS(element[0], 'marginRight', true)) || 0); (parseFloat($.css(element[0], 'marginRight', true)) || 0);
} }
function hborders(element) { function hborders(element) {
return (parseFloat($.curCSS(element[0], 'borderLeftWidth', true)) || 0) + return (parseFloat($.css(element[0], 'borderLeftWidth', true)) || 0) +
(parseFloat($.curCSS(element[0], 'borderRightWidth', true)) || 0); (parseFloat($.css(element[0], 'borderRightWidth', true)) || 0);
} }
@ -1774,29 +1773,20 @@ function vsides(element, includeMargins) {
function vpadding(element) { function vpadding(element) {
return (parseFloat($.curCSS(element[0], 'paddingTop', true)) || 0) + return (parseFloat($.css(element[0], 'paddingTop', true)) || 0) +
(parseFloat($.curCSS(element[0], 'paddingBottom', true)) || 0); (parseFloat($.css(element[0], 'paddingBottom', true)) || 0);
} }
function vmargins(element) { function vmargins(element) {
return (parseFloat($.curCSS(element[0], 'marginTop', true)) || 0) + return (parseFloat($.css(element[0], 'marginTop', true)) || 0) +
(parseFloat($.curCSS(element[0], 'marginBottom', true)) || 0); (parseFloat($.css(element[0], 'marginBottom', true)) || 0);
} }
function vborders(element) { function vborders(element) {
return (parseFloat($.curCSS(element[0], 'borderTopWidth', true)) || 0) + return (parseFloat($.css(element[0], 'borderTopWidth', true)) || 0) +
(parseFloat($.curCSS(element[0], 'borderBottomWidth', true)) || 0); (parseFloat($.css(element[0], 'borderBottomWidth', true)) || 0);
}
function setMinHeight(element, height) {
height = (typeof height == 'number' ? height + 'px' : height);
element.each(function(i, _element) {
_element.style.cssText += ';min-height:' + height + ';_height:' + height;
// why can't we just use .css() ? i forget
});
} }
@ -1812,7 +1802,7 @@ function setMinHeight(element, height) {
function noop() { } function noop() { }
function cmp(a, b) { function dateCompare(a, b) {
return a - b; return a - b;
} }
@ -1853,11 +1843,6 @@ function htmlEscape(s) {
} }
function cssKey(_element) {
return _element.id + '/' + _element.className + '/' + _element.style.cssText.replace(/(^|;)\s*(top|left|width|height)\s*:[^;]*/ig, '');
}
function disableTextSelection(element) { function disableTextSelection(element) {
element element
.attr('unselectable', 'on') .attr('unselectable', 'on')
@ -1956,6 +1941,7 @@ function firstDefined() {
} }
;;
fcViews.month = MonthView; fcViews.month = MonthView;
@ -1971,44 +1957,56 @@ function MonthView(element, calendar) {
BasicView.call(t, element, calendar, 'month'); BasicView.call(t, element, calendar, 'month');
var opt = t.opt; var opt = t.opt;
var renderBasic = t.renderBasic; var renderBasic = t.renderBasic;
var skipHiddenDays = t.skipHiddenDays;
var getCellsPerWeek = t.getCellsPerWeek;
var formatDate = calendar.formatDate; var formatDate = calendar.formatDate;
function render(date, delta) { function render(date, delta) {
if (delta) { if (delta) {
addMonths(date, delta); addMonths(date, delta);
date.setDate(1); date.setDate(1);
} }
var firstDay = opt('firstDay');
var start = cloneDate(date, true); var start = cloneDate(date, true);
start.setDate(1); start.setDate(1);
var end = addMonths(cloneDate(start), 1); var end = addMonths(cloneDate(start), 1);
var visStart = cloneDate(start); var visStart = cloneDate(start);
addDays(visStart, -((visStart.getDay() - firstDay + 7) % 7));
skipHiddenDays(visStart);
var visEnd = cloneDate(end); var visEnd = cloneDate(end);
var firstDay = opt('firstDay'); addDays(visEnd, (7 - visEnd.getDay() + firstDay) % 7);
var nwe = opt('weekends') ? 0 : 1; skipHiddenDays(visEnd, -1, true);
if (nwe) {
skipWeekend(visStart); var colCnt = getCellsPerWeek();
skipWeekend(visEnd, -1, true); var rowCnt = Math.round(dayDiff(visEnd, visStart) / 7); // should be no need for Math.round
}
addDays(visStart, -((visStart.getDay() - Math.max(firstDay, nwe) + 7) % 7));
addDays(visEnd, (7 - visEnd.getDay() + Math.max(firstDay, nwe)) % 7);
var rowCnt = Math.round((visEnd - visStart) / (DAY_MS * 7));
if (opt('weekMode') == 'fixed') { if (opt('weekMode') == 'fixed') {
addDays(visEnd, (6 - rowCnt) * 7); addDays(visEnd, (6 - rowCnt) * 7); // add weeks to make up for it
rowCnt = 6; rowCnt = 6;
} }
t.title = formatDate(start, opt('titleFormat')); t.title = formatDate(start, opt('titleFormat'));
t.start = start; t.start = start;
t.end = end; t.end = end;
t.visStart = visStart; t.visStart = visStart;
t.visEnd = visEnd; t.visEnd = visEnd;
renderBasic(6, rowCnt, nwe ? 5 : 7, true);
renderBasic(rowCnt, colCnt, true);
} }
} }
;;
fcViews.basicWeek = BasicWeekView; fcViews.basicWeek = BasicWeekView;
function BasicWeekView(element, calendar) { function BasicWeekView(element, calendar) {
@ -2023,41 +2021,48 @@ function BasicWeekView(element, calendar) {
BasicView.call(t, element, calendar, 'basicWeek'); BasicView.call(t, element, calendar, 'basicWeek');
var opt = t.opt; var opt = t.opt;
var renderBasic = t.renderBasic; var renderBasic = t.renderBasic;
var skipHiddenDays = t.skipHiddenDays;
var getCellsPerWeek = t.getCellsPerWeek;
var formatDates = calendar.formatDates; var formatDates = calendar.formatDates;
function render(date, delta) { function render(date, delta) {
if (delta) { if (delta) {
addDays(date, delta * 7); addDays(date, delta * 7);
} }
var start = addDays(cloneDate(date), -((date.getDay() - opt('firstDay') + 7) % 7)); var start = addDays(cloneDate(date), -((date.getDay() - opt('firstDay') + 7) % 7));
var end = addDays(cloneDate(start), 7); var end = addDays(cloneDate(start), 7);
var visStart = cloneDate(start); var visStart = cloneDate(start);
skipHiddenDays(visStart);
var visEnd = cloneDate(end); var visEnd = cloneDate(end);
var weekends = opt('weekends'); skipHiddenDays(visEnd, -1, true);
if (!weekends) {
skipWeekend(visStart); var colCnt = getCellsPerWeek();
skipWeekend(visEnd, -1, true);
} t.start = start;
t.end = end;
t.visStart = visStart;
t.visEnd = visEnd;
t.title = formatDates( t.title = formatDates(
visStart, visStart,
addDays(cloneDate(visEnd), -1), addDays(cloneDate(visEnd), -1),
opt('titleFormat') opt('titleFormat')
); );
t.start = start;
t.end = end; renderBasic(1, colCnt, false);
t.visStart = visStart;
t.visEnd = visEnd;
renderBasic(1, 1, weekends ? 7 : 5, false);
} }
} }
fcViews.basicDay = BasicDayView; ;;
//TODO: when calendar's date starts out on a weekend, shouldn't happen fcViews.basicDay = BasicDayView;
function BasicDayView(element, calendar) { function BasicDayView(element, calendar) {
@ -2072,26 +2077,33 @@ function BasicDayView(element, calendar) {
BasicView.call(t, element, calendar, 'basicDay'); BasicView.call(t, element, calendar, 'basicDay');
var opt = t.opt; var opt = t.opt;
var renderBasic = t.renderBasic; var renderBasic = t.renderBasic;
var skipHiddenDays = t.skipHiddenDays;
var formatDate = calendar.formatDate; var formatDate = calendar.formatDate;
function render(date, delta) { function render(date, delta) {
if (delta) { if (delta) {
addDays(date, delta); addDays(date, delta);
if (!opt('weekends')) {
skipWeekend(date, delta < 0 ? -1 : 1);
}
} }
skipHiddenDays(date, delta < 0 ? -1 : 1);
var start = cloneDate(date, true);
var end = addDays(cloneDate(start), 1);
t.title = formatDate(date, opt('titleFormat')); t.title = formatDate(date, opt('titleFormat'));
t.start = t.visStart = cloneDate(date, true);
t.end = t.visEnd = addDays(cloneDate(t.start), 1); t.start = t.visStart = start;
renderBasic(1, 1, 1, false); t.end = t.visEnd = end;
renderBasic(1, 1, false);
} }
} }
;;
setDefaults({ setDefaults({
weekMode: 'fixed' weekMode: 'fixed'
}); });
@ -2114,14 +2126,12 @@ function BasicView(element, calendar, viewName) {
t.dragStop = dragStop; t.dragStop = dragStop;
t.defaultEventEnd = defaultEventEnd; t.defaultEventEnd = defaultEventEnd;
t.getHoverListener = function() { return hoverListener }; t.getHoverListener = function() { return hoverListener };
t.colLeft = colLeft;
t.colRight = colRight;
t.colContentLeft = colContentLeft; t.colContentLeft = colContentLeft;
t.colContentRight = colContentRight; t.colContentRight = colContentRight;
t.dayOfWeekCol = dayOfWeekCol; t.getIsCellAllDay = function() { return true };
t.dateCell = dateCell;
t.cellDate = cellDate;
t.cellIsAllDay = function() { return true };
t.allDayRow = allDayRow; t.allDayRow = allDayRow;
t.allDayBounds = allDayBounds;
t.getRowCnt = function() { return rowCnt }; t.getRowCnt = function() { return rowCnt };
t.getColCnt = function() { return colCnt }; t.getColCnt = function() { return colCnt };
t.getColWidth = function() { return colWidth }; t.getColWidth = function() { return colWidth };
@ -2135,38 +2145,45 @@ function BasicView(element, calendar, viewName) {
BasicEventRenderer.call(t); BasicEventRenderer.call(t);
var opt = t.opt; var opt = t.opt;
var trigger = t.trigger; var trigger = t.trigger;
var clearEvents = t.clearEvents;
var renderOverlay = t.renderOverlay; var renderOverlay = t.renderOverlay;
var clearOverlays = t.clearOverlays; var clearOverlays = t.clearOverlays;
var daySelectionMousedown = t.daySelectionMousedown; var daySelectionMousedown = t.daySelectionMousedown;
var cellToDate = t.cellToDate;
var dateToCell = t.dateToCell;
var rangeToSegments = t.rangeToSegments;
var formatDate = calendar.formatDate; var formatDate = calendar.formatDate;
// locals // locals
var table;
var head; var head;
var headCells; var headCells;
var body; var body;
var bodyRows; var bodyRows;
var bodyCells; var bodyCells;
var bodyFirstCells; var bodyFirstCells;
var bodyCellTopInners; var firstRowCellInners;
var firstRowCellContentInners;
var daySegmentContainer; var daySegmentContainer;
var viewWidth; var viewWidth;
var viewHeight; var viewHeight;
var colWidth; var colWidth;
var weekNumberWidth;
var rowCnt, colCnt; var rowCnt, colCnt;
var showNumbers;
var coordinateGrid; var coordinateGrid;
var hoverListener; var hoverListener;
var colPositions;
var colContentPositions; var colContentPositions;
var rtl, dis, dit;
var firstDay;
var nwe;
var tm; var tm;
var colFormat; var colFormat;
var showWeekNumbers;
var weekNumberTitle;
var weekNumberFormat;
@ -2177,154 +2194,212 @@ function BasicView(element, calendar, viewName) {
disableTextSelection(element.addClass('fc-grid')); disableTextSelection(element.addClass('fc-grid'));
function renderBasic(maxr, r, c, showNumbers) { function renderBasic(_rowCnt, _colCnt, _showNumbers) {
rowCnt = r; rowCnt = _rowCnt;
colCnt = c; colCnt = _colCnt;
showNumbers = _showNumbers;
updateOptions(); updateOptions();
var firstTime = !body;
if (firstTime) { if (!body) {
buildSkeleton(maxr, showNumbers); buildEventContainer();
}else{
clearEvents();
} }
updateCells(firstTime);
buildTable();
} }
function updateOptions() { function updateOptions() {
rtl = opt('isRTL');
if (rtl) {
dis = -1;
dit = colCnt - 1;
}else{
dis = 1;
dit = 0;
}
firstDay = opt('firstDay');
nwe = opt('weekends') ? 0 : 1;
tm = opt('theme') ? 'ui' : 'fc'; tm = opt('theme') ? 'ui' : 'fc';
colFormat = opt('columnFormat'); colFormat = opt('columnFormat');
// week # options. (TODO: bad, logic also in other views)
showWeekNumbers = opt('weekNumbers');
weekNumberTitle = opt('weekNumberTitle');
if (opt('weekNumberCalculation') != 'iso') {
weekNumberFormat = "w";
}
else {
weekNumberFormat = "W";
}
} }
function buildEventContainer() {
function buildSkeleton(maxRowCnt, showNumbers) {
var s;
var headerClass = tm + "-widget-header";
var contentClass = tm + "-widget-content";
var i, j;
var table;
s =
"<table class='fc-border-separate' style='width:100%' cellspacing='0'>" +
"<thead>" +
"<tr>";
for (i=0; i<colCnt; i++) {
s +=
"<th class='fc- " + headerClass + "'/>"; // need fc- for setDayID
}
s +=
"</tr>" +
"</thead>" +
"<tbody>";
for (i=0; i<maxRowCnt; i++) {
s +=
"<tr class='fc-week" + i + "'>";
for (j=0; j<colCnt; j++) {
s +=
"<td class='fc- " + contentClass + " fc-day" + (i*colCnt+j) + "'>" + // need fc- for setDayID
"<div>" +
(showNumbers ?
"<div class='fc-day-number'/>" :
''
) +
"<div class='fc-day-content'>" +
"<div style='position:relative'>&nbsp;</div>" +
"</div>" +
"</div>" +
"</td>";
}
s +=
"</tr>";
}
s +=
"</tbody>" +
"</table>";
table = $(s).appendTo(element);
head = table.find('thead');
headCells = head.find('th');
body = table.find('tbody');
bodyRows = body.find('tr');
bodyCells = body.find('td');
bodyFirstCells = bodyCells.filter(':first-child');
bodyCellTopInners = bodyRows.eq(0).find('div.fc-day-content div');
markFirstLast(head.add(head.find('tr'))); // marks first+last tr/th's
markFirstLast(bodyRows); // marks first+last td's
bodyRows.eq(0).addClass('fc-first'); // fc-last is done in updateCells
dayBind(bodyCells);
daySegmentContainer = daySegmentContainer =
$("<div style='position:absolute;z-index:8;top:0;left:0'/>") $("<div class='fc-event-container' style='position:absolute;z-index:8;top:0;left:0'/>")
.appendTo(element); .appendTo(element);
} }
function buildTable() {
function updateCells(firstTime) { var html = buildTableHTML();
var dowDirty = firstTime || rowCnt == 1; // could the cells' day-of-weeks need updating?
if (table) {
table.remove();
}
table = $(html).appendTo(element);
head = table.find('thead');
headCells = head.find('.fc-day-header');
body = table.find('tbody');
bodyRows = body.find('tr');
bodyCells = body.find('.fc-day');
bodyFirstCells = bodyRows.find('td:first-child');
firstRowCellInners = bodyRows.eq(0).find('.fc-day > div');
firstRowCellContentInners = bodyRows.eq(0).find('.fc-day-content > div');
markFirstLast(head.add(head.find('tr'))); // marks first+last tr/th's
markFirstLast(bodyRows); // marks first+last td's
bodyRows.eq(0).addClass('fc-first');
bodyRows.filter(':last').addClass('fc-last');
bodyCells.each(function(i, _cell) {
var date = cellToDate(
Math.floor(i / colCnt),
i % colCnt
);
trigger('dayRender', t, date, $(_cell));
});
dayBind(bodyCells);
}
/* HTML Building
-----------------------------------------------------------*/
function buildTableHTML() {
var html =
"<table class='fc-border-separate' style='width:100%' cellspacing='0'>" +
buildHeadHTML() +
buildBodyHTML() +
"</table>";
return html;
}
function buildHeadHTML() {
var headerClass = tm + "-widget-header";
var html = '';
var col;
var date;
html += "<thead><tr>";
if (showWeekNumbers) {
html +=
"<th class='fc-week-number " + headerClass + "'>" +
htmlEscape(weekNumberTitle) +
"</th>";
}
for (col=0; col<colCnt; col++) {
date = cellToDate(0, col);
html +=
"<th class='fc-day-header fc-" + dayIDs[date.getDay()] + " " + headerClass + "'>" +
htmlEscape(formatDate(date, colFormat)) +
"</th>";
}
html += "</tr></thead>";
return html;
}
function buildBodyHTML() {
var contentClass = tm + "-widget-content";
var html = '';
var row;
var col;
var date;
html += "<tbody>";
for (row=0; row<rowCnt; row++) {
html += "<tr class='fc-week'>";
if (showWeekNumbers) {
date = cellToDate(row, 0);
html +=
"<td class='fc-week-number " + contentClass + "'>" +
"<div>" +
htmlEscape(formatDate(date, weekNumberFormat)) +
"</div>" +
"</td>";
}
for (col=0; col<colCnt; col++) {
date = cellToDate(row, col);
html += buildCellHTML(date);
}
html += "</tr>";
}
html += "</tbody>";
return html;
}
function buildCellHTML(date) {
var contentClass = tm + "-widget-content";
var month = t.start.getMonth(); var month = t.start.getMonth();
var today = clearTime(new Date()); var today = clearTime(new Date());
var cell; var html = '';
var date; var classNames = [
var row; 'fc-day',
'fc-' + dayIDs[date.getDay()],
if (dowDirty) { contentClass
headCells.each(function(i, _cell) { ];
cell = $(_cell);
date = indexDate(i); if (date.getMonth() != month) {
cell.html(formatDate(date, colFormat)); classNames.push('fc-other-month');
setDayID(cell, date);
});
} }
if (+date == +today) {
bodyCells.each(function(i, _cell) { classNames.push(
cell = $(_cell); 'fc-today',
date = indexDate(i); tm + '-state-highlight'
if (date.getMonth() == month) { );
cell.removeClass('fc-other-month'); }
}else{ else if (date < today) {
cell.addClass('fc-other-month'); classNames.push('fc-past');
} }
if (+date == +today) { else {
cell.addClass(tm + '-state-highlight fc-today'); classNames.push('fc-future');
}else{ }
cell.removeClass(tm + '-state-highlight fc-today');
} html +=
cell.find('div.fc-day-number').text(date.getDate()); "<td" +
if (dowDirty) { " class='" + classNames.join(' ') + "'" +
setDayID(cell, date); " data-date='" + formatDate(date, 'yyyy-MM-dd') + "'" +
} ">" +
}); "<div>";
bodyRows.each(function(i, _row) { if (showNumbers) {
row = $(_row); html += "<div class='fc-day-number'>" + date.getDate() + "</div>";
if (i < rowCnt) { }
row.show();
if (i == rowCnt-1) { html +=
row.addClass('fc-last'); "<div class='fc-day-content'>" +
}else{ "<div style='position:relative'>&nbsp;</div>" +
row.removeClass('fc-last'); "</div>" +
} "</div>" +
}else{ "</td>";
row.hide();
} return html;
});
} }
/* Dimensions
-----------------------------------------------------------*/
function setHeight(height) { function setHeight(height) {
@ -2345,8 +2420,8 @@ function BasicView(element, calendar, viewName) {
bodyFirstCells.each(function(i, _cell) { bodyFirstCells.each(function(i, _cell) {
if (i < rowCnt) { if (i < rowCnt) {
cell = $(_cell); cell = $(_cell);
setMinHeight( cell.find('> div').css(
cell.find('> div'), 'min-height',
(i==rowCnt-1 ? rowHeightLast : rowHeight) - vsides(cell) (i==rowCnt-1 ? rowHeightLast : rowHeight) - vsides(cell)
); );
} }
@ -2357,8 +2432,15 @@ function BasicView(element, calendar, viewName) {
function setWidth(width) { function setWidth(width) {
viewWidth = width; viewWidth = width;
colPositions.clear();
colContentPositions.clear(); colContentPositions.clear();
colWidth = Math.floor(viewWidth / colCnt);
weekNumberWidth = 0;
if (showWeekNumbers) {
weekNumberWidth = head.find('th.fc-week-number').outerWidth();
}
colWidth = Math.floor((viewWidth - weekNumberWidth) / colCnt);
setOuterWidth(headCells.slice(0, -1), colWidth); setOuterWidth(headCells.slice(0, -1), colWidth);
} }
@ -2376,8 +2458,7 @@ function BasicView(element, calendar, viewName) {
function dayClick(ev) { function dayClick(ev) {
if (!opt('selectable')) { // if selectable, SelectionManager will worry about dayClick if (!opt('selectable')) { // if selectable, SelectionManager will worry about dayClick
var index = parseInt(this.className.match(/fc\-day(\d+)/)[1]); // TODO: maybe use .data var date = parseISO8601($(this).data('date'));
var date = indexDate(index);
trigger('dayClick', this, date, true, ev); trigger('dayClick', this, date, true, ev);
} }
} }
@ -2386,35 +2467,30 @@ function BasicView(element, calendar, viewName) {
/* Semi-transparent Overlay Helpers /* Semi-transparent Overlay Helpers
------------------------------------------------------*/ ------------------------------------------------------*/
// TODO: should be consolidated with AgendaView's methods
function renderDayOverlay(overlayStart, overlayEnd, refreshCoordinateGrid) { // overlayEnd is exclusive function renderDayOverlay(overlayStart, overlayEnd, refreshCoordinateGrid) { // overlayEnd is exclusive
if (refreshCoordinateGrid) { if (refreshCoordinateGrid) {
coordinateGrid.build(); coordinateGrid.build();
} }
var rowStart = cloneDate(t.visStart);
var rowEnd = addDays(cloneDate(rowStart), colCnt); var segments = rangeToSegments(overlayStart, overlayEnd);
for (var i=0; i<rowCnt; i++) {
var stretchStart = new Date(Math.max(rowStart, overlayStart)); for (var i=0; i<segments.length; i++) {
var stretchEnd = new Date(Math.min(rowEnd, overlayEnd)); var segment = segments[i];
if (stretchStart < stretchEnd) { dayBind(
var colStart, colEnd; renderCellOverlay(
if (rtl) { segment.row,
colStart = dayDiff(stretchEnd, rowStart)*dis+dit+1; segment.leftCol,
colEnd = dayDiff(stretchStart, rowStart)*dis+dit+1; segment.row,
}else{ segment.rightCol
colStart = dayDiff(stretchStart, rowStart); )
colEnd = dayDiff(stretchEnd, rowStart); );
}
dayBind(
renderCellOverlay(i, colStart, i, colEnd-1)
);
}
addDays(rowStart, 7);
addDays(rowEnd, 7);
} }
} }
function renderCellOverlay(row0, col0, row1, col1) { // row1,col1 is inclusive function renderCellOverlay(row0, col0, row1, col1) { // row1,col1 is inclusive
var rect = coordinateGrid.rect(row0, col0, row1, col1, element); var rect = coordinateGrid.rect(row0, col0, row1, col1, element);
@ -2443,7 +2519,7 @@ function BasicView(element, calendar, viewName) {
function reportDayClick(date, allDay, ev) { function reportDayClick(date, allDay, ev) {
var cell = dateCell(date); var cell = dateToCell(date);
var _element = bodyCells[cell.row*colCnt + cell.col]; var _element = bodyCells[cell.row*colCnt + cell.col];
trigger('dayClick', _element, date, allDay, ev); trigger('dayClick', _element, date, allDay, ev);
} }
@ -2468,7 +2544,7 @@ function BasicView(element, calendar, viewName) {
var cell = hoverListener.stop(); var cell = hoverListener.stop();
clearOverlays(); clearOverlays();
if (cell) { if (cell) {
var d = cellDate(cell); var d = cellToDate(cell);
trigger('drop', _dragElement, d, true, ev, ui); trigger('drop', _dragElement, d, true, ev, ui);
} }
} }
@ -2513,10 +2589,23 @@ function BasicView(element, calendar, viewName) {
hoverListener = new HoverListener(coordinateGrid); hoverListener = new HoverListener(coordinateGrid);
colPositions = new HorizontalPositionCache(function(col) {
colContentPositions = new HorizontalPositionCache(function(col) { return firstRowCellInners.eq(col);
return bodyCellTopInners.eq(col);
}); });
colContentPositions = new HorizontalPositionCache(function(col) {
return firstRowCellContentInners.eq(col);
});
function colLeft(col) {
return colPositions.left(col);
}
function colRight(col) {
return colPositions.right(col);
}
function colContentLeft(col) { function colContentLeft(col) {
@ -2529,195 +2618,43 @@ function BasicView(element, calendar, viewName) {
} }
function dateCell(date) {
return {
row: Math.floor(dayDiff(date, t.visStart) / 7),
col: dayOfWeekCol(date.getDay())
};
}
function cellDate(cell) {
return _cellDate(cell.row, cell.col);
}
function _cellDate(row, col) {
return addDays(cloneDate(t.visStart), row*7 + col*dis+dit);
// what about weekends in middle of week?
}
function indexDate(index) {
return _cellDate(Math.floor(index/colCnt), index%colCnt);
}
function dayOfWeekCol(dayOfWeek) {
return ((dayOfWeek - Math.max(firstDay, nwe) + colCnt) % colCnt) * dis + dit;
}
function allDayRow(i) { function allDayRow(i) {
return bodyRows.eq(i); return bodyRows.eq(i);
} }
function allDayBounds(i) {
return {
left: 0,
right: viewWidth
};
}
} }
;;
function BasicEventRenderer() { function BasicEventRenderer() {
var t = this; var t = this;
// exports // exports
t.renderEvents = renderEvents; t.renderEvents = renderEvents;
t.compileDaySegs = compileSegs; // for DayEventRenderer
t.clearEvents = clearEvents; t.clearEvents = clearEvents;
t.bindDaySeg = bindDaySeg;
// imports // imports
DayEventRenderer.call(t); DayEventRenderer.call(t);
var opt = t.opt;
var trigger = t.trigger;
//var setOverflowHidden = t.setOverflowHidden;
var isEventDraggable = t.isEventDraggable;
var isEventResizable = t.isEventResizable;
var reportEvents = t.reportEvents;
var reportEventClear = t.reportEventClear;
var eventElementHandlers = t.eventElementHandlers;
var showEvents = t.showEvents;
var hideEvents = t.hideEvents;
var eventDrop = t.eventDrop;
var getDaySegmentContainer = t.getDaySegmentContainer;
var getHoverListener = t.getHoverListener;
var renderDayOverlay = t.renderDayOverlay;
var clearOverlays = t.clearOverlays;
var getRowCnt = t.getRowCnt;
var getColCnt = t.getColCnt;
var renderDaySegs = t.renderDaySegs;
var resizableDayEvent = t.resizableDayEvent;
/* Rendering
--------------------------------------------------------------------*/
function renderEvents(events, modifiedEventId) { function renderEvents(events, modifiedEventId) {
reportEvents(events); t.renderDayEvents(events, modifiedEventId);
renderDaySegs(compileSegs(events), modifiedEventId);
} }
function clearEvents() { function clearEvents() {
reportEventClear(); t.getDaySegmentContainer().empty();
getDaySegmentContainer().empty();
}
function compileSegs(events) {
var rowCnt = getRowCnt(),
colCnt = getColCnt(),
d1 = cloneDate(t.visStart),
d2 = addDays(cloneDate(d1), colCnt),
visEventsEnds = $.map(events, exclEndDay),
i, row,
j, level,
k, seg,
segs=[];
for (i=0; i<rowCnt; i++) {
row = stackSegs(sliceSegs(events, visEventsEnds, d1, d2));
for (j=0; j<row.length; j++) {
level = row[j];
for (k=0; k<level.length; k++) {
seg = level[k];
seg.row = i;
seg.level = j; // not needed anymore
segs.push(seg);
}
}
addDays(d1, 7);
addDays(d2, 7);
}
return segs;
}
function bindDaySeg(event, eventElement, seg) {
if (isEventDraggable(event)) {
draggableDayEvent(event, eventElement);
}
if (seg.isEnd && isEventResizable(event)) {
resizableDayEvent(event, eventElement, seg);
}
eventElementHandlers(event, eventElement);
// needs to be after, because resizableDayEvent might stopImmediatePropagation on click
}
/* Dragging
----------------------------------------------------------------------------*/
function draggableDayEvent(event, eventElement) {
var hoverListener = getHoverListener();
var dayDelta;
eventElement.draggable({
zIndex: 9,
delay: 50,
opacity: opt('dragOpacity'),
revertDuration: opt('dragRevertDuration'),
start: function(ev, ui) {
trigger('eventDragStart', eventElement, event, ev, ui);
hideEvents(event, eventElement);
hoverListener.start(function(cell, origCell, rowDelta, colDelta) {
eventElement.draggable('option', 'revert', !cell || !rowDelta && !colDelta);
clearOverlays();
if (cell) {
//setOverflowHidden(true);
dayDelta = rowDelta*7 + colDelta * (opt('isRTL') ? -1 : 1);
renderDayOverlay(
addDays(cloneDate(event.start), dayDelta),
addDays(exclEndDay(event), dayDelta)
);
}else{
//setOverflowHidden(false);
dayDelta = 0;
}
}, ev, 'drag');
},
stop: function(ev, ui) {
hoverListener.stop();
clearOverlays();
trigger('eventDragStop', eventElement, event, ev, ui);
if (dayDelta) {
eventDrop(this, event, dayDelta, 0, event.allDay, ev, ui);
}else{
eventElement.css('filter', ''); // clear IE opacity side-effects
showEvents(event, eventElement);
}
//setOverflowHidden(false);
}
});
} }
// TODO: have this class (and AgendaEventRenderer) be responsible for creating the event container div
} }
;;
fcViews.agendaWeek = AgendaWeekView; fcViews.agendaWeek = AgendaWeekView;
function AgendaWeekView(element, calendar) { function AgendaWeekView(element, calendar) {
@ -2732,40 +2669,49 @@ function AgendaWeekView(element, calendar) {
AgendaView.call(t, element, calendar, 'agendaWeek'); AgendaView.call(t, element, calendar, 'agendaWeek');
var opt = t.opt; var opt = t.opt;
var renderAgenda = t.renderAgenda; var renderAgenda = t.renderAgenda;
var skipHiddenDays = t.skipHiddenDays;
var getCellsPerWeek = t.getCellsPerWeek;
var formatDates = calendar.formatDates; var formatDates = calendar.formatDates;
function render(date, delta) { function render(date, delta) {
if (delta) { if (delta) {
addDays(date, delta * 7); addDays(date, delta * 7);
} }
var start = addDays(cloneDate(date), -((date.getDay() - opt('firstDay') + 7) % 7)); var start = addDays(cloneDate(date), -((date.getDay() - opt('firstDay') + 7) % 7));
var end = addDays(cloneDate(start), 7); var end = addDays(cloneDate(start), 7);
var visStart = cloneDate(start); var visStart = cloneDate(start);
skipHiddenDays(visStart);
var visEnd = cloneDate(end); var visEnd = cloneDate(end);
var weekends = opt('weekends'); skipHiddenDays(visEnd, -1, true);
if (!weekends) {
skipWeekend(visStart); var colCnt = getCellsPerWeek();
skipWeekend(visEnd, -1, true);
}
t.title = formatDates( t.title = formatDates(
visStart, visStart,
addDays(cloneDate(visEnd), -1), addDays(cloneDate(visEnd), -1),
opt('titleFormat') opt('titleFormat')
); );
t.start = start; t.start = start;
t.end = end; t.end = end;
t.visStart = visStart; t.visStart = visStart;
t.visEnd = visEnd; t.visEnd = visEnd;
renderAgenda(weekends ? 7 : 5);
renderAgenda(colCnt);
} }
} }
;;
fcViews.agendaDay = AgendaDayView; fcViews.agendaDay = AgendaDayView;
function AgendaDayView(element, calendar) { function AgendaDayView(element, calendar) {
var t = this; var t = this;
@ -2778,28 +2724,33 @@ function AgendaDayView(element, calendar) {
AgendaView.call(t, element, calendar, 'agendaDay'); AgendaView.call(t, element, calendar, 'agendaDay');
var opt = t.opt; var opt = t.opt;
var renderAgenda = t.renderAgenda; var renderAgenda = t.renderAgenda;
var skipHiddenDays = t.skipHiddenDays;
var formatDate = calendar.formatDate; var formatDate = calendar.formatDate;
function render(date, delta) { function render(date, delta) {
if (delta) { if (delta) {
addDays(date, delta); addDays(date, delta);
if (!opt('weekends')) {
skipWeekend(date, delta < 0 ? -1 : 1);
}
} }
skipHiddenDays(date, delta < 0 ? -1 : 1);
var start = cloneDate(date, true); var start = cloneDate(date, true);
var end = addDays(cloneDate(start), 1); var end = addDays(cloneDate(start), 1);
t.title = formatDate(date, opt('titleFormat')); t.title = formatDate(date, opt('titleFormat'));
t.start = t.visStart = start; t.start = t.visStart = start;
t.end = t.visEnd = end; t.end = t.visEnd = end;
renderAgenda(1); renderAgenda(1);
} }
} }
;;
setDefaults({ setDefaults({
allDaySlot: true, allDaySlot: true,
allDayText: 'all-day', allDayText: 'all-day',
@ -2814,7 +2765,8 @@ setDefaults({
agenda: .5 agenda: .5
}, },
minTime: 0, minTime: 0,
maxTime: 24 maxTime: 24,
slotEventOverlap: true
}); });
@ -2830,28 +2782,27 @@ function AgendaView(element, calendar, viewName) {
t.renderAgenda = renderAgenda; t.renderAgenda = renderAgenda;
t.setWidth = setWidth; t.setWidth = setWidth;
t.setHeight = setHeight; t.setHeight = setHeight;
t.beforeHide = beforeHide; t.afterRender = afterRender;
t.afterShow = afterShow;
t.defaultEventEnd = defaultEventEnd; t.defaultEventEnd = defaultEventEnd;
t.timePosition = timePosition; t.timePosition = timePosition;
t.dayOfWeekCol = dayOfWeekCol; t.getIsCellAllDay = getIsCellAllDay;
t.dateCell = dateCell;
t.cellDate = cellDate;
t.cellIsAllDay = cellIsAllDay;
t.allDayRow = getAllDayRow; t.allDayRow = getAllDayRow;
t.allDayBounds = allDayBounds; t.getCoordinateGrid = function() { return coordinateGrid }; // specifically for AgendaEventRenderer
t.getHoverListener = function() { return hoverListener }; t.getHoverListener = function() { return hoverListener };
t.colLeft = colLeft;
t.colRight = colRight;
t.colContentLeft = colContentLeft; t.colContentLeft = colContentLeft;
t.colContentRight = colContentRight; t.colContentRight = colContentRight;
t.getDaySegmentContainer = function() { return daySegmentContainer }; t.getDaySegmentContainer = function() { return daySegmentContainer };
t.getSlotSegmentContainer = function() { return slotSegmentContainer }; t.getSlotSegmentContainer = function() { return slotSegmentContainer };
t.getMinMinute = function() { return minMinute }; t.getMinMinute = function() { return minMinute };
t.getMaxMinute = function() { return maxMinute }; t.getMaxMinute = function() { return maxMinute };
t.getBodyContent = function() { return slotContent }; // !!?? t.getSlotContainer = function() { return slotContainer };
t.getRowCnt = function() { return 1 }; t.getRowCnt = function() { return 1 };
t.getColCnt = function() { return colCnt }; t.getColCnt = function() { return colCnt };
t.getColWidth = function() { return colWidth }; t.getColWidth = function() { return colWidth };
t.getSlotHeight = function() { return slotHeight }; t.getSnapHeight = function() { return snapHeight };
t.getSnapMinutes = function() { return snapMinutes };
t.defaultSelectionEnd = defaultSelectionEnd; t.defaultSelectionEnd = defaultSelectionEnd;
t.renderDayOverlay = renderDayOverlay; t.renderDayOverlay = renderDayOverlay;
t.renderSelection = renderSelection; t.renderSelection = renderSelection;
@ -2868,13 +2819,15 @@ function AgendaView(element, calendar, viewName) {
AgendaEventRenderer.call(t); AgendaEventRenderer.call(t);
var opt = t.opt; var opt = t.opt;
var trigger = t.trigger; var trigger = t.trigger;
var clearEvents = t.clearEvents;
var renderOverlay = t.renderOverlay; var renderOverlay = t.renderOverlay;
var clearOverlays = t.clearOverlays; var clearOverlays = t.clearOverlays;
var reportSelection = t.reportSelection; var reportSelection = t.reportSelection;
var unselect = t.unselect; var unselect = t.unselect;
var daySelectionMousedown = t.daySelectionMousedown; var daySelectionMousedown = t.daySelectionMousedown;
var slotSegHtml = t.slotSegHtml; var slotSegHtml = t.slotSegHtml;
var cellToDate = t.cellToDate;
var dateToCell = t.dateToCell;
var rangeToSegments = t.rangeToSegments;
var formatDate = calendar.formatDate; var formatDate = calendar.formatDate;
@ -2886,6 +2839,7 @@ function AgendaView(element, calendar, viewName) {
var dayBody; var dayBody;
var dayBodyCells; var dayBodyCells;
var dayBodyCellInners; var dayBodyCellInners;
var dayBodyCellContentInners;
var dayBodyFirstCell; var dayBodyFirstCell;
var dayBodyFirstCellStretcher; var dayBodyFirstCellStretcher;
var slotLayer; var slotLayer;
@ -2893,12 +2847,9 @@ function AgendaView(element, calendar, viewName) {
var allDayTable; var allDayTable;
var allDayRow; var allDayRow;
var slotScroller; var slotScroller;
var slotContent; var slotContainer;
var slotSegmentContainer; var slotSegmentContainer;
var slotTable; var slotTable;
var slotTableFirstInner;
var axisFirstCells;
var gutterCells;
var selectionHelper; var selectionHelper;
var viewWidth; var viewWidth;
@ -2907,21 +2858,26 @@ function AgendaView(element, calendar, viewName) {
var colWidth; var colWidth;
var gutterWidth; var gutterWidth;
var slotHeight; // TODO: what if slotHeight changes? (see issue 650) var slotHeight; // TODO: what if slotHeight changes? (see issue 650)
var savedScrollTop;
var snapMinutes;
var snapRatio; // ratio of number of "selection" slots to normal slots. (ex: 1, 2, 4)
var snapHeight; // holds the pixel hight of a "selection" slot
var colCnt; var colCnt;
var slotCnt; var slotCnt;
var coordinateGrid; var coordinateGrid;
var hoverListener; var hoverListener;
var colPositions;
var colContentPositions; var colContentPositions;
var slotTopCache = {}; var slotTopCache = {};
var tm; var tm;
var firstDay; var rtl;
var nwe; // no weekends (int)
var rtl, dis, dit; // day index sign / translate
var minMinute, maxMinute; var minMinute, maxMinute;
var colFormat; var colFormat;
var showWeekNumbers;
var weekNumberTitle;
var weekNumberFormat;
@ -2935,89 +2891,54 @@ function AgendaView(element, calendar, viewName) {
function renderAgenda(c) { function renderAgenda(c) {
colCnt = c; colCnt = c;
updateOptions(); updateOptions();
if (!dayTable) {
buildSkeleton(); if (!dayTable) { // first time rendering?
}else{ buildSkeleton(); // builds day table, slot area, events containers
clearEvents(); }
else {
buildDayTable(); // rebuilds day table
} }
updateCells();
} }
function updateOptions() { function updateOptions() {
tm = opt('theme') ? 'ui' : 'fc'; tm = opt('theme') ? 'ui' : 'fc';
nwe = opt('weekends') ? 0 : 1; rtl = opt('isRTL')
firstDay = opt('firstDay');
if (rtl = opt('isRTL')) {
dis = -1;
dit = colCnt - 1;
}else{
dis = 1;
dit = 0;
}
minMinute = parseTime(opt('minTime')); minMinute = parseTime(opt('minTime'));
maxMinute = parseTime(opt('maxTime')); maxMinute = parseTime(opt('maxTime'));
colFormat = opt('columnFormat'); colFormat = opt('columnFormat');
// week # options. (TODO: bad, logic also in other views)
showWeekNumbers = opt('weekNumbers');
weekNumberTitle = opt('weekNumberTitle');
if (opt('weekNumberCalculation') != 'iso') {
weekNumberFormat = "w";
}
else {
weekNumberFormat = "W";
}
snapMinutes = opt('snapMinutes') || opt('slotMinutes');
} }
/* Build DOM
-----------------------------------------------------------------------*/
function buildSkeleton() { function buildSkeleton() {
var headerClass = tm + "-widget-header"; var headerClass = tm + "-widget-header";
var contentClass = tm + "-widget-content"; var contentClass = tm + "-widget-content";
var s; var s;
var i;
var d; var d;
var i;
var maxd; var maxd;
var minutes; var minutes;
var slotNormal = opt('slotMinutes') % 15 == 0; var slotNormal = opt('slotMinutes') % 15 == 0;
s = buildDayTable();
"<table style='width:100%' class='fc-agenda-days fc-border-separate' cellspacing='0'>" +
"<thead>" +
"<tr>" +
"<th class='fc-agenda-axis " + headerClass + "'>&nbsp;</th>";
for (i=0; i<colCnt; i++) {
s +=
"<th class='fc- fc-col" + i + ' ' + headerClass + "'/>"; // fc- needed for setDayID
}
s +=
"<th class='fc-agenda-gutter " + headerClass + "'>&nbsp;</th>" +
"</tr>" +
"</thead>" +
"<tbody>" +
"<tr>" +
"<th class='fc-agenda-axis " + headerClass + "'>&nbsp;</th>";
for (i=0; i<colCnt; i++) {
s +=
"<td class='fc- fc-col" + i + ' ' + contentClass + "'>" + // fc- needed for setDayID
"<div>" +
"<div class='fc-day-content'>" +
"<div style='position:relative'>&nbsp;</div>" +
"</div>" +
"</div>" +
"</td>";
}
s +=
"<td class='fc-agenda-gutter " + contentClass + "'>&nbsp;</td>" +
"</tr>" +
"</tbody>" +
"</table>";
dayTable = $(s).appendTo(element);
dayHead = dayTable.find('thead');
dayHeadCells = dayHead.find('th').slice(1, -1);
dayBody = dayTable.find('tbody');
dayBodyCells = dayBody.find('td').slice(0, -1);
dayBodyCellInners = dayBodyCells.find('div.fc-day-content div');
dayBodyFirstCell = dayBodyCells.eq(0);
dayBodyFirstCellStretcher = dayBodyFirstCell.find('> div');
markFirstLast(dayHead.add(dayHead.find('tr')));
markFirstLast(dayBody.add(dayBody.find('tr')));
axisFirstCells = dayHead.find('th:first');
gutterCells = dayTable.find('.fc-agenda-gutter');
slotLayer = slotLayer =
$("<div style='position:absolute;z-index:2;left:0;width:100%'/>") $("<div style='position:absolute;z-index:2;left:0;width:100%'/>")
@ -3026,7 +2947,7 @@ function AgendaView(element, calendar, viewName) {
if (opt('allDaySlot')) { if (opt('allDaySlot')) {
daySegmentContainer = daySegmentContainer =
$("<div style='position:absolute;z-index:8;top:0;left:0'/>") $("<div class='fc-event-container' style='position:absolute;z-index:8;top:0;left:0'/>")
.appendTo(slotLayer); .appendTo(slotLayer);
s = s =
@ -3044,9 +2965,6 @@ function AgendaView(element, calendar, viewName) {
dayBind(allDayRow.find('td')); dayBind(allDayRow.find('td'));
axisFirstCells = axisFirstCells.add(allDayTable.find('th:first'));
gutterCells = gutterCells.add(allDayTable.find('th.fc-agenda-gutter'));
slotLayer.append( slotLayer.append(
"<div class='fc-agenda-divider " + headerClass + "'>" + "<div class='fc-agenda-divider " + headerClass + "'>" +
"<div class='fc-agenda-divider-inner'/>" + "<div class='fc-agenda-divider-inner'/>" +
@ -3063,13 +2981,13 @@ function AgendaView(element, calendar, viewName) {
$("<div style='position:absolute;width:100%;overflow-x:hidden;overflow-y:auto'/>") $("<div style='position:absolute;width:100%;overflow-x:hidden;overflow-y:auto'/>")
.appendTo(slotLayer); .appendTo(slotLayer);
slotContent = slotContainer =
$("<div style='position:relative;width:100%;overflow:hidden'/>") $("<div style='position:relative;width:100%;overflow:hidden'/>")
.appendTo(slotScroller); .appendTo(slotScroller);
slotSegmentContainer = slotSegmentContainer =
$("<div style='position:absolute;z-index:8;top:0;left:0'/>") $("<div class='fc-event-container' style='position:absolute;z-index:8;top:0;left:0'/>")
.appendTo(slotContent); .appendTo(slotContainer);
s = s =
"<table class='fc-agenda-slots' style='width:100%' cellspacing='0'>" + "<table class='fc-agenda-slots' style='width:100%' cellspacing='0'>" +
@ -3095,39 +3013,170 @@ function AgendaView(element, calendar, viewName) {
s += s +=
"</tbody>" + "</tbody>" +
"</table>"; "</table>";
slotTable = $(s).appendTo(slotContent); slotTable = $(s).appendTo(slotContainer);
slotTableFirstInner = slotTable.find('div:first');
slotBind(slotTable.find('td')); slotBind(slotTable.find('td'));
axisFirstCells = axisFirstCells.add(slotTable.find('th:first'));
} }
function updateCells() { /* Build Day Table
var i; -----------------------------------------------------------------------*/
var headCell;
var bodyCell;
function buildDayTable() {
var html = buildDayTableHTML();
if (dayTable) {
dayTable.remove();
}
dayTable = $(html).appendTo(element);
dayHead = dayTable.find('thead');
dayHeadCells = dayHead.find('th').slice(1, -1); // exclude gutter
dayBody = dayTable.find('tbody');
dayBodyCells = dayBody.find('td').slice(0, -1); // exclude gutter
dayBodyCellInners = dayBodyCells.find('> div');
dayBodyCellContentInners = dayBodyCells.find('.fc-day-content > div');
dayBodyFirstCell = dayBodyCells.eq(0);
dayBodyFirstCellStretcher = dayBodyCellInners.eq(0);
markFirstLast(dayHead.add(dayHead.find('tr')));
markFirstLast(dayBody.add(dayBody.find('tr')));
// TODO: now that we rebuild the cells every time, we should call dayRender
}
function buildDayTableHTML() {
var html =
"<table style='width:100%' class='fc-agenda-days fc-border-separate' cellspacing='0'>" +
buildDayTableHeadHTML() +
buildDayTableBodyHTML() +
"</table>";
return html;
}
function buildDayTableHeadHTML() {
var headerClass = tm + "-widget-header";
var date;
var html = '';
var weekText;
var col;
html +=
"<thead>" +
"<tr>";
if (showWeekNumbers) {
date = cellToDate(0, 0);
weekText = formatDate(date, weekNumberFormat);
if (rtl) {
weekText += weekNumberTitle;
}
else {
weekText = weekNumberTitle + weekText;
}
html +=
"<th class='fc-agenda-axis fc-week-number " + headerClass + "'>" +
htmlEscape(weekText) +
"</th>";
}
else {
html += "<th class='fc-agenda-axis " + headerClass + "'>&nbsp;</th>";
}
for (col=0; col<colCnt; col++) {
date = cellToDate(0, col);
html +=
"<th class='fc-" + dayIDs[date.getDay()] + " fc-col" + col + ' ' + headerClass + "'>" +
htmlEscape(formatDate(date, colFormat)) +
"</th>";
}
html +=
"<th class='fc-agenda-gutter " + headerClass + "'>&nbsp;</th>" +
"</tr>" +
"</thead>";
return html;
}
function buildDayTableBodyHTML() {
var headerClass = tm + "-widget-header"; // TODO: make these when updateOptions() called
var contentClass = tm + "-widget-content";
var date; var date;
var today = clearTime(new Date()); var today = clearTime(new Date());
for (i=0; i<colCnt; i++) { var col;
date = colDate(i); var cellsHTML;
headCell = dayHeadCells.eq(i); var cellHTML;
headCell.html(formatDate(date, colFormat)); var classNames;
bodyCell = dayBodyCells.eq(i); var html = '';
html +=
"<tbody>" +
"<tr>" +
"<th class='fc-agenda-axis " + headerClass + "'>&nbsp;</th>";
cellsHTML = '';
for (col=0; col<colCnt; col++) {
date = cellToDate(0, col);
classNames = [
'fc-col' + col,
'fc-' + dayIDs[date.getDay()],
contentClass
];
if (+date == +today) { if (+date == +today) {
bodyCell.addClass(tm + '-state-highlight fc-today'); classNames.push(
}else{ tm + '-state-highlight',
bodyCell.removeClass(tm + '-state-highlight fc-today'); 'fc-today'
);
} }
setDayID(headCell.add(bodyCell), date); else if (date < today) {
classNames.push('fc-past');
}
else {
classNames.push('fc-future');
}
cellHTML =
"<td class='" + classNames.join(' ') + "'>" +
"<div>" +
"<div class='fc-day-content'>" +
"<div style='position:relative'>&nbsp;</div>" +
"</div>" +
"</div>" +
"</td>";
cellsHTML += cellHTML;
} }
html += cellsHTML;
html +=
"<td class='fc-agenda-gutter " + contentClass + "'>&nbsp;</td>" +
"</tr>" +
"</tbody>";
return html;
} }
// TODO: data-date on the cells
/* Dimensions
-----------------------------------------------------------------------*/
function setHeight(height, dateChanged) { function setHeight(height) {
if (height === undefined) { if (height === undefined) {
height = viewHeight; height = viewHeight;
} }
@ -3140,7 +3189,7 @@ function AgendaView(element, calendar, viewName) {
height - headHeight, // when scrollbars height - headHeight, // when scrollbars
slotTable.height() + allDayHeight + 1 // when no scrollbars. +1 for bottom border slotTable.height() + allDayHeight + 1 // when no scrollbars. +1 for bottom border
); );
dayBodyFirstCellStretcher dayBodyFirstCellStretcher
.height(bodyHeight - vsides(dayBodyFirstCell)); .height(bodyHeight - vsides(dayBodyFirstCell));
@ -3148,18 +3197,25 @@ function AgendaView(element, calendar, viewName) {
slotScroller.height(bodyHeight - allDayHeight - 1); slotScroller.height(bodyHeight - allDayHeight - 1);
slotHeight = slotTableFirstInner.height() + 1; // +1 for border // the stylesheet guarantees that the first row has no border.
// this allows .height() to work well cross-browser.
if (dateChanged) { slotHeight = slotTable.find('tr:first').height() + 1; // +1 for bottom border
resetScroll();
} snapRatio = opt('slotMinutes') / snapMinutes;
snapHeight = slotHeight / snapRatio;
} }
function setWidth(width) { function setWidth(width) {
viewWidth = width; viewWidth = width;
colPositions.clear();
colContentPositions.clear(); colContentPositions.clear();
var axisFirstCells = dayHead.find('th:first');
if (allDayTable) {
axisFirstCells = axisFirstCells.add(allDayTable.find('th:first'));
}
axisFirstCells = axisFirstCells.add(slotTable.find('th:first'));
axisWidth = 0; axisWidth = 0;
setOuterWidth( setOuterWidth(
@ -3171,8 +3227,12 @@ function AgendaView(element, calendar, viewName) {
axisWidth axisWidth
); );
var gutterCells = dayTable.find('.fc-agenda-gutter');
if (allDayTable) {
gutterCells = gutterCells.add(allDayTable.find('th.fc-agenda-gutter'));
}
var slotTableWidth = slotScroller[0].clientWidth; // needs to be done after axisWidth (for IE7) var slotTableWidth = slotScroller[0].clientWidth; // needs to be done after axisWidth (for IE7)
//slotTable.width(slotTableWidth);
gutterWidth = slotScroller.width() - slotTableWidth; gutterWidth = slotScroller.width() - slotTableWidth;
if (gutterWidth) { if (gutterWidth) {
@ -3194,6 +3254,10 @@ function AgendaView(element, calendar, viewName) {
/* Scrolling
-----------------------------------------------------------------------*/
function resetScroll() { function resetScroll() {
var d0 = zeroDate(); var d0 = zeroDate();
var scrollDate = cloneDate(d0); var scrollDate = cloneDate(d0);
@ -3205,15 +3269,10 @@ function AgendaView(element, calendar, viewName) {
scroll(); scroll();
setTimeout(scroll, 0); // overrides any previous scroll state made by the browser setTimeout(scroll, 0); // overrides any previous scroll state made by the browser
} }
function beforeHide() { function afterRender() { // after the view has been freshly rendered and sized
savedScrollTop = slotScroller.scrollTop(); resetScroll();
}
function afterShow() {
slotScroller.scrollTop(savedScrollTop);
} }
@ -3237,7 +3296,7 @@ function AgendaView(element, calendar, viewName) {
function slotClick(ev) { function slotClick(ev) {
if (!opt('selectable')) { // if selectable, SelectionManager will worry about dayClick if (!opt('selectable')) { // if selectable, SelectionManager will worry about dayClick
var col = Math.min(colCnt-1, Math.floor((ev.pageX - dayTable.offset().left - axisWidth) / colWidth)); var col = Math.min(colCnt-1, Math.floor((ev.pageX - dayTable.offset().left - axisWidth) / colWidth));
var date = colDate(col); var date = cellToDate(0, col);
var rowMatch = this.parentNode.className.match(/fc-slot(\d+)/); // TODO: maybe use data var rowMatch = this.parentNode.className.match(/fc-slot(\d+)/); // TODO: maybe use data
if (rowMatch) { if (rowMatch) {
var mins = parseInt(rowMatch[1]) * opt('slotMinutes'); var mins = parseInt(rowMatch[1]) * opt('slotMinutes');
@ -3255,26 +3314,26 @@ function AgendaView(element, calendar, viewName) {
/* Semi-transparent Overlay Helpers /* Semi-transparent Overlay Helpers
-----------------------------------------------------*/ -----------------------------------------------------*/
// TODO: should be consolidated with BasicView's methods
function renderDayOverlay(overlayStart, overlayEnd, refreshCoordinateGrid) { // overlayEnd is exclusive
function renderDayOverlay(startDate, endDate, refreshCoordinateGrid) { // endDate is exclusive
if (refreshCoordinateGrid) { if (refreshCoordinateGrid) {
coordinateGrid.build(); coordinateGrid.build();
} }
var visStart = cloneDate(t.visStart);
var startCol, endCol; var segments = rangeToSegments(overlayStart, overlayEnd);
if (rtl) {
startCol = dayDiff(endDate, visStart)*dis+dit+1; for (var i=0; i<segments.length; i++) {
endCol = dayDiff(startDate, visStart)*dis+dit+1; var segment = segments[i];
}else{
startCol = dayDiff(startDate, visStart);
endCol = dayDiff(endDate, visStart);
}
startCol = Math.max(0, startCol);
endCol = Math.min(colCnt, endCol);
if (startCol < endCol) {
dayBind( dayBind(
renderCellOverlay(0, startCol, 0, endCol-1) renderCellOverlay(
segment.row,
segment.leftCol,
segment.row,
segment.rightCol
)
); );
} }
} }
@ -3287,24 +3346,21 @@ function AgendaView(element, calendar, viewName) {
function renderSlotOverlay(overlayStart, overlayEnd) { function renderSlotOverlay(overlayStart, overlayEnd) {
var dayStart = cloneDate(t.visStart);
var dayEnd = addDays(cloneDate(dayStart), 1);
for (var i=0; i<colCnt; i++) { for (var i=0; i<colCnt; i++) {
var dayStart = cellToDate(0, i);
var dayEnd = addDays(cloneDate(dayStart), 1);
var stretchStart = new Date(Math.max(dayStart, overlayStart)); var stretchStart = new Date(Math.max(dayStart, overlayStart));
var stretchEnd = new Date(Math.min(dayEnd, overlayEnd)); var stretchEnd = new Date(Math.min(dayEnd, overlayEnd));
if (stretchStart < stretchEnd) { if (stretchStart < stretchEnd) {
var col = i*dis+dit; var rect = coordinateGrid.rect(0, i, 0, i, slotContainer); // only use it for horizontal coords
var rect = coordinateGrid.rect(0, col, 0, col, slotContent); // only use it for horizontal coords
var top = timePosition(dayStart, stretchStart); var top = timePosition(dayStart, stretchStart);
var bottom = timePosition(dayStart, stretchEnd); var bottom = timePosition(dayStart, stretchEnd);
rect.top = top; rect.top = top;
rect.height = bottom - top; rect.height = bottom - top;
slotBind( slotBind(
renderOverlay(rect, slotContent) renderOverlay(rect, slotContainer)
); );
} }
addDays(dayStart, 1);
addDays(dayEnd, 1);
} }
} }
@ -3331,16 +3387,16 @@ function AgendaView(element, calendar, viewName) {
n = e.offset().top; n = e.offset().top;
rows[0] = [n, n+e.outerHeight()]; rows[0] = [n, n+e.outerHeight()];
} }
var slotTableTop = slotContent.offset().top; var slotTableTop = slotContainer.offset().top;
var slotScrollerTop = slotScroller.offset().top; var slotScrollerTop = slotScroller.offset().top;
var slotScrollerBottom = slotScrollerTop + slotScroller.outerHeight(); var slotScrollerBottom = slotScrollerTop + slotScroller.outerHeight();
function constrain(n) { function constrain(n) {
return Math.max(slotScrollerTop, Math.min(slotScrollerBottom, n)); return Math.max(slotScrollerTop, Math.min(slotScrollerBottom, n));
} }
for (var i=0; i<slotCnt; i++) { for (var i=0; i<slotCnt*snapRatio; i++) { // adapt slot count to increased/decreased selection slot count
rows.push([ rows.push([
constrain(slotTableTop + slotHeight*i), constrain(slotTableTop + snapHeight*i),
constrain(slotTableTop + slotHeight*(i+1)) constrain(slotTableTop + snapHeight*(i+1))
]); ]);
} }
}); });
@ -3348,62 +3404,53 @@ function AgendaView(element, calendar, viewName) {
hoverListener = new HoverListener(coordinateGrid); hoverListener = new HoverListener(coordinateGrid);
colPositions = new HorizontalPositionCache(function(col) {
colContentPositions = new HorizontalPositionCache(function(col) {
return dayBodyCellInners.eq(col); return dayBodyCellInners.eq(col);
}); });
colContentPositions = new HorizontalPositionCache(function(col) {
return dayBodyCellContentInners.eq(col);
});
function colLeft(col) {
return colPositions.left(col);
}
function colContentLeft(col) { function colContentLeft(col) {
return colContentPositions.left(col); return colContentPositions.left(col);
} }
function colRight(col) {
return colPositions.right(col);
}
function colContentRight(col) { function colContentRight(col) {
return colContentPositions.right(col); return colContentPositions.right(col);
} }
function getIsCellAllDay(cell) {
return opt('allDaySlot') && !cell.row;
function dateCell(date) { // "cell" terminology is now confusing
return {
row: Math.floor(dayDiff(date, t.visStart) / 7),
col: dayOfWeekCol(date.getDay())
};
} }
function cellDate(cell) { function realCellToDate(cell) { // ugh "real" ... but blame it on our abuse of the "cell" system
var d = colDate(cell.col); var d = cellToDate(0, cell.col);
var slotIndex = cell.row; var slotIndex = cell.row;
if (opt('allDaySlot')) { if (opt('allDaySlot')) {
slotIndex--; slotIndex--;
} }
if (slotIndex >= 0) { if (slotIndex >= 0) {
addMinutes(d, minMinute + slotIndex * opt('slotMinutes')); addMinutes(d, minMinute + slotIndex * snapMinutes);
} }
return d; return d;
} }
function colDate(col) { // returns dates with 00:00:00
return addDays(cloneDate(t.visStart), col*dis+dit);
}
function cellIsAllDay(cell) {
return opt('allDaySlot') && !cell.row;
}
function dayOfWeekCol(dayOfWeek) {
return ((dayOfWeek - Math.max(firstDay, nwe) + colCnt) % colCnt)*dis+dit;
}
// get the Y coordinate of the given time on the given day (both Date objects) // get the Y coordinate of the given time on the given day (both Date objects)
function timePosition(day, time) { // both date objects. day holds 00:00 of current day function timePosition(day, time) { // both date objects. day holds 00:00 of current day
day = cloneDate(day, true); day = cloneDate(day, true);
@ -3418,7 +3465,11 @@ function AgendaView(element, calendar, viewName) {
slotI = Math.floor(minutes / slotMinutes), slotI = Math.floor(minutes / slotMinutes),
slotTop = slotTopCache[slotI]; slotTop = slotTopCache[slotI];
if (slotTop === undefined) { if (slotTop === undefined) {
slotTop = slotTopCache[slotI] = slotTable.find('tr:eq(' + slotI + ') td div')[0].offsetTop; //.position().top; // need this optimization??? slotTop = slotTopCache[slotI] =
slotTable.find('tr').eq(slotI).find('td div')[0].offsetTop;
// .eq() is faster than ":eq()" selector
// [0].offsetTop is faster than .position().top (do we really need this optimization?)
// a better optimization would be to cache all these divs
} }
return Math.max(0, Math.round( return Math.max(0, Math.round(
slotTop - 1 + slotHeight * ((minutes % slotMinutes) / slotMinutes) slotTop - 1 + slotHeight * ((minutes % slotMinutes) / slotMinutes)
@ -3426,14 +3477,6 @@ function AgendaView(element, calendar, viewName) {
} }
function allDayBounds() {
return {
left: axisWidth,
right: viewWidth - gutterWidth
}
}
function getAllDayRow(index) { function getAllDayRow(index) {
return allDayRow; return allDayRow;
} }
@ -3476,9 +3519,9 @@ function AgendaView(element, calendar, viewName) {
var helperOption = opt('selectHelper'); var helperOption = opt('selectHelper');
coordinateGrid.build(); coordinateGrid.build();
if (helperOption) { if (helperOption) {
var col = dayDiff(startDate, t.visStart) * dis + dit; var col = dateToCell(startDate).col;
if (col >= 0 && col < colCnt) { // only works when times are on same day if (col >= 0 && col < colCnt) { // only works when times are on same day
var rect = coordinateGrid.rect(0, col, 0, col, slotContent); // only for horizontal coords var rect = coordinateGrid.rect(0, col, 0, col, slotContainer); // only for horizontal coords
var top = timePosition(startDate, startDate); var top = timePosition(startDate, startDate);
var bottom = timePosition(startDate, endDate); var bottom = timePosition(startDate, endDate);
if (bottom > top) { // protect against selections that are entirely before or after visible range if (bottom > top) { // protect against selections that are entirely before or after visible range
@ -3490,10 +3533,9 @@ function AgendaView(element, calendar, viewName) {
var helperRes = helperOption(startDate, endDate); var helperRes = helperOption(startDate, endDate);
if (helperRes) { if (helperRes) {
rect.position = 'absolute'; rect.position = 'absolute';
rect.zIndex = 8;
selectionHelper = $(helperRes) selectionHelper = $(helperRes)
.css(rect) .css(rect)
.appendTo(slotContent); .appendTo(slotContainer);
} }
}else{ }else{
rect.isStart = true; // conside rect a "seg" now rect.isStart = true; // conside rect a "seg" now
@ -3512,7 +3554,7 @@ function AgendaView(element, calendar, viewName) {
} }
if (selectionHelper) { if (selectionHelper) {
slotBind(selectionHelper); slotBind(selectionHelper);
slotContent.append(selectionHelper); slotContainer.append(selectionHelper);
setOuterWidth(selectionHelper, rect.width, true); // needs to be after appended setOuterWidth(selectionHelper, rect.width, true); // needs to be after appended
setOuterHeight(selectionHelper, rect.height, true); setOuterHeight(selectionHelper, rect.height, true);
} }
@ -3539,15 +3581,15 @@ function AgendaView(element, calendar, viewName) {
var dates; var dates;
hoverListener.start(function(cell, origCell) { hoverListener.start(function(cell, origCell) {
clearSelection(); clearSelection();
if (cell && cell.col == origCell.col && !cellIsAllDay(cell)) { if (cell && cell.col == origCell.col && !getIsCellAllDay(cell)) {
var d1 = cellDate(origCell); var d1 = realCellToDate(origCell);
var d2 = cellDate(cell); var d2 = realCellToDate(cell);
dates = [ dates = [
d1, d1,
addMinutes(cloneDate(d1), opt('slotMinutes')), addMinutes(cloneDate(d1), snapMinutes), // calculate minutes depending on selection slot minutes
d2, d2,
addMinutes(cloneDate(d2), opt('slotMinutes')) addMinutes(cloneDate(d2), snapMinutes)
].sort(cmp); ].sort(dateCompare);
renderSlotSelection(dates[0], dates[3]); renderSlotSelection(dates[0], dates[3]);
}else{ }else{
dates = null; dates = null;
@ -3564,10 +3606,10 @@ function AgendaView(element, calendar, viewName) {
}); });
} }
} }
function reportDayClick(date, allDay, ev) { function reportDayClick(date, allDay, ev) {
trigger('dayClick', dayBodyCells[dayOfWeekCol(date.getDay())], date, allDay, ev); trigger('dayClick', dayBodyCells[dateToCell(date).col], date, allDay, ev);
} }
@ -3580,10 +3622,10 @@ function AgendaView(element, calendar, viewName) {
hoverListener.start(function(cell) { hoverListener.start(function(cell) {
clearOverlays(); clearOverlays();
if (cell) { if (cell) {
if (cellIsAllDay(cell)) { if (getIsCellAllDay(cell)) {
renderCellOverlay(cell.row, cell.col, cell.row, cell.col); renderCellOverlay(cell.row, cell.col, cell.row, cell.col);
}else{ }else{
var d1 = cellDate(cell); var d1 = realCellToDate(cell);
var d2 = addMinutes(cloneDate(d1), opt('defaultEventMinutes')); var d2 = addMinutes(cloneDate(d1), opt('defaultEventMinutes'));
renderSlotOverlay(d1, d2); renderSlotOverlay(d1, d2);
} }
@ -3596,35 +3638,32 @@ function AgendaView(element, calendar, viewName) {
var cell = hoverListener.stop(); var cell = hoverListener.stop();
clearOverlays(); clearOverlays();
if (cell) { if (cell) {
trigger('drop', _dragElement, cellDate(cell), cellIsAllDay(cell), ev, ui); trigger('drop', _dragElement, realCellToDate(cell), getIsCellAllDay(cell), ev, ui);
} }
} }
} }
;;
function AgendaEventRenderer() { function AgendaEventRenderer() {
var t = this; var t = this;
// exports // exports
t.renderEvents = renderEvents; t.renderEvents = renderEvents;
t.compileDaySegs = compileDaySegs; // for DayEventRenderer
t.clearEvents = clearEvents; t.clearEvents = clearEvents;
t.slotSegHtml = slotSegHtml; t.slotSegHtml = slotSegHtml;
t.bindDaySeg = bindDaySeg;
// imports // imports
DayEventRenderer.call(t); DayEventRenderer.call(t);
var opt = t.opt; var opt = t.opt;
var trigger = t.trigger; var trigger = t.trigger;
//var setOverflowHidden = t.setOverflowHidden;
var isEventDraggable = t.isEventDraggable; var isEventDraggable = t.isEventDraggable;
var isEventResizable = t.isEventResizable; var isEventResizable = t.isEventResizable;
var eventEnd = t.eventEnd; var eventEnd = t.eventEnd;
var reportEvents = t.reportEvents;
var reportEventClear = t.reportEventClear;
var eventElementHandlers = t.eventElementHandlers; var eventElementHandlers = t.eventElementHandlers;
var setHeight = t.setHeight; var setHeight = t.setHeight;
var getDaySegmentContainer = t.getDaySegmentContainer; var getDaySegmentContainer = t.getDaySegmentContainer;
@ -3633,14 +3672,15 @@ function AgendaEventRenderer() {
var getMaxMinute = t.getMaxMinute; var getMaxMinute = t.getMaxMinute;
var getMinMinute = t.getMinMinute; var getMinMinute = t.getMinMinute;
var timePosition = t.timePosition; var timePosition = t.timePosition;
var getIsCellAllDay = t.getIsCellAllDay;
var colContentLeft = t.colContentLeft; var colContentLeft = t.colContentLeft;
var colContentRight = t.colContentRight; var colContentRight = t.colContentRight;
var renderDaySegs = t.renderDaySegs; var cellToDate = t.cellToDate;
var resizableDayEvent = t.resizableDayEvent; // TODO: streamline binding architecture
var getColCnt = t.getColCnt; var getColCnt = t.getColCnt;
var getColWidth = t.getColWidth; var getColWidth = t.getColWidth;
var getSlotHeight = t.getSlotHeight; var getSnapHeight = t.getSnapHeight;
var getBodyContent = t.getBodyContent; var getSnapMinutes = t.getSnapMinutes;
var getSlotContainer = t.getSlotContainer;
var reportEventElement = t.reportEventElement; var reportEventElement = t.reportEventElement;
var showEvents = t.showEvents; var showEvents = t.showEvents;
var hideEvents = t.hideEvents; var hideEvents = t.hideEvents;
@ -3648,10 +3688,15 @@ function AgendaEventRenderer() {
var eventResize = t.eventResize; var eventResize = t.eventResize;
var renderDayOverlay = t.renderDayOverlay; var renderDayOverlay = t.renderDayOverlay;
var clearOverlays = t.clearOverlays; var clearOverlays = t.clearOverlays;
var renderDayEvents = t.renderDayEvents;
var calendar = t.calendar; var calendar = t.calendar;
var formatDate = calendar.formatDate; var formatDate = calendar.formatDate;
var formatDates = calendar.formatDates; var formatDates = calendar.formatDates;
// overrides
t.draggableDayEvent = draggableDayEvent;
/* Rendering /* Rendering
@ -3659,7 +3704,6 @@ function AgendaEventRenderer() {
function renderEvents(events, modifiedEventId) { function renderEvents(events, modifiedEventId) {
reportEvents(events);
var i, len=events.length, var i, len=events.length,
dayEvents=[], dayEvents=[],
slotEvents=[]; slotEvents=[];
@ -3670,67 +3714,96 @@ function AgendaEventRenderer() {
slotEvents.push(events[i]); slotEvents.push(events[i]);
} }
} }
if (opt('allDaySlot')) { if (opt('allDaySlot')) {
renderDaySegs(compileDaySegs(dayEvents), modifiedEventId); renderDayEvents(dayEvents, modifiedEventId);
setHeight(); // no params means set to viewHeight setHeight(); // no params means set to viewHeight
} }
renderSlotSegs(compileSlotSegs(slotEvents), modifiedEventId); renderSlotSegs(compileSlotSegs(slotEvents), modifiedEventId);
} }
function clearEvents() { function clearEvents() {
reportEventClear();
getDaySegmentContainer().empty(); getDaySegmentContainer().empty();
getSlotSegmentContainer().empty(); getSlotSegmentContainer().empty();
} }
function compileDaySegs(events) {
var levels = stackSegs(sliceSegs(events, $.map(events, exclEndDay), t.visStart, t.visEnd)),
i, levelCnt=levels.length, level,
j, seg,
segs=[];
for (i=0; i<levelCnt; i++) {
level = levels[i];
for (j=0; j<level.length; j++) {
seg = level[j];
seg.row = 0;
seg.level = i; // not needed anymore
segs.push(seg);
}
}
return segs;
}
function compileSlotSegs(events) { function compileSlotSegs(events) {
var colCnt = getColCnt(), var colCnt = getColCnt(),
minMinute = getMinMinute(), minMinute = getMinMinute(),
maxMinute = getMaxMinute(), maxMinute = getMaxMinute(),
d = addMinutes(cloneDate(t.visStart), minMinute), d,
visEventEnds = $.map(events, slotEventEnd), visEventEnds = $.map(events, slotEventEnd),
i, col, i,
j, level, j, seg,
k, seg, colSegs,
segs=[]; segs = [];
for (i=0; i<colCnt; i++) { for (i=0; i<colCnt; i++) {
col = stackSegs(sliceSegs(events, visEventEnds, d, addMinutes(cloneDate(d), maxMinute-minMinute)));
countForwardSegs(col); d = cellToDate(0, i);
for (j=0; j<col.length; j++) { addMinutes(d, minMinute);
level = col[j];
for (k=0; k<level.length; k++) { colSegs = sliceSegs(
seg = level[k]; events,
seg.col = i; visEventEnds,
seg.level = j; d,
segs.push(seg); addMinutes(cloneDate(d), maxMinute-minMinute)
} );
colSegs = placeSlotSegs(colSegs); // returns a new order
for (j=0; j<colSegs.length; j++) {
seg = colSegs[j];
seg.col = i;
segs.push(seg);
} }
addDays(d, 1, true);
} }
return segs; return segs;
} }
function sliceSegs(events, visEventEnds, start, end) {
var segs = [],
i, len=events.length, event,
eventStart, eventEnd,
segStart, segEnd,
isStart, isEnd;
for (i=0; i<len; i++) {
event = events[i];
eventStart = event.start;
eventEnd = visEventEnds[i];
if (eventEnd > start && eventStart < end) {
if (eventStart < start) {
segStart = cloneDate(start);
isStart = false;
}else{
segStart = eventStart;
isStart = true;
}
if (eventEnd > end) {
segEnd = cloneDate(end);
isEnd = false;
}else{
segEnd = eventEnd;
isEnd = true;
}
segs.push({
event: event,
start: segStart,
end: segEnd,
isStart: isStart,
isEnd: isEnd
});
}
}
return segs.sort(compareSlotSegs);
}
function slotEventEnd(event) { function slotEventEnd(event) {
if (event.end) { if (event.end) {
return cloneDate(event.end); return cloneDate(event.end);
@ -3741,38 +3814,29 @@ function AgendaEventRenderer() {
// renders events in the 'time slots' at the bottom // renders events in the 'time slots' at the bottom
// TODO: when we refactor this, when user returns `false` eventRender, don't have empty space
// TODO: refactor will include using pixels to detect collisions instead of dates (handy for seg cmp)
function renderSlotSegs(segs, modifiedEventId) { function renderSlotSegs(segs, modifiedEventId) {
var i, segCnt=segs.length, seg, var i, segCnt=segs.length, seg,
event, event,
classes, top,
top, bottom, bottom,
colI, levelI, forward, columnLeft,
leftmost, columnRight,
availWidth, columnWidth,
outerWidth, width,
left, left,
html='', right,
html = '',
eventElements, eventElements,
eventElement, eventElement,
triggerRes, triggerRes,
vsideCache={}, titleElement,
hsideCache={},
key, val,
contentElement,
height, height,
slotSegmentContainer = getSlotSegmentContainer(), slotSegmentContainer = getSlotSegmentContainer(),
rtl, dis, dit, isRTL = opt('isRTL');
colCnt = getColCnt();
if (rtl = opt('isRTL')) {
dis = -1;
dit = colCnt - 1;
}else{
dis = 1;
dit = 0;
}
// calculate position/dimensions, create html // calculate position/dimensions, create html
for (i=0; i<segCnt; i++) { for (i=0; i<segCnt; i++) {
@ -3780,33 +3844,48 @@ function AgendaEventRenderer() {
event = seg.event; event = seg.event;
top = timePosition(seg.start, seg.start); top = timePosition(seg.start, seg.start);
bottom = timePosition(seg.start, seg.end); bottom = timePosition(seg.start, seg.end);
colI = seg.col; columnLeft = colContentLeft(seg.col);
levelI = seg.level; columnRight = colContentRight(seg.col);
forward = seg.forward || 0; columnWidth = columnRight - columnLeft;
leftmost = colContentLeft(colI*dis + dit);
availWidth = colContentRight(colI*dis + dit) - leftmost; // shave off space on right near scrollbars (2.5%)
availWidth = Math.min(availWidth-6, availWidth*.95); // TODO: move this to CSS // TODO: move this to CSS somehow
if (levelI) { columnRight -= columnWidth * .025;
// indented and thin columnWidth = columnRight - columnLeft;
outerWidth = availWidth / (levelI + forward + 1);
}else{ width = columnWidth * (seg.forwardCoord - seg.backwardCoord);
if (forward) {
// moderately wide, aligned left still if (opt('slotEventOverlap')) {
outerWidth = ((availWidth / (forward + 1)) - (12/2)) * 2; // 12 is the predicted width of resizer = // double the width while making sure resize handle is visible
}else{ // (assumed to be 20px wide)
// can be entire width, aligned left width = Math.max(
outerWidth = availWidth; (width - (20/2)) * 2,
} width // narrow columns will want to make the segment smaller than
// the natural width. don't allow it
);
} }
left = leftmost + // leftmost possible
(availWidth / (levelI + forward + 1) * levelI) // indentation if (isRTL) {
* dis + (rtl ? availWidth - outerWidth : 0); // rtl right = columnRight - seg.backwardCoord * columnWidth;
left = right - width;
}
else {
left = columnLeft + seg.backwardCoord * columnWidth;
right = left + width;
}
// make sure horizontal coordinates are in bounds
left = Math.max(left, columnLeft);
right = Math.min(right, columnRight);
width = right - left;
seg.top = top; seg.top = top;
seg.left = left; seg.left = left;
seg.outerWidth = outerWidth; seg.outerWidth = width;
seg.outerHeight = bottom - top; seg.outerHeight = bottom - top;
html += slotSegHtml(event, seg); html += slotSegHtml(event, seg);
} }
slotSegmentContainer[0].innerHTML = html; // faster than html() slotSegmentContainer[0].innerHTML = html; // faster than html()
eventElements = slotSegmentContainer.children(); eventElements = slotSegmentContainer.children();
@ -3845,13 +3924,11 @@ function AgendaEventRenderer() {
for (i=0; i<segCnt; i++) { for (i=0; i<segCnt; i++) {
seg = segs[i]; seg = segs[i];
if (eventElement = seg.element) { if (eventElement = seg.element) {
val = vsideCache[key = seg.key = cssKey(eventElement[0])]; seg.vsides = vsides(eventElement, true);
seg.vsides = val === undefined ? (vsideCache[key] = vsides(eventElement, true)) : val; seg.hsides = hsides(eventElement, true);
val = hsideCache[key]; titleElement = eventElement.find('.fc-event-title');
seg.hsides = val === undefined ? (hsideCache[key] = hsides(eventElement, true)) : val; if (titleElement.length) {
contentElement = eventElement.find('div.fc-event-content'); seg.contentTop = titleElement[0].offsetTop;
if (contentElement.length) {
seg.contentTop = contentElement[0].offsetTop;
} }
} }
} }
@ -3865,7 +3942,7 @@ function AgendaEventRenderer() {
eventElement[0].style.height = height + 'px'; eventElement[0].style.height = height + 'px';
event = seg.event; event = seg.event;
if (seg.contentTop !== undefined && height - seg.contentTop < 10) { if (seg.contentTop !== undefined && height - seg.contentTop < 10) {
// not enough room for title, put it in the time header // not enough room for title, put it in the time (TODO: maybe make both display:inline instead)
eventElement.find('div.fc-event-time') eventElement.find('div.fc-event-time')
.text(formatDate(event.start, opt('timeFormat')) + ' - ' + event.title); .text(formatDate(event.start, opt('timeFormat')) + ' - ' + event.title);
eventElement.find('div.fc-event-title') eventElement.find('div.fc-event-title')
@ -3882,16 +3959,15 @@ function AgendaEventRenderer() {
var html = "<"; var html = "<";
var url = event.url; var url = event.url;
var skinCss = getSkinCss(event, opt); var skinCss = getSkinCss(event, opt);
var skinCssAttr = (skinCss ? " style='" + skinCss + "'" : ''); var classes = ['fc-event', 'fc-event-vert'];
var classes = ['fc-event', 'fc-event-skin', 'fc-event-vert'];
if (isEventDraggable(event)) { if (isEventDraggable(event)) {
classes.push('fc-event-draggable'); classes.push('fc-event-draggable');
} }
if (seg.isStart) { if (seg.isStart) {
classes.push('fc-corner-top'); classes.push('fc-event-start');
} }
if (seg.isEnd) { if (seg.isEnd) {
classes.push('fc-corner-bottom'); classes.push('fc-event-end');
} }
classes = classes.concat(event.className); classes = classes.concat(event.className);
if (event.source) { if (event.source) {
@ -3904,21 +3980,23 @@ function AgendaEventRenderer() {
} }
html += html +=
" class='" + classes.join(' ') + "'" + " class='" + classes.join(' ') + "'" +
" style='position:absolute;z-index:8;top:" + seg.top + "px;left:" + seg.left + "px;" + skinCss + "'" + " style=" +
"'" +
"position:absolute;" +
"top:" + seg.top + "px;" +
"left:" + seg.left + "px;" +
skinCss +
"'" +
">" + ">" +
"<div class='fc-event-inner fc-event-skin'" + skinCssAttr + ">" + "<div class='fc-event-inner'>" +
"<div class='fc-event-head fc-event-skin'" + skinCssAttr + ">" +
"<div class='fc-event-time'>" + "<div class='fc-event-time'>" +
htmlEscape(formatDates(event.start, event.end, opt('timeFormat'))) + htmlEscape(formatDates(event.start, event.end, opt('timeFormat'))) +
"</div>" + "</div>" +
"</div>" +
"<div class='fc-event-content'>" +
"<div class='fc-event-title'>" + "<div class='fc-event-title'>" +
htmlEscape(event.title) + htmlEscape(event.title || '') +
"</div>" + "</div>" +
"</div>" + "</div>" +
"<div class='fc-event-bg'></div>" + "<div class='fc-event-bg'></div>";
"</div>"; // close inner
if (seg.isEnd && isEventResizable(event)) { if (seg.isEnd && isEventResizable(event)) {
html += html +=
"<div class='ui-resizable-handle ui-resizable-s'>=</div>"; "<div class='ui-resizable-handle ui-resizable-s'>=</div>";
@ -3929,18 +4007,6 @@ function AgendaEventRenderer() {
} }
function bindDaySeg(event, eventElement, seg) {
if (isEventDraggable(event)) {
draggableDayEvent(event, eventElement, seg.isStart);
}
if (seg.isEnd && isEventResizable(event)) {
resizableDayEvent(event, eventElement, seg);
}
eventElementHandlers(event, eventElement);
// needs to be after, because resizableDayEvent might stopImmediatePropagation on click
}
function bindSlotSeg(event, eventElement, seg) { function bindSlotSeg(event, eventElement, seg) {
var timeElement = eventElement.find('div.fc-event-time'); var timeElement = eventElement.find('div.fc-event-time');
if (isEventDraggable(event)) { if (isEventDraggable(event)) {
@ -3959,31 +4025,34 @@ function AgendaEventRenderer() {
// when event starts out FULL-DAY // when event starts out FULL-DAY
// overrides DayEventRenderer's version because it needs to account for dragging elements
// to and from the slot area.
function draggableDayEvent(event, eventElement, isStart) { function draggableDayEvent(event, eventElement, seg) {
var isStart = seg.isStart;
var origWidth; var origWidth;
var revert; var revert;
var allDay=true; var allDay = true;
var dayDelta; var dayDelta;
var dis = opt('isRTL') ? -1 : 1;
var hoverListener = getHoverListener(); var hoverListener = getHoverListener();
var colWidth = getColWidth(); var colWidth = getColWidth();
var slotHeight = getSlotHeight(); var snapHeight = getSnapHeight();
var snapMinutes = getSnapMinutes();
var minMinute = getMinMinute(); var minMinute = getMinMinute();
eventElement.draggable({ eventElement.draggable({
zIndex: 9,
opacity: opt('dragOpacity', 'month'), // use whatever the month view was using opacity: opt('dragOpacity', 'month'), // use whatever the month view was using
revertDuration: opt('dragRevertDuration'), revertDuration: opt('dragRevertDuration'),
start: function(ev, ui) { start: function(ev, ui) {
trigger('eventDragStart', eventElement, event, ev, ui); trigger('eventDragStart', eventElement, event, ev, ui);
hideEvents(event, eventElement); hideEvents(event, eventElement);
origWidth = eventElement.width(); origWidth = eventElement.width();
hoverListener.start(function(cell, origCell, rowDelta, colDelta) { hoverListener.start(function(cell, origCell) {
clearOverlays(); clearOverlays();
if (cell) { if (cell) {
//setOverflowHidden(true);
revert = false; revert = false;
dayDelta = colDelta * dis; var origDate = cellToDate(0, origCell.col);
var date = cellToDate(0, cell.col);
dayDelta = dayDiff(date, origDate);
if (!cell.row) { if (!cell.row) {
// on full-days // on full-days
renderDayOverlay( renderDayOverlay(
@ -3999,9 +4068,9 @@ function AgendaEventRenderer() {
eventElement.width(colWidth - 10); // don't use entire width eventElement.width(colWidth - 10); // don't use entire width
setOuterHeight( setOuterHeight(
eventElement, eventElement,
slotHeight * Math.round( snapHeight * Math.round(
(event.end ? ((event.end - event.start) / MINUTE_MS) : opt('defaultEventMinutes')) (event.end ? ((event.end - event.start) / MINUTE_MS) : opt('defaultEventMinutes')) /
/ opt('slotMinutes') snapMinutes
) )
); );
eventElement.draggable('option', 'grid', [colWidth, 1]); eventElement.draggable('option', 'grid', [colWidth, 1]);
@ -4014,7 +4083,6 @@ function AgendaEventRenderer() {
revert = revert || (allDay && !dayDelta); revert = revert || (allDay && !dayDelta);
}else{ }else{
resetElement(); resetElement();
//setOverflowHidden(false);
revert = true; revert = true;
} }
eventElement.draggable('option', 'revert', revert); eventElement.draggable('option', 'revert', revert);
@ -4033,14 +4101,13 @@ function AgendaEventRenderer() {
// changed! // changed!
var minuteDelta = 0; var minuteDelta = 0;
if (!allDay) { if (!allDay) {
minuteDelta = Math.round((eventElement.offset().top - getBodyContent().offset().top) / slotHeight) minuteDelta = Math.round((eventElement.offset().top - getSlotContainer().offset().top) / snapHeight)
* opt('slotMinutes') * snapMinutes
+ minMinute + minMinute
- (event.start.getHours() * 60 + event.start.getMinutes()); - (event.start.getHours() * 60 + event.start.getMinutes());
} }
eventDrop(this, event, dayDelta, minuteDelta, allDay, ev, ui); eventDrop(this, event, dayDelta, minuteDelta, allDay, ev, ui);
} }
//setOverflowHidden(false);
} }
}); });
function resetElement() { function resetElement() {
@ -4058,78 +4125,147 @@ function AgendaEventRenderer() {
// when event starts out IN TIMESLOTS // when event starts out IN TIMESLOTS
function draggableSlotEvent(event, eventElement, timeElement) { function draggableSlotEvent(event, eventElement, timeElement) {
var origPosition; var coordinateGrid = t.getCoordinateGrid();
var allDay=false;
var dayDelta;
var minuteDelta;
var prevMinuteDelta;
var dis = opt('isRTL') ? -1 : 1;
var hoverListener = getHoverListener();
var colCnt = getColCnt(); var colCnt = getColCnt();
var colWidth = getColWidth(); var colWidth = getColWidth();
var slotHeight = getSlotHeight(); var snapHeight = getSnapHeight();
var snapMinutes = getSnapMinutes();
// states
var origPosition; // original position of the element, not the mouse
var origCell;
var isInBounds, prevIsInBounds;
var isAllDay, prevIsAllDay;
var colDelta, prevColDelta;
var dayDelta; // derived from colDelta
var minuteDelta, prevMinuteDelta;
eventElement.draggable({ eventElement.draggable({
zIndex: 9,
scroll: false, scroll: false,
grid: [colWidth, slotHeight], grid: [ colWidth, snapHeight ],
axis: colCnt==1 ? 'y' : false, axis: colCnt==1 ? 'y' : false,
opacity: opt('dragOpacity'), opacity: opt('dragOpacity'),
revertDuration: opt('dragRevertDuration'), revertDuration: opt('dragRevertDuration'),
start: function(ev, ui) { start: function(ev, ui) {
trigger('eventDragStart', eventElement, event, ev, ui); trigger('eventDragStart', eventElement, event, ev, ui);
hideEvents(event, eventElement); hideEvents(event, eventElement);
coordinateGrid.build();
// initialize states
origPosition = eventElement.position(); origPosition = eventElement.position();
origCell = coordinateGrid.cell(ev.pageX, ev.pageY);
isInBounds = prevIsInBounds = true;
isAllDay = prevIsAllDay = getIsCellAllDay(origCell);
colDelta = prevColDelta = 0;
dayDelta = 0;
minuteDelta = prevMinuteDelta = 0; minuteDelta = prevMinuteDelta = 0;
hoverListener.start(function(cell, origCell, rowDelta, colDelta) {
eventElement.draggable('option', 'revert', !cell);
clearOverlays();
if (cell) {
dayDelta = colDelta * dis;
if (opt('allDaySlot') && !cell.row) {
// over full days
if (!allDay) {
// convert to temporary all-day event
allDay = true;
timeElement.hide();
eventElement.draggable('option', 'grid', null);
}
renderDayOverlay(
addDays(cloneDate(event.start), dayDelta),
addDays(exclEndDay(event), dayDelta)
);
}else{
// on slots
resetElement();
}
}
}, ev, 'drag');
}, },
drag: function(ev, ui) { drag: function(ev, ui) {
minuteDelta = Math.round((ui.position.top - origPosition.top) / slotHeight) * opt('slotMinutes');
if (minuteDelta != prevMinuteDelta) { // NOTE: this `cell` value is only useful for determining in-bounds and all-day.
if (!allDay) { // Bad for anything else due to the discrepancy between the mouse position and the
updateTimeText(minuteDelta); // element position while snapping. (problem revealed in PR #55)
//
// PS- the problem exists for draggableDayEvent() when dragging an all-day event to a slot event.
// We should overhaul the dragging system and stop relying on jQuery UI.
var cell = coordinateGrid.cell(ev.pageX, ev.pageY);
// update states
isInBounds = !!cell;
if (isInBounds) {
isAllDay = getIsCellAllDay(cell);
// calculate column delta
colDelta = Math.round((ui.position.left - origPosition.left) / colWidth);
if (colDelta != prevColDelta) {
// calculate the day delta based off of the original clicked column and the column delta
var origDate = cellToDate(0, origCell.col);
var col = origCell.col + colDelta;
col = Math.max(0, col);
col = Math.min(colCnt-1, col);
var date = cellToDate(0, col);
dayDelta = dayDiff(date, origDate);
} }
// calculate minute delta (only if over slots)
if (!isAllDay) {
minuteDelta = Math.round((ui.position.top - origPosition.top) / snapHeight) * snapMinutes;
}
}
// any state changes?
if (
isInBounds != prevIsInBounds ||
isAllDay != prevIsAllDay ||
colDelta != prevColDelta ||
minuteDelta != prevMinuteDelta
) {
updateUI();
// update previous states for next time
prevIsInBounds = isInBounds;
prevIsAllDay = isAllDay;
prevColDelta = colDelta;
prevMinuteDelta = minuteDelta; prevMinuteDelta = minuteDelta;
} }
// if out-of-bounds, revert when done, and vice versa.
eventElement.draggable('option', 'revert', !isInBounds);
}, },
stop: function(ev, ui) { stop: function(ev, ui) {
var cell = hoverListener.stop();
clearOverlays(); clearOverlays();
trigger('eventDragStop', eventElement, event, ev, ui); trigger('eventDragStop', eventElement, event, ev, ui);
if (cell && (dayDelta || minuteDelta || allDay)) {
// changed! if (isInBounds && (isAllDay || dayDelta || minuteDelta)) { // changed!
eventDrop(this, event, dayDelta, allDay ? 0 : minuteDelta, allDay, ev, ui); eventDrop(this, event, dayDelta, isAllDay ? 0 : minuteDelta, isAllDay, ev, ui);
}else{ }
// either no change or out-of-bounds (draggable has already reverted) else { // either no change or out-of-bounds (draggable has already reverted)
resetElement();
// reset states for next time, and for updateUI()
isInBounds = true;
isAllDay = false;
colDelta = 0;
dayDelta = 0;
minuteDelta = 0;
updateUI();
eventElement.css('filter', ''); // clear IE opacity side-effects eventElement.css('filter', ''); // clear IE opacity side-effects
eventElement.css(origPosition); // sometimes fast drags make event revert to wrong position
updateTimeText(0); // sometimes fast drags make event revert to wrong position, so reset.
// also, if we dragged the element out of the area because of snapping,
// but the *mouse* is still in bounds, we need to reset the position.
eventElement.css(origPosition);
showEvents(event, eventElement); showEvents(event, eventElement);
} }
} }
}); });
function updateUI() {
clearOverlays();
if (isInBounds) {
if (isAllDay) {
timeElement.hide();
eventElement.draggable('option', 'grid', null); // disable grid snapping
renderDayOverlay(
addDays(cloneDate(event.start), dayDelta),
addDays(exclEndDay(event), dayDelta)
);
}
else {
updateTimeText(minuteDelta);
timeElement.css('display', ''); // show() was causing display=inline
eventElement.draggable('option', 'grid', [colWidth, snapHeight]); // re-enable grid snapping
}
}
}
function updateTimeText(minuteDelta) { function updateTimeText(minuteDelta) {
var newStart = addMinutes(cloneDate(event.start), minuteDelta); var newStart = addMinutes(cloneDate(event.start), minuteDelta);
var newEnd; var newEnd;
@ -4138,14 +4274,7 @@ function AgendaEventRenderer() {
} }
timeElement.text(formatDates(newStart, newEnd, opt('timeFormat'))); timeElement.text(formatDates(newStart, newEnd, opt('timeFormat')));
} }
function resetElement() {
// convert back to original slot-event
if (allDay) {
timeElement.css('display', ''); // show() was causing display=inline
eventElement.draggable('option', 'grid', [colWidth, slotHeight]);
allDay = false;
}
}
} }
@ -4155,40 +4284,39 @@ function AgendaEventRenderer() {
function resizableSlotEvent(event, eventElement, timeElement) { function resizableSlotEvent(event, eventElement, timeElement) {
var slotDelta, prevSlotDelta; var snapDelta, prevSnapDelta;
var slotHeight = getSlotHeight(); var snapHeight = getSnapHeight();
var snapMinutes = getSnapMinutes();
eventElement.resizable({ eventElement.resizable({
handles: { handles: {
s: 'div.ui-resizable-s' s: '.ui-resizable-handle'
}, },
grid: slotHeight, grid: snapHeight,
start: function(ev, ui) { start: function(ev, ui) {
slotDelta = prevSlotDelta = 0; snapDelta = prevSnapDelta = 0;
hideEvents(event, eventElement); hideEvents(event, eventElement);
eventElement.css('z-index', 9);
trigger('eventResizeStart', this, event, ev, ui); trigger('eventResizeStart', this, event, ev, ui);
}, },
resize: function(ev, ui) { resize: function(ev, ui) {
// don't rely on ui.size.height, doesn't take grid into account // don't rely on ui.size.height, doesn't take grid into account
slotDelta = Math.round((Math.max(slotHeight, eventElement.height()) - ui.originalSize.height) / slotHeight); snapDelta = Math.round((Math.max(snapHeight, eventElement.height()) - ui.originalSize.height) / snapHeight);
if (slotDelta != prevSlotDelta) { if (snapDelta != prevSnapDelta) {
timeElement.text( timeElement.text(
formatDates( formatDates(
event.start, event.start,
(!slotDelta && !event.end) ? null : // no change, so don't display time range (!snapDelta && !event.end) ? null : // no change, so don't display time range
addMinutes(eventEnd(event), opt('slotMinutes')*slotDelta), addMinutes(eventEnd(event), snapMinutes*snapDelta),
opt('timeFormat') opt('timeFormat')
) )
); );
prevSlotDelta = slotDelta; prevSnapDelta = snapDelta;
} }
}, },
stop: function(ev, ui) { stop: function(ev, ui) {
trigger('eventResizeStop', this, event, ev, ui); trigger('eventResizeStop', this, event, ev, ui);
if (slotDelta) { if (snapDelta) {
eventResize(this, event, 0, opt('slotMinutes')*slotDelta, ev, ui); eventResize(this, event, 0, snapMinutes*snapDelta, ev, ui);
}else{ }else{
eventElement.css('z-index', 8);
showEvents(event, eventElement); showEvents(event, eventElement);
// BUG: if event was really short, need to put title back in span // BUG: if event was really short, need to put title back in span
} }
@ -4200,23 +4328,213 @@ function AgendaEventRenderer() {
} }
function countForwardSegs(levels) {
var i, j, k, level, segForward, segBack; /* Agenda Event Segment Utilities
for (i=levels.length-1; i>0; i--) { -----------------------------------------------------------------------------*/
// Sets the seg.backwardCoord and seg.forwardCoord on each segment and returns a new
// list in the order they should be placed into the DOM (an implicit z-index).
function placeSlotSegs(segs) {
var levels = buildSlotSegLevels(segs);
var level0 = levels[0];
var i;
computeForwardSlotSegs(levels);
if (level0) {
for (i=0; i<level0.length; i++) {
computeSlotSegPressures(level0[i]);
}
for (i=0; i<level0.length; i++) {
computeSlotSegCoords(level0[i], 0, 0);
}
}
return flattenSlotSegLevels(levels);
}
// Builds an array of segments "levels". The first level will be the leftmost tier of segments
// if the calendar is left-to-right, or the rightmost if the calendar is right-to-left.
function buildSlotSegLevels(segs) {
var levels = [];
var i, seg;
var j;
for (i=0; i<segs.length; i++) {
seg = segs[i];
// go through all the levels and stop on the first level where there are no collisions
for (j=0; j<levels.length; j++) {
if (!computeSlotSegCollisions(seg, levels[j]).length) {
break;
}
}
(levels[j] || (levels[j] = [])).push(seg);
}
return levels;
}
// For every segment, figure out the other segments that are in subsequent
// levels that also occupy the same vertical space. Accumulate in seg.forwardSegs
function computeForwardSlotSegs(levels) {
var i, level;
var j, seg;
var k;
for (i=0; i<levels.length; i++) {
level = levels[i]; level = levels[i];
for (j=0; j<level.length; j++) { for (j=0; j<level.length; j++) {
segForward = level[j]; seg = level[j];
for (k=0; k<levels[i-1].length; k++) {
segBack = levels[i-1][k]; seg.forwardSegs = [];
if (segsCollide(segForward, segBack)) { for (k=i+1; k<levels.length; k++) {
segBack.forward = Math.max(segBack.forward||0, (segForward.forward||0)+1); computeSlotSegCollisions(seg, levels[k], seg.forwardSegs);
}
} }
} }
} }
} }
// Figure out which path forward (via seg.forwardSegs) results in the longest path until
// the furthest edge is reached. The number of segments in this path will be seg.forwardPressure
function computeSlotSegPressures(seg) {
var forwardSegs = seg.forwardSegs;
var forwardPressure = 0;
var i, forwardSeg;
if (seg.forwardPressure === undefined) { // not already computed
for (i=0; i<forwardSegs.length; i++) {
forwardSeg = forwardSegs[i];
// figure out the child's maximum forward path
computeSlotSegPressures(forwardSeg);
// either use the existing maximum, or use the child's forward pressure
// plus one (for the forwardSeg itself)
forwardPressure = Math.max(
forwardPressure,
1 + forwardSeg.forwardPressure
);
}
seg.forwardPressure = forwardPressure;
}
}
// Calculate seg.forwardCoord and seg.backwardCoord for the segment, where both values range
// from 0 to 1. If the calendar is left-to-right, the seg.backwardCoord maps to "left" and
// seg.forwardCoord maps to "right" (via percentage). Vice-versa if the calendar is right-to-left.
//
// The segment might be part of a "series", which means consecutive segments with the same pressure
// who's width is unknown until an edge has been hit. `seriesBackwardPressure` is the number of
// segments behind this one in the current series, and `seriesBackwardCoord` is the starting
// coordinate of the first segment in the series.
function computeSlotSegCoords(seg, seriesBackwardPressure, seriesBackwardCoord) {
var forwardSegs = seg.forwardSegs;
var i;
if (seg.forwardCoord === undefined) { // not already computed
if (!forwardSegs.length) {
// if there are no forward segments, this segment should butt up against the edge
seg.forwardCoord = 1;
}
else {
// sort highest pressure first
forwardSegs.sort(compareForwardSlotSegs);
// this segment's forwardCoord will be calculated from the backwardCoord of the
// highest-pressure forward segment.
computeSlotSegCoords(forwardSegs[0], seriesBackwardPressure + 1, seriesBackwardCoord);
seg.forwardCoord = forwardSegs[0].backwardCoord;
}
// calculate the backwardCoord from the forwardCoord. consider the series
seg.backwardCoord = seg.forwardCoord -
(seg.forwardCoord - seriesBackwardCoord) / // available width for series
(seriesBackwardPressure + 1); // # of segments in the series
// use this segment's coordinates to computed the coordinates of the less-pressurized
// forward segments
for (i=0; i<forwardSegs.length; i++) {
computeSlotSegCoords(forwardSegs[i], 0, seg.forwardCoord);
}
}
}
// Outputs a flat array of segments, from lowest to highest level
function flattenSlotSegLevels(levels) {
var segs = [];
var i, level;
var j;
for (i=0; i<levels.length; i++) {
level = levels[i];
for (j=0; j<level.length; j++) {
segs.push(level[j]);
}
}
return segs;
}
// Find all the segments in `otherSegs` that vertically collide with `seg`.
// Append into an optionally-supplied `results` array and return.
function computeSlotSegCollisions(seg, otherSegs, results) {
results = results || [];
for (var i=0; i<otherSegs.length; i++) {
if (isSlotSegCollision(seg, otherSegs[i])) {
results.push(otherSegs[i]);
}
}
return results;
}
// Do these segments occupy the same vertical space?
function isSlotSegCollision(seg1, seg2) {
return seg1.end > seg2.start && seg1.start < seg2.end;
}
// A cmp function for determining which forward segment to rely on more when computing coordinates.
function compareForwardSlotSegs(seg1, seg2) {
// put higher-pressure first
return seg2.forwardPressure - seg1.forwardPressure ||
// put segments that are closer to initial edge first (and favor ones with no coords yet)
(seg1.backwardCoord || 0) - (seg2.backwardCoord || 0) ||
// do normal sorting...
compareSlotSegs(seg1, seg2);
}
// A cmp function for determining which segment should be closer to the initial edge
// (the left edge on a left-to-right calendar).
function compareSlotSegs(seg1, seg2) {
return seg1.start - seg2.start || // earlier start time goes first
(seg2.end - seg2.start) - (seg1.end - seg1.start) || // tie? longer-duration goes first
(seg1.event.title || '').localeCompare(seg2.event.title); // tie? alphabetically by title
}
;;
function View(element, calendar, viewName) { function View(element, calendar, viewName) {
@ -4229,13 +4547,13 @@ function View(element, calendar, viewName) {
t.name = viewName; t.name = viewName;
t.opt = opt; t.opt = opt;
t.trigger = trigger; t.trigger = trigger;
//t.setOverflowHidden = setOverflowHidden;
t.isEventDraggable = isEventDraggable; t.isEventDraggable = isEventDraggable;
t.isEventResizable = isEventResizable; t.isEventResizable = isEventResizable;
t.reportEvents = reportEvents; t.setEventData = setEventData;
t.clearEventData = clearEventData;
t.eventEnd = eventEnd; t.eventEnd = eventEnd;
t.reportEventElement = reportEventElement; t.reportEventElement = reportEventElement;
t.reportEventClear = reportEventClear; t.triggerEventDestroy = triggerEventDestroy;
t.eventElementHandlers = eventElementHandlers; t.eventElementHandlers = eventElementHandlers;
t.showEvents = showEvents; t.showEvents = showEvents;
t.hideEvents = hideEvents; t.hideEvents = hideEvents;
@ -4253,16 +4571,16 @@ function View(element, calendar, viewName) {
// locals // locals
var eventsByID = {}; var eventsByID = {}; // eventID mapped to array of events (there can be multiple b/c of repeating events)
var eventElements = []; var eventElementsByID = {}; // eventID mapped to array of jQuery elements
var eventElementsByID = {}; var eventElementCouples = []; // array of objects, { event, element } // TODO: unify with segment system
var options = calendar.options; var options = calendar.options;
function opt(name, viewNameOverride) { function opt(name, viewNameOverride) {
var v = options[name]; var v = options[name];
if (typeof v == 'object') { if ($.isPlainObject(v)) {
return smartProperty(v, viewNameOverride || viewName); return smartProperty(v, viewNameOverride || viewName);
} }
return v; return v;
@ -4276,26 +4594,37 @@ function View(element, calendar, viewName) {
); );
} }
/*
function setOverflowHidden(bool) { /* Event Editable Boolean Calculations
element.css('overflow', bool ? 'hidden' : ''); ------------------------------------------------------------------------------*/
}
*/
function isEventDraggable(event) { function isEventDraggable(event) {
return isEventEditable(event) && !opt('disableDragging'); var source = event.source || {};
return firstDefined(
event.startEditable,
source.startEditable,
opt('eventStartEditable'),
event.editable,
source.editable,
opt('editable')
)
&& !opt('disableDragging'); // deprecated
} }
function isEventResizable(event) { // but also need to make sure the seg.isEnd == true function isEventResizable(event) { // but also need to make sure the seg.isEnd == true
return isEventEditable(event) && !opt('disableResizing'); var source = event.source || {};
} return firstDefined(
event.durationEditable,
source.durationEditable,
function isEventEditable(event) { opt('eventDurationEditable'),
return firstDefined(event.editable, (event.source || {}).editable, opt('editable')); event.editable,
source.editable,
opt('editable')
)
&& !opt('disableResizing'); // deprecated
} }
@ -4304,8 +4633,7 @@ function View(element, calendar, viewName) {
------------------------------------------------------------------------------*/ ------------------------------------------------------------------------------*/
// report when view receives new events function setEventData(events) { // events are already normalized at this point
function reportEvents(events) { // events are already normalized at this point
eventsByID = {}; eventsByID = {};
var i, len=events.length, event; var i, len=events.length, event;
for (i=0; i<len; i++) { for (i=0; i<len; i++) {
@ -4317,6 +4645,13 @@ function View(element, calendar, viewName) {
} }
} }
} }
function clearEventData() {
eventsByID = {};
eventElementsByID = {};
eventElementCouples = [];
}
// returns a Date object for an event's end // returns a Date object for an event's end
@ -4332,18 +4667,19 @@ function View(element, calendar, viewName) {
// report when view creates an element for an event // report when view creates an element for an event
function reportEventElement(event, element) { function reportEventElement(event, element) {
eventElements.push(element); eventElementCouples.push({ event: event, element: element });
if (eventElementsByID[event._id]) { if (eventElementsByID[event._id]) {
eventElementsByID[event._id].push(element); eventElementsByID[event._id].push(element);
}else{ }else{
eventElementsByID[event._id] = [element]; eventElementsByID[event._id] = [element];
} }
} }
function reportEventClear() { function triggerEventDestroy() {
eventElements = []; $.each(eventElementCouples, function(i, couple) {
eventElementsByID = {}; t.trigger('eventDestroy', couple.event, couple.event, couple.element);
});
} }
@ -4380,6 +4716,8 @@ function View(element, calendar, viewName) {
function eachEventElement(event, exceptElement, funcName) { function eachEventElement(event, exceptElement, funcName) {
// NOTE: there may be multiple events per ID (repeating events)
// and multiple segments per event
var elements = eventElementsByID[event._id], var elements = eventElementsByID[event._id],
i, len = elements.length; i, len = elements.length;
for (i=0; i<len; i++) { for (i=0; i<len; i++) {
@ -4468,17 +4806,286 @@ function View(element, calendar, viewName) {
normalizeEvent(e, options); normalizeEvent(e, options);
} }
} }
// ====================================================================================================
// Utilities for day "cells"
// ====================================================================================================
// The "basic" views are completely made up of day cells.
// The "agenda" views have day cells at the top "all day" slot.
// This was the obvious common place to put these utilities, but they should be abstracted out into
// a more meaningful class (like DayEventRenderer).
// ====================================================================================================
// For determining how a given "cell" translates into a "date":
//
// 1. Convert the "cell" (row and column) into a "cell offset" (the # of the cell, cronologically from the first).
// Keep in mind that column indices are inverted with isRTL. This is taken into account.
//
// 2. Convert the "cell offset" to a "day offset" (the # of days since the first visible day in the view).
//
// 3. Convert the "day offset" into a "date" (a JavaScript Date object).
//
// The reverse transformation happens when transforming a date into a cell.
// exports
t.isHiddenDay = isHiddenDay;
t.skipHiddenDays = skipHiddenDays;
t.getCellsPerWeek = getCellsPerWeek;
t.dateToCell = dateToCell;
t.dateToDayOffset = dateToDayOffset;
t.dayOffsetToCellOffset = dayOffsetToCellOffset;
t.cellOffsetToCell = cellOffsetToCell;
t.cellToDate = cellToDate;
t.cellToCellOffset = cellToCellOffset;
t.cellOffsetToDayOffset = cellOffsetToDayOffset;
t.dayOffsetToDate = dayOffsetToDate;
t.rangeToSegments = rangeToSegments;
// internals
var hiddenDays = opt('hiddenDays') || []; // array of day-of-week indices that are hidden
var isHiddenDayHash = []; // is the day-of-week hidden? (hash with day-of-week-index -> bool)
var cellsPerWeek;
var dayToCellMap = []; // hash from dayIndex -> cellIndex, for one week
var cellToDayMap = []; // hash from cellIndex -> dayIndex, for one week
var isRTL = opt('isRTL');
// initialize important internal variables
(function() {
if (opt('weekends') === false) {
hiddenDays.push(0, 6); // 0=sunday, 6=saturday
}
// Loop through a hypothetical week and determine which
// days-of-week are hidden. Record in both hashes (one is the reverse of the other).
for (var dayIndex=0, cellIndex=0; dayIndex<7; dayIndex++) {
dayToCellMap[dayIndex] = cellIndex;
isHiddenDayHash[dayIndex] = $.inArray(dayIndex, hiddenDays) != -1;
if (!isHiddenDayHash[dayIndex]) {
cellToDayMap[cellIndex] = dayIndex;
cellIndex++;
}
}
cellsPerWeek = cellIndex;
if (!cellsPerWeek) {
throw 'invalid hiddenDays'; // all days were hidden? bad.
}
})();
// Is the current day hidden?
// `day` is a day-of-week index (0-6), or a Date object
function isHiddenDay(day) {
if (typeof day == 'object') {
day = day.getDay();
}
return isHiddenDayHash[day];
}
function getCellsPerWeek() {
return cellsPerWeek;
}
// Keep incrementing the current day until it is no longer a hidden day.
// If the initial value of `date` is not a hidden day, don't do anything.
// Pass `isExclusive` as `true` if you are dealing with an end date.
// `inc` defaults to `1` (increment one day forward each time)
function skipHiddenDays(date, inc, isExclusive) {
inc = inc || 1;
while (
isHiddenDayHash[ ( date.getDay() + (isExclusive ? inc : 0) + 7 ) % 7 ]
) {
addDays(date, inc);
}
}
//
// TRANSFORMATIONS: cell -> cell offset -> day offset -> date
//
// cell -> date (combines all transformations)
// Possible arguments:
// - row, col
// - { row:#, col: # }
function cellToDate() {
var cellOffset = cellToCellOffset.apply(null, arguments);
var dayOffset = cellOffsetToDayOffset(cellOffset);
var date = dayOffsetToDate(dayOffset);
return date;
}
// cell -> cell offset
// Possible arguments:
// - row, col
// - { row:#, col:# }
function cellToCellOffset(row, col) {
var colCnt = t.getColCnt();
// rtl variables. wish we could pre-populate these. but where?
var dis = isRTL ? -1 : 1;
var dit = isRTL ? colCnt - 1 : 0;
if (typeof row == 'object') {
col = row.col;
row = row.row;
}
var cellOffset = row * colCnt + (col * dis + dit); // column, adjusted for RTL (dis & dit)
return cellOffset;
}
// cell offset -> day offset
function cellOffsetToDayOffset(cellOffset) {
var day0 = t.visStart.getDay(); // first date's day of week
cellOffset += dayToCellMap[day0]; // normlize cellOffset to beginning-of-week
return Math.floor(cellOffset / cellsPerWeek) * 7 // # of days from full weeks
+ cellToDayMap[ // # of days from partial last week
(cellOffset % cellsPerWeek + cellsPerWeek) % cellsPerWeek // crazy math to handle negative cellOffsets
]
- day0; // adjustment for beginning-of-week normalization
}
// day offset -> date (JavaScript Date object)
function dayOffsetToDate(dayOffset) {
var date = cloneDate(t.visStart);
addDays(date, dayOffset);
return date;
}
//
// TRANSFORMATIONS: date -> day offset -> cell offset -> cell
//
// date -> cell (combines all transformations)
function dateToCell(date) {
var dayOffset = dateToDayOffset(date);
var cellOffset = dayOffsetToCellOffset(dayOffset);
var cell = cellOffsetToCell(cellOffset);
return cell;
}
// date -> day offset
function dateToDayOffset(date) {
return dayDiff(date, t.visStart);
}
// day offset -> cell offset
function dayOffsetToCellOffset(dayOffset) {
var day0 = t.visStart.getDay(); // first date's day of week
dayOffset += day0; // normalize dayOffset to beginning-of-week
return Math.floor(dayOffset / 7) * cellsPerWeek // # of cells from full weeks
+ dayToCellMap[ // # of cells from partial last week
(dayOffset % 7 + 7) % 7 // crazy math to handle negative dayOffsets
]
- dayToCellMap[day0]; // adjustment for beginning-of-week normalization
}
// cell offset -> cell (object with row & col keys)
function cellOffsetToCell(cellOffset) {
var colCnt = t.getColCnt();
// rtl variables. wish we could pre-populate these. but where?
var dis = isRTL ? -1 : 1;
var dit = isRTL ? colCnt - 1 : 0;
var row = Math.floor(cellOffset / colCnt);
var col = ((cellOffset % colCnt + colCnt) % colCnt) * dis + dit; // column, adjusted for RTL (dis & dit)
return {
row: row,
col: col
};
}
//
// Converts a date range into an array of segment objects.
// "Segments" are horizontal stretches of time, sliced up by row.
// A segment object has the following properties:
// - row
// - cols
// - isStart
// - isEnd
//
function rangeToSegments(startDate, endDate) {
var rowCnt = t.getRowCnt();
var colCnt = t.getColCnt();
var segments = []; // array of segments to return
// day offset for given date range
var rangeDayOffsetStart = dateToDayOffset(startDate);
var rangeDayOffsetEnd = dateToDayOffset(endDate); // exclusive
// first and last cell offset for the given date range
// "last" implies inclusivity
var rangeCellOffsetFirst = dayOffsetToCellOffset(rangeDayOffsetStart);
var rangeCellOffsetLast = dayOffsetToCellOffset(rangeDayOffsetEnd) - 1;
// loop through all the rows in the view
for (var row=0; row<rowCnt; row++) {
// first and last cell offset for the row
var rowCellOffsetFirst = row * colCnt;
var rowCellOffsetLast = rowCellOffsetFirst + colCnt - 1;
// get the segment's cell offsets by constraining the range's cell offsets to the bounds of the row
var segmentCellOffsetFirst = Math.max(rangeCellOffsetFirst, rowCellOffsetFirst);
var segmentCellOffsetLast = Math.min(rangeCellOffsetLast, rowCellOffsetLast);
// make sure segment's offsets are valid and in view
if (segmentCellOffsetFirst <= segmentCellOffsetLast) {
// translate to cells
var segmentCellFirst = cellOffsetToCell(segmentCellOffsetFirst);
var segmentCellLast = cellOffsetToCell(segmentCellOffsetLast);
// view might be RTL, so order by leftmost column
var cols = [ segmentCellFirst.col, segmentCellLast.col ].sort();
// Determine if segment's first/last cell is the beginning/end of the date range.
// We need to compare "day offset" because "cell offsets" are often ambiguous and
// can translate to multiple days, and an edge case reveals itself when we the
// range's first cell is hidden (we don't want isStart to be true).
var isStart = cellOffsetToDayOffset(segmentCellOffsetFirst) == rangeDayOffsetStart;
var isEnd = cellOffsetToDayOffset(segmentCellOffsetLast) + 1 == rangeDayOffsetEnd; // +1 for comparing exclusively
segments.push({
row: row,
leftCol: cols[0],
rightCol: cols[1],
isStart: isStart,
isEnd: isEnd
});
}
}
return segments;
}
} }
;;
function DayEventRenderer() { function DayEventRenderer() {
var t = this; var t = this;
// exports // exports
t.renderDaySegs = renderDaySegs; t.renderDayEvents = renderDayEvents;
t.resizableDayEvent = resizableDayEvent; t.draggableDayEvent = draggableDayEvent; // made public so that subclasses can override
t.resizableDayEvent = resizableDayEvent; // "
// imports // imports
@ -4488,378 +5095,601 @@ function DayEventRenderer() {
var isEventResizable = t.isEventResizable; var isEventResizable = t.isEventResizable;
var eventEnd = t.eventEnd; var eventEnd = t.eventEnd;
var reportEventElement = t.reportEventElement; var reportEventElement = t.reportEventElement;
var eventElementHandlers = t.eventElementHandlers;
var showEvents = t.showEvents; var showEvents = t.showEvents;
var hideEvents = t.hideEvents; var hideEvents = t.hideEvents;
var eventDrop = t.eventDrop;
var eventResize = t.eventResize; var eventResize = t.eventResize;
var getRowCnt = t.getRowCnt; var getRowCnt = t.getRowCnt;
var getColCnt = t.getColCnt; var getColCnt = t.getColCnt;
var getColWidth = t.getColWidth; var getColWidth = t.getColWidth;
var allDayRow = t.allDayRow; var allDayRow = t.allDayRow; // TODO: rename
var allDayBounds = t.allDayBounds; var colLeft = t.colLeft;
var colRight = t.colRight;
var colContentLeft = t.colContentLeft; var colContentLeft = t.colContentLeft;
var colContentRight = t.colContentRight; var colContentRight = t.colContentRight;
var dayOfWeekCol = t.dayOfWeekCol; var dateToCell = t.dateToCell;
var dateCell = t.dateCell;
var compileDaySegs = t.compileDaySegs;
var getDaySegmentContainer = t.getDaySegmentContainer; var getDaySegmentContainer = t.getDaySegmentContainer;
var bindDaySeg = t.bindDaySeg; //TODO: streamline this
var formatDates = t.calendar.formatDates; var formatDates = t.calendar.formatDates;
var renderDayOverlay = t.renderDayOverlay; var renderDayOverlay = t.renderDayOverlay;
var clearOverlays = t.clearOverlays; var clearOverlays = t.clearOverlays;
var clearSelection = t.clearSelection; var clearSelection = t.clearSelection;
var getHoverListener = t.getHoverListener;
var rangeToSegments = t.rangeToSegments;
var cellToDate = t.cellToDate;
/* Rendering var cellToCellOffset = t.cellToCellOffset;
-----------------------------------------------------------------------------*/ var cellOffsetToDayOffset = t.cellOffsetToDayOffset;
var dateToDayOffset = t.dateToDayOffset;
var dayOffsetToCellOffset = t.dayOffsetToCellOffset;
function renderDaySegs(segs, modifiedEventId) {
var segmentContainer = getDaySegmentContainer();
var rowDivs; // Render `events` onto the calendar, attach mouse event handlers, and call the `eventAfterRender` callback for each.
var rowCnt = getRowCnt(); // Mouse event will be lazily applied, except if the event has an ID of `modifiedEventId`.
var colCnt = getColCnt(); // Can only be called when the event container is empty (because it wipes out all innerHTML).
var i = 0; function renderDayEvents(events, modifiedEventId) {
var rowI;
var levelI; // do the actual rendering. Receive the intermediate "segment" data structures.
var colHeights; var segments = _renderDayEvents(
var j; events,
var segCnt = segs.length; false, // don't append event elements
var seg; true // set the heights of the rows
var top; );
var k;
segmentContainer[0].innerHTML = daySegHTML(segs); // faster than .html() // report the elements to the View, for general drag/resize utilities
daySegElementResolve(segs, segmentContainer.children()); segmentElementEach(segments, function(segment, element) {
daySegElementReport(segs); reportEventElement(segment.event, element);
daySegHandlers(segs, segmentContainer, modifiedEventId); });
daySegCalcHSides(segs);
daySegSetWidths(segs); // attach mouse handlers
daySegCalcHeights(segs); attachHandlers(segments, modifiedEventId);
rowDivs = getRowDivs();
// set row heights, calculate event tops (in relation to row top) // call `eventAfterRender` callback for each event
for (rowI=0; rowI<rowCnt; rowI++) { segmentElementEach(segments, function(segment, element) {
levelI = 0; trigger('eventAfterRender', segment.event, segment.event, element);
colHeights = []; });
for (j=0; j<colCnt; j++) {
colHeights[j] = 0;
}
while (i<segCnt && (seg = segs[i]).row == rowI) {
// loop through segs in a row
top = arrayMax(colHeights.slice(seg.startCol, seg.endCol));
seg.top = top;
top += seg.outerHeight;
for (k=seg.startCol; k<seg.endCol; k++) {
colHeights[k] = top;
}
i++;
}
rowDivs[rowI].height(arrayMax(colHeights));
}
daySegSetTops(segs, getRowTops(rowDivs));
} }
function renderTempDaySegs(segs, adjustRow, adjustTop) { // Render an event on the calendar, but don't report them anywhere, and don't attach mouse handlers.
var tempContainer = $("<div/>"); // Append this event element to the event container, which might already be populated with events.
// If an event's segment will have row equal to `adjustRow`, then explicitly set its top coordinate to `adjustTop`.
// This hack is used to maintain continuity when user is manually resizing an event.
// Returns an array of DOM elements for the event.
function renderTempDayEvent(event, adjustRow, adjustTop) {
// actually render the event. `true` for appending element to container.
// Recieve the intermediate "segment" data structures.
var segments = _renderDayEvents(
[ event ],
true, // append event elements
false // don't set the heights of the rows
);
var elements = [];
// Adjust certain elements' top coordinates
segmentElementEach(segments, function(segment, element) {
if (segment.row === adjustRow) {
element.css('top', adjustTop);
}
elements.push(element[0]); // accumulate DOM nodes
});
return elements;
}
// Render events onto the calendar. Only responsible for the VISUAL aspect.
// Not responsible for attaching handlers or calling callbacks.
// Set `doAppend` to `true` for rendering elements without clearing the existing container.
// Set `doRowHeights` to allow setting the height of each row, to compensate for vertical event overflow.
function _renderDayEvents(events, doAppend, doRowHeights) {
// where the DOM nodes will eventually end up
var finalContainer = getDaySegmentContainer();
// the container where the initial HTML will be rendered.
// If `doAppend`==true, uses a temporary container.
var renderContainer = doAppend ? $("<div/>") : finalContainer;
var segments = buildSegments(events);
var html;
var elements; var elements;
var segmentContainer = getDaySegmentContainer();
var i; // calculate the desired `left` and `width` properties on each segment object
var segCnt = segs.length; calculateHorizontals(segments);
var element;
tempContainer[0].innerHTML = daySegHTML(segs); // faster than .html() // build the HTML string. relies on `left` property
elements = tempContainer.children(); html = buildHTML(segments);
segmentContainer.append(elements);
daySegElementResolve(segs, elements); // render the HTML. innerHTML is considerably faster than jQuery's .html()
daySegCalcHSides(segs); renderContainer[0].innerHTML = html;
daySegSetWidths(segs);
daySegCalcHeights(segs); // retrieve the individual elements
daySegSetTops(segs, getRowTops(getRowDivs())); elements = renderContainer.children();
elements = [];
for (i=0; i<segCnt; i++) { // if we were appending, and thus using a temporary container,
element = segs[i].element; // re-attach elements to the real container.
if (element) { if (doAppend) {
if (segs[i].row === adjustRow) { finalContainer.append(elements);
element.css('top', adjustTop);
}
elements.push(element[0]);
}
} }
return $(elements);
// assigns each element to `segment.event`, after filtering them through user callbacks
resolveElements(segments, elements);
// Calculate the left and right padding+margin for each element.
// We need this for setting each element's desired outer width, because of the W3C box model.
// It's important we do this in a separate pass from acually setting the width on the DOM elements
// because alternating reading/writing dimensions causes reflow for every iteration.
segmentElementEach(segments, function(segment, element) {
segment.hsides = hsides(element, true); // include margins = `true`
});
// Set the width of each element
segmentElementEach(segments, function(segment, element) {
element.width(
Math.max(0, segment.outerWidth - segment.hsides)
);
});
// Grab each element's outerHeight (setVerticals uses this).
// To get an accurate reading, it's important to have each element's width explicitly set already.
segmentElementEach(segments, function(segment, element) {
segment.outerHeight = element.outerHeight(true); // include margins = `true`
});
// Set the top coordinate on each element (requires segment.outerHeight)
setVerticals(segments, doRowHeights);
return segments;
} }
function daySegHTML(segs) { // also sets seg.left and seg.outerWidth // Generate an array of "segments" for all events.
var rtl = opt('isRTL'); function buildSegments(events) {
var i; var segments = [];
var segCnt=segs.length; for (var i=0; i<events.length; i++) {
var seg; var eventSegments = buildSegmentsForEvent(events[i]);
var event; segments.push.apply(segments, eventSegments); // append an array to an array
var url; }
var classes; return segments;
var bounds = allDayBounds(); }
var minLeft = bounds.left;
var maxLeft = bounds.right;
var leftCol; // Generate an array of segments for a single event.
var rightCol; // A "segment" is the same data structure that View.rangeToSegments produces,
var left; // with the addition of the `event` property being set to reference the original event.
var right; function buildSegmentsForEvent(event) {
var skinCss; var startDate = event.start;
var endDate = exclEndDay(event);
var segments = rangeToSegments(startDate, endDate);
for (var i=0; i<segments.length; i++) {
segments[i].event = event;
}
return segments;
}
// Sets the `left` and `outerWidth` property of each segment.
// These values are the desired dimensions for the eventual DOM elements.
function calculateHorizontals(segments) {
var isRTL = opt('isRTL');
for (var i=0; i<segments.length; i++) {
var segment = segments[i];
// Determine functions used for calulating the elements left/right coordinates,
// depending on whether the view is RTL or not.
// NOTE:
// colLeft/colRight returns the coordinate butting up the edge of the cell.
// colContentLeft/colContentRight is indented a little bit from the edge.
var leftFunc = (isRTL ? segment.isEnd : segment.isStart) ? colContentLeft : colLeft;
var rightFunc = (isRTL ? segment.isStart : segment.isEnd) ? colContentRight : colRight;
var left = leftFunc(segment.leftCol);
var right = rightFunc(segment.rightCol);
segment.left = left;
segment.outerWidth = right - left;
}
}
// Build a concatenated HTML string for an array of segments
function buildHTML(segments) {
var html = ''; var html = '';
// calculate desired position/dimensions, create html for (var i=0; i<segments.length; i++) {
for (i=0; i<segCnt; i++) { html += buildHTMLForSegment(segments[i]);
seg = segs[i];
event = seg.event;
classes = ['fc-event', 'fc-event-skin', 'fc-event-hori'];
if (isEventDraggable(event)) {
classes.push('fc-event-draggable');
}
if (rtl) {
if (seg.isStart) {
classes.push('fc-corner-right');
}
if (seg.isEnd) {
classes.push('fc-corner-left');
}
leftCol = dayOfWeekCol(seg.end.getDay()-1);
rightCol = dayOfWeekCol(seg.start.getDay());
left = seg.isEnd ? colContentLeft(leftCol) : minLeft;
right = seg.isStart ? colContentRight(rightCol) : maxLeft;
}else{
if (seg.isStart) {
classes.push('fc-corner-left');
}
if (seg.isEnd) {
classes.push('fc-corner-right');
}
leftCol = dayOfWeekCol(seg.start.getDay());
rightCol = dayOfWeekCol(seg.end.getDay()-1);
left = seg.isStart ? colContentLeft(leftCol) : minLeft;
right = seg.isEnd ? colContentRight(rightCol) : maxLeft;
}
classes = classes.concat(event.className);
if (event.source) {
classes = classes.concat(event.source.className || []);
}
url = event.url;
skinCss = getSkinCss(event, opt);
if (url) {
html += "<a href='" + htmlEscape(url) + "'";
}else{
html += "<div";
}
html +=
" class='" + classes.join(' ') + "'" +
" style='position:absolute;z-index:8;left:"+left+"px;" + skinCss + "'" +
">" +
"<div" +
" class='fc-event-inner fc-event-skin'" +
(skinCss ? " style='" + skinCss + "'" : '') +
">";
if (!event.allDay && seg.isStart) {
html +=
"<span class='fc-event-time'>" +
htmlEscape(formatDates(event.start, event.end, opt('timeFormat'))) +
"</span>";
}
html +=
"<span class='fc-event-title'>" + htmlEscape(event.title) + "</span>" +
"</div>";
if (seg.isEnd && isEventResizable(event)) {
html +=
"<div class='ui-resizable-handle ui-resizable-" + (rtl ? 'w' : 'e') + "'>" +
"&nbsp;&nbsp;&nbsp;" + // makes hit area a lot better for IE6/7
"</div>";
}
html +=
"</" + (url ? "a" : "div" ) + ">";
seg.left = left;
seg.outerWidth = right - left;
seg.startCol = leftCol;
seg.endCol = rightCol + 1; // needs to be exclusive
} }
return html; return html;
} }
function daySegElementResolve(segs, elements) { // sets seg.element // Build an HTML string for a single segment.
var i; // Relies on the following properties:
var segCnt = segs.length; // - `segment.event` (from `buildSegmentsForEvent`)
var seg; // - `segment.left` (from `calculateHorizontals`)
var event; function buildHTMLForSegment(segment) {
var element; var html = '';
var triggerRes; var isRTL = opt('isRTL');
for (i=0; i<segCnt; i++) { var event = segment.event;
seg = segs[i]; var url = event.url;
event = seg.event;
element = $(elements[i]); // faster than .eq() // generate the list of CSS classNames
triggerRes = trigger('eventRender', event, event, element); var classNames = [ 'fc-event', 'fc-event-hori' ];
if (isEventDraggable(event)) {
classNames.push('fc-event-draggable');
}
if (segment.isStart) {
classNames.push('fc-event-start');
}
if (segment.isEnd) {
classNames.push('fc-event-end');
}
// use the event's configured classNames
// guaranteed to be an array via `normalizeEvent`
classNames = classNames.concat(event.className);
if (event.source) {
// use the event's source's classNames, if specified
classNames = classNames.concat(event.source.className || []);
}
// generate a semicolon delimited CSS string for any of the "skin" properties
// of the event object (`backgroundColor`, `borderColor` and such)
var skinCss = getSkinCss(event, opt);
if (url) {
html += "<a href='" + htmlEscape(url) + "'";
}else{
html += "<div";
}
html +=
" class='" + classNames.join(' ') + "'" +
" style=" +
"'" +
"position:absolute;" +
"left:" + segment.left + "px;" +
skinCss +
"'" +
">" +
"<div class='fc-event-inner'>";
if (!event.allDay && segment.isStart) {
html +=
"<span class='fc-event-time'>" +
htmlEscape(
formatDates(event.start, event.end, opt('timeFormat'))
) +
"</span>";
}
html +=
"<span class='fc-event-title'>" +
htmlEscape(event.title || '') +
"</span>" +
"</div>";
if (segment.isEnd && isEventResizable(event)) {
html +=
"<div class='ui-resizable-handle ui-resizable-" + (isRTL ? 'w' : 'e') + "'>" +
"&nbsp;&nbsp;&nbsp;" + // makes hit area a lot better for IE6/7
"</div>";
}
html += "</" + (url ? "a" : "div") + ">";
// TODO:
// When these elements are initially rendered, they will be briefly visibile on the screen,
// even though their widths/heights are not set.
// SOLUTION: initially set them as visibility:hidden ?
return html;
}
// Associate each segment (an object) with an element (a jQuery object),
// by setting each `segment.element`.
// Run each element through the `eventRender` filter, which allows developers to
// modify an existing element, supply a new one, or cancel rendering.
function resolveElements(segments, elements) {
for (var i=0; i<segments.length; i++) {
var segment = segments[i];
var event = segment.event;
var element = elements.eq(i);
// call the trigger with the original element
var triggerRes = trigger('eventRender', event, event, element);
if (triggerRes === false) { if (triggerRes === false) {
// if `false`, remove the event from the DOM and don't assign it to `segment.event`
element.remove(); element.remove();
}else{ }
else {
if (triggerRes && triggerRes !== true) { if (triggerRes && triggerRes !== true) {
// the trigger returned a new element, but not `true` (which means keep the existing element)
// re-assign the important CSS dimension properties that were already assigned in `buildHTMLForSegment`
triggerRes = $(triggerRes) triggerRes = $(triggerRes)
.css({ .css({
position: 'absolute', position: 'absolute',
left: seg.left left: segment.left
}); });
element.replaceWith(triggerRes); element.replaceWith(triggerRes);
element = triggerRes; element = triggerRes;
} }
seg.element = element;
segment.element = element;
} }
} }
} }
function daySegElementReport(segs) {
var i; /* Top-coordinate Methods
var segCnt = segs.length; -------------------------------------------------------------------------------------------------*/
var seg;
var element;
for (i=0; i<segCnt; i++) { // Sets the "top" CSS property for each element.
seg = segs[i]; // If `doRowHeights` is `true`, also sets each row's first cell to an explicit height,
element = seg.element; // so that if elements vertically overflow, the cell expands vertically to compensate.
if (element) { function setVerticals(segments, doRowHeights) {
reportEventElement(seg.event, element); var rowContentHeights = calculateVerticals(segments); // also sets segment.top
var rowContentElements = getRowContentElements(); // returns 1 inner div per row
var rowContentTops = [];
// Set each row's height by setting height of first inner div
if (doRowHeights) {
for (var i=0; i<rowContentElements.length; i++) {
rowContentElements[i].height(rowContentHeights[i]);
} }
} }
// Get each row's top, relative to the views's origin.
// Important to do this after setting each row's height.
for (var i=0; i<rowContentElements.length; i++) {
rowContentTops.push(
rowContentElements[i].position().top
);
}
// Set each segment element's CSS "top" property.
// Each segment object has a "top" property, which is relative to the row's top, but...
segmentElementEach(segments, function(segment, element) {
element.css(
'top',
rowContentTops[segment.row] + segment.top // ...now, relative to views's origin
);
});
} }
function daySegHandlers(segs, segmentContainer, modifiedEventId) { // Calculate the "top" coordinate for each segment, relative to the "top" of the row.
var i; // Also, return an array that contains the "content" height for each row
var segCnt = segs.length; // (the height displaced by the vertically stacked events in the row).
var seg; // Requires segments to have their `outerHeight` property already set.
var element; function calculateVerticals(segments) {
var event; var rowCnt = getRowCnt();
// retrieve elements, run through eventRender callback, bind handlers var colCnt = getColCnt();
for (i=0; i<segCnt; i++) { var rowContentHeights = []; // content height for each row
seg = segs[i]; var segmentRows = buildSegmentRows(segments); // an array of segment arrays, one for each row
element = seg.element;
if (element) { for (var rowI=0; rowI<rowCnt; rowI++) {
event = seg.event; var segmentRow = segmentRows[rowI];
if (event._id === modifiedEventId) {
bindDaySeg(event, element, seg); // an array of running total heights for each column.
}else{ // initialize with all zeros.
element[0]._fci = i; // for lazySegBind var colHeights = [];
for (var colI=0; colI<colCnt; colI++) {
colHeights.push(0);
}
// loop through every segment
for (var segmentI=0; segmentI<segmentRow.length; segmentI++) {
var segment = segmentRow[segmentI];
// find the segment's top coordinate by looking at the max height
// of all the columns the segment will be in.
segment.top = arrayMax(
colHeights.slice(
segment.leftCol,
segment.rightCol + 1 // make exclusive for slice
)
);
// adjust the columns to account for the segment's height
for (var colI=segment.leftCol; colI<=segment.rightCol; colI++) {
colHeights[colI] = segment.top + segment.outerHeight;
}
}
// the tallest column in the row should be the "content height"
rowContentHeights.push(arrayMax(colHeights));
}
return rowContentHeights;
}
// Build an array of segment arrays, each representing the segments that will
// be in a row of the grid, sorted by which event should be closest to the top.
function buildSegmentRows(segments) {
var rowCnt = getRowCnt();
var segmentRows = [];
var segmentI;
var segment;
var rowI;
// group segments by row
for (segmentI=0; segmentI<segments.length; segmentI++) {
segment = segments[segmentI];
rowI = segment.row;
if (segment.element) { // was rendered?
if (segmentRows[rowI]) {
// already other segments. append to array
segmentRows[rowI].push(segment);
}
else {
// first segment in row. create new array
segmentRows[rowI] = [ segment ];
} }
} }
} }
lazySegBind(segmentContainer, segs, bindDaySeg);
// sort each row
for (rowI=0; rowI<rowCnt; rowI++) {
segmentRows[rowI] = sortSegmentRow(
segmentRows[rowI] || [] // guarantee an array, even if no segments
);
}
return segmentRows;
} }
function daySegCalcHSides(segs) { // also sets seg.key // Sort an array of segments according to which segment should appear closest to the top
var i; function sortSegmentRow(segments) {
var segCnt = segs.length; var sortedSegments = [];
var seg;
var element; // build the subrow array
var key, val; var subrows = buildSegmentSubrows(segments);
var hsideCache = {};
// record event horizontal sides // flatten it
for (i=0; i<segCnt; i++) { for (var i=0; i<subrows.length; i++) {
seg = segs[i]; sortedSegments.push.apply(sortedSegments, subrows[i]); // append an array to an array
element = seg.element; }
if (element) {
key = seg.key = cssKey(element[0]); return sortedSegments;
val = hsideCache[key]; }
if (val === undefined) {
val = hsideCache[key] = hsides(element, true);
// Take an array of segments, which are all assumed to be in the same row,
// and sort into subrows.
function buildSegmentSubrows(segments) {
// Give preference to elements with certain criteria, so they have
// a chance to be closer to the top.
segments.sort(compareDaySegments);
var subrows = [];
for (var i=0; i<segments.length; i++) {
var segment = segments[i];
// loop through subrows, starting with the topmost, until the segment
// doesn't collide with other segments.
for (var j=0; j<subrows.length; j++) {
if (!isDaySegmentCollision(segment, subrows[j])) {
break;
} }
seg.hsides = val; }
// `j` now holds the desired subrow index
if (subrows[j]) {
subrows[j].push(segment);
}
else {
subrows[j] = [ segment ];
} }
} }
return subrows;
} }
function daySegSetWidths(segs) { // Return an array of jQuery objects for the placeholder content containers of each row.
var i; // The content containers don't actually contain anything, but their dimensions should match
var segCnt = segs.length; // the events that are overlaid on top.
var seg; function getRowContentElements() {
var element;
for (i=0; i<segCnt; i++) {
seg = segs[i];
element = seg.element;
if (element) {
element[0].style.width = Math.max(0, seg.outerWidth - seg.hsides) + 'px';
}
}
}
function daySegCalcHeights(segs) {
var i;
var segCnt = segs.length;
var seg;
var element;
var key, val;
var vmarginCache = {};
// record event heights
for (i=0; i<segCnt; i++) {
seg = segs[i];
element = seg.element;
if (element) {
key = seg.key; // created in daySegCalcHSides
val = vmarginCache[key];
if (val === undefined) {
val = vmarginCache[key] = vmargins(element);
}
seg.outerHeight = element[0].offsetHeight + val;
}
}
}
function getRowDivs() {
var i; var i;
var rowCnt = getRowCnt(); var rowCnt = getRowCnt();
var rowDivs = []; var rowDivs = [];
for (i=0; i<rowCnt; i++) { for (i=0; i<rowCnt; i++) {
rowDivs[i] = allDayRow(i) rowDivs[i] = allDayRow(i)
.find('td:first div.fc-day-content > div'); // optimal selector? .find('div.fc-day-content > div');
} }
return rowDivs; return rowDivs;
} }
function getRowTops(rowDivs) {
var i; /* Mouse Handlers
var rowCnt = rowDivs.length; ---------------------------------------------------------------------------------------------------*/
var tops = []; // TODO: better documentation!
for (i=0; i<rowCnt; i++) {
tops[i] = rowDivs[i][0].offsetTop; // !!?? but this means the element needs position:relative if in a table cell!!!!
} function attachHandlers(segments, modifiedEventId) {
return tops; var segmentContainer = getDaySegmentContainer();
}
segmentElementEach(segments, function(segment, element, i) {
var event = segment.event;
function daySegSetTops(segs, rowTops) { // also triggers eventAfterRender if (event._id === modifiedEventId) {
var i; bindDaySeg(event, element, segment);
var segCnt = segs.length; }else{
var seg; element[0]._fci = i; // for lazySegBind
var element;
var event;
for (i=0; i<segCnt; i++) {
seg = segs[i];
element = seg.element;
if (element) {
element[0].style.top = rowTops[seg.row] + (seg.top||0) + 'px';
event = seg.event;
trigger('eventAfterRender', event, event, element);
} }
} });
lazySegBind(segmentContainer, segments, bindDaySeg);
} }
function bindDaySeg(event, eventElement, segment) {
if (isEventDraggable(event)) {
t.draggableDayEvent(event, eventElement, segment); // use `t` so subclasses can override
}
if (
segment.isEnd && // only allow resizing on the final segment for an event
isEventResizable(event)
) {
t.resizableDayEvent(event, eventElement, segment); // use `t` so subclasses can override
}
// attach all other handlers.
// needs to be after, because resizableDayEvent might stopImmediatePropagation on click
eventElementHandlers(event, eventElement);
}
function draggableDayEvent(event, eventElement) {
var hoverListener = getHoverListener();
var dayDelta;
eventElement.draggable({
delay: 50,
opacity: opt('dragOpacity'),
revertDuration: opt('dragRevertDuration'),
start: function(ev, ui) {
trigger('eventDragStart', eventElement, event, ev, ui);
hideEvents(event, eventElement);
hoverListener.start(function(cell, origCell, rowDelta, colDelta) {
eventElement.draggable('option', 'revert', !cell || !rowDelta && !colDelta);
clearOverlays();
if (cell) {
var origDate = cellToDate(origCell);
var date = cellToDate(cell);
dayDelta = dayDiff(date, origDate);
renderDayOverlay(
addDays(cloneDate(event.start), dayDelta),
addDays(exclEndDay(event), dayDelta)
);
}else{
dayDelta = 0;
}
}, ev, 'drag');
},
stop: function(ev, ui) {
hoverListener.stop();
clearOverlays();
trigger('eventDragStop', eventElement, event, ev, ui);
if (dayDelta) {
eventDrop(this, event, dayDelta, 0, event.allDay, ev, ui);
}else{
eventElement.css('filter', ''); // clear IE opacity side-effects
showEvents(event, eventElement);
}
}
});
}
function resizableDayEvent(event, element, segment) {
/* Resizing var isRTL = opt('isRTL');
-----------------------------------------------------------------------------------*/ var direction = isRTL ? 'w' : 'e';
var handle = element.find('.ui-resizable-' + direction); // TODO: stop using this class because we aren't using jqui for this
function resizableDayEvent(event, element, seg) {
var rtl = opt('isRTL');
var direction = rtl ? 'w' : 'e';
var handle = element.find('div.ui-resizable-' + direction);
var isResizing = false; var isResizing = false;
// TODO: look into using jquery-ui mouse widget for this stuff // TODO: look into using jquery-ui mouse widget for this stuff
@ -4881,16 +5711,14 @@ function DayEventRenderer() {
return; // needs to be left mouse button return; // needs to be left mouse button
} }
isResizing = true; isResizing = true;
var hoverListener = t.getHoverListener(); var hoverListener = getHoverListener();
var rowCnt = getRowCnt(); var rowCnt = getRowCnt();
var colCnt = getColCnt(); var colCnt = getColCnt();
var dis = rtl ? -1 : 1;
var dit = rtl ? colCnt-1 : 0;
var elementTop = element.css('top'); var elementTop = element.css('top');
var dayDelta; var dayDelta;
var helpers; var helpers;
var eventCopy = $.extend({}, event); var eventCopy = $.extend({}, event);
var minCell = dateCell(event.start); var minCellOffset = dayOffsetToCellOffset( dateToDayOffset(event.start) );
clearSelection(); clearSelection();
$('body') $('body')
.css('cursor', direction + '-resize') .css('cursor', direction + '-resize')
@ -4898,30 +5726,32 @@ function DayEventRenderer() {
trigger('eventResizeStart', this, event, ev); trigger('eventResizeStart', this, event, ev);
hoverListener.start(function(cell, origCell) { hoverListener.start(function(cell, origCell) {
if (cell) { if (cell) {
var r = Math.max(minCell.row, cell.row);
var c = cell.col; var origCellOffset = cellToCellOffset(origCell);
if (rowCnt == 1) { var cellOffset = cellToCellOffset(cell);
r = 0; // hack for all-day area in agenda views
} // don't let resizing move earlier than start date cell
if (r == minCell.row) { cellOffset = Math.max(cellOffset, minCellOffset);
if (rtl) {
c = Math.min(minCell.col, c); dayDelta =
}else{ cellOffsetToDayOffset(cellOffset) -
c = Math.max(minCell.col, c); cellOffsetToDayOffset(origCellOffset);
}
}
dayDelta = (r*7 + c*dis+dit) - (origCell.row*7 + origCell.col*dis+dit);
var newEnd = addDays(eventEnd(event), dayDelta, true);
if (dayDelta) { if (dayDelta) {
eventCopy.end = newEnd; eventCopy.end = addDays(eventEnd(event), dayDelta, true);
var oldHelpers = helpers; var oldHelpers = helpers;
helpers = renderTempDaySegs(compileDaySegs([eventCopy]), seg.row, elementTop);
helpers = renderTempDayEvent(eventCopy, segment.row, elementTop);
helpers = $(helpers); // turn array into a jQuery object
helpers.find('*').css('cursor', direction + '-resize'); helpers.find('*').css('cursor', direction + '-resize');
if (oldHelpers) { if (oldHelpers) {
oldHelpers.remove(); oldHelpers.remove();
} }
hideEvents(event); hideEvents(event);
}else{ }
else {
if (helpers) { if (helpers) {
showEvents(event); showEvents(event);
helpers.remove(); helpers.remove();
@ -4929,7 +5759,12 @@ function DayEventRenderer() {
} }
} }
clearOverlays(); clearOverlays();
renderDayOverlay(event.start, addDays(cloneDate(newEnd), 1)); // coordinate grid already rebuild at hoverListener.start renderDayOverlay( // coordinate grid already rebuilt with hoverListener.start()
event.start,
addDays( exclEndDay(event), dayDelta )
// TODO: instead of calling renderDayOverlay() with dates,
// call _renderDayOverlay (or whatever) with cell offsets.
);
} }
}, ev); }, ev);
@ -4948,13 +5783,54 @@ function DayEventRenderer() {
isResizing = false; isResizing = false;
},0); },0);
} }
}); });
} }
} }
/* Generalized Segment Utilities
-------------------------------------------------------------------------------------------------*/
function isDaySegmentCollision(segment, otherSegments) {
for (var i=0; i<otherSegments.length; i++) {
var otherSegment = otherSegments[i];
if (
otherSegment.leftCol <= segment.rightCol &&
otherSegment.rightCol >= segment.leftCol
) {
return true;
}
}
return false;
}
function segmentElementEach(segments, callback) { // TODO: use in AgendaView?
for (var i=0; i<segments.length; i++) {
var segment = segments[i];
var element = segment.element;
if (element) {
callback(segment, element, i);
}
}
}
// A cmp function for determining which segments should appear higher up
function compareDaySegments(a, b) {
return (b.rightCol - b.leftCol) - (a.rightCol - a.leftCol) || // put wider events first
b.event.allDay - a.event.allDay || // if tie, put all-day events first (booleans cast to 0/1)
a.event.start - b.event.start || // if a tie, sort by event start date
(a.event.title || '').localeCompare(b.event.title) // if a tie, sort by event title
}
;;
//BUG: unselect needs to be triggered when events are dragged+dropped //BUG: unselect needs to be triggered when events are dragged+dropped
function SelectionManager() { function SelectionManager() {
@ -5021,18 +5897,18 @@ function SelectionManager() {
function daySelectionMousedown(ev) { // not really a generic manager method, oh well function daySelectionMousedown(ev) { // not really a generic manager method, oh well
var cellDate = t.cellDate; var cellToDate = t.cellToDate;
var cellIsAllDay = t.cellIsAllDay; var getIsCellAllDay = t.getIsCellAllDay;
var hoverListener = t.getHoverListener(); var hoverListener = t.getHoverListener();
var reportDayClick = t.reportDayClick; // this is hacky and sort of weird var reportDayClick = t.reportDayClick; // this is hacky and sort of weird
if (ev.which == 1 && opt('selectable')) { // which==1 means left mouse button if (ev.which == 1 && opt('selectable')) { // which==1 means left mouse button
unselect(ev); unselect(ev);
var _mousedownElement = this; var _mousedownElement = this;
var dates; var dates;
hoverListener.start(function(cell, origCell) { // TODO: maybe put cellDate/cellIsAllDay info in cell hoverListener.start(function(cell, origCell) { // TODO: maybe put cellToDate/getIsCellAllDay info in cell
clearSelection(); clearSelection();
if (cell && cellIsAllDay(cell)) { if (cell && getIsCellAllDay(cell)) {
dates = [ cellDate(origCell), cellDate(cell) ].sort(cmp); dates = [ cellToDate(origCell), cellToDate(cell) ].sort(dateCompare);
renderSelection(dates[0], dates[1], true); renderSelection(dates[0], dates[1], true);
}else{ }else{
dates = null; dates = null;
@ -5052,6 +5928,8 @@ function SelectionManager() {
} }
;;
function OverlayManager() { function OverlayManager() {
var t = this; var t = this;
@ -5090,6 +5968,8 @@ function OverlayManager() {
} }
;;
function CoordinateGrid(buildFunc) { function CoordinateGrid(buildFunc) {
var t = this; var t = this;
@ -5136,6 +6016,8 @@ function CoordinateGrid(buildFunc) {
} }
;;
function HoverListener(coordinateGrid) { function HoverListener(coordinateGrid) {
@ -5194,6 +6076,8 @@ function _fixUIEvent(event) { // for issue 1168
event.pageY = event.originalEvent.pageY; event.pageY = event.originalEvent.pageY;
} }
} }
;;
function HorizontalPositionCache(getElement) { function HorizontalPositionCache(getElement) {
var t = this, var t = this,
@ -5220,5 +6104,7 @@ function HorizontalPositionCache(getElement) {
}; };
} }
})(jQuery); ;;
})(jQuery);

File diff suppressed because one or more lines are too long

View file

@ -1,54 +1,25 @@
/*!
* FullCalendar v1.6.4 Print Stylesheet
* Docs & License: http://arshaw.com/fullcalendar/
* (c) 2013 Adam Shaw
*/
/* /*
* FullCalendar v1.5.3 Print Stylesheet
*
* Include this stylesheet on your page to get a more printer-friendly calendar. * Include this stylesheet on your page to get a more printer-friendly calendar.
* When including this stylesheet, use the media='print' attribute of the <link> tag. * When including this stylesheet, use the media='print' attribute of the <link> tag.
* Make sure to include this stylesheet IN ADDITION to the regular fullcalendar.css. * Make sure to include this stylesheet IN ADDITION to the regular fullcalendar.css.
*
* Copyright (c) 2011 Adam Shaw
* Dual licensed under the MIT and GPL licenses, located in
* MIT-LICENSE.txt and GPL-LICENSE.txt respectively.
*
* Date: Mon Feb 6 22:40:40 2012 -0800
*
*/ */
/* Events /* Events
-----------------------------------------------------*/ -----------------------------------------------------*/
.fc-event-skin { .fc-event {
background: none !important; background: #fff !important;
color: #000 !important; color: #000 !important;
} }
/* horizontal events */ /* for vertical events */
.fc-event-hori {
border-width: 0 0 1px 0 !important;
border-bottom-style: dotted !important;
border-bottom-color: #000 !important;
padding: 1px 0 0 0 !important;
}
.fc-event-hori .fc-event-inner {
border-width: 0 !important;
padding: 0 1px !important;
}
/* vertical events */
.fc-event-vert {
border-width: 0 0 0 1px !important;
border-left-style: dotted !important;
border-left-color: #000 !important;
padding: 0 1px 0 0 !important;
}
.fc-event-vert .fc-event-inner {
border-width: 0 !important;
padding: 1px 0 !important;
}
.fc-event-bg { .fc-event-bg {
display: none !important; display: none !important;

View file

@ -1,12 +1,7 @@
/* /*!
* FullCalendar v1.5.3 Google Calendar Plugin * FullCalendar v1.6.4 Google Calendar Plugin
* * Docs & License: http://arshaw.com/fullcalendar/
* Copyright (c) 2011 Adam Shaw * (c) 2013 Adam Shaw
* Dual licensed under the MIT and GPL licenses, located in
* MIT-LICENSE.txt and GPL-LICENSE.txt respectively.
*
* Date: Mon Feb 6 22:40:40 2012 -0800
*
*/ */
(function($) { (function($) {

View file

@ -1,4 +1,4 @@
Copyright (c) 2009 Adam Shaw Copyright (c) 2013 Adam Shaw
Permission is hereby granted, free of charge, to any person obtaining Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the a copy of this software and associated documentation files (the