fullcalendar.js 257 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264
  1. /*!
  2. * FullCalendar v2.2.3
  3. * Docs & License: http://arshaw.com/fullcalendar/
  4. * (c) 2013 Adam Shaw
  5. */
  6. (function(factory) {
  7. if (typeof define === 'function' && define.amd) {
  8. define([ 'jquery', 'moment' ], factory);
  9. }
  10. else {
  11. factory(jQuery, moment);
  12. }
  13. })(function($, moment) {
  14. ;;
  15. var defaults = {
  16. lang: 'en',
  17. defaultTimedEventDuration: '02:00:00',
  18. defaultAllDayEventDuration: { days: 1 },
  19. forceEventDuration: false,
  20. nextDayThreshold: '09:00:00', // 9am
  21. // display
  22. defaultView: 'month',
  23. aspectRatio: 1.35,
  24. header: {
  25. left: 'title',
  26. center: '',
  27. right: 'today prev,next'
  28. },
  29. weekends: true,
  30. weekNumbers: false,
  31. weekNumberTitle: 'W',
  32. weekNumberCalculation: 'local',
  33. //editable: false,
  34. // event ajax
  35. lazyFetching: true,
  36. startParam: 'start',
  37. endParam: 'end',
  38. timezoneParam: 'timezone',
  39. timezone: false,
  40. //allDayDefault: undefined,
  41. // time formats
  42. titleFormat: {
  43. month: 'MMMM YYYY', // like "September 1986". each language will override this
  44. week: 'll', // like "Sep 4 1986"
  45. day: 'LL' // like "September 4 1986"
  46. },
  47. columnFormat: {
  48. month: 'ddd', // like "Sat"
  49. week: generateWeekColumnFormat,
  50. day: 'dddd' // like "Saturday"
  51. },
  52. timeFormat: { // for event elements
  53. 'default': generateShortTimeFormat
  54. },
  55. displayEventEnd: {
  56. month: false,
  57. basicWeek: false,
  58. 'default': true
  59. },
  60. // locale
  61. isRTL: false,
  62. defaultButtonText: {
  63. prev: "prev",
  64. next: "next",
  65. prevYear: "prev year",
  66. nextYear: "next year",
  67. today: 'today',
  68. month: 'month',
  69. week: 'week',
  70. day: 'day'
  71. },
  72. buttonIcons: {
  73. prev: 'left-single-arrow',
  74. next: 'right-single-arrow',
  75. prevYear: 'left-double-arrow',
  76. nextYear: 'right-double-arrow'
  77. },
  78. // jquery-ui theming
  79. theme: false,
  80. themeButtonIcons: {
  81. prev: 'circle-triangle-w',
  82. next: 'circle-triangle-e',
  83. prevYear: 'seek-prev',
  84. nextYear: 'seek-next'
  85. },
  86. dragOpacity: .75,
  87. dragRevertDuration: 500,
  88. dragScroll: true,
  89. //selectable: false,
  90. unselectAuto: true,
  91. dropAccept: '*',
  92. eventLimit: false,
  93. eventLimitText: 'more',
  94. eventLimitClick: 'popover',
  95. dayPopoverFormat: 'LL',
  96. handleWindowResize: true,
  97. windowResizeDelay: 200 // milliseconds before a rerender happens
  98. };
  99. function generateShortTimeFormat(options, langData) {
  100. return langData.longDateFormat('LT')
  101. .replace(':mm', '(:mm)')
  102. .replace(/(\Wmm)$/, '($1)') // like above, but for foreign langs
  103. .replace(/\s*a$/i, 't'); // convert to AM/PM/am/pm to lowercase one-letter. remove any spaces beforehand
  104. }
  105. function generateWeekColumnFormat(options, langData) {
  106. var format = langData.longDateFormat('L'); // for the format like "MM/DD/YYYY"
  107. format = format.replace(/^Y+[^\w\s]*|[^\w\s]*Y+$/g, ''); // strip the year off the edge, as well as other misc non-whitespace chars
  108. if (options.isRTL) {
  109. format += ' ddd'; // for RTL, add day-of-week to end
  110. }
  111. else {
  112. format = 'ddd ' + format; // for LTR, add day-of-week to beginning
  113. }
  114. return format;
  115. }
  116. var langOptionHash = {
  117. en: {
  118. columnFormat: {
  119. week: 'ddd M/D' // override for english. different from the generated default, which is MM/DD
  120. },
  121. dayPopoverFormat: 'dddd, MMMM D'
  122. }
  123. };
  124. // right-to-left defaults
  125. var rtlDefaults = {
  126. header: {
  127. left: 'next,prev today',
  128. center: '',
  129. right: 'title'
  130. },
  131. buttonIcons: {
  132. prev: 'right-single-arrow',
  133. next: 'left-single-arrow',
  134. prevYear: 'right-double-arrow',
  135. nextYear: 'left-double-arrow'
  136. },
  137. themeButtonIcons: {
  138. prev: 'circle-triangle-e',
  139. next: 'circle-triangle-w',
  140. nextYear: 'seek-prev',
  141. prevYear: 'seek-next'
  142. }
  143. };
  144. ;;
  145. var fc = $.fullCalendar = { version: "2.2.3" };
  146. var fcViews = fc.views = {};
  147. $.fn.fullCalendar = function(options) {
  148. var args = Array.prototype.slice.call(arguments, 1); // for a possible method call
  149. var res = this; // what this function will return (this jQuery object by default)
  150. this.each(function(i, _element) { // loop each DOM element involved
  151. var element = $(_element);
  152. var calendar = element.data('fullCalendar'); // get the existing calendar object (if any)
  153. var singleRes; // the returned value of this single method call
  154. // a method call
  155. if (typeof options === 'string') {
  156. if (calendar && $.isFunction(calendar[options])) {
  157. singleRes = calendar[options].apply(calendar, args);
  158. if (!i) {
  159. res = singleRes; // record the first method call result
  160. }
  161. if (options === 'destroy') { // for the destroy method, must remove Calendar object data
  162. element.removeData('fullCalendar');
  163. }
  164. }
  165. }
  166. // a new calendar initialization
  167. else if (!calendar) { // don't initialize twice
  168. calendar = new Calendar(element, options);
  169. element.data('fullCalendar', calendar);
  170. calendar.render();
  171. }
  172. });
  173. return res;
  174. };
  175. // function for adding/overriding defaults
  176. function setDefaults(d) {
  177. mergeOptions(defaults, d);
  178. }
  179. // Recursively combines option hash-objects.
  180. // Better than `$.extend(true, ...)` because arrays are not traversed/copied.
  181. //
  182. // called like:
  183. // mergeOptions(target, obj1, obj2, ...)
  184. //
  185. function mergeOptions(target) {
  186. function mergeIntoTarget(name, value) {
  187. if ($.isPlainObject(value) && $.isPlainObject(target[name]) && !isForcedAtomicOption(name)) {
  188. // merge into a new object to avoid destruction
  189. target[name] = mergeOptions({}, target[name], value); // combine. `value` object takes precedence
  190. }
  191. else if (value !== undefined) { // only use values that are set and not undefined
  192. target[name] = value;
  193. }
  194. }
  195. for (var i=1; i<arguments.length; i++) {
  196. $.each(arguments[i], mergeIntoTarget);
  197. }
  198. return target;
  199. }
  200. // overcome sucky view-option-hash and option-merging behavior messing with options it shouldn't
  201. function isForcedAtomicOption(name) {
  202. // Any option that ends in "Time" or "Duration" is probably a Duration,
  203. // and these will commonly be specified as plain objects, which we don't want to mess up.
  204. return /(Time|Duration)$/.test(name);
  205. }
  206. // FIX: find a different solution for view-option-hashes and have a whitelist
  207. // for options that can be recursively merged.
  208. ;;
  209. //var langOptionHash = {}; // initialized in defaults.js
  210. fc.langs = langOptionHash; // expose
  211. // Initialize jQuery UI Datepicker translations while using some of the translations
  212. // for our own purposes. Will set this as the default language for datepicker.
  213. // Called from a translation file.
  214. fc.datepickerLang = function(langCode, datepickerLangCode, options) {
  215. var langOptions = langOptionHash[langCode];
  216. // initialize FullCalendar's lang hash for this language
  217. if (!langOptions) {
  218. langOptions = langOptionHash[langCode] = {};
  219. }
  220. // merge certain Datepicker options into FullCalendar's options
  221. mergeOptions(langOptions, {
  222. isRTL: options.isRTL,
  223. weekNumberTitle: options.weekHeader,
  224. titleFormat: {
  225. month: options.showMonthAfterYear ?
  226. 'YYYY[' + options.yearSuffix + '] MMMM' :
  227. 'MMMM YYYY[' + options.yearSuffix + ']'
  228. },
  229. defaultButtonText: {
  230. // the translations sometimes wrongly contain HTML entities
  231. prev: stripHtmlEntities(options.prevText),
  232. next: stripHtmlEntities(options.nextText),
  233. today: stripHtmlEntities(options.currentText)
  234. }
  235. });
  236. // is jQuery UI Datepicker is on the page?
  237. if ($.datepicker) {
  238. // Register the language data.
  239. // FullCalendar and MomentJS use language codes like "pt-br" but Datepicker
  240. // does it like "pt-BR" or if it doesn't have the language, maybe just "pt".
  241. // Make an alias so the language can be referenced either way.
  242. $.datepicker.regional[datepickerLangCode] =
  243. $.datepicker.regional[langCode] = // alias
  244. options;
  245. // Alias 'en' to the default language data. Do this every time.
  246. $.datepicker.regional.en = $.datepicker.regional[''];
  247. // Set as Datepicker's global defaults.
  248. $.datepicker.setDefaults(options);
  249. }
  250. };
  251. // Sets FullCalendar-specific translations. Also sets the language as the global default.
  252. // Called from a translation file.
  253. fc.lang = function(langCode, options) {
  254. var langOptions;
  255. if (options) {
  256. langOptions = langOptionHash[langCode];
  257. // initialize the hash for this language
  258. if (!langOptions) {
  259. langOptions = langOptionHash[langCode] = {};
  260. }
  261. mergeOptions(langOptions, options || {});
  262. }
  263. // set it as the default language for FullCalendar
  264. defaults.lang = langCode;
  265. };
  266. ;;
  267. function Calendar(element, instanceOptions) {
  268. var t = this;
  269. // Build options object
  270. // -----------------------------------------------------------------------------------
  271. // Precedence (lowest to highest): defaults, rtlDefaults, langOptions, instanceOptions
  272. instanceOptions = instanceOptions || {};
  273. var options = mergeOptions({}, defaults, instanceOptions);
  274. var langOptions;
  275. // determine language options
  276. if (options.lang in langOptionHash) {
  277. langOptions = langOptionHash[options.lang];
  278. }
  279. else {
  280. langOptions = langOptionHash[defaults.lang];
  281. }
  282. if (langOptions) { // if language options exist, rebuild...
  283. options = mergeOptions({}, defaults, langOptions, instanceOptions);
  284. }
  285. if (options.isRTL) { // is isRTL, rebuild...
  286. options = mergeOptions({}, defaults, rtlDefaults, langOptions || {}, instanceOptions);
  287. }
  288. // Exports
  289. // -----------------------------------------------------------------------------------
  290. t.options = options;
  291. t.render = render;
  292. t.destroy = destroy;
  293. t.refetchEvents = refetchEvents;
  294. t.reportEvents = reportEvents;
  295. t.reportEventChange = reportEventChange;
  296. t.rerenderEvents = renderEvents; // `renderEvents` serves as a rerender. an API method
  297. t.changeView = changeView;
  298. t.select = select;
  299. t.unselect = unselect;
  300. t.prev = prev;
  301. t.next = next;
  302. t.prevYear = prevYear;
  303. t.nextYear = nextYear;
  304. t.today = today;
  305. t.gotoDate = gotoDate;
  306. t.incrementDate = incrementDate;
  307. t.zoomTo = zoomTo;
  308. t.getDate = getDate;
  309. t.getCalendar = getCalendar;
  310. t.getView = getView;
  311. t.option = option;
  312. t.trigger = trigger;
  313. // Language-data Internals
  314. // -----------------------------------------------------------------------------------
  315. // Apply overrides to the current language's data
  316. // Returns moment's internal locale data. If doesn't exist, returns English.
  317. // Works with moment-pre-2.8
  318. function getLocaleData(langCode) {
  319. var f = moment.localeData || moment.langData;
  320. return f.call(moment, langCode) ||
  321. f.call(moment, 'en'); // the newer localData could return null, so fall back to en
  322. }
  323. var localeData = createObject(getLocaleData(options.lang)); // make a cheap copy
  324. if (options.monthNames) {
  325. localeData._months = options.monthNames;
  326. }
  327. if (options.monthNamesShort) {
  328. localeData._monthsShort = options.monthNamesShort;
  329. }
  330. if (options.dayNames) {
  331. localeData._weekdays = options.dayNames;
  332. }
  333. if (options.dayNamesShort) {
  334. localeData._weekdaysShort = options.dayNamesShort;
  335. }
  336. if (options.firstDay != null) {
  337. var _week = createObject(localeData._week); // _week: { dow: # }
  338. _week.dow = options.firstDay;
  339. localeData._week = _week;
  340. }
  341. // Calendar-specific Date Utilities
  342. // -----------------------------------------------------------------------------------
  343. t.defaultAllDayEventDuration = moment.duration(options.defaultAllDayEventDuration);
  344. t.defaultTimedEventDuration = moment.duration(options.defaultTimedEventDuration);
  345. // Builds a moment using the settings of the current calendar: timezone and language.
  346. // Accepts anything the vanilla moment() constructor accepts.
  347. t.moment = function() {
  348. var mom;
  349. if (options.timezone === 'local') {
  350. mom = fc.moment.apply(null, arguments);
  351. // Force the moment to be local, because fc.moment doesn't guarantee it.
  352. if (mom.hasTime()) { // don't give ambiguously-timed moments a local zone
  353. mom.local();
  354. }
  355. }
  356. else if (options.timezone === 'UTC') {
  357. mom = fc.moment.utc.apply(null, arguments); // process as UTC
  358. }
  359. else {
  360. mom = fc.moment.parseZone.apply(null, arguments); // let the input decide the zone
  361. }
  362. if ('_locale' in mom) { // moment 2.8 and above
  363. mom._locale = localeData;
  364. }
  365. else { // pre-moment-2.8
  366. mom._lang = localeData;
  367. }
  368. return mom;
  369. };
  370. // Returns a boolean about whether or not the calendar knows how to calculate
  371. // the timezone offset of arbitrary dates in the current timezone.
  372. t.getIsAmbigTimezone = function() {
  373. return options.timezone !== 'local' && options.timezone !== 'UTC';
  374. };
  375. // Returns a copy of the given date in the current timezone of it is ambiguously zoned.
  376. // This will also give the date an unambiguous time.
  377. t.rezoneDate = function(date) {
  378. return t.moment(date.toArray());
  379. };
  380. // Returns a moment for the current date, as defined by the client's computer,
  381. // or overridden by the `now` option.
  382. t.getNow = function() {
  383. var now = options.now;
  384. if (typeof now === 'function') {
  385. now = now();
  386. }
  387. return t.moment(now);
  388. };
  389. // Calculates the week number for a moment according to the calendar's
  390. // `weekNumberCalculation` setting.
  391. t.calculateWeekNumber = function(mom) {
  392. var calc = options.weekNumberCalculation;
  393. if (typeof calc === 'function') {
  394. return calc(mom);
  395. }
  396. else if (calc === 'local') {
  397. return mom.week();
  398. }
  399. else if (calc.toUpperCase() === 'ISO') {
  400. return mom.isoWeek();
  401. }
  402. };
  403. // Get an event's normalized end date. If not present, calculate it from the defaults.
  404. t.getEventEnd = function(event) {
  405. if (event.end) {
  406. return event.end.clone();
  407. }
  408. else {
  409. return t.getDefaultEventEnd(event.allDay, event.start);
  410. }
  411. };
  412. // Given an event's allDay status and start date, return swhat its fallback end date should be.
  413. t.getDefaultEventEnd = function(allDay, start) { // TODO: rename to computeDefaultEventEnd
  414. var end = start.clone();
  415. if (allDay) {
  416. end.stripTime().add(t.defaultAllDayEventDuration);
  417. }
  418. else {
  419. end.add(t.defaultTimedEventDuration);
  420. }
  421. if (t.getIsAmbigTimezone()) {
  422. end.stripZone(); // we don't know what the tzo should be
  423. }
  424. return end;
  425. };
  426. // Date-formatting Utilities
  427. // -----------------------------------------------------------------------------------
  428. // Like the vanilla formatRange, but with calendar-specific settings applied.
  429. t.formatRange = function(m1, m2, formatStr) {
  430. // a function that returns a formatStr // TODO: in future, precompute this
  431. if (typeof formatStr === 'function') {
  432. formatStr = formatStr.call(t, options, localeData);
  433. }
  434. return formatRange(m1, m2, formatStr, null, options.isRTL);
  435. };
  436. // Like the vanilla formatDate, but with calendar-specific settings applied.
  437. t.formatDate = function(mom, formatStr) {
  438. // a function that returns a formatStr // TODO: in future, precompute this
  439. if (typeof formatStr === 'function') {
  440. formatStr = formatStr.call(t, options, localeData);
  441. }
  442. return formatDate(mom, formatStr);
  443. };
  444. // Imports
  445. // -----------------------------------------------------------------------------------
  446. EventManager.call(t, options);
  447. var isFetchNeeded = t.isFetchNeeded;
  448. var fetchEvents = t.fetchEvents;
  449. // Locals
  450. // -----------------------------------------------------------------------------------
  451. var _element = element[0];
  452. var header;
  453. var headerElement;
  454. var content;
  455. var tm; // for making theme classes
  456. var currentView;
  457. var suggestedViewHeight;
  458. var windowResizeProxy; // wraps the windowResize function
  459. var ignoreWindowResize = 0;
  460. var date;
  461. var events = [];
  462. // Main Rendering
  463. // -----------------------------------------------------------------------------------
  464. if (options.defaultDate != null) {
  465. date = t.moment(options.defaultDate);
  466. }
  467. else {
  468. date = t.getNow();
  469. }
  470. function render(inc) {
  471. if (!content) {
  472. initialRender();
  473. }
  474. else if (elementVisible()) {
  475. // mainly for the public API
  476. calcSize();
  477. renderView(inc);
  478. }
  479. }
  480. function initialRender() {
  481. tm = options.theme ? 'ui' : 'fc';
  482. element.addClass('fc');
  483. if (options.isRTL) {
  484. element.addClass('fc-rtl');
  485. }
  486. else {
  487. element.addClass('fc-ltr');
  488. }
  489. if (options.theme) {
  490. element.addClass('ui-widget');
  491. }
  492. else {
  493. element.addClass('fc-unthemed');
  494. }
  495. content = $("<div class='fc-view-container'/>").prependTo(element);
  496. header = new Header(t, options);
  497. headerElement = header.render();
  498. if (headerElement) {
  499. element.prepend(headerElement);
  500. }
  501. changeView(options.defaultView);
  502. if (options.handleWindowResize) {
  503. windowResizeProxy = debounce(windowResize, options.windowResizeDelay); // prevents rapid calls
  504. $(window).resize(windowResizeProxy);
  505. }
  506. }
  507. function destroy() {
  508. if (currentView) {
  509. currentView.destroy();
  510. }
  511. header.destroy();
  512. content.remove();
  513. element.removeClass('fc fc-ltr fc-rtl fc-unthemed ui-widget');
  514. $(window).unbind('resize', windowResizeProxy);
  515. }
  516. function elementVisible() {
  517. return element.is(':visible');
  518. }
  519. // View Rendering
  520. // -----------------------------------------------------------------------------------
  521. function changeView(viewName) {
  522. renderView(0, viewName);
  523. }
  524. // Renders a view because of a date change, view-type change, or for the first time
  525. function renderView(delta, viewName) {
  526. ignoreWindowResize++;
  527. // if viewName is changing, destroy the old view
  528. if (currentView && viewName && currentView.name !== viewName) {
  529. header.deactivateButton(currentView.name);
  530. freezeContentHeight(); // prevent a scroll jump when view element is removed
  531. if (currentView.start) { // rendered before?
  532. currentView.destroy();
  533. }
  534. currentView.el.remove();
  535. currentView = null;
  536. }
  537. // if viewName changed, or the view was never created, create a fresh view
  538. if (!currentView && viewName) {
  539. currentView = new fcViews[viewName](t);
  540. currentView.el = $("<div class='fc-view fc-" + viewName + "-view' />").appendTo(content);
  541. header.activateButton(viewName);
  542. }
  543. if (currentView) {
  544. // let the view determine what the delta means
  545. if (delta) {
  546. date = currentView.incrementDate(date, delta);
  547. }
  548. // render or rerender the view
  549. if (
  550. !currentView.start || // never rendered before
  551. delta || // explicit date window change
  552. !date.isWithin(currentView.intervalStart, currentView.intervalEnd) // implicit date window change
  553. ) {
  554. if (elementVisible()) {
  555. freezeContentHeight();
  556. if (currentView.start) { // rendered before?
  557. currentView.destroy();
  558. }
  559. currentView.render(date);
  560. unfreezeContentHeight();
  561. // need to do this after View::render, so dates are calculated
  562. updateTitle();
  563. updateTodayButton();
  564. getAndRenderEvents();
  565. }
  566. }
  567. }
  568. unfreezeContentHeight(); // undo any lone freezeContentHeight calls
  569. ignoreWindowResize--;
  570. }
  571. // Resizing
  572. // -----------------------------------------------------------------------------------
  573. t.getSuggestedViewHeight = function() {
  574. if (suggestedViewHeight === undefined) {
  575. calcSize();
  576. }
  577. return suggestedViewHeight;
  578. };
  579. t.isHeightAuto = function() {
  580. return options.contentHeight === 'auto' || options.height === 'auto';
  581. };
  582. function updateSize(shouldRecalc) {
  583. if (elementVisible()) {
  584. if (shouldRecalc) {
  585. _calcSize();
  586. }
  587. ignoreWindowResize++;
  588. currentView.updateSize(true); // isResize=true. will poll getSuggestedViewHeight() and isHeightAuto()
  589. ignoreWindowResize--;
  590. return true; // signal success
  591. }
  592. }
  593. function calcSize() {
  594. if (elementVisible()) {
  595. _calcSize();
  596. }
  597. }
  598. function _calcSize() { // assumes elementVisible
  599. if (typeof options.contentHeight === 'number') { // exists and not 'auto'
  600. suggestedViewHeight = options.contentHeight;
  601. }
  602. else if (typeof options.height === 'number') { // exists and not 'auto'
  603. suggestedViewHeight = options.height - (headerElement ? headerElement.outerHeight(true) : 0);
  604. }
  605. else {
  606. suggestedViewHeight = Math.round(content.width() / Math.max(options.aspectRatio, .5));
  607. }
  608. }
  609. function windowResize(ev) {
  610. if (
  611. !ignoreWindowResize &&
  612. ev.target === window && // so we don't process jqui "resize" events that have bubbled up
  613. currentView.start // view has already been rendered
  614. ) {
  615. if (updateSize(true)) {
  616. currentView.trigger('windowResize', _element);
  617. }
  618. }
  619. }
  620. /* Event Fetching/Rendering
  621. -----------------------------------------------------------------------------*/
  622. // TODO: going forward, most of this stuff should be directly handled by the view
  623. function refetchEvents() { // can be called as an API method
  624. destroyEvents(); // so that events are cleared before user starts waiting for AJAX
  625. fetchAndRenderEvents();
  626. }
  627. function renderEvents() { // destroys old events if previously rendered
  628. if (elementVisible()) {
  629. freezeContentHeight();
  630. currentView.destroyEvents(); // no performance cost if never rendered
  631. currentView.renderEvents(events);
  632. unfreezeContentHeight();
  633. }
  634. }
  635. function destroyEvents() {
  636. freezeContentHeight();
  637. currentView.destroyEvents();
  638. unfreezeContentHeight();
  639. }
  640. function getAndRenderEvents() {
  641. if (!options.lazyFetching || isFetchNeeded(currentView.start, currentView.end)) {
  642. fetchAndRenderEvents();
  643. }
  644. else {
  645. renderEvents();
  646. }
  647. }
  648. function fetchAndRenderEvents() {
  649. fetchEvents(currentView.start, currentView.end);
  650. // ... will call reportEvents
  651. // ... which will call renderEvents
  652. }
  653. // called when event data arrives
  654. function reportEvents(_events) {
  655. events = _events;
  656. renderEvents();
  657. }
  658. // called when a single event's data has been changed
  659. function reportEventChange() {
  660. renderEvents();
  661. }
  662. /* Header Updating
  663. -----------------------------------------------------------------------------*/
  664. function updateTitle() {
  665. header.updateTitle(currentView.title);
  666. }
  667. function updateTodayButton() {
  668. var now = t.getNow();
  669. if (now.isWithin(currentView.intervalStart, currentView.intervalEnd)) {
  670. header.disableButton('today');
  671. }
  672. else {
  673. header.enableButton('today');
  674. }
  675. }
  676. /* Selection
  677. -----------------------------------------------------------------------------*/
  678. function select(start, end) {
  679. start = t.moment(start);
  680. if (end) {
  681. end = t.moment(end);
  682. }
  683. else if (start.hasTime()) {
  684. end = start.clone().add(t.defaultTimedEventDuration);
  685. }
  686. else {
  687. end = start.clone().add(t.defaultAllDayEventDuration);
  688. }
  689. currentView.select(start, end);
  690. }
  691. function unselect() { // safe to be called before renderView
  692. if (currentView) {
  693. currentView.unselect();
  694. }
  695. }
  696. /* Date
  697. -----------------------------------------------------------------------------*/
  698. function prev() {
  699. renderView(-1);
  700. }
  701. function next() {
  702. renderView(1);
  703. }
  704. function prevYear() {
  705. date.add(-1, 'years');
  706. renderView();
  707. }
  708. function nextYear() {
  709. date.add(1, 'years');
  710. renderView();
  711. }
  712. function today() {
  713. date = t.getNow();
  714. renderView();
  715. }
  716. function gotoDate(dateInput) {
  717. date = t.moment(dateInput);
  718. renderView();
  719. }
  720. function incrementDate(delta) {
  721. date.add(moment.duration(delta));
  722. renderView();
  723. }
  724. // Forces navigation to a view for the given date.
  725. // `viewName` can be a specific view name or a generic one like "week" or "day".
  726. function zoomTo(newDate, viewName) {
  727. var viewStr;
  728. var match;
  729. if (!viewName || fcViews[viewName] === undefined) { // a general view name, or "auto"
  730. viewName = viewName || 'day';
  731. viewStr = header.getViewsWithButtons().join(' '); // space-separated string of all the views in the header
  732. // try to match a general view name, like "week", against a specific one, like "agendaWeek"
  733. match = viewStr.match(new RegExp('\\w+' + capitaliseFirstLetter(viewName)));
  734. // fall back to the day view being used in the header
  735. if (!match) {
  736. match = viewStr.match(/\w+Day/);
  737. }
  738. viewName = match ? match[0] : 'agendaDay'; // fall back to agendaDay
  739. }
  740. date = newDate;
  741. changeView(viewName);
  742. }
  743. function getDate() {
  744. return date.clone();
  745. }
  746. /* Height "Freezing"
  747. -----------------------------------------------------------------------------*/
  748. function freezeContentHeight() {
  749. content.css({
  750. width: '100%',
  751. height: content.height(),
  752. overflow: 'hidden'
  753. });
  754. }
  755. function unfreezeContentHeight() {
  756. content.css({
  757. width: '',
  758. height: '',
  759. overflow: ''
  760. });
  761. }
  762. /* Misc
  763. -----------------------------------------------------------------------------*/
  764. function getCalendar() {
  765. return t;
  766. }
  767. function getView() {
  768. return currentView;
  769. }
  770. function option(name, value) {
  771. if (value === undefined) {
  772. return options[name];
  773. }
  774. if (name == 'height' || name == 'contentHeight' || name == 'aspectRatio') {
  775. options[name] = value;
  776. updateSize(true); // true = allow recalculation of height
  777. }
  778. }
  779. function trigger(name, thisObj) {
  780. if (options[name]) {
  781. return options[name].apply(
  782. thisObj || _element,
  783. Array.prototype.slice.call(arguments, 2)
  784. );
  785. }
  786. }
  787. }
  788. ;;
  789. /* Top toolbar area with buttons and title
  790. ----------------------------------------------------------------------------------------------------------------------*/
  791. // TODO: rename all header-related things to "toolbar"
  792. function Header(calendar, options) {
  793. var t = this;
  794. // exports
  795. t.render = render;
  796. t.destroy = destroy;
  797. t.updateTitle = updateTitle;
  798. t.activateButton = activateButton;
  799. t.deactivateButton = deactivateButton;
  800. t.disableButton = disableButton;
  801. t.enableButton = enableButton;
  802. t.getViewsWithButtons = getViewsWithButtons;
  803. // locals
  804. var el = $();
  805. var viewsWithButtons = [];
  806. var tm;
  807. function render() {
  808. var sections = options.header;
  809. tm = options.theme ? 'ui' : 'fc';
  810. if (sections) {
  811. el = $("<div class='fc-toolbar'/>")
  812. .append(renderSection('left'))
  813. .append(renderSection('right'))
  814. .append(renderSection('center'))
  815. .append('<div class="fc-clear"/>');
  816. return el;
  817. }
  818. }
  819. function destroy() {
  820. el.remove();
  821. }
  822. function renderSection(position) {
  823. var sectionEl = $('<div class="fc-' + position + '"/>');
  824. var buttonStr = options.header[position];
  825. if (buttonStr) {
  826. $.each(buttonStr.split(' '), function(i) {
  827. var groupChildren = $();
  828. var isOnlyButtons = true;
  829. var groupEl;
  830. $.each(this.split(','), function(j, buttonName) {
  831. var buttonClick;
  832. var themeIcon;
  833. var normalIcon;
  834. var defaultText;
  835. var customText;
  836. var innerHtml;
  837. var classes;
  838. var button;
  839. if (buttonName == 'title') {
  840. groupChildren = groupChildren.add($('<h2>&nbsp;</h2>')); // we always want it to take up height
  841. isOnlyButtons = false;
  842. }
  843. else {
  844. if (calendar[buttonName]) { // a calendar method
  845. buttonClick = function() {
  846. calendar[buttonName]();
  847. };
  848. }
  849. else if (fcViews[buttonName]) { // a view name
  850. buttonClick = function() {
  851. calendar.changeView(buttonName);
  852. };
  853. viewsWithButtons.push(buttonName);
  854. }
  855. if (buttonClick) {
  856. // smartProperty allows different text per view button (ex: "Agenda Week" vs "Basic Week")
  857. themeIcon = smartProperty(options.themeButtonIcons, buttonName);
  858. normalIcon = smartProperty(options.buttonIcons, buttonName);
  859. defaultText = smartProperty(options.defaultButtonText, buttonName);
  860. customText = smartProperty(options.buttonText, buttonName);
  861. if (customText) {
  862. innerHtml = htmlEscape(customText);
  863. }
  864. else if (themeIcon && options.theme) {
  865. innerHtml = "<span class='ui-icon ui-icon-" + themeIcon + "'></span>";
  866. }
  867. else if (normalIcon && !options.theme) {
  868. innerHtml = "<span class='fc-icon fc-icon-" + normalIcon + "'></span>";
  869. }
  870. else {
  871. innerHtml = htmlEscape(defaultText || buttonName);
  872. }
  873. classes = [
  874. 'fc-' + buttonName + '-button',
  875. tm + '-button',
  876. tm + '-state-default'
  877. ];
  878. button = $( // type="button" so that it doesn't submit a form
  879. '<button type="button" class="' + classes.join(' ') + '">' +
  880. innerHtml +
  881. '</button>'
  882. )
  883. .click(function() {
  884. // don't process clicks for disabled buttons
  885. if (!button.hasClass(tm + '-state-disabled')) {
  886. buttonClick();
  887. // after the click action, if the button becomes the "active" tab, or disabled,
  888. // it should never have a hover class, so remove it now.
  889. if (
  890. button.hasClass(tm + '-state-active') ||
  891. button.hasClass(tm + '-state-disabled')
  892. ) {
  893. button.removeClass(tm + '-state-hover');
  894. }
  895. }
  896. })
  897. .mousedown(function() {
  898. // the *down* effect (mouse pressed in).
  899. // only on buttons that are not the "active" tab, or disabled
  900. button
  901. .not('.' + tm + '-state-active')
  902. .not('.' + tm + '-state-disabled')
  903. .addClass(tm + '-state-down');
  904. })
  905. .mouseup(function() {
  906. // undo the *down* effect
  907. button.removeClass(tm + '-state-down');
  908. })
  909. .hover(
  910. function() {
  911. // the *hover* effect.
  912. // only on buttons that are not the "active" tab, or disabled
  913. button
  914. .not('.' + tm + '-state-active')
  915. .not('.' + tm + '-state-disabled')
  916. .addClass(tm + '-state-hover');
  917. },
  918. function() {
  919. // undo the *hover* effect
  920. button
  921. .removeClass(tm + '-state-hover')
  922. .removeClass(tm + '-state-down'); // if mouseleave happens before mouseup
  923. }
  924. );
  925. groupChildren = groupChildren.add(button);
  926. }
  927. }
  928. });
  929. if (isOnlyButtons) {
  930. groupChildren
  931. .first().addClass(tm + '-corner-left').end()
  932. .last().addClass(tm + '-corner-right').end();
  933. }
  934. if (groupChildren.length > 1) {
  935. groupEl = $('<div/>');
  936. if (isOnlyButtons) {
  937. groupEl.addClass('fc-button-group');
  938. }
  939. groupEl.append(groupChildren);
  940. sectionEl.append(groupEl);
  941. }
  942. else {
  943. sectionEl.append(groupChildren); // 1 or 0 children
  944. }
  945. });
  946. }
  947. return sectionEl;
  948. }
  949. function updateTitle(text) {
  950. el.find('h2').text(text);
  951. }
  952. function activateButton(buttonName) {
  953. el.find('.fc-' + buttonName + '-button')
  954. .addClass(tm + '-state-active');
  955. }
  956. function deactivateButton(buttonName) {
  957. el.find('.fc-' + buttonName + '-button')
  958. .removeClass(tm + '-state-active');
  959. }
  960. function disableButton(buttonName) {
  961. el.find('.fc-' + buttonName + '-button')
  962. .attr('disabled', 'disabled')
  963. .addClass(tm + '-state-disabled');
  964. }
  965. function enableButton(buttonName) {
  966. el.find('.fc-' + buttonName + '-button')
  967. .removeAttr('disabled')
  968. .removeClass(tm + '-state-disabled');
  969. }
  970. function getViewsWithButtons() {
  971. return viewsWithButtons;
  972. }
  973. }
  974. ;;
  975. fc.sourceNormalizers = [];
  976. fc.sourceFetchers = [];
  977. var ajaxDefaults = {
  978. dataType: 'json',
  979. cache: false
  980. };
  981. var eventGUID = 1;
  982. function EventManager(options) { // assumed to be a calendar
  983. var t = this;
  984. // exports
  985. t.isFetchNeeded = isFetchNeeded;
  986. t.fetchEvents = fetchEvents;
  987. t.addEventSource = addEventSource;
  988. t.removeEventSource = removeEventSource;
  989. t.updateEvent = updateEvent;
  990. t.renderEvent = renderEvent;
  991. t.removeEvents = removeEvents;
  992. t.clientEvents = clientEvents;
  993. t.mutateEvent = mutateEvent;
  994. // imports
  995. var trigger = t.trigger;
  996. var getView = t.getView;
  997. var reportEvents = t.reportEvents;
  998. var getEventEnd = t.getEventEnd;
  999. // locals
  1000. var stickySource = { events: [] };
  1001. var sources = [ stickySource ];
  1002. var rangeStart, rangeEnd;
  1003. var currentFetchID = 0;
  1004. var pendingSourceCnt = 0;
  1005. var loadingLevel = 0;
  1006. var cache = []; // holds events that have already been expanded
  1007. $.each(
  1008. (options.events ? [ options.events ] : []).concat(options.eventSources || []),
  1009. function(i, sourceInput) {
  1010. var source = buildEventSource(sourceInput);
  1011. if (source) {
  1012. sources.push(source);
  1013. }
  1014. }
  1015. );
  1016. /* Fetching
  1017. -----------------------------------------------------------------------------*/
  1018. function isFetchNeeded(start, end) {
  1019. return !rangeStart || // nothing has been fetched yet?
  1020. // or, a part of the new range is outside of the old range? (after normalizing)
  1021. start.clone().stripZone() < rangeStart.clone().stripZone() ||
  1022. end.clone().stripZone() > rangeEnd.clone().stripZone();
  1023. }
  1024. function fetchEvents(start, end) {
  1025. rangeStart = start;
  1026. rangeEnd = end;
  1027. cache = [];
  1028. var fetchID = ++currentFetchID;
  1029. var len = sources.length;
  1030. pendingSourceCnt = len;
  1031. for (var i=0; i<len; i++) {
  1032. fetchEventSource(sources[i], fetchID);
  1033. }
  1034. }
  1035. function fetchEventSource(source, fetchID) {
  1036. _fetchEventSource(source, function(eventInputs) {
  1037. var isArraySource = $.isArray(source.events);
  1038. var i, eventInput;
  1039. var abstractEvent;
  1040. if (fetchID == currentFetchID) {
  1041. if (eventInputs) {
  1042. for (i = 0; i < eventInputs.length; i++) {
  1043. eventInput = eventInputs[i];
  1044. if (isArraySource) { // array sources have already been convert to Event Objects
  1045. abstractEvent = eventInput;
  1046. }
  1047. else {
  1048. abstractEvent = buildEventFromInput(eventInput, source);
  1049. }
  1050. if (abstractEvent) { // not false (an invalid event)
  1051. cache.push.apply(
  1052. cache,
  1053. expandEvent(abstractEvent) // add individual expanded events to the cache
  1054. );
  1055. }
  1056. }
  1057. }
  1058. pendingSourceCnt--;
  1059. if (!pendingSourceCnt) {
  1060. reportEvents(cache);
  1061. }
  1062. }
  1063. });
  1064. }
  1065. function _fetchEventSource(source, callback) {
  1066. var i;
  1067. var fetchers = fc.sourceFetchers;
  1068. var res;
  1069. for (i=0; i<fetchers.length; i++) {
  1070. res = fetchers[i].call(
  1071. t, // this, the Calendar object
  1072. source,
  1073. rangeStart.clone(),
  1074. rangeEnd.clone(),
  1075. options.timezone,
  1076. callback
  1077. );
  1078. if (res === true) {
  1079. // the fetcher is in charge. made its own async request
  1080. return;
  1081. }
  1082. else if (typeof res == 'object') {
  1083. // the fetcher returned a new source. process it
  1084. _fetchEventSource(res, callback);
  1085. return;
  1086. }
  1087. }
  1088. var events = source.events;
  1089. if (events) {
  1090. if ($.isFunction(events)) {
  1091. pushLoading();
  1092. events.call(
  1093. t, // this, the Calendar object
  1094. rangeStart.clone(),
  1095. rangeEnd.clone(),
  1096. options.timezone,
  1097. function(events) {
  1098. callback(events);
  1099. popLoading();
  1100. }
  1101. );
  1102. }
  1103. else if ($.isArray(events)) {
  1104. callback(events);
  1105. }
  1106. else {
  1107. callback();
  1108. }
  1109. }else{
  1110. var url = source.url;
  1111. if (url) {
  1112. var success = source.success;
  1113. var error = source.error;
  1114. var complete = source.complete;
  1115. // retrieve any outbound GET/POST $.ajax data from the options
  1116. var customData;
  1117. if ($.isFunction(source.data)) {
  1118. // supplied as a function that returns a key/value object
  1119. customData = source.data();
  1120. }
  1121. else {
  1122. // supplied as a straight key/value object
  1123. customData = source.data;
  1124. }
  1125. // use a copy of the custom data so we can modify the parameters
  1126. // and not affect the passed-in object.
  1127. var data = $.extend({}, customData || {});
  1128. var startParam = firstDefined(source.startParam, options.startParam);
  1129. var endParam = firstDefined(source.endParam, options.endParam);
  1130. var timezoneParam = firstDefined(source.timezoneParam, options.timezoneParam);
  1131. if (startParam) {
  1132. data[startParam] = rangeStart.format();
  1133. }
  1134. if (endParam) {
  1135. data[endParam] = rangeEnd.format();
  1136. }
  1137. if (options.timezone && options.timezone != 'local') {
  1138. data[timezoneParam] = options.timezone;
  1139. }
  1140. pushLoading();
  1141. $.ajax($.extend({}, ajaxDefaults, source, {
  1142. data: data,
  1143. success: function(events) {
  1144. events = events || [];
  1145. var res = applyAll(success, this, arguments);
  1146. if ($.isArray(res)) {
  1147. events = res;
  1148. }
  1149. callback(events);
  1150. },
  1151. error: function() {
  1152. applyAll(error, this, arguments);
  1153. callback();
  1154. },
  1155. complete: function() {
  1156. applyAll(complete, this, arguments);
  1157. popLoading();
  1158. }
  1159. }));
  1160. }else{
  1161. callback();
  1162. }
  1163. }
  1164. }
  1165. /* Sources
  1166. -----------------------------------------------------------------------------*/
  1167. function addEventSource(sourceInput) {
  1168. var source = buildEventSource(sourceInput);
  1169. if (source) {
  1170. sources.push(source);
  1171. pendingSourceCnt++;
  1172. fetchEventSource(source, currentFetchID); // will eventually call reportEvents
  1173. }
  1174. }
  1175. function buildEventSource(sourceInput) { // will return undefined if invalid source
  1176. var normalizers = fc.sourceNormalizers;
  1177. var source;
  1178. var i;
  1179. if ($.isFunction(sourceInput) || $.isArray(sourceInput)) {
  1180. source = { events: sourceInput };
  1181. }
  1182. else if (typeof sourceInput === 'string') {
  1183. source = { url: sourceInput };
  1184. }
  1185. else if (typeof sourceInput === 'object') {
  1186. source = $.extend({}, sourceInput); // shallow copy
  1187. }
  1188. if (source) {
  1189. // TODO: repeat code, same code for event classNames
  1190. if (source.className) {
  1191. if (typeof source.className === 'string') {
  1192. source.className = source.className.split(/\s+/);
  1193. }
  1194. // otherwise, assumed to be an array
  1195. }
  1196. else {
  1197. source.className = [];
  1198. }
  1199. // for array sources, we convert to standard Event Objects up front
  1200. if ($.isArray(source.events)) {
  1201. source.origArray = source.events; // for removeEventSource
  1202. source.events = $.map(source.events, function(eventInput) {
  1203. return buildEventFromInput(eventInput, source);
  1204. });
  1205. }
  1206. for (i=0; i<normalizers.length; i++) {
  1207. normalizers[i].call(t, source);
  1208. }
  1209. return source;
  1210. }
  1211. }
  1212. function removeEventSource(source) {
  1213. sources = $.grep(sources, function(src) {
  1214. return !isSourcesEqual(src, source);
  1215. });
  1216. // remove all client events from that source
  1217. cache = $.grep(cache, function(e) {
  1218. return !isSourcesEqual(e.source, source);
  1219. });
  1220. reportEvents(cache);
  1221. }
  1222. function isSourcesEqual(source1, source2) {
  1223. return source1 && source2 && getSourcePrimitive(source1) == getSourcePrimitive(source2);
  1224. }
  1225. function getSourcePrimitive(source) {
  1226. return (
  1227. (typeof source === 'object') ? // a normalized event source?
  1228. (source.origArray || source.googleCalendarId || source.url || source.events) : // get the primitive
  1229. null
  1230. ) ||
  1231. source; // the given argument *is* the primitive
  1232. }
  1233. /* Manipulation
  1234. -----------------------------------------------------------------------------*/
  1235. function updateEvent(event) {
  1236. event.start = t.moment(event.start);
  1237. if (event.end) {
  1238. event.end = t.moment(event.end);
  1239. }
  1240. mutateEvent(event);
  1241. propagateMiscProperties(event);
  1242. reportEvents(cache); // reports event modifications (so we can redraw)
  1243. }
  1244. var miscCopyableProps = [
  1245. 'title',
  1246. 'url',
  1247. 'allDay',
  1248. 'className',
  1249. 'editable',
  1250. 'color',
  1251. 'backgroundColor',
  1252. 'borderColor',
  1253. 'textColor'
  1254. ];
  1255. function propagateMiscProperties(event) {
  1256. var i;
  1257. var cachedEvent;
  1258. var j;
  1259. var prop;
  1260. for (i=0; i<cache.length; i++) {
  1261. cachedEvent = cache[i];
  1262. if (cachedEvent._id == event._id && cachedEvent !== event) {
  1263. for (j=0; j<miscCopyableProps.length; j++) {
  1264. prop = miscCopyableProps[j];
  1265. if (event[prop] !== undefined) {
  1266. cachedEvent[prop] = event[prop];
  1267. }
  1268. }
  1269. }
  1270. }
  1271. }
  1272. // returns the expanded events that were created
  1273. function renderEvent(eventInput, stick) {
  1274. var abstractEvent = buildEventFromInput(eventInput);
  1275. var events;
  1276. var i, event;
  1277. if (abstractEvent) { // not false (a valid input)
  1278. events = expandEvent(abstractEvent);
  1279. for (i = 0; i < events.length; i++) {
  1280. event = events[i];
  1281. if (!event.source) {
  1282. if (stick) {
  1283. stickySource.events.push(event);
  1284. event.source = stickySource;
  1285. }
  1286. cache.push(event);
  1287. }
  1288. }
  1289. reportEvents(cache);
  1290. return events;
  1291. }
  1292. return [];
  1293. }
  1294. function removeEvents(filter) {
  1295. var eventID;
  1296. var i;
  1297. if (filter == null) { // null or undefined. remove all events
  1298. filter = function() { return true; }; // will always match
  1299. }
  1300. else if (!$.isFunction(filter)) { // an event ID
  1301. eventID = filter + '';
  1302. filter = function(event) {
  1303. return event._id == eventID;
  1304. };
  1305. }
  1306. // Purge event(s) from our local cache
  1307. cache = $.grep(cache, filter, true); // inverse=true
  1308. // Remove events from array sources.
  1309. // This works because they have been converted to official Event Objects up front.
  1310. // (and as a result, event._id has been calculated).
  1311. for (i=0; i<sources.length; i++) {
  1312. if ($.isArray(sources[i].events)) {
  1313. sources[i].events = $.grep(sources[i].events, filter, true);
  1314. }
  1315. }
  1316. reportEvents(cache);
  1317. }
  1318. function clientEvents(filter) {
  1319. if ($.isFunction(filter)) {
  1320. return $.grep(cache, filter);
  1321. }
  1322. else if (filter != null) { // not null, not undefined. an event ID
  1323. filter += '';
  1324. return $.grep(cache, function(e) {
  1325. return e._id == filter;
  1326. });
  1327. }
  1328. return cache; // else, return all
  1329. }
  1330. /* Loading State
  1331. -----------------------------------------------------------------------------*/
  1332. function pushLoading() {
  1333. if (!(loadingLevel++)) {
  1334. trigger('loading', null, true, getView());
  1335. }
  1336. }
  1337. function popLoading() {
  1338. if (!(--loadingLevel)) {
  1339. trigger('loading', null, false, getView());
  1340. }
  1341. }
  1342. /* Event Normalization
  1343. -----------------------------------------------------------------------------*/
  1344. // Given a raw object with key/value properties, returns an "abstract" Event object.
  1345. // An "abstract" event is an event that, if recurring, will not have been expanded yet.
  1346. // Will return `false` when input is invalid.
  1347. // `source` is optional
  1348. function buildEventFromInput(input, source) {
  1349. var out = {};
  1350. var start, end;
  1351. var allDay;
  1352. var allDayDefault;
  1353. if (options.eventDataTransform) {
  1354. input = options.eventDataTransform(input);
  1355. }
  1356. if (source && source.eventDataTransform) {
  1357. input = source.eventDataTransform(input);
  1358. }
  1359. // Copy all properties over to the resulting object.
  1360. // The special-case properties will be copied over afterwards.
  1361. $.extend(out, input);
  1362. if (source) {
  1363. out.source = source;
  1364. }
  1365. out._id = input._id || (input.id === undefined ? '_fc' + eventGUID++ : input.id + '');
  1366. if (input.className) {
  1367. if (typeof input.className == 'string') {
  1368. out.className = input.className.split(/\s+/);
  1369. }
  1370. else { // assumed to be an array
  1371. out.className = input.className;
  1372. }
  1373. }
  1374. else {
  1375. out.className = [];
  1376. }
  1377. start = input.start || input.date; // "date" is an alias for "start"
  1378. end = input.end;
  1379. // parse as a time (Duration) if applicable
  1380. if (isTimeString(start)) {
  1381. start = moment.duration(start);
  1382. }
  1383. if (isTimeString(end)) {
  1384. end = moment.duration(end);
  1385. }
  1386. if (input.dow || moment.isDuration(start) || moment.isDuration(end)) {
  1387. // the event is "abstract" (recurring) so don't calculate exact start/end dates just yet
  1388. out.start = start ? moment.duration(start) : null; // will be a Duration or null
  1389. out.end = end ? moment.duration(end) : null; // will be a Duration or null
  1390. out._recurring = true; // our internal marker
  1391. }
  1392. else {
  1393. if (start) {
  1394. start = t.moment(start);
  1395. if (!start.isValid()) {
  1396. return false;
  1397. }
  1398. }
  1399. if (end) {
  1400. end = t.moment(end);
  1401. if (!end.isValid()) {
  1402. end = null; // let defaults take over
  1403. }
  1404. }
  1405. allDay = input.allDay;
  1406. if (allDay === undefined) {
  1407. allDayDefault = firstDefined(
  1408. source ? source.allDayDefault : undefined,
  1409. options.allDayDefault
  1410. );
  1411. if (allDayDefault !== undefined) {
  1412. // use the default
  1413. allDay = allDayDefault;
  1414. }
  1415. else {
  1416. // if a single date has a time, the event should not be all-day
  1417. allDay = !start.hasTime() && (!end || !end.hasTime());
  1418. }
  1419. }
  1420. assignDatesToEvent(start, end, allDay, out);
  1421. }
  1422. return out;
  1423. }
  1424. // Normalizes and assigns the given dates to the given partially-formed event object.
  1425. // Requires an explicit `allDay` boolean parameter.
  1426. // NOTE: mutates the given start/end moments. does not make an internal copy
  1427. function assignDatesToEvent(start, end, allDay, event) {
  1428. // normalize the date based on allDay
  1429. if (allDay) {
  1430. // neither date should have a time
  1431. if (start.hasTime()) {
  1432. start.stripTime();
  1433. }
  1434. if (end && end.hasTime()) {
  1435. end.stripTime();
  1436. }
  1437. }
  1438. else {
  1439. // force a time/zone up the dates
  1440. if (!start.hasTime()) {
  1441. start = t.rezoneDate(start);
  1442. }
  1443. if (end && !end.hasTime()) {
  1444. end = t.rezoneDate(end);
  1445. }
  1446. }
  1447. if (end && end <= start) { // end is exclusive. must be after start
  1448. end = null; // let defaults take over
  1449. }
  1450. event.allDay = allDay;
  1451. event.start = start;
  1452. event.end = end || null; // ensure null if falsy
  1453. if (options.forceEventDuration && !event.end) {
  1454. event.end = getEventEnd(event);
  1455. }
  1456. backupEventDates(event);
  1457. }
  1458. // If the given event is a recurring event, break it down into an array of individual instances.
  1459. // If not a recurring event, return an array with the single original event.
  1460. // If given a falsy input (probably because of a failed buildEventFromInput call), returns an empty array.
  1461. // HACK: can override the recurring window by providing custom rangeStart/rangeEnd (for businessHours).
  1462. function expandEvent(abstractEvent, _rangeStart, _rangeEnd) {
  1463. var events = [];
  1464. var dowHash;
  1465. var dow;
  1466. var i;
  1467. var date;
  1468. var startTime, endTime;
  1469. var start, end;
  1470. var event;
  1471. _rangeStart = _rangeStart || rangeStart;
  1472. _rangeEnd = _rangeEnd || rangeEnd;
  1473. if (abstractEvent) {
  1474. if (abstractEvent._recurring) {
  1475. // make a boolean hash as to whether the event occurs on each day-of-week
  1476. if ((dow = abstractEvent.dow)) {
  1477. dowHash = {};
  1478. for (i = 0; i < dow.length; i++) {
  1479. dowHash[dow[i]] = true;
  1480. }
  1481. }
  1482. // iterate through every day in the current range
  1483. date = _rangeStart.clone().stripTime(); // holds the date of the current day
  1484. while (date.isBefore(_rangeEnd)) {
  1485. if (!dowHash || dowHash[date.day()]) { // if everyday, or this particular day-of-week
  1486. startTime = abstractEvent.start; // the stored start and end properties are times (Durations)
  1487. endTime = abstractEvent.end; // "
  1488. start = date.clone();
  1489. end = null;
  1490. if (startTime) {
  1491. start = start.time(startTime);
  1492. }
  1493. if (endTime) {
  1494. end = date.clone().time(endTime);
  1495. }
  1496. event = $.extend({}, abstractEvent); // make a copy of the original
  1497. assignDatesToEvent(
  1498. start, end,
  1499. !startTime && !endTime, // allDay?
  1500. event
  1501. );
  1502. events.push(event);
  1503. }
  1504. date.add(1, 'days');
  1505. }
  1506. }
  1507. else {
  1508. events.push(abstractEvent); // return the original event. will be a one-item array
  1509. }
  1510. }
  1511. return events;
  1512. }
  1513. /* Event Modification Math
  1514. -----------------------------------------------------------------------------------------*/
  1515. // Modify the date(s) of an event and make this change propagate to all other events with
  1516. // the same ID (related repeating events).
  1517. //
  1518. // If `newStart`/`newEnd` are not specified, the "new" dates are assumed to be `event.start` and `event.end`.
  1519. // The "old" dates to be compare against are always `event._start` and `event._end` (set by EventManager).
  1520. //
  1521. // Returns an object with delta information and a function to undo all operations.
  1522. //
  1523. function mutateEvent(event, newStart, newEnd) {
  1524. var oldAllDay = event._allDay;
  1525. var oldStart = event._start;
  1526. var oldEnd = event._end;
  1527. var clearEnd = false;
  1528. var newAllDay;
  1529. var dateDelta;
  1530. var durationDelta;
  1531. var undoFunc;
  1532. // if no new dates were passed in, compare against the event's existing dates
  1533. if (!newStart && !newEnd) {
  1534. newStart = event.start;
  1535. newEnd = event.end;
  1536. }
  1537. // NOTE: throughout this function, the initial values of `newStart` and `newEnd` are
  1538. // preserved. These values may be undefined.
  1539. // detect new allDay
  1540. if (event.allDay != oldAllDay) { // if value has changed, use it
  1541. newAllDay = event.allDay;
  1542. }
  1543. else { // otherwise, see if any of the new dates are allDay
  1544. newAllDay = !(newStart || newEnd).hasTime();
  1545. }
  1546. // normalize the new dates based on allDay
  1547. if (newAllDay) {
  1548. if (newStart) {
  1549. newStart = newStart.clone().stripTime();
  1550. }
  1551. if (newEnd) {
  1552. newEnd = newEnd.clone().stripTime();
  1553. }
  1554. }
  1555. // compute dateDelta
  1556. if (newStart) {
  1557. if (newAllDay) {
  1558. dateDelta = dayishDiff(newStart, oldStart.clone().stripTime()); // treat oldStart as allDay
  1559. }
  1560. else {
  1561. dateDelta = dayishDiff(newStart, oldStart);
  1562. }
  1563. }
  1564. if (newAllDay != oldAllDay) {
  1565. // if allDay has changed, always throw away the end
  1566. clearEnd = true;
  1567. }
  1568. else if (newEnd) {
  1569. durationDelta = dayishDiff(
  1570. // new duration
  1571. newEnd || t.getDefaultEventEnd(newAllDay, newStart || oldStart),
  1572. newStart || oldStart
  1573. ).subtract(dayishDiff(
  1574. // subtract old duration
  1575. oldEnd || t.getDefaultEventEnd(oldAllDay, oldStart),
  1576. oldStart
  1577. ));
  1578. }
  1579. undoFunc = mutateEvents(
  1580. clientEvents(event._id), // get events with this ID
  1581. clearEnd,
  1582. newAllDay,
  1583. dateDelta,
  1584. durationDelta
  1585. );
  1586. return {
  1587. dateDelta: dateDelta,
  1588. durationDelta: durationDelta,
  1589. undo: undoFunc
  1590. };
  1591. }
  1592. // Modifies an array of events in the following ways (operations are in order):
  1593. // - clear the event's `end`
  1594. // - convert the event to allDay
  1595. // - add `dateDelta` to the start and end
  1596. // - add `durationDelta` to the event's duration
  1597. //
  1598. // Returns a function that can be called to undo all the operations.
  1599. //
  1600. function mutateEvents(events, clearEnd, forceAllDay, dateDelta, durationDelta) {
  1601. var isAmbigTimezone = t.getIsAmbigTimezone();
  1602. var undoFunctions = [];
  1603. $.each(events, function(i, event) {
  1604. var oldAllDay = event._allDay;
  1605. var oldStart = event._start;
  1606. var oldEnd = event._end;
  1607. var newAllDay = forceAllDay != null ? forceAllDay : oldAllDay;
  1608. var newStart = oldStart.clone();
  1609. var newEnd = (!clearEnd && oldEnd) ? oldEnd.clone() : null;
  1610. // NOTE: this function is responsible for transforming `newStart` and `newEnd`,
  1611. // which were initialized to the OLD values first. `newEnd` may be null.
  1612. // normlize newStart/newEnd to be consistent with newAllDay
  1613. if (newAllDay) {
  1614. newStart.stripTime();
  1615. if (newEnd) {
  1616. newEnd.stripTime();
  1617. }
  1618. }
  1619. else {
  1620. if (!newStart.hasTime()) {
  1621. newStart = t.rezoneDate(newStart);
  1622. }
  1623. if (newEnd && !newEnd.hasTime()) {
  1624. newEnd = t.rezoneDate(newEnd);
  1625. }
  1626. }
  1627. // ensure we have an end date if necessary
  1628. if (!newEnd && (options.forceEventDuration || +durationDelta)) {
  1629. newEnd = t.getDefaultEventEnd(newAllDay, newStart);
  1630. }
  1631. // translate the dates
  1632. newStart.add(dateDelta);
  1633. if (newEnd) {
  1634. newEnd.add(dateDelta).add(durationDelta);
  1635. }
  1636. // if the dates have changed, and we know it is impossible to recompute the
  1637. // timezone offsets, strip the zone.
  1638. if (isAmbigTimezone) {
  1639. if (+dateDelta || +durationDelta) {
  1640. newStart.stripZone();
  1641. if (newEnd) {
  1642. newEnd.stripZone();
  1643. }
  1644. }
  1645. }
  1646. event.allDay = newAllDay;
  1647. event.start = newStart;
  1648. event.end = newEnd;
  1649. backupEventDates(event);
  1650. undoFunctions.push(function() {
  1651. event.allDay = oldAllDay;
  1652. event.start = oldStart;
  1653. event.end = oldEnd;
  1654. backupEventDates(event);
  1655. });
  1656. });
  1657. return function() {
  1658. for (var i=0; i<undoFunctions.length; i++) {
  1659. undoFunctions[i]();
  1660. }
  1661. };
  1662. }
  1663. /* Business Hours
  1664. -----------------------------------------------------------------------------------------*/
  1665. t.getBusinessHoursEvents = getBusinessHoursEvents;
  1666. // Returns an array of events as to when the business hours occur in the given view.
  1667. // Abuse of our event system :(
  1668. function getBusinessHoursEvents() {
  1669. var optionVal = options.businessHours;
  1670. var defaultVal = {
  1671. className: 'fc-nonbusiness',
  1672. start: '09:00',
  1673. end: '17:00',
  1674. dow: [ 1, 2, 3, 4, 5 ], // monday - friday
  1675. rendering: 'inverse-background'
  1676. };
  1677. var view = t.getView();
  1678. var eventInput;
  1679. if (optionVal) {
  1680. if (typeof optionVal === 'object') {
  1681. // option value is an object that can override the default business hours
  1682. eventInput = $.extend({}, defaultVal, optionVal);
  1683. }
  1684. else {
  1685. // option value is `true`. use default business hours
  1686. eventInput = defaultVal;
  1687. }
  1688. }
  1689. if (eventInput) {
  1690. return expandEvent(
  1691. buildEventFromInput(eventInput),
  1692. view.start,
  1693. view.end
  1694. );
  1695. }
  1696. return [];
  1697. }
  1698. /* Overlapping / Constraining
  1699. -----------------------------------------------------------------------------------------*/
  1700. t.isEventAllowedInRange = isEventAllowedInRange;
  1701. t.isSelectionAllowedInRange = isSelectionAllowedInRange;
  1702. t.isExternalDragAllowedInRange = isExternalDragAllowedInRange;
  1703. function isEventAllowedInRange(event, start, end) {
  1704. var source = event.source || {};
  1705. var constraint = firstDefined(
  1706. event.constraint,
  1707. source.constraint,
  1708. options.eventConstraint
  1709. );
  1710. var overlap = firstDefined(
  1711. event.overlap,
  1712. source.overlap,
  1713. options.eventOverlap
  1714. );
  1715. return isRangeAllowed(start, end, constraint, overlap, event);
  1716. }
  1717. function isSelectionAllowedInRange(start, end) {
  1718. return isRangeAllowed(
  1719. start,
  1720. end,
  1721. options.selectConstraint,
  1722. options.selectOverlap
  1723. );
  1724. }
  1725. function isExternalDragAllowedInRange(start, end, eventInput) { // eventInput is optional associated event data
  1726. var event;
  1727. if (eventInput) {
  1728. event = expandEvent(buildEventFromInput(eventInput))[0];
  1729. if (event) {
  1730. return isEventAllowedInRange(event, start, end);
  1731. }
  1732. }
  1733. return isSelectionAllowedInRange(start, end); // treat it as a selection
  1734. }
  1735. // Returns true if the given range (caused by an event drop/resize or a selection) is allowed to exist
  1736. // according to the constraint/overlap settings.
  1737. // `event` is not required if checking a selection.
  1738. function isRangeAllowed(start, end, constraint, overlap, event) {
  1739. var constraintEvents;
  1740. var anyContainment;
  1741. var i, otherEvent;
  1742. var otherOverlap;
  1743. // normalize. fyi, we're normalizing in too many places :(
  1744. start = start.clone().stripZone();
  1745. end = end.clone().stripZone();
  1746. // the range must be fully contained by at least one of produced constraint events
  1747. if (constraint != null) {
  1748. constraintEvents = constraintToEvents(constraint);
  1749. anyContainment = false;
  1750. for (i = 0; i < constraintEvents.length; i++) {
  1751. if (eventContainsRange(constraintEvents[i], start, end)) {
  1752. anyContainment = true;
  1753. break;
  1754. }
  1755. }
  1756. if (!anyContainment) {
  1757. return false;
  1758. }
  1759. }
  1760. for (i = 0; i < cache.length; i++) { // loop all events and detect overlap
  1761. otherEvent = cache[i];
  1762. // don't compare the event to itself or other related [repeating] events
  1763. if (event && event._id === otherEvent._id) {
  1764. continue;
  1765. }
  1766. // there needs to be an actual intersection before disallowing anything
  1767. if (eventIntersectsRange(otherEvent, start, end)) {
  1768. // evaluate overlap for the given range and short-circuit if necessary
  1769. if (overlap === false) {
  1770. return false;
  1771. }
  1772. else if (typeof overlap === 'function' && !overlap(otherEvent, event)) {
  1773. return false;
  1774. }
  1775. // if we are computing if the given range is allowable for an event, consider the other event's
  1776. // EventObject-specific or Source-specific `overlap` property
  1777. if (event) {
  1778. otherOverlap = firstDefined(
  1779. otherEvent.overlap,
  1780. (otherEvent.source || {}).overlap
  1781. // we already considered the global `eventOverlap`
  1782. );
  1783. if (otherOverlap === false) {
  1784. return false;
  1785. }
  1786. if (typeof otherOverlap === 'function' && !otherOverlap(event, otherEvent)) {
  1787. return false;
  1788. }
  1789. }
  1790. }
  1791. }
  1792. return true;
  1793. }
  1794. // Given an event input from the API, produces an array of event objects. Possible event inputs:
  1795. // 'businessHours'
  1796. // An event ID (number or string)
  1797. // An object with specific start/end dates or a recurring event (like what businessHours accepts)
  1798. function constraintToEvents(constraintInput) {
  1799. if (constraintInput === 'businessHours') {
  1800. return getBusinessHoursEvents();
  1801. }
  1802. if (typeof constraintInput === 'object') {
  1803. return expandEvent(buildEventFromInput(constraintInput));
  1804. }
  1805. return clientEvents(constraintInput); // probably an ID
  1806. }
  1807. // Is the event's date ranged fully contained by the given range?
  1808. // start/end already assumed to have stripped zones :(
  1809. function eventContainsRange(event, start, end) {
  1810. var eventStart = event.start.clone().stripZone();
  1811. var eventEnd = t.getEventEnd(event).stripZone();
  1812. return start >= eventStart && end <= eventEnd;
  1813. }
  1814. // Does the event's date range intersect with the given range?
  1815. // start/end already assumed to have stripped zones :(
  1816. function eventIntersectsRange(event, start, end) {
  1817. var eventStart = event.start.clone().stripZone();
  1818. var eventEnd = t.getEventEnd(event).stripZone();
  1819. return start < eventEnd && end > eventStart;
  1820. }
  1821. }
  1822. // updates the "backup" properties, which are preserved in order to compute diffs later on.
  1823. function backupEventDates(event) {
  1824. event._allDay = event.allDay;
  1825. event._start = event.start.clone();
  1826. event._end = event.end ? event.end.clone() : null;
  1827. }
  1828. ;;
  1829. /* FullCalendar-specific DOM Utilities
  1830. ----------------------------------------------------------------------------------------------------------------------*/
  1831. // Given the scrollbar widths of some other container, create borders/margins on rowEls in order to match the left
  1832. // and right space that was offset by the scrollbars. A 1-pixel border first, then margin beyond that.
  1833. function compensateScroll(rowEls, scrollbarWidths) {
  1834. if (scrollbarWidths.left) {
  1835. rowEls.css({
  1836. 'border-left-width': 1,
  1837. 'margin-left': scrollbarWidths.left - 1
  1838. });
  1839. }
  1840. if (scrollbarWidths.right) {
  1841. rowEls.css({
  1842. 'border-right-width': 1,
  1843. 'margin-right': scrollbarWidths.right - 1
  1844. });
  1845. }
  1846. }
  1847. // Undoes compensateScroll and restores all borders/margins
  1848. function uncompensateScroll(rowEls) {
  1849. rowEls.css({
  1850. 'margin-left': '',
  1851. 'margin-right': '',
  1852. 'border-left-width': '',
  1853. 'border-right-width': ''
  1854. });
  1855. }
  1856. // Make the mouse cursor express that an event is not allowed in the current area
  1857. function disableCursor() {
  1858. $('body').addClass('fc-not-allowed');
  1859. }
  1860. // Returns the mouse cursor to its original look
  1861. function enableCursor() {
  1862. $('body').removeClass('fc-not-allowed');
  1863. }
  1864. // Given a total available height to fill, have `els` (essentially child rows) expand to accomodate.
  1865. // By default, all elements that are shorter than the recommended height are expanded uniformly, not considering
  1866. // any other els that are already too tall. if `shouldRedistribute` is on, it considers these tall rows and
  1867. // reduces the available height.
  1868. function distributeHeight(els, availableHeight, shouldRedistribute) {
  1869. // *FLOORING NOTE*: we floor in certain places because zoom can give inaccurate floating-point dimensions,
  1870. // and it is better to be shorter than taller, to avoid creating unnecessary scrollbars.
  1871. var minOffset1 = Math.floor(availableHeight / els.length); // for non-last element
  1872. var minOffset2 = Math.floor(availableHeight - minOffset1 * (els.length - 1)); // for last element *FLOORING NOTE*
  1873. var flexEls = []; // elements that are allowed to expand. array of DOM nodes
  1874. var flexOffsets = []; // amount of vertical space it takes up
  1875. var flexHeights = []; // actual css height
  1876. var usedHeight = 0;
  1877. undistributeHeight(els); // give all elements their natural height
  1878. // find elements that are below the recommended height (expandable).
  1879. // important to query for heights in a single first pass (to avoid reflow oscillation).
  1880. els.each(function(i, el) {
  1881. var minOffset = i === els.length - 1 ? minOffset2 : minOffset1;
  1882. var naturalOffset = $(el).outerHeight(true);
  1883. if (naturalOffset < minOffset) {
  1884. flexEls.push(el);
  1885. flexOffsets.push(naturalOffset);
  1886. flexHeights.push($(el).height());
  1887. }
  1888. else {
  1889. // this element stretches past recommended height (non-expandable). mark the space as occupied.
  1890. usedHeight += naturalOffset;
  1891. }
  1892. });
  1893. // readjust the recommended height to only consider the height available to non-maxed-out rows.
  1894. if (shouldRedistribute) {
  1895. availableHeight -= usedHeight;
  1896. minOffset1 = Math.floor(availableHeight / flexEls.length);
  1897. minOffset2 = Math.floor(availableHeight - minOffset1 * (flexEls.length - 1)); // *FLOORING NOTE*
  1898. }
  1899. // assign heights to all expandable elements
  1900. $(flexEls).each(function(i, el) {
  1901. var minOffset = i === flexEls.length - 1 ? minOffset2 : minOffset1;
  1902. var naturalOffset = flexOffsets[i];
  1903. var naturalHeight = flexHeights[i];
  1904. var newHeight = minOffset - (naturalOffset - naturalHeight); // subtract the margin/padding
  1905. if (naturalOffset < minOffset) { // we check this again because redistribution might have changed things
  1906. $(el).height(newHeight);
  1907. }
  1908. });
  1909. }
  1910. // Undoes distrubuteHeight, restoring all els to their natural height
  1911. function undistributeHeight(els) {
  1912. els.height('');
  1913. }
  1914. // Given `els`, a jQuery set of <td> cells, find the cell with the largest natural width and set the widths of all the
  1915. // cells to be that width.
  1916. // PREREQUISITE: if you want a cell to take up width, it needs to have a single inner element w/ display:inline
  1917. function matchCellWidths(els) {
  1918. var maxInnerWidth = 0;
  1919. els.find('> *').each(function(i, innerEl) {
  1920. var innerWidth = $(innerEl).outerWidth();
  1921. if (innerWidth > maxInnerWidth) {
  1922. maxInnerWidth = innerWidth;
  1923. }
  1924. });
  1925. maxInnerWidth++; // sometimes not accurate of width the text needs to stay on one line. insurance
  1926. els.width(maxInnerWidth);
  1927. return maxInnerWidth;
  1928. }
  1929. // Turns a container element into a scroller if its contents is taller than the allotted height.
  1930. // Returns true if the element is now a scroller, false otherwise.
  1931. // NOTE: this method is best because it takes weird zooming dimensions into account
  1932. function setPotentialScroller(containerEl, height) {
  1933. containerEl.height(height).addClass('fc-scroller');
  1934. // are scrollbars needed?
  1935. if (containerEl[0].scrollHeight - 1 > containerEl[0].clientHeight) { // !!! -1 because IE is often off-by-one :(
  1936. return true;
  1937. }
  1938. unsetScroller(containerEl); // undo
  1939. return false;
  1940. }
  1941. // Takes an element that might have been a scroller, and turns it back into a normal element.
  1942. function unsetScroller(containerEl) {
  1943. containerEl.height('').removeClass('fc-scroller');
  1944. }
  1945. /* General DOM Utilities
  1946. ----------------------------------------------------------------------------------------------------------------------*/
  1947. // borrowed from https://github.com/jquery/jquery-ui/blob/1.11.0/ui/core.js#L51
  1948. function getScrollParent(el) {
  1949. var position = el.css('position'),
  1950. scrollParent = el.parents().filter(function() {
  1951. var parent = $(this);
  1952. return (/(auto|scroll)/).test(
  1953. parent.css('overflow') + parent.css('overflow-y') + parent.css('overflow-x')
  1954. );
  1955. }).eq(0);
  1956. return position === 'fixed' || !scrollParent.length ? $(el[0].ownerDocument || document) : scrollParent;
  1957. }
  1958. // Given a container element, return an object with the pixel values of the left/right scrollbars.
  1959. // Left scrollbars might occur on RTL browsers (IE maybe?) but I have not tested.
  1960. // PREREQUISITE: container element must have a single child with display:block
  1961. function getScrollbarWidths(container) {
  1962. var containerLeft = container.offset().left;
  1963. var containerRight = containerLeft + container.width();
  1964. var inner = container.children();
  1965. var innerLeft = inner.offset().left;
  1966. var innerRight = innerLeft + inner.outerWidth();
  1967. return {
  1968. left: innerLeft - containerLeft,
  1969. right: containerRight - innerRight
  1970. };
  1971. }
  1972. // Returns a boolean whether this was a left mouse click and no ctrl key (which means right click on Mac)
  1973. function isPrimaryMouseButton(ev) {
  1974. return ev.which == 1 && !ev.ctrlKey;
  1975. }
  1976. /* FullCalendar-specific Misc Utilities
  1977. ----------------------------------------------------------------------------------------------------------------------*/
  1978. // Creates a basic segment with the intersection of the two ranges. Returns undefined if no intersection.
  1979. // Expects all dates to be normalized to the same timezone beforehand.
  1980. function intersectionToSeg(subjectStart, subjectEnd, intervalStart, intervalEnd) {
  1981. var segStart, segEnd;
  1982. var isStart, isEnd;
  1983. if (subjectEnd > intervalStart && subjectStart < intervalEnd) { // in bounds at all?
  1984. if (subjectStart >= intervalStart) {
  1985. segStart = subjectStart.clone();
  1986. isStart = true;
  1987. }
  1988. else {
  1989. segStart = intervalStart.clone();
  1990. isStart = false;
  1991. }
  1992. if (subjectEnd <= intervalEnd) {
  1993. segEnd = subjectEnd.clone();
  1994. isEnd = true;
  1995. }
  1996. else {
  1997. segEnd = intervalEnd.clone();
  1998. isEnd = false;
  1999. }
  2000. return {
  2001. start: segStart,
  2002. end: segEnd,
  2003. isStart: isStart,
  2004. isEnd: isEnd
  2005. };
  2006. }
  2007. }
  2008. function smartProperty(obj, name) { // get a camel-cased/namespaced property of an object
  2009. obj = obj || {};
  2010. if (obj[name] !== undefined) {
  2011. return obj[name];
  2012. }
  2013. var parts = name.split(/(?=[A-Z])/),
  2014. i = parts.length - 1, res;
  2015. for (; i>=0; i--) {
  2016. res = obj[parts[i].toLowerCase()];
  2017. if (res !== undefined) {
  2018. return res;
  2019. }
  2020. }
  2021. return obj['default'];
  2022. }
  2023. /* Date Utilities
  2024. ----------------------------------------------------------------------------------------------------------------------*/
  2025. var dayIDs = [ 'sun', 'mon', 'tue', 'wed', 'thu', 'fri', 'sat' ];
  2026. // Diffs the two moments into a Duration where full-days are recorded first, then the remaining time.
  2027. // Moments will have their timezones normalized.
  2028. function dayishDiff(a, b) {
  2029. return moment.duration({
  2030. days: a.clone().stripTime().diff(b.clone().stripTime(), 'days'),
  2031. ms: a.time() - b.time()
  2032. });
  2033. }
  2034. function isNativeDate(input) {
  2035. return Object.prototype.toString.call(input) === '[object Date]' || input instanceof Date;
  2036. }
  2037. // Returns a boolean about whether the given input is a time string, like "06:40:00" or "06:00"
  2038. function isTimeString(str) {
  2039. return /^\d+\:\d+(?:\:\d+\.?(?:\d{3})?)?$/.test(str);
  2040. }
  2041. /* General Utilities
  2042. ----------------------------------------------------------------------------------------------------------------------*/
  2043. fc.applyAll = applyAll; // export
  2044. // Create an object that has the given prototype. Just like Object.create
  2045. function createObject(proto) {
  2046. var f = function() {};
  2047. f.prototype = proto;
  2048. return new f();
  2049. }
  2050. function applyAll(functions, thisObj, args) {
  2051. if ($.isFunction(functions)) {
  2052. functions = [ functions ];
  2053. }
  2054. if (functions) {
  2055. var i;
  2056. var ret;
  2057. for (i=0; i<functions.length; i++) {
  2058. ret = functions[i].apply(thisObj, args) || ret;
  2059. }
  2060. return ret;
  2061. }
  2062. }
  2063. function firstDefined() {
  2064. for (var i=0; i<arguments.length; i++) {
  2065. if (arguments[i] !== undefined) {
  2066. return arguments[i];
  2067. }
  2068. }
  2069. }
  2070. function htmlEscape(s) {
  2071. return (s + '').replace(/&/g, '&amp;')
  2072. .replace(/</g, '&lt;')
  2073. .replace(/>/g, '&gt;')
  2074. .replace(/'/g, '&#039;')
  2075. .replace(/"/g, '&quot;')
  2076. .replace(/\n/g, '<br />');
  2077. }
  2078. function stripHtmlEntities(text) {
  2079. return text.replace(/&.*?;/g, '');
  2080. }
  2081. function capitaliseFirstLetter(str) {
  2082. return str.charAt(0).toUpperCase() + str.slice(1);
  2083. }
  2084. function compareNumbers(a, b) { // for .sort()
  2085. return a - b;
  2086. }
  2087. // Returns a function, that, as long as it continues to be invoked, will not
  2088. // be triggered. The function will be called after it stops being called for
  2089. // N milliseconds.
  2090. // https://github.com/jashkenas/underscore/blob/1.6.0/underscore.js#L714
  2091. function debounce(func, wait) {
  2092. var timeoutId;
  2093. var args;
  2094. var context;
  2095. var timestamp; // of most recent call
  2096. var later = function() {
  2097. var last = +new Date() - timestamp;
  2098. if (last < wait && last > 0) {
  2099. timeoutId = setTimeout(later, wait - last);
  2100. }
  2101. else {
  2102. timeoutId = null;
  2103. func.apply(context, args);
  2104. if (!timeoutId) {
  2105. context = args = null;
  2106. }
  2107. }
  2108. };
  2109. return function() {
  2110. context = this;
  2111. args = arguments;
  2112. timestamp = +new Date();
  2113. if (!timeoutId) {
  2114. timeoutId = setTimeout(later, wait);
  2115. }
  2116. };
  2117. }
  2118. ;;
  2119. var ambigDateOfMonthRegex = /^\s*\d{4}-\d\d$/;
  2120. var ambigTimeOrZoneRegex =
  2121. /^\s*\d{4}-(?:(\d\d-\d\d)|(W\d\d$)|(W\d\d-\d)|(\d\d\d))((T| )(\d\d(:\d\d(:\d\d(\.\d+)?)?)?)?)?$/;
  2122. var newMomentProto = moment.fn; // where we will attach our new methods
  2123. var oldMomentProto = $.extend({}, newMomentProto); // copy of original moment methods
  2124. var allowValueOptimization;
  2125. var setUTCValues; // function defined below
  2126. var setLocalValues; // function defined below
  2127. // Creating
  2128. // -------------------------------------------------------------------------------------------------
  2129. // Creates a new moment, similar to the vanilla moment(...) constructor, but with
  2130. // extra features (ambiguous time, enhanced formatting). When given an existing moment,
  2131. // it will function as a clone (and retain the zone of the moment). Anything else will
  2132. // result in a moment in the local zone.
  2133. fc.moment = function() {
  2134. return makeMoment(arguments);
  2135. };
  2136. // Sames as fc.moment, but forces the resulting moment to be in the UTC timezone.
  2137. fc.moment.utc = function() {
  2138. var mom = makeMoment(arguments, true);
  2139. // Force it into UTC because makeMoment doesn't guarantee it
  2140. // (if given a pre-existing moment for example)
  2141. if (mom.hasTime()) { // don't give ambiguously-timed moments a UTC zone
  2142. mom.utc();
  2143. }
  2144. return mom;
  2145. };
  2146. // Same as fc.moment, but when given an ISO8601 string, the timezone offset is preserved.
  2147. // ISO8601 strings with no timezone offset will become ambiguously zoned.
  2148. fc.moment.parseZone = function() {
  2149. return makeMoment(arguments, true, true);
  2150. };
  2151. // Builds an enhanced moment from args. When given an existing moment, it clones. When given a
  2152. // native Date, or called with no arguments (the current time), the resulting moment will be local.
  2153. // Anything else needs to be "parsed" (a string or an array), and will be affected by:
  2154. // parseAsUTC - if there is no zone information, should we parse the input in UTC?
  2155. // parseZone - if there is zone information, should we force the zone of the moment?
  2156. function makeMoment(args, parseAsUTC, parseZone) {
  2157. var input = args[0];
  2158. var isSingleString = args.length == 1 && typeof input === 'string';
  2159. var isAmbigTime;
  2160. var isAmbigZone;
  2161. var ambigMatch;
  2162. var mom;
  2163. if (moment.isMoment(input)) {
  2164. mom = moment.apply(null, args); // clone it
  2165. transferAmbigs(input, mom); // the ambig flags weren't transfered with the clone
  2166. }
  2167. else if (isNativeDate(input) || input === undefined) {
  2168. mom = moment.apply(null, args); // will be local
  2169. }
  2170. else { // "parsing" is required
  2171. isAmbigTime = false;
  2172. isAmbigZone = false;
  2173. if (isSingleString) {
  2174. if (ambigDateOfMonthRegex.test(input)) {
  2175. // accept strings like '2014-05', but convert to the first of the month
  2176. input += '-01';
  2177. args = [ input ]; // for when we pass it on to moment's constructor
  2178. isAmbigTime = true;
  2179. isAmbigZone = true;
  2180. }
  2181. else if ((ambigMatch = ambigTimeOrZoneRegex.exec(input))) {
  2182. isAmbigTime = !ambigMatch[5]; // no time part?
  2183. isAmbigZone = true;
  2184. }
  2185. }
  2186. else if ($.isArray(input)) {
  2187. // arrays have no timezone information, so assume ambiguous zone
  2188. isAmbigZone = true;
  2189. }
  2190. // otherwise, probably a string with a format
  2191. if (parseAsUTC) {
  2192. mom = moment.utc.apply(moment, args);
  2193. }
  2194. else {
  2195. mom = moment.apply(null, args);
  2196. }
  2197. if (isAmbigTime) {
  2198. mom._ambigTime = true;
  2199. mom._ambigZone = true; // ambiguous time always means ambiguous zone
  2200. }
  2201. else if (parseZone) { // let's record the inputted zone somehow
  2202. if (isAmbigZone) {
  2203. mom._ambigZone = true;
  2204. }
  2205. else if (isSingleString) {
  2206. mom.zone(input); // if not a valid zone, will assign UTC
  2207. }
  2208. }
  2209. }
  2210. mom._fullCalendar = true; // flag for extended functionality
  2211. return mom;
  2212. }
  2213. // A clone method that works with the flags related to our enhanced functionality.
  2214. // In the future, use moment.momentProperties
  2215. newMomentProto.clone = function() {
  2216. var mom = oldMomentProto.clone.apply(this, arguments);
  2217. // these flags weren't transfered with the clone
  2218. transferAmbigs(this, mom);
  2219. if (this._fullCalendar) {
  2220. mom._fullCalendar = true;
  2221. }
  2222. return mom;
  2223. };
  2224. // Time-of-day
  2225. // -------------------------------------------------------------------------------------------------
  2226. // GETTER
  2227. // Returns a Duration with the hours/minutes/seconds/ms values of the moment.
  2228. // If the moment has an ambiguous time, a duration of 00:00 will be returned.
  2229. //
  2230. // SETTER
  2231. // You can supply a Duration, a Moment, or a Duration-like argument.
  2232. // When setting the time, and the moment has an ambiguous time, it then becomes unambiguous.
  2233. newMomentProto.time = function(time) {
  2234. // Fallback to the original method (if there is one) if this moment wasn't created via FullCalendar.
  2235. // `time` is a generic enough method name where this precaution is necessary to avoid collisions w/ other plugins.
  2236. if (!this._fullCalendar) {
  2237. return oldMomentProto.time.apply(this, arguments);
  2238. }
  2239. if (time == null) { // getter
  2240. return moment.duration({
  2241. hours: this.hours(),
  2242. minutes: this.minutes(),
  2243. seconds: this.seconds(),
  2244. milliseconds: this.milliseconds()
  2245. });
  2246. }
  2247. else { // setter
  2248. this._ambigTime = false; // mark that the moment now has a time
  2249. if (!moment.isDuration(time) && !moment.isMoment(time)) {
  2250. time = moment.duration(time);
  2251. }
  2252. // The day value should cause overflow (so 24 hours becomes 00:00:00 of next day).
  2253. // Only for Duration times, not Moment times.
  2254. var dayHours = 0;
  2255. if (moment.isDuration(time)) {
  2256. dayHours = Math.floor(time.asDays()) * 24;
  2257. }
  2258. // We need to set the individual fields.
  2259. // Can't use startOf('day') then add duration. In case of DST at start of day.
  2260. return this.hours(dayHours + time.hours())
  2261. .minutes(time.minutes())
  2262. .seconds(time.seconds())
  2263. .milliseconds(time.milliseconds());
  2264. }
  2265. };
  2266. // Converts the moment to UTC, stripping out its time-of-day and timezone offset,
  2267. // but preserving its YMD. A moment with a stripped time will display no time
  2268. // nor timezone offset when .format() is called.
  2269. newMomentProto.stripTime = function() {
  2270. var a = this.toArray(); // year,month,date,hours,minutes,seconds as an array
  2271. this.utc(); // set the internal UTC flag (will clear the ambig flags)
  2272. setUTCValues(this, a.slice(0, 3)); // set the year/month/date. time will be zero
  2273. // Mark the time as ambiguous. This needs to happen after the .utc() call, which calls .zone(),
  2274. // which clears all ambig flags. Same with setUTCValues with moment-timezone.
  2275. this._ambigTime = true;
  2276. this._ambigZone = true; // if ambiguous time, also ambiguous timezone offset
  2277. return this; // for chaining
  2278. };
  2279. // Returns if the moment has a non-ambiguous time (boolean)
  2280. newMomentProto.hasTime = function() {
  2281. return !this._ambigTime;
  2282. };
  2283. // Timezone
  2284. // -------------------------------------------------------------------------------------------------
  2285. // Converts the moment to UTC, stripping out its timezone offset, but preserving its
  2286. // YMD and time-of-day. A moment with a stripped timezone offset will display no
  2287. // timezone offset when .format() is called.
  2288. newMomentProto.stripZone = function() {
  2289. var a = this.toArray(); // year,month,date,hours,minutes,seconds as an array
  2290. var wasAmbigTime = this._ambigTime;
  2291. this.utc(); // set the internal UTC flag (will clear the ambig flags)
  2292. setUTCValues(this, a); // will set the year/month/date/hours/minutes/seconds/ms
  2293. if (wasAmbigTime) {
  2294. // the above call to .utc()/.zone() unfortunately clears the ambig flags, so reassign
  2295. this._ambigTime = true;
  2296. }
  2297. // Mark the zone as ambiguous. This needs to happen after the .utc() call, which calls .zone(),
  2298. // which clears all ambig flags. Same with setUTCValues with moment-timezone.
  2299. this._ambigZone = true;
  2300. return this; // for chaining
  2301. };
  2302. // Returns of the moment has a non-ambiguous timezone offset (boolean)
  2303. newMomentProto.hasZone = function() {
  2304. return !this._ambigZone;
  2305. };
  2306. // this method implicitly marks a zone (will get called upon .utc() and .local())
  2307. newMomentProto.zone = function(tzo) {
  2308. if (tzo != null) { // setter
  2309. // these assignments needs to happen before the original zone method is called.
  2310. // I forget why, something to do with a browser crash.
  2311. this._ambigTime = false;
  2312. this._ambigZone = false;
  2313. }
  2314. return oldMomentProto.zone.apply(this, arguments);
  2315. };
  2316. // this method implicitly marks a zone
  2317. newMomentProto.local = function() {
  2318. var a = this.toArray(); // year,month,date,hours,minutes,seconds,ms as an array
  2319. var wasAmbigZone = this._ambigZone;
  2320. oldMomentProto.local.apply(this, arguments); // will clear ambig flags
  2321. if (wasAmbigZone) {
  2322. // If the moment was ambiguously zoned, the date fields were stored as UTC.
  2323. // We want to preserve these, but in local time.
  2324. setLocalValues(this, a);
  2325. }
  2326. return this; // for chaining
  2327. };
  2328. // Formatting
  2329. // -------------------------------------------------------------------------------------------------
  2330. newMomentProto.format = function() {
  2331. if (this._fullCalendar && arguments[0]) { // an enhanced moment? and a format string provided?
  2332. return formatDate(this, arguments[0]); // our extended formatting
  2333. }
  2334. if (this._ambigTime) {
  2335. return oldMomentFormat(this, 'YYYY-MM-DD');
  2336. }
  2337. if (this._ambigZone) {
  2338. return oldMomentFormat(this, 'YYYY-MM-DD[T]HH:mm:ss');
  2339. }
  2340. return oldMomentProto.format.apply(this, arguments);
  2341. };
  2342. newMomentProto.toISOString = function() {
  2343. if (this._ambigTime) {
  2344. return oldMomentFormat(this, 'YYYY-MM-DD');
  2345. }
  2346. if (this._ambigZone) {
  2347. return oldMomentFormat(this, 'YYYY-MM-DD[T]HH:mm:ss');
  2348. }
  2349. return oldMomentProto.toISOString.apply(this, arguments);
  2350. };
  2351. // Querying
  2352. // -------------------------------------------------------------------------------------------------
  2353. // Is the moment within the specified range? `end` is exclusive.
  2354. // FYI, this method is not a standard Moment method, so always do our enhanced logic.
  2355. newMomentProto.isWithin = function(start, end) {
  2356. var a = commonlyAmbiguate([ this, start, end ]);
  2357. return a[0] >= a[1] && a[0] < a[2];
  2358. };
  2359. // When isSame is called with units, timezone ambiguity is normalized before the comparison happens.
  2360. // If no units specified, the two moments must be identically the same, with matching ambig flags.
  2361. newMomentProto.isSame = function(input, units) {
  2362. var a;
  2363. // only do custom logic if this is an enhanced moment
  2364. if (!this._fullCalendar) {
  2365. return oldMomentProto.isSame.apply(this, arguments);
  2366. }
  2367. if (units) {
  2368. a = commonlyAmbiguate([ this, input ], true); // normalize timezones but don't erase times
  2369. return oldMomentProto.isSame.call(a[0], a[1], units);
  2370. }
  2371. else {
  2372. input = fc.moment.parseZone(input); // normalize input
  2373. return oldMomentProto.isSame.call(this, input) &&
  2374. Boolean(this._ambigTime) === Boolean(input._ambigTime) &&
  2375. Boolean(this._ambigZone) === Boolean(input._ambigZone);
  2376. }
  2377. };
  2378. // Make these query methods work with ambiguous moments
  2379. $.each([
  2380. 'isBefore',
  2381. 'isAfter'
  2382. ], function(i, methodName) {
  2383. newMomentProto[methodName] = function(input, units) {
  2384. var a;
  2385. // only do custom logic if this is an enhanced moment
  2386. if (!this._fullCalendar) {
  2387. return oldMomentProto[methodName].apply(this, arguments);
  2388. }
  2389. a = commonlyAmbiguate([ this, input ]);
  2390. return oldMomentProto[methodName].call(a[0], a[1], units);
  2391. };
  2392. });
  2393. // Misc Internals
  2394. // -------------------------------------------------------------------------------------------------
  2395. // given an array of moment-like inputs, return a parallel array w/ moments similarly ambiguated.
  2396. // for example, of one moment has ambig time, but not others, all moments will have their time stripped.
  2397. // set `preserveTime` to `true` to keep times, but only normalize zone ambiguity.
  2398. function commonlyAmbiguate(inputs, preserveTime) {
  2399. var outputs = [];
  2400. var anyAmbigTime = false;
  2401. var anyAmbigZone = false;
  2402. var i;
  2403. for (i=0; i<inputs.length; i++) {
  2404. outputs.push(fc.moment.parseZone(inputs[i]));
  2405. anyAmbigTime = anyAmbigTime || outputs[i]._ambigTime;
  2406. anyAmbigZone = anyAmbigZone || outputs[i]._ambigZone;
  2407. }
  2408. for (i=0; i<outputs.length; i++) {
  2409. if (anyAmbigTime && !preserveTime) {
  2410. outputs[i].stripTime();
  2411. }
  2412. else if (anyAmbigZone) {
  2413. outputs[i].stripZone();
  2414. }
  2415. }
  2416. return outputs;
  2417. }
  2418. // Transfers all the flags related to ambiguous time/zone from the `src` moment to the `dest` moment
  2419. function transferAmbigs(src, dest) {
  2420. if (src._ambigTime) {
  2421. dest._ambigTime = true;
  2422. }
  2423. else if (dest._ambigTime) {
  2424. dest._ambigTime = false;
  2425. }
  2426. if (src._ambigZone) {
  2427. dest._ambigZone = true;
  2428. }
  2429. else if (dest._ambigZone) {
  2430. dest._ambigZone = false;
  2431. }
  2432. }
  2433. // Sets the year/month/date/etc values of the moment from the given array.
  2434. // Inefficient because it calls each individual setter.
  2435. function setMomentValues(mom, a) {
  2436. mom.year(a[0] || 0)
  2437. .month(a[1] || 0)
  2438. .date(a[2] || 0)
  2439. .hours(a[3] || 0)
  2440. .minutes(a[4] || 0)
  2441. .seconds(a[5] || 0)
  2442. .milliseconds(a[6] || 0);
  2443. }
  2444. // Can we set the moment's internal date directly?
  2445. allowValueOptimization = '_d' in moment() && 'updateOffset' in moment;
  2446. // Utility function. Accepts a moment and an array of the UTC year/month/date/etc values to set.
  2447. // Assumes the given moment is already in UTC mode.
  2448. setUTCValues = allowValueOptimization ? function(mom, a) {
  2449. // simlate what moment's accessors do
  2450. mom._d.setTime(Date.UTC.apply(Date, a));
  2451. moment.updateOffset(mom, false); // keepTime=false
  2452. } : setMomentValues;
  2453. // Utility function. Accepts a moment and an array of the local year/month/date/etc values to set.
  2454. // Assumes the given moment is already in local mode.
  2455. setLocalValues = allowValueOptimization ? function(mom, a) {
  2456. // simlate what moment's accessors do
  2457. mom._d.setTime(+new Date( // FYI, there is now way to apply an array of args to a constructor
  2458. a[0] || 0,
  2459. a[1] || 0,
  2460. a[2] || 0,
  2461. a[3] || 0,
  2462. a[4] || 0,
  2463. a[5] || 0,
  2464. a[6] || 0
  2465. ));
  2466. moment.updateOffset(mom, false); // keepTime=false
  2467. } : setMomentValues;
  2468. ;;
  2469. // Single Date Formatting
  2470. // -------------------------------------------------------------------------------------------------
  2471. // call this if you want Moment's original format method to be used
  2472. function oldMomentFormat(mom, formatStr) {
  2473. return oldMomentProto.format.call(mom, formatStr); // oldMomentProto defined in moment-ext.js
  2474. }
  2475. // Formats `date` with a Moment formatting string, but allow our non-zero areas and
  2476. // additional token.
  2477. function formatDate(date, formatStr) {
  2478. return formatDateWithChunks(date, getFormatStringChunks(formatStr));
  2479. }
  2480. function formatDateWithChunks(date, chunks) {
  2481. var s = '';
  2482. var i;
  2483. for (i=0; i<chunks.length; i++) {
  2484. s += formatDateWithChunk(date, chunks[i]);
  2485. }
  2486. return s;
  2487. }
  2488. // addition formatting tokens we want recognized
  2489. var tokenOverrides = {
  2490. t: function(date) { // "a" or "p"
  2491. return oldMomentFormat(date, 'a').charAt(0);
  2492. },
  2493. T: function(date) { // "A" or "P"
  2494. return oldMomentFormat(date, 'A').charAt(0);
  2495. }
  2496. };
  2497. function formatDateWithChunk(date, chunk) {
  2498. var token;
  2499. var maybeStr;
  2500. if (typeof chunk === 'string') { // a literal string
  2501. return chunk;
  2502. }
  2503. else if ((token = chunk.token)) { // a token, like "YYYY"
  2504. if (tokenOverrides[token]) {
  2505. return tokenOverrides[token](date); // use our custom token
  2506. }
  2507. return oldMomentFormat(date, token);
  2508. }
  2509. else if (chunk.maybe) { // a grouping of other chunks that must be non-zero
  2510. maybeStr = formatDateWithChunks(date, chunk.maybe);
  2511. if (maybeStr.match(/[1-9]/)) {
  2512. return maybeStr;
  2513. }
  2514. }
  2515. return '';
  2516. }
  2517. // Date Range Formatting
  2518. // -------------------------------------------------------------------------------------------------
  2519. // TODO: make it work with timezone offset
  2520. // Using a formatting string meant for a single date, generate a range string, like
  2521. // "Sep 2 - 9 2013", that intelligently inserts a separator where the dates differ.
  2522. // If the dates are the same as far as the format string is concerned, just return a single
  2523. // rendering of one date, without any separator.
  2524. function formatRange(date1, date2, formatStr, separator, isRTL) {
  2525. var localeData;
  2526. date1 = fc.moment.parseZone(date1);
  2527. date2 = fc.moment.parseZone(date2);
  2528. localeData = (date1.localeData || date1.lang).call(date1); // works with moment-pre-2.8
  2529. // Expand localized format strings, like "LL" -> "MMMM D YYYY"
  2530. formatStr = localeData.longDateFormat(formatStr) || formatStr;
  2531. // BTW, this is not important for `formatDate` because it is impossible to put custom tokens
  2532. // or non-zero areas in Moment's localized format strings.
  2533. separator = separator || ' - ';
  2534. return formatRangeWithChunks(
  2535. date1,
  2536. date2,
  2537. getFormatStringChunks(formatStr),
  2538. separator,
  2539. isRTL
  2540. );
  2541. }
  2542. fc.formatRange = formatRange; // expose
  2543. function formatRangeWithChunks(date1, date2, chunks, separator, isRTL) {
  2544. var chunkStr; // the rendering of the chunk
  2545. var leftI;
  2546. var leftStr = '';
  2547. var rightI;
  2548. var rightStr = '';
  2549. var middleI;
  2550. var middleStr1 = '';
  2551. var middleStr2 = '';
  2552. var middleStr = '';
  2553. // Start at the leftmost side of the formatting string and continue until you hit a token
  2554. // that is not the same between dates.
  2555. for (leftI=0; leftI<chunks.length; leftI++) {
  2556. chunkStr = formatSimilarChunk(date1, date2, chunks[leftI]);
  2557. if (chunkStr === false) {
  2558. break;
  2559. }
  2560. leftStr += chunkStr;
  2561. }
  2562. // Similarly, start at the rightmost side of the formatting string and move left
  2563. for (rightI=chunks.length-1; rightI>leftI; rightI--) {
  2564. chunkStr = formatSimilarChunk(date1, date2, chunks[rightI]);
  2565. if (chunkStr === false) {
  2566. break;
  2567. }
  2568. rightStr = chunkStr + rightStr;
  2569. }
  2570. // The area in the middle is different for both of the dates.
  2571. // Collect them distinctly so we can jam them together later.
  2572. for (middleI=leftI; middleI<=rightI; middleI++) {
  2573. middleStr1 += formatDateWithChunk(date1, chunks[middleI]);
  2574. middleStr2 += formatDateWithChunk(date2, chunks[middleI]);
  2575. }
  2576. if (middleStr1 || middleStr2) {
  2577. if (isRTL) {
  2578. middleStr = middleStr2 + separator + middleStr1;
  2579. }
  2580. else {
  2581. middleStr = middleStr1 + separator + middleStr2;
  2582. }
  2583. }
  2584. return leftStr + middleStr + rightStr;
  2585. }
  2586. var similarUnitMap = {
  2587. Y: 'year',
  2588. M: 'month',
  2589. D: 'day', // day of month
  2590. d: 'day', // day of week
  2591. // prevents a separator between anything time-related...
  2592. A: 'second', // AM/PM
  2593. a: 'second', // am/pm
  2594. T: 'second', // A/P
  2595. t: 'second', // a/p
  2596. H: 'second', // hour (24)
  2597. h: 'second', // hour (12)
  2598. m: 'second', // minute
  2599. s: 'second' // second
  2600. };
  2601. // TODO: week maybe?
  2602. // Given a formatting chunk, and given that both dates are similar in the regard the
  2603. // formatting chunk is concerned, format date1 against `chunk`. Otherwise, return `false`.
  2604. function formatSimilarChunk(date1, date2, chunk) {
  2605. var token;
  2606. var unit;
  2607. if (typeof chunk === 'string') { // a literal string
  2608. return chunk;
  2609. }
  2610. else if ((token = chunk.token)) {
  2611. unit = similarUnitMap[token.charAt(0)];
  2612. // are the dates the same for this unit of measurement?
  2613. if (unit && date1.isSame(date2, unit)) {
  2614. return oldMomentFormat(date1, token); // would be the same if we used `date2`
  2615. // BTW, don't support custom tokens
  2616. }
  2617. }
  2618. return false; // the chunk is NOT the same for the two dates
  2619. // BTW, don't support splitting on non-zero areas
  2620. }
  2621. // Chunking Utils
  2622. // -------------------------------------------------------------------------------------------------
  2623. var formatStringChunkCache = {};
  2624. function getFormatStringChunks(formatStr) {
  2625. if (formatStr in formatStringChunkCache) {
  2626. return formatStringChunkCache[formatStr];
  2627. }
  2628. return (formatStringChunkCache[formatStr] = chunkFormatString(formatStr));
  2629. }
  2630. // Break the formatting string into an array of chunks
  2631. function chunkFormatString(formatStr) {
  2632. var chunks = [];
  2633. var chunker = /\[([^\]]*)\]|\(([^\)]*)\)|(LT|(\w)\4*o?)|([^\w\[\(]+)/g; // TODO: more descrimination
  2634. var match;
  2635. while ((match = chunker.exec(formatStr))) {
  2636. if (match[1]) { // a literal string inside [ ... ]
  2637. chunks.push(match[1]);
  2638. }
  2639. else if (match[2]) { // non-zero formatting inside ( ... )
  2640. chunks.push({ maybe: chunkFormatString(match[2]) });
  2641. }
  2642. else if (match[3]) { // a formatting token
  2643. chunks.push({ token: match[3] });
  2644. }
  2645. else if (match[5]) { // an unenclosed literal string
  2646. chunks.push(match[5]);
  2647. }
  2648. }
  2649. return chunks;
  2650. }
  2651. ;;
  2652. /* A rectangular panel that is absolutely positioned over other content
  2653. ------------------------------------------------------------------------------------------------------------------------
  2654. Options:
  2655. - className (string)
  2656. - content (HTML string or jQuery element set)
  2657. - parentEl
  2658. - top
  2659. - left
  2660. - right (the x coord of where the right edge should be. not a "CSS" right)
  2661. - autoHide (boolean)
  2662. - show (callback)
  2663. - hide (callback)
  2664. */
  2665. function Popover(options) {
  2666. this.options = options || {};
  2667. }
  2668. Popover.prototype = {
  2669. isHidden: true,
  2670. options: null,
  2671. el: null, // the container element for the popover. generated by this object
  2672. documentMousedownProxy: null, // document mousedown handler bound to `this`
  2673. margin: 10, // the space required between the popover and the edges of the scroll container
  2674. // Shows the popover on the specified position. Renders it if not already
  2675. show: function() {
  2676. if (this.isHidden) {
  2677. if (!this.el) {
  2678. this.render();
  2679. }
  2680. this.el.show();
  2681. this.position();
  2682. this.isHidden = false;
  2683. this.trigger('show');
  2684. }
  2685. },
  2686. // Hides the popover, through CSS, but does not remove it from the DOM
  2687. hide: function() {
  2688. if (!this.isHidden) {
  2689. this.el.hide();
  2690. this.isHidden = true;
  2691. this.trigger('hide');
  2692. }
  2693. },
  2694. // Creates `this.el` and renders content inside of it
  2695. render: function() {
  2696. var _this = this;
  2697. var options = this.options;
  2698. this.el = $('<div class="fc-popover"/>')
  2699. .addClass(options.className || '')
  2700. .css({
  2701. // position initially to the top left to avoid creating scrollbars
  2702. top: 0,
  2703. left: 0
  2704. })
  2705. .append(options.content)
  2706. .appendTo(options.parentEl);
  2707. // when a click happens on anything inside with a 'fc-close' className, hide the popover
  2708. this.el.on('click', '.fc-close', function() {
  2709. _this.hide();
  2710. });
  2711. if (options.autoHide) {
  2712. $(document).on('mousedown', this.documentMousedownProxy = $.proxy(this, 'documentMousedown'));
  2713. }
  2714. },
  2715. // Triggered when the user clicks *anywhere* in the document, for the autoHide feature
  2716. documentMousedown: function(ev) {
  2717. // only hide the popover if the click happened outside the popover
  2718. if (this.el && !$(ev.target).closest(this.el).length) {
  2719. this.hide();
  2720. }
  2721. },
  2722. // Hides and unregisters any handlers
  2723. destroy: function() {
  2724. this.hide();
  2725. if (this.el) {
  2726. this.el.remove();
  2727. this.el = null;
  2728. }
  2729. $(document).off('mousedown', this.documentMousedownProxy);
  2730. },
  2731. // Positions the popover optimally, using the top/left/right options
  2732. position: function() {
  2733. var options = this.options;
  2734. var origin = this.el.offsetParent().offset();
  2735. var width = this.el.outerWidth();
  2736. var height = this.el.outerHeight();
  2737. var windowEl = $(window);
  2738. var viewportEl = getScrollParent(this.el);
  2739. var viewportTop;
  2740. var viewportLeft;
  2741. var viewportOffset;
  2742. var top; // the "position" (not "offset") values for the popover
  2743. var left; //
  2744. // compute top and left
  2745. top = options.top || 0;
  2746. if (options.left !== undefined) {
  2747. left = options.left;
  2748. }
  2749. else if (options.right !== undefined) {
  2750. left = options.right - width; // derive the left value from the right value
  2751. }
  2752. else {
  2753. left = 0;
  2754. }
  2755. if (viewportEl.is(window) || viewportEl.is(document)) { // normalize getScrollParent's result
  2756. viewportEl = windowEl;
  2757. viewportTop = 0; // the window is always at the top left
  2758. viewportLeft = 0; // (and .offset() won't work if called here)
  2759. }
  2760. else {
  2761. viewportOffset = viewportEl.offset();
  2762. viewportTop = viewportOffset.top;
  2763. viewportLeft = viewportOffset.left;
  2764. }
  2765. // if the window is scrolled, it causes the visible area to be further down
  2766. viewportTop += windowEl.scrollTop();
  2767. viewportLeft += windowEl.scrollLeft();
  2768. // constrain to the view port. if constrained by two edges, give precedence to top/left
  2769. if (options.viewportConstrain !== false) {
  2770. top = Math.min(top, viewportTop + viewportEl.outerHeight() - height - this.margin);
  2771. top = Math.max(top, viewportTop + this.margin);
  2772. left = Math.min(left, viewportLeft + viewportEl.outerWidth() - width - this.margin);
  2773. left = Math.max(left, viewportLeft + this.margin);
  2774. }
  2775. this.el.css({
  2776. top: top - origin.top,
  2777. left: left - origin.left
  2778. });
  2779. },
  2780. // Triggers a callback. Calls a function in the option hash of the same name.
  2781. // Arguments beyond the first `name` are forwarded on.
  2782. // TODO: better code reuse for this. Repeat code
  2783. trigger: function(name) {
  2784. if (this.options[name]) {
  2785. this.options[name].apply(this, Array.prototype.slice.call(arguments, 1));
  2786. }
  2787. }
  2788. };
  2789. ;;
  2790. /* A "coordinate map" converts pixel coordinates into an associated cell, which has an associated date
  2791. ------------------------------------------------------------------------------------------------------------------------
  2792. Common interface:
  2793. CoordMap.prototype = {
  2794. build: function() {},
  2795. getCell: function(x, y) {}
  2796. };
  2797. */
  2798. /* Coordinate map for a grid component
  2799. ----------------------------------------------------------------------------------------------------------------------*/
  2800. function GridCoordMap(grid) {
  2801. this.grid = grid;
  2802. }
  2803. GridCoordMap.prototype = {
  2804. grid: null, // reference to the Grid
  2805. rows: null, // the top-to-bottom y coordinates. including the bottom of the last item
  2806. cols: null, // the left-to-right x coordinates. including the right of the last item
  2807. containerEl: null, // container element that all coordinates are constrained to. optionally assigned
  2808. minX: null,
  2809. maxX: null, // exclusive
  2810. minY: null,
  2811. maxY: null, // exclusive
  2812. // Queries the grid for the coordinates of all the cells
  2813. build: function() {
  2814. this.grid.buildCoords(
  2815. this.rows = [],
  2816. this.cols = []
  2817. );
  2818. this.computeBounds();
  2819. },
  2820. // Given a coordinate of the document, gets the associated cell. If no cell is underneath, returns null
  2821. getCell: function(x, y) {
  2822. var cell = null;
  2823. var rows = this.rows;
  2824. var cols = this.cols;
  2825. var r = -1;
  2826. var c = -1;
  2827. var i;
  2828. if (this.inBounds(x, y)) {
  2829. for (i = 0; i < rows.length; i++) {
  2830. if (y >= rows[i][0] && y < rows[i][1]) {
  2831. r = i;
  2832. break;
  2833. }
  2834. }
  2835. for (i = 0; i < cols.length; i++) {
  2836. if (x >= cols[i][0] && x < cols[i][1]) {
  2837. c = i;
  2838. break;
  2839. }
  2840. }
  2841. if (r >= 0 && c >= 0) {
  2842. cell = { row: r, col: c };
  2843. cell.grid = this.grid;
  2844. cell.date = this.grid.getCellDate(cell);
  2845. }
  2846. }
  2847. return cell;
  2848. },
  2849. // If there is a containerEl, compute the bounds into min/max values
  2850. computeBounds: function() {
  2851. var containerOffset;
  2852. if (this.containerEl) {
  2853. containerOffset = this.containerEl.offset();
  2854. this.minX = containerOffset.left;
  2855. this.maxX = containerOffset.left + this.containerEl.outerWidth();
  2856. this.minY = containerOffset.top;
  2857. this.maxY = containerOffset.top + this.containerEl.outerHeight();
  2858. }
  2859. },
  2860. // Determines if the given coordinates are in bounds. If no `containerEl`, always true
  2861. inBounds: function(x, y) {
  2862. if (this.containerEl) {
  2863. return x >= this.minX && x < this.maxX && y >= this.minY && y < this.maxY;
  2864. }
  2865. return true;
  2866. }
  2867. };
  2868. /* Coordinate map that is a combination of multiple other coordinate maps
  2869. ----------------------------------------------------------------------------------------------------------------------*/
  2870. function ComboCoordMap(coordMaps) {
  2871. this.coordMaps = coordMaps;
  2872. }
  2873. ComboCoordMap.prototype = {
  2874. coordMaps: null, // an array of CoordMaps
  2875. // Builds all coordMaps
  2876. build: function() {
  2877. var coordMaps = this.coordMaps;
  2878. var i;
  2879. for (i = 0; i < coordMaps.length; i++) {
  2880. coordMaps[i].build();
  2881. }
  2882. },
  2883. // Queries all coordMaps for the cell underneath the given coordinates, returning the first result
  2884. getCell: function(x, y) {
  2885. var coordMaps = this.coordMaps;
  2886. var cell = null;
  2887. var i;
  2888. for (i = 0; i < coordMaps.length && !cell; i++) {
  2889. cell = coordMaps[i].getCell(x, y);
  2890. }
  2891. return cell;
  2892. }
  2893. };
  2894. ;;
  2895. /* Tracks mouse movements over a CoordMap and raises events about which cell the mouse is over.
  2896. ----------------------------------------------------------------------------------------------------------------------*/
  2897. // TODO: very useful to have a handler that gets called upon cellOut OR when dragging stops (for cleanup)
  2898. function DragListener(coordMap, options) {
  2899. this.coordMap = coordMap;
  2900. this.options = options || {};
  2901. }
  2902. DragListener.prototype = {
  2903. coordMap: null,
  2904. options: null,
  2905. isListening: false,
  2906. isDragging: false,
  2907. // the cell/date the mouse was over when listening started
  2908. origCell: null,
  2909. origDate: null,
  2910. // the cell/date the mouse is over
  2911. cell: null,
  2912. date: null,
  2913. // coordinates of the initial mousedown
  2914. mouseX0: null,
  2915. mouseY0: null,
  2916. // handler attached to the document, bound to the DragListener's `this`
  2917. mousemoveProxy: null,
  2918. mouseupProxy: null,
  2919. scrollEl: null,
  2920. scrollBounds: null, // { top, bottom, left, right }
  2921. scrollTopVel: null, // pixels per second
  2922. scrollLeftVel: null, // pixels per second
  2923. scrollIntervalId: null, // ID of setTimeout for scrolling animation loop
  2924. scrollHandlerProxy: null, // this-scoped function for handling when scrollEl is scrolled
  2925. scrollSensitivity: 30, // pixels from edge for scrolling to start
  2926. scrollSpeed: 200, // pixels per second, at maximum speed
  2927. scrollIntervalMs: 50, // millisecond wait between scroll increment
  2928. // Call this when the user does a mousedown. Will probably lead to startListening
  2929. mousedown: function(ev) {
  2930. if (isPrimaryMouseButton(ev)) {
  2931. ev.preventDefault(); // prevents native selection in most browsers
  2932. this.startListening(ev);
  2933. // start the drag immediately if there is no minimum distance for a drag start
  2934. if (!this.options.distance) {
  2935. this.startDrag(ev);
  2936. }
  2937. }
  2938. },
  2939. // Call this to start tracking mouse movements
  2940. startListening: function(ev) {
  2941. var scrollParent;
  2942. var cell;
  2943. if (!this.isListening) {
  2944. // grab scroll container and attach handler
  2945. if (ev && this.options.scroll) {
  2946. scrollParent = getScrollParent($(ev.target));
  2947. if (!scrollParent.is(window) && !scrollParent.is(document)) {
  2948. this.scrollEl = scrollParent;
  2949. // scope to `this`, and use `debounce` to make sure rapid calls don't happen
  2950. this.scrollHandlerProxy = debounce($.proxy(this, 'scrollHandler'), 100);
  2951. this.scrollEl.on('scroll', this.scrollHandlerProxy);
  2952. }
  2953. }
  2954. this.computeCoords(); // relies on `scrollEl`
  2955. // get info on the initial cell, date, and coordinates
  2956. if (ev) {
  2957. cell = this.getCell(ev);
  2958. this.origCell = cell;
  2959. this.origDate = cell ? cell.date : null;
  2960. this.mouseX0 = ev.pageX;
  2961. this.mouseY0 = ev.pageY;
  2962. }
  2963. $(document)
  2964. .on('mousemove', this.mousemoveProxy = $.proxy(this, 'mousemove'))
  2965. .on('mouseup', this.mouseupProxy = $.proxy(this, 'mouseup'))
  2966. .on('selectstart', this.preventDefault); // prevents native selection in IE<=8
  2967. this.isListening = true;
  2968. this.trigger('listenStart', ev);
  2969. }
  2970. },
  2971. // Recomputes the drag-critical positions of elements
  2972. computeCoords: function() {
  2973. this.coordMap.build();
  2974. this.computeScrollBounds();
  2975. },
  2976. // Called when the user moves the mouse
  2977. mousemove: function(ev) {
  2978. var minDistance;
  2979. var distanceSq; // current distance from mouseX0/mouseY0, squared
  2980. if (!this.isDragging) { // if not already dragging...
  2981. // then start the drag if the minimum distance criteria is met
  2982. minDistance = this.options.distance || 1;
  2983. distanceSq = Math.pow(ev.pageX - this.mouseX0, 2) + Math.pow(ev.pageY - this.mouseY0, 2);
  2984. if (distanceSq >= minDistance * minDistance) { // use pythagorean theorem
  2985. this.startDrag(ev);
  2986. }
  2987. }
  2988. if (this.isDragging) {
  2989. this.drag(ev); // report a drag, even if this mousemove initiated the drag
  2990. }
  2991. },
  2992. // Call this to initiate a legitimate drag.
  2993. // This function is called internally from this class, but can also be called explicitly from outside
  2994. startDrag: function(ev) {
  2995. var cell;
  2996. if (!this.isListening) { // startDrag must have manually initiated
  2997. this.startListening();
  2998. }
  2999. if (!this.isDragging) {
  3000. this.isDragging = true;
  3001. this.trigger('dragStart', ev);
  3002. // report the initial cell the mouse is over
  3003. cell = this.getCell(ev);
  3004. if (cell) {
  3005. this.cellOver(cell, true);
  3006. }
  3007. }
  3008. },
  3009. // Called while the mouse is being moved and when we know a legitimate drag is taking place
  3010. drag: function(ev) {
  3011. var cell;
  3012. if (this.isDragging) {
  3013. cell = this.getCell(ev);
  3014. if (!isCellsEqual(cell, this.cell)) { // a different cell than before?
  3015. if (this.cell) {
  3016. this.cellOut();
  3017. }
  3018. if (cell) {
  3019. this.cellOver(cell);
  3020. }
  3021. }
  3022. this.dragScroll(ev); // will possibly cause scrolling
  3023. }
  3024. },
  3025. // Called when a the mouse has just moved over a new cell
  3026. cellOver: function(cell) {
  3027. this.cell = cell;
  3028. this.date = cell.date;
  3029. this.trigger('cellOver', cell, cell.date);
  3030. },
  3031. // Called when the mouse has just moved out of a cell
  3032. cellOut: function() {
  3033. if (this.cell) {
  3034. this.trigger('cellOut', this.cell);
  3035. this.cell = null;
  3036. this.date = null;
  3037. }
  3038. },
  3039. // Called when the user does a mouseup
  3040. mouseup: function(ev) {
  3041. this.stopDrag(ev);
  3042. this.stopListening(ev);
  3043. },
  3044. // Called when the drag is over. Will not cause listening to stop however.
  3045. // A concluding 'cellOut' event will NOT be triggered.
  3046. stopDrag: function(ev) {
  3047. if (this.isDragging) {
  3048. this.stopScrolling();
  3049. this.trigger('dragStop', ev);
  3050. this.isDragging = false;
  3051. }
  3052. },
  3053. // Call this to stop listening to the user's mouse events
  3054. stopListening: function(ev) {
  3055. if (this.isListening) {
  3056. // remove the scroll handler if there is a scrollEl
  3057. if (this.scrollEl) {
  3058. this.scrollEl.off('scroll', this.scrollHandlerProxy);
  3059. this.scrollHandlerProxy = null;
  3060. }
  3061. $(document)
  3062. .off('mousemove', this.mousemoveProxy)
  3063. .off('mouseup', this.mouseupProxy)
  3064. .off('selectstart', this.preventDefault);
  3065. this.mousemoveProxy = null;
  3066. this.mouseupProxy = null;
  3067. this.isListening = false;
  3068. this.trigger('listenStop', ev);
  3069. this.origCell = this.cell = null;
  3070. this.origDate = this.date = null;
  3071. }
  3072. },
  3073. // Gets the cell underneath the coordinates for the given mouse event
  3074. getCell: function(ev) {
  3075. return this.coordMap.getCell(ev.pageX, ev.pageY);
  3076. },
  3077. // Triggers a callback. Calls a function in the option hash of the same name.
  3078. // Arguments beyond the first `name` are forwarded on.
  3079. trigger: function(name) {
  3080. if (this.options[name]) {
  3081. this.options[name].apply(this, Array.prototype.slice.call(arguments, 1));
  3082. }
  3083. },
  3084. // Stops a given mouse event from doing it's native browser action. In our case, text selection.
  3085. preventDefault: function(ev) {
  3086. ev.preventDefault();
  3087. },
  3088. /* Scrolling
  3089. ------------------------------------------------------------------------------------------------------------------*/
  3090. // Computes and stores the bounding rectangle of scrollEl
  3091. computeScrollBounds: function() {
  3092. var el = this.scrollEl;
  3093. var offset;
  3094. if (el) {
  3095. offset = el.offset();
  3096. this.scrollBounds = {
  3097. top: offset.top,
  3098. left: offset.left,
  3099. bottom: offset.top + el.outerHeight(),
  3100. right: offset.left + el.outerWidth()
  3101. };
  3102. }
  3103. },
  3104. // Called when the dragging is in progress and scrolling should be updated
  3105. dragScroll: function(ev) {
  3106. var sensitivity = this.scrollSensitivity;
  3107. var bounds = this.scrollBounds;
  3108. var topCloseness, bottomCloseness;
  3109. var leftCloseness, rightCloseness;
  3110. var topVel = 0;
  3111. var leftVel = 0;
  3112. if (bounds) { // only scroll if scrollEl exists
  3113. // compute closeness to edges. valid range is from 0.0 - 1.0
  3114. topCloseness = (sensitivity - (ev.pageY - bounds.top)) / sensitivity;
  3115. bottomCloseness = (sensitivity - (bounds.bottom - ev.pageY)) / sensitivity;
  3116. leftCloseness = (sensitivity - (ev.pageX - bounds.left)) / sensitivity;
  3117. rightCloseness = (sensitivity - (bounds.right - ev.pageX)) / sensitivity;
  3118. // translate vertical closeness into velocity.
  3119. // mouse must be completely in bounds for velocity to happen.
  3120. if (topCloseness >= 0 && topCloseness <= 1) {
  3121. topVel = topCloseness * this.scrollSpeed * -1; // negative. for scrolling up
  3122. }
  3123. else if (bottomCloseness >= 0 && bottomCloseness <= 1) {
  3124. topVel = bottomCloseness * this.scrollSpeed;
  3125. }
  3126. // translate horizontal closeness into velocity
  3127. if (leftCloseness >= 0 && leftCloseness <= 1) {
  3128. leftVel = leftCloseness * this.scrollSpeed * -1; // negative. for scrolling left
  3129. }
  3130. else if (rightCloseness >= 0 && rightCloseness <= 1) {
  3131. leftVel = rightCloseness * this.scrollSpeed;
  3132. }
  3133. }
  3134. this.setScrollVel(topVel, leftVel);
  3135. },
  3136. // Sets the speed-of-scrolling for the scrollEl
  3137. setScrollVel: function(topVel, leftVel) {
  3138. this.scrollTopVel = topVel;
  3139. this.scrollLeftVel = leftVel;
  3140. this.constrainScrollVel(); // massages into realistic values
  3141. // if there is non-zero velocity, and an animation loop hasn't already started, then START
  3142. if ((this.scrollTopVel || this.scrollLeftVel) && !this.scrollIntervalId) {
  3143. this.scrollIntervalId = setInterval(
  3144. $.proxy(this, 'scrollIntervalFunc'), // scope to `this`
  3145. this.scrollIntervalMs
  3146. );
  3147. }
  3148. },
  3149. // Forces scrollTopVel and scrollLeftVel to be zero if scrolling has already gone all the way
  3150. constrainScrollVel: function() {
  3151. var el = this.scrollEl;
  3152. if (this.scrollTopVel < 0) { // scrolling up?
  3153. if (el.scrollTop() <= 0) { // already scrolled all the way up?
  3154. this.scrollTopVel = 0;
  3155. }
  3156. }
  3157. else if (this.scrollTopVel > 0) { // scrolling down?
  3158. if (el.scrollTop() + el[0].clientHeight >= el[0].scrollHeight) { // already scrolled all the way down?
  3159. this.scrollTopVel = 0;
  3160. }
  3161. }
  3162. if (this.scrollLeftVel < 0) { // scrolling left?
  3163. if (el.scrollLeft() <= 0) { // already scrolled all the left?
  3164. this.scrollLeftVel = 0;
  3165. }
  3166. }
  3167. else if (this.scrollLeftVel > 0) { // scrolling right?
  3168. if (el.scrollLeft() + el[0].clientWidth >= el[0].scrollWidth) { // already scrolled all the way right?
  3169. this.scrollLeftVel = 0;
  3170. }
  3171. }
  3172. },
  3173. // This function gets called during every iteration of the scrolling animation loop
  3174. scrollIntervalFunc: function() {
  3175. var el = this.scrollEl;
  3176. var frac = this.scrollIntervalMs / 1000; // considering animation frequency, what the vel should be mult'd by
  3177. // change the value of scrollEl's scroll
  3178. if (this.scrollTopVel) {
  3179. el.scrollTop(el.scrollTop() + this.scrollTopVel * frac);
  3180. }
  3181. if (this.scrollLeftVel) {
  3182. el.scrollLeft(el.scrollLeft() + this.scrollLeftVel * frac);
  3183. }
  3184. this.constrainScrollVel(); // since the scroll values changed, recompute the velocities
  3185. // if scrolled all the way, which causes the vels to be zero, stop the animation loop
  3186. if (!this.scrollTopVel && !this.scrollLeftVel) {
  3187. this.stopScrolling();
  3188. }
  3189. },
  3190. // Kills any existing scrolling animation loop
  3191. stopScrolling: function() {
  3192. if (this.scrollIntervalId) {
  3193. clearInterval(this.scrollIntervalId);
  3194. this.scrollIntervalId = null;
  3195. // when all done with scrolling, recompute positions since they probably changed
  3196. this.computeCoords();
  3197. }
  3198. },
  3199. // Get called when the scrollEl is scrolled (NOTE: this is delayed via debounce)
  3200. scrollHandler: function() {
  3201. // recompute all coordinates, but *only* if this is *not* part of our scrolling animation
  3202. if (!this.scrollIntervalId) {
  3203. this.computeCoords();
  3204. }
  3205. }
  3206. };
  3207. // Returns `true` if the cells are identically equal. `false` otherwise.
  3208. // They must have the same row, col, and be from the same grid.
  3209. // Two null values will be considered equal, as two "out of the grid" states are the same.
  3210. function isCellsEqual(cell1, cell2) {
  3211. if (!cell1 && !cell2) {
  3212. return true;
  3213. }
  3214. if (cell1 && cell2) {
  3215. return cell1.grid === cell2.grid &&
  3216. cell1.row === cell2.row &&
  3217. cell1.col === cell2.col;
  3218. }
  3219. return false;
  3220. }
  3221. ;;
  3222. /* Creates a clone of an element and lets it track the mouse as it moves
  3223. ----------------------------------------------------------------------------------------------------------------------*/
  3224. function MouseFollower(sourceEl, options) {
  3225. this.options = options = options || {};
  3226. this.sourceEl = sourceEl;
  3227. this.parentEl = options.parentEl ? $(options.parentEl) : sourceEl.parent(); // default to sourceEl's parent
  3228. }
  3229. MouseFollower.prototype = {
  3230. options: null,
  3231. sourceEl: null, // the element that will be cloned and made to look like it is dragging
  3232. el: null, // the clone of `sourceEl` that will track the mouse
  3233. parentEl: null, // the element that `el` (the clone) will be attached to
  3234. // the initial position of el, relative to the offset parent. made to match the initial offset of sourceEl
  3235. top0: null,
  3236. left0: null,
  3237. // the initial position of the mouse
  3238. mouseY0: null,
  3239. mouseX0: null,
  3240. // the number of pixels the mouse has moved from its initial position
  3241. topDelta: null,
  3242. leftDelta: null,
  3243. mousemoveProxy: null, // document mousemove handler, bound to the MouseFollower's `this`
  3244. isFollowing: false,
  3245. isHidden: false,
  3246. isAnimating: false, // doing the revert animation?
  3247. // Causes the element to start following the mouse
  3248. start: function(ev) {
  3249. if (!this.isFollowing) {
  3250. this.isFollowing = true;
  3251. this.mouseY0 = ev.pageY;
  3252. this.mouseX0 = ev.pageX;
  3253. this.topDelta = 0;
  3254. this.leftDelta = 0;
  3255. if (!this.isHidden) {
  3256. this.updatePosition();
  3257. }
  3258. $(document).on('mousemove', this.mousemoveProxy = $.proxy(this, 'mousemove'));
  3259. }
  3260. },
  3261. // Causes the element to stop following the mouse. If shouldRevert is true, will animate back to original position.
  3262. // `callback` gets invoked when the animation is complete. If no animation, it is invoked immediately.
  3263. stop: function(shouldRevert, callback) {
  3264. var _this = this;
  3265. var revertDuration = this.options.revertDuration;
  3266. function complete() {
  3267. this.isAnimating = false;
  3268. _this.destroyEl();
  3269. this.top0 = this.left0 = null; // reset state for future updatePosition calls
  3270. if (callback) {
  3271. callback();
  3272. }
  3273. }
  3274. if (this.isFollowing && !this.isAnimating) { // disallow more than one stop animation at a time
  3275. this.isFollowing = false;
  3276. $(document).off('mousemove', this.mousemoveProxy);
  3277. if (shouldRevert && revertDuration && !this.isHidden) { // do a revert animation?
  3278. this.isAnimating = true;
  3279. this.el.animate({
  3280. top: this.top0,
  3281. left: this.left0
  3282. }, {
  3283. duration: revertDuration,
  3284. complete: complete
  3285. });
  3286. }
  3287. else {
  3288. complete();
  3289. }
  3290. }
  3291. },
  3292. // Gets the tracking element. Create it if necessary
  3293. getEl: function() {
  3294. var el = this.el;
  3295. if (!el) {
  3296. this.sourceEl.width(); // hack to force IE8 to compute correct bounding box
  3297. el = this.el = this.sourceEl.clone()
  3298. .css({
  3299. position: 'absolute',
  3300. visibility: '', // in case original element was hidden (commonly through hideEvents())
  3301. display: this.isHidden ? 'none' : '', // for when initially hidden
  3302. margin: 0,
  3303. right: 'auto', // erase and set width instead
  3304. bottom: 'auto', // erase and set height instead
  3305. width: this.sourceEl.width(), // explicit height in case there was a 'right' value
  3306. height: this.sourceEl.height(), // explicit width in case there was a 'bottom' value
  3307. opacity: this.options.opacity || '',
  3308. zIndex: this.options.zIndex
  3309. })
  3310. .appendTo(this.parentEl);
  3311. }
  3312. return el;
  3313. },
  3314. // Removes the tracking element if it has already been created
  3315. destroyEl: function() {
  3316. if (this.el) {
  3317. this.el.remove();
  3318. this.el = null;
  3319. }
  3320. },
  3321. // Update the CSS position of the tracking element
  3322. updatePosition: function() {
  3323. var sourceOffset;
  3324. var origin;
  3325. this.getEl(); // ensure this.el
  3326. // make sure origin info was computed
  3327. if (this.top0 === null) {
  3328. this.sourceEl.width(); // hack to force IE8 to compute correct bounding box
  3329. sourceOffset = this.sourceEl.offset();
  3330. origin = this.el.offsetParent().offset();
  3331. this.top0 = sourceOffset.top - origin.top;
  3332. this.left0 = sourceOffset.left - origin.left;
  3333. }
  3334. this.el.css({
  3335. top: this.top0 + this.topDelta,
  3336. left: this.left0 + this.leftDelta
  3337. });
  3338. },
  3339. // Gets called when the user moves the mouse
  3340. mousemove: function(ev) {
  3341. this.topDelta = ev.pageY - this.mouseY0;
  3342. this.leftDelta = ev.pageX - this.mouseX0;
  3343. if (!this.isHidden) {
  3344. this.updatePosition();
  3345. }
  3346. },
  3347. // Temporarily makes the tracking element invisible. Can be called before following starts
  3348. hide: function() {
  3349. if (!this.isHidden) {
  3350. this.isHidden = true;
  3351. if (this.el) {
  3352. this.el.hide();
  3353. }
  3354. }
  3355. },
  3356. // Show the tracking element after it has been temporarily hidden
  3357. show: function() {
  3358. if (this.isHidden) {
  3359. this.isHidden = false;
  3360. this.updatePosition();
  3361. this.getEl().show();
  3362. }
  3363. }
  3364. };
  3365. ;;
  3366. /* A utility class for rendering <tr> rows.
  3367. ----------------------------------------------------------------------------------------------------------------------*/
  3368. // It leverages methods of the subclass and the View to determine custom rendering behavior for each row "type"
  3369. // (such as highlight rows, day rows, helper rows, etc).
  3370. function RowRenderer(view) {
  3371. this.view = view;
  3372. }
  3373. RowRenderer.prototype = {
  3374. view: null, // a View object
  3375. cellHtml: '<td/>', // plain default HTML used for a cell when no other is available
  3376. // Renders the HTML for a row, leveraging custom cell-HTML-renderers based on the `rowType`.
  3377. // Also applies the "intro" and "outro" cells, which are specified by the subclass and views.
  3378. // `row` is an optional row number.
  3379. rowHtml: function(rowType, row) {
  3380. var view = this.view;
  3381. var renderCell = this.getHtmlRenderer('cell', rowType);
  3382. var cellHtml = '';
  3383. var col;
  3384. var date;
  3385. row = row || 0;
  3386. for (col = 0; col < view.colCnt; col++) {
  3387. date = view.cellToDate(row, col);
  3388. cellHtml += renderCell(row, col, date);
  3389. }
  3390. cellHtml = this.bookendCells(cellHtml, rowType, row); // apply intro and outro
  3391. return '<tr>' + cellHtml + '</tr>';
  3392. },
  3393. // Applies the "intro" and "outro" HTML to the given cells.
  3394. // Intro means the leftmost cell when the calendar is LTR and the rightmost cell when RTL. Vice-versa for outro.
  3395. // `cells` can be an HTML string of <td>'s or a jQuery <tr> element
  3396. // `row` is an optional row number.
  3397. bookendCells: function(cells, rowType, row) {
  3398. var view = this.view;
  3399. var intro = this.getHtmlRenderer('intro', rowType)(row || 0);
  3400. var outro = this.getHtmlRenderer('outro', rowType)(row || 0);
  3401. var isRTL = view.opt('isRTL');
  3402. var prependHtml = isRTL ? outro : intro;
  3403. var appendHtml = isRTL ? intro : outro;
  3404. if (typeof cells === 'string') {
  3405. return prependHtml + cells + appendHtml;
  3406. }
  3407. else { // a jQuery <tr> element
  3408. return cells.prepend(prependHtml).append(appendHtml);
  3409. }
  3410. },
  3411. // Returns an HTML-rendering function given a specific `rendererName` (like cell, intro, or outro) and a specific
  3412. // `rowType` (like day, eventSkeleton, helperSkeleton), which is optional.
  3413. // If a renderer for the specific rowType doesn't exist, it will fall back to a generic renderer.
  3414. // We will query the View object first for any custom rendering functions, then the methods of the subclass.
  3415. getHtmlRenderer: function(rendererName, rowType) {
  3416. var view = this.view;
  3417. var generalName; // like "cellHtml"
  3418. var specificName; // like "dayCellHtml". based on rowType
  3419. var provider; // either the View or the RowRenderer subclass, whichever provided the method
  3420. var renderer;
  3421. generalName = rendererName + 'Html';
  3422. if (rowType) {
  3423. specificName = rowType + capitaliseFirstLetter(rendererName) + 'Html';
  3424. }
  3425. if (specificName && (renderer = view[specificName])) {
  3426. provider = view;
  3427. }
  3428. else if (specificName && (renderer = this[specificName])) {
  3429. provider = this;
  3430. }
  3431. else if ((renderer = view[generalName])) {
  3432. provider = view;
  3433. }
  3434. else if ((renderer = this[generalName])) {
  3435. provider = this;
  3436. }
  3437. if (typeof renderer === 'function') {
  3438. return function() {
  3439. return renderer.apply(provider, arguments) || ''; // use correct `this` and always return a string
  3440. };
  3441. }
  3442. // the rendered can be a plain string as well. if not specified, always an empty string.
  3443. return function() {
  3444. return renderer || '';
  3445. };
  3446. }
  3447. };
  3448. ;;
  3449. /* An abstract class comprised of a "grid" of cells that each represent a specific datetime
  3450. ----------------------------------------------------------------------------------------------------------------------*/
  3451. function Grid(view) {
  3452. RowRenderer.call(this, view); // call the super-constructor
  3453. this.coordMap = new GridCoordMap(this);
  3454. this.elsByFill = {};
  3455. }
  3456. Grid.prototype = createObject(RowRenderer.prototype); // declare the super-class
  3457. $.extend(Grid.prototype, {
  3458. el: null, // the containing element
  3459. coordMap: null, // a GridCoordMap that converts pixel values to datetimes
  3460. cellDuration: null, // a cell's duration. subclasses must assign this ASAP
  3461. elsByFill: null, // a hash of jQuery element sets used for rendering each fill. Keyed by fill name.
  3462. // Renders the grid into the `el` element.
  3463. // Subclasses should override and call this super-method when done.
  3464. render: function() {
  3465. this.bindHandlers();
  3466. },
  3467. // Called when the grid's resources need to be cleaned up
  3468. destroy: function() {
  3469. // subclasses can implement
  3470. },
  3471. /* Coordinates & Cells
  3472. ------------------------------------------------------------------------------------------------------------------*/
  3473. // Populates the given empty arrays with the y and x coordinates of the cells
  3474. buildCoords: function(rows, cols) {
  3475. // subclasses must implement
  3476. },
  3477. // Given a cell object, returns the date for that cell
  3478. getCellDate: function(cell) {
  3479. // subclasses must implement
  3480. },
  3481. // Given a cell object, returns the element that represents the cell's whole-day
  3482. getCellDayEl: function(cell) {
  3483. // subclasses must implement
  3484. },
  3485. // Converts a range with an inclusive `start` and an exclusive `end` into an array of segment objects
  3486. rangeToSegs: function(start, end) {
  3487. // subclasses must implement
  3488. },
  3489. /* Handlers
  3490. ------------------------------------------------------------------------------------------------------------------*/
  3491. // Attach handlers to `this.el`, using bubbling to listen to all ancestors.
  3492. // We don't need to undo any of this in a "destroy" method, because the view will simply remove `this.el` from the
  3493. // DOM and jQuery will be smart enough to garbage collect the handlers.
  3494. bindHandlers: function() {
  3495. var _this = this;
  3496. this.el.on('mousedown', function(ev) {
  3497. if (
  3498. !$(ev.target).is('.fc-event-container *, .fc-more') && // not an an event element, or "more.." link
  3499. !$(ev.target).closest('.fc-popover').length // not on a popover (like the "more.." events one)
  3500. ) {
  3501. _this.dayMousedown(ev);
  3502. }
  3503. });
  3504. this.bindSegHandlers(); // attach event-element-related handlers. in Grid.events.js
  3505. },
  3506. // Process a mousedown on an element that represents a day. For day clicking and selecting.
  3507. dayMousedown: function(ev) {
  3508. var _this = this;
  3509. var view = this.view;
  3510. var calendar = view.calendar;
  3511. var isSelectable = view.opt('selectable');
  3512. var dates = null; // the inclusive dates of the selection. will be null if no selection
  3513. var start; // the inclusive start of the selection
  3514. var end; // the *exclusive* end of the selection
  3515. var dayEl;
  3516. // this listener tracks a mousedown on a day element, and a subsequent drag.
  3517. // if the drag ends on the same day, it is a 'dayClick'.
  3518. // if 'selectable' is enabled, this listener also detects selections.
  3519. var dragListener = new DragListener(this.coordMap, {
  3520. //distance: 5, // needs more work if we want dayClick to fire correctly
  3521. scroll: view.opt('dragScroll'),
  3522. dragStart: function() {
  3523. view.unselect(); // since we could be rendering a new selection, we want to clear any old one
  3524. },
  3525. cellOver: function(cell, date) {
  3526. if (dragListener.origDate) { // click needs to have started on a cell
  3527. dayEl = _this.getCellDayEl(cell);
  3528. dates = [ date, dragListener.origDate ].sort(compareNumbers); // works with Moments
  3529. start = dates[0];
  3530. end = dates[1].clone().add(_this.cellDuration);
  3531. if (isSelectable) {
  3532. if (calendar.isSelectionAllowedInRange(start, end)) { // allowed to select within this range?
  3533. _this.renderSelection(start, end);
  3534. }
  3535. else {
  3536. dates = null; // flag for an invalid selection
  3537. disableCursor();
  3538. }
  3539. }
  3540. }
  3541. },
  3542. cellOut: function(cell, date) {
  3543. dates = null;
  3544. _this.destroySelection();
  3545. enableCursor();
  3546. },
  3547. listenStop: function(ev) {
  3548. if (dates) { // started and ended on a cell?
  3549. if (dates[0].isSame(dates[1])) {
  3550. view.trigger('dayClick', dayEl[0], start, ev);
  3551. }
  3552. if (isSelectable) {
  3553. // the selection will already have been rendered. just report it
  3554. view.reportSelection(start, end, ev);
  3555. }
  3556. }
  3557. enableCursor();
  3558. }
  3559. });
  3560. dragListener.mousedown(ev); // start listening, which will eventually initiate a dragStart
  3561. },
  3562. /* Event Dragging
  3563. ------------------------------------------------------------------------------------------------------------------*/
  3564. // Renders a visual indication of a event being dragged over the given date(s).
  3565. // `end` can be null, as well as `seg`. See View's documentation on renderDrag for more info.
  3566. // A returned value of `true` signals that a mock "helper" event has been rendered.
  3567. renderDrag: function(start, end, seg) {
  3568. // subclasses must implement
  3569. },
  3570. // Unrenders a visual indication of an event being dragged
  3571. destroyDrag: function() {
  3572. // subclasses must implement
  3573. },
  3574. /* Event Resizing
  3575. ------------------------------------------------------------------------------------------------------------------*/
  3576. // Renders a visual indication of an event being resized.
  3577. // `start` and `end` are the updated dates of the event. `seg` is the original segment object involved in the drag.
  3578. renderResize: function(start, end, seg) {
  3579. // subclasses must implement
  3580. },
  3581. // Unrenders a visual indication of an event being resized.
  3582. destroyResize: function() {
  3583. // subclasses must implement
  3584. },
  3585. /* Event Helper
  3586. ------------------------------------------------------------------------------------------------------------------*/
  3587. // Renders a mock event over the given date(s).
  3588. // `end` can be null, in which case the mock event that is rendered will have a null end time.
  3589. // `sourceSeg` is the internal segment object involved in the drag. If null, something external is dragging.
  3590. renderRangeHelper: function(start, end, sourceSeg) {
  3591. var view = this.view;
  3592. var fakeEvent;
  3593. // compute the end time if forced to do so (this is what EventManager does)
  3594. if (!end && view.opt('forceEventDuration')) {
  3595. end = view.calendar.getDefaultEventEnd(!start.hasTime(), start);
  3596. }
  3597. fakeEvent = sourceSeg ? createObject(sourceSeg.event) : {}; // mask the original event object if possible
  3598. fakeEvent.start = start;
  3599. fakeEvent.end = end;
  3600. fakeEvent.allDay = !(start.hasTime() || (end && end.hasTime())); // freshly compute allDay
  3601. // this extra className will be useful for differentiating real events from mock events in CSS
  3602. fakeEvent.className = (fakeEvent.className || []).concat('fc-helper');
  3603. // if something external is being dragged in, don't render a resizer
  3604. if (!sourceSeg) {
  3605. fakeEvent.editable = false;
  3606. }
  3607. this.renderHelper(fakeEvent, sourceSeg); // do the actual rendering
  3608. },
  3609. // Renders a mock event
  3610. renderHelper: function(event, sourceSeg) {
  3611. // subclasses must implement
  3612. },
  3613. // Unrenders a mock event
  3614. destroyHelper: function() {
  3615. // subclasses must implement
  3616. },
  3617. /* Selection
  3618. ------------------------------------------------------------------------------------------------------------------*/
  3619. // Renders a visual indication of a selection. Will highlight by default but can be overridden by subclasses.
  3620. renderSelection: function(start, end) {
  3621. this.renderHighlight(start, end);
  3622. },
  3623. // Unrenders any visual indications of a selection. Will unrender a highlight by default.
  3624. destroySelection: function() {
  3625. this.destroyHighlight();
  3626. },
  3627. /* Highlight
  3628. ------------------------------------------------------------------------------------------------------------------*/
  3629. // Renders an emphasis on the given date range. `start` is inclusive. `end` is exclusive.
  3630. renderHighlight: function(start, end) {
  3631. this.renderFill('highlight', this.rangeToSegs(start, end));
  3632. },
  3633. // Unrenders the emphasis on a date range
  3634. destroyHighlight: function() {
  3635. this.destroyFill('highlight');
  3636. },
  3637. // Generates an array of classNames for rendering the highlight. Used by the fill system.
  3638. highlightSegClasses: function() {
  3639. return [ 'fc-highlight' ];
  3640. },
  3641. /* Fill System (highlight, background events, business hours)
  3642. ------------------------------------------------------------------------------------------------------------------*/
  3643. // Renders a set of rectangles over the given segments of time.
  3644. // Returns a subset of segs, the segs that were actually rendered.
  3645. // Responsible for populating this.elsByFill
  3646. renderFill: function(type, segs) {
  3647. // subclasses must implement
  3648. },
  3649. // Unrenders a specific type of fill that is currently rendered on the grid
  3650. destroyFill: function(type) {
  3651. var el = this.elsByFill[type];
  3652. if (el) {
  3653. el.remove();
  3654. delete this.elsByFill[type];
  3655. }
  3656. },
  3657. // Renders and assigns an `el` property for each fill segment. Generic enough to work with different types.
  3658. // Only returns segments that successfully rendered.
  3659. // To be harnessed by renderFill (implemented by subclasses).
  3660. // Analagous to renderFgSegEls.
  3661. renderFillSegEls: function(type, segs) {
  3662. var _this = this;
  3663. var segElMethod = this[type + 'SegEl'];
  3664. var html = '';
  3665. var renderedSegs = [];
  3666. var i;
  3667. if (segs.length) {
  3668. // build a large concatenation of segment HTML
  3669. for (i = 0; i < segs.length; i++) {
  3670. html += this.fillSegHtml(type, segs[i]);
  3671. }
  3672. // Grab individual elements from the combined HTML string. Use each as the default rendering.
  3673. // Then, compute the 'el' for each segment.
  3674. $(html).each(function(i, node) {
  3675. var seg = segs[i];
  3676. var el = $(node);
  3677. // allow custom filter methods per-type
  3678. if (segElMethod) {
  3679. el = segElMethod.call(_this, seg, el);
  3680. }
  3681. if (el) { // custom filters did not cancel the render
  3682. el = $(el); // allow custom filter to return raw DOM node
  3683. // correct element type? (would be bad if a non-TD were inserted into a table for example)
  3684. if (el.is(_this.fillSegTag)) {
  3685. seg.el = el;
  3686. renderedSegs.push(seg);
  3687. }
  3688. }
  3689. });
  3690. }
  3691. return renderedSegs;
  3692. },
  3693. fillSegTag: 'div', // subclasses can override
  3694. // Builds the HTML needed for one fill segment. Generic enought o work with different types.
  3695. fillSegHtml: function(type, seg) {
  3696. var classesMethod = this[type + 'SegClasses']; // custom hooks per-type
  3697. var stylesMethod = this[type + 'SegStyles']; //
  3698. var classes = classesMethod ? classesMethod.call(this, seg) : [];
  3699. var styles = stylesMethod ? stylesMethod.call(this, seg) : ''; // a semi-colon separated CSS property string
  3700. return '<' + this.fillSegTag +
  3701. (classes.length ? ' class="' + classes.join(' ') + '"' : '') +
  3702. (styles ? ' style="' + styles + '"' : '') +
  3703. ' />';
  3704. },
  3705. /* Generic rendering utilities for subclasses
  3706. ------------------------------------------------------------------------------------------------------------------*/
  3707. // Renders a day-of-week header row
  3708. headHtml: function() {
  3709. return '' +
  3710. '<div class="fc-row ' + this.view.widgetHeaderClass + '">' +
  3711. '<table>' +
  3712. '<thead>' +
  3713. this.rowHtml('head') + // leverages RowRenderer
  3714. '</thead>' +
  3715. '</table>' +
  3716. '</div>';
  3717. },
  3718. // Used by the `headHtml` method, via RowRenderer, for rendering the HTML of a day-of-week header cell
  3719. headCellHtml: function(row, col, date) {
  3720. var view = this.view;
  3721. var calendar = view.calendar;
  3722. var colFormat = view.opt('columnFormat');
  3723. return '' +
  3724. '<th class="fc-day-header ' + view.widgetHeaderClass + ' fc-' + dayIDs[date.day()] + '">' +
  3725. htmlEscape(calendar.formatDate(date, colFormat)) +
  3726. '</th>';
  3727. },
  3728. // Renders the HTML for a single-day background cell
  3729. bgCellHtml: function(row, col, date) {
  3730. var view = this.view;
  3731. var classes = this.getDayClasses(date);
  3732. classes.unshift('fc-day', view.widgetContentClass);
  3733. return '<td class="' + classes.join(' ') + '" data-date="' + date.format() + '"></td>';
  3734. },
  3735. // Computes HTML classNames for a single-day cell
  3736. getDayClasses: function(date) {
  3737. var view = this.view;
  3738. var today = view.calendar.getNow().stripTime();
  3739. var classes = [ 'fc-' + dayIDs[date.day()] ];
  3740. if (
  3741. view.name === 'month' &&
  3742. date.month() != view.intervalStart.month()
  3743. ) {
  3744. classes.push('fc-other-month');
  3745. }
  3746. if (date.isSame(today, 'day')) {
  3747. classes.push(
  3748. 'fc-today',
  3749. view.highlightStateClass
  3750. );
  3751. }
  3752. else if (date < today) {
  3753. classes.push('fc-past');
  3754. }
  3755. else {
  3756. classes.push('fc-future');
  3757. }
  3758. return classes;
  3759. }
  3760. });
  3761. ;;
  3762. /* Event-rendering and event-interaction methods for the abstract Grid class
  3763. ----------------------------------------------------------------------------------------------------------------------*/
  3764. $.extend(Grid.prototype, {
  3765. mousedOverSeg: null, // the segment object the user's mouse is over. null if over nothing
  3766. isDraggingSeg: false, // is a segment being dragged? boolean
  3767. isResizingSeg: false, // is a segment being resized? boolean
  3768. segs: null, // the event segments currently rendered in the grid
  3769. // Renders the given events onto the grid
  3770. renderEvents: function(events) {
  3771. var segs = this.eventsToSegs(events);
  3772. var bgSegs = [];
  3773. var fgSegs = [];
  3774. var i, seg;
  3775. for (i = 0; i < segs.length; i++) {
  3776. seg = segs[i];
  3777. if (isBgEvent(seg.event)) {
  3778. bgSegs.push(seg);
  3779. }
  3780. else {
  3781. fgSegs.push(seg);
  3782. }
  3783. }
  3784. // Render each different type of segment.
  3785. // Each function may return a subset of the segs, segs that were actually rendered.
  3786. bgSegs = this.renderBgSegs(bgSegs) || bgSegs;
  3787. fgSegs = this.renderFgSegs(fgSegs) || fgSegs;
  3788. this.segs = bgSegs.concat(fgSegs);
  3789. },
  3790. // Unrenders all events currently rendered on the grid
  3791. destroyEvents: function() {
  3792. this.triggerSegMouseout(); // trigger an eventMouseout if user's mouse is over an event
  3793. this.destroyFgSegs();
  3794. this.destroyBgSegs();
  3795. this.segs = null;
  3796. },
  3797. // Retrieves all rendered segment objects currently rendered on the grid
  3798. getSegs: function() {
  3799. return this.segs || [];
  3800. },
  3801. /* Foreground Segment Rendering
  3802. ------------------------------------------------------------------------------------------------------------------*/
  3803. // Renders foreground event segments onto the grid. May return a subset of segs that were rendered.
  3804. renderFgSegs: function(segs) {
  3805. // subclasses must implement
  3806. },
  3807. // Unrenders all currently rendered foreground segments
  3808. destroyFgSegs: function() {
  3809. // subclasses must implement
  3810. },
  3811. // Renders and assigns an `el` property for each foreground event segment.
  3812. // Only returns segments that successfully rendered.
  3813. // A utility that subclasses may use.
  3814. renderFgSegEls: function(segs, disableResizing) {
  3815. var view = this.view;
  3816. var html = '';
  3817. var renderedSegs = [];
  3818. var i;
  3819. if (segs.length) { // don't build an empty html string
  3820. // build a large concatenation of event segment HTML
  3821. for (i = 0; i < segs.length; i++) {
  3822. html += this.fgSegHtml(segs[i], disableResizing);
  3823. }
  3824. // Grab individual elements from the combined HTML string. Use each as the default rendering.
  3825. // Then, compute the 'el' for each segment. An el might be null if the eventRender callback returned false.
  3826. $(html).each(function(i, node) {
  3827. var seg = segs[i];
  3828. var el = view.resolveEventEl(seg.event, $(node));
  3829. if (el) {
  3830. el.data('fc-seg', seg); // used by handlers
  3831. seg.el = el;
  3832. renderedSegs.push(seg);
  3833. }
  3834. });
  3835. }
  3836. return renderedSegs;
  3837. },
  3838. // Generates the HTML for the default rendering of a foreground event segment. Used by renderFgSegEls()
  3839. fgSegHtml: function(seg, disableResizing) {
  3840. // subclasses should implement
  3841. },
  3842. /* Background Segment Rendering
  3843. ------------------------------------------------------------------------------------------------------------------*/
  3844. // Renders the given background event segments onto the grid.
  3845. // Returns a subset of the segs that were actually rendered.
  3846. renderBgSegs: function(segs) {
  3847. return this.renderFill('bgEvent', segs);
  3848. },
  3849. // Unrenders all the currently rendered background event segments
  3850. destroyBgSegs: function() {
  3851. this.destroyFill('bgEvent');
  3852. },
  3853. // Renders a background event element, given the default rendering. Called by the fill system.
  3854. bgEventSegEl: function(seg, el) {
  3855. return this.view.resolveEventEl(seg.event, el); // will filter through eventRender
  3856. },
  3857. // Generates an array of classNames to be used for the default rendering of a background event.
  3858. // Called by the fill system.
  3859. bgEventSegClasses: function(seg) {
  3860. var event = seg.event;
  3861. var source = event.source || {};
  3862. return [ 'fc-bgevent' ].concat(
  3863. event.className,
  3864. source.className || []
  3865. );
  3866. },
  3867. // Generates a semicolon-separated CSS string to be used for the default rendering of a background event.
  3868. // Called by the fill system.
  3869. // TODO: consolidate with getEventSkinCss?
  3870. bgEventSegStyles: function(seg) {
  3871. var view = this.view;
  3872. var event = seg.event;
  3873. var source = event.source || {};
  3874. var eventColor = event.color;
  3875. var sourceColor = source.color;
  3876. var optionColor = view.opt('eventColor');
  3877. var backgroundColor =
  3878. event.backgroundColor ||
  3879. eventColor ||
  3880. source.backgroundColor ||
  3881. sourceColor ||
  3882. view.opt('eventBackgroundColor') ||
  3883. optionColor;
  3884. if (backgroundColor) {
  3885. return 'background-color:' + backgroundColor;
  3886. }
  3887. return '';
  3888. },
  3889. // Generates an array of classNames to be used for the rendering business hours overlay. Called by the fill system.
  3890. businessHoursSegClasses: function(seg) {
  3891. return [ 'fc-nonbusiness', 'fc-bgevent' ];
  3892. },
  3893. /* Handlers
  3894. ------------------------------------------------------------------------------------------------------------------*/
  3895. // Attaches event-element-related handlers to the container element and leverage bubbling
  3896. bindSegHandlers: function() {
  3897. var _this = this;
  3898. var view = this.view;
  3899. $.each(
  3900. {
  3901. mouseenter: function(seg, ev) {
  3902. _this.triggerSegMouseover(seg, ev);
  3903. },
  3904. mouseleave: function(seg, ev) {
  3905. _this.triggerSegMouseout(seg, ev);
  3906. },
  3907. click: function(seg, ev) {
  3908. return view.trigger('eventClick', this, seg.event, ev); // can return `false` to cancel
  3909. },
  3910. mousedown: function(seg, ev) {
  3911. if ($(ev.target).is('.fc-resizer') && view.isEventResizable(seg.event)) {
  3912. _this.segResizeMousedown(seg, ev);
  3913. }
  3914. else if (view.isEventDraggable(seg.event)) {
  3915. _this.segDragMousedown(seg, ev);
  3916. }
  3917. }
  3918. },
  3919. function(name, func) {
  3920. // attach the handler to the container element and only listen for real event elements via bubbling
  3921. _this.el.on(name, '.fc-event-container > *', function(ev) {
  3922. var seg = $(this).data('fc-seg'); // grab segment data. put there by View::renderEvents
  3923. // only call the handlers if there is not a drag/resize in progress
  3924. if (seg && !_this.isDraggingSeg && !_this.isResizingSeg) {
  3925. return func.call(this, seg, ev); // `this` will be the event element
  3926. }
  3927. });
  3928. }
  3929. );
  3930. },
  3931. // Updates internal state and triggers handlers for when an event element is moused over
  3932. triggerSegMouseover: function(seg, ev) {
  3933. if (!this.mousedOverSeg) {
  3934. this.mousedOverSeg = seg;
  3935. this.view.trigger('eventMouseover', seg.el[0], seg.event, ev);
  3936. }
  3937. },
  3938. // Updates internal state and triggers handlers for when an event element is moused out.
  3939. // Can be given no arguments, in which case it will mouseout the segment that was previously moused over.
  3940. triggerSegMouseout: function(seg, ev) {
  3941. ev = ev || {}; // if given no args, make a mock mouse event
  3942. if (this.mousedOverSeg) {
  3943. seg = seg || this.mousedOverSeg; // if given no args, use the currently moused-over segment
  3944. this.mousedOverSeg = null;
  3945. this.view.trigger('eventMouseout', seg.el[0], seg.event, ev);
  3946. }
  3947. },
  3948. /* Dragging
  3949. ------------------------------------------------------------------------------------------------------------------*/
  3950. // Called when the user does a mousedown on an event, which might lead to dragging.
  3951. // Generic enough to work with any type of Grid.
  3952. segDragMousedown: function(seg, ev) {
  3953. var _this = this;
  3954. var view = this.view;
  3955. var calendar = view.calendar;
  3956. var el = seg.el;
  3957. var event = seg.event;
  3958. var newStart, newEnd;
  3959. // A clone of the original element that will move with the mouse
  3960. var mouseFollower = new MouseFollower(seg.el, {
  3961. parentEl: view.el,
  3962. opacity: view.opt('dragOpacity'),
  3963. revertDuration: view.opt('dragRevertDuration'),
  3964. zIndex: 2 // one above the .fc-view
  3965. });
  3966. // Tracks mouse movement over the *view's* coordinate map. Allows dragging and dropping between subcomponents
  3967. // of the view.
  3968. var dragListener = new DragListener(view.coordMap, {
  3969. distance: 5,
  3970. scroll: view.opt('dragScroll'),
  3971. listenStart: function(ev) {
  3972. mouseFollower.hide(); // don't show until we know this is a real drag
  3973. mouseFollower.start(ev);
  3974. },
  3975. dragStart: function(ev) {
  3976. _this.triggerSegMouseout(seg, ev); // ensure a mouseout on the manipulated event has been reported
  3977. _this.isDraggingSeg = true;
  3978. view.hideEvent(event); // hide all event segments. our mouseFollower will take over
  3979. view.trigger('eventDragStart', el[0], event, ev, {}); // last argument is jqui dummy
  3980. },
  3981. cellOver: function(cell, date) {
  3982. var origDate = seg.cellDate || dragListener.origDate;
  3983. var res = _this.computeDraggedEventDates(seg, origDate, date);
  3984. newStart = res.start;
  3985. newEnd = res.end;
  3986. if (calendar.isEventAllowedInRange(event, newStart, res.visibleEnd)) { // allowed to drop here?
  3987. if (view.renderDrag(newStart, newEnd, seg)) { // have the view render a visual indication
  3988. mouseFollower.hide(); // if the view is already using a mock event "helper", hide our own
  3989. }
  3990. else {
  3991. mouseFollower.show();
  3992. }
  3993. }
  3994. else {
  3995. // have the helper follow the mouse (no snapping) with a warning-style cursor
  3996. newStart = null; // mark an invalid drop date
  3997. mouseFollower.show();
  3998. disableCursor();
  3999. }
  4000. },
  4001. cellOut: function() { // called before mouse moves to a different cell OR moved out of all cells
  4002. newStart = null;
  4003. view.destroyDrag(); // unrender whatever was done in view.renderDrag
  4004. mouseFollower.show(); // show in case we are moving out of all cells
  4005. enableCursor();
  4006. },
  4007. dragStop: function(ev) {
  4008. var hasChanged = newStart && !newStart.isSame(event.start);
  4009. // do revert animation if hasn't changed. calls a callback when finished (whether animation or not)
  4010. mouseFollower.stop(!hasChanged, function() {
  4011. _this.isDraggingSeg = false;
  4012. view.destroyDrag();
  4013. view.showEvent(event);
  4014. view.trigger('eventDragStop', el[0], event, ev, {}); // last argument is jqui dummy
  4015. if (hasChanged) {
  4016. view.eventDrop(el[0], event, newStart, ev); // will rerender all events...
  4017. }
  4018. });
  4019. enableCursor();
  4020. },
  4021. listenStop: function() {
  4022. mouseFollower.stop(); // put in listenStop in case there was a mousedown but the drag never started
  4023. }
  4024. });
  4025. dragListener.mousedown(ev); // start listening, which will eventually lead to a dragStart
  4026. },
  4027. // Given a segment, the dates where a drag began and ended, calculates the Event Object's new start and end dates.
  4028. // Might return a `null` end (even when forceEventDuration is on).
  4029. computeDraggedEventDates: function(seg, dragStartDate, dropDate) {
  4030. var view = this.view;
  4031. var event = seg.event;
  4032. var start = event.start;
  4033. var end = view.calendar.getEventEnd(event);
  4034. var delta;
  4035. var newStart;
  4036. var newEnd;
  4037. var newAllDay;
  4038. var visibleEnd;
  4039. if (dropDate.hasTime() === dragStartDate.hasTime()) {
  4040. delta = dayishDiff(dropDate, dragStartDate);
  4041. newStart = start.clone().add(delta);
  4042. if (event.end === null) { // do we need to compute an end?
  4043. newEnd = null;
  4044. }
  4045. else {
  4046. newEnd = end.clone().add(delta);
  4047. }
  4048. newAllDay = event.allDay; // keep it the same
  4049. }
  4050. else {
  4051. // if switching from day <-> timed, start should be reset to the dropped date, and the end cleared
  4052. newStart = dropDate;
  4053. newEnd = null; // end should be cleared
  4054. newAllDay = !dropDate.hasTime();
  4055. }
  4056. // compute what the end date will appear to be
  4057. visibleEnd = newEnd || view.calendar.getDefaultEventEnd(newAllDay, newStart);
  4058. return { start: newStart, end: newEnd, visibleEnd: visibleEnd };
  4059. },
  4060. /* Resizing
  4061. ------------------------------------------------------------------------------------------------------------------*/
  4062. // Called when the user does a mousedown on an event's resizer, which might lead to resizing.
  4063. // Generic enough to work with any type of Grid.
  4064. segResizeMousedown: function(seg, ev) {
  4065. var _this = this;
  4066. var view = this.view;
  4067. var calendar = view.calendar;
  4068. var el = seg.el;
  4069. var event = seg.event;
  4070. var start = event.start;
  4071. var end = view.calendar.getEventEnd(event);
  4072. var newEnd = null;
  4073. var dragListener;
  4074. function destroy() { // resets the rendering to show the original event
  4075. _this.destroyResize();
  4076. view.showEvent(event);
  4077. }
  4078. // Tracks mouse movement over the *grid's* coordinate map
  4079. dragListener = new DragListener(this.coordMap, {
  4080. distance: 5,
  4081. scroll: view.opt('dragScroll'),
  4082. dragStart: function(ev) {
  4083. _this.triggerSegMouseout(seg, ev); // ensure a mouseout on the manipulated event has been reported
  4084. _this.isResizingSeg = true;
  4085. view.trigger('eventResizeStart', el[0], event, ev, {}); // last argument is jqui dummy
  4086. },
  4087. cellOver: function(cell, date) {
  4088. // compute the new end. don't allow it to go before the event's start
  4089. if (date.isBefore(start)) { // allows comparing ambig to non-ambig
  4090. date = start;
  4091. }
  4092. newEnd = date.clone().add(_this.cellDuration); // make it an exclusive end
  4093. if (calendar.isEventAllowedInRange(event, start, newEnd)) { // allowed to be resized here?
  4094. if (newEnd.isSame(end)) {
  4095. newEnd = null; // mark an invalid resize
  4096. destroy();
  4097. }
  4098. else {
  4099. _this.renderResize(start, newEnd, seg);
  4100. view.hideEvent(event);
  4101. }
  4102. }
  4103. else {
  4104. newEnd = null; // mark an invalid resize
  4105. destroy();
  4106. disableCursor();
  4107. }
  4108. },
  4109. cellOut: function() { // called before mouse moves to a different cell OR moved out of all cells
  4110. newEnd = null;
  4111. destroy();
  4112. enableCursor();
  4113. },
  4114. dragStop: function(ev) {
  4115. _this.isResizingSeg = false;
  4116. destroy();
  4117. enableCursor();
  4118. view.trigger('eventResizeStop', el[0], event, ev, {}); // last argument is jqui dummy
  4119. if (newEnd) {
  4120. view.eventResize(el[0], event, newEnd, ev); // will rerender all events...
  4121. }
  4122. }
  4123. });
  4124. dragListener.mousedown(ev); // start listening, which will eventually lead to a dragStart
  4125. },
  4126. /* Rendering Utils
  4127. ------------------------------------------------------------------------------------------------------------------*/
  4128. // Generic utility for generating the HTML classNames for an event segment's element
  4129. getSegClasses: function(seg, isDraggable, isResizable) {
  4130. var event = seg.event;
  4131. var classes = [
  4132. 'fc-event',
  4133. seg.isStart ? 'fc-start' : 'fc-not-start',
  4134. seg.isEnd ? 'fc-end' : 'fc-not-end'
  4135. ].concat(
  4136. event.className,
  4137. event.source ? event.source.className : []
  4138. );
  4139. if (isDraggable) {
  4140. classes.push('fc-draggable');
  4141. }
  4142. if (isResizable) {
  4143. classes.push('fc-resizable');
  4144. }
  4145. return classes;
  4146. },
  4147. // Utility for generating a CSS string with all the event skin-related properties
  4148. getEventSkinCss: function(event) {
  4149. var view = this.view;
  4150. var source = event.source || {};
  4151. var eventColor = event.color;
  4152. var sourceColor = source.color;
  4153. var optionColor = view.opt('eventColor');
  4154. var backgroundColor =
  4155. event.backgroundColor ||
  4156. eventColor ||
  4157. source.backgroundColor ||
  4158. sourceColor ||
  4159. view.opt('eventBackgroundColor') ||
  4160. optionColor;
  4161. var borderColor =
  4162. event.borderColor ||
  4163. eventColor ||
  4164. source.borderColor ||
  4165. sourceColor ||
  4166. view.opt('eventBorderColor') ||
  4167. optionColor;
  4168. var textColor =
  4169. event.textColor ||
  4170. source.textColor ||
  4171. view.opt('eventTextColor');
  4172. var statements = [];
  4173. if (backgroundColor) {
  4174. statements.push('background-color:' + backgroundColor);
  4175. }
  4176. if (borderColor) {
  4177. statements.push('border-color:' + borderColor);
  4178. }
  4179. if (textColor) {
  4180. statements.push('color:' + textColor);
  4181. }
  4182. return statements.join(';');
  4183. },
  4184. /* Converting events -> ranges -> segs
  4185. ------------------------------------------------------------------------------------------------------------------*/
  4186. // Converts an array of event objects into an array of event segment objects.
  4187. // A custom `rangeToSegsFunc` may be given for arbitrarily slicing up events.
  4188. eventsToSegs: function(events, rangeToSegsFunc) {
  4189. var eventRanges = this.eventsToRanges(events);
  4190. var segs = [];
  4191. var i;
  4192. for (i = 0; i < eventRanges.length; i++) {
  4193. segs.push.apply(
  4194. segs,
  4195. this.eventRangeToSegs(eventRanges[i], rangeToSegsFunc)
  4196. );
  4197. }
  4198. return segs;
  4199. },
  4200. // Converts an array of events into an array of "range" objects.
  4201. // A "range" object is a plain object with start/end properties denoting the time it covers. Also an event property.
  4202. // For "normal" events, this will be identical to the event's start/end, but for "inverse-background" events,
  4203. // will create an array of ranges that span the time *not* covered by the given event.
  4204. eventsToRanges: function(events) {
  4205. var _this = this;
  4206. var eventsById = groupEventsById(events);
  4207. var ranges = [];
  4208. // group by ID so that related inverse-background events can be rendered together
  4209. $.each(eventsById, function(id, eventGroup) {
  4210. if (eventGroup.length) {
  4211. ranges.push.apply(
  4212. ranges,
  4213. isInverseBgEvent(eventGroup[0]) ?
  4214. _this.eventsToInverseRanges(eventGroup) :
  4215. _this.eventsToNormalRanges(eventGroup)
  4216. );
  4217. }
  4218. });
  4219. return ranges;
  4220. },
  4221. // Converts an array of "normal" events (not inverted rendering) into a parallel array of ranges
  4222. eventsToNormalRanges: function(events) {
  4223. var calendar = this.view.calendar;
  4224. var ranges = [];
  4225. var i, event;
  4226. var eventStart, eventEnd;
  4227. for (i = 0; i < events.length; i++) {
  4228. event = events[i];
  4229. // make copies and normalize by stripping timezone
  4230. eventStart = event.start.clone().stripZone();
  4231. eventEnd = calendar.getEventEnd(event).stripZone();
  4232. ranges.push({
  4233. event: event,
  4234. start: eventStart,
  4235. end: eventEnd,
  4236. eventStartMS: +eventStart,
  4237. eventDurationMS: eventEnd - eventStart
  4238. });
  4239. }
  4240. return ranges;
  4241. },
  4242. // Converts an array of events, with inverse-background rendering, into an array of range objects.
  4243. // The range objects will cover all the time NOT covered by the events.
  4244. eventsToInverseRanges: function(events) {
  4245. var view = this.view;
  4246. var viewStart = view.start.clone().stripZone(); // normalize timezone
  4247. var viewEnd = view.end.clone().stripZone(); // normalize timezone
  4248. var normalRanges = this.eventsToNormalRanges(events); // will give us normalized dates we can use w/o copies
  4249. var inverseRanges = [];
  4250. var event0 = events[0]; // assign this to each range's `.event`
  4251. var start = viewStart; // the end of the previous range. the start of the new range
  4252. var i, normalRange;
  4253. // ranges need to be in order. required for our date-walking algorithm
  4254. normalRanges.sort(compareNormalRanges);
  4255. for (i = 0; i < normalRanges.length; i++) {
  4256. normalRange = normalRanges[i];
  4257. // add the span of time before the event (if there is any)
  4258. if (normalRange.start > start) { // compare millisecond time (skip any ambig logic)
  4259. inverseRanges.push({
  4260. event: event0,
  4261. start: start,
  4262. end: normalRange.start
  4263. });
  4264. }
  4265. start = normalRange.end;
  4266. }
  4267. // add the span of time after the last event (if there is any)
  4268. if (start < viewEnd) { // compare millisecond time (skip any ambig logic)
  4269. inverseRanges.push({
  4270. event: event0,
  4271. start: start,
  4272. end: viewEnd
  4273. });
  4274. }
  4275. return inverseRanges;
  4276. },
  4277. // Slices the given event range into one or more segment objects.
  4278. // A `rangeToSegsFunc` custom slicing function can be given.
  4279. eventRangeToSegs: function(eventRange, rangeToSegsFunc) {
  4280. var segs;
  4281. var i, seg;
  4282. if (rangeToSegsFunc) {
  4283. segs = rangeToSegsFunc(eventRange.start, eventRange.end);
  4284. }
  4285. else {
  4286. segs = this.rangeToSegs(eventRange.start, eventRange.end); // defined by the subclass
  4287. }
  4288. for (i = 0; i < segs.length; i++) {
  4289. seg = segs[i];
  4290. seg.event = eventRange.event;
  4291. seg.eventStartMS = eventRange.eventStartMS;
  4292. seg.eventDurationMS = eventRange.eventDurationMS;
  4293. }
  4294. return segs;
  4295. }
  4296. });
  4297. /* Utilities
  4298. ----------------------------------------------------------------------------------------------------------------------*/
  4299. function isBgEvent(event) { // returns true if background OR inverse-background
  4300. var rendering = getEventRendering(event);
  4301. return rendering === 'background' || rendering === 'inverse-background';
  4302. }
  4303. function isInverseBgEvent(event) {
  4304. return getEventRendering(event) === 'inverse-background';
  4305. }
  4306. function getEventRendering(event) {
  4307. return firstDefined((event.source || {}).rendering, event.rendering);
  4308. }
  4309. function groupEventsById(events) {
  4310. var eventsById = {};
  4311. var i, event;
  4312. for (i = 0; i < events.length; i++) {
  4313. event = events[i];
  4314. (eventsById[event._id] || (eventsById[event._id] = [])).push(event);
  4315. }
  4316. return eventsById;
  4317. }
  4318. // A cmp function for determining which non-inverted "ranges" (see above) happen earlier
  4319. function compareNormalRanges(range1, range2) {
  4320. return range1.eventStartMS - range2.eventStartMS; // earlier ranges go first
  4321. }
  4322. // A cmp function for determining which segments should take visual priority
  4323. // DOES NOT WORK ON INVERTED BACKGROUND EVENTS because they have no eventStartMS/eventDurationMS
  4324. function compareSegs(seg1, seg2) {
  4325. return seg1.eventStartMS - seg2.eventStartMS || // earlier events go first
  4326. seg2.eventDurationMS - seg1.eventDurationMS || // tie? longer events go first
  4327. seg2.event.allDay - seg1.event.allDay || // tie? put all-day events first (booleans cast to 0/1)
  4328. (seg1.event.title || '').localeCompare(seg2.event.title); // tie? alphabetically by title
  4329. }
  4330. ;;
  4331. /* A component that renders a grid of whole-days that runs horizontally. There can be multiple rows, one per week.
  4332. ----------------------------------------------------------------------------------------------------------------------*/
  4333. function DayGrid(view) {
  4334. Grid.call(this, view); // call the super-constructor
  4335. }
  4336. DayGrid.prototype = createObject(Grid.prototype); // declare the super-class
  4337. $.extend(DayGrid.prototype, {
  4338. numbersVisible: false, // should render a row for day/week numbers? manually set by the view
  4339. cellDuration: moment.duration({ days: 1 }), // required for Grid.event.js. Each cell is always a single day
  4340. bottomCoordPadding: 0, // hack for extending the hit area for the last row of the coordinate grid
  4341. rowEls: null, // set of fake row elements
  4342. dayEls: null, // set of whole-day elements comprising the row's background
  4343. helperEls: null, // set of cell skeleton elements for rendering the mock event "helper"
  4344. // Renders the rows and columns into the component's `this.el`, which should already be assigned.
  4345. // isRigid determins whether the individual rows should ignore the contents and be a constant height.
  4346. // Relies on the view's colCnt and rowCnt. In the future, this component should probably be self-sufficient.
  4347. render: function(isRigid) {
  4348. var view = this.view;
  4349. var html = '';
  4350. var row;
  4351. for (row = 0; row < view.rowCnt; row++) {
  4352. html += this.dayRowHtml(row, isRigid);
  4353. }
  4354. this.el.html(html);
  4355. this.rowEls = this.el.find('.fc-row');
  4356. this.dayEls = this.el.find('.fc-day');
  4357. // run all the day cells through the dayRender callback
  4358. this.dayEls.each(function(i, node) {
  4359. var date = view.cellToDate(Math.floor(i / view.colCnt), i % view.colCnt);
  4360. view.trigger('dayRender', null, date, $(node));
  4361. });
  4362. Grid.prototype.render.call(this); // call the super-method
  4363. },
  4364. destroy: function() {
  4365. this.destroySegPopover();
  4366. },
  4367. // Generates the HTML for a single row. `row` is the row number.
  4368. dayRowHtml: function(row, isRigid) {
  4369. var view = this.view;
  4370. var classes = [ 'fc-row', 'fc-week', view.widgetContentClass ];
  4371. if (isRigid) {
  4372. classes.push('fc-rigid');
  4373. }
  4374. return '' +
  4375. '<div class="' + classes.join(' ') + '">' +
  4376. '<div class="fc-bg">' +
  4377. '<table>' +
  4378. this.rowHtml('day', row) + // leverages RowRenderer. calls dayCellHtml()
  4379. '</table>' +
  4380. '</div>' +
  4381. '<div class="fc-content-skeleton">' +
  4382. '<table>' +
  4383. (this.numbersVisible ?
  4384. '<thead>' +
  4385. this.rowHtml('number', row) + // leverages RowRenderer. View will define render method
  4386. '</thead>' :
  4387. ''
  4388. ) +
  4389. '</table>' +
  4390. '</div>' +
  4391. '</div>';
  4392. },
  4393. // Renders the HTML for a whole-day cell. Will eventually end up in the day-row's background.
  4394. // We go through a 'day' row type instead of just doing a 'bg' row type so that the View can do custom rendering
  4395. // specifically for whole-day rows, whereas a 'bg' might also be used for other purposes (TimeGrid bg for example).
  4396. dayCellHtml: function(row, col, date) {
  4397. return this.bgCellHtml(row, col, date);
  4398. },
  4399. /* Coordinates & Cells
  4400. ------------------------------------------------------------------------------------------------------------------*/
  4401. // Populates the empty `rows` and `cols` arrays with coordinates of the cells. For CoordGrid.
  4402. buildCoords: function(rows, cols) {
  4403. var colCnt = this.view.colCnt;
  4404. var e, n, p;
  4405. this.dayEls.slice(0, colCnt).each(function(i, _e) { // iterate the first row of day elements
  4406. e = $(_e);
  4407. n = e.offset().left;
  4408. if (i) {
  4409. p[1] = n;
  4410. }
  4411. p = [ n ];
  4412. cols[i] = p;
  4413. });
  4414. p[1] = n + e.outerWidth();
  4415. this.rowEls.each(function(i, _e) {
  4416. e = $(_e);
  4417. n = e.offset().top;
  4418. if (i) {
  4419. p[1] = n;
  4420. }
  4421. p = [ n ];
  4422. rows[i] = p;
  4423. });
  4424. p[1] = n + e.outerHeight() + this.bottomCoordPadding; // hack to extend hit area of last row
  4425. },
  4426. // Converts a cell to a date
  4427. getCellDate: function(cell) {
  4428. return this.view.cellToDate(cell); // leverages the View's cell system
  4429. },
  4430. // Gets the whole-day element associated with the cell
  4431. getCellDayEl: function(cell) {
  4432. return this.dayEls.eq(cell.row * this.view.colCnt + cell.col);
  4433. },
  4434. // Converts a range with an inclusive `start` and an exclusive `end` into an array of segment objects
  4435. rangeToSegs: function(start, end) {
  4436. return this.view.rangeToSegments(start, end); // leverages the View's cell system
  4437. },
  4438. /* Event Drag Visualization
  4439. ------------------------------------------------------------------------------------------------------------------*/
  4440. // Renders a visual indication of an event hovering over the given date(s).
  4441. // `end` can be null, as well as `seg`. See View's documentation on renderDrag for more info.
  4442. // A returned value of `true` signals that a mock "helper" event has been rendered.
  4443. renderDrag: function(start, end, seg) {
  4444. var opacity;
  4445. // always render a highlight underneath
  4446. this.renderHighlight(
  4447. start,
  4448. end || this.view.calendar.getDefaultEventEnd(true, start)
  4449. );
  4450. // if a segment from the same calendar but another component is being dragged, render a helper event
  4451. if (seg && !seg.el.closest(this.el).length) {
  4452. this.renderRangeHelper(start, end, seg);
  4453. opacity = this.view.opt('dragOpacity');
  4454. if (opacity !== undefined) {
  4455. this.helperEls.css('opacity', opacity);
  4456. }
  4457. return true; // a helper has been rendered
  4458. }
  4459. },
  4460. // Unrenders any visual indication of a hovering event
  4461. destroyDrag: function() {
  4462. this.destroyHighlight();
  4463. this.destroyHelper();
  4464. },
  4465. /* Event Resize Visualization
  4466. ------------------------------------------------------------------------------------------------------------------*/
  4467. // Renders a visual indication of an event being resized
  4468. renderResize: function(start, end, seg) {
  4469. this.renderHighlight(start, end);
  4470. this.renderRangeHelper(start, end, seg);
  4471. },
  4472. // Unrenders a visual indication of an event being resized
  4473. destroyResize: function() {
  4474. this.destroyHighlight();
  4475. this.destroyHelper();
  4476. },
  4477. /* Event Helper
  4478. ------------------------------------------------------------------------------------------------------------------*/
  4479. // Renders a mock "helper" event. `sourceSeg` is the associated internal segment object. It can be null.
  4480. renderHelper: function(event, sourceSeg) {
  4481. var helperNodes = [];
  4482. var segs = this.eventsToSegs([ event ]);
  4483. var rowStructs;
  4484. segs = this.renderFgSegEls(segs); // assigns each seg's el and returns a subset of segs that were rendered
  4485. rowStructs = this.renderSegRows(segs);
  4486. // inject each new event skeleton into each associated row
  4487. this.rowEls.each(function(row, rowNode) {
  4488. var rowEl = $(rowNode); // the .fc-row
  4489. var skeletonEl = $('<div class="fc-helper-skeleton"><table/></div>'); // will be absolutely positioned
  4490. var skeletonTop;
  4491. // If there is an original segment, match the top position. Otherwise, put it at the row's top level
  4492. if (sourceSeg && sourceSeg.row === row) {
  4493. skeletonTop = sourceSeg.el.position().top;
  4494. }
  4495. else {
  4496. skeletonTop = rowEl.find('.fc-content-skeleton tbody').position().top;
  4497. }
  4498. skeletonEl.css('top', skeletonTop)
  4499. .find('table')
  4500. .append(rowStructs[row].tbodyEl);
  4501. rowEl.append(skeletonEl);
  4502. helperNodes.push(skeletonEl[0]);
  4503. });
  4504. this.helperEls = $(helperNodes); // array -> jQuery set
  4505. },
  4506. // Unrenders any visual indication of a mock helper event
  4507. destroyHelper: function() {
  4508. if (this.helperEls) {
  4509. this.helperEls.remove();
  4510. this.helperEls = null;
  4511. }
  4512. },
  4513. /* Fill System (highlight, background events, business hours)
  4514. ------------------------------------------------------------------------------------------------------------------*/
  4515. fillSegTag: 'td', // override the default tag name
  4516. // Renders a set of rectangles over the given segments of days.
  4517. // Only returns segments that successfully rendered.
  4518. renderFill: function(type, segs) {
  4519. var nodes = [];
  4520. var i, seg;
  4521. var skeletonEl;
  4522. segs = this.renderFillSegEls(type, segs); // assignes `.el` to each seg. returns successfully rendered segs
  4523. for (i = 0; i < segs.length; i++) {
  4524. seg = segs[i];
  4525. skeletonEl = this.renderFillRow(type, seg);
  4526. this.rowEls.eq(seg.row).append(skeletonEl);
  4527. nodes.push(skeletonEl[0]);
  4528. }
  4529. this.elsByFill[type] = $(nodes);
  4530. return segs;
  4531. },
  4532. // Generates the HTML needed for one row of a fill. Requires the seg's el to be rendered.
  4533. renderFillRow: function(type, seg) {
  4534. var colCnt = this.view.colCnt;
  4535. var startCol = seg.leftCol;
  4536. var endCol = seg.rightCol + 1;
  4537. var skeletonEl;
  4538. var trEl;
  4539. skeletonEl = $(
  4540. '<div class="fc-' + type.toLowerCase() + '-skeleton">' +
  4541. '<table><tr/></table>' +
  4542. '</div>'
  4543. );
  4544. trEl = skeletonEl.find('tr');
  4545. if (startCol > 0) {
  4546. trEl.append('<td colspan="' + startCol + '"/>');
  4547. }
  4548. trEl.append(
  4549. seg.el.attr('colspan', endCol - startCol)
  4550. );
  4551. if (endCol < colCnt) {
  4552. trEl.append('<td colspan="' + (colCnt - endCol) + '"/>');
  4553. }
  4554. this.bookendCells(trEl, type);
  4555. return skeletonEl;
  4556. }
  4557. });
  4558. ;;
  4559. /* Event-rendering methods for the DayGrid class
  4560. ----------------------------------------------------------------------------------------------------------------------*/
  4561. $.extend(DayGrid.prototype, {
  4562. rowStructs: null, // an array of objects, each holding information about a row's foreground event-rendering
  4563. // Unrenders all events currently rendered on the grid
  4564. destroyEvents: function() {
  4565. this.destroySegPopover(); // removes the "more.." events popover
  4566. Grid.prototype.destroyEvents.apply(this, arguments); // calls the super-method
  4567. },
  4568. // Retrieves all rendered segment objects currently rendered on the grid
  4569. getSegs: function() {
  4570. return Grid.prototype.getSegs.call(this) // get the segments from the super-method
  4571. .concat(this.popoverSegs || []); // append the segments from the "more..." popover
  4572. },
  4573. // Renders the given background event segments onto the grid
  4574. renderBgSegs: function(segs) {
  4575. // don't render timed background events
  4576. var allDaySegs = $.grep(segs, function(seg) {
  4577. return seg.event.allDay;
  4578. });
  4579. return Grid.prototype.renderBgSegs.call(this, allDaySegs); // call the super-method
  4580. },
  4581. // Renders the given foreground event segments onto the grid
  4582. renderFgSegs: function(segs) {
  4583. var rowStructs;
  4584. // render an `.el` on each seg
  4585. // returns a subset of the segs. segs that were actually rendered
  4586. segs = this.renderFgSegEls(segs);
  4587. rowStructs = this.rowStructs = this.renderSegRows(segs);
  4588. // append to each row's content skeleton
  4589. this.rowEls.each(function(i, rowNode) {
  4590. $(rowNode).find('.fc-content-skeleton > table').append(
  4591. rowStructs[i].tbodyEl
  4592. );
  4593. });
  4594. return segs; // return only the segs that were actually rendered
  4595. },
  4596. // Unrenders all currently rendered foreground event segments
  4597. destroyFgSegs: function() {
  4598. var rowStructs = this.rowStructs || [];
  4599. var rowStruct;
  4600. while ((rowStruct = rowStructs.pop())) {
  4601. rowStruct.tbodyEl.remove();
  4602. }
  4603. this.rowStructs = null;
  4604. },
  4605. // Uses the given events array to generate <tbody> elements that should be appended to each row's content skeleton.
  4606. // Returns an array of rowStruct objects (see the bottom of `renderSegRow`).
  4607. // PRECONDITION: each segment shoud already have a rendered and assigned `.el`
  4608. renderSegRows: function(segs) {
  4609. var rowStructs = [];
  4610. var segRows;
  4611. var row;
  4612. segRows = this.groupSegRows(segs); // group into nested arrays
  4613. // iterate each row of segment groupings
  4614. for (row = 0; row < segRows.length; row++) {
  4615. rowStructs.push(
  4616. this.renderSegRow(row, segRows[row])
  4617. );
  4618. }
  4619. return rowStructs;
  4620. },
  4621. // Builds the HTML to be used for the default element for an individual segment
  4622. fgSegHtml: function(seg, disableResizing) {
  4623. var view = this.view;
  4624. var isRTL = view.opt('isRTL');
  4625. var event = seg.event;
  4626. var isDraggable = view.isEventDraggable(event);
  4627. var isResizable = !disableResizing && event.allDay && seg.isEnd && view.isEventResizable(event);
  4628. var classes = this.getSegClasses(seg, isDraggable, isResizable);
  4629. var skinCss = this.getEventSkinCss(event);
  4630. var timeHtml = '';
  4631. var titleHtml;
  4632. classes.unshift('fc-day-grid-event');
  4633. // Only display a timed events time if it is the starting segment
  4634. if (!event.allDay && seg.isStart) {
  4635. timeHtml = '<span class="fc-time">' + htmlEscape(view.getEventTimeText(event)) + '</span>';
  4636. }
  4637. titleHtml =
  4638. '<span class="fc-title">' +
  4639. (htmlEscape(event.title || '') || '&nbsp;') + // we always want one line of height
  4640. '</span>';
  4641. return '<a class="' + classes.join(' ') + '"' +
  4642. (event.url ?
  4643. ' href="' + htmlEscape(event.url) + '"' :
  4644. ''
  4645. ) +
  4646. (skinCss ?
  4647. ' style="' + skinCss + '"' :
  4648. ''
  4649. ) +
  4650. '>' +
  4651. '<div class="fc-content">' +
  4652. (isRTL ?
  4653. titleHtml + ' ' + timeHtml : // put a natural space in between
  4654. timeHtml + ' ' + titleHtml //
  4655. ) +
  4656. '</div>' +
  4657. (isResizable ?
  4658. '<div class="fc-resizer"/>' :
  4659. ''
  4660. ) +
  4661. '</a>';
  4662. },
  4663. // Given a row # and an array of segments all in the same row, render a <tbody> element, a skeleton that contains
  4664. // the segments. Returns object with a bunch of internal data about how the render was calculated.
  4665. renderSegRow: function(row, rowSegs) {
  4666. var view = this.view;
  4667. var colCnt = view.colCnt;
  4668. var segLevels = this.buildSegLevels(rowSegs); // group into sub-arrays of levels
  4669. var levelCnt = Math.max(1, segLevels.length); // ensure at least one level
  4670. var tbody = $('<tbody/>');
  4671. var segMatrix = []; // lookup for which segments are rendered into which level+col cells
  4672. var cellMatrix = []; // lookup for all <td> elements of the level+col matrix
  4673. var loneCellMatrix = []; // lookup for <td> elements that only take up a single column
  4674. var i, levelSegs;
  4675. var col;
  4676. var tr;
  4677. var j, seg;
  4678. var td;
  4679. // populates empty cells from the current column (`col`) to `endCol`
  4680. function emptyCellsUntil(endCol) {
  4681. while (col < endCol) {
  4682. // try to grab a cell from the level above and extend its rowspan. otherwise, create a fresh cell
  4683. td = (loneCellMatrix[i - 1] || [])[col];
  4684. if (td) {
  4685. td.attr(
  4686. 'rowspan',
  4687. parseInt(td.attr('rowspan') || 1, 10) + 1
  4688. );
  4689. }
  4690. else {
  4691. td = $('<td/>');
  4692. tr.append(td);
  4693. }
  4694. cellMatrix[i][col] = td;
  4695. loneCellMatrix[i][col] = td;
  4696. col++;
  4697. }
  4698. }
  4699. for (i = 0; i < levelCnt; i++) { // iterate through all levels
  4700. levelSegs = segLevels[i];
  4701. col = 0;
  4702. tr = $('<tr/>');
  4703. segMatrix.push([]);
  4704. cellMatrix.push([]);
  4705. loneCellMatrix.push([]);
  4706. // levelCnt might be 1 even though there are no actual levels. protect against this.
  4707. // this single empty row is useful for styling.
  4708. if (levelSegs) {
  4709. for (j = 0; j < levelSegs.length; j++) { // iterate through segments in level
  4710. seg = levelSegs[j];
  4711. emptyCellsUntil(seg.leftCol);
  4712. // create a container that occupies or more columns. append the event element.
  4713. td = $('<td class="fc-event-container"/>').append(seg.el);
  4714. if (seg.leftCol != seg.rightCol) {
  4715. td.attr('colspan', seg.rightCol - seg.leftCol + 1);
  4716. }
  4717. else { // a single-column segment
  4718. loneCellMatrix[i][col] = td;
  4719. }
  4720. while (col <= seg.rightCol) {
  4721. cellMatrix[i][col] = td;
  4722. segMatrix[i][col] = seg;
  4723. col++;
  4724. }
  4725. tr.append(td);
  4726. }
  4727. }
  4728. emptyCellsUntil(colCnt); // finish off the row
  4729. this.bookendCells(tr, 'eventSkeleton');
  4730. tbody.append(tr);
  4731. }
  4732. return { // a "rowStruct"
  4733. row: row, // the row number
  4734. tbodyEl: tbody,
  4735. cellMatrix: cellMatrix,
  4736. segMatrix: segMatrix,
  4737. segLevels: segLevels,
  4738. segs: rowSegs
  4739. };
  4740. },
  4741. // Stacks a flat array of segments, which are all assumed to be in the same row, into subarrays of vertical levels.
  4742. buildSegLevels: function(segs) {
  4743. var levels = [];
  4744. var i, seg;
  4745. var j;
  4746. // Give preference to elements with certain criteria, so they have
  4747. // a chance to be closer to the top.
  4748. segs.sort(compareSegs);
  4749. for (i = 0; i < segs.length; i++) {
  4750. seg = segs[i];
  4751. // loop through levels, starting with the topmost, until the segment doesn't collide with other segments
  4752. for (j = 0; j < levels.length; j++) {
  4753. if (!isDaySegCollision(seg, levels[j])) {
  4754. break;
  4755. }
  4756. }
  4757. // `j` now holds the desired subrow index
  4758. seg.level = j;
  4759. // create new level array if needed and append segment
  4760. (levels[j] || (levels[j] = [])).push(seg);
  4761. }
  4762. // order segments left-to-right. very important if calendar is RTL
  4763. for (j = 0; j < levels.length; j++) {
  4764. levels[j].sort(compareDaySegCols);
  4765. }
  4766. return levels;
  4767. },
  4768. // Given a flat array of segments, return an array of sub-arrays, grouped by each segment's row
  4769. groupSegRows: function(segs) {
  4770. var view = this.view;
  4771. var segRows = [];
  4772. var i;
  4773. for (i = 0; i < view.rowCnt; i++) {
  4774. segRows.push([]);
  4775. }
  4776. for (i = 0; i < segs.length; i++) {
  4777. segRows[segs[i].row].push(segs[i]);
  4778. }
  4779. return segRows;
  4780. }
  4781. });
  4782. // Computes whether two segments' columns collide. They are assumed to be in the same row.
  4783. function isDaySegCollision(seg, otherSegs) {
  4784. var i, otherSeg;
  4785. for (i = 0; i < otherSegs.length; i++) {
  4786. otherSeg = otherSegs[i];
  4787. if (
  4788. otherSeg.leftCol <= seg.rightCol &&
  4789. otherSeg.rightCol >= seg.leftCol
  4790. ) {
  4791. return true;
  4792. }
  4793. }
  4794. return false;
  4795. }
  4796. // A cmp function for determining the leftmost event
  4797. function compareDaySegCols(a, b) {
  4798. return a.leftCol - b.leftCol;
  4799. }
  4800. ;;
  4801. /* Methods relate to limiting the number events for a given day on a DayGrid
  4802. ----------------------------------------------------------------------------------------------------------------------*/
  4803. // NOTE: all the segs being passed around in here are foreground segs
  4804. $.extend(DayGrid.prototype, {
  4805. segPopover: null, // the Popover that holds events that can't fit in a cell. null when not visible
  4806. popoverSegs: null, // an array of segment objects that the segPopover holds. null when not visible
  4807. destroySegPopover: function() {
  4808. if (this.segPopover) {
  4809. this.segPopover.hide(); // will trigger destruction of `segPopover` and `popoverSegs`
  4810. }
  4811. },
  4812. // Limits the number of "levels" (vertically stacking layers of events) for each row of the grid.
  4813. // `levelLimit` can be false (don't limit), a number, or true (should be computed).
  4814. limitRows: function(levelLimit) {
  4815. var rowStructs = this.rowStructs || [];
  4816. var row; // row #
  4817. var rowLevelLimit;
  4818. for (row = 0; row < rowStructs.length; row++) {
  4819. this.unlimitRow(row);
  4820. if (!levelLimit) {
  4821. rowLevelLimit = false;
  4822. }
  4823. else if (typeof levelLimit === 'number') {
  4824. rowLevelLimit = levelLimit;
  4825. }
  4826. else {
  4827. rowLevelLimit = this.computeRowLevelLimit(row);
  4828. }
  4829. if (rowLevelLimit !== false) {
  4830. this.limitRow(row, rowLevelLimit);
  4831. }
  4832. }
  4833. },
  4834. // Computes the number of levels a row will accomodate without going outside its bounds.
  4835. // Assumes the row is "rigid" (maintains a constant height regardless of what is inside).
  4836. // `row` is the row number.
  4837. computeRowLevelLimit: function(row) {
  4838. var rowEl = this.rowEls.eq(row); // the containing "fake" row div
  4839. var rowHeight = rowEl.height(); // TODO: cache somehow?
  4840. var trEls = this.rowStructs[row].tbodyEl.children();
  4841. var i, trEl;
  4842. // Reveal one level <tr> at a time and stop when we find one out of bounds
  4843. for (i = 0; i < trEls.length; i++) {
  4844. trEl = trEls.eq(i).removeClass('fc-limited'); // get and reveal
  4845. if (trEl.position().top + trEl.outerHeight() > rowHeight) {
  4846. return i;
  4847. }
  4848. }
  4849. return false; // should not limit at all
  4850. },
  4851. // Limits the given grid row to the maximum number of levels and injects "more" links if necessary.
  4852. // `row` is the row number.
  4853. // `levelLimit` is a number for the maximum (inclusive) number of levels allowed.
  4854. limitRow: function(row, levelLimit) {
  4855. var _this = this;
  4856. var view = this.view;
  4857. var rowStruct = this.rowStructs[row];
  4858. var moreNodes = []; // array of "more" <a> links and <td> DOM nodes
  4859. var col = 0; // col #
  4860. var cell;
  4861. var levelSegs; // array of segment objects in the last allowable level, ordered left-to-right
  4862. var cellMatrix; // a matrix (by level, then column) of all <td> jQuery elements in the row
  4863. var limitedNodes; // array of temporarily hidden level <tr> and segment <td> DOM nodes
  4864. var i, seg;
  4865. var segsBelow; // array of segment objects below `seg` in the current `col`
  4866. var totalSegsBelow; // total number of segments below `seg` in any of the columns `seg` occupies
  4867. var colSegsBelow; // array of segment arrays, below seg, one for each column (offset from segs's first column)
  4868. var td, rowspan;
  4869. var segMoreNodes; // array of "more" <td> cells that will stand-in for the current seg's cell
  4870. var j;
  4871. var moreTd, moreWrap, moreLink;
  4872. // Iterates through empty level cells and places "more" links inside if need be
  4873. function emptyCellsUntil(endCol) { // goes from current `col` to `endCol`
  4874. while (col < endCol) {
  4875. cell = { row: row, col: col };
  4876. segsBelow = _this.getCellSegs(cell, levelLimit);
  4877. if (segsBelow.length) {
  4878. td = cellMatrix[levelLimit - 1][col];
  4879. moreLink = _this.renderMoreLink(cell, segsBelow);
  4880. moreWrap = $('<div/>').append(moreLink);
  4881. td.append(moreWrap);
  4882. moreNodes.push(moreWrap[0]);
  4883. }
  4884. col++;
  4885. }
  4886. }
  4887. if (levelLimit && levelLimit < rowStruct.segLevels.length) { // is it actually over the limit?
  4888. levelSegs = rowStruct.segLevels[levelLimit - 1];
  4889. cellMatrix = rowStruct.cellMatrix;
  4890. limitedNodes = rowStruct.tbodyEl.children().slice(levelLimit) // get level <tr> elements past the limit
  4891. .addClass('fc-limited').get(); // hide elements and get a simple DOM-nodes array
  4892. // iterate though segments in the last allowable level
  4893. for (i = 0; i < levelSegs.length; i++) {
  4894. seg = levelSegs[i];
  4895. emptyCellsUntil(seg.leftCol); // process empty cells before the segment
  4896. // determine *all* segments below `seg` that occupy the same columns
  4897. colSegsBelow = [];
  4898. totalSegsBelow = 0;
  4899. while (col <= seg.rightCol) {
  4900. cell = { row: row, col: col };
  4901. segsBelow = this.getCellSegs(cell, levelLimit);
  4902. colSegsBelow.push(segsBelow);
  4903. totalSegsBelow += segsBelow.length;
  4904. col++;
  4905. }
  4906. if (totalSegsBelow) { // do we need to replace this segment with one or many "more" links?
  4907. td = cellMatrix[levelLimit - 1][seg.leftCol]; // the segment's parent cell
  4908. rowspan = td.attr('rowspan') || 1;
  4909. segMoreNodes = [];
  4910. // make a replacement <td> for each column the segment occupies. will be one for each colspan
  4911. for (j = 0; j < colSegsBelow.length; j++) {
  4912. moreTd = $('<td class="fc-more-cell"/>').attr('rowspan', rowspan);
  4913. segsBelow = colSegsBelow[j];
  4914. cell = { row: row, col: seg.leftCol + j };
  4915. moreLink = this.renderMoreLink(cell, [ seg ].concat(segsBelow)); // count seg as hidden too
  4916. moreWrap = $('<div/>').append(moreLink);
  4917. moreTd.append(moreWrap);
  4918. segMoreNodes.push(moreTd[0]);
  4919. moreNodes.push(moreTd[0]);
  4920. }
  4921. td.addClass('fc-limited').after($(segMoreNodes)); // hide original <td> and inject replacements
  4922. limitedNodes.push(td[0]);
  4923. }
  4924. }
  4925. emptyCellsUntil(view.colCnt); // finish off the level
  4926. rowStruct.moreEls = $(moreNodes); // for easy undoing later
  4927. rowStruct.limitedEls = $(limitedNodes); // for easy undoing later
  4928. }
  4929. },
  4930. // Reveals all levels and removes all "more"-related elements for a grid's row.
  4931. // `row` is a row number.
  4932. unlimitRow: function(row) {
  4933. var rowStruct = this.rowStructs[row];
  4934. if (rowStruct.moreEls) {
  4935. rowStruct.moreEls.remove();
  4936. rowStruct.moreEls = null;
  4937. }
  4938. if (rowStruct.limitedEls) {
  4939. rowStruct.limitedEls.removeClass('fc-limited');
  4940. rowStruct.limitedEls = null;
  4941. }
  4942. },
  4943. // Renders an <a> element that represents hidden event element for a cell.
  4944. // Responsible for attaching click handler as well.
  4945. renderMoreLink: function(cell, hiddenSegs) {
  4946. var _this = this;
  4947. var view = this.view;
  4948. return $('<a class="fc-more"/>')
  4949. .text(
  4950. this.getMoreLinkText(hiddenSegs.length)
  4951. )
  4952. .on('click', function(ev) {
  4953. var clickOption = view.opt('eventLimitClick');
  4954. var date = view.cellToDate(cell);
  4955. var moreEl = $(this);
  4956. var dayEl = _this.getCellDayEl(cell);
  4957. var allSegs = _this.getCellSegs(cell);
  4958. // rescope the segments to be within the cell's date
  4959. var reslicedAllSegs = _this.resliceDaySegs(allSegs, date);
  4960. var reslicedHiddenSegs = _this.resliceDaySegs(hiddenSegs, date);
  4961. if (typeof clickOption === 'function') {
  4962. // the returned value can be an atomic option
  4963. clickOption = view.trigger('eventLimitClick', null, {
  4964. date: date,
  4965. dayEl: dayEl,
  4966. moreEl: moreEl,
  4967. segs: reslicedAllSegs,
  4968. hiddenSegs: reslicedHiddenSegs
  4969. }, ev);
  4970. }
  4971. if (clickOption === 'popover') {
  4972. _this.showSegPopover(date, cell, moreEl, reslicedAllSegs);
  4973. }
  4974. else if (typeof clickOption === 'string') { // a view name
  4975. view.calendar.zoomTo(date, clickOption);
  4976. }
  4977. });
  4978. },
  4979. // Reveals the popover that displays all events within a cell
  4980. showSegPopover: function(date, cell, moreLink, segs) {
  4981. var _this = this;
  4982. var view = this.view;
  4983. var moreWrap = moreLink.parent(); // the <div> wrapper around the <a>
  4984. var topEl; // the element we want to match the top coordinate of
  4985. var options;
  4986. if (view.rowCnt == 1) {
  4987. topEl = this.view.el; // will cause the popover to cover any sort of header
  4988. }
  4989. else {
  4990. topEl = this.rowEls.eq(cell.row); // will align with top of row
  4991. }
  4992. options = {
  4993. className: 'fc-more-popover',
  4994. content: this.renderSegPopoverContent(date, segs),
  4995. parentEl: this.el,
  4996. top: topEl.offset().top,
  4997. autoHide: true, // when the user clicks elsewhere, hide the popover
  4998. viewportConstrain: view.opt('popoverViewportConstrain'),
  4999. hide: function() {
  5000. // destroy everything when the popover is hidden
  5001. _this.segPopover.destroy();
  5002. _this.segPopover = null;
  5003. _this.popoverSegs = null;
  5004. }
  5005. };
  5006. // Determine horizontal coordinate.
  5007. // We use the moreWrap instead of the <td> to avoid border confusion.
  5008. if (view.opt('isRTL')) {
  5009. options.right = moreWrap.offset().left + moreWrap.outerWidth() + 1; // +1 to be over cell border
  5010. }
  5011. else {
  5012. options.left = moreWrap.offset().left - 1; // -1 to be over cell border
  5013. }
  5014. this.segPopover = new Popover(options);
  5015. this.segPopover.show();
  5016. },
  5017. // Builds the inner DOM contents of the segment popover
  5018. renderSegPopoverContent: function(date, segs) {
  5019. var view = this.view;
  5020. var isTheme = view.opt('theme');
  5021. var title = date.format(view.opt('dayPopoverFormat'));
  5022. var content = $(
  5023. '<div class="fc-header ' + view.widgetHeaderClass + '">' +
  5024. '<span class="fc-close ' +
  5025. (isTheme ? 'ui-icon ui-icon-closethick' : 'fc-icon fc-icon-x') +
  5026. '"></span>' +
  5027. '<span class="fc-title">' +
  5028. htmlEscape(title) +
  5029. '</span>' +
  5030. '<div class="fc-clear"/>' +
  5031. '</div>' +
  5032. '<div class="fc-body ' + view.widgetContentClass + '">' +
  5033. '<div class="fc-event-container"></div>' +
  5034. '</div>'
  5035. );
  5036. var segContainer = content.find('.fc-event-container');
  5037. var i;
  5038. // render each seg's `el` and only return the visible segs
  5039. segs = this.renderFgSegEls(segs, true); // disableResizing=true
  5040. this.popoverSegs = segs;
  5041. for (i = 0; i < segs.length; i++) {
  5042. // because segments in the popover are not part of a grid coordinate system, provide a hint to any
  5043. // grids that want to do drag-n-drop about which cell it came from
  5044. segs[i].cellDate = date;
  5045. segContainer.append(segs[i].el);
  5046. }
  5047. return content;
  5048. },
  5049. // Given the events within an array of segment objects, reslice them to be in a single day
  5050. resliceDaySegs: function(segs, dayDate) {
  5051. // build an array of the original events
  5052. var events = $.map(segs, function(seg) {
  5053. return seg.event;
  5054. });
  5055. var dayStart = dayDate.clone().stripTime();
  5056. var dayEnd = dayStart.clone().add(1, 'days');
  5057. // slice the events with a custom slicing function
  5058. return this.eventsToSegs(
  5059. events,
  5060. function(rangeStart, rangeEnd) {
  5061. var seg = intersectionToSeg(rangeStart, rangeEnd, dayStart, dayEnd); // if no intersection, undefined
  5062. return seg ? [ seg ] : []; // must return an array of segments
  5063. }
  5064. );
  5065. },
  5066. // Generates the text that should be inside a "more" link, given the number of events it represents
  5067. getMoreLinkText: function(num) {
  5068. var view = this.view;
  5069. var opt = view.opt('eventLimitText');
  5070. if (typeof opt === 'function') {
  5071. return opt(num);
  5072. }
  5073. else {
  5074. return '+' + num + ' ' + opt;
  5075. }
  5076. },
  5077. // Returns segments within a given cell.
  5078. // If `startLevel` is specified, returns only events including and below that level. Otherwise returns all segs.
  5079. getCellSegs: function(cell, startLevel) {
  5080. var segMatrix = this.rowStructs[cell.row].segMatrix;
  5081. var level = startLevel || 0;
  5082. var segs = [];
  5083. var seg;
  5084. while (level < segMatrix.length) {
  5085. seg = segMatrix[level][cell.col];
  5086. if (seg) {
  5087. segs.push(seg);
  5088. }
  5089. level++;
  5090. }
  5091. return segs;
  5092. }
  5093. });
  5094. ;;
  5095. /* A component that renders one or more columns of vertical time slots
  5096. ----------------------------------------------------------------------------------------------------------------------*/
  5097. function TimeGrid(view) {
  5098. Grid.call(this, view); // call the super-constructor
  5099. }
  5100. TimeGrid.prototype = createObject(Grid.prototype); // define the super-class
  5101. $.extend(TimeGrid.prototype, {
  5102. slotDuration: null, // duration of a "slot", a distinct time segment on given day, visualized by lines
  5103. snapDuration: null, // granularity of time for dragging and selecting
  5104. minTime: null, // Duration object that denotes the first visible time of any given day
  5105. maxTime: null, // Duration object that denotes the exclusive visible end time of any given day
  5106. dayEls: null, // cells elements in the day-row background
  5107. slatEls: null, // elements running horizontally across all columns
  5108. slatTops: null, // an array of top positions, relative to the container. last item holds bottom of last slot
  5109. helperEl: null, // cell skeleton element for rendering the mock event "helper"
  5110. businessHourSegs: null,
  5111. // Renders the time grid into `this.el`, which should already be assigned.
  5112. // Relies on the view's colCnt. In the future, this component should probably be self-sufficient.
  5113. render: function() {
  5114. this.processOptions();
  5115. this.el.html(this.renderHtml());
  5116. this.dayEls = this.el.find('.fc-day');
  5117. this.slatEls = this.el.find('.fc-slats tr');
  5118. this.computeSlatTops();
  5119. this.renderBusinessHours();
  5120. Grid.prototype.render.call(this); // call the super-method
  5121. },
  5122. renderBusinessHours: function() {
  5123. var events = this.view.calendar.getBusinessHoursEvents();
  5124. this.businessHourSegs = this.renderFill('businessHours', this.eventsToSegs(events), 'bgevent');
  5125. },
  5126. // Renders the basic HTML skeleton for the grid
  5127. renderHtml: function() {
  5128. return '' +
  5129. '<div class="fc-bg">' +
  5130. '<table>' +
  5131. this.rowHtml('slotBg') + // leverages RowRenderer, which will call slotBgCellHtml
  5132. '</table>' +
  5133. '</div>' +
  5134. '<div class="fc-slats">' +
  5135. '<table>' +
  5136. this.slatRowHtml() +
  5137. '</table>' +
  5138. '</div>';
  5139. },
  5140. // Renders the HTML for a vertical background cell behind the slots.
  5141. // This method is distinct from 'bg' because we wanted a new `rowType` so the View could customize the rendering.
  5142. slotBgCellHtml: function(row, col, date) {
  5143. return this.bgCellHtml(row, col, date);
  5144. },
  5145. // Generates the HTML for the horizontal "slats" that run width-wise. Has a time axis on a side. Depends on RTL.
  5146. slatRowHtml: function() {
  5147. var view = this.view;
  5148. var calendar = view.calendar;
  5149. var isRTL = view.opt('isRTL');
  5150. var html = '';
  5151. var slotNormal = this.slotDuration.asMinutes() % 15 === 0;
  5152. var slotTime = moment.duration(+this.minTime); // wish there was .clone() for durations
  5153. var slotDate; // will be on the view's first day, but we only care about its time
  5154. var minutes;
  5155. var axisHtml;
  5156. // Calculate the time for each slot
  5157. while (slotTime < this.maxTime) {
  5158. slotDate = view.start.clone().time(slotTime); // will be in UTC but that's good. to avoid DST issues
  5159. minutes = slotDate.minutes();
  5160. axisHtml =
  5161. '<td class="fc-axis fc-time ' + view.widgetContentClass + '" ' + view.axisStyleAttr() + '>' +
  5162. ((!slotNormal || !minutes) ? // if irregular slot duration, or on the hour, then display the time
  5163. '<span>' + // for matchCellWidths
  5164. htmlEscape(calendar.formatDate(slotDate, view.opt('axisFormat'))) +
  5165. '</span>' :
  5166. ''
  5167. ) +
  5168. '</td>';
  5169. html +=
  5170. '<tr ' + (!minutes ? '' : 'class="fc-minor"') + '>' +
  5171. (!isRTL ? axisHtml : '') +
  5172. '<td class="' + view.widgetContentClass + '"/>' +
  5173. (isRTL ? axisHtml : '') +
  5174. "</tr>";
  5175. slotTime.add(this.slotDuration);
  5176. }
  5177. return html;
  5178. },
  5179. // Parses various options into properties of this object
  5180. processOptions: function() {
  5181. var view = this.view;
  5182. var slotDuration = view.opt('slotDuration');
  5183. var snapDuration = view.opt('snapDuration');
  5184. slotDuration = moment.duration(slotDuration);
  5185. snapDuration = snapDuration ? moment.duration(snapDuration) : slotDuration;
  5186. this.slotDuration = slotDuration;
  5187. this.snapDuration = snapDuration;
  5188. this.cellDuration = snapDuration; // important to assign this for Grid.events.js
  5189. this.minTime = moment.duration(view.opt('minTime'));
  5190. this.maxTime = moment.duration(view.opt('maxTime'));
  5191. },
  5192. // Slices up a date range into a segment for each column
  5193. rangeToSegs: function(rangeStart, rangeEnd) {
  5194. var view = this.view;
  5195. var segs = [];
  5196. var seg;
  5197. var col;
  5198. var cellDate;
  5199. var colStart, colEnd;
  5200. // normalize
  5201. rangeStart = rangeStart.clone().stripZone();
  5202. rangeEnd = rangeEnd.clone().stripZone();
  5203. for (col = 0; col < view.colCnt; col++) {
  5204. cellDate = view.cellToDate(0, col); // use the View's cell system for this
  5205. colStart = cellDate.clone().time(this.minTime);
  5206. colEnd = cellDate.clone().time(this.maxTime);
  5207. seg = intersectionToSeg(rangeStart, rangeEnd, colStart, colEnd);
  5208. if (seg) {
  5209. seg.col = col;
  5210. segs.push(seg);
  5211. }
  5212. }
  5213. return segs;
  5214. },
  5215. /* Coordinates
  5216. ------------------------------------------------------------------------------------------------------------------*/
  5217. // Called when there is a window resize/zoom and we need to recalculate coordinates for the grid
  5218. resize: function() {
  5219. this.computeSlatTops();
  5220. this.updateSegVerticals();
  5221. },
  5222. // Populates the given empty `rows` and `cols` arrays with offset positions of the "snap" cells.
  5223. // "Snap" cells are different the slots because they might have finer granularity.
  5224. buildCoords: function(rows, cols) {
  5225. var colCnt = this.view.colCnt;
  5226. var originTop = this.el.offset().top;
  5227. var snapTime = moment.duration(+this.minTime);
  5228. var p = null;
  5229. var e, n;
  5230. this.dayEls.slice(0, colCnt).each(function(i, _e) {
  5231. e = $(_e);
  5232. n = e.offset().left;
  5233. if (p) {
  5234. p[1] = n;
  5235. }
  5236. p = [ n ];
  5237. cols[i] = p;
  5238. });
  5239. p[1] = n + e.outerWidth();
  5240. p = null;
  5241. while (snapTime < this.maxTime) {
  5242. n = originTop + this.computeTimeTop(snapTime);
  5243. if (p) {
  5244. p[1] = n;
  5245. }
  5246. p = [ n ];
  5247. rows.push(p);
  5248. snapTime.add(this.snapDuration);
  5249. }
  5250. p[1] = originTop + this.computeTimeTop(snapTime); // the position of the exclusive end
  5251. },
  5252. // Gets the datetime for the given slot cell
  5253. getCellDate: function(cell) {
  5254. var view = this.view;
  5255. var calendar = view.calendar;
  5256. return calendar.rezoneDate( // since we are adding a time, it needs to be in the calendar's timezone
  5257. view.cellToDate(0, cell.col) // View's coord system only accounts for start-of-day for column
  5258. .time(this.minTime + this.snapDuration * cell.row)
  5259. );
  5260. },
  5261. // Gets the element that represents the whole-day the cell resides on
  5262. getCellDayEl: function(cell) {
  5263. return this.dayEls.eq(cell.col);
  5264. },
  5265. // Computes the top coordinate, relative to the bounds of the grid, of the given date.
  5266. // A `startOfDayDate` must be given for avoiding ambiguity over how to treat midnight.
  5267. computeDateTop: function(date, startOfDayDate) {
  5268. return this.computeTimeTop(
  5269. moment.duration(
  5270. date.clone().stripZone() - startOfDayDate.clone().stripTime()
  5271. )
  5272. );
  5273. },
  5274. // Computes the top coordinate, relative to the bounds of the grid, of the given time (a Duration).
  5275. computeTimeTop: function(time) {
  5276. var slatCoverage = (time - this.minTime) / this.slotDuration; // floating-point value of # of slots covered
  5277. var slatIndex;
  5278. var slatRemainder;
  5279. var slatTop;
  5280. var slatBottom;
  5281. // constrain. because minTime/maxTime might be customized
  5282. slatCoverage = Math.max(0, slatCoverage);
  5283. slatCoverage = Math.min(this.slatEls.length, slatCoverage);
  5284. slatIndex = Math.floor(slatCoverage); // an integer index of the furthest whole slot
  5285. slatRemainder = slatCoverage - slatIndex;
  5286. slatTop = this.slatTops[slatIndex]; // the top position of the furthest whole slot
  5287. if (slatRemainder) { // time spans part-way into the slot
  5288. slatBottom = this.slatTops[slatIndex + 1];
  5289. return slatTop + (slatBottom - slatTop) * slatRemainder; // part-way between slots
  5290. }
  5291. else {
  5292. return slatTop;
  5293. }
  5294. },
  5295. // Queries each `slatEl` for its position relative to the grid's container and stores it in `slatTops`.
  5296. // Includes the the bottom of the last slat as the last item in the array.
  5297. computeSlatTops: function() {
  5298. var tops = [];
  5299. var top;
  5300. this.slatEls.each(function(i, node) {
  5301. top = $(node).position().top;
  5302. tops.push(top);
  5303. });
  5304. tops.push(top + this.slatEls.last().outerHeight()); // bottom of the last slat
  5305. this.slatTops = tops;
  5306. },
  5307. /* Event Drag Visualization
  5308. ------------------------------------------------------------------------------------------------------------------*/
  5309. // Renders a visual indication of an event being dragged over the specified date(s).
  5310. // `end` and `seg` can be null. See View's documentation on renderDrag for more info.
  5311. renderDrag: function(start, end, seg) {
  5312. var opacity;
  5313. if (seg) { // if there is event information for this drag, render a helper event
  5314. this.renderRangeHelper(start, end, seg);
  5315. opacity = this.view.opt('dragOpacity');
  5316. if (opacity !== undefined) {
  5317. this.helperEl.css('opacity', opacity);
  5318. }
  5319. return true; // signal that a helper has been rendered
  5320. }
  5321. else {
  5322. // otherwise, just render a highlight
  5323. this.renderHighlight(
  5324. start,
  5325. end || this.view.calendar.getDefaultEventEnd(false, start)
  5326. );
  5327. }
  5328. },
  5329. // Unrenders any visual indication of an event being dragged
  5330. destroyDrag: function() {
  5331. this.destroyHelper();
  5332. this.destroyHighlight();
  5333. },
  5334. /* Event Resize Visualization
  5335. ------------------------------------------------------------------------------------------------------------------*/
  5336. // Renders a visual indication of an event being resized
  5337. renderResize: function(start, end, seg) {
  5338. this.renderRangeHelper(start, end, seg);
  5339. },
  5340. // Unrenders any visual indication of an event being resized
  5341. destroyResize: function() {
  5342. this.destroyHelper();
  5343. },
  5344. /* Event Helper
  5345. ------------------------------------------------------------------------------------------------------------------*/
  5346. // Renders a mock "helper" event. `sourceSeg` is the original segment object and might be null (an external drag)
  5347. renderHelper: function(event, sourceSeg) {
  5348. var segs = this.eventsToSegs([ event ]);
  5349. var tableEl;
  5350. var i, seg;
  5351. var sourceEl;
  5352. segs = this.renderFgSegEls(segs); // assigns each seg's el and returns a subset of segs that were rendered
  5353. tableEl = this.renderSegTable(segs);
  5354. // Try to make the segment that is in the same row as sourceSeg look the same
  5355. for (i = 0; i < segs.length; i++) {
  5356. seg = segs[i];
  5357. if (sourceSeg && sourceSeg.col === seg.col) {
  5358. sourceEl = sourceSeg.el;
  5359. seg.el.css({
  5360. left: sourceEl.css('left'),
  5361. right: sourceEl.css('right'),
  5362. 'margin-left': sourceEl.css('margin-left'),
  5363. 'margin-right': sourceEl.css('margin-right')
  5364. });
  5365. }
  5366. }
  5367. this.helperEl = $('<div class="fc-helper-skeleton"/>')
  5368. .append(tableEl)
  5369. .appendTo(this.el);
  5370. },
  5371. // Unrenders any mock helper event
  5372. destroyHelper: function() {
  5373. if (this.helperEl) {
  5374. this.helperEl.remove();
  5375. this.helperEl = null;
  5376. }
  5377. },
  5378. /* Selection
  5379. ------------------------------------------------------------------------------------------------------------------*/
  5380. // Renders a visual indication of a selection. Overrides the default, which was to simply render a highlight.
  5381. renderSelection: function(start, end) {
  5382. if (this.view.opt('selectHelper')) { // this setting signals that a mock helper event should be rendered
  5383. this.renderRangeHelper(start, end);
  5384. }
  5385. else {
  5386. this.renderHighlight(start, end);
  5387. }
  5388. },
  5389. // Unrenders any visual indication of a selection
  5390. destroySelection: function() {
  5391. this.destroyHelper();
  5392. this.destroyHighlight();
  5393. },
  5394. /* Fill System (highlight, background events, business hours)
  5395. ------------------------------------------------------------------------------------------------------------------*/
  5396. // Renders a set of rectangles over the given time segments.
  5397. // Only returns segments that successfully rendered.
  5398. renderFill: function(type, segs, className) {
  5399. var view = this.view;
  5400. var segCols;
  5401. var skeletonEl;
  5402. var trEl;
  5403. var col, colSegs;
  5404. var tdEl;
  5405. var containerEl;
  5406. var dayDate;
  5407. var i, seg;
  5408. if (segs.length) {
  5409. segs = this.renderFillSegEls(type, segs); // assignes `.el` to each seg. returns successfully rendered segs
  5410. segCols = this.groupSegCols(segs); // group into sub-arrays, and assigns 'col' to each seg
  5411. className = className || type.toLowerCase();
  5412. skeletonEl = $(
  5413. '<div class="fc-' + className + '-skeleton">' +
  5414. '<table><tr/></table>' +
  5415. '</div>'
  5416. );
  5417. trEl = skeletonEl.find('tr');
  5418. for (col = 0; col < segCols.length; col++) {
  5419. colSegs = segCols[col];
  5420. tdEl = $('<td/>').appendTo(trEl);
  5421. if (colSegs.length) {
  5422. containerEl = $('<div class="fc-' + className + '-container"/>').appendTo(tdEl);
  5423. dayDate = view.cellToDate(0, col);
  5424. for (i = 0; i < colSegs.length; i++) {
  5425. seg = colSegs[i];
  5426. containerEl.append(
  5427. seg.el.css({
  5428. top: this.computeDateTop(seg.start, dayDate),
  5429. bottom: -this.computeDateTop(seg.end, dayDate) // the y position of the bottom edge
  5430. })
  5431. );
  5432. }
  5433. }
  5434. }
  5435. this.bookendCells(trEl, type);
  5436. this.el.append(skeletonEl);
  5437. this.elsByFill[type] = skeletonEl;
  5438. }
  5439. return segs;
  5440. }
  5441. });
  5442. ;;
  5443. /* Event-rendering methods for the TimeGrid class
  5444. ----------------------------------------------------------------------------------------------------------------------*/
  5445. $.extend(TimeGrid.prototype, {
  5446. eventSkeletonEl: null, // has cells with event-containers, which contain absolutely positioned event elements
  5447. // Renders the given foreground event segments onto the grid
  5448. renderFgSegs: function(segs) {
  5449. segs = this.renderFgSegEls(segs); // returns a subset of the segs. segs that were actually rendered
  5450. this.el.append(
  5451. this.eventSkeletonEl = $('<div class="fc-content-skeleton"/>')
  5452. .append(this.renderSegTable(segs))
  5453. );
  5454. return segs; // return only the segs that were actually rendered
  5455. },
  5456. // Unrenders all currently rendered foreground event segments
  5457. destroyFgSegs: function(segs) {
  5458. if (this.eventSkeletonEl) {
  5459. this.eventSkeletonEl.remove();
  5460. this.eventSkeletonEl = null;
  5461. }
  5462. },
  5463. // Renders and returns the <table> portion of the event-skeleton.
  5464. // Returns an object with properties 'tbodyEl' and 'segs'.
  5465. renderSegTable: function(segs) {
  5466. var tableEl = $('<table><tr/></table>');
  5467. var trEl = tableEl.find('tr');
  5468. var segCols;
  5469. var i, seg;
  5470. var col, colSegs;
  5471. var containerEl;
  5472. segCols = this.groupSegCols(segs); // group into sub-arrays, and assigns 'col' to each seg
  5473. this.computeSegVerticals(segs); // compute and assign top/bottom
  5474. for (col = 0; col < segCols.length; col++) { // iterate each column grouping
  5475. colSegs = segCols[col];
  5476. placeSlotSegs(colSegs); // compute horizontal coordinates, z-index's, and reorder the array
  5477. containerEl = $('<div class="fc-event-container"/>');
  5478. // assign positioning CSS and insert into container
  5479. for (i = 0; i < colSegs.length; i++) {
  5480. seg = colSegs[i];
  5481. seg.el.css(this.generateSegPositionCss(seg));
  5482. // if the height is short, add a className for alternate styling
  5483. if (seg.bottom - seg.top < 30) {
  5484. seg.el.addClass('fc-short');
  5485. }
  5486. containerEl.append(seg.el);
  5487. }
  5488. trEl.append($('<td/>').append(containerEl));
  5489. }
  5490. this.bookendCells(trEl, 'eventSkeleton');
  5491. return tableEl;
  5492. },
  5493. // Refreshes the CSS top/bottom coordinates for each segment element. Probably after a window resize/zoom.
  5494. // Repositions business hours segs too, so not just for events. Maybe shouldn't be here.
  5495. updateSegVerticals: function() {
  5496. var allSegs = (this.segs || []).concat(this.businessHourSegs || []);
  5497. var i;
  5498. this.computeSegVerticals(allSegs);
  5499. for (i = 0; i < allSegs.length; i++) {
  5500. allSegs[i].el.css(
  5501. this.generateSegVerticalCss(allSegs[i])
  5502. );
  5503. }
  5504. },
  5505. // For each segment in an array, computes and assigns its top and bottom properties
  5506. computeSegVerticals: function(segs) {
  5507. var i, seg;
  5508. for (i = 0; i < segs.length; i++) {
  5509. seg = segs[i];
  5510. seg.top = this.computeDateTop(seg.start, seg.start);
  5511. seg.bottom = this.computeDateTop(seg.end, seg.start);
  5512. }
  5513. },
  5514. // Renders the HTML for a single event segment's default rendering
  5515. fgSegHtml: function(seg, disableResizing) {
  5516. var view = this.view;
  5517. var event = seg.event;
  5518. var isDraggable = view.isEventDraggable(event);
  5519. var isResizable = !disableResizing && seg.isEnd && view.isEventResizable(event);
  5520. var classes = this.getSegClasses(seg, isDraggable, isResizable);
  5521. var skinCss = this.getEventSkinCss(event);
  5522. var timeText;
  5523. var fullTimeText; // more verbose time text. for the print stylesheet
  5524. var startTimeText; // just the start time text
  5525. classes.unshift('fc-time-grid-event');
  5526. if (view.isMultiDayEvent(event)) { // if the event appears to span more than one day...
  5527. // Don't display time text on segments that run entirely through a day.
  5528. // That would appear as midnight-midnight and would look dumb.
  5529. // Otherwise, display the time text for the *segment's* times (like 6pm-midnight or midnight-10am)
  5530. if (seg.isStart || seg.isEnd) {
  5531. timeText = view.getEventTimeText(seg.start, seg.end);
  5532. fullTimeText = view.getEventTimeText(seg.start, seg.end, 'LT');
  5533. startTimeText = view.getEventTimeText(seg.start, null);
  5534. }
  5535. } else {
  5536. // Display the normal time text for the *event's* times
  5537. timeText = view.getEventTimeText(event);
  5538. fullTimeText = view.getEventTimeText(event, 'LT');
  5539. startTimeText = view.getEventTimeText(event.start, null);
  5540. }
  5541. return '<a class="' + classes.join(' ') + '"' +
  5542. (event.url ?
  5543. ' href="' + htmlEscape(event.url) + '"' :
  5544. ''
  5545. ) +
  5546. (skinCss ?
  5547. ' style="' + skinCss + '"' :
  5548. ''
  5549. ) +
  5550. '>' +
  5551. '<div class="fc-content">' +
  5552. (timeText ?
  5553. '<div class="fc-time"' +
  5554. ' data-start="' + htmlEscape(startTimeText) + '"' +
  5555. ' data-full="' + htmlEscape(fullTimeText) + '"' +
  5556. '>' +
  5557. '<span>' + htmlEscape(timeText) + '</span>' +
  5558. '</div>' :
  5559. ''
  5560. ) +
  5561. (event.title ?
  5562. '<div class="fc-title">' +
  5563. htmlEscape(event.title) +
  5564. '</div>' :
  5565. ''
  5566. ) +
  5567. '</div>' +
  5568. '<div class="fc-bg"/>' +
  5569. (isResizable ?
  5570. '<div class="fc-resizer"/>' :
  5571. ''
  5572. ) +
  5573. '</a>';
  5574. },
  5575. // Generates an object with CSS properties/values that should be applied to an event segment element.
  5576. // Contains important positioning-related properties that should be applied to any event element, customized or not.
  5577. generateSegPositionCss: function(seg) {
  5578. var view = this.view;
  5579. var isRTL = view.opt('isRTL');
  5580. var shouldOverlap = view.opt('slotEventOverlap');
  5581. var backwardCoord = seg.backwardCoord; // the left side if LTR. the right side if RTL. floating-point
  5582. var forwardCoord = seg.forwardCoord; // the right side if LTR. the left side if RTL. floating-point
  5583. var props = this.generateSegVerticalCss(seg); // get top/bottom first
  5584. var left; // amount of space from left edge, a fraction of the total width
  5585. var right; // amount of space from right edge, a fraction of the total width
  5586. if (shouldOverlap) {
  5587. // double the width, but don't go beyond the maximum forward coordinate (1.0)
  5588. forwardCoord = Math.min(1, backwardCoord + (forwardCoord - backwardCoord) * 2);
  5589. }
  5590. if (isRTL) {
  5591. left = 1 - forwardCoord;
  5592. right = backwardCoord;
  5593. }
  5594. else {
  5595. left = backwardCoord;
  5596. right = 1 - forwardCoord;
  5597. }
  5598. props.zIndex = seg.level + 1; // convert from 0-base to 1-based
  5599. props.left = left * 100 + '%';
  5600. props.right = right * 100 + '%';
  5601. if (shouldOverlap && seg.forwardPressure) {
  5602. // add padding to the edge so that forward stacked events don't cover the resizer's icon
  5603. props[isRTL ? 'marginLeft' : 'marginRight'] = 10 * 2; // 10 is a guesstimate of the icon's width
  5604. }
  5605. return props;
  5606. },
  5607. // Generates an object with CSS properties for the top/bottom coordinates of a segment element
  5608. generateSegVerticalCss: function(seg) {
  5609. return {
  5610. top: seg.top,
  5611. bottom: -seg.bottom // flipped because needs to be space beyond bottom edge of event container
  5612. };
  5613. },
  5614. // Given a flat array of segments, return an array of sub-arrays, grouped by each segment's col
  5615. groupSegCols: function(segs) {
  5616. var view = this.view;
  5617. var segCols = [];
  5618. var i;
  5619. for (i = 0; i < view.colCnt; i++) {
  5620. segCols.push([]);
  5621. }
  5622. for (i = 0; i < segs.length; i++) {
  5623. segCols[segs[i].col].push(segs[i]);
  5624. }
  5625. return segCols;
  5626. }
  5627. });
  5628. // Given an array of segments that are all in the same column, sets the backwardCoord and forwardCoord on each.
  5629. // Also reorders the given array by date!
  5630. function placeSlotSegs(segs) {
  5631. var levels;
  5632. var level0;
  5633. var i;
  5634. segs.sort(compareSegs); // order by date
  5635. levels = buildSlotSegLevels(segs);
  5636. computeForwardSlotSegs(levels);
  5637. if ((level0 = levels[0])) {
  5638. for (i = 0; i < level0.length; i++) {
  5639. computeSlotSegPressures(level0[i]);
  5640. }
  5641. for (i = 0; i < level0.length; i++) {
  5642. computeSlotSegCoords(level0[i], 0, 0);
  5643. }
  5644. }
  5645. }
  5646. // Builds an array of segments "levels". The first level will be the leftmost tier of segments if the calendar is
  5647. // left-to-right, or the rightmost if the calendar is right-to-left. Assumes the segments are already ordered by date.
  5648. function buildSlotSegLevels(segs) {
  5649. var levels = [];
  5650. var i, seg;
  5651. var j;
  5652. for (i=0; i<segs.length; i++) {
  5653. seg = segs[i];
  5654. // go through all the levels and stop on the first level where there are no collisions
  5655. for (j=0; j<levels.length; j++) {
  5656. if (!computeSlotSegCollisions(seg, levels[j]).length) {
  5657. break;
  5658. }
  5659. }
  5660. seg.level = j;
  5661. (levels[j] || (levels[j] = [])).push(seg);
  5662. }
  5663. return levels;
  5664. }
  5665. // For every segment, figure out the other segments that are in subsequent
  5666. // levels that also occupy the same vertical space. Accumulate in seg.forwardSegs
  5667. function computeForwardSlotSegs(levels) {
  5668. var i, level;
  5669. var j, seg;
  5670. var k;
  5671. for (i=0; i<levels.length; i++) {
  5672. level = levels[i];
  5673. for (j=0; j<level.length; j++) {
  5674. seg = level[j];
  5675. seg.forwardSegs = [];
  5676. for (k=i+1; k<levels.length; k++) {
  5677. computeSlotSegCollisions(seg, levels[k], seg.forwardSegs);
  5678. }
  5679. }
  5680. }
  5681. }
  5682. // Figure out which path forward (via seg.forwardSegs) results in the longest path until
  5683. // the furthest edge is reached. The number of segments in this path will be seg.forwardPressure
  5684. function computeSlotSegPressures(seg) {
  5685. var forwardSegs = seg.forwardSegs;
  5686. var forwardPressure = 0;
  5687. var i, forwardSeg;
  5688. if (seg.forwardPressure === undefined) { // not already computed
  5689. for (i=0; i<forwardSegs.length; i++) {
  5690. forwardSeg = forwardSegs[i];
  5691. // figure out the child's maximum forward path
  5692. computeSlotSegPressures(forwardSeg);
  5693. // either use the existing maximum, or use the child's forward pressure
  5694. // plus one (for the forwardSeg itself)
  5695. forwardPressure = Math.max(
  5696. forwardPressure,
  5697. 1 + forwardSeg.forwardPressure
  5698. );
  5699. }
  5700. seg.forwardPressure = forwardPressure;
  5701. }
  5702. }
  5703. // Calculate seg.forwardCoord and seg.backwardCoord for the segment, where both values range
  5704. // from 0 to 1. If the calendar is left-to-right, the seg.backwardCoord maps to "left" and
  5705. // seg.forwardCoord maps to "right" (via percentage). Vice-versa if the calendar is right-to-left.
  5706. //
  5707. // The segment might be part of a "series", which means consecutive segments with the same pressure
  5708. // who's width is unknown until an edge has been hit. `seriesBackwardPressure` is the number of
  5709. // segments behind this one in the current series, and `seriesBackwardCoord` is the starting
  5710. // coordinate of the first segment in the series.
  5711. function computeSlotSegCoords(seg, seriesBackwardPressure, seriesBackwardCoord) {
  5712. var forwardSegs = seg.forwardSegs;
  5713. var i;
  5714. if (seg.forwardCoord === undefined) { // not already computed
  5715. if (!forwardSegs.length) {
  5716. // if there are no forward segments, this segment should butt up against the edge
  5717. seg.forwardCoord = 1;
  5718. }
  5719. else {
  5720. // sort highest pressure first
  5721. forwardSegs.sort(compareForwardSlotSegs);
  5722. // this segment's forwardCoord will be calculated from the backwardCoord of the
  5723. // highest-pressure forward segment.
  5724. computeSlotSegCoords(forwardSegs[0], seriesBackwardPressure + 1, seriesBackwardCoord);
  5725. seg.forwardCoord = forwardSegs[0].backwardCoord;
  5726. }
  5727. // calculate the backwardCoord from the forwardCoord. consider the series
  5728. seg.backwardCoord = seg.forwardCoord -
  5729. (seg.forwardCoord - seriesBackwardCoord) / // available width for series
  5730. (seriesBackwardPressure + 1); // # of segments in the series
  5731. // use this segment's coordinates to computed the coordinates of the less-pressurized
  5732. // forward segments
  5733. for (i=0; i<forwardSegs.length; i++) {
  5734. computeSlotSegCoords(forwardSegs[i], 0, seg.forwardCoord);
  5735. }
  5736. }
  5737. }
  5738. // Find all the segments in `otherSegs` that vertically collide with `seg`.
  5739. // Append into an optionally-supplied `results` array and return.
  5740. function computeSlotSegCollisions(seg, otherSegs, results) {
  5741. results = results || [];
  5742. for (var i=0; i<otherSegs.length; i++) {
  5743. if (isSlotSegCollision(seg, otherSegs[i])) {
  5744. results.push(otherSegs[i]);
  5745. }
  5746. }
  5747. return results;
  5748. }
  5749. // Do these segments occupy the same vertical space?
  5750. function isSlotSegCollision(seg1, seg2) {
  5751. return seg1.bottom > seg2.top && seg1.top < seg2.bottom;
  5752. }
  5753. // A cmp function for determining which forward segment to rely on more when computing coordinates.
  5754. function compareForwardSlotSegs(seg1, seg2) {
  5755. // put higher-pressure first
  5756. return seg2.forwardPressure - seg1.forwardPressure ||
  5757. // put segments that are closer to initial edge first (and favor ones with no coords yet)
  5758. (seg1.backwardCoord || 0) - (seg2.backwardCoord || 0) ||
  5759. // do normal sorting...
  5760. compareSegs(seg1, seg2);
  5761. }
  5762. ;;
  5763. /* An abstract class from which other views inherit from
  5764. ----------------------------------------------------------------------------------------------------------------------*/
  5765. // Newer methods should be written as prototype methods, not in the monster `View` function at the bottom.
  5766. View.prototype = {
  5767. calendar: null, // owner Calendar object
  5768. coordMap: null, // a CoordMap object for converting pixel regions to dates
  5769. el: null, // the view's containing element. set by Calendar
  5770. // important Moments
  5771. start: null, // the date of the very first cell
  5772. end: null, // the date after the very last cell
  5773. intervalStart: null, // the start of the interval of time the view represents (1st of month for month view)
  5774. intervalEnd: null, // the exclusive end of the interval of time the view represents
  5775. // used for cell-to-date and date-to-cell calculations
  5776. rowCnt: null, // # of weeks
  5777. colCnt: null, // # of days displayed in a week
  5778. isSelected: false, // boolean whether cells are user-selected or not
  5779. // subclasses can optionally use a scroll container
  5780. scrollerEl: null, // the element that will most likely scroll when content is too tall
  5781. scrollTop: null, // cached vertical scroll value
  5782. // classNames styled by jqui themes
  5783. widgetHeaderClass: null,
  5784. widgetContentClass: null,
  5785. highlightStateClass: null,
  5786. // document handlers, bound to `this` object
  5787. documentMousedownProxy: null,
  5788. documentDragStartProxy: null,
  5789. // Serves as a "constructor" to suppliment the monster `View` constructor below
  5790. init: function() {
  5791. var tm = this.opt('theme') ? 'ui' : 'fc';
  5792. this.widgetHeaderClass = tm + '-widget-header';
  5793. this.widgetContentClass = tm + '-widget-content';
  5794. this.highlightStateClass = tm + '-state-highlight';
  5795. // save references to `this`-bound handlers
  5796. this.documentMousedownProxy = $.proxy(this, 'documentMousedown');
  5797. this.documentDragStartProxy = $.proxy(this, 'documentDragStart');
  5798. },
  5799. // Renders the view inside an already-defined `this.el`.
  5800. // Subclasses should override this and then call the super method afterwards.
  5801. render: function() {
  5802. this.updateSize();
  5803. this.trigger('viewRender', this, this, this.el);
  5804. // attach handlers to document. do it here to allow for destroy/rerender
  5805. $(document)
  5806. .on('mousedown', this.documentMousedownProxy)
  5807. .on('dragstart', this.documentDragStartProxy); // jqui drag
  5808. },
  5809. // Clears all view rendering, event elements, and unregisters handlers
  5810. destroy: function() {
  5811. this.unselect();
  5812. this.trigger('viewDestroy', this, this, this.el);
  5813. this.destroyEvents();
  5814. this.el.empty(); // removes inner contents but leaves the element intact
  5815. $(document)
  5816. .off('mousedown', this.documentMousedownProxy)
  5817. .off('dragstart', this.documentDragStartProxy);
  5818. },
  5819. // Used to determine what happens when the users clicks next/prev. Given -1 for prev, 1 for next.
  5820. // Should apply the delta to `date` (a Moment) and return it.
  5821. incrementDate: function(date, delta) {
  5822. // subclasses should implement
  5823. },
  5824. /* Dimensions
  5825. ------------------------------------------------------------------------------------------------------------------*/
  5826. // Refreshes anything dependant upon sizing of the container element of the grid
  5827. updateSize: function(isResize) {
  5828. if (isResize) {
  5829. this.recordScroll();
  5830. }
  5831. this.updateHeight();
  5832. this.updateWidth();
  5833. },
  5834. // Refreshes the horizontal dimensions of the calendar
  5835. updateWidth: function() {
  5836. // subclasses should implement
  5837. },
  5838. // Refreshes the vertical dimensions of the calendar
  5839. updateHeight: function() {
  5840. var calendar = this.calendar; // we poll the calendar for height information
  5841. this.setHeight(
  5842. calendar.getSuggestedViewHeight(),
  5843. calendar.isHeightAuto()
  5844. );
  5845. },
  5846. // Updates the vertical dimensions of the calendar to the specified height.
  5847. // if `isAuto` is set to true, height becomes merely a suggestion and the view should use its "natural" height.
  5848. setHeight: function(height, isAuto) {
  5849. // subclasses should implement
  5850. },
  5851. // Given the total height of the view, return the number of pixels that should be used for the scroller.
  5852. // Utility for subclasses.
  5853. computeScrollerHeight: function(totalHeight) {
  5854. var both = this.el.add(this.scrollerEl);
  5855. var otherHeight; // cumulative height of everything that is not the scrollerEl in the view (header+borders)
  5856. // fuckin IE8/9/10/11 sometimes returns 0 for dimensions. this weird hack was the only thing that worked
  5857. both.css({
  5858. position: 'relative', // cause a reflow, which will force fresh dimension recalculation
  5859. left: -1 // ensure reflow in case the el was already relative. negative is less likely to cause new scroll
  5860. });
  5861. otherHeight = this.el.outerHeight() - this.scrollerEl.height(); // grab the dimensions
  5862. both.css({ position: '', left: '' }); // undo hack
  5863. return totalHeight - otherHeight;
  5864. },
  5865. // Called for remembering the current scroll value of the scroller.
  5866. // Should be called before there is a destructive operation (like removing DOM elements) that might inadvertently
  5867. // change the scroll of the container.
  5868. recordScroll: function() {
  5869. if (this.scrollerEl) {
  5870. this.scrollTop = this.scrollerEl.scrollTop();
  5871. }
  5872. },
  5873. // Set the scroll value of the scroller to the previously recorded value.
  5874. // Should be called after we know the view's dimensions have been restored following some type of destructive
  5875. // operation (like temporarily removing DOM elements).
  5876. restoreScroll: function() {
  5877. if (this.scrollTop !== null) {
  5878. this.scrollerEl.scrollTop(this.scrollTop);
  5879. }
  5880. },
  5881. /* Events
  5882. ------------------------------------------------------------------------------------------------------------------*/
  5883. // Renders the events onto the view.
  5884. // Should be overriden by subclasses. Subclasses should call the super-method afterwards.
  5885. renderEvents: function(events) {
  5886. this.segEach(function(seg) {
  5887. this.trigger('eventAfterRender', seg.event, seg.event, seg.el);
  5888. });
  5889. this.trigger('eventAfterAllRender');
  5890. },
  5891. // Removes event elements from the view.
  5892. // Should be overridden by subclasses. Should call this super-method FIRST, then subclass DOM destruction.
  5893. destroyEvents: function() {
  5894. this.segEach(function(seg) {
  5895. this.trigger('eventDestroy', seg.event, seg.event, seg.el);
  5896. });
  5897. },
  5898. // Given an event and the default element used for rendering, returns the element that should actually be used.
  5899. // Basically runs events and elements through the eventRender hook.
  5900. resolveEventEl: function(event, el) {
  5901. var custom = this.trigger('eventRender', event, event, el);
  5902. if (custom === false) { // means don't render at all
  5903. el = null;
  5904. }
  5905. else if (custom && custom !== true) {
  5906. el = $(custom);
  5907. }
  5908. return el;
  5909. },
  5910. // Hides all rendered event segments linked to the given event
  5911. showEvent: function(event) {
  5912. this.segEach(function(seg) {
  5913. seg.el.css('visibility', '');
  5914. }, event);
  5915. },
  5916. // Shows all rendered event segments linked to the given event
  5917. hideEvent: function(event) {
  5918. this.segEach(function(seg) {
  5919. seg.el.css('visibility', 'hidden');
  5920. }, event);
  5921. },
  5922. // Iterates through event segments. Goes through all by default.
  5923. // If the optional `event` argument is specified, only iterates through segments linked to that event.
  5924. // The `this` value of the callback function will be the view.
  5925. segEach: function(func, event) {
  5926. var segs = this.getSegs();
  5927. var i;
  5928. for (i = 0; i < segs.length; i++) {
  5929. if (!event || segs[i].event._id === event._id) {
  5930. func.call(this, segs[i]);
  5931. }
  5932. }
  5933. },
  5934. // Retrieves all the rendered segment objects for the view
  5935. getSegs: function() {
  5936. // subclasses must implement
  5937. },
  5938. /* Event Drag Visualization
  5939. ------------------------------------------------------------------------------------------------------------------*/
  5940. // Renders a visual indication of an event hovering over the specified date.
  5941. // `end` is a Moment and might be null.
  5942. // `seg` might be null. if specified, it is the segment object of the event being dragged.
  5943. // otherwise, an external event from outside the calendar is being dragged.
  5944. renderDrag: function(start, end, seg) {
  5945. // subclasses should implement
  5946. },
  5947. // Unrenders a visual indication of event hovering
  5948. destroyDrag: function() {
  5949. // subclasses should implement
  5950. },
  5951. // Handler for accepting externally dragged events being dropped in the view.
  5952. // Gets called when jqui's 'dragstart' is fired.
  5953. documentDragStart: function(ev, ui) {
  5954. var _this = this;
  5955. var calendar = this.calendar;
  5956. var eventStart = null; // a null value signals an unsuccessful drag
  5957. var eventEnd = null;
  5958. var visibleEnd = null; // will be calculated event when no eventEnd
  5959. var el;
  5960. var accept;
  5961. var meta;
  5962. var eventProps; // if an object, signals an event should be created upon drop
  5963. var dragListener;
  5964. if (this.opt('droppable')) { // only listen if this setting is on
  5965. el = $(ev.target);
  5966. // Test that the dragged element passes the dropAccept selector or filter function.
  5967. // FYI, the default is "*" (matches all)
  5968. accept = this.opt('dropAccept');
  5969. if ($.isFunction(accept) ? accept.call(el[0], el) : el.is(accept)) {
  5970. meta = getDraggedElMeta(el); // data for possibly creating an event
  5971. eventProps = meta.eventProps;
  5972. // listener that tracks mouse movement over date-associated pixel regions
  5973. dragListener = new DragListener(this.coordMap, {
  5974. cellOver: function(cell, cellDate) {
  5975. eventStart = cellDate;
  5976. eventEnd = meta.duration ? eventStart.clone().add(meta.duration) : null;
  5977. visibleEnd = eventEnd || calendar.getDefaultEventEnd(!eventStart.hasTime(), eventStart);
  5978. // keep the start/end up to date when dragging
  5979. if (eventProps) {
  5980. $.extend(eventProps, { start: eventStart, end: eventEnd });
  5981. }
  5982. if (calendar.isExternalDragAllowedInRange(eventStart, visibleEnd, eventProps)) {
  5983. _this.renderDrag(eventStart, visibleEnd);
  5984. }
  5985. else {
  5986. eventStart = null; // signal unsuccessful
  5987. disableCursor();
  5988. }
  5989. },
  5990. cellOut: function() {
  5991. eventStart = null;
  5992. _this.destroyDrag();
  5993. enableCursor();
  5994. }
  5995. });
  5996. // gets called, only once, when jqui drag is finished
  5997. $(document).one('dragstop', function(ev, ui) {
  5998. var renderedEvents;
  5999. _this.destroyDrag();
  6000. enableCursor();
  6001. if (eventStart) { // element was dropped on a valid date/time cell
  6002. // if dropped on an all-day cell, and element's metadata specified a time, set it
  6003. if (meta.startTime && !eventStart.hasTime()) {
  6004. eventStart.time(meta.startTime);
  6005. }
  6006. // trigger 'drop' regardless of whether element represents an event
  6007. _this.trigger('drop', el[0], eventStart, ev, ui);
  6008. // create an event from the given properties and the latest dates
  6009. if (eventProps) {
  6010. renderedEvents = calendar.renderEvent(eventProps, meta.stick);
  6011. _this.trigger('eventReceive', null, renderedEvents[0]); // signal an external event landed
  6012. }
  6013. }
  6014. });
  6015. dragListener.startDrag(ev); // start listening immediately
  6016. }
  6017. }
  6018. },
  6019. /* Selection
  6020. ------------------------------------------------------------------------------------------------------------------*/
  6021. // Selects a date range on the view. `start` and `end` are both Moments.
  6022. // `ev` is the native mouse event that begin the interaction.
  6023. select: function(start, end, ev) {
  6024. this.unselect(ev);
  6025. this.renderSelection(start, end);
  6026. this.reportSelection(start, end, ev);
  6027. },
  6028. // Renders a visual indication of the selection
  6029. renderSelection: function(start, end) {
  6030. // subclasses should implement
  6031. },
  6032. // Called when a new selection is made. Updates internal state and triggers handlers.
  6033. reportSelection: function(start, end, ev) {
  6034. this.isSelected = true;
  6035. this.trigger('select', null, start, end, ev);
  6036. },
  6037. // Undoes a selection. updates in the internal state and triggers handlers.
  6038. // `ev` is the native mouse event that began the interaction.
  6039. unselect: function(ev) {
  6040. if (this.isSelected) {
  6041. this.isSelected = false;
  6042. this.destroySelection();
  6043. this.trigger('unselect', null, ev);
  6044. }
  6045. },
  6046. // Unrenders a visual indication of selection
  6047. destroySelection: function() {
  6048. // subclasses should implement
  6049. },
  6050. // Handler for unselecting when the user clicks something and the 'unselectAuto' setting is on
  6051. documentMousedown: function(ev) {
  6052. var ignore;
  6053. // is there a selection, and has the user made a proper left click?
  6054. if (this.isSelected && this.opt('unselectAuto') && isPrimaryMouseButton(ev)) {
  6055. // only unselect if the clicked element is not identical to or inside of an 'unselectCancel' element
  6056. ignore = this.opt('unselectCancel');
  6057. if (!ignore || !$(ev.target).closest(ignore).length) {
  6058. this.unselect(ev);
  6059. }
  6060. }
  6061. }
  6062. };
  6063. // We are mixing JavaScript OOP design patterns here by putting methods and member variables in the closed scope of the
  6064. // constructor. Going forward, methods should be part of the prototype.
  6065. function View(calendar) {
  6066. var t = this;
  6067. // exports
  6068. t.calendar = calendar;
  6069. t.opt = opt;
  6070. t.trigger = trigger;
  6071. t.isEventDraggable = isEventDraggable;
  6072. t.isEventResizable = isEventResizable;
  6073. t.eventDrop = eventDrop;
  6074. t.eventResize = eventResize;
  6075. // imports
  6076. var reportEventChange = calendar.reportEventChange;
  6077. // locals
  6078. var options = calendar.options;
  6079. var nextDayThreshold = moment.duration(options.nextDayThreshold);
  6080. t.init(); // the "constructor" that concerns the prototype methods
  6081. function opt(name) {
  6082. var v = options[name];
  6083. if ($.isPlainObject(v) && !isForcedAtomicOption(name)) {
  6084. return smartProperty(v, t.name);
  6085. }
  6086. return v;
  6087. }
  6088. function trigger(name, thisObj) {
  6089. return calendar.trigger.apply(
  6090. calendar,
  6091. [name, thisObj || t].concat(Array.prototype.slice.call(arguments, 2), [t])
  6092. );
  6093. }
  6094. /* Event Editable Boolean Calculations
  6095. ------------------------------------------------------------------------------*/
  6096. function isEventDraggable(event) {
  6097. var source = event.source || {};
  6098. return firstDefined(
  6099. event.startEditable,
  6100. source.startEditable,
  6101. opt('eventStartEditable'),
  6102. event.editable,
  6103. source.editable,
  6104. opt('editable')
  6105. );
  6106. }
  6107. function isEventResizable(event) {
  6108. var source = event.source || {};
  6109. return firstDefined(
  6110. event.durationEditable,
  6111. source.durationEditable,
  6112. opt('eventDurationEditable'),
  6113. event.editable,
  6114. source.editable,
  6115. opt('editable')
  6116. );
  6117. }
  6118. /* Event Elements
  6119. ------------------------------------------------------------------------------*/
  6120. // Compute the text that should be displayed on an event's element.
  6121. // Based off the settings of the view. Possible signatures:
  6122. // .getEventTimeText(event, formatStr)
  6123. // .getEventTimeText(startMoment, endMoment, formatStr)
  6124. // .getEventTimeText(startMoment, null, formatStr)
  6125. // `timeFormat` is used but the `formatStr` argument can be used to override.
  6126. t.getEventTimeText = function(event, formatStr) {
  6127. var start;
  6128. var end;
  6129. if (typeof event === 'object' && typeof formatStr === 'object') {
  6130. // first two arguments are actually moments (or null). shift arguments.
  6131. start = event;
  6132. end = formatStr;
  6133. formatStr = arguments[2];
  6134. }
  6135. else {
  6136. // otherwise, an event object was the first argument
  6137. start = event.start;
  6138. end = event.end;
  6139. }
  6140. formatStr = formatStr || opt('timeFormat');
  6141. if (end && opt('displayEventEnd')) {
  6142. return calendar.formatRange(start, end, formatStr);
  6143. }
  6144. else {
  6145. return calendar.formatDate(start, formatStr);
  6146. }
  6147. };
  6148. /* Event Modification Reporting
  6149. ---------------------------------------------------------------------------------*/
  6150. function eventDrop(el, event, newStart, ev) {
  6151. var mutateResult = calendar.mutateEvent(event, newStart, null);
  6152. trigger(
  6153. 'eventDrop',
  6154. el,
  6155. event,
  6156. mutateResult.dateDelta,
  6157. function() {
  6158. mutateResult.undo();
  6159. reportEventChange();
  6160. },
  6161. ev,
  6162. {} // jqui dummy
  6163. );
  6164. reportEventChange();
  6165. }
  6166. function eventResize(el, event, newEnd, ev) {
  6167. var mutateResult = calendar.mutateEvent(event, null, newEnd);
  6168. trigger(
  6169. 'eventResize',
  6170. el,
  6171. event,
  6172. mutateResult.durationDelta,
  6173. function() {
  6174. mutateResult.undo();
  6175. reportEventChange();
  6176. },
  6177. ev,
  6178. {} // jqui dummy
  6179. );
  6180. reportEventChange();
  6181. }
  6182. // ====================================================================================================
  6183. // Utilities for day "cells"
  6184. // ====================================================================================================
  6185. // The "basic" views are completely made up of day cells.
  6186. // The "agenda" views have day cells at the top "all day" slot.
  6187. // This was the obvious common place to put these utilities, but they should be abstracted out into
  6188. // a more meaningful class (like DayEventRenderer).
  6189. // ====================================================================================================
  6190. // For determining how a given "cell" translates into a "date":
  6191. //
  6192. // 1. Convert the "cell" (row and column) into a "cell offset" (the # of the cell, cronologically from the first).
  6193. // Keep in mind that column indices are inverted with isRTL. This is taken into account.
  6194. //
  6195. // 2. Convert the "cell offset" to a "day offset" (the # of days since the first visible day in the view).
  6196. //
  6197. // 3. Convert the "day offset" into a "date" (a Moment).
  6198. //
  6199. // The reverse transformation happens when transforming a date into a cell.
  6200. // exports
  6201. t.isHiddenDay = isHiddenDay;
  6202. t.skipHiddenDays = skipHiddenDays;
  6203. t.getCellsPerWeek = getCellsPerWeek;
  6204. t.dateToCell = dateToCell;
  6205. t.dateToDayOffset = dateToDayOffset;
  6206. t.dayOffsetToCellOffset = dayOffsetToCellOffset;
  6207. t.cellOffsetToCell = cellOffsetToCell;
  6208. t.cellToDate = cellToDate;
  6209. t.cellToCellOffset = cellToCellOffset;
  6210. t.cellOffsetToDayOffset = cellOffsetToDayOffset;
  6211. t.dayOffsetToDate = dayOffsetToDate;
  6212. t.rangeToSegments = rangeToSegments;
  6213. t.isMultiDayEvent = isMultiDayEvent;
  6214. // internals
  6215. var hiddenDays = opt('hiddenDays') || []; // array of day-of-week indices that are hidden
  6216. var isHiddenDayHash = []; // is the day-of-week hidden? (hash with day-of-week-index -> bool)
  6217. var cellsPerWeek;
  6218. var dayToCellMap = []; // hash from dayIndex -> cellIndex, for one week
  6219. var cellToDayMap = []; // hash from cellIndex -> dayIndex, for one week
  6220. var isRTL = opt('isRTL');
  6221. // initialize important internal variables
  6222. (function() {
  6223. if (opt('weekends') === false) {
  6224. hiddenDays.push(0, 6); // 0=sunday, 6=saturday
  6225. }
  6226. // Loop through a hypothetical week and determine which
  6227. // days-of-week are hidden. Record in both hashes (one is the reverse of the other).
  6228. for (var dayIndex=0, cellIndex=0; dayIndex<7; dayIndex++) {
  6229. dayToCellMap[dayIndex] = cellIndex;
  6230. isHiddenDayHash[dayIndex] = $.inArray(dayIndex, hiddenDays) != -1;
  6231. if (!isHiddenDayHash[dayIndex]) {
  6232. cellToDayMap[cellIndex] = dayIndex;
  6233. cellIndex++;
  6234. }
  6235. }
  6236. cellsPerWeek = cellIndex;
  6237. if (!cellsPerWeek) {
  6238. throw 'invalid hiddenDays'; // all days were hidden? bad.
  6239. }
  6240. })();
  6241. // Is the current day hidden?
  6242. // `day` is a day-of-week index (0-6), or a Moment
  6243. function isHiddenDay(day) {
  6244. if (moment.isMoment(day)) {
  6245. day = day.day();
  6246. }
  6247. return isHiddenDayHash[day];
  6248. }
  6249. function getCellsPerWeek() {
  6250. return cellsPerWeek;
  6251. }
  6252. // Incrementing the current day until it is no longer a hidden day, returning a copy.
  6253. // If the initial value of `date` is not a hidden day, don't do anything.
  6254. // Pass `isExclusive` as `true` if you are dealing with an end date.
  6255. // `inc` defaults to `1` (increment one day forward each time)
  6256. function skipHiddenDays(date, inc, isExclusive) {
  6257. var out = date.clone();
  6258. inc = inc || 1;
  6259. while (
  6260. isHiddenDayHash[(out.day() + (isExclusive ? inc : 0) + 7) % 7]
  6261. ) {
  6262. out.add(inc, 'days');
  6263. }
  6264. return out;
  6265. }
  6266. //
  6267. // TRANSFORMATIONS: cell -> cell offset -> day offset -> date
  6268. //
  6269. // cell -> date (combines all transformations)
  6270. // Possible arguments:
  6271. // - row, col
  6272. // - { row:#, col: # }
  6273. function cellToDate() {
  6274. var cellOffset = cellToCellOffset.apply(null, arguments);
  6275. var dayOffset = cellOffsetToDayOffset(cellOffset);
  6276. var date = dayOffsetToDate(dayOffset);
  6277. return date;
  6278. }
  6279. // cell -> cell offset
  6280. // Possible arguments:
  6281. // - row, col
  6282. // - { row:#, col:# }
  6283. function cellToCellOffset(row, col) {
  6284. var colCnt = t.colCnt;
  6285. // rtl variables. wish we could pre-populate these. but where?
  6286. var dis = isRTL ? -1 : 1;
  6287. var dit = isRTL ? colCnt - 1 : 0;
  6288. if (typeof row == 'object') {
  6289. col = row.col;
  6290. row = row.row;
  6291. }
  6292. var cellOffset = row * colCnt + (col * dis + dit); // column, adjusted for RTL (dis & dit)
  6293. return cellOffset;
  6294. }
  6295. // cell offset -> day offset
  6296. function cellOffsetToDayOffset(cellOffset) {
  6297. var day0 = t.start.day(); // first date's day of week
  6298. cellOffset += dayToCellMap[day0]; // normlize cellOffset to beginning-of-week
  6299. return Math.floor(cellOffset / cellsPerWeek) * 7 + // # of days from full weeks
  6300. cellToDayMap[ // # of days from partial last week
  6301. (cellOffset % cellsPerWeek + cellsPerWeek) % cellsPerWeek // crazy math to handle negative cellOffsets
  6302. ] -
  6303. day0; // adjustment for beginning-of-week normalization
  6304. }
  6305. // day offset -> date
  6306. function dayOffsetToDate(dayOffset) {
  6307. return t.start.clone().add(dayOffset, 'days');
  6308. }
  6309. //
  6310. // TRANSFORMATIONS: date -> day offset -> cell offset -> cell
  6311. //
  6312. // date -> cell (combines all transformations)
  6313. function dateToCell(date) {
  6314. var dayOffset = dateToDayOffset(date);
  6315. var cellOffset = dayOffsetToCellOffset(dayOffset);
  6316. var cell = cellOffsetToCell(cellOffset);
  6317. return cell;
  6318. }
  6319. // date -> day offset
  6320. function dateToDayOffset(date) {
  6321. return date.clone().stripTime().diff(t.start, 'days');
  6322. }
  6323. // day offset -> cell offset
  6324. function dayOffsetToCellOffset(dayOffset) {
  6325. var day0 = t.start.day(); // first date's day of week
  6326. dayOffset += day0; // normalize dayOffset to beginning-of-week
  6327. return Math.floor(dayOffset / 7) * cellsPerWeek + // # of cells from full weeks
  6328. dayToCellMap[ // # of cells from partial last week
  6329. (dayOffset % 7 + 7) % 7 // crazy math to handle negative dayOffsets
  6330. ] -
  6331. dayToCellMap[day0]; // adjustment for beginning-of-week normalization
  6332. }
  6333. // cell offset -> cell (object with row & col keys)
  6334. function cellOffsetToCell(cellOffset) {
  6335. var colCnt = t.colCnt;
  6336. // rtl variables. wish we could pre-populate these. but where?
  6337. var dis = isRTL ? -1 : 1;
  6338. var dit = isRTL ? colCnt - 1 : 0;
  6339. var row = Math.floor(cellOffset / colCnt);
  6340. var col = ((cellOffset % colCnt + colCnt) % colCnt) * dis + dit; // column, adjusted for RTL (dis & dit)
  6341. return {
  6342. row: row,
  6343. col: col
  6344. };
  6345. }
  6346. //
  6347. // Converts a date range into an array of segment objects.
  6348. // "Segments" are horizontal stretches of time, sliced up by row.
  6349. // A segment object has the following properties:
  6350. // - row
  6351. // - cols
  6352. // - isStart
  6353. // - isEnd
  6354. //
  6355. function rangeToSegments(start, end) {
  6356. var rowCnt = t.rowCnt;
  6357. var colCnt = t.colCnt;
  6358. var segments = []; // array of segments to return
  6359. // day offset for given date range
  6360. var dayRange = computeDayRange(start, end); // convert to a whole-day range
  6361. var rangeDayOffsetStart = dateToDayOffset(dayRange.start);
  6362. var rangeDayOffsetEnd = dateToDayOffset(dayRange.end); // an exclusive value
  6363. // first and last cell offset for the given date range
  6364. // "last" implies inclusivity
  6365. var rangeCellOffsetFirst = dayOffsetToCellOffset(rangeDayOffsetStart);
  6366. var rangeCellOffsetLast = dayOffsetToCellOffset(rangeDayOffsetEnd) - 1;
  6367. // loop through all the rows in the view
  6368. for (var row=0; row<rowCnt; row++) {
  6369. // first and last cell offset for the row
  6370. var rowCellOffsetFirst = row * colCnt;
  6371. var rowCellOffsetLast = rowCellOffsetFirst + colCnt - 1;
  6372. // get the segment's cell offsets by constraining the range's cell offsets to the bounds of the row
  6373. var segmentCellOffsetFirst = Math.max(rangeCellOffsetFirst, rowCellOffsetFirst);
  6374. var segmentCellOffsetLast = Math.min(rangeCellOffsetLast, rowCellOffsetLast);
  6375. // make sure segment's offsets are valid and in view
  6376. if (segmentCellOffsetFirst <= segmentCellOffsetLast) {
  6377. // translate to cells
  6378. var segmentCellFirst = cellOffsetToCell(segmentCellOffsetFirst);
  6379. var segmentCellLast = cellOffsetToCell(segmentCellOffsetLast);
  6380. // view might be RTL, so order by leftmost column
  6381. var cols = [ segmentCellFirst.col, segmentCellLast.col ].sort(compareNumbers);
  6382. // Determine if segment's first/last cell is the beginning/end of the date range.
  6383. // We need to compare "day offset" because "cell offsets" are often ambiguous and
  6384. // can translate to multiple days, and an edge case reveals itself when we the
  6385. // range's first cell is hidden (we don't want isStart to be true).
  6386. var isStart = cellOffsetToDayOffset(segmentCellOffsetFirst) == rangeDayOffsetStart;
  6387. var isEnd = cellOffsetToDayOffset(segmentCellOffsetLast) + 1 == rangeDayOffsetEnd;
  6388. // +1 for comparing exclusively
  6389. segments.push({
  6390. row: row,
  6391. leftCol: cols[0],
  6392. rightCol: cols[1],
  6393. isStart: isStart,
  6394. isEnd: isEnd
  6395. });
  6396. }
  6397. }
  6398. return segments;
  6399. }
  6400. // Returns the date range of the full days the given range visually appears to occupy.
  6401. // Returns object with properties `start` (moment) and `end` (moment, exclusive end).
  6402. function computeDayRange(start, end) {
  6403. var startDay = start.clone().stripTime(); // the beginning of the day the range starts
  6404. var endDay;
  6405. var endTimeMS;
  6406. if (end) {
  6407. endDay = end.clone().stripTime(); // the beginning of the day the range exclusively ends
  6408. endTimeMS = +end.time(); // # of milliseconds into `endDay`
  6409. // If the end time is actually inclusively part of the next day and is equal to or
  6410. // beyond the next day threshold, adjust the end to be the exclusive end of `endDay`.
  6411. // Otherwise, leaving it as inclusive will cause it to exclude `endDay`.
  6412. if (endTimeMS && endTimeMS >= nextDayThreshold) {
  6413. endDay.add(1, 'days');
  6414. }
  6415. }
  6416. // If no end was specified, or if it is within `startDay` but not past nextDayThreshold,
  6417. // assign the default duration of one day.
  6418. if (!end || endDay <= startDay) {
  6419. endDay = startDay.clone().add(1, 'days');
  6420. }
  6421. return { start: startDay, end: endDay };
  6422. }
  6423. // Does the given event visually appear to occupy more than one day?
  6424. function isMultiDayEvent(event) {
  6425. var range = computeDayRange(event.start, event.end);
  6426. return range.end.diff(range.start, 'days') > 1;
  6427. }
  6428. }
  6429. /* Utils
  6430. ----------------------------------------------------------------------------------------------------------------------*/
  6431. // Require all HTML5 data-* attributes used by FullCalendar to have this prefix.
  6432. // A value of '' will query attributes like data-event. A value of 'fc' will query attributes like data-fc-event.
  6433. fc.dataAttrPrefix = '';
  6434. // Given a jQuery element that might represent a dragged FullCalendar event, returns an intermediate data structure
  6435. // to be used for Event Object creation.
  6436. // A defined `.eventProps`, even when empty, indicates that an event should be created.
  6437. function getDraggedElMeta(el) {
  6438. var prefix = fc.dataAttrPrefix;
  6439. var eventProps; // properties for creating the event, not related to date/time
  6440. var startTime; // a Duration
  6441. var duration;
  6442. var stick;
  6443. if (prefix) { prefix += '-'; }
  6444. eventProps = el.data(prefix + 'event') || null;
  6445. if (eventProps) {
  6446. if (typeof eventProps === 'object') {
  6447. eventProps = $.extend({}, eventProps); // make a copy
  6448. }
  6449. else { // something like 1 or true. still signal event creation
  6450. eventProps = {};
  6451. }
  6452. // pluck special-cased date/time properties
  6453. startTime = eventProps.start;
  6454. if (startTime == null) { startTime = eventProps.time; } // accept 'time' as well
  6455. duration = eventProps.duration;
  6456. stick = eventProps.stick;
  6457. delete eventProps.start;
  6458. delete eventProps.time;
  6459. delete eventProps.duration;
  6460. delete eventProps.stick;
  6461. }
  6462. // fallback to standalone attribute values for each of the date/time properties
  6463. if (startTime == null) { startTime = el.data(prefix + 'start'); }
  6464. if (startTime == null) { startTime = el.data(prefix + 'time'); } // accept 'time' as well
  6465. if (duration == null) { duration = el.data(prefix + 'duration'); }
  6466. if (stick == null) { stick = el.data(prefix + 'stick'); }
  6467. // massage into correct data types
  6468. startTime = startTime != null ? moment.duration(startTime) : null;
  6469. duration = duration != null ? moment.duration(duration) : null;
  6470. stick = Boolean(stick);
  6471. return { eventProps: eventProps, startTime: startTime, duration: duration, stick: stick };
  6472. }
  6473. ;;
  6474. /* An abstract class for the "basic" views, as well as month view. Renders one or more rows of day cells.
  6475. ----------------------------------------------------------------------------------------------------------------------*/
  6476. // It is a manager for a DayGrid subcomponent, which does most of the heavy lifting.
  6477. // It is responsible for managing width/height.
  6478. function BasicView(calendar) {
  6479. View.call(this, calendar); // call the super-constructor
  6480. this.dayGrid = new DayGrid(this);
  6481. this.coordMap = this.dayGrid.coordMap; // the view's date-to-cell mapping is identical to the subcomponent's
  6482. }
  6483. BasicView.prototype = createObject(View.prototype); // define the super-class
  6484. $.extend(BasicView.prototype, {
  6485. dayGrid: null, // the main subcomponent that does most of the heavy lifting
  6486. dayNumbersVisible: false, // display day numbers on each day cell?
  6487. weekNumbersVisible: false, // display week numbers along the side?
  6488. weekNumberWidth: null, // width of all the week-number cells running down the side
  6489. headRowEl: null, // the fake row element of the day-of-week header
  6490. // Renders the view into `this.el`, which should already be assigned.
  6491. // rowCnt, colCnt, and dayNumbersVisible have been calculated by a subclass and passed here.
  6492. render: function(rowCnt, colCnt, dayNumbersVisible) {
  6493. // needed for cell-to-date and date-to-cell calculations in View
  6494. this.rowCnt = rowCnt;
  6495. this.colCnt = colCnt;
  6496. this.dayNumbersVisible = dayNumbersVisible;
  6497. this.weekNumbersVisible = this.opt('weekNumbers');
  6498. this.dayGrid.numbersVisible = this.dayNumbersVisible || this.weekNumbersVisible;
  6499. this.el.addClass('fc-basic-view').html(this.renderHtml());
  6500. this.headRowEl = this.el.find('thead .fc-row');
  6501. this.scrollerEl = this.el.find('.fc-day-grid-container');
  6502. this.dayGrid.coordMap.containerEl = this.scrollerEl; // constrain clicks/etc to the dimensions of the scroller
  6503. this.dayGrid.el = this.el.find('.fc-day-grid');
  6504. this.dayGrid.render(this.hasRigidRows());
  6505. View.prototype.render.call(this); // call the super-method
  6506. },
  6507. // Make subcomponents ready for cleanup
  6508. destroy: function() {
  6509. this.dayGrid.destroy();
  6510. View.prototype.destroy.call(this); // call the super-method
  6511. },
  6512. // Builds the HTML skeleton for the view.
  6513. // The day-grid component will render inside of a container defined by this HTML.
  6514. renderHtml: function() {
  6515. return '' +
  6516. '<table>' +
  6517. '<thead>' +
  6518. '<tr>' +
  6519. '<td class="' + this.widgetHeaderClass + '">' +
  6520. this.dayGrid.headHtml() + // render the day-of-week headers
  6521. '</td>' +
  6522. '</tr>' +
  6523. '</thead>' +
  6524. '<tbody>' +
  6525. '<tr>' +
  6526. '<td class="' + this.widgetContentClass + '">' +
  6527. '<div class="fc-day-grid-container">' +
  6528. '<div class="fc-day-grid"/>' +
  6529. '</div>' +
  6530. '</td>' +
  6531. '</tr>' +
  6532. '</tbody>' +
  6533. '</table>';
  6534. },
  6535. // Generates the HTML that will go before the day-of week header cells.
  6536. // Queried by the DayGrid subcomponent when generating rows. Ordering depends on isRTL.
  6537. headIntroHtml: function() {
  6538. if (this.weekNumbersVisible) {
  6539. return '' +
  6540. '<th class="fc-week-number ' + this.widgetHeaderClass + '" ' + this.weekNumberStyleAttr() + '>' +
  6541. '<span>' + // needed for matchCellWidths
  6542. htmlEscape(this.opt('weekNumberTitle')) +
  6543. '</span>' +
  6544. '</th>';
  6545. }
  6546. },
  6547. // Generates the HTML that will go before content-skeleton cells that display the day/week numbers.
  6548. // Queried by the DayGrid subcomponent. Ordering depends on isRTL.
  6549. numberIntroHtml: function(row) {
  6550. if (this.weekNumbersVisible) {
  6551. return '' +
  6552. '<td class="fc-week-number" ' + this.weekNumberStyleAttr() + '>' +
  6553. '<span>' + // needed for matchCellWidths
  6554. this.calendar.calculateWeekNumber(this.cellToDate(row, 0)) +
  6555. '</span>' +
  6556. '</td>';
  6557. }
  6558. },
  6559. // Generates the HTML that goes before the day bg cells for each day-row.
  6560. // Queried by the DayGrid subcomponent. Ordering depends on isRTL.
  6561. dayIntroHtml: function() {
  6562. if (this.weekNumbersVisible) {
  6563. return '<td class="fc-week-number ' + this.widgetContentClass + '" ' +
  6564. this.weekNumberStyleAttr() + '></td>';
  6565. }
  6566. },
  6567. // Generates the HTML that goes before every other type of row generated by DayGrid. Ordering depends on isRTL.
  6568. // Affects helper-skeleton and highlight-skeleton rows.
  6569. introHtml: function() {
  6570. if (this.weekNumbersVisible) {
  6571. return '<td class="fc-week-number" ' + this.weekNumberStyleAttr() + '></td>';
  6572. }
  6573. },
  6574. // Generates the HTML for the <td>s of the "number" row in the DayGrid's content skeleton.
  6575. // The number row will only exist if either day numbers or week numbers are turned on.
  6576. numberCellHtml: function(row, col, date) {
  6577. var classes;
  6578. if (!this.dayNumbersVisible) { // if there are week numbers but not day numbers
  6579. return '<td/>'; // will create an empty space above events :(
  6580. }
  6581. classes = this.dayGrid.getDayClasses(date);
  6582. classes.unshift('fc-day-number');
  6583. return '' +
  6584. '<td class="' + classes.join(' ') + '" data-date="' + date.format() + '">' +
  6585. date.date() +
  6586. '</td>';
  6587. },
  6588. // Generates an HTML attribute string for setting the width of the week number column, if it is known
  6589. weekNumberStyleAttr: function() {
  6590. if (this.weekNumberWidth !== null) {
  6591. return 'style="width:' + this.weekNumberWidth + 'px"';
  6592. }
  6593. return '';
  6594. },
  6595. // Determines whether each row should have a constant height
  6596. hasRigidRows: function() {
  6597. var eventLimit = this.opt('eventLimit');
  6598. return eventLimit && typeof eventLimit !== 'number';
  6599. },
  6600. /* Dimensions
  6601. ------------------------------------------------------------------------------------------------------------------*/
  6602. // Refreshes the horizontal dimensions of the view
  6603. updateWidth: function() {
  6604. if (this.weekNumbersVisible) {
  6605. // Make sure all week number cells running down the side have the same width.
  6606. // Record the width for cells created later.
  6607. this.weekNumberWidth = matchCellWidths(
  6608. this.el.find('.fc-week-number')
  6609. );
  6610. }
  6611. },
  6612. // Adjusts the vertical dimensions of the view to the specified values
  6613. setHeight: function(totalHeight, isAuto) {
  6614. var eventLimit = this.opt('eventLimit');
  6615. var scrollerHeight;
  6616. // reset all heights to be natural
  6617. unsetScroller(this.scrollerEl);
  6618. uncompensateScroll(this.headRowEl);
  6619. this.dayGrid.destroySegPopover(); // kill the "more" popover if displayed
  6620. // is the event limit a constant level number?
  6621. if (eventLimit && typeof eventLimit === 'number') {
  6622. this.dayGrid.limitRows(eventLimit); // limit the levels first so the height can redistribute after
  6623. }
  6624. scrollerHeight = this.computeScrollerHeight(totalHeight);
  6625. this.setGridHeight(scrollerHeight, isAuto);
  6626. // is the event limit dynamically calculated?
  6627. if (eventLimit && typeof eventLimit !== 'number') {
  6628. this.dayGrid.limitRows(eventLimit); // limit the levels after the grid's row heights have been set
  6629. }
  6630. if (!isAuto && setPotentialScroller(this.scrollerEl, scrollerHeight)) { // using scrollbars?
  6631. compensateScroll(this.headRowEl, getScrollbarWidths(this.scrollerEl));
  6632. // doing the scrollbar compensation might have created text overflow which created more height. redo
  6633. scrollerHeight = this.computeScrollerHeight(totalHeight);
  6634. this.scrollerEl.height(scrollerHeight);
  6635. this.restoreScroll();
  6636. }
  6637. },
  6638. // Sets the height of just the DayGrid component in this view
  6639. setGridHeight: function(height, isAuto) {
  6640. if (isAuto) {
  6641. undistributeHeight(this.dayGrid.rowEls); // let the rows be their natural height with no expanding
  6642. }
  6643. else {
  6644. distributeHeight(this.dayGrid.rowEls, height, true); // true = compensate for height-hogging rows
  6645. }
  6646. },
  6647. /* Events
  6648. ------------------------------------------------------------------------------------------------------------------*/
  6649. // Renders the given events onto the view and populates the segments array
  6650. renderEvents: function(events) {
  6651. this.dayGrid.renderEvents(events);
  6652. this.updateHeight(); // must compensate for events that overflow the row
  6653. View.prototype.renderEvents.call(this, events); // call the super-method
  6654. },
  6655. // Retrieves all segment objects that are rendered in the view
  6656. getSegs: function() {
  6657. return this.dayGrid.getSegs();
  6658. },
  6659. // Unrenders all event elements and clears internal segment data
  6660. destroyEvents: function() {
  6661. View.prototype.destroyEvents.call(this); // do this before dayGrid's segs have been cleared
  6662. this.recordScroll(); // removing events will reduce height and mess with the scroll, so record beforehand
  6663. this.dayGrid.destroyEvents();
  6664. // we DON'T need to call updateHeight() because:
  6665. // A) a renderEvents() call always happens after this, which will eventually call updateHeight()
  6666. // B) in IE8, this causes a flash whenever events are rerendered
  6667. },
  6668. /* Event Dragging
  6669. ------------------------------------------------------------------------------------------------------------------*/
  6670. // Renders a visual indication of an event being dragged over the view.
  6671. // A returned value of `true` signals that a mock "helper" event has been rendered.
  6672. renderDrag: function(start, end, seg) {
  6673. return this.dayGrid.renderDrag(start, end, seg);
  6674. },
  6675. // Unrenders the visual indication of an event being dragged over the view
  6676. destroyDrag: function() {
  6677. this.dayGrid.destroyDrag();
  6678. },
  6679. /* Selection
  6680. ------------------------------------------------------------------------------------------------------------------*/
  6681. // Renders a visual indication of a selection
  6682. renderSelection: function(start, end) {
  6683. this.dayGrid.renderSelection(start, end);
  6684. },
  6685. // Unrenders a visual indications of a selection
  6686. destroySelection: function() {
  6687. this.dayGrid.destroySelection();
  6688. }
  6689. });
  6690. ;;
  6691. /* A month view with day cells running in rows (one-per-week) and columns
  6692. ----------------------------------------------------------------------------------------------------------------------*/
  6693. setDefaults({
  6694. fixedWeekCount: true
  6695. });
  6696. fcViews.month = MonthView; // register the view
  6697. function MonthView(calendar) {
  6698. BasicView.call(this, calendar); // call the super-constructor
  6699. }
  6700. MonthView.prototype = createObject(BasicView.prototype); // define the super-class
  6701. $.extend(MonthView.prototype, {
  6702. name: 'month',
  6703. incrementDate: function(date, delta) {
  6704. return date.clone().stripTime().add(delta, 'months').startOf('month');
  6705. },
  6706. render: function(date) {
  6707. var rowCnt;
  6708. this.intervalStart = date.clone().stripTime().startOf('month');
  6709. this.intervalEnd = this.intervalStart.clone().add(1, 'months');
  6710. this.start = this.intervalStart.clone();
  6711. this.start = this.skipHiddenDays(this.start); // move past the first week if no visible days
  6712. this.start.startOf('week');
  6713. this.start = this.skipHiddenDays(this.start); // move past the first invisible days of the week
  6714. this.end = this.intervalEnd.clone();
  6715. this.end = this.skipHiddenDays(this.end, -1, true); // move in from the last week if no visible days
  6716. this.end.add((7 - this.end.weekday()) % 7, 'days'); // move to end of week if not already
  6717. this.end = this.skipHiddenDays(this.end, -1, true); // move in from the last invisible days of the week
  6718. rowCnt = Math.ceil( // need to ceil in case there are hidden days
  6719. this.end.diff(this.start, 'weeks', true) // returnfloat=true
  6720. );
  6721. if (this.isFixedWeeks()) {
  6722. this.end.add(6 - rowCnt, 'weeks');
  6723. rowCnt = 6;
  6724. }
  6725. this.title = this.calendar.formatDate(this.intervalStart, this.opt('titleFormat'));
  6726. BasicView.prototype.render.call(this, rowCnt, this.getCellsPerWeek(), true); // call the super-method
  6727. },
  6728. // Overrides the default BasicView behavior to have special multi-week auto-height logic
  6729. setGridHeight: function(height, isAuto) {
  6730. isAuto = isAuto || this.opt('weekMode') === 'variable'; // LEGACY: weekMode is deprecated
  6731. // if auto, make the height of each row the height that it would be if there were 6 weeks
  6732. if (isAuto) {
  6733. height *= this.rowCnt / 6;
  6734. }
  6735. distributeHeight(this.dayGrid.rowEls, height, !isAuto); // if auto, don't compensate for height-hogging rows
  6736. },
  6737. isFixedWeeks: function() {
  6738. var weekMode = this.opt('weekMode'); // LEGACY: weekMode is deprecated
  6739. if (weekMode) {
  6740. return weekMode === 'fixed'; // if any other type of weekMode, assume NOT fixed
  6741. }
  6742. return this.opt('fixedWeekCount');
  6743. }
  6744. });
  6745. ;;
  6746. /* A week view with simple day cells running horizontally
  6747. ----------------------------------------------------------------------------------------------------------------------*/
  6748. // TODO: a WeekView mixin for calculating dates and titles
  6749. fcViews.basicWeek = BasicWeekView; // register this view
  6750. function BasicWeekView(calendar) {
  6751. BasicView.call(this, calendar); // call the super-constructor
  6752. }
  6753. BasicWeekView.prototype = createObject(BasicView.prototype); // define the super-class
  6754. $.extend(BasicWeekView.prototype, {
  6755. name: 'basicWeek',
  6756. incrementDate: function(date, delta) {
  6757. return date.clone().stripTime().add(delta, 'weeks').startOf('week');
  6758. },
  6759. render: function(date) {
  6760. this.intervalStart = date.clone().stripTime().startOf('week');
  6761. this.intervalEnd = this.intervalStart.clone().add(1, 'weeks');
  6762. this.start = this.skipHiddenDays(this.intervalStart);
  6763. this.end = this.skipHiddenDays(this.intervalEnd, -1, true);
  6764. this.title = this.calendar.formatRange(
  6765. this.start,
  6766. this.end.clone().subtract(1), // make inclusive by subtracting 1 ms
  6767. this.opt('titleFormat'),
  6768. ' \u2014 ' // emphasized dash
  6769. );
  6770. BasicView.prototype.render.call(this, 1, this.getCellsPerWeek(), false); // call the super-method
  6771. }
  6772. });
  6773. ;;
  6774. /* A view with a single simple day cell
  6775. ----------------------------------------------------------------------------------------------------------------------*/
  6776. fcViews.basicDay = BasicDayView; // register this view
  6777. function BasicDayView(calendar) {
  6778. BasicView.call(this, calendar); // call the super-constructor
  6779. }
  6780. BasicDayView.prototype = createObject(BasicView.prototype); // define the super-class
  6781. $.extend(BasicDayView.prototype, {
  6782. name: 'basicDay',
  6783. incrementDate: function(date, delta) {
  6784. var out = date.clone().stripTime().add(delta, 'days');
  6785. out = this.skipHiddenDays(out, delta < 0 ? -1 : 1);
  6786. return out;
  6787. },
  6788. render: function(date) {
  6789. this.start = this.intervalStart = date.clone().stripTime();
  6790. this.end = this.intervalEnd = this.start.clone().add(1, 'days');
  6791. this.title = this.calendar.formatDate(this.start, this.opt('titleFormat'));
  6792. BasicView.prototype.render.call(this, 1, 1, false); // call the super-method
  6793. }
  6794. });
  6795. ;;
  6796. /* An abstract class for all agenda-related views. Displays one more columns with time slots running vertically.
  6797. ----------------------------------------------------------------------------------------------------------------------*/
  6798. // Is a manager for the TimeGrid subcomponent and possibly the DayGrid subcomponent (if allDaySlot is on).
  6799. // Responsible for managing width/height.
  6800. setDefaults({
  6801. allDaySlot: true,
  6802. allDayText: 'all-day',
  6803. scrollTime: '06:00:00',
  6804. slotDuration: '00:30:00',
  6805. axisFormat: generateAgendaAxisFormat,
  6806. timeFormat: {
  6807. agenda: generateAgendaTimeFormat
  6808. },
  6809. minTime: '00:00:00',
  6810. maxTime: '24:00:00',
  6811. slotEventOverlap: true
  6812. });
  6813. var AGENDA_ALL_DAY_EVENT_LIMIT = 5;
  6814. function generateAgendaAxisFormat(options, langData) {
  6815. return langData.longDateFormat('LT')
  6816. .replace(':mm', '(:mm)')
  6817. .replace(/(\Wmm)$/, '($1)') // like above, but for foreign langs
  6818. .replace(/\s*a$/i, 'a'); // convert AM/PM/am/pm to lowercase. remove any spaces beforehand
  6819. }
  6820. function generateAgendaTimeFormat(options, langData) {
  6821. return langData.longDateFormat('LT')
  6822. .replace(/\s*a$/i, ''); // remove trailing AM/PM
  6823. }
  6824. function AgendaView(calendar) {
  6825. View.call(this, calendar); // call the super-constructor
  6826. this.timeGrid = new TimeGrid(this);
  6827. if (this.opt('allDaySlot')) { // should we display the "all-day" area?
  6828. this.dayGrid = new DayGrid(this); // the all-day subcomponent of this view
  6829. // the coordinate grid will be a combination of both subcomponents' grids
  6830. this.coordMap = new ComboCoordMap([
  6831. this.dayGrid.coordMap,
  6832. this.timeGrid.coordMap
  6833. ]);
  6834. }
  6835. else {
  6836. this.coordMap = this.timeGrid.coordMap;
  6837. }
  6838. }
  6839. AgendaView.prototype = createObject(View.prototype); // define the super-class
  6840. $.extend(AgendaView.prototype, {
  6841. timeGrid: null, // the main time-grid subcomponent of this view
  6842. dayGrid: null, // the "all-day" subcomponent. if all-day is turned off, this will be null
  6843. axisWidth: null, // the width of the time axis running down the side
  6844. noScrollRowEls: null, // set of fake row elements that must compensate when scrollerEl has scrollbars
  6845. // when the time-grid isn't tall enough to occupy the given height, we render an <hr> underneath
  6846. bottomRuleEl: null,
  6847. bottomRuleHeight: null,
  6848. /* Rendering
  6849. ------------------------------------------------------------------------------------------------------------------*/
  6850. // Renders the view into `this.el`, which has already been assigned.
  6851. // `colCnt` has been calculated by a subclass and passed here.
  6852. render: function(colCnt) {
  6853. // needed for cell-to-date and date-to-cell calculations in View
  6854. this.rowCnt = 1;
  6855. this.colCnt = colCnt;
  6856. this.el.addClass('fc-agenda-view').html(this.renderHtml());
  6857. // the element that wraps the time-grid that will probably scroll
  6858. this.scrollerEl = this.el.find('.fc-time-grid-container');
  6859. this.timeGrid.coordMap.containerEl = this.scrollerEl; // don't accept clicks/etc outside of this
  6860. this.timeGrid.el = this.el.find('.fc-time-grid');
  6861. this.timeGrid.render();
  6862. // the <hr> that sometimes displays under the time-grid
  6863. this.bottomRuleEl = $('<hr class="' + this.widgetHeaderClass + '"/>')
  6864. .appendTo(this.timeGrid.el); // inject it into the time-grid
  6865. if (this.dayGrid) {
  6866. this.dayGrid.el = this.el.find('.fc-day-grid');
  6867. this.dayGrid.render();
  6868. // have the day-grid extend it's coordinate area over the <hr> dividing the two grids
  6869. this.dayGrid.bottomCoordPadding = this.dayGrid.el.next('hr').outerHeight();
  6870. }
  6871. this.noScrollRowEls = this.el.find('.fc-row:not(.fc-scroller *)'); // fake rows not within the scroller
  6872. View.prototype.render.call(this); // call the super-method
  6873. this.resetScroll(); // do this after sizes have been set
  6874. },
  6875. // Make subcomponents ready for cleanup
  6876. destroy: function() {
  6877. this.timeGrid.destroy();
  6878. if (this.dayGrid) {
  6879. this.dayGrid.destroy();
  6880. }
  6881. View.prototype.destroy.call(this); // call the super-method
  6882. },
  6883. // Builds the HTML skeleton for the view.
  6884. // The day-grid and time-grid components will render inside containers defined by this HTML.
  6885. renderHtml: function() {
  6886. return '' +
  6887. '<table>' +
  6888. '<thead>' +
  6889. '<tr>' +
  6890. '<td class="' + this.widgetHeaderClass + '">' +
  6891. this.timeGrid.headHtml() + // render the day-of-week headers
  6892. '</td>' +
  6893. '</tr>' +
  6894. '</thead>' +
  6895. '<tbody>' +
  6896. '<tr>' +
  6897. '<td class="' + this.widgetContentClass + '">' +
  6898. (this.dayGrid ?
  6899. '<div class="fc-day-grid"/>' +
  6900. '<hr class="' + this.widgetHeaderClass + '"/>' :
  6901. ''
  6902. ) +
  6903. '<div class="fc-time-grid-container">' +
  6904. '<div class="fc-time-grid"/>' +
  6905. '</div>' +
  6906. '</td>' +
  6907. '</tr>' +
  6908. '</tbody>' +
  6909. '</table>';
  6910. },
  6911. // Generates the HTML that will go before the day-of week header cells.
  6912. // Queried by the TimeGrid subcomponent when generating rows. Ordering depends on isRTL.
  6913. headIntroHtml: function() {
  6914. var date;
  6915. var weekNumber;
  6916. var weekTitle;
  6917. var weekText;
  6918. if (this.opt('weekNumbers')) {
  6919. date = this.cellToDate(0, 0);
  6920. weekNumber = this.calendar.calculateWeekNumber(date);
  6921. weekTitle = this.opt('weekNumberTitle');
  6922. if (this.opt('isRTL')) {
  6923. weekText = weekNumber + weekTitle;
  6924. }
  6925. else {
  6926. weekText = weekTitle + weekNumber;
  6927. }
  6928. return '' +
  6929. '<th class="fc-axis fc-week-number ' + this.widgetHeaderClass + '" ' + this.axisStyleAttr() + '>' +
  6930. '<span>' + // needed for matchCellWidths
  6931. htmlEscape(weekText) +
  6932. '</span>' +
  6933. '</th>';
  6934. }
  6935. else {
  6936. return '<th class="fc-axis ' + this.widgetHeaderClass + '" ' + this.axisStyleAttr() + '></th>';
  6937. }
  6938. },
  6939. // Generates the HTML that goes before the all-day cells.
  6940. // Queried by the DayGrid subcomponent when generating rows. Ordering depends on isRTL.
  6941. dayIntroHtml: function() {
  6942. return '' +
  6943. '<td class="fc-axis ' + this.widgetContentClass + '" ' + this.axisStyleAttr() + '>' +
  6944. '<span>' + // needed for matchCellWidths
  6945. (this.opt('allDayHtml') || htmlEscape(this.opt('allDayText'))) +
  6946. '</span>' +
  6947. '</td>';
  6948. },
  6949. // Generates the HTML that goes before the bg of the TimeGrid slot area. Long vertical column.
  6950. slotBgIntroHtml: function() {
  6951. return '<td class="fc-axis ' + this.widgetContentClass + '" ' + this.axisStyleAttr() + '></td>';
  6952. },
  6953. // Generates the HTML that goes before all other types of cells.
  6954. // Affects content-skeleton, helper-skeleton, highlight-skeleton for both the time-grid and day-grid.
  6955. // Queried by the TimeGrid and DayGrid subcomponents when generating rows. Ordering depends on isRTL.
  6956. introHtml: function() {
  6957. return '<td class="fc-axis" ' + this.axisStyleAttr() + '></td>';
  6958. },
  6959. // Generates an HTML attribute string for setting the width of the axis, if it is known
  6960. axisStyleAttr: function() {
  6961. if (this.axisWidth !== null) {
  6962. return 'style="width:' + this.axisWidth + 'px"';
  6963. }
  6964. return '';
  6965. },
  6966. /* Dimensions
  6967. ------------------------------------------------------------------------------------------------------------------*/
  6968. updateSize: function(isResize) {
  6969. if (isResize) {
  6970. this.timeGrid.resize();
  6971. }
  6972. View.prototype.updateSize.call(this, isResize);
  6973. },
  6974. // Refreshes the horizontal dimensions of the view
  6975. updateWidth: function() {
  6976. // make all axis cells line up, and record the width so newly created axis cells will have it
  6977. this.axisWidth = matchCellWidths(this.el.find('.fc-axis'));
  6978. },
  6979. // Adjusts the vertical dimensions of the view to the specified values
  6980. setHeight: function(totalHeight, isAuto) {
  6981. var eventLimit;
  6982. var scrollerHeight;
  6983. if (this.bottomRuleHeight === null) {
  6984. // calculate the height of the rule the very first time
  6985. this.bottomRuleHeight = this.bottomRuleEl.outerHeight();
  6986. }
  6987. this.bottomRuleEl.hide(); // .show() will be called later if this <hr> is necessary
  6988. // reset all dimensions back to the original state
  6989. this.scrollerEl.css('overflow', '');
  6990. unsetScroller(this.scrollerEl);
  6991. uncompensateScroll(this.noScrollRowEls);
  6992. // limit number of events in the all-day area
  6993. if (this.dayGrid) {
  6994. this.dayGrid.destroySegPopover(); // kill the "more" popover if displayed
  6995. eventLimit = this.opt('eventLimit');
  6996. if (eventLimit && typeof eventLimit !== 'number') {
  6997. eventLimit = AGENDA_ALL_DAY_EVENT_LIMIT; // make sure "auto" goes to a real number
  6998. }
  6999. if (eventLimit) {
  7000. this.dayGrid.limitRows(eventLimit);
  7001. }
  7002. }
  7003. if (!isAuto) { // should we force dimensions of the scroll container, or let the contents be natural height?
  7004. scrollerHeight = this.computeScrollerHeight(totalHeight);
  7005. if (setPotentialScroller(this.scrollerEl, scrollerHeight)) { // using scrollbars?
  7006. // make the all-day and header rows lines up
  7007. compensateScroll(this.noScrollRowEls, getScrollbarWidths(this.scrollerEl));
  7008. // the scrollbar compensation might have changed text flow, which might affect height, so recalculate
  7009. // and reapply the desired height to the scroller.
  7010. scrollerHeight = this.computeScrollerHeight(totalHeight);
  7011. this.scrollerEl.height(scrollerHeight);
  7012. this.restoreScroll();
  7013. }
  7014. else { // no scrollbars
  7015. // still, force a height and display the bottom rule (marks the end of day)
  7016. this.scrollerEl.height(scrollerHeight).css('overflow', 'hidden'); // in case <hr> goes outside
  7017. this.bottomRuleEl.show();
  7018. }
  7019. }
  7020. },
  7021. // Sets the scroll value of the scroller to the intial pre-configured state prior to allowing the user to change it.
  7022. resetScroll: function() {
  7023. var _this = this;
  7024. var scrollTime = moment.duration(this.opt('scrollTime'));
  7025. var top = this.timeGrid.computeTimeTop(scrollTime);
  7026. // zoom can give weird floating-point values. rather scroll a little bit further
  7027. top = Math.ceil(top);
  7028. if (top) {
  7029. top++; // to overcome top border that slots beyond the first have. looks better
  7030. }
  7031. function scroll() {
  7032. _this.scrollerEl.scrollTop(top);
  7033. }
  7034. scroll();
  7035. setTimeout(scroll, 0); // overrides any previous scroll state made by the browser
  7036. },
  7037. /* Events
  7038. ------------------------------------------------------------------------------------------------------------------*/
  7039. // Renders events onto the view and populates the View's segment array
  7040. renderEvents: function(events) {
  7041. var dayEvents = [];
  7042. var timedEvents = [];
  7043. var daySegs = [];
  7044. var timedSegs;
  7045. var i;
  7046. // separate the events into all-day and timed
  7047. for (i = 0; i < events.length; i++) {
  7048. if (events[i].allDay) {
  7049. dayEvents.push(events[i]);
  7050. }
  7051. else {
  7052. timedEvents.push(events[i]);
  7053. }
  7054. }
  7055. // render the events in the subcomponents
  7056. timedSegs = this.timeGrid.renderEvents(timedEvents);
  7057. if (this.dayGrid) {
  7058. daySegs = this.dayGrid.renderEvents(dayEvents);
  7059. }
  7060. // the all-day area is flexible and might have a lot of events, so shift the height
  7061. this.updateHeight();
  7062. View.prototype.renderEvents.call(this, events); // call the super-method
  7063. },
  7064. // Retrieves all segment objects that are rendered in the view
  7065. getSegs: function() {
  7066. return this.timeGrid.getSegs().concat(
  7067. this.dayGrid ? this.dayGrid.getSegs() : []
  7068. );
  7069. },
  7070. // Unrenders all event elements and clears internal segment data
  7071. destroyEvents: function() {
  7072. View.prototype.destroyEvents.call(this); // do this before the grids' segs have been cleared
  7073. // if destroyEvents is being called as part of an event rerender, renderEvents will be called shortly
  7074. // after, so remember what the scroll value was so we can restore it.
  7075. this.recordScroll();
  7076. // destroy the events in the subcomponents
  7077. this.timeGrid.destroyEvents();
  7078. if (this.dayGrid) {
  7079. this.dayGrid.destroyEvents();
  7080. }
  7081. // we DON'T need to call updateHeight() because:
  7082. // A) a renderEvents() call always happens after this, which will eventually call updateHeight()
  7083. // B) in IE8, this causes a flash whenever events are rerendered
  7084. },
  7085. /* Event Dragging
  7086. ------------------------------------------------------------------------------------------------------------------*/
  7087. // Renders a visual indication of an event being dragged over the view.
  7088. // A returned value of `true` signals that a mock "helper" event has been rendered.
  7089. renderDrag: function(start, end, seg) {
  7090. if (start.hasTime()) {
  7091. return this.timeGrid.renderDrag(start, end, seg);
  7092. }
  7093. else if (this.dayGrid) {
  7094. return this.dayGrid.renderDrag(start, end, seg);
  7095. }
  7096. },
  7097. // Unrenders a visual indications of an event being dragged over the view
  7098. destroyDrag: function() {
  7099. this.timeGrid.destroyDrag();
  7100. if (this.dayGrid) {
  7101. this.dayGrid.destroyDrag();
  7102. }
  7103. },
  7104. /* Selection
  7105. ------------------------------------------------------------------------------------------------------------------*/
  7106. // Renders a visual indication of a selection
  7107. renderSelection: function(start, end) {
  7108. if (start.hasTime() || end.hasTime()) {
  7109. this.timeGrid.renderSelection(start, end);
  7110. }
  7111. else if (this.dayGrid) {
  7112. this.dayGrid.renderSelection(start, end);
  7113. }
  7114. },
  7115. // Unrenders a visual indications of a selection
  7116. destroySelection: function() {
  7117. this.timeGrid.destroySelection();
  7118. if (this.dayGrid) {
  7119. this.dayGrid.destroySelection();
  7120. }
  7121. }
  7122. });
  7123. ;;
  7124. /* A week view with an all-day cell area at the top, and a time grid below
  7125. ----------------------------------------------------------------------------------------------------------------------*/
  7126. // TODO: a WeekView mixin for calculating dates and titles
  7127. fcViews.agendaWeek = AgendaWeekView; // register the view
  7128. function AgendaWeekView(calendar) {
  7129. AgendaView.call(this, calendar); // call the super-constructor
  7130. }
  7131. AgendaWeekView.prototype = createObject(AgendaView.prototype); // define the super-class
  7132. $.extend(AgendaWeekView.prototype, {
  7133. name: 'agendaWeek',
  7134. incrementDate: function(date, delta) {
  7135. return date.clone().stripTime().add(delta, 'weeks').startOf('week');
  7136. },
  7137. render: function(date) {
  7138. this.intervalStart = date.clone().stripTime().startOf('week');
  7139. this.intervalEnd = this.intervalStart.clone().add(1, 'weeks');
  7140. this.start = this.skipHiddenDays(this.intervalStart);
  7141. this.end = this.skipHiddenDays(this.intervalEnd, -1, true);
  7142. this.title = this.calendar.formatRange(
  7143. this.start,
  7144. this.end.clone().subtract(1), // make inclusive by subtracting 1 ms
  7145. this.opt('titleFormat'),
  7146. ' \u2014 ' // emphasized dash
  7147. );
  7148. AgendaView.prototype.render.call(this, this.getCellsPerWeek()); // call the super-method
  7149. }
  7150. });
  7151. ;;
  7152. /* A day view with an all-day cell area at the top, and a time grid below
  7153. ----------------------------------------------------------------------------------------------------------------------*/
  7154. fcViews.agendaDay = AgendaDayView; // register the view
  7155. function AgendaDayView(calendar) {
  7156. AgendaView.call(this, calendar); // call the super-constructor
  7157. }
  7158. AgendaDayView.prototype = createObject(AgendaView.prototype); // define the super-class
  7159. $.extend(AgendaDayView.prototype, {
  7160. name: 'agendaDay',
  7161. incrementDate: function(date, delta) {
  7162. var out = date.clone().stripTime().add(delta, 'days');
  7163. out = this.skipHiddenDays(out, delta < 0 ? -1 : 1);
  7164. return out;
  7165. },
  7166. render: function(date) {
  7167. this.start = this.intervalStart = date.clone().stripTime();
  7168. this.end = this.intervalEnd = this.start.clone().add(1, 'days');
  7169. this.title = this.calendar.formatDate(this.start, this.opt('titleFormat'));
  7170. AgendaView.prototype.render.call(this, 1); // call the super-method
  7171. }
  7172. });
  7173. ;;
  7174. });