|
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934 |
- /*!
- * FullCalendar v2.0.0-beta2
- * Docs & License: http://arshaw.com/fullcalendar/
- * (c) 2013 Adam Shaw
- */
-
- (function(factory) {
- if (typeof define === 'function' && define.amd) {
- define([ 'jquery', 'moment' ], factory);
- }
- else {
- factory(jQuery, moment);
- }
- })(function($, moment) {
-
- ;;
-
- var defaults = {
-
- lang: 'en',
-
- defaultTimedEventDuration: '02:00:00',
- defaultAllDayEventDuration: { days: 1 },
- forceEventDuration: false,
- nextDayThreshold: '09:00:00', // 9am
-
- // display
- defaultView: 'month',
- aspectRatio: 1.35,
- header: {
- left: 'title',
- center: '',
- right: 'today prev,next'
- },
- weekends: true,
- weekNumbers: false,
-
- weekNumberTitle: 'W',
- weekNumberCalculation: 'local',
-
- //editable: false,
-
- // event ajax
- lazyFetching: true,
- startParam: 'start',
- endParam: 'end',
- timezoneParam: 'timezone',
-
- //allDayDefault: undefined,
-
- // time formats
- titleFormat: {
- month: 'MMMM YYYY', // like "September 1986". each language will override this
- week: 'll', // like "Sep 4 1986"
- day: 'LL' // like "September 4 1986"
- },
- columnFormat: {
- month: 'ddd', // like "Sat"
- week: generateWeekColumnFormat,
- day: 'dddd' // like "Saturday"
- },
- timeFormat: { // for event elements
- 'default': generateShortTimeFormat
- },
-
- // locale
- isRTL: false,
- buttonText: {
- prev: "prev",
- next: "next",
- prevYear: "prev year",
- nextYear: "next year",
- today: 'today',
- month: 'month',
- week: 'week',
- day: 'day'
- },
-
- buttonIcons: {
- prev: 'left-single-arrow',
- next: 'right-single-arrow',
- prevYear: 'left-double-arrow',
- nextYear: 'right-double-arrow'
- },
-
- // jquery-ui theming
- theme: false,
- themeButtonIcons: {
- prev: 'circle-triangle-w',
- next: 'circle-triangle-e',
- prevYear: 'seek-prev',
- nextYear: 'seek-next'
- },
-
- //selectable: false,
- unselectAuto: true,
-
- dropAccept: '*',
-
- handleWindowResize: true
-
- };
-
-
- function generateShortTimeFormat(options, langData) {
- return langData.longDateFormat('LT')
- .replace(':mm', '(:mm)')
- .replace(/(\Wmm)$/, '($1)') // like above, but for foreign langs
- .replace(/\s*a$/i, 't'); // convert to AM/PM/am/pm to lowercase one-letter. remove any spaces beforehand
- }
-
-
- function generateWeekColumnFormat(options, langData) {
- var format = langData.longDateFormat('L'); // for the format like "MM/DD/YYYY"
- format = format.replace(/^Y+[^\w\s]*|[^\w\s]*Y+$/g, ''); // strip the year off the edge, as well as other misc non-whitespace chars
- if (options.isRTL) {
- format += ' ddd'; // for RTL, add day-of-week to end
- }
- else {
- format = 'ddd ' + format; // for LTR, add day-of-week to beginning
- }
- return format;
- }
-
-
- var langOptionHash = {
- en: {
- columnFormat: {
- week: 'ddd M/D' // override for english. different from the generated default, which is MM/DD
- }
- }
- };
-
-
- // right-to-left defaults
- var rtlDefaults = {
- header: {
- left: 'next,prev today',
- center: '',
- right: 'title'
- },
- buttonIcons: {
- prev: 'right-single-arrow',
- next: 'left-single-arrow',
- prevYear: 'right-double-arrow',
- nextYear: 'left-double-arrow'
- },
- themeButtonIcons: {
- prev: 'circle-triangle-e',
- next: 'circle-triangle-w',
- nextYear: 'seek-prev',
- prevYear: 'seek-next'
- }
- };
-
-
-
- ;;
-
- var fc = $.fullCalendar = { version: "2.0.0-beta2" };
- var fcViews = fc.views = {};
-
-
- $.fn.fullCalendar = function(options) {
- var args = Array.prototype.slice.call(arguments, 1); // for a possible method call
- var res = this; // what this function will return (this jQuery object by default)
-
- this.each(function(i, _element) { // loop each DOM element involved
- var element = $(_element);
- var calendar = element.data('fullCalendar'); // get the existing calendar object (if any)
- var singleRes; // the returned value of this single method call
-
- // a method call
- if (typeof options === 'string') {
- if (calendar && $.isFunction(calendar[options])) {
- singleRes = calendar[options].apply(calendar, args);
- if (!i) {
- res = singleRes; // record the first method call result
- }
- if (options === 'destroy') { // for the destroy method, must remove Calendar object data
- element.removeData('fullCalendar');
- }
- }
- }
- // a new calendar initialization
- else if (!calendar) { // don't initialize twice
- calendar = new Calendar(element, options);
- element.data('fullCalendar', calendar);
- calendar.render();
- }
- });
-
- return res;
- };
-
-
- // function for adding/overriding defaults
- function setDefaults(d) {
- mergeOptions(defaults, d);
- }
-
-
- // Recursively combines option hash-objects.
- // Better than `$.extend(true, ...)` because arrays are not traversed/copied.
- //
- // called like:
- // mergeOptions(target, obj1, obj2, ...)
- //
- function mergeOptions(target) {
-
- function mergeIntoTarget(name, value) {
- if ($.isPlainObject(value) && $.isPlainObject(target[name]) && !isForcedAtomicOption(name)) {
- // merge into a new object to avoid destruction
- target[name] = mergeOptions({}, target[name], value); // combine. `value` object takes precedence
- }
- else if (value !== undefined) { // only use values that are set and not undefined
- target[name] = value;
- }
- }
-
- for (var i=1; i<arguments.length; i++) {
- $.each(arguments[i], mergeIntoTarget);
- }
-
- return target;
- }
-
-
- // overcome sucky view-option-hash and option-merging behavior messing with options it shouldn't
- function isForcedAtomicOption(name) {
- // Any option that ends in "Time" or "Duration" is probably a Duration,
- // and these will commonly be specified as plain objects, which we don't want to mess up.
- return /(Time|Duration)$/.test(name);
- }
- // FIX: find a different solution for view-option-hashes and have a whitelist
- // for options that can be recursively merged.
-
- ;;
-
- //var langOptionHash = {}; // initialized in defaults.js
- fc.langs = langOptionHash; // expose
-
-
- // Initialize jQuery UI Datepicker translations while using some of the translations
- // for our own purposes. Will set this as the default language for datepicker.
- // Called from a translation file.
- fc.datepickerLang = function(langCode, datepickerLangCode, options) {
- var langOptions = langOptionHash[langCode];
-
- // initialize FullCalendar's lang hash for this language
- if (!langOptions) {
- langOptions = langOptionHash[langCode] = {};
- }
-
- // merge certain Datepicker options into FullCalendar's options
- mergeOptions(langOptions, {
- isRTL: options.isRTL,
- weekNumberTitle: options.weekHeader,
- titleFormat: {
- month: options.showMonthAfterYear ?
- 'YYYY[' + options.yearSuffix + '] MMMM' :
- 'MMMM YYYY[' + options.yearSuffix + ']'
- },
- buttonText: {
- // the translations sometimes wrongly contain HTML entities
- prev: stripHTMLEntities(options.prevText),
- next: stripHTMLEntities(options.nextText),
- today: stripHTMLEntities(options.currentText)
- }
- });
-
- // is jQuery UI Datepicker is on the page?
- if ($.datepicker) {
-
- // Register the language data.
- // FullCalendar and MomentJS use language codes like "pt-br" but Datepicker
- // does it like "pt-BR" or if it doesn't have the language, maybe just "pt".
- // Make an alias so the language can be referenced either way.
- $.datepicker.regional[datepickerLangCode] =
- $.datepicker.regional[langCode] = // alias
- options;
-
- // Alias 'en' to the default language data. Do this every time.
- $.datepicker.regional.en = $.datepicker.regional[''];
-
- // Set as Datepicker's global defaults.
- $.datepicker.setDefaults(options);
- }
- };
-
-
- // Sets FullCalendar-specific translations. Also sets the language as the global default.
- // Called from a translation file.
- fc.lang = function(langCode, options) {
- var langOptions;
-
- if (options) {
- langOptions = langOptionHash[langCode];
-
- // initialize the hash for this language
- if (!langOptions) {
- langOptions = langOptionHash[langCode] = {};
- }
-
- mergeOptions(langOptions, options || {});
- }
-
- // set it as the default language for FullCalendar
- defaults.lang = langCode;
- };
- ;;
-
-
- function Calendar(element, instanceOptions) {
- var t = this;
-
-
-
- // Build options object
- // -----------------------------------------------------------------------------------
- // Precedence (lowest to highest): defaults, rtlDefaults, langOptions, instanceOptions
-
- instanceOptions = instanceOptions || {};
-
- var options = mergeOptions({}, defaults, instanceOptions);
- var langOptions;
-
- // determine language options
- if (options.lang in langOptionHash) {
- langOptions = langOptionHash[options.lang];
- }
- else {
- langOptions = langOptionHash[defaults.lang];
- }
-
- if (langOptions) { // if language options exist, rebuild...
- options = mergeOptions({}, defaults, langOptions, instanceOptions);
- }
-
- if (options.isRTL) { // is isRTL, rebuild...
- options = mergeOptions({}, defaults, rtlDefaults, langOptions || {}, instanceOptions);
- }
-
-
-
- // Exports
- // -----------------------------------------------------------------------------------
-
- t.options = options;
- t.render = render;
- t.destroy = destroy;
- t.refetchEvents = refetchEvents;
- t.reportEvents = reportEvents;
- t.reportEventChange = reportEventChange;
- t.rerenderEvents = rerenderEvents;
- t.changeView = changeView;
- t.select = select;
- t.unselect = unselect;
- t.prev = prev;
- t.next = next;
- t.prevYear = prevYear;
- t.nextYear = nextYear;
- t.today = today;
- t.gotoDate = gotoDate;
- t.incrementDate = incrementDate;
- t.getDate = getDate;
- t.getCalendar = getCalendar;
- t.getView = getView;
- t.option = option;
- t.trigger = trigger;
-
-
-
- // Language-data Internals
- // -----------------------------------------------------------------------------------
- // Apply overrides to the current language's data
-
- var langData = createObject( // make a cheap clone
- moment.langData(options.lang)
- );
-
- if (options.monthNames) {
- langData._months = options.monthNames;
- }
- if (options.monthNamesShort) {
- langData._monthsShort = options.monthNamesShort;
- }
- if (options.dayNames) {
- langData._weekdays = options.dayNames;
- }
- if (options.dayNamesShort) {
- langData._weekdaysShort = options.dayNamesShort;
- }
- if (options.firstDay) {
- var _week = createObject(langData._week); // _week: { dow: # }
- _week.dow = options.firstDay;
- langData._week = _week;
- }
-
-
-
- // Calendar-specific Date Utilities
- // -----------------------------------------------------------------------------------
-
-
- t.defaultAllDayEventDuration = moment.duration(options.defaultAllDayEventDuration);
- t.defaultTimedEventDuration = moment.duration(options.defaultTimedEventDuration);
-
-
- // Builds a moment using the settings of the current calendar: timezone and language.
- // Accepts anything the vanilla moment() constructor accepts.
- t.moment = function() {
- var mom;
-
- if (options.timezone === 'local') {
- mom = fc.moment.apply(null, arguments);
- }
- else if (options.timezone === 'UTC') {
- mom = fc.moment.utc.apply(null, arguments);
- }
- else {
- mom = fc.moment.parseZone.apply(null, arguments);
- }
-
- mom._lang = langData;
-
- return mom;
- };
-
-
- // Returns a boolean about whether or not the calendar knows how to calculate
- // the timezone offset of arbitrary dates in the current timezone.
- t.getIsAmbigTimezone = function() {
- return options.timezone !== 'local' && options.timezone !== 'UTC';
- };
-
-
- // Returns a copy of the given date in the current timezone of it is ambiguously zoned.
- // This will also give the date an unambiguous time.
- t.rezoneDate = function(date) {
- return t.moment(date.toArray());
- };
-
-
- // Returns a moment for the current date, as defined by the client's computer,
- // or overridden by the `now` option.
- t.getNow = function() {
- var now = options.now;
- if (typeof now === 'function') {
- now = now();
- }
- return t.moment(now);
- };
-
-
- // Calculates the week number for a moment according to the calendar's
- // `weekNumberCalculation` setting.
- t.calculateWeekNumber = function(mom) {
- var calc = options.weekNumberCalculation;
-
- if (typeof calc === 'function') {
- return calc(mom);
- }
- else if (calc === 'local') {
- return mom.week();
- }
- else if (calc.toUpperCase() === 'ISO') {
- return mom.isoWeek();
- }
- };
-
-
- // Get an event's normalized end date. If not present, calculate it from the defaults.
- t.getEventEnd = function(event) {
- if (event.end) {
- return event.end.clone();
- }
- else {
- return t.getDefaultEventEnd(event.allDay, event.start);
- }
- };
-
-
- // Given an event's allDay status and start date, return swhat its fallback end date should be.
- t.getDefaultEventEnd = function(allDay, start) { // TODO: rename to computeDefaultEventEnd
- var end = start.clone();
-
- if (allDay) {
- end.stripTime().add(t.defaultAllDayEventDuration);
- }
- else {
- end.add(t.defaultTimedEventDuration);
- }
-
- if (t.getIsAmbigTimezone()) {
- end.stripZone(); // we don't know what the tzo should be
- }
-
- return end;
- };
-
-
-
- // Date-formatting Utilities
- // -----------------------------------------------------------------------------------
-
-
- // Like the vanilla formatRange, but with calendar-specific settings applied.
- t.formatRange = function(m1, m2, formatStr) {
-
- // a function that returns a formatStr // TODO: in future, precompute this
- if (typeof formatStr === 'function') {
- formatStr = formatStr.call(t, options, langData);
- }
-
- return formatRange(m1, m2, formatStr, null, options.isRTL);
- };
-
-
- // Like the vanilla formatDate, but with calendar-specific settings applied.
- t.formatDate = function(mom, formatStr) {
-
- // a function that returns a formatStr // TODO: in future, precompute this
- if (typeof formatStr === 'function') {
- formatStr = formatStr.call(t, options, langData);
- }
-
- return formatDate(mom, formatStr);
- };
-
-
-
- // Imports
- // -----------------------------------------------------------------------------------
-
-
- EventManager.call(t, options);
- var isFetchNeeded = t.isFetchNeeded;
- var fetchEvents = t.fetchEvents;
-
-
-
- // Locals
- // -----------------------------------------------------------------------------------
-
-
- var _element = element[0];
- var header;
- var headerElement;
- var content;
- var tm; // for making theme classes
- var currentView;
- var elementOuterWidth;
- var suggestedViewHeight;
- var resizeUID = 0;
- var ignoreWindowResize = 0;
- var date;
- var events = [];
- var _dragElement;
-
-
-
- // Main Rendering
- // -----------------------------------------------------------------------------------
-
-
- if (options.defaultDate != null) {
- date = t.moment(options.defaultDate);
- }
- else {
- date = t.getNow();
- }
-
-
- function render(inc) {
- if (!content) {
- initialRender();
- }
- else if (elementVisible()) {
- // mainly for the public API
- calcSize();
- _renderView(inc);
- }
- }
-
-
- function initialRender() {
- tm = options.theme ? 'ui' : 'fc';
- element.addClass('fc');
- if (options.isRTL) {
- element.addClass('fc-rtl');
- }
- else {
- element.addClass('fc-ltr');
- }
- if (options.theme) {
- element.addClass('ui-widget');
- }
-
- content = $("<div class='fc-content' />")
- .prependTo(element);
-
- header = new Header(t, options);
- headerElement = header.render();
- if (headerElement) {
- element.prepend(headerElement);
- }
-
- changeView(options.defaultView);
-
- if (options.handleWindowResize) {
- $(window).resize(windowResize);
- }
-
- // needed for IE in a 0x0 iframe, b/c when it is resized, never triggers a windowResize
- if (!bodyVisible()) {
- lateRender();
- }
- }
-
-
- // called when we know the calendar couldn't be rendered when it was initialized,
- // but we think it's ready now
- function lateRender() {
- setTimeout(function() { // IE7 needs this so dimensions are calculated correctly
- if (!currentView.start && bodyVisible()) { // !currentView.start makes sure this never happens more than once
- renderView();
- }
- },0);
- }
-
-
- function destroy() {
-
- if (currentView) {
- trigger('viewDestroy', currentView, currentView, currentView.element);
- currentView.triggerEventDestroy();
- }
-
- $(window).unbind('resize', windowResize);
-
- header.destroy();
- content.remove();
- element.removeClass('fc fc-rtl ui-widget');
- }
-
-
- function elementVisible() {
- return element.is(':visible');
- }
-
-
- function bodyVisible() {
- return $('body').is(':visible');
- }
-
-
-
- // View Rendering
- // -----------------------------------------------------------------------------------
-
-
- function changeView(newViewName) {
- if (!currentView || newViewName != currentView.name) {
- _changeView(newViewName);
- }
- }
-
-
- function _changeView(newViewName) {
- ignoreWindowResize++;
-
- if (currentView) {
- trigger('viewDestroy', currentView, currentView, currentView.element);
- unselect();
- currentView.triggerEventDestroy(); // trigger 'eventDestroy' for each event
- freezeContentHeight();
- currentView.element.remove();
- header.deactivateButton(currentView.name);
- }
-
- header.activateButton(newViewName);
-
- currentView = new fcViews[newViewName](
- $("<div class='fc-view fc-view-" + newViewName + "' />")
- .appendTo(content),
- t // the calendar object
- );
-
- renderView();
- unfreezeContentHeight();
-
- ignoreWindowResize--;
- }
-
-
- function renderView(inc) {
- if (
- !currentView.start || // never rendered before
- inc || // explicit date window change
- !date.isWithin(currentView.intervalStart, currentView.intervalEnd) // implicit date window change
- ) {
- if (elementVisible()) {
- _renderView(inc);
- }
- }
- }
-
-
- function _renderView(inc) { // assumes elementVisible
- ignoreWindowResize++;
-
- if (currentView.start) { // already been rendered?
- trigger('viewDestroy', currentView, currentView, currentView.element);
- unselect();
- clearEvents();
- }
-
- freezeContentHeight();
- if (inc) {
- date = currentView.incrementDate(date, inc);
- }
- currentView.render(date.clone()); // the view's render method ONLY renders the skeleton, nothing else
- setSize();
- unfreezeContentHeight();
- (currentView.afterRender || noop)();
-
- updateTitle();
- updateTodayButton();
-
- trigger('viewRender', currentView, currentView, currentView.element);
-
- ignoreWindowResize--;
-
- getAndRenderEvents();
- }
-
-
-
- // Resizing
- // -----------------------------------------------------------------------------------
-
-
- function updateSize() {
- if (elementVisible()) {
- unselect();
- clearEvents();
- calcSize();
- setSize();
- renderEvents();
- }
- }
-
-
- function calcSize() { // assumes elementVisible
- if (options.contentHeight) {
- suggestedViewHeight = options.contentHeight;
- }
- else if (options.height) {
- suggestedViewHeight = options.height - (headerElement ? headerElement.height() : 0) - vsides(content);
- }
- else {
- suggestedViewHeight = Math.round(content.width() / Math.max(options.aspectRatio, .5));
- }
- }
-
-
- function setSize() { // assumes elementVisible
-
- if (suggestedViewHeight === undefined) {
- calcSize(); // for first time
- // NOTE: we don't want to recalculate on every renderView because
- // it could result in oscillating heights due to scrollbars.
- }
-
- ignoreWindowResize++;
- currentView.setHeight(suggestedViewHeight);
- currentView.setWidth(content.width());
- ignoreWindowResize--;
-
- elementOuterWidth = element.outerWidth();
- }
-
-
- function windowResize() {
- if (!ignoreWindowResize) {
- if (currentView.start) { // view has already been rendered
- var uid = ++resizeUID;
- setTimeout(function() { // add a delay
- if (uid == resizeUID && !ignoreWindowResize && elementVisible()) {
- if (elementOuterWidth != (elementOuterWidth = element.outerWidth())) {
- ignoreWindowResize++; // in case the windowResize callback changes the height
- updateSize();
- currentView.trigger('windowResize', _element);
- ignoreWindowResize--;
- }
- }
- }, 200);
- }else{
- // calendar must have been initialized in a 0x0 iframe that has just been resized
- lateRender();
- }
- }
- }
-
-
-
- /* Event Fetching/Rendering
- -----------------------------------------------------------------------------*/
- // TODO: going forward, most of this stuff should be directly handled by the view
-
-
- function refetchEvents() { // can be called as an API method
- clearEvents();
- fetchAndRenderEvents();
- }
-
-
- function rerenderEvents(modifiedEventID) { // can be called as an API method
- clearEvents();
- renderEvents(modifiedEventID);
- }
-
-
- function renderEvents(modifiedEventID) { // TODO: remove modifiedEventID hack
- if (elementVisible()) {
- currentView.renderEvents(events, modifiedEventID); // actually render the DOM elements
- currentView.trigger('eventAfterAllRender');
- }
- }
-
-
- function clearEvents() {
- currentView.triggerEventDestroy(); // trigger 'eventDestroy' for each event
- currentView.clearEvents(); // actually remove the DOM elements
- currentView.clearEventData(); // for View.js, TODO: unify with clearEvents
- }
-
-
- function getAndRenderEvents() {
- if (!options.lazyFetching || isFetchNeeded(currentView.start, currentView.end)) {
- fetchAndRenderEvents();
- }
- else {
- renderEvents();
- }
- }
-
-
- function fetchAndRenderEvents() {
- fetchEvents(currentView.start, currentView.end);
- // ... will call reportEvents
- // ... which will call renderEvents
- }
-
-
- // called when event data arrives
- function reportEvents(_events) {
- events = _events;
- renderEvents();
- }
-
-
- // called when a single event's data has been changed
- function reportEventChange(eventID) {
- rerenderEvents(eventID);
- }
-
-
-
- /* Header Updating
- -----------------------------------------------------------------------------*/
-
-
- function updateTitle() {
- header.updateTitle(currentView.title);
- }
-
-
- function updateTodayButton() {
- var now = t.getNow();
- if (now.isWithin(currentView.intervalStart, currentView.intervalEnd)) {
- header.disableButton('today');
- }
- else {
- header.enableButton('today');
- }
- }
-
-
-
- /* Selection
- -----------------------------------------------------------------------------*/
-
-
- function select(start, end) {
- currentView.select(start, end);
- }
-
-
- function unselect() { // safe to be called before renderView
- if (currentView) {
- currentView.unselect();
- }
- }
-
-
-
- /* Date
- -----------------------------------------------------------------------------*/
-
-
- function prev() {
- renderView(-1);
- }
-
-
- function next() {
- renderView(1);
- }
-
-
- function prevYear() {
- date.add('years', -1);
- renderView();
- }
-
-
- function nextYear() {
- date.add('years', 1);
- renderView();
- }
-
-
- function today() {
- date = t.getNow();
- renderView();
- }
-
-
- function gotoDate(dateInput) {
- date = t.moment(dateInput);
- renderView();
- }
-
-
- function incrementDate() {
- date.add.apply(date, arguments);
- renderView();
- }
-
-
- function getDate() {
- return date.clone();
- }
-
-
-
- /* Height "Freezing"
- -----------------------------------------------------------------------------*/
-
-
- function freezeContentHeight() {
- content.css({
- width: '100%',
- height: content.height(),
- overflow: 'hidden'
- });
- }
-
-
- function unfreezeContentHeight() {
- content.css({
- width: '',
- height: '',
- overflow: ''
- });
- }
-
-
-
- /* Misc
- -----------------------------------------------------------------------------*/
-
-
- function getCalendar() {
- return t;
- }
-
-
- function getView() {
- return currentView;
- }
-
-
- function option(name, value) {
- if (value === undefined) {
- return options[name];
- }
- if (name == 'height' || name == 'contentHeight' || name == 'aspectRatio') {
- options[name] = value;
- updateSize();
- }
- }
-
-
- function trigger(name, thisObj) {
- if (options[name]) {
- return options[name].apply(
- thisObj || _element,
- Array.prototype.slice.call(arguments, 2)
- );
- }
- }
-
-
-
- /* External Dragging
- ------------------------------------------------------------------------*/
-
- if (options.droppable) {
- // TODO: unbind on destroy
- $(document)
- .bind('dragstart', function(ev, ui) {
- var _e = ev.target;
- var e = $(_e);
- if (!e.parents('.fc').length) { // not already inside a calendar
- var accept = options.dropAccept;
- if ($.isFunction(accept) ? accept.call(_e, e) : e.is(accept)) {
- _dragElement = _e;
- currentView.dragStart(_dragElement, ev, ui);
- }
- }
- })
- .bind('dragstop', function(ev, ui) {
- if (_dragElement) {
- currentView.dragStop(_dragElement, ev, ui);
- _dragElement = null;
- }
- });
- }
-
-
- }
-
- ;;
-
- function Header(calendar, options) {
- var t = this;
-
-
- // exports
- t.render = render;
- t.destroy = destroy;
- t.updateTitle = updateTitle;
- t.activateButton = activateButton;
- t.deactivateButton = deactivateButton;
- t.disableButton = disableButton;
- t.enableButton = enableButton;
-
-
- // locals
- var element = $([]);
- var tm;
-
-
-
- function render() {
- tm = options.theme ? 'ui' : 'fc';
- var sections = options.header;
- if (sections) {
- element = $("<table class='fc-header' style='width:100%'/>")
- .append(
- $("<tr/>")
- .append(renderSection('left'))
- .append(renderSection('center'))
- .append(renderSection('right'))
- );
- return element;
- }
- }
-
-
- function destroy() {
- element.remove();
- }
-
-
- function renderSection(position) {
- var e = $("<td class='fc-header-" + position + "'/>");
- var buttonStr = options.header[position];
- if (buttonStr) {
- $.each(buttonStr.split(' '), function(i) {
- if (i > 0) {
- e.append("<span class='fc-header-space'/>");
- }
- var prevButton;
- $.each(this.split(','), function(j, buttonName) {
- if (buttonName == 'title') {
- e.append("<span class='fc-header-title'><h2> </h2></span>");
- if (prevButton) {
- prevButton.addClass(tm + '-corner-right');
- }
- prevButton = null;
- }else{
- var buttonClick;
- if (calendar[buttonName]) {
- buttonClick = calendar[buttonName]; // calendar method
- }
- else if (fcViews[buttonName]) {
- buttonClick = function() {
- button.removeClass(tm + '-state-hover'); // forget why
- calendar.changeView(buttonName);
- };
- }
- if (buttonClick) {
-
- // smartProperty allows different text per view button (ex: "Agenda Week" vs "Basic Week")
- var themeIcon = smartProperty(options.themeButtonIcons, buttonName);
- var normalIcon = smartProperty(options.buttonIcons, buttonName);
- var text = smartProperty(options.buttonText, buttonName);
- var html;
-
- if (themeIcon && options.theme) {
- html = "<span class='ui-icon ui-icon-" + themeIcon + "'></span>";
- }
- else if (normalIcon && !options.theme) {
- html = "<span class='fc-icon fc-icon-" + normalIcon + "'></span>";
- }
- else {
- html = htmlEscape(text || buttonName);
- }
-
- var button = $(
- "<span class='fc-button fc-button-" + buttonName + " " + tm + "-state-default'>" +
- html +
- "</span>"
- )
- .click(function() {
- if (!button.hasClass(tm + '-state-disabled')) {
- buttonClick();
- }
- })
- .mousedown(function() {
- button
- .not('.' + tm + '-state-active')
- .not('.' + tm + '-state-disabled')
- .addClass(tm + '-state-down');
- })
- .mouseup(function() {
- button.removeClass(tm + '-state-down');
- })
- .hover(
- function() {
- button
- .not('.' + tm + '-state-active')
- .not('.' + tm + '-state-disabled')
- .addClass(tm + '-state-hover');
- },
- function() {
- button
- .removeClass(tm + '-state-hover')
- .removeClass(tm + '-state-down');
- }
- )
- .appendTo(e);
- disableTextSelection(button);
- if (!prevButton) {
- button.addClass(tm + '-corner-left');
- }
- prevButton = button;
- }
- }
- });
- if (prevButton) {
- prevButton.addClass(tm + '-corner-right');
- }
- });
- }
- return e;
- }
-
-
- function updateTitle(html) {
- element.find('h2')
- .html(html);
- }
-
-
- function activateButton(buttonName) {
- element.find('span.fc-button-' + buttonName)
- .addClass(tm + '-state-active');
- }
-
-
- function deactivateButton(buttonName) {
- element.find('span.fc-button-' + buttonName)
- .removeClass(tm + '-state-active');
- }
-
-
- function disableButton(buttonName) {
- element.find('span.fc-button-' + buttonName)
- .addClass(tm + '-state-disabled');
- }
-
-
- function enableButton(buttonName) {
- element.find('span.fc-button-' + buttonName)
- .removeClass(tm + '-state-disabled');
- }
-
-
- }
-
- ;;
-
- fc.sourceNormalizers = [];
- fc.sourceFetchers = [];
-
- var ajaxDefaults = {
- dataType: 'json',
- cache: false
- };
-
- var eventGUID = 1;
-
-
- function EventManager(options) { // assumed to be a calendar
- var t = this;
-
-
- // exports
- t.isFetchNeeded = isFetchNeeded;
- t.fetchEvents = fetchEvents;
- t.addEventSource = addEventSource;
- t.removeEventSource = removeEventSource;
- t.updateEvent = updateEvent;
- t.renderEvent = renderEvent;
- t.removeEvents = removeEvents;
- t.clientEvents = clientEvents;
- t.mutateEvent = mutateEvent;
-
-
- // imports
- var trigger = t.trigger;
- var getView = t.getView;
- var reportEvents = t.reportEvents;
- var getEventEnd = t.getEventEnd;
-
-
- // locals
- var stickySource = { events: [] };
- var sources = [ stickySource ];
- var rangeStart, rangeEnd;
- var currentFetchID = 0;
- var pendingSourceCnt = 0;
- var loadingLevel = 0;
- var cache = [];
-
-
-
- var _sources = options.eventSources || [];
-
- if (options.events) {
- _sources.push(options.events);
- }
-
- for (var i=0; i<_sources.length; i++) {
- _addEventSource(_sources[i]);
- }
-
-
-
- /* Fetching
- -----------------------------------------------------------------------------*/
-
-
- function isFetchNeeded(start, end) {
- return !rangeStart || // nothing has been fetched yet?
- // or, a part of the new range is outside of the old range? (after normalizing)
- start.clone().stripZone() < rangeStart.clone().stripZone() ||
- end.clone().stripZone() > rangeEnd.clone().stripZone();
- }
-
-
- function fetchEvents(start, end) {
- rangeStart = start;
- rangeEnd = end;
- cache = [];
- var fetchID = ++currentFetchID;
- var len = sources.length;
- pendingSourceCnt = len;
- for (var i=0; i<len; i++) {
- fetchEventSource(sources[i], fetchID);
- }
- }
-
-
- function fetchEventSource(source, fetchID) {
- _fetchEventSource(source, function(events) {
- if (fetchID == currentFetchID) {
-
- if (events) {
- for (var i=0; i<events.length; i++) {
- var event = buildEvent(events[i], source);
- if (event) {
- cache.push(event);
- }
- }
- }
-
- pendingSourceCnt--;
- if (!pendingSourceCnt) {
- reportEvents(cache);
- }
- }
- });
- }
-
-
- function _fetchEventSource(source, callback) {
- var i;
- var fetchers = fc.sourceFetchers;
- var res;
-
- for (i=0; i<fetchers.length; i++) {
- res = fetchers[i].call(
- t, // this, the Calendar object
- source,
- rangeStart.clone(),
- rangeEnd.clone(),
- options.timezone,
- callback
- );
-
- if (res === true) {
- // the fetcher is in charge. made its own async request
- return;
- }
- else if (typeof res == 'object') {
- // the fetcher returned a new source. process it
- _fetchEventSource(res, callback);
- return;
- }
- }
-
- var events = source.events;
- if (events) {
- if ($.isFunction(events)) {
- pushLoading();
- events.call(
- t, // this, the Calendar object
- rangeStart.clone(),
- rangeEnd.clone(),
- options.timezone,
- function(events) {
- callback(events);
- popLoading();
- }
- );
- }
- else if ($.isArray(events)) {
- callback(events);
- }
- else {
- callback();
- }
- }else{
- var url = source.url;
- if (url) {
- var success = source.success;
- var error = source.error;
- var complete = source.complete;
-
- // retrieve any outbound GET/POST $.ajax data from the options
- var customData;
- if ($.isFunction(source.data)) {
- // supplied as a function that returns a key/value object
- customData = source.data();
- }
- else {
- // supplied as a straight key/value object
- customData = source.data;
- }
-
- // use a copy of the custom data so we can modify the parameters
- // and not affect the passed-in object.
- var data = $.extend({}, customData || {});
-
- var startParam = firstDefined(source.startParam, options.startParam);
- var endParam = firstDefined(source.endParam, options.endParam);
- var timezoneParam = firstDefined(source.timezoneParam, options.timezoneParam);
-
- if (startParam) {
- data[startParam] = rangeStart.format();
- }
- if (endParam) {
- data[endParam] = rangeEnd.format();
- }
- if (options.timezone && options.timezone != 'local') {
- data[timezoneParam] = options.timezone;
- }
-
- pushLoading();
- $.ajax($.extend({}, ajaxDefaults, source, {
- data: data,
- success: function(events) {
- events = events || [];
- var res = applyAll(success, this, arguments);
- if ($.isArray(res)) {
- events = res;
- }
- callback(events);
- },
- error: function() {
- applyAll(error, this, arguments);
- callback();
- },
- complete: function() {
- applyAll(complete, this, arguments);
- popLoading();
- }
- }));
- }else{
- callback();
- }
- }
- }
-
-
-
- /* Sources
- -----------------------------------------------------------------------------*/
-
-
- function addEventSource(source) {
- source = _addEventSource(source);
- if (source) {
- pendingSourceCnt++;
- fetchEventSource(source, currentFetchID); // will eventually call reportEvents
- }
- }
-
-
- function _addEventSource(source) {
- if ($.isFunction(source) || $.isArray(source)) {
- source = { events: source };
- }
- else if (typeof source == 'string') {
- source = { url: source };
- }
- if (typeof source == 'object') {
- normalizeSource(source);
- sources.push(source);
- return source;
- }
- }
-
-
- function removeEventSource(source) {
- sources = $.grep(sources, function(src) {
- return !isSourcesEqual(src, source);
- });
- // remove all client events from that source
- cache = $.grep(cache, function(e) {
- return !isSourcesEqual(e.source, source);
- });
- reportEvents(cache);
- }
-
-
-
- /* Manipulation
- -----------------------------------------------------------------------------*/
-
-
- function updateEvent(event) {
- mutateEvent(event);
- propagateMiscProperties(event);
- reportEvents(cache); // reports event modifications (so we can redraw)
- }
-
-
- var miscCopyableProps = [
- 'title',
- 'url',
- 'allDay',
- 'className',
- 'editable',
- 'color',
- 'backgroundColor',
- 'borderColor',
- 'textColor'
- ];
-
- function propagateMiscProperties(event) {
- var i;
- var cachedEvent;
- var j;
- var prop;
-
- for (i=0; i<cache.length; i++) {
- cachedEvent = cache[i];
- if (cachedEvent._id == event._id && cachedEvent !== event) {
- for (j=0; j<miscCopyableProps.length; j++) {
- prop = miscCopyableProps[j];
- if (event[prop] !== undefined) {
- cachedEvent[prop] = event[prop];
- }
- }
- }
- }
- }
-
-
-
- function renderEvent(eventData, stick) {
- var event = buildEvent(eventData);
- if (event) {
- if (!event.source) {
- if (stick) {
- stickySource.events.push(event);
- event.source = stickySource;
- }
- cache.push(event);
- }
- reportEvents(cache);
- }
- }
-
-
- function removeEvents(filter) {
- var i;
- if (!filter) { // remove all
- cache = [];
- // clear all array sources
- for (i=0; i<sources.length; i++) {
- if ($.isArray(sources[i].events)) {
- sources[i].events = [];
- }
- }
- }else{
- if (!$.isFunction(filter)) { // an event ID
- var id = filter + '';
- filter = function(e) {
- return e._id == id;
- };
- }
- cache = $.grep(cache, filter, true);
- // remove events from array sources
- for (i=0; i<sources.length; i++) {
- if ($.isArray(sources[i].events)) {
- sources[i].events = $.grep(sources[i].events, filter, true);
- }
- }
- }
- reportEvents(cache);
- }
-
-
- function clientEvents(filter) {
- if ($.isFunction(filter)) {
- return $.grep(cache, filter);
- }
- else if (filter) { // an event ID
- filter += '';
- return $.grep(cache, function(e) {
- return e._id == filter;
- });
- }
- return cache; // else, return all
- }
-
-
-
- /* Loading State
- -----------------------------------------------------------------------------*/
-
-
- function pushLoading() {
- if (!(loadingLevel++)) {
- trigger('loading', null, true, getView());
- }
- }
-
-
- function popLoading() {
- if (!(--loadingLevel)) {
- trigger('loading', null, false, getView());
- }
- }
-
-
-
- /* Event Normalization
- -----------------------------------------------------------------------------*/
-
- function buildEvent(data, source) { // source may be undefined!
- var out = {};
- var start;
- var end;
- var allDay;
- var allDayDefault;
-
- if (options.eventDataTransform) {
- data = options.eventDataTransform(data);
- }
- if (source && source.eventDataTransform) {
- data = source.eventDataTransform(data);
- }
-
- start = t.moment(data.start || data.date); // "date" is an alias for "start"
- if (!start.isValid()) {
- return;
- }
-
- end = null;
- if (data.end) {
- end = t.moment(data.end);
- if (!end.isValid()) {
- return;
- }
- }
-
- allDay = data.allDay;
- if (allDay === undefined) {
- allDayDefault = firstDefined(
- source ? source.allDayDefault : undefined,
- options.allDayDefault
- );
- if (allDayDefault !== undefined) {
- // use the default
- allDay = allDayDefault;
- }
- else {
- // all dates need to have ambig time for the event to be considered allDay
- allDay = !start.hasTime() && (!end || !end.hasTime());
- }
- }
-
- // normalize the date based on allDay
- if (allDay) {
- // neither date should have a time
- if (start.hasTime()) {
- start.stripTime();
- }
- if (end && end.hasTime()) {
- end.stripTime();
- }
- }
- else {
- // force a time/zone up the dates
- if (!start.hasTime()) {
- start = t.rezoneDate(start);
- }
- if (end && !end.hasTime()) {
- end = t.rezoneDate(end);
- }
- }
-
- // Copy all properties over to the resulting object.
- // The special-case properties will be copied over afterwards.
- $.extend(out, data);
-
- if (source) {
- out.source = source;
- }
-
- out._id = data._id || (data.id === undefined ? '_fc' + eventGUID++ : data.id + '');
-
- if (data.className) {
- if (typeof data.className == 'string') {
- out.className = data.className.split(/\s+/);
- }
- else { // assumed to be an array
- out.className = data.className;
- }
- }
- else {
- out.className = [];
- }
-
- out.allDay = allDay;
- out.start = start;
- out.end = end;
-
- if (options.forceEventDuration && !out.end) {
- out.end = getEventEnd(out);
- }
-
- backupEventDates(out);
-
- return out;
- }
-
-
-
- /* Event Modification Math
- -----------------------------------------------------------------------------------------*/
-
-
- // Modify the date(s) of an event and make this change propagate to all other events with
- // the same ID (related repeating events).
- //
- // If `newStart`/`newEnd` are not specified, the "new" dates are assumed to be `event.start` and `event.end`.
- // The "old" dates to be compare against are always `event._start` and `event._end` (set by EventManager).
- //
- // Returns a function that can be called to undo all the operations.
- //
- function mutateEvent(event, newStart, newEnd) {
- var oldAllDay = event._allDay;
- var oldStart = event._start;
- var oldEnd = event._end;
- var clearEnd = false;
- var newAllDay;
- var dateDelta;
- var durationDelta;
-
- // if no new dates were passed in, compare against the event's existing dates
- if (!newStart && !newEnd) {
- newStart = event.start;
- newEnd = event.end;
- }
-
- // NOTE: throughout this function, the initial values of `newStart` and `newEnd` are
- // preserved. These values may be undefined.
-
- // detect new allDay
- if (event.allDay != oldAllDay) { // if value has changed, use it
- newAllDay = event.allDay;
- }
- else { // otherwise, see if any of the new dates are allDay
- newAllDay = !(newStart || newEnd).hasTime();
- }
-
- // normalize the new dates based on allDay
- if (newAllDay) {
- if (newStart) {
- newStart = newStart.clone().stripTime();
- }
- if (newEnd) {
- newEnd = newEnd.clone().stripTime();
- }
- }
-
- // compute dateDelta
- if (newStart) {
- if (newAllDay) {
- dateDelta = dayishDiff(newStart, oldStart.clone().stripTime()); // treat oldStart as allDay
- }
- else {
- dateDelta = dayishDiff(newStart, oldStart);
- }
- }
-
- if (newAllDay != oldAllDay) {
- // if allDay has changed, always throw away the end
- clearEnd = true;
- }
- else if (newEnd) {
- durationDelta = dayishDiff(
- // new duration
- newEnd || t.getDefaultEventEnd(newAllDay, newStart || oldStart),
- newStart || oldStart
- ).subtract(dayishDiff(
- // subtract old duration
- oldEnd || t.getDefaultEventEnd(oldAllDay, oldStart),
- oldStart
- ));
- }
-
- return mutateEvents(
- clientEvents(event._id), // get events with this ID
- clearEnd,
- newAllDay,
- dateDelta,
- durationDelta
- );
- }
-
-
- // Modifies an array of events in the following ways (operations are in order):
- // - clear the event's `end`
- // - convert the event to allDay
- // - add `dateDelta` to the start and end
- // - add `durationDelta` to the event's duration
- //
- // Returns a function that can be called to undo all the operations.
- //
- function mutateEvents(events, clearEnd, forceAllDay, dateDelta, durationDelta) {
- var isAmbigTimezone = t.getIsAmbigTimezone();
- var undoFunctions = [];
-
- $.each(events, function(i, event) {
- var oldAllDay = event._allDay;
- var oldStart = event._start;
- var oldEnd = event._end;
- var newAllDay = forceAllDay != null ? forceAllDay : oldAllDay;
- var newStart = oldStart.clone();
- var newEnd = (!clearEnd && oldEnd) ? oldEnd.clone() : null;
-
- // NOTE: this function is responsible for transforming `newStart` and `newEnd`,
- // which were initialized to the OLD values first. `newEnd` may be null.
-
- // normlize newStart/newEnd to be consistent with newAllDay
- if (newAllDay) {
- newStart.stripTime();
- if (newEnd) {
- newEnd.stripTime();
- }
- }
- else {
- if (!newStart.hasTime()) {
- newStart = t.rezoneDate(newStart);
- }
- if (newEnd && !newEnd.hasTime()) {
- newEnd = t.rezoneDate(newEnd);
- }
- }
-
- // ensure we have an end date if necessary
- if (!newEnd && (options.forceEventDuration || +durationDelta)) {
- newEnd = t.getDefaultEventEnd(newAllDay, newStart);
- }
-
- // translate the dates
- newStart.add(dateDelta);
- if (newEnd) {
- newEnd.add(dateDelta).add(durationDelta);
- }
-
- // if the dates have changed, and we know it is impossible to recompute the
- // timezone offsets, strip the zone.
- if (isAmbigTimezone) {
- if (+dateDelta) {
- newStart.stripZone();
- }
- if (newEnd && (+dateDelta || +durationDelta)) {
- newEnd.stripZone();
- }
- }
-
- event.allDay = newAllDay;
- event.start = newStart;
- event.end = newEnd;
- backupEventDates(event);
-
- undoFunctions.push(function() {
- event.allDay = oldAllDay;
- event.start = oldStart;
- event.end = oldEnd;
- backupEventDates(event);
- });
- });
-
- return function() {
- for (var i=0; i<undoFunctions.length; i++) {
- undoFunctions[i]();
- }
- };
- }
-
-
-
- /* Utils
- ------------------------------------------------------------------------------*/
-
-
- function normalizeSource(source) {
- if (source.className) {
- // TODO: repeat code, same code for event classNames
- if (typeof source.className == 'string') {
- source.className = source.className.split(/\s+/);
- }
- }else{
- source.className = [];
- }
- var normalizers = fc.sourceNormalizers;
- for (var i=0; i<normalizers.length; i++) {
- normalizers[i].call(t, source);
- }
- }
-
-
- function isSourcesEqual(source1, source2) {
- return source1 && source2 && getSourcePrimitive(source1) == getSourcePrimitive(source2);
- }
-
-
- function getSourcePrimitive(source) {
- return ((typeof source == 'object') ? (source.events || source.url) : '') || source;
- }
-
-
- }
-
-
- // updates the "backup" properties, which are preserved in order to compute diffs later on.
- function backupEventDates(event) {
- event._allDay = event.allDay;
- event._start = event.start.clone();
- event._end = event.end ? event.end.clone() : null;
- }
-
- ;;
-
- fc.applyAll = applyAll;
-
-
-
- // Create an object that has the given prototype.
- // Just like Object.create
- function createObject(proto) {
- var f = function() {};
- f.prototype = proto;
- return new f();
- }
-
- // copy specifically-owned (non-protoype) properties of `b` onto `a`
- function extend(a, b) {
- for (var i in b) {
- if (b.hasOwnProperty(i)) {
- a[i] = b[i];
- }
- }
- }
-
-
-
- /* Date
- -----------------------------------------------------------------------------*/
-
-
- var dayIDs = ['sun', 'mon', 'tue', 'wed', 'thu', 'fri', 'sat'];
-
-
- // diffs the two moments into a Duration where full-days are recorded first,
- // then the remaining time.
- function dayishDiff(d1, d0) {
- return moment.duration({
- days: d1.clone().stripTime().diff(d0.clone().stripTime(), 'days'),
- ms: d1.time() - d0.time()
- });
- }
-
-
- function isNativeDate(input) {
- return Object.prototype.toString.call(input) === '[object Date]' ||
- input instanceof Date;
- }
-
-
-
- /* Event Element Binding
- -----------------------------------------------------------------------------*/
-
-
- function lazySegBind(container, segs, bindHandlers) {
- container.unbind('mouseover').mouseover(function(ev) {
- var parent=ev.target, e,
- i, seg;
- while (parent != this) {
- e = parent;
- parent = parent.parentNode;
- }
- if ((i = e._fci) !== undefined) {
- e._fci = undefined;
- seg = segs[i];
- bindHandlers(seg.event, seg.element, seg);
- $(ev.target).trigger(ev);
- }
- ev.stopPropagation();
- });
- }
-
-
-
- /* Element Dimensions
- -----------------------------------------------------------------------------*/
-
-
- function setOuterWidth(element, width, includeMargins) {
- for (var i=0, e; i<element.length; i++) {
- e = $(element[i]);
- e.width(Math.max(0, width - hsides(e, includeMargins)));
- }
- }
-
-
- function setOuterHeight(element, height, includeMargins) {
- for (var i=0, e; i<element.length; i++) {
- e = $(element[i]);
- e.height(Math.max(0, height - vsides(e, includeMargins)));
- }
- }
-
-
- function hsides(element, includeMargins) {
- return hpadding(element) + hborders(element) + (includeMargins ? hmargins(element) : 0);
- }
-
-
- function hpadding(element) {
- return (parseFloat($.css(element[0], 'paddingLeft', true)) || 0) +
- (parseFloat($.css(element[0], 'paddingRight', true)) || 0);
- }
-
-
- function hmargins(element) {
- return (parseFloat($.css(element[0], 'marginLeft', true)) || 0) +
- (parseFloat($.css(element[0], 'marginRight', true)) || 0);
- }
-
-
- function hborders(element) {
- return (parseFloat($.css(element[0], 'borderLeftWidth', true)) || 0) +
- (parseFloat($.css(element[0], 'borderRightWidth', true)) || 0);
- }
-
-
- function vsides(element, includeMargins) {
- return vpadding(element) + vborders(element) + (includeMargins ? vmargins(element) : 0);
- }
-
-
- function vpadding(element) {
- return (parseFloat($.css(element[0], 'paddingTop', true)) || 0) +
- (parseFloat($.css(element[0], 'paddingBottom', true)) || 0);
- }
-
-
- function vmargins(element) {
- return (parseFloat($.css(element[0], 'marginTop', true)) || 0) +
- (parseFloat($.css(element[0], 'marginBottom', true)) || 0);
- }
-
-
- function vborders(element) {
- return (parseFloat($.css(element[0], 'borderTopWidth', true)) || 0) +
- (parseFloat($.css(element[0], 'borderBottomWidth', true)) || 0);
- }
-
-
-
- /* Misc Utils
- -----------------------------------------------------------------------------*/
-
-
- //TODO: arraySlice
- //TODO: isFunction, grep ?
-
-
- function noop() { }
-
-
- function dateCompare(a, b) { // works with moments too
- return a - b;
- }
-
-
- function arrayMax(a) {
- return Math.max.apply(Math, a);
- }
-
-
- function smartProperty(obj, name) { // get a camel-cased/namespaced property of an object
- if (obj[name] !== undefined) {
- return obj[name];
- }
- var parts = name.split(/(?=[A-Z])/),
- i=parts.length-1, res;
- for (; i>=0; i--) {
- res = obj[parts[i].toLowerCase()];
- if (res !== undefined) {
- return res;
- }
- }
- return obj['default'];
- }
-
-
- function htmlEscape(s) {
- return (s + '').replace(/&/g, '&')
- .replace(/</g, '<')
- .replace(/>/g, '>')
- .replace(/'/g, ''')
- .replace(/"/g, '"')
- .replace(/\n/g, '<br />');
- }
-
-
- function stripHTMLEntities(text) {
- return text.replace(/&.*?;/g, '');
- }
-
-
- function disableTextSelection(element) {
- element
- .attr('unselectable', 'on')
- .css('MozUserSelect', 'none')
- .bind('selectstart.ui', function() { return false; });
- }
-
-
- /*
- function enableTextSelection(element) {
- element
- .attr('unselectable', 'off')
- .css('MozUserSelect', '')
- .unbind('selectstart.ui');
- }
- */
-
-
- function markFirstLast(e) { // TODO: use CSS selectors instead
- e.children()
- .removeClass('fc-first fc-last')
- .filter(':first-child')
- .addClass('fc-first')
- .end()
- .filter(':last-child')
- .addClass('fc-last');
- }
-
-
- function getSkinCss(event, opt) {
- var source = event.source || {};
- var eventColor = event.color;
- var sourceColor = source.color;
- var optionColor = opt('eventColor');
- var backgroundColor =
- event.backgroundColor ||
- eventColor ||
- source.backgroundColor ||
- sourceColor ||
- opt('eventBackgroundColor') ||
- optionColor;
- var borderColor =
- event.borderColor ||
- eventColor ||
- source.borderColor ||
- sourceColor ||
- opt('eventBorderColor') ||
- optionColor;
- var textColor =
- event.textColor ||
- source.textColor ||
- opt('eventTextColor');
- var statements = [];
- if (backgroundColor) {
- statements.push('background-color:' + backgroundColor);
- }
- if (borderColor) {
- statements.push('border-color:' + borderColor);
- }
- if (textColor) {
- statements.push('color:' + textColor);
- }
- return statements.join(';');
- }
-
-
- function applyAll(functions, thisObj, args) {
- if ($.isFunction(functions)) {
- functions = [ functions ];
- }
- if (functions) {
- var i;
- var ret;
- for (i=0; i<functions.length; i++) {
- ret = functions[i].apply(thisObj, args) || ret;
- }
- return ret;
- }
- }
-
-
- function firstDefined() {
- for (var i=0; i<arguments.length; i++) {
- if (arguments[i] !== undefined) {
- return arguments[i];
- }
- }
- }
-
-
- ;;
-
- var ambigDateOfMonthRegex = /^\s*\d{4}-\d\d$/;
- var ambigTimeOrZoneRegex = /^\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+)?)?)?)?)?$/;
-
-
- // Creating
- // -------------------------------------------------------------------------------------------------
-
- // Creates a moment in the local timezone, similar to the vanilla moment(...) constructor,
- // but with extra features:
- // - ambiguous times
- // - enhanced formatting (TODO)
- fc.moment = function() {
- return makeMoment(arguments);
- };
-
- // Sames as fc.moment, but creates a moment in the UTC timezone.
- fc.moment.utc = function() {
- return makeMoment(arguments, true);
- };
-
- // Creates a moment and preserves the timezone offset of the ISO8601 string,
- // allowing for ambigous timezones. If the string is not an ISO8601 string,
- // the moment is processed in UTC-mode (a departure from moment's method).
- fc.moment.parseZone = function() {
- return makeMoment(arguments, true, true);
- };
-
- // when parseZone==true, if can't figure it out, fall back to parseUTC
- function makeMoment(args, parseUTC, parseZone) {
- var input = args[0];
- var isSingleString = args.length == 1 && typeof input === 'string';
- var isAmbigTime = false;
- var isAmbigZone = false;
- var ambigMatch;
- var mom;
-
- if (isSingleString) {
- if (ambigDateOfMonthRegex.test(input)) {
- // accept strings like '2014-05', but convert to the first of the month
- input += '-01';
- isAmbigTime = true;
- isAmbigZone = true;
- }
- else if ((ambigMatch = ambigTimeOrZoneRegex.exec(input))) {
- isAmbigTime = !ambigMatch[5]; // no time part?
- isAmbigZone = true;
- }
- }
- else if ($.isArray(input)) {
- // arrays have no timezone information, so assume ambiguous zone
- isAmbigZone = true;
- }
-
- // instantiate a vanilla moment
- if (parseUTC || parseZone || isAmbigTime) {
- mom = moment.utc.apply(moment, args);
- }
- else {
- mom = moment.apply(null, args);
- }
-
- if (moment.isMoment(input)) {
- transferAmbigs(input, mom);
- }
-
- if (isAmbigTime) {
- mom._ambigTime = true;
- mom._ambigZone = true; // if ambiguous time, also ambiguous timezone offset
- }
-
- if (parseZone) {
- if (isAmbigZone) {
- mom._ambigZone = true;
- }
- else if (isSingleString) {
- mom.zone(input); // if fails, will set it to 0, which it already was
- }
- else if (isNativeDate(input) || input === undefined) {
- // native Date object?
- // specified with no arguments?
- // then consider the moment to be local
- mom.local();
- }
- }
-
- return new FCMoment(mom);
- }
-
- // our subclass of Moment.
- // accepts an object with the internal Moment properties that should be copied over to
- // this object (most likely another Moment object).
- function FCMoment(config) {
- extend(this, config);
- }
-
- // chain the prototype to Moment's
- FCMoment.prototype = createObject(moment.fn);
-
- // we need this because Moment's implementation will not copy of the ambig flags
- FCMoment.prototype.clone = function() {
- return makeMoment([ this ]);
- };
-
-
- // Time-of-day
- // -------------------------------------------------------------------------------------------------
-
- // GETTER
- // Returns a Duration with the hours/minutes/seconds/ms values of the moment.
- // If the moment has an ambiguous time, a duration of 00:00 will be returned.
- //
- // SETTER
- // You can supply a Duration, a Moment, or a Duration-like argument.
- // When setting the time, and the moment has an ambiguous time, it then becomes unambiguous.
- FCMoment.prototype.time = function(time) {
- if (time == null) { // getter
- return moment.duration({
- hours: this.hours(),
- minutes: this.minutes(),
- seconds: this.seconds(),
- milliseconds: this.milliseconds()
- });
- }
- else { // setter
-
- delete this._ambigTime; // mark that the moment now has a time
-
- if (!moment.isDuration(time) && !moment.isMoment(time)) {
- time = moment.duration(time);
- }
-
- return this.hours(time.hours() + time.days() * 24) // day value will cause overflow (so 24 hours becomes 00:00:00 of next day)
- .minutes(time.minutes())
- .seconds(time.seconds())
- .milliseconds(time.milliseconds());
- }
- };
-
- // Converts the moment to UTC, stripping out its time-of-day and timezone offset,
- // but preserving its YMD. A moment with a stripped time will display no time
- // nor timezone offset when .format() is called.
- FCMoment.prototype.stripTime = function() {
- var a = this.toArray(); // year,month,date,hours,minutes,seconds as an array
-
- // set the internal UTC flag
- moment.fn.utc.call(this); // call the original method, because we don't want to affect _ambigZone
-
- this._ambigTime = true;
- this._ambigZone = true; // if ambiguous time, also ambiguous timezone offset
-
- this.year(a[0])
- .month(a[1])
- .date(a[2])
- .hours(0)
- .minutes(0)
- .seconds(0)
- .milliseconds(0);
-
- return this; // for chaining
- };
-
- // Returns if the moment has a non-ambiguous time (boolean)
- FCMoment.prototype.hasTime = function() {
- return !this._ambigTime;
- };
-
-
- // Timezone
- // -------------------------------------------------------------------------------------------------
-
- // Converts the moment to UTC, stripping out its timezone offset, but preserving its
- // YMD and time-of-day. A moment with a stripped timezone offset will display no
- // timezone offset when .format() is called.
- FCMoment.prototype.stripZone = function() {
- var a = this.toArray(); // year,month,date,hours,minutes,seconds as an array
-
- // set the internal UTC flag
- moment.fn.utc.call(this); // call the original method, because we don't want to affect _ambigZone
-
- this._ambigZone = true;
-
- this.year(a[0])
- .month(a[1])
- .date(a[2])
- .hours(a[3])
- .minutes(a[4])
- .seconds(a[5])
- .milliseconds(a[6]);
-
- return this; // for chaining
- };
-
- // Returns of the moment has a non-ambiguous timezone offset (boolean)
- FCMoment.prototype.hasZone = function() {
- return !this._ambigZone;
- };
-
- // this method implicitly marks a zone
- FCMoment.prototype.zone = function(tzo) {
- if (tzo != null) {
- delete this._ambigZone;
- }
- return moment.fn.zone.apply(this, arguments);
- };
-
- // this method implicitly marks a zone.
- // we don't need this, because .local internally calls .zone, but we don't want to depend on that.
- FCMoment.prototype.local = function() {
- delete this._ambigZone;
- return moment.fn.local.apply(this, arguments);
- };
-
- // this method implicitly marks a zone.
- // we don't need this, because .utc internally calls .zone, but we don't want to depend on that.
- FCMoment.prototype.utc = function() {
- delete this._ambigZone;
- return moment.fn.utc.apply(this, arguments);
- };
-
-
- // Formatting
- // -------------------------------------------------------------------------------------------------
-
- FCMoment.prototype.format = function() {
- if (arguments[0]) {
- return formatDate(this, arguments[0]); // our extended formatting
- }
- if (this._ambigTime) {
- return momentFormat(this, 'YYYY-MM-DD');
- }
- if (this._ambigZone) {
- return momentFormat(this, 'YYYY-MM-DD[T]HH:mm:ss');
- }
- return momentFormat(this); // default moment original formatting
- };
-
- FCMoment.prototype.toISOString = function() {
- if (this._ambigTime) {
- return momentFormat(this, 'YYYY-MM-DD');
- }
- if (this._ambigZone) {
- return momentFormat(this, 'YYYY-MM-DD[T]HH:mm:ss');
- }
- return moment.fn.toISOString.apply(this, arguments);
- };
-
-
- // Querying
- // -------------------------------------------------------------------------------------------------
-
- // Is the moment within the specified range? `end` is exclusive.
- FCMoment.prototype.isWithin = function(start, end) {
- var a = commonlyAmbiguate([ this, start, end ]);
- return a[0] >= a[1] && a[0] < a[2];
- };
-
- // Make these query methods work with ambiguous moments
- $.each([
- 'isBefore',
- 'isAfter',
- 'isSame'
- ], function(i, methodName) {
- FCMoment.prototype[methodName] = function(input, units) {
- var a = commonlyAmbiguate([ this, input ]);
- return moment.fn[methodName].call(a[0], a[1], units);
- };
- });
-
-
- // Misc Internals
- // -------------------------------------------------------------------------------------------------
-
- // transfers our internal _ambig properties from one moment to another
- function transferAmbigs(src, dest) {
- if (src._ambigTime) {
- dest._ambigTime = true;
- }
- else if (dest._ambigTime) {
- delete dest._ambigTime;
- }
-
- if (src._ambigZone) {
- dest._ambigZone = true;
- }
- else if (dest._ambigZone) {
- delete dest._ambigZone;
- }
- }
-
- // given an array of moment-like inputs, return a parallel array w/ moments similarly ambiguated.
- // for example, of one moment has ambig time, but not others, all moments will have their time stripped.
- function commonlyAmbiguate(inputs) {
- var outputs = [];
- var anyAmbigTime = false;
- var anyAmbigZone = false;
- var i;
-
- for (i=0; i<inputs.length; i++) {
- outputs.push(fc.moment(inputs[i]));
- anyAmbigTime = anyAmbigTime || outputs[i]._ambigTime;
- anyAmbigZone = anyAmbigZone || outputs[i]._ambigZone;
- }
-
- for (i=0; i<outputs.length; i++) {
- if (anyAmbigTime) {
- outputs[i].stripTime();
- }
- else if (anyAmbigZone) {
- outputs[i].stripZone();
- }
- }
-
- return outputs;
- }
-
- ;;
-
- // Single Date Formatting
- // -------------------------------------------------------------------------------------------------
-
-
- // call this if you want Moment's original format method to be used
- function momentFormat(mom, formatStr) {
- return moment.fn.format.call(mom, formatStr);
- }
-
-
- // Formats `date` with a Moment formatting string, but allow our non-zero areas and
- // additional token.
- function formatDate(date, formatStr) {
- return formatDateWithChunks(date, getFormatStringChunks(formatStr));
- }
-
-
- function formatDateWithChunks(date, chunks) {
- var s = '';
- var i;
-
- for (i=0; i<chunks.length; i++) {
- s += formatDateWithChunk(date, chunks[i]);
- }
-
- return s;
- }
-
-
- // addition formatting tokens we want recognized
- var tokenOverrides = {
- t: function(date) { // "a" or "p"
- return momentFormat(date, 'a').charAt(0);
- },
- T: function(date) { // "A" or "P"
- return momentFormat(date, 'A').charAt(0);
- }
- };
-
-
- function formatDateWithChunk(date, chunk) {
- var token;
- var maybeStr;
-
- if (typeof chunk === 'string') { // a literal string
- return chunk;
- }
- else if ((token = chunk.token)) { // a token, like "YYYY"
- if (tokenOverrides[token]) {
- return tokenOverrides[token](date); // use our custom token
- }
- return momentFormat(date, token);
- }
- else if (chunk.maybe) { // a grouping of other chunks that must be non-zero
- maybeStr = formatDateWithChunks(date, chunk.maybe);
- if (maybeStr.match(/[1-9]/)) {
- return maybeStr;
- }
- }
-
- return '';
- }
-
-
- // Date Range Formatting
- // -------------------------------------------------------------------------------------------------
- // TODO: make it work with timezone offset
-
- // Using a formatting string meant for a single date, generate a range string, like
- // "Sep 2 - 9 2013", that intelligently inserts a separator where the dates differ.
- // If the dates are the same as far as the format string is concerned, just return a single
- // rendering of one date, without any separator.
- function formatRange(date1, date2, formatStr, separator, isRTL) {
-
- // Expand localized format strings, like "LL" -> "MMMM D YYYY"
- formatStr = date1.lang().longDateFormat(formatStr) || formatStr;
- // BTW, this is not important for `formatDate` because it is impossible to put custom tokens
- // or non-zero areas in Moment's localized format strings.
-
- separator = separator || ' - ';
-
- return formatRangeWithChunks(
- date1,
- date2,
- getFormatStringChunks(formatStr),
- separator,
- isRTL
- );
- }
- fc.formatRange = formatRange; // expose
-
-
- function formatRangeWithChunks(date1, date2, chunks, separator, isRTL) {
- var chunkStr; // the rendering of the chunk
- var leftI;
- var leftStr = '';
- var rightI;
- var rightStr = '';
- var middleI;
- var middleStr1 = '';
- var middleStr2 = '';
- var middleStr = '';
-
- // Start at the leftmost side of the formatting string and continue until you hit a token
- // that is not the same between dates.
- for (leftI=0; leftI<chunks.length; leftI++) {
- chunkStr = formatSimilarChunk(date1, date2, chunks[leftI]);
- if (chunkStr === false) {
- break;
- }
- leftStr += chunkStr;
- }
-
- // Similarly, start at the rightmost side of the formatting string and move left
- for (rightI=chunks.length-1; rightI>leftI; rightI--) {
- chunkStr = formatSimilarChunk(date1, date2, chunks[rightI]);
- if (chunkStr === false) {
- break;
- }
- rightStr = chunkStr + rightStr;
- }
-
- // The area in the middle is different for both of the dates.
- // Collect them distinctly so we can jam them together later.
- for (middleI=leftI; middleI<=rightI; middleI++) {
- middleStr1 += formatDateWithChunk(date1, chunks[middleI]);
- middleStr2 += formatDateWithChunk(date2, chunks[middleI]);
- }
-
- if (middleStr1 || middleStr2) {
- if (isRTL) {
- middleStr = middleStr2 + separator + middleStr1;
- }
- else {
- middleStr = middleStr1 + separator + middleStr2;
- }
- }
-
- return leftStr + middleStr + rightStr;
- }
-
-
- var similarUnitMap = {
- Y: 'year',
- M: 'month',
- D: 'day', // day of month
- d: 'day' // day of week
- };
- // don't go any further than day, because we don't want to break apart times like "12:30:00"
- // TODO: week maybe?
-
-
- // Given a formatting chunk, and given that both dates are similar in the regard the
- // formatting chunk is concerned, format date1 against `chunk`. Otherwise, return `false`.
- function formatSimilarChunk(date1, date2, chunk) {
- var token;
- var unit;
-
- if (typeof chunk === 'string') { // a literal string
- return chunk;
- }
- else if ((token = chunk.token)) {
- unit = similarUnitMap[token.charAt(0)];
- // are the dates the same for this unit of measurement?
- if (unit && date1.isSame(date2, unit)) {
- return momentFormat(date1, token); // would be the same if we used `date2`
- // BTW, don't support custom tokens
- }
- }
-
- return false; // the chunk is NOT the same for the two dates
- // BTW, don't support splitting on non-zero areas
- }
-
-
- // Chunking Utils
- // -------------------------------------------------------------------------------------------------
-
-
- var formatStringChunkCache = {};
-
-
- function getFormatStringChunks(formatStr) {
- if (formatStr in formatStringChunkCache) {
- return formatStringChunkCache[formatStr];
- }
- return (formatStringChunkCache[formatStr] = chunkFormatString(formatStr));
- }
-
-
- // Break the formatting string into an array of chunks
- function chunkFormatString(formatStr) {
- var chunks = [];
- var chunker = /\[([^\]]*)\]|\(([^\)]*)\)|((\w)\4*o?T?)|([^\w\[\(]+)/g; // TODO: more descrimination
- var match;
-
- while ((match = chunker.exec(formatStr))) {
- if (match[1]) { // a literal string instead [ ... ]
- chunks.push(match[1]);
- }
- else if (match[2]) { // non-zero formatting inside ( ... )
- chunks.push({ maybe: chunkFormatString(match[2]) });
- }
- else if (match[3]) { // a formatting token
- chunks.push({ token: match[3] });
- }
- else if (match[5]) { // an unenclosed literal string
- chunks.push(match[5]);
- }
- }
-
- return chunks;
- }
-
- ;;
-
- fcViews.month = MonthView;
-
- function MonthView(element, calendar) {
- var t = this;
-
-
- // exports
- t.incrementDate = incrementDate;
- t.render = render;
-
-
- // imports
- BasicView.call(t, element, calendar, 'month');
-
-
- function incrementDate(date, delta) {
- return date.clone().stripTime().add('months', delta).startOf('month');
- }
-
-
- function render(date) {
-
- t.intervalStart = date.clone().stripTime().startOf('month');
- t.intervalEnd = t.intervalStart.clone().add('months', 1);
-
- t.start = t.intervalStart.clone().startOf('week');
- t.start = t.skipHiddenDays(t.start);
-
- t.end = t.intervalEnd.clone().add('days', (7 - t.intervalEnd.weekday()) % 7);
- t.end = t.skipHiddenDays(t.end, -1, true);
-
- var rowCnt = Math.ceil( // need to ceil in case there are hidden days
- t.end.diff(t.start, 'weeks', true) // returnfloat=true
- );
- if (t.opt('weekMode') == 'fixed') {
- t.end.add('weeks', 6 - rowCnt);
- rowCnt = 6;
- }
-
- t.title = calendar.formatDate(t.intervalStart, t.opt('titleFormat'));
-
- t.renderBasic(rowCnt, t.getCellsPerWeek(), true);
- }
-
-
- }
-
- ;;
-
- fcViews.basicWeek = BasicWeekView;
-
- function BasicWeekView(element, calendar) { // TODO: do a WeekView mixin
- var t = this;
-
-
- // exports
- t.incrementDate = incrementDate;
- t.render = render;
-
-
- // imports
- BasicView.call(t, element, calendar, 'basicWeek');
-
-
- function incrementDate(date, delta) {
- return date.clone().stripTime().add('weeks', delta).startOf('week');
- }
-
-
- function render(date) {
-
- t.intervalStart = date.clone().stripTime().startOf('week');
- t.intervalEnd = t.intervalStart.clone().add('weeks', 1);
-
- t.start = t.skipHiddenDays(t.intervalStart);
- t.end = t.skipHiddenDays(t.intervalEnd, -1, true);
-
- t.title = calendar.formatRange(
- t.start,
- t.end.clone().subtract(1), // make inclusive by subtracting 1 ms
- t.opt('titleFormat'),
- ' \u2014 ' // emphasized dash
- );
-
- t.renderBasic(1, t.getCellsPerWeek(), false);
- }
-
-
- }
-
- ;;
-
- fcViews.basicDay = BasicDayView;
-
- function BasicDayView(element, calendar) { // TODO: make a DayView mixin
- var t = this;
-
-
- // exports
- t.incrementDate = incrementDate;
- t.render = render;
-
-
- // imports
- BasicView.call(t, element, calendar, 'basicDay');
-
-
- function incrementDate(date, delta) {
- var out = date.clone().stripTime().add('days', delta);
- out = t.skipHiddenDays(out, delta < 0 ? -1 : 1);
- return out;
- }
-
-
- function render(date) {
-
- t.start = t.intervalStart = date.clone().stripTime();
- t.end = t.intervalEnd = t.start.clone().add('days', 1);
-
- t.title = calendar.formatDate(t.start, t.opt('titleFormat'));
-
- t.renderBasic(1, 1, false);
- }
-
-
- }
-
- ;;
-
- setDefaults({
- weekMode: 'fixed'
- });
-
-
- function BasicView(element, calendar, viewName) {
- var t = this;
-
-
- // exports
- t.renderBasic = renderBasic;
- t.setHeight = setHeight;
- t.setWidth = setWidth;
- t.renderDayOverlay = renderDayOverlay;
- t.defaultSelectionEnd = defaultSelectionEnd;
- t.renderSelection = renderSelection;
- t.clearSelection = clearSelection;
- t.reportDayClick = reportDayClick; // for selection (kinda hacky)
- t.dragStart = dragStart;
- t.dragStop = dragStop;
- t.getHoverListener = function() { return hoverListener; };
- t.colLeft = colLeft;
- t.colRight = colRight;
- t.colContentLeft = colContentLeft;
- t.colContentRight = colContentRight;
- t.getIsCellAllDay = function() { return true; };
- t.allDayRow = allDayRow;
- t.getRowCnt = function() { return rowCnt; };
- t.getColCnt = function() { return colCnt; };
- t.getColWidth = function() { return colWidth; };
- t.getDaySegmentContainer = function() { return daySegmentContainer; };
-
-
- // imports
- View.call(t, element, calendar, viewName);
- OverlayManager.call(t);
- SelectionManager.call(t);
- BasicEventRenderer.call(t);
- var opt = t.opt;
- var trigger = t.trigger;
- var renderOverlay = t.renderOverlay;
- var clearOverlays = t.clearOverlays;
- var daySelectionMousedown = t.daySelectionMousedown;
- var cellToDate = t.cellToDate;
- var dateToCell = t.dateToCell;
- var rangeToSegments = t.rangeToSegments;
- var formatDate = calendar.formatDate;
- var calculateWeekNumber = calendar.calculateWeekNumber;
-
-
- // locals
-
- var table;
- var head;
- var headCells;
- var body;
- var bodyRows;
- var bodyCells;
- var bodyFirstCells;
- var firstRowCellInners;
- var firstRowCellContentInners;
- var daySegmentContainer;
-
- var viewWidth;
- var viewHeight;
- var colWidth;
- var weekNumberWidth;
-
- var rowCnt, colCnt;
- var showNumbers;
- var coordinateGrid;
- var hoverListener;
- var colPositions;
- var colContentPositions;
-
- var tm;
- var colFormat;
- var showWeekNumbers;
-
-
-
- /* Rendering
- ------------------------------------------------------------*/
-
-
- disableTextSelection(element.addClass('fc-grid'));
-
-
- function renderBasic(_rowCnt, _colCnt, _showNumbers) {
- rowCnt = _rowCnt;
- colCnt = _colCnt;
- showNumbers = _showNumbers;
- updateOptions();
-
- if (!body) {
- buildEventContainer();
- }
-
- buildTable();
- }
-
-
- function updateOptions() {
- tm = opt('theme') ? 'ui' : 'fc';
- colFormat = opt('columnFormat');
- showWeekNumbers = opt('weekNumbers');
- }
-
-
- function buildEventContainer() {
- daySegmentContainer =
- $("<div class='fc-event-container' style='position:absolute;z-index:8;top:0;left:0'/>")
- .appendTo(element);
- }
-
-
- function buildTable() {
- var html = buildTableHTML();
-
- if (table) {
- table.remove();
- }
- table = $(html).appendTo(element);
-
- head = table.find('thead');
- headCells = head.find('.fc-day-header');
- body = table.find('tbody');
- bodyRows = body.find('tr');
- bodyCells = body.find('.fc-day');
- bodyFirstCells = bodyRows.find('td:first-child');
-
- firstRowCellInners = bodyRows.eq(0).find('.fc-day > div');
- firstRowCellContentInners = bodyRows.eq(0).find('.fc-day-content > div');
-
- markFirstLast(head.add(head.find('tr'))); // marks first+last tr/th's
- markFirstLast(bodyRows); // marks first+last td's
- bodyRows.eq(0).addClass('fc-first');
- bodyRows.filter(':last').addClass('fc-last');
-
- bodyCells.each(function(i, _cell) {
- var date = cellToDate(
- Math.floor(i / colCnt),
- i % colCnt
- );
- trigger('dayRender', t, date, $(_cell));
- });
-
- dayBind(bodyCells);
- }
-
-
-
- /* HTML Building
- -----------------------------------------------------------*/
-
-
- function buildTableHTML() {
- var html =
- "<table class='fc-border-separate' style='width:100%' cellspacing='0'>" +
- buildHeadHTML() +
- buildBodyHTML() +
- "</table>";
-
- return html;
- }
-
-
- function buildHeadHTML() {
- var headerClass = tm + "-widget-header";
- var html = '';
- var col;
- var date;
-
- html += "<thead><tr>";
-
- if (showWeekNumbers) {
- html +=
- "<th class='fc-week-number " + headerClass + "'>" +
- htmlEscape(opt('weekNumberTitle')) +
- "</th>";
- }
-
- for (col=0; col<colCnt; col++) {
- date = cellToDate(0, col);
- html +=
- "<th class='fc-day-header fc-" + dayIDs[date.day()] + " " + headerClass + "'>" +
- htmlEscape(formatDate(date, colFormat)) +
- "</th>";
- }
-
- html += "</tr></thead>";
-
- return html;
- }
-
-
- function buildBodyHTML() {
- var contentClass = tm + "-widget-content";
- var html = '';
- var row;
- var col;
- var date;
-
- html += "<tbody>";
-
- for (row=0; row<rowCnt; row++) {
-
- html += "<tr class='fc-week'>";
-
- if (showWeekNumbers) {
- date = cellToDate(row, 0);
- html +=
- "<td class='fc-week-number " + contentClass + "'>" +
- "<div>" +
- htmlEscape(calculateWeekNumber(date)) +
- "</div>" +
- "</td>";
- }
-
- for (col=0; col<colCnt; col++) {
- date = cellToDate(row, col);
- html += buildCellHTML(date);
- }
-
- html += "</tr>";
- }
-
- html += "</tbody>";
-
- return html;
- }
-
-
- function buildCellHTML(date) { // date assumed to have stripped time
- var month = t.intervalStart.month();
- var today = calendar.getNow().stripTime();
- var html = '';
- var contentClass = tm + "-widget-content";
- var classNames = [
- 'fc-day',
- 'fc-' + dayIDs[date.day()],
- contentClass
- ];
-
- if (date.month() != month) {
- classNames.push('fc-other-month');
- }
- if (date.isSame(today, 'day')) {
- classNames.push(
- 'fc-today',
- tm + '-state-highlight'
- );
- }
- else if (date < today) {
- classNames.push('fc-past');
- }
- else {
- classNames.push('fc-future');
- }
-
- html +=
- "<td" +
- " class='" + classNames.join(' ') + "'" +
- " data-date='" + date.format() + "'" +
- ">" +
- "<div>";
-
- if (showNumbers) {
- html += "<div class='fc-day-number'>" + date.date() + "</div>";
- }
-
- html +=
- "<div class='fc-day-content'>" +
- "<div style='position:relative'> </div>" +
- "</div>" +
- "</div>" +
- "</td>";
-
- return html;
- }
-
-
-
- /* Dimensions
- -----------------------------------------------------------*/
-
-
- function setHeight(height) {
- viewHeight = height;
-
- var bodyHeight = Math.max(viewHeight - head.height(), 0);
- var rowHeight;
- var rowHeightLast;
- var cell;
-
- if (opt('weekMode') == 'variable') {
- rowHeight = rowHeightLast = Math.floor(bodyHeight / (rowCnt==1 ? 2 : 6));
- }else{
- rowHeight = Math.floor(bodyHeight / rowCnt);
- rowHeightLast = bodyHeight - rowHeight * (rowCnt-1);
- }
-
- bodyFirstCells.each(function(i, _cell) {
- if (i < rowCnt) {
- cell = $(_cell);
- cell.find('> div').css(
- 'min-height',
- (i==rowCnt-1 ? rowHeightLast : rowHeight) - vsides(cell)
- );
- }
- });
-
- }
-
-
- function setWidth(width) {
- viewWidth = width;
- colPositions.clear();
- colContentPositions.clear();
-
- weekNumberWidth = 0;
- if (showWeekNumbers) {
- weekNumberWidth = head.find('th.fc-week-number').outerWidth();
- }
-
- colWidth = Math.floor((viewWidth - weekNumberWidth) / colCnt);
- setOuterWidth(headCells.slice(0, -1), colWidth);
- }
-
-
-
- /* Day clicking and binding
- -----------------------------------------------------------*/
-
-
- function dayBind(days) {
- days.click(dayClick)
- .mousedown(daySelectionMousedown);
- }
-
-
- function dayClick(ev) {
- if (!opt('selectable')) { // if selectable, SelectionManager will worry about dayClick
- var date = calendar.moment($(this).data('date'));
- trigger('dayClick', this, date, ev);
- }
- }
-
-
-
- /* Semi-transparent Overlay Helpers
- ------------------------------------------------------*/
- // TODO: should be consolidated with AgendaView's methods
-
-
- function renderDayOverlay(overlayStart, overlayEnd, refreshCoordinateGrid) { // overlayEnd is exclusive
-
- if (refreshCoordinateGrid) {
- coordinateGrid.build();
- }
-
- var segments = rangeToSegments(overlayStart, overlayEnd);
-
- for (var i=0; i<segments.length; i++) {
- var segment = segments[i];
- dayBind(
- renderCellOverlay(
- segment.row,
- segment.leftCol,
- segment.row,
- segment.rightCol
- )
- );
- }
- }
-
-
- function renderCellOverlay(row0, col0, row1, col1) { // row1,col1 is inclusive
- var rect = coordinateGrid.rect(row0, col0, row1, col1, element);
- return renderOverlay(rect, element);
- }
-
-
-
- /* Selection
- -----------------------------------------------------------------------*/
-
-
- function defaultSelectionEnd(start) {
- return start.clone().stripTime().add('days', 1);
- }
-
-
- function renderSelection(start, end) { // end is exclusive
- renderDayOverlay(start, end, true); // true = rebuild every time
- }
-
-
- function clearSelection() {
- clearOverlays();
- }
-
-
- function reportDayClick(date, ev) {
- var cell = dateToCell(date);
- var _element = bodyCells[cell.row*colCnt + cell.col];
- trigger('dayClick', _element, date, ev);
- }
-
-
-
- /* External Dragging
- -----------------------------------------------------------------------*/
-
-
- function dragStart(_dragElement, ev, ui) {
- hoverListener.start(function(cell) {
- clearOverlays();
- if (cell) {
- var d1 = cellToDate(cell);
- var d2 = d1.clone().add(calendar.defaultAllDayEventDuration);
- renderDayOverlay(d1, d2);
- }
- }, ev);
- }
-
-
- function dragStop(_dragElement, ev, ui) {
- var cell = hoverListener.stop();
- clearOverlays();
- if (cell) {
- trigger(
- 'drop',
- _dragElement,
- cellToDate(cell),
- ev,
- ui
- );
- }
- }
-
-
-
- /* Utilities
- --------------------------------------------------------*/
-
-
- coordinateGrid = new CoordinateGrid(function(rows, cols) {
- var e, n, p;
- headCells.each(function(i, _e) {
- e = $(_e);
- n = e.offset().left;
- if (i) {
- p[1] = n;
- }
- p = [n];
- cols[i] = p;
- });
- p[1] = n + e.outerWidth();
- bodyRows.each(function(i, _e) {
- if (i < rowCnt) {
- e = $(_e);
- n = e.offset().top;
- if (i) {
- p[1] = n;
- }
- p = [n];
- rows[i] = p;
- }
- });
- p[1] = n + e.outerHeight();
- });
-
-
- hoverListener = new HoverListener(coordinateGrid);
-
- colPositions = new HorizontalPositionCache(function(col) {
- return firstRowCellInners.eq(col);
- });
-
- colContentPositions = new HorizontalPositionCache(function(col) {
- return firstRowCellContentInners.eq(col);
- });
-
-
- function colLeft(col) {
- return colPositions.left(col);
- }
-
-
- function colRight(col) {
- return colPositions.right(col);
- }
-
-
- function colContentLeft(col) {
- return colContentPositions.left(col);
- }
-
-
- function colContentRight(col) {
- return colContentPositions.right(col);
- }
-
-
- function allDayRow(i) {
- return bodyRows.eq(i);
- }
-
- }
-
- ;;
-
- function BasicEventRenderer() {
- var t = this;
-
-
- // exports
- t.renderEvents = renderEvents;
- t.clearEvents = clearEvents;
-
-
- // imports
- DayEventRenderer.call(t);
-
-
- function renderEvents(events, modifiedEventId) {
- t.renderDayEvents(events, modifiedEventId);
- }
-
-
- function clearEvents() {
- t.getDaySegmentContainer().empty();
- }
-
-
- // TODO: have this class (and AgendaEventRenderer) be responsible for creating the event container div
-
- }
-
- ;;
-
- fcViews.agendaWeek = AgendaWeekView;
-
- function AgendaWeekView(element, calendar) { // TODO: do a WeekView mixin
- var t = this;
-
-
- // exports
- t.incrementDate = incrementDate;
- t.render = render;
-
-
- // imports
- AgendaView.call(t, element, calendar, 'agendaWeek');
-
-
- function incrementDate(date, delta) {
- return date.clone().stripTime().add('weeks', delta).startOf('week');
- }
-
-
- function render(date) {
-
- t.intervalStart = date.clone().stripTime().startOf('week');
- t.intervalEnd = t.intervalStart.clone().add('weeks', 1);
-
- t.start = t.skipHiddenDays(t.intervalStart);
- t.end = t.skipHiddenDays(t.intervalEnd, -1, true);
-
- t.title = calendar.formatRange(
- t.start,
- t.end.clone().subtract(1), // make inclusive by subtracting 1 ms
- t.opt('titleFormat'),
- ' \u2014 ' // emphasized dash
- );
-
- t.renderAgenda(t.getCellsPerWeek());
- }
-
-
- }
-
- ;;
-
- fcViews.agendaDay = AgendaDayView;
-
- function AgendaDayView(element, calendar) { // TODO: make a DayView mixin
- var t = this;
-
-
- // exports
- t.incrementDate = incrementDate;
- t.render = render;
-
-
- // imports
- AgendaView.call(t, element, calendar, 'agendaDay');
-
-
- function incrementDate(date, delta) {
- var out = date.clone().stripTime().add('days', delta);
- out = t.skipHiddenDays(out, delta < 0 ? -1 : 1);
- return out;
- }
-
-
- function render(date) {
-
- t.start = t.intervalStart = date.clone().stripTime();
- t.end = t.intervalEnd = t.start.clone().add('days', 1);
-
- t.title = calendar.formatDate(t.start, t.opt('titleFormat'));
-
- t.renderAgenda(1);
- }
-
-
- }
-
- ;;
-
- setDefaults({
- allDaySlot: true,
- allDayText: 'all-day',
-
- scrollTime: '06:00:00',
-
- slotDuration: '00:30:00',
-
- axisFormat: generateAgendaAxisFormat,
- timeFormat: {
- agenda: generateAgendaTimeFormat
- },
-
- dragOpacity: {
- agenda: .5
- },
- minTime: '00:00:00',
- maxTime: '24:00:00',
- slotEventOverlap: true
- });
-
-
- function generateAgendaAxisFormat(options, langData) {
- return langData.longDateFormat('LT')
- .replace(':mm', '(:mm)')
- .replace(/(\Wmm)$/, '($1)') // like above, but for foreign langs
- .replace(/\s*a$/i, 'a'); // convert AM/PM/am/pm to lowercase. remove any spaces beforehand
- }
-
-
- function generateAgendaTimeFormat(options, langData) {
- return langData.longDateFormat('LT')
- .replace(/\s*a$/i, ''); // remove trailing AM/PM
- }
-
-
- // TODO: make it work in quirks mode (event corners, all-day height)
- // TODO: test liquid width, especially in IE6
-
-
- function AgendaView(element, calendar, viewName) {
- var t = this;
-
-
- // exports
- t.renderAgenda = renderAgenda;
- t.setWidth = setWidth;
- t.setHeight = setHeight;
- t.afterRender = afterRender;
- t.computeDateTop = computeDateTop;
- t.getIsCellAllDay = getIsCellAllDay;
- t.allDayRow = function() { return allDayRow; }; // badly named
- t.getCoordinateGrid = function() { return coordinateGrid; }; // specifically for AgendaEventRenderer
- t.getHoverListener = function() { return hoverListener; };
- t.colLeft = colLeft;
- t.colRight = colRight;
- t.colContentLeft = colContentLeft;
- t.colContentRight = colContentRight;
- t.getDaySegmentContainer = function() { return daySegmentContainer; };
- t.getSlotSegmentContainer = function() { return slotSegmentContainer; };
- t.getSlotContainer = function() { return slotContainer; };
- t.getRowCnt = function() { return 1; };
- t.getColCnt = function() { return colCnt; };
- t.getColWidth = function() { return colWidth; };
- t.getSnapHeight = function() { return snapHeight; };
- t.getSnapDuration = function() { return snapDuration; };
- t.getSlotHeight = function() { return slotHeight; };
- t.getSlotDuration = function() { return slotDuration; };
- t.getMinTime = function() { return minTime; };
- t.getMaxTime = function() { return maxTime; };
- t.defaultSelectionEnd = defaultSelectionEnd;
- t.renderDayOverlay = renderDayOverlay;
- t.renderSelection = renderSelection;
- t.clearSelection = clearSelection;
- t.reportDayClick = reportDayClick; // selection mousedown hack
- t.dragStart = dragStart;
- t.dragStop = dragStop;
-
-
- // imports
- View.call(t, element, calendar, viewName);
- OverlayManager.call(t);
- SelectionManager.call(t);
- AgendaEventRenderer.call(t);
- var opt = t.opt;
- var trigger = t.trigger;
- var renderOverlay = t.renderOverlay;
- var clearOverlays = t.clearOverlays;
- var reportSelection = t.reportSelection;
- var unselect = t.unselect;
- var daySelectionMousedown = t.daySelectionMousedown;
- var slotSegHtml = t.slotSegHtml;
- var cellToDate = t.cellToDate;
- var dateToCell = t.dateToCell;
- var rangeToSegments = t.rangeToSegments;
- var formatDate = calendar.formatDate;
- var calculateWeekNumber = calendar.calculateWeekNumber;
-
-
- // locals
-
- var dayTable;
- var dayHead;
- var dayHeadCells;
- var dayBody;
- var dayBodyCells;
- var dayBodyCellInners;
- var dayBodyCellContentInners;
- var dayBodyFirstCell;
- var dayBodyFirstCellStretcher;
- var slotLayer;
- var daySegmentContainer;
- var allDayTable;
- var allDayRow;
- var slotScroller;
- var slotContainer;
- var slotSegmentContainer;
- var slotTable;
- var selectionHelper;
-
- var viewWidth;
- var viewHeight;
- var axisWidth;
- var colWidth;
- var gutterWidth;
-
- var slotDuration;
- var slotHeight; // TODO: what if slotHeight changes? (see issue 650)
-
- var snapDuration;
- var snapRatio; // ratio of number of "selection" slots to normal slots. (ex: 1, 2, 4)
- var snapHeight; // holds the pixel hight of a "selection" slot
-
- var colCnt;
- var slotCnt;
- var coordinateGrid;
- var hoverListener;
- var colPositions;
- var colContentPositions;
- var slotTopCache = {};
-
- var tm;
- var rtl;
- var minTime;
- var maxTime;
- var colFormat;
-
-
-
- /* Rendering
- -----------------------------------------------------------------------------*/
-
-
- disableTextSelection(element.addClass('fc-agenda'));
-
-
- function renderAgenda(c) {
- colCnt = c;
- updateOptions();
-
- if (!dayTable) { // first time rendering?
- buildSkeleton(); // builds day table, slot area, events containers
- }
- else {
- buildDayTable(); // rebuilds day table
- }
- }
-
-
- function updateOptions() {
-
- tm = opt('theme') ? 'ui' : 'fc';
- rtl = opt('isRTL');
- colFormat = opt('columnFormat');
-
- minTime = moment.duration(opt('minTime'));
- maxTime = moment.duration(opt('maxTime'));
-
- slotDuration = moment.duration(opt('slotDuration'));
- snapDuration = opt('snapDuration');
- snapDuration = snapDuration ? moment.duration(snapDuration) : slotDuration;
- }
-
-
-
- /* Build DOM
- -----------------------------------------------------------------------*/
-
-
- function buildSkeleton() {
- var s;
- var headerClass = tm + "-widget-header";
- var contentClass = tm + "-widget-content";
- var slotTime;
- var slotDate;
- var minutes;
- var slotNormal = slotDuration.asMinutes() % 15 === 0;
-
- buildDayTable();
-
- slotLayer =
- $("<div style='position:absolute;z-index:2;left:0;width:100%'/>")
- .appendTo(element);
-
- if (opt('allDaySlot')) {
-
- daySegmentContainer =
- $("<div class='fc-event-container' style='position:absolute;z-index:8;top:0;left:0'/>")
- .appendTo(slotLayer);
-
- s =
- "<table style='width:100%' class='fc-agenda-allday' cellspacing='0'>" +
- "<tr>" +
- "<th class='" + headerClass + " fc-agenda-axis'>" +
- (
- opt('allDayHTML') ||
- htmlEscape(opt('allDayText'))
- ) +
- "</th>" +
- "<td>" +
- "<div class='fc-day-content'><div style='position:relative'/></div>" +
- "</td>" +
- "<th class='" + headerClass + " fc-agenda-gutter'> </th>" +
- "</tr>" +
- "</table>";
- allDayTable = $(s).appendTo(slotLayer);
- allDayRow = allDayTable.find('tr');
-
- dayBind(allDayRow.find('td'));
-
- slotLayer.append(
- "<div class='fc-agenda-divider " + headerClass + "'>" +
- "<div class='fc-agenda-divider-inner'/>" +
- "</div>"
- );
-
- }else{
-
- daySegmentContainer = $([]); // in jQuery 1.4, we can just do $()
-
- }
-
- slotScroller =
- $("<div style='position:absolute;width:100%;overflow-x:hidden;overflow-y:auto'/>")
- .appendTo(slotLayer);
-
- slotContainer =
- $("<div style='position:relative;width:100%;overflow:hidden'/>")
- .appendTo(slotScroller);
-
- slotSegmentContainer =
- $("<div class='fc-event-container' style='position:absolute;z-index:8;top:0;left:0'/>")
- .appendTo(slotContainer);
-
- s =
- "<table class='fc-agenda-slots' style='width:100%' cellspacing='0'>" +
- "<tbody>";
-
- slotTime = moment.duration(+minTime); // i wish there was .clone() for durations
- slotCnt = 0;
- while (slotTime < maxTime) {
- slotDate = t.start.clone().time(slotTime); // will be in UTC but that's good. to avoid DST issues
- minutes = slotDate.minutes();
- s +=
- "<tr class='fc-slot" + slotCnt + ' ' + (!minutes ? '' : 'fc-minor') + "'>" +
- "<th class='fc-agenda-axis " + headerClass + "'>" +
- ((!slotNormal || !minutes) ?
- htmlEscape(formatDate(slotDate, opt('axisFormat'))) :
- ' '
- ) +
- "</th>" +
- "<td class='" + contentClass + "'>" +
- "<div style='position:relative'> </div>" +
- "</td>" +
- "</tr>";
- slotTime.add(slotDuration);
- slotCnt++;
- }
-
- s +=
- "</tbody>" +
- "</table>";
-
- slotTable = $(s).appendTo(slotContainer);
-
- slotBind(slotTable.find('td'));
- }
-
-
-
- /* Build Day Table
- -----------------------------------------------------------------------*/
-
-
- function buildDayTable() {
- var html = buildDayTableHTML();
-
- if (dayTable) {
- dayTable.remove();
- }
- dayTable = $(html).appendTo(element);
-
- dayHead = dayTable.find('thead');
- dayHeadCells = dayHead.find('th').slice(1, -1); // exclude gutter
- dayBody = dayTable.find('tbody');
- dayBodyCells = dayBody.find('td').slice(0, -1); // exclude gutter
- dayBodyCellInners = dayBodyCells.find('> div');
- dayBodyCellContentInners = dayBodyCells.find('.fc-day-content > div');
-
- dayBodyFirstCell = dayBodyCells.eq(0);
- dayBodyFirstCellStretcher = dayBodyCellInners.eq(0);
-
- markFirstLast(dayHead.add(dayHead.find('tr')));
- markFirstLast(dayBody.add(dayBody.find('tr')));
-
- // TODO: now that we rebuild the cells every time, we should call dayRender
- }
-
-
- function buildDayTableHTML() {
- var html =
- "<table style='width:100%' class='fc-agenda-days fc-border-separate' cellspacing='0'>" +
- buildDayTableHeadHTML() +
- buildDayTableBodyHTML() +
- "</table>";
-
- return html;
- }
-
-
- function buildDayTableHeadHTML() {
- var headerClass = tm + "-widget-header";
- var date;
- var html = '';
- var weekText;
- var col;
-
- html +=
- "<thead>" +
- "<tr>";
-
- if (opt('weekNumbers')) {
- date = cellToDate(0, 0);
- weekText = calculateWeekNumber(date);
- if (rtl) {
- weekText += opt('weekNumberTitle');
- }
- else {
- weekText = opt('weekNumberTitle') + weekText;
- }
- html +=
- "<th class='fc-agenda-axis fc-week-number " + headerClass + "'>" +
- htmlEscape(weekText) +
- "</th>";
- }
- else {
- html += "<th class='fc-agenda-axis " + headerClass + "'> </th>";
- }
-
- for (col=0; col<colCnt; col++) {
- date = cellToDate(0, col);
- html +=
- "<th class='fc-" + dayIDs[date.day()] + " fc-col" + col + ' ' + headerClass + "'>" +
- htmlEscape(formatDate(date, colFormat)) +
- "</th>";
- }
-
- html +=
- "<th class='fc-agenda-gutter " + headerClass + "'> </th>" +
- "</tr>" +
- "</thead>";
-
- return html;
- }
-
-
- function buildDayTableBodyHTML() {
- var headerClass = tm + "-widget-header"; // TODO: make these when updateOptions() called
- var contentClass = tm + "-widget-content";
- var date;
- var today = calendar.getNow().stripTime();
- var col;
- var cellsHTML;
- var cellHTML;
- var classNames;
- var html = '';
-
- html +=
- "<tbody>" +
- "<tr>" +
- "<th class='fc-agenda-axis " + headerClass + "'> </th>";
-
- cellsHTML = '';
-
- for (col=0; col<colCnt; col++) {
-
- date = cellToDate(0, col);
-
- classNames = [
- 'fc-col' + col,
- 'fc-' + dayIDs[date.day()],
- contentClass
- ];
- if (date.isSame(today, 'day')) {
- classNames.push(
- tm + '-state-highlight',
- 'fc-today'
- );
- }
- else if (date < today) {
- classNames.push('fc-past');
- }
- else {
- classNames.push('fc-future');
- }
-
- cellHTML =
- "<td class='" + classNames.join(' ') + "'>" +
- "<div>" +
- "<div class='fc-day-content'>" +
- "<div style='position:relative'> </div>" +
- "</div>" +
- "</div>" +
- "</td>";
-
- cellsHTML += cellHTML;
- }
-
- html += cellsHTML;
- html +=
- "<td class='fc-agenda-gutter " + contentClass + "'> </td>" +
- "</tr>" +
- "</tbody>";
-
- return html;
- }
-
-
- // TODO: data-date on the cells
-
-
-
- /* Dimensions
- -----------------------------------------------------------------------*/
-
-
- function setHeight(height) {
- if (height === undefined) {
- height = viewHeight;
- }
- viewHeight = height;
- slotTopCache = {};
-
- var headHeight = dayBody.position().top;
- var allDayHeight = slotScroller.position().top; // including divider
- var bodyHeight = Math.min( // total body height, including borders
- height - headHeight, // when scrollbars
- slotTable.height() + allDayHeight + 1 // when no scrollbars. +1 for bottom border
- );
-
- dayBodyFirstCellStretcher
- .height(bodyHeight - vsides(dayBodyFirstCell));
-
- slotLayer.css('top', headHeight);
-
- slotScroller.height(bodyHeight - allDayHeight - 1);
-
- // the stylesheet guarantees that the first row has no border.
- // this allows .height() to work well cross-browser.
- var slotHeight0 = slotTable.find('tr:first').height() + 1; // +1 for bottom border
- var slotHeight1 = slotTable.find('tr:eq(1)').height();
- // HACK: i forget why we do this, but i think a cross-browser issue
- slotHeight = (slotHeight0 + slotHeight1) / 2;
-
- snapRatio = slotDuration / snapDuration;
- snapHeight = slotHeight / snapRatio;
- }
-
-
- function setWidth(width) {
- viewWidth = width;
- colPositions.clear();
- colContentPositions.clear();
-
- var axisFirstCells = dayHead.find('th:first');
- if (allDayTable) {
- axisFirstCells = axisFirstCells.add(allDayTable.find('th:first'));
- }
- axisFirstCells = axisFirstCells.add(slotTable.find('th:first'));
-
- axisWidth = 0;
- setOuterWidth(
- axisFirstCells
- .width('')
- .each(function(i, _cell) {
- axisWidth = Math.max(axisWidth, $(_cell).outerWidth());
- }),
- axisWidth
- );
-
- var gutterCells = dayTable.find('.fc-agenda-gutter');
- if (allDayTable) {
- gutterCells = gutterCells.add(allDayTable.find('th.fc-agenda-gutter'));
- }
-
- var slotTableWidth = slotScroller[0].clientWidth; // needs to be done after axisWidth (for IE7)
-
- gutterWidth = slotScroller.width() - slotTableWidth;
- if (gutterWidth) {
- setOuterWidth(gutterCells, gutterWidth);
- gutterCells
- .show()
- .prev()
- .removeClass('fc-last');
- }else{
- gutterCells
- .hide()
- .prev()
- .addClass('fc-last');
- }
-
- colWidth = Math.floor((slotTableWidth - axisWidth) / colCnt);
- setOuterWidth(dayHeadCells.slice(0, -1), colWidth);
- }
-
-
-
- /* Scrolling
- -----------------------------------------------------------------------*/
-
-
- function resetScroll() {
- var top = computeTimeTop(
- moment.duration(opt('scrollTime'))
- ) + 1; // +1 for the border
-
- function scroll() {
- slotScroller.scrollTop(top);
- }
-
- scroll();
- setTimeout(scroll, 0); // overrides any previous scroll state made by the browser
- }
-
-
- function afterRender() { // after the view has been freshly rendered and sized
- resetScroll();
- }
-
-
-
- /* Slot/Day clicking and binding
- -----------------------------------------------------------------------*/
-
-
- function dayBind(cells) {
- cells.click(slotClick)
- .mousedown(daySelectionMousedown);
- }
-
-
- function slotBind(cells) {
- cells.click(slotClick)
- .mousedown(slotSelectionMousedown);
- }
-
-
- function slotClick(ev) {
- if (!opt('selectable')) { // if selectable, SelectionManager will worry about dayClick
- var col = Math.min(colCnt-1, Math.floor((ev.pageX - dayTable.offset().left - axisWidth) / colWidth));
- var date = cellToDate(0, col);
- var match = this.parentNode.className.match(/fc-slot(\d+)/); // TODO: maybe use data
- if (match) {
- var slotIndex = parseInt(match[1]);
- date.add(minTime + slotIndex * slotDuration);
- date = calendar.rezoneDate(date);
- trigger(
- 'dayClick',
- dayBodyCells[col],
- date,
- ev
- );
- }else{
- trigger(
- 'dayClick',
- dayBodyCells[col],
- date,
- ev
- );
- }
- }
- }
-
-
-
- /* Semi-transparent Overlay Helpers
- -----------------------------------------------------*/
- // TODO: should be consolidated with BasicView's methods
-
-
- function renderDayOverlay(overlayStart, overlayEnd, refreshCoordinateGrid) { // overlayEnd is exclusive
-
- if (refreshCoordinateGrid) {
- coordinateGrid.build();
- }
-
- var segments = rangeToSegments(overlayStart, overlayEnd);
-
- for (var i=0; i<segments.length; i++) {
- var segment = segments[i];
- dayBind(
- renderCellOverlay(
- segment.row,
- segment.leftCol,
- segment.row,
- segment.rightCol
- )
- );
- }
- }
-
-
- function renderCellOverlay(row0, col0, row1, col1) { // only for all-day?
- var rect = coordinateGrid.rect(row0, col0, row1, col1, slotLayer);
- return renderOverlay(rect, slotLayer);
- }
-
-
- function renderSlotOverlay(overlayStart, overlayEnd) {
-
- // normalize, because dayStart/dayEnd have stripped time+zone
- overlayStart = overlayStart.clone().stripZone();
- overlayEnd = overlayEnd.clone().stripZone();
-
- for (var i=0; i<colCnt; i++) { // loop through the day columns
-
- var dayStart = cellToDate(0, i);
- var dayEnd = dayStart.clone().add('days', 1);
-
- var stretchStart = dayStart < overlayStart ? overlayStart : dayStart; // the max of the two
- var stretchEnd = dayEnd < overlayEnd ? dayEnd : overlayEnd; // the min of the two
-
- if (stretchStart < stretchEnd) {
- var rect = coordinateGrid.rect(0, i, 0, i, slotContainer); // only use it for horizontal coords
- var top = computeDateTop(stretchStart, dayStart);
- var bottom = computeDateTop(stretchEnd, dayStart);
-
- rect.top = top;
- rect.height = bottom - top;
- slotBind(
- renderOverlay(rect, slotContainer)
- );
- }
- }
- }
-
-
-
- /* Coordinate Utilities
- -----------------------------------------------------------------------------*/
-
-
- coordinateGrid = new CoordinateGrid(function(rows, cols) {
- var e, n, p;
- dayHeadCells.each(function(i, _e) {
- e = $(_e);
- n = e.offset().left;
- if (i) {
- p[1] = n;
- }
- p = [n];
- cols[i] = p;
- });
- p[1] = n + e.outerWidth();
- if (opt('allDaySlot')) {
- e = allDayRow;
- n = e.offset().top;
- rows[0] = [n, n+e.outerHeight()];
- }
- var slotTableTop = slotContainer.offset().top;
- var slotScrollerTop = slotScroller.offset().top;
- var slotScrollerBottom = slotScrollerTop + slotScroller.outerHeight();
- function constrain(n) {
- return Math.max(slotScrollerTop, Math.min(slotScrollerBottom, n));
- }
- for (var i=0; i<slotCnt*snapRatio; i++) { // adapt slot count to increased/decreased selection slot count
- rows.push([
- constrain(slotTableTop + snapHeight*i),
- constrain(slotTableTop + snapHeight*(i+1))
- ]);
- }
- });
-
-
- hoverListener = new HoverListener(coordinateGrid);
-
- colPositions = new HorizontalPositionCache(function(col) {
- return dayBodyCellInners.eq(col);
- });
-
- colContentPositions = new HorizontalPositionCache(function(col) {
- return dayBodyCellContentInners.eq(col);
- });
-
-
- function colLeft(col) {
- return colPositions.left(col);
- }
-
-
- function colContentLeft(col) {
- return colContentPositions.left(col);
- }
-
-
- function colRight(col) {
- return colPositions.right(col);
- }
-
-
- function colContentRight(col) {
- return colContentPositions.right(col);
- }
-
-
- function getIsCellAllDay(cell) { // TODO: remove because mom.hasTime() from realCellToDate() is better
- return opt('allDaySlot') && !cell.row;
- }
-
-
- function realCellToDate(cell) { // ugh "real" ... but blame it on our abuse of the "cell" system
- var date = cellToDate(0, cell.col);
- var slotIndex = cell.row;
-
- if (opt('allDaySlot')) {
- slotIndex--;
- }
-
- if (slotIndex >= 0) {
- date.time(moment.duration(minTime + slotIndex * slotDuration));
- date = calendar.rezoneDate(date);
- }
-
- return date;
- }
-
-
- function computeDateTop(date, startOfDayDate) {
- return computeTimeTop(
- moment.duration(
- date.clone().stripZone() - startOfDayDate.clone().stripTime()
- )
- );
- }
-
-
- function computeTimeTop(time) { // time is a duration
-
- if (time < minTime) {
- return 0;
- }
- if (time >= maxTime) {
- return slotTable.height();
- }
-
- var slots = (time - minTime) / slotDuration;
- var slotIndex = Math.floor(slots);
- var slotPartial = slots - slotIndex;
- var slotTop = slotTopCache[slotIndex];
-
- // find the position of the corresponding <tr>
- // need to use this tecnhique because not all rows are rendered at same height sometimes.
- if (slotTop === undefined) {
- slotTop = slotTopCache[slotIndex] =
- slotTable.find('tr').eq(slotIndex).find('td div')[0].offsetTop;
- // .eq() is faster than ":eq()" selector
- // [0].offsetTop is faster than .position().top (do we really need this optimization?)
- // a better optimization would be to cache all these divs
- }
-
- var top =
- slotTop - 1 + // because first row doesn't have a top border
- slotPartial * slotHeight; // part-way through the row
-
- top = Math.max(top, 0);
-
- return top;
- }
-
-
-
- /* Selection
- ---------------------------------------------------------------------------------*/
-
-
- function defaultSelectionEnd(start) {
- if (start.hasTime()) {
- return start.clone().add(slotDuration);
- }
- else {
- return start.clone().add('days', 1);
- }
- }
-
-
- function renderSelection(start, end) {
- if (start.hasTime() || end.hasTime()) {
- renderSlotSelection(start, end);
- }
- else if (opt('allDaySlot')) {
- renderDayOverlay(start, end, true); // true for refreshing coordinate grid
- }
- }
-
-
- function renderSlotSelection(startDate, endDate) {
- var helperOption = opt('selectHelper');
- coordinateGrid.build();
- if (helperOption) {
- var col = dateToCell(startDate).col;
- if (col >= 0 && col < colCnt) { // only works when times are on same day
- var rect = coordinateGrid.rect(0, col, 0, col, slotContainer); // only for horizontal coords
- var top = computeDateTop(startDate, startDate);
- var bottom = computeDateTop(endDate, startDate);
- if (bottom > top) { // protect against selections that are entirely before or after visible range
- rect.top = top;
- rect.height = bottom - top;
- rect.left += 2;
- rect.width -= 5;
- if ($.isFunction(helperOption)) {
- var helperRes = helperOption(startDate, endDate);
- if (helperRes) {
- rect.position = 'absolute';
- selectionHelper = $(helperRes)
- .css(rect)
- .appendTo(slotContainer);
- }
- }else{
- rect.isStart = true; // conside rect a "seg" now
- rect.isEnd = true; //
- selectionHelper = $(slotSegHtml(
- {
- title: '',
- start: startDate,
- end: endDate,
- className: ['fc-select-helper'],
- editable: false
- },
- rect
- ));
- selectionHelper.css('opacity', opt('dragOpacity'));
- }
- if (selectionHelper) {
- slotBind(selectionHelper);
- slotContainer.append(selectionHelper);
- setOuterWidth(selectionHelper, rect.width, true); // needs to be after appended
- setOuterHeight(selectionHelper, rect.height, true);
- }
- }
- }
- }else{
- renderSlotOverlay(startDate, endDate);
- }
- }
-
-
- function clearSelection() {
- clearOverlays();
- if (selectionHelper) {
- selectionHelper.remove();
- selectionHelper = null;
- }
- }
-
-
- function slotSelectionMousedown(ev) {
- if (ev.which == 1 && opt('selectable')) { // ev.which==1 means left mouse button
- unselect(ev);
- var dates;
- hoverListener.start(function(cell, origCell) {
- clearSelection();
- if (cell && cell.col == origCell.col && !getIsCellAllDay(cell)) {
- var d1 = realCellToDate(origCell);
- var d2 = realCellToDate(cell);
- dates = [
- d1,
- d1.clone().add(snapDuration), // calculate minutes depending on selection slot minutes
- d2,
- d2.clone().add(snapDuration)
- ].sort(dateCompare);
- renderSlotSelection(dates[0], dates[3]);
- }else{
- dates = null;
- }
- }, ev);
- $(document).one('mouseup', function(ev) {
- hoverListener.stop();
- if (dates) {
- if (+dates[0] == +dates[1]) {
- reportDayClick(dates[0], ev);
- }
- reportSelection(dates[0], dates[3], ev);
- }
- });
- }
- }
-
-
- function reportDayClick(date, ev) {
- trigger('dayClick', dayBodyCells[dateToCell(date).col], date, ev);
- }
-
-
-
- /* External Dragging
- --------------------------------------------------------------------------------*/
-
-
- function dragStart(_dragElement, ev, ui) {
- hoverListener.start(function(cell) {
- clearOverlays();
- if (cell) {
- var d1 = realCellToDate(cell);
- var d2 = d1.clone();
- if (d1.hasTime()) {
- d2.add(calendar.defaultTimedEventDuration);
- renderSlotOverlay(d1, d2);
- }
- else {
- d2.add(calendar.defaultAllDayEventDuration);
- renderDayOverlay(d1, d2);
- }
- }
- }, ev);
- }
-
-
- function dragStop(_dragElement, ev, ui) {
- var cell = hoverListener.stop();
- clearOverlays();
- if (cell) {
- trigger(
- 'drop',
- _dragElement,
- realCellToDate(cell),
- ev,
- ui
- );
- }
- }
-
-
- }
-
- ;;
-
- function AgendaEventRenderer() {
- var t = this;
-
-
- // exports
- t.renderEvents = renderEvents;
- t.clearEvents = clearEvents;
- t.slotSegHtml = slotSegHtml;
-
-
- // imports
- DayEventRenderer.call(t);
- var opt = t.opt;
- var trigger = t.trigger;
- var isEventDraggable = t.isEventDraggable;
- var isEventResizable = t.isEventResizable;
- var eventElementHandlers = t.eventElementHandlers;
- var setHeight = t.setHeight;
- var getDaySegmentContainer = t.getDaySegmentContainer;
- var getSlotSegmentContainer = t.getSlotSegmentContainer;
- var getHoverListener = t.getHoverListener;
- var computeDateTop = t.computeDateTop;
- var getIsCellAllDay = t.getIsCellAllDay;
- var colContentLeft = t.colContentLeft;
- var colContentRight = t.colContentRight;
- var cellToDate = t.cellToDate;
- var getColCnt = t.getColCnt;
- var getColWidth = t.getColWidth;
- var getSnapHeight = t.getSnapHeight;
- var getSnapDuration = t.getSnapDuration;
- var getSlotHeight = t.getSlotHeight;
- var getSlotDuration = t.getSlotDuration;
- var getSlotContainer = t.getSlotContainer;
- var reportEventElement = t.reportEventElement;
- var showEvents = t.showEvents;
- var hideEvents = t.hideEvents;
- var eventDrop = t.eventDrop;
- var eventResize = t.eventResize;
- var renderDayOverlay = t.renderDayOverlay;
- var clearOverlays = t.clearOverlays;
- var renderDayEvents = t.renderDayEvents;
- var getMinTime = t.getMinTime;
- var getMaxTime = t.getMaxTime;
- var calendar = t.calendar;
- var formatDate = calendar.formatDate;
- var formatRange = calendar.formatRange;
- var getEventEnd = calendar.getEventEnd;
-
-
- // overrides
- t.draggableDayEvent = draggableDayEvent;
-
-
-
- /* Rendering
- ----------------------------------------------------------------------------*/
-
-
- function renderEvents(events, modifiedEventId) {
- var i, len=events.length,
- dayEvents=[],
- slotEvents=[];
- for (i=0; i<len; i++) {
- if (events[i].allDay) {
- dayEvents.push(events[i]);
- }else{
- slotEvents.push(events[i]);
- }
- }
-
- if (opt('allDaySlot')) {
- renderDayEvents(dayEvents, modifiedEventId);
- setHeight(); // no params means set to viewHeight
- }
-
- renderSlotSegs(compileSlotSegs(slotEvents), modifiedEventId);
- }
-
-
- function clearEvents() {
- getDaySegmentContainer().empty();
- getSlotSegmentContainer().empty();
- }
-
-
- function compileSlotSegs(events) {
- var colCnt = getColCnt(),
- minTime = getMinTime(),
- maxTime = getMaxTime(),
- cellDate,
- i,
- j, seg,
- colSegs,
- segs = [];
-
- for (i=0; i<colCnt; i++) {
- cellDate = cellToDate(0, i);
-
- colSegs = sliceSegs(
- events,
- cellDate.clone().time(minTime),
- cellDate.clone().time(maxTime)
- );
-
- colSegs = placeSlotSegs(colSegs); // returns a new order
-
- for (j=0; j<colSegs.length; j++) {
- seg = colSegs[j];
- seg.col = i;
- segs.push(seg);
- }
- }
-
- return segs;
- }
-
-
- function sliceSegs(events, rangeStart, rangeEnd) {
-
- // normalize, because all dates will be compared w/o zones
- rangeStart = rangeStart.clone().stripZone();
- rangeEnd = rangeEnd.clone().stripZone();
-
- var segs = [],
- i, len=events.length, event,
- eventStart, eventEnd,
- segStart, segEnd,
- isStart, isEnd;
- for (i=0; i<len; i++) {
-
- event = events[i];
-
- // get dates, make copies, then strip zone to normalize
- eventStart = event.start.clone().stripZone();
- eventEnd = getEventEnd(event).stripZone();
-
- if (eventEnd > rangeStart && eventStart < rangeEnd) {
-
- if (eventStart < rangeStart) {
- segStart = rangeStart.clone();
- isStart = false;
- }
- else {
- segStart = eventStart;
- isStart = true;
- }
-
- if (eventEnd > rangeEnd) {
- segEnd = rangeEnd.clone();
- isEnd = false;
- }
- else {
- segEnd = eventEnd;
- isEnd = true;
- }
-
- segs.push({
- event: event,
- start: segStart,
- end: segEnd,
- isStart: isStart,
- isEnd: isEnd
- });
- }
- }
-
- return segs.sort(compareSlotSegs);
- }
-
-
- // renders events in the 'time slots' at the bottom
- // TODO: when we refactor this, when user returns `false` eventRender, don't have empty space
- // TODO: refactor will include using pixels to detect collisions instead of dates (handy for seg cmp)
-
- function renderSlotSegs(segs, modifiedEventId) {
-
- var i, segCnt=segs.length, seg,
- event,
- top,
- bottom,
- columnLeft,
- columnRight,
- columnWidth,
- width,
- left,
- right,
- html = '',
- eventElements,
- eventElement,
- triggerRes,
- titleElement,
- height,
- slotSegmentContainer = getSlotSegmentContainer(),
- isRTL = opt('isRTL');
-
- // calculate position/dimensions, create html
- for (i=0; i<segCnt; i++) {
- seg = segs[i];
- event = seg.event;
- top = computeDateTop(seg.start, seg.start);
- bottom = computeDateTop(seg.end, seg.start);
- columnLeft = colContentLeft(seg.col);
- columnRight = colContentRight(seg.col);
- columnWidth = columnRight - columnLeft;
-
- // shave off space on right near scrollbars (2.5%)
- // TODO: move this to CSS somehow
- columnRight -= columnWidth * .025;
- columnWidth = columnRight - columnLeft;
-
- width = columnWidth * (seg.forwardCoord - seg.backwardCoord);
-
- if (opt('slotEventOverlap')) {
- // double the width while making sure resize handle is visible
- // (assumed to be 20px wide)
- width = Math.max(
- (width - (20/2)) * 2,
- width // narrow columns will want to make the segment smaller than
- // the natural width. don't allow it
- );
- }
-
- if (isRTL) {
- right = columnRight - seg.backwardCoord * columnWidth;
- left = right - width;
- }
- else {
- left = columnLeft + seg.backwardCoord * columnWidth;
- right = left + width;
- }
-
- // make sure horizontal coordinates are in bounds
- left = Math.max(left, columnLeft);
- right = Math.min(right, columnRight);
- width = right - left;
-
- seg.top = top;
- seg.left = left;
- seg.outerWidth = width;
- seg.outerHeight = bottom - top;
- html += slotSegHtml(event, seg);
- }
-
- slotSegmentContainer[0].innerHTML = html; // faster than html()
- eventElements = slotSegmentContainer.children();
-
- // retrieve elements, run through eventRender callback, bind event handlers
- for (i=0; i<segCnt; i++) {
- seg = segs[i];
- event = seg.event;
- eventElement = $(eventElements[i]); // faster than eq()
- triggerRes = trigger('eventRender', event, event, eventElement);
- if (triggerRes === false) {
- eventElement.remove();
- }else{
- if (triggerRes && triggerRes !== true) {
- eventElement.remove();
- eventElement = $(triggerRes)
- .css({
- position: 'absolute',
- top: seg.top,
- left: seg.left
- })
- .appendTo(slotSegmentContainer);
- }
- seg.element = eventElement;
- if (event._id === modifiedEventId) {
- bindSlotSeg(event, eventElement, seg);
- }else{
- eventElement[0]._fci = i; // for lazySegBind
- }
- reportEventElement(event, eventElement);
- }
- }
-
- lazySegBind(slotSegmentContainer, segs, bindSlotSeg);
-
- // record event sides and title positions
- for (i=0; i<segCnt; i++) {
- seg = segs[i];
- if ((eventElement = seg.element)) {
- seg.vsides = vsides(eventElement, true);
- seg.hsides = hsides(eventElement, true);
- titleElement = eventElement.find('.fc-event-title');
- if (titleElement.length) {
- seg.contentTop = titleElement[0].offsetTop;
- }
- }
- }
-
- // set all positions/dimensions at once
- for (i=0; i<segCnt; i++) {
- seg = segs[i];
- if ((eventElement = seg.element)) {
- eventElement[0].style.width = Math.max(0, seg.outerWidth - seg.hsides) + 'px';
- height = Math.max(0, seg.outerHeight - seg.vsides);
- eventElement[0].style.height = height + 'px';
- event = seg.event;
- if (seg.contentTop !== undefined && height - seg.contentTop < 10) {
- // not enough room for title, put it in the time (TODO: maybe make both display:inline instead)
- eventElement.find('div.fc-event-time')
- .text(
- formatDate(event.start, opt('timeFormat')) + ' - ' + event.title
- );
- eventElement.find('div.fc-event-title')
- .remove();
- }
- trigger('eventAfterRender', event, event, eventElement);
- }
- }
-
- }
-
-
- function slotSegHtml(event, seg) {
- var html = "<";
- var url = event.url;
- var skinCss = getSkinCss(event, opt);
- var classes = ['fc-event', 'fc-event-vert'];
- if (isEventDraggable(event)) {
- classes.push('fc-event-draggable');
- }
- if (seg.isStart) {
- classes.push('fc-event-start');
- }
- if (seg.isEnd) {
- classes.push('fc-event-end');
- }
- classes = classes.concat(event.className);
- if (event.source) {
- classes = classes.concat(event.source.className || []);
- }
- if (url) {
- html += "a href='" + htmlEscape(event.url) + "'";
- }else{
- html += "div";
- }
-
- html +=
- " class='" + classes.join(' ') + "'" +
- " style=" +
- "'" +
- "position:absolute;" +
- "top:" + seg.top + "px;" +
- "left:" + seg.left + "px;" +
- skinCss +
- "'" +
- ">" +
- "<div class='fc-event-inner'>" +
- "<div class='fc-event-time'>";
-
- if (event.end) {
- html += htmlEscape(formatRange(event.start, event.end, opt('timeFormat')));
- }else{
- html += htmlEscape(formatDate(event.start, opt('timeFormat')));
- }
-
- html +=
- "</div>" +
- "<div class='fc-event-title'>" +
- htmlEscape(event.title || '') +
- "</div>" +
- "</div>" +
- "<div class='fc-event-bg'></div>";
-
- if (seg.isEnd && isEventResizable(event)) {
- html +=
- "<div class='ui-resizable-handle ui-resizable-s'>=</div>";
- }
- html +=
- "</" + (url ? "a" : "div") + ">";
- return html;
- }
-
-
- function bindSlotSeg(event, eventElement, seg) {
- var timeElement = eventElement.find('div.fc-event-time');
- if (isEventDraggable(event)) {
- draggableSlotEvent(event, eventElement, timeElement);
- }
- if (seg.isEnd && isEventResizable(event)) {
- resizableSlotEvent(event, eventElement, timeElement);
- }
- eventElementHandlers(event, eventElement);
- }
-
-
-
- /* Dragging
- -----------------------------------------------------------------------------------*/
-
-
- // when event starts out FULL-DAY
- // overrides DayEventRenderer's version because it needs to account for dragging elements
- // to and from the slot area.
-
- function draggableDayEvent(event, eventElement, seg) {
- var isStart = seg.isStart;
- var origWidth;
- var revert;
- var allDay = true;
- var dayDelta;
-
- var hoverListener = getHoverListener();
- var colWidth = getColWidth();
- var minTime = getMinTime();
- var slotDuration = getSlotDuration();
- var slotHeight = getSlotHeight();
- var snapDuration = getSnapDuration();
- var snapHeight = getSnapHeight();
-
- eventElement.draggable({
- opacity: opt('dragOpacity', 'month'), // use whatever the month view was using
- revertDuration: opt('dragRevertDuration'),
- start: function(ev, ui) {
-
- trigger('eventDragStart', eventElement, event, ev, ui);
- hideEvents(event, eventElement);
- origWidth = eventElement.width();
-
- hoverListener.start(function(cell, origCell) {
- clearOverlays();
- if (cell) {
- revert = false;
-
- var origDate = cellToDate(0, origCell.col);
- var date = cellToDate(0, cell.col);
- dayDelta = date.diff(origDate, 'days');
-
- if (!cell.row) { // on full-days
-
- renderDayOverlay(
- event.start.clone().add('days', dayDelta),
- getEventEnd(event).add('days', dayDelta)
- );
-
- resetElement();
- }
- else { // mouse is over bottom slots
-
- if (isStart) {
- if (allDay) {
- // convert event to temporary slot-event
- eventElement.width(colWidth - 10); // don't use entire width
- setOuterHeight(eventElement, calendar.defaultTimedEventDuration / slotDuration * slotHeight); // the default height
- eventElement.draggable('option', 'grid', [ colWidth, 1 ]);
- allDay = false;
- }
- }
- else {
- revert = true;
- }
- }
-
- revert = revert || (allDay && !dayDelta);
- }
- else {
- resetElement();
- revert = true;
- }
-
- eventElement.draggable('option', 'revert', revert);
-
- }, ev, 'drag');
- },
- stop: function(ev, ui) {
- hoverListener.stop();
- clearOverlays();
- trigger('eventDragStop', eventElement, event, ev, ui);
-
- if (revert) { // hasn't moved or is out of bounds (draggable has already reverted)
-
- resetElement();
- eventElement.css('filter', ''); // clear IE opacity side-effects
- showEvents(event, eventElement);
- }
- else { // changed!
-
- var eventStart = event.start.clone().add('days', dayDelta); // already assumed to have a stripped time
- var snapTime;
- var snapIndex;
- if (!allDay) {
- snapIndex = Math.round((eventElement.offset().top - getSlotContainer().offset().top) / snapHeight); // why not use ui.offset.top?
- snapTime = moment.duration(minTime + snapIndex * snapDuration);
- eventStart = calendar.rezoneDate(eventStart.clone().time(snapTime));
- }
-
- eventDrop(
- this, // el
- event,
- eventStart,
- ev,
- ui
- );
- }
- }
- });
- function resetElement() {
- if (!allDay) {
- eventElement
- .width(origWidth)
- .height('')
- .draggable('option', 'grid', null);
- allDay = true;
- }
- }
- }
-
-
- // when event starts out IN TIMESLOTS
-
- function draggableSlotEvent(event, eventElement, timeElement) {
- var coordinateGrid = t.getCoordinateGrid();
- var colCnt = getColCnt();
- var colWidth = getColWidth();
- var snapHeight = getSnapHeight();
- var snapDuration = getSnapDuration();
-
- // states
- var origPosition; // original position of the element, not the mouse
- var origCell;
- var isInBounds, prevIsInBounds;
- var isAllDay, prevIsAllDay;
- var colDelta, prevColDelta;
- var dayDelta; // derived from colDelta
- var snapDelta, prevSnapDelta; // the number of snaps away from the original position
-
- // newly computed
- var eventStart, eventEnd;
-
- eventElement.draggable({
- scroll: false,
- grid: [ colWidth, snapHeight ],
- axis: colCnt==1 ? 'y' : false,
- opacity: opt('dragOpacity'),
- revertDuration: opt('dragRevertDuration'),
- start: function(ev, ui) {
-
- trigger('eventDragStart', eventElement, event, ev, ui);
- hideEvents(event, eventElement);
-
- coordinateGrid.build();
-
- // initialize states
- origPosition = eventElement.position();
- origCell = coordinateGrid.cell(ev.pageX, ev.pageY);
- isInBounds = prevIsInBounds = true;
- isAllDay = prevIsAllDay = getIsCellAllDay(origCell);
- colDelta = prevColDelta = 0;
- dayDelta = 0;
- snapDelta = prevSnapDelta = 0;
-
- eventStart = null;
- eventEnd = null;
- },
- drag: function(ev, ui) {
-
- // NOTE: this `cell` value is only useful for determining in-bounds and all-day.
- // Bad for anything else due to the discrepancy between the mouse position and the
- // element position while snapping. (problem revealed in PR #55)
- //
- // PS- the problem exists for draggableDayEvent() when dragging an all-day event to a slot event.
- // We should overhaul the dragging system and stop relying on jQuery UI.
- var cell = coordinateGrid.cell(ev.pageX, ev.pageY);
-
- // update states
- isInBounds = !!cell;
- if (isInBounds) {
- isAllDay = getIsCellAllDay(cell);
-
- // calculate column delta
- colDelta = Math.round((ui.position.left - origPosition.left) / colWidth);
- if (colDelta != prevColDelta) {
- // calculate the day delta based off of the original clicked column and the column delta
- var origDate = cellToDate(0, origCell.col);
- var col = origCell.col + colDelta;
- col = Math.max(0, col);
- col = Math.min(colCnt-1, col);
- var date = cellToDate(0, col);
- dayDelta = date.diff(origDate, 'days');
- }
-
- // calculate minute delta (only if over slots)
- if (!isAllDay) {
- snapDelta = Math.round((ui.position.top - origPosition.top) / snapHeight);
- }
- }
-
- // any state changes?
- if (
- isInBounds != prevIsInBounds ||
- isAllDay != prevIsAllDay ||
- colDelta != prevColDelta ||
- snapDelta != prevSnapDelta
- ) {
-
- // compute new dates
- if (isAllDay) {
- eventStart = event.start.clone().stripTime().add('days', dayDelta);
- eventEnd = eventStart.clone().add(calendar.defaultAllDayEventDuration);
- }
- else {
- eventStart = event.start.clone().add(snapDelta * snapDuration).add('days', dayDelta);
- eventEnd = getEventEnd(event).add(snapDelta * snapDuration).add('days', dayDelta);
- }
-
- updateUI();
-
- // update previous states for next time
- prevIsInBounds = isInBounds;
- prevIsAllDay = isAllDay;
- prevColDelta = colDelta;
- prevSnapDelta = snapDelta;
- }
-
- // if out-of-bounds, revert when done, and vice versa.
- eventElement.draggable('option', 'revert', !isInBounds);
-
- },
- stop: function(ev, ui) {
-
- clearOverlays();
- trigger('eventDragStop', eventElement, event, ev, ui);
-
- if (isInBounds && (isAllDay || dayDelta || snapDelta)) { // changed!
- eventDrop(
- this, // el
- event,
- eventStart,
- ev,
- ui
- );
- }
- else { // either no change or out-of-bounds (draggable has already reverted)
-
- // reset states for next time, and for updateUI()
- isInBounds = true;
- isAllDay = false;
- colDelta = 0;
- dayDelta = 0;
- snapDelta = 0;
-
- updateUI();
- eventElement.css('filter', ''); // clear IE opacity side-effects
-
- // sometimes fast drags make event revert to wrong position, so reset.
- // also, if we dragged the element out of the area because of snapping,
- // but the *mouse* is still in bounds, we need to reset the position.
- eventElement.css(origPosition);
-
- showEvents(event, eventElement);
- }
- }
- });
-
- function updateUI() {
- clearOverlays();
- if (isInBounds) {
- if (isAllDay) {
- timeElement.hide();
- eventElement.draggable('option', 'grid', null); // disable grid snapping
- renderDayOverlay(eventStart, eventEnd);
- }
- else {
- updateTimeText();
- timeElement.css('display', ''); // show() was causing display=inline
- eventElement.draggable('option', 'grid', [colWidth, snapHeight]); // re-enable grid snapping
- }
- }
- }
-
- function updateTimeText() {
- var text;
- if (eventStart) { // must of had a state change
- if (event.end) {
- text = formatRange(eventStart, eventEnd, opt('timeFormat'));
- }
- else {
- text = formatDate(eventStart, opt('timeFormat'));
- }
- timeElement.text(text);
- }
- }
-
- }
-
-
-
- /* Resizing
- --------------------------------------------------------------------------------------*/
-
-
- function resizableSlotEvent(event, eventElement, timeElement) {
- var snapDelta, prevSnapDelta;
- var snapHeight = getSnapHeight();
- var snapDuration = getSnapDuration();
- var eventEnd;
-
- eventElement.resizable({
- handles: {
- s: '.ui-resizable-handle'
- },
- grid: snapHeight,
- start: function(ev, ui) {
- snapDelta = prevSnapDelta = 0;
- hideEvents(event, eventElement);
- trigger('eventResizeStart', this, event, ev, ui);
- },
- resize: function(ev, ui) {
- // don't rely on ui.size.height, doesn't take grid into account
- snapDelta = Math.round((Math.max(snapHeight, eventElement.height()) - ui.originalSize.height) / snapHeight);
- if (snapDelta != prevSnapDelta) {
- eventEnd = getEventEnd(event).add(snapDuration * snapDelta);
- var text;
- if (snapDelta || event.end) {
- text = formatRange(
- event.start,
- eventEnd,
- opt('timeFormat')
- );
- }
- else {
- text = formatDate(event.start, opt('timeFormat'));
- }
- timeElement.text(text);
- prevSnapDelta = snapDelta;
- }
- },
- stop: function(ev, ui) {
- trigger('eventResizeStop', this, event, ev, ui);
- if (snapDelta) {
- eventResize(
- this,
- event,
- eventEnd,
- ev,
- ui
- );
- }
- else {
- showEvents(event, eventElement);
- // BUG: if event was really short, need to put title back in span
- }
- }
- });
- }
-
-
- }
-
-
-
- /* Agenda Event Segment Utilities
- -----------------------------------------------------------------------------*/
-
-
- // Sets the seg.backwardCoord and seg.forwardCoord on each segment and returns a new
- // list in the order they should be placed into the DOM (an implicit z-index).
- function placeSlotSegs(segs) {
- var levels = buildSlotSegLevels(segs);
- var level0 = levels[0];
- var i;
-
- computeForwardSlotSegs(levels);
-
- if (level0) {
-
- for (i=0; i<level0.length; i++) {
- computeSlotSegPressures(level0[i]);
- }
-
- for (i=0; i<level0.length; i++) {
- computeSlotSegCoords(level0[i], 0, 0);
- }
- }
-
- return flattenSlotSegLevels(levels);
- }
-
-
- // Builds an array of segments "levels". The first level will be the leftmost tier of segments
- // if the calendar is left-to-right, or the rightmost if the calendar is right-to-left.
- function buildSlotSegLevels(segs) {
- var levels = [];
- var i, seg;
- var j;
-
- for (i=0; i<segs.length; i++) {
- seg = segs[i];
-
- // go through all the levels and stop on the first level where there are no collisions
- for (j=0; j<levels.length; j++) {
- if (!computeSlotSegCollisions(seg, levels[j]).length) {
- break;
- }
- }
-
- (levels[j] || (levels[j] = [])).push(seg);
- }
-
- return levels;
- }
-
-
- // For every segment, figure out the other segments that are in subsequent
- // levels that also occupy the same vertical space. Accumulate in seg.forwardSegs
- function computeForwardSlotSegs(levels) {
- var i, level;
- var j, seg;
- var k;
-
- for (i=0; i<levels.length; i++) {
- level = levels[i];
-
- for (j=0; j<level.length; j++) {
- seg = level[j];
-
- seg.forwardSegs = [];
- for (k=i+1; k<levels.length; k++) {
- computeSlotSegCollisions(seg, levels[k], seg.forwardSegs);
- }
- }
- }
- }
-
-
- // Figure out which path forward (via seg.forwardSegs) results in the longest path until
- // the furthest edge is reached. The number of segments in this path will be seg.forwardPressure
- function computeSlotSegPressures(seg) {
- var forwardSegs = seg.forwardSegs;
- var forwardPressure = 0;
- var i, forwardSeg;
-
- if (seg.forwardPressure === undefined) { // not already computed
-
- for (i=0; i<forwardSegs.length; i++) {
- forwardSeg = forwardSegs[i];
-
- // figure out the child's maximum forward path
- computeSlotSegPressures(forwardSeg);
-
- // either use the existing maximum, or use the child's forward pressure
- // plus one (for the forwardSeg itself)
- forwardPressure = Math.max(
- forwardPressure,
- 1 + forwardSeg.forwardPressure
- );
- }
-
- seg.forwardPressure = forwardPressure;
- }
- }
-
-
- // Calculate seg.forwardCoord and seg.backwardCoord for the segment, where both values range
- // from 0 to 1. If the calendar is left-to-right, the seg.backwardCoord maps to "left" and
- // seg.forwardCoord maps to "right" (via percentage). Vice-versa if the calendar is right-to-left.
- //
- // The segment might be part of a "series", which means consecutive segments with the same pressure
- // who's width is unknown until an edge has been hit. `seriesBackwardPressure` is the number of
- // segments behind this one in the current series, and `seriesBackwardCoord` is the starting
- // coordinate of the first segment in the series.
- function computeSlotSegCoords(seg, seriesBackwardPressure, seriesBackwardCoord) {
- var forwardSegs = seg.forwardSegs;
- var i;
-
- if (seg.forwardCoord === undefined) { // not already computed
-
- if (!forwardSegs.length) {
-
- // if there are no forward segments, this segment should butt up against the edge
- seg.forwardCoord = 1;
- }
- else {
-
- // sort highest pressure first
- forwardSegs.sort(compareForwardSlotSegs);
-
- // this segment's forwardCoord will be calculated from the backwardCoord of the
- // highest-pressure forward segment.
- computeSlotSegCoords(forwardSegs[0], seriesBackwardPressure + 1, seriesBackwardCoord);
- seg.forwardCoord = forwardSegs[0].backwardCoord;
- }
-
- // calculate the backwardCoord from the forwardCoord. consider the series
- seg.backwardCoord = seg.forwardCoord -
- (seg.forwardCoord - seriesBackwardCoord) / // available width for series
- (seriesBackwardPressure + 1); // # of segments in the series
-
- // use this segment's coordinates to computed the coordinates of the less-pressurized
- // forward segments
- for (i=0; i<forwardSegs.length; i++) {
- computeSlotSegCoords(forwardSegs[i], 0, seg.forwardCoord);
- }
- }
- }
-
-
- // Outputs a flat array of segments, from lowest to highest level
- function flattenSlotSegLevels(levels) {
- var segs = [];
- var i, level;
- var j;
-
- for (i=0; i<levels.length; i++) {
- level = levels[i];
-
- for (j=0; j<level.length; j++) {
- segs.push(level[j]);
- }
- }
-
- return segs;
- }
-
-
- // Find all the segments in `otherSegs` that vertically collide with `seg`.
- // Append into an optionally-supplied `results` array and return.
- function computeSlotSegCollisions(seg, otherSegs, results) {
- results = results || [];
-
- for (var i=0; i<otherSegs.length; i++) {
- if (isSlotSegCollision(seg, otherSegs[i])) {
- results.push(otherSegs[i]);
- }
- }
-
- return results;
- }
-
-
- // Do these segments occupy the same vertical space?
- function isSlotSegCollision(seg1, seg2) {
- return seg1.end > seg2.start && seg1.start < seg2.end;
- }
-
-
- // A cmp function for determining which forward segment to rely on more when computing coordinates.
- function compareForwardSlotSegs(seg1, seg2) {
- // put higher-pressure first
- return seg2.forwardPressure - seg1.forwardPressure ||
- // put segments that are closer to initial edge first (and favor ones with no coords yet)
- (seg1.backwardCoord || 0) - (seg2.backwardCoord || 0) ||
- // do normal sorting...
- compareSlotSegs(seg1, seg2);
- }
-
-
- // A cmp function for determining which segment should be closer to the initial edge
- // (the left edge on a left-to-right calendar).
- function compareSlotSegs(seg1, seg2) {
- return seg1.start - seg2.start || // earlier start time goes first
- (seg2.end - seg2.start) - (seg1.end - seg1.start) || // tie? longer-duration goes first
- (seg1.event.title || '').localeCompare(seg2.event.title); // tie? alphabetically by title
- }
-
-
- ;;
-
-
- function View(element, calendar, viewName) {
- var t = this;
-
-
- // exports
- t.element = element;
- t.calendar = calendar;
- t.name = viewName;
- t.opt = opt;
- t.trigger = trigger;
- t.isEventDraggable = isEventDraggable;
- t.isEventResizable = isEventResizable;
- t.clearEventData = clearEventData;
- t.reportEventElement = reportEventElement;
- t.triggerEventDestroy = triggerEventDestroy;
- t.eventElementHandlers = eventElementHandlers;
- t.showEvents = showEvents;
- t.hideEvents = hideEvents;
- t.eventDrop = eventDrop;
- t.eventResize = eventResize;
- // t.start, t.end // moments with ambiguous-time
- // t.intervalStart, t.intervalEnd // moments with ambiguous-time
-
-
- // imports
- var reportEventChange = calendar.reportEventChange;
-
-
- // locals
- var eventElementsByID = {}; // eventID mapped to array of jQuery elements
- var eventElementCouples = []; // array of objects, { event, element } // TODO: unify with segment system
- var options = calendar.options;
- var nextDayThreshold = moment.duration(options.nextDayThreshold);
-
-
-
-
- function opt(name, viewNameOverride) {
- var v = options[name];
- if ($.isPlainObject(v) && !isForcedAtomicOption(name)) {
- return smartProperty(v, viewNameOverride || viewName);
- }
- return v;
- }
-
-
- function trigger(name, thisObj) {
- return calendar.trigger.apply(
- calendar,
- [name, thisObj || t].concat(Array.prototype.slice.call(arguments, 2), [t])
- );
- }
-
-
-
- /* Event Editable Boolean Calculations
- ------------------------------------------------------------------------------*/
-
-
- function isEventDraggable(event) {
- var source = event.source || {};
- return firstDefined(
- event.startEditable,
- source.startEditable,
- opt('eventStartEditable'),
- event.editable,
- source.editable,
- opt('editable')
- );
- }
-
-
- function isEventResizable(event) { // but also need to make sure the seg.isEnd == true
- var source = event.source || {};
- return firstDefined(
- event.durationEditable,
- source.durationEditable,
- opt('eventDurationEditable'),
- event.editable,
- source.editable,
- opt('editable')
- );
- }
-
-
-
- /* Event Data
- ------------------------------------------------------------------------------*/
-
-
- function clearEventData() {
- eventElementsByID = {};
- eventElementCouples = [];
- }
-
-
-
- /* Event Elements
- ------------------------------------------------------------------------------*/
-
-
- // report when view creates an element for an event
- function reportEventElement(event, element) {
- eventElementCouples.push({ event: event, element: element });
- if (eventElementsByID[event._id]) {
- eventElementsByID[event._id].push(element);
- }else{
- eventElementsByID[event._id] = [element];
- }
- }
-
-
- function triggerEventDestroy() {
- $.each(eventElementCouples, function(i, couple) {
- t.trigger('eventDestroy', couple.event, couple.event, couple.element);
- });
- }
-
-
- // attaches eventClick, eventMouseover, eventMouseout
- function eventElementHandlers(event, eventElement) {
- eventElement
- .click(function(ev) {
- if (!eventElement.hasClass('ui-draggable-dragging') &&
- !eventElement.hasClass('ui-resizable-resizing')) {
- return trigger('eventClick', this, event, ev);
- }
- })
- .hover(
- function(ev) {
- trigger('eventMouseover', this, event, ev);
- },
- function(ev) {
- trigger('eventMouseout', this, event, ev);
- }
- );
- // TODO: don't fire eventMouseover/eventMouseout *while* dragging is occuring (on subject element)
- // TODO: same for resizing
- }
-
-
- function showEvents(event, exceptElement) {
- eachEventElement(event, exceptElement, 'show');
- }
-
-
- function hideEvents(event, exceptElement) {
- eachEventElement(event, exceptElement, 'hide');
- }
-
-
- function eachEventElement(event, exceptElement, funcName) {
- // NOTE: there may be multiple events per ID (repeating events)
- // and multiple segments per event
- var elements = eventElementsByID[event._id],
- i, len = elements.length;
- for (i=0; i<len; i++) {
- if (!exceptElement || elements[i][0] != exceptElement[0]) {
- elements[i][funcName]();
- }
- }
- }
-
-
-
- /* Event Modification Reporting
- ---------------------------------------------------------------------------------*/
-
-
- function eventDrop(el, event, newStart, ev, ui) {
- var undoMutation = calendar.mutateEvent(event, newStart, null);
-
- trigger(
- 'eventDrop',
- el,
- event,
- function() {
- undoMutation();
- reportEventChange(event._id);
- },
- ev,
- ui
- );
-
- reportEventChange(event._id);
- }
-
-
- function eventResize(el, event, newEnd, ev, ui) {
- var undoMutation = calendar.mutateEvent(event, null, newEnd);
-
- trigger(
- 'eventResize',
- el,
- event,
- function() {
- undoMutation();
- reportEventChange(event._id);
- },
- ev,
- ui
- );
-
- reportEventChange(event._id);
- }
-
-
- // ====================================================================================================
- // Utilities for day "cells"
- // ====================================================================================================
- // The "basic" views are completely made up of day cells.
- // The "agenda" views have day cells at the top "all day" slot.
- // This was the obvious common place to put these utilities, but they should be abstracted out into
- // a more meaningful class (like DayEventRenderer).
- // ====================================================================================================
-
-
- // For determining how a given "cell" translates into a "date":
- //
- // 1. Convert the "cell" (row and column) into a "cell offset" (the # of the cell, cronologically from the first).
- // Keep in mind that column indices are inverted with isRTL. This is taken into account.
- //
- // 2. Convert the "cell offset" to a "day offset" (the # of days since the first visible day in the view).
- //
- // 3. Convert the "day offset" into a "date" (a Moment).
- //
- // The reverse transformation happens when transforming a date into a cell.
-
-
- // exports
- t.isHiddenDay = isHiddenDay;
- t.skipHiddenDays = skipHiddenDays;
- t.getCellsPerWeek = getCellsPerWeek;
- t.dateToCell = dateToCell;
- t.dateToDayOffset = dateToDayOffset;
- t.dayOffsetToCellOffset = dayOffsetToCellOffset;
- t.cellOffsetToCell = cellOffsetToCell;
- t.cellToDate = cellToDate;
- t.cellToCellOffset = cellToCellOffset;
- t.cellOffsetToDayOffset = cellOffsetToDayOffset;
- t.dayOffsetToDate = dayOffsetToDate;
- t.rangeToSegments = rangeToSegments;
-
-
- // internals
- var hiddenDays = opt('hiddenDays') || []; // array of day-of-week indices that are hidden
- var isHiddenDayHash = []; // is the day-of-week hidden? (hash with day-of-week-index -> bool)
- var cellsPerWeek;
- var dayToCellMap = []; // hash from dayIndex -> cellIndex, for one week
- var cellToDayMap = []; // hash from cellIndex -> dayIndex, for one week
- var isRTL = opt('isRTL');
-
-
- // initialize important internal variables
- (function() {
-
- if (opt('weekends') === false) {
- hiddenDays.push(0, 6); // 0=sunday, 6=saturday
- }
-
- // Loop through a hypothetical week and determine which
- // days-of-week are hidden. Record in both hashes (one is the reverse of the other).
- for (var dayIndex=0, cellIndex=0; dayIndex<7; dayIndex++) {
- dayToCellMap[dayIndex] = cellIndex;
- isHiddenDayHash[dayIndex] = $.inArray(dayIndex, hiddenDays) != -1;
- if (!isHiddenDayHash[dayIndex]) {
- cellToDayMap[cellIndex] = dayIndex;
- cellIndex++;
- }
- }
-
- cellsPerWeek = cellIndex;
- if (!cellsPerWeek) {
- throw 'invalid hiddenDays'; // all days were hidden? bad.
- }
-
- })();
-
-
- // Is the current day hidden?
- // `day` is a day-of-week index (0-6), or a Moment
- function isHiddenDay(day) {
- if (moment.isMoment(day)) {
- day = day.day();
- }
- return isHiddenDayHash[day];
- }
-
-
- function getCellsPerWeek() {
- return cellsPerWeek;
- }
-
-
- // Incrementing the current day until it is no longer a hidden day, returning a copy.
- // If the initial value of `date` is not a hidden day, don't do anything.
- // Pass `isExclusive` as `true` if you are dealing with an end date.
- // `inc` defaults to `1` (increment one day forward each time)
- function skipHiddenDays(date, inc, isExclusive) {
- var out = date.clone();
- inc = inc || 1;
- while (
- isHiddenDayHash[(out.day() + (isExclusive ? inc : 0) + 7) % 7]
- ) {
- out.add('days', inc);
- }
- return out;
- }
-
-
- //
- // TRANSFORMATIONS: cell -> cell offset -> day offset -> date
- //
-
- // cell -> date (combines all transformations)
- // Possible arguments:
- // - row, col
- // - { row:#, col: # }
- function cellToDate() {
- var cellOffset = cellToCellOffset.apply(null, arguments);
- var dayOffset = cellOffsetToDayOffset(cellOffset);
- var date = dayOffsetToDate(dayOffset);
- return date;
- }
-
- // cell -> cell offset
- // Possible arguments:
- // - row, col
- // - { row:#, col:# }
- function cellToCellOffset(row, col) {
- var colCnt = t.getColCnt();
-
- // rtl variables. wish we could pre-populate these. but where?
- var dis = isRTL ? -1 : 1;
- var dit = isRTL ? colCnt - 1 : 0;
-
- if (typeof row == 'object') {
- col = row.col;
- row = row.row;
- }
- var cellOffset = row * colCnt + (col * dis + dit); // column, adjusted for RTL (dis & dit)
-
- return cellOffset;
- }
-
- // cell offset -> day offset
- function cellOffsetToDayOffset(cellOffset) {
- var day0 = t.start.day(); // first date's day of week
- cellOffset += dayToCellMap[day0]; // normlize cellOffset to beginning-of-week
- return Math.floor(cellOffset / cellsPerWeek) * 7 + // # of days from full weeks
- cellToDayMap[ // # of days from partial last week
- (cellOffset % cellsPerWeek + cellsPerWeek) % cellsPerWeek // crazy math to handle negative cellOffsets
- ] -
- day0; // adjustment for beginning-of-week normalization
- }
-
- // day offset -> date
- function dayOffsetToDate(dayOffset) {
- return t.start.clone().add('days', dayOffset);
- }
-
-
- //
- // TRANSFORMATIONS: date -> day offset -> cell offset -> cell
- //
-
- // date -> cell (combines all transformations)
- function dateToCell(date) {
- var dayOffset = dateToDayOffset(date);
- var cellOffset = dayOffsetToCellOffset(dayOffset);
- var cell = cellOffsetToCell(cellOffset);
- return cell;
- }
-
- // date -> day offset
- function dateToDayOffset(date) {
- return date.clone().stripTime().diff(t.start, 'days');
- }
-
- // day offset -> cell offset
- function dayOffsetToCellOffset(dayOffset) {
- var day0 = t.start.day(); // first date's day of week
- dayOffset += day0; // normalize dayOffset to beginning-of-week
- return Math.floor(dayOffset / 7) * cellsPerWeek + // # of cells from full weeks
- dayToCellMap[ // # of cells from partial last week
- (dayOffset % 7 + 7) % 7 // crazy math to handle negative dayOffsets
- ] -
- dayToCellMap[day0]; // adjustment for beginning-of-week normalization
- }
-
- // cell offset -> cell (object with row & col keys)
- function cellOffsetToCell(cellOffset) {
- var colCnt = t.getColCnt();
-
- // rtl variables. wish we could pre-populate these. but where?
- var dis = isRTL ? -1 : 1;
- var dit = isRTL ? colCnt - 1 : 0;
-
- var row = Math.floor(cellOffset / colCnt);
- var col = ((cellOffset % colCnt + colCnt) % colCnt) * dis + dit; // column, adjusted for RTL (dis & dit)
- return {
- row: row,
- col: col
- };
- }
-
-
- //
- // Converts a date range into an array of segment objects.
- // "Segments" are horizontal stretches of time, sliced up by row.
- // A segment object has the following properties:
- // - row
- // - cols
- // - isStart
- // - isEnd
- //
- function rangeToSegments(start, end) {
-
- var rowCnt = t.getRowCnt();
- var colCnt = t.getColCnt();
- var segments = []; // array of segments to return
-
- // day offset for given date range
- var rangeDayOffsetStart = dateToDayOffset(start);
- var rangeDayOffsetEnd = dateToDayOffset(end); // an exclusive value
- var endTimeMS = +end.time();
- if (endTimeMS && endTimeMS >= nextDayThreshold) {
- rangeDayOffsetEnd++;
- }
- rangeDayOffsetEnd = Math.max(rangeDayOffsetEnd, rangeDayOffsetStart + 1);
-
- // first and last cell offset for the given date range
- // "last" implies inclusivity
- var rangeCellOffsetFirst = dayOffsetToCellOffset(rangeDayOffsetStart);
- var rangeCellOffsetLast = dayOffsetToCellOffset(rangeDayOffsetEnd) - 1;
-
- // loop through all the rows in the view
- for (var row=0; row<rowCnt; row++) {
-
- // first and last cell offset for the row
- var rowCellOffsetFirst = row * colCnt;
- var rowCellOffsetLast = rowCellOffsetFirst + colCnt - 1;
-
- // get the segment's cell offsets by constraining the range's cell offsets to the bounds of the row
- var segmentCellOffsetFirst = Math.max(rangeCellOffsetFirst, rowCellOffsetFirst);
- var segmentCellOffsetLast = Math.min(rangeCellOffsetLast, rowCellOffsetLast);
-
- // make sure segment's offsets are valid and in view
- if (segmentCellOffsetFirst <= segmentCellOffsetLast) {
-
- // translate to cells
- var segmentCellFirst = cellOffsetToCell(segmentCellOffsetFirst);
- var segmentCellLast = cellOffsetToCell(segmentCellOffsetLast);
-
- // view might be RTL, so order by leftmost column
- var cols = [ segmentCellFirst.col, segmentCellLast.col ].sort();
-
- // Determine if segment's first/last cell is the beginning/end of the date range.
- // We need to compare "day offset" because "cell offsets" are often ambiguous and
- // can translate to multiple days, and an edge case reveals itself when we the
- // range's first cell is hidden (we don't want isStart to be true).
- var isStart = cellOffsetToDayOffset(segmentCellOffsetFirst) == rangeDayOffsetStart;
- var isEnd = cellOffsetToDayOffset(segmentCellOffsetLast) + 1 == rangeDayOffsetEnd; // +1 for comparing exclusively
-
- segments.push({
- row: row,
- leftCol: cols[0],
- rightCol: cols[1],
- isStart: isStart,
- isEnd: isEnd
- });
- }
- }
-
- return segments;
- }
-
-
- }
-
- ;;
-
- function DayEventRenderer() {
- var t = this;
-
-
- // exports
- t.renderDayEvents = renderDayEvents;
- t.draggableDayEvent = draggableDayEvent; // made public so that subclasses can override
- t.resizableDayEvent = resizableDayEvent; // "
-
-
- // imports
- var opt = t.opt;
- var trigger = t.trigger;
- var isEventDraggable = t.isEventDraggable;
- var isEventResizable = t.isEventResizable;
- var reportEventElement = t.reportEventElement;
- var eventElementHandlers = t.eventElementHandlers;
- var showEvents = t.showEvents;
- var hideEvents = t.hideEvents;
- var eventDrop = t.eventDrop;
- var eventResize = t.eventResize;
- var getRowCnt = t.getRowCnt;
- var getColCnt = t.getColCnt;
- var allDayRow = t.allDayRow; // TODO: rename
- var colLeft = t.colLeft;
- var colRight = t.colRight;
- var colContentLeft = t.colContentLeft;
- var colContentRight = t.colContentRight;
- var getDaySegmentContainer = t.getDaySegmentContainer;
- var renderDayOverlay = t.renderDayOverlay;
- var clearOverlays = t.clearOverlays;
- var clearSelection = t.clearSelection;
- var getHoverListener = t.getHoverListener;
- var rangeToSegments = t.rangeToSegments;
- var cellToDate = t.cellToDate;
- var cellToCellOffset = t.cellToCellOffset;
- var cellOffsetToDayOffset = t.cellOffsetToDayOffset;
- var dateToDayOffset = t.dateToDayOffset;
- var dayOffsetToCellOffset = t.dayOffsetToCellOffset;
- var calendar = t.calendar;
- var getEventEnd = calendar.getEventEnd;
- var formatDate = calendar.formatDate;
-
-
- // Render `events` onto the calendar, attach mouse event handlers, and call the `eventAfterRender` callback for each.
- // Mouse event will be lazily applied, except if the event has an ID of `modifiedEventId`.
- // Can only be called when the event container is empty (because it wipes out all innerHTML).
- function renderDayEvents(events, modifiedEventId) {
-
- // do the actual rendering. Receive the intermediate "segment" data structures.
- var segments = _renderDayEvents(
- events,
- false, // don't append event elements
- true // set the heights of the rows
- );
-
- // report the elements to the View, for general drag/resize utilities
- segmentElementEach(segments, function(segment, element) {
- reportEventElement(segment.event, element);
- });
-
- // attach mouse handlers
- attachHandlers(segments, modifiedEventId);
-
- // call `eventAfterRender` callback for each event
- segmentElementEach(segments, function(segment, element) {
- trigger('eventAfterRender', segment.event, segment.event, element);
- });
- }
-
-
- // Render an event on the calendar, but don't report them anywhere, and don't attach mouse handlers.
- // Append this event element to the event container, which might already be populated with events.
- // If an event's segment will have row equal to `adjustRow`, then explicitly set its top coordinate to `adjustTop`.
- // This hack is used to maintain continuity when user is manually resizing an event.
- // Returns an array of DOM elements for the event.
- function renderTempDayEvent(event, adjustRow, adjustTop) {
-
- // actually render the event. `true` for appending element to container.
- // Recieve the intermediate "segment" data structures.
- var segments = _renderDayEvents(
- [ event ],
- true, // append event elements
- false // don't set the heights of the rows
- );
-
- var elements = [];
-
- // Adjust certain elements' top coordinates
- segmentElementEach(segments, function(segment, element) {
- if (segment.row === adjustRow) {
- element.css('top', adjustTop);
- }
- elements.push(element[0]); // accumulate DOM nodes
- });
-
- return elements;
- }
-
-
- // Render events onto the calendar. Only responsible for the VISUAL aspect.
- // Not responsible for attaching handlers or calling callbacks.
- // Set `doAppend` to `true` for rendering elements without clearing the existing container.
- // Set `doRowHeights` to allow setting the height of each row, to compensate for vertical event overflow.
- function _renderDayEvents(events, doAppend, doRowHeights) {
-
- // where the DOM nodes will eventually end up
- var finalContainer = getDaySegmentContainer();
-
- // the container where the initial HTML will be rendered.
- // If `doAppend`==true, uses a temporary container.
- var renderContainer = doAppend ? $("<div/>") : finalContainer;
-
- var segments = buildSegments(events);
- var html;
- var elements;
-
- // calculate the desired `left` and `width` properties on each segment object
- calculateHorizontals(segments);
-
- // build the HTML string. relies on `left` property
- html = buildHTML(segments);
-
- // render the HTML. innerHTML is considerably faster than jQuery's .html()
- renderContainer[0].innerHTML = html;
-
- // retrieve the individual elements
- elements = renderContainer.children();
-
- // if we were appending, and thus using a temporary container,
- // re-attach elements to the real container.
- if (doAppend) {
- finalContainer.append(elements);
- }
-
- // assigns each element to `segment.event`, after filtering them through user callbacks
- resolveElements(segments, elements);
-
- // Calculate the left and right padding+margin for each element.
- // We need this for setting each element's desired outer width, because of the W3C box model.
- // It's important we do this in a separate pass from acually setting the width on the DOM elements
- // because alternating reading/writing dimensions causes reflow for every iteration.
- segmentElementEach(segments, function(segment, element) {
- segment.hsides = hsides(element, true); // include margins = `true`
- });
-
- // Set the width of each element
- segmentElementEach(segments, function(segment, element) {
- element.width(
- Math.max(0, segment.outerWidth - segment.hsides)
- );
- });
-
- // Grab each element's outerHeight (setVerticals uses this).
- // To get an accurate reading, it's important to have each element's width explicitly set already.
- segmentElementEach(segments, function(segment, element) {
- segment.outerHeight = element.outerHeight(true); // include margins = `true`
- });
-
- // Set the top coordinate on each element (requires segment.outerHeight)
- setVerticals(segments, doRowHeights);
-
- return segments;
- }
-
-
- // Generate an array of "segments" for all events.
- function buildSegments(events) {
- var segments = [];
- for (var i=0; i<events.length; i++) {
- var eventSegments = buildSegmentsForEvent(events[i]);
- segments.push.apply(segments, eventSegments); // append an array to an array
- }
- return segments;
- }
-
-
- // Generate an array of segments for a single event.
- // A "segment" is the same data structure that View.rangeToSegments produces,
- // with the addition of the `event` property being set to reference the original event.
- function buildSegmentsForEvent(event) {
- var segments = rangeToSegments(event.start, getEventEnd(event));
- for (var i=0; i<segments.length; i++) {
- segments[i].event = event;
- }
- return segments;
- }
-
-
- // Sets the `left` and `outerWidth` property of each segment.
- // These values are the desired dimensions for the eventual DOM elements.
- function calculateHorizontals(segments) {
- var isRTL = opt('isRTL');
- for (var i=0; i<segments.length; i++) {
- var segment = segments[i];
-
- // Determine functions used for calulating the elements left/right coordinates,
- // depending on whether the view is RTL or not.
- // NOTE:
- // colLeft/colRight returns the coordinate butting up the edge of the cell.
- // colContentLeft/colContentRight is indented a little bit from the edge.
- var leftFunc = (isRTL ? segment.isEnd : segment.isStart) ? colContentLeft : colLeft;
- var rightFunc = (isRTL ? segment.isStart : segment.isEnd) ? colContentRight : colRight;
-
- var left = leftFunc(segment.leftCol);
- var right = rightFunc(segment.rightCol);
- segment.left = left;
- segment.outerWidth = right - left;
- }
- }
-
-
- // Build a concatenated HTML string for an array of segments
- function buildHTML(segments) {
- var html = '';
- for (var i=0; i<segments.length; i++) {
- html += buildHTMLForSegment(segments[i]);
- }
- return html;
- }
-
-
- // Build an HTML string for a single segment.
- // Relies on the following properties:
- // - `segment.event` (from `buildSegmentsForEvent`)
- // - `segment.left` (from `calculateHorizontals`)
- function buildHTMLForSegment(segment) {
- var html = '';
- var isRTL = opt('isRTL');
- var event = segment.event;
- var url = event.url;
-
- // generate the list of CSS classNames
- var classNames = [ 'fc-event', 'fc-event-hori' ];
- if (isEventDraggable(event)) {
- classNames.push('fc-event-draggable');
- }
- if (segment.isStart) {
- classNames.push('fc-event-start');
- }
- if (segment.isEnd) {
- classNames.push('fc-event-end');
- }
- // use the event's configured classNames
- // guaranteed to be an array via `buildEvent`
- classNames = classNames.concat(event.className);
- if (event.source) {
- // use the event's source's classNames, if specified
- classNames = classNames.concat(event.source.className || []);
- }
-
- // generate a semicolon delimited CSS string for any of the "skin" properties
- // of the event object (`backgroundColor`, `borderColor` and such)
- var skinCss = getSkinCss(event, opt);
-
- if (url) {
- html += "<a href='" + htmlEscape(url) + "'";
- }else{
- html += "<div";
- }
- html +=
- " class='" + classNames.join(' ') + "'" +
- " style=" +
- "'" +
- "position:absolute;" +
- "left:" + segment.left + "px;" +
- skinCss +
- "'" +
- ">" +
- "<div class='fc-event-inner'>";
- if (!event.allDay && segment.isStart) {
- html +=
- "<span class='fc-event-time'>" +
- htmlEscape(
- formatDate(event.start, opt('timeFormat'))
- ) +
- "</span>";
- }
- html +=
- "<span class='fc-event-title'>" +
- htmlEscape(event.title || '') +
- "</span>" +
- "</div>";
- if (event.allDay && segment.isEnd && isEventResizable(event)) {
- html +=
- "<div class='ui-resizable-handle ui-resizable-" + (isRTL ? 'w' : 'e') + "'>" +
- " " + // makes hit area a lot better for IE6/7
- "</div>";
- }
- html += "</" + (url ? "a" : "div") + ">";
-
- // TODO:
- // When these elements are initially rendered, they will be briefly visibile on the screen,
- // even though their widths/heights are not set.
- // SOLUTION: initially set them as visibility:hidden ?
-
- return html;
- }
-
-
- // Associate each segment (an object) with an element (a jQuery object),
- // by setting each `segment.element`.
- // Run each element through the `eventRender` filter, which allows developers to
- // modify an existing element, supply a new one, or cancel rendering.
- function resolveElements(segments, elements) {
- for (var i=0; i<segments.length; i++) {
- var segment = segments[i];
- var event = segment.event;
- var element = elements.eq(i);
-
- // call the trigger with the original element
- var triggerRes = trigger('eventRender', event, event, element);
-
- if (triggerRes === false) {
- // if `false`, remove the event from the DOM and don't assign it to `segment.event`
- element.remove();
- }
- else {
- if (triggerRes && triggerRes !== true) {
- // the trigger returned a new element, but not `true` (which means keep the existing element)
-
- // re-assign the important CSS dimension properties that were already assigned in `buildHTMLForSegment`
- triggerRes = $(triggerRes)
- .css({
- position: 'absolute',
- left: segment.left
- });
-
- element.replaceWith(triggerRes);
- element = triggerRes;
- }
-
- segment.element = element;
- }
- }
- }
-
-
-
- /* Top-coordinate Methods
- -------------------------------------------------------------------------------------------------*/
-
-
- // Sets the "top" CSS property for each element.
- // If `doRowHeights` is `true`, also sets each row's first cell to an explicit height,
- // so that if elements vertically overflow, the cell expands vertically to compensate.
- function setVerticals(segments, doRowHeights) {
- var rowContentHeights = calculateVerticals(segments); // also sets segment.top
- var rowContentElements = getRowContentElements(); // returns 1 inner div per row
- var rowContentTops = [];
- var i;
-
- // Set each row's height by setting height of first inner div
- if (doRowHeights) {
- for (i=0; i<rowContentElements.length; i++) {
- rowContentElements[i].height(rowContentHeights[i]);
- }
- }
-
- // Get each row's top, relative to the views's origin.
- // Important to do this after setting each row's height.
- for (i=0; i<rowContentElements.length; i++) {
- rowContentTops.push(
- rowContentElements[i].position().top
- );
- }
-
- // Set each segment element's CSS "top" property.
- // Each segment object has a "top" property, which is relative to the row's top, but...
- segmentElementEach(segments, function(segment, element) {
- element.css(
- 'top',
- rowContentTops[segment.row] + segment.top // ...now, relative to views's origin
- );
- });
- }
-
-
- // Calculate the "top" coordinate for each segment, relative to the "top" of the row.
- // Also, return an array that contains the "content" height for each row
- // (the height displaced by the vertically stacked events in the row).
- // Requires segments to have their `outerHeight` property already set.
- function calculateVerticals(segments) {
- var rowCnt = getRowCnt();
- var colCnt = getColCnt();
- var rowContentHeights = []; // content height for each row
- var segmentRows = buildSegmentRows(segments); // an array of segment arrays, one for each row
- var colI;
-
- for (var rowI=0; rowI<rowCnt; rowI++) {
- var segmentRow = segmentRows[rowI];
-
- // an array of running total heights for each column.
- // initialize with all zeros.
- var colHeights = [];
- for (colI=0; colI<colCnt; colI++) {
- colHeights.push(0);
- }
-
- // loop through every segment
- for (var segmentI=0; segmentI<segmentRow.length; segmentI++) {
- var segment = segmentRow[segmentI];
-
- // find the segment's top coordinate by looking at the max height
- // of all the columns the segment will be in.
- segment.top = arrayMax(
- colHeights.slice(
- segment.leftCol,
- segment.rightCol + 1 // make exclusive for slice
- )
- );
-
- // adjust the columns to account for the segment's height
- for (colI=segment.leftCol; colI<=segment.rightCol; colI++) {
- colHeights[colI] = segment.top + segment.outerHeight;
- }
- }
-
- // the tallest column in the row should be the "content height"
- rowContentHeights.push(arrayMax(colHeights));
- }
-
- return rowContentHeights;
- }
-
-
- // Build an array of segment arrays, each representing the segments that will
- // be in a row of the grid, sorted by which event should be closest to the top.
- function buildSegmentRows(segments) {
- var rowCnt = getRowCnt();
- var segmentRows = [];
- var segmentI;
- var segment;
- var rowI;
-
- // group segments by row
- for (segmentI=0; segmentI<segments.length; segmentI++) {
- segment = segments[segmentI];
- rowI = segment.row;
- if (segment.element) { // was rendered?
- if (segmentRows[rowI]) {
- // already other segments. append to array
- segmentRows[rowI].push(segment);
- }
- else {
- // first segment in row. create new array
- segmentRows[rowI] = [ segment ];
- }
- }
- }
-
- // sort each row
- for (rowI=0; rowI<rowCnt; rowI++) {
- segmentRows[rowI] = sortSegmentRow(
- segmentRows[rowI] || [] // guarantee an array, even if no segments
- );
- }
-
- return segmentRows;
- }
-
-
- // Sort an array of segments according to which segment should appear closest to the top
- function sortSegmentRow(segments) {
- var sortedSegments = [];
-
- // build the subrow array
- var subrows = buildSegmentSubrows(segments);
-
- // flatten it
- for (var i=0; i<subrows.length; i++) {
- sortedSegments.push.apply(sortedSegments, subrows[i]); // append an array to an array
- }
-
- return sortedSegments;
- }
-
-
- // Take an array of segments, which are all assumed to be in the same row,
- // and sort into subrows.
- function buildSegmentSubrows(segments) {
-
- // Give preference to elements with certain criteria, so they have
- // a chance to be closer to the top.
- segments.sort(compareDaySegments);
-
- var subrows = [];
- for (var i=0; i<segments.length; i++) {
- var segment = segments[i];
-
- // loop through subrows, starting with the topmost, until the segment
- // doesn't collide with other segments.
- for (var j=0; j<subrows.length; j++) {
- if (!isDaySegmentCollision(segment, subrows[j])) {
- break;
- }
- }
- // `j` now holds the desired subrow index
- if (subrows[j]) {
- subrows[j].push(segment);
- }
- else {
- subrows[j] = [ segment ];
- }
- }
-
- return subrows;
- }
-
-
- // Return an array of jQuery objects for the placeholder content containers of each row.
- // The content containers don't actually contain anything, but their dimensions should match
- // the events that are overlaid on top.
- function getRowContentElements() {
- var i;
- var rowCnt = getRowCnt();
- var rowDivs = [];
- for (i=0; i<rowCnt; i++) {
- rowDivs[i] = allDayRow(i)
- .find('div.fc-day-content > div');
- }
- return rowDivs;
- }
-
-
-
- /* Mouse Handlers
- ---------------------------------------------------------------------------------------------------*/
- // TODO: better documentation!
-
-
- function attachHandlers(segments, modifiedEventId) {
- var segmentContainer = getDaySegmentContainer();
-
- segmentElementEach(segments, function(segment, element, i) {
- var event = segment.event;
- if (event._id === modifiedEventId) {
- bindDaySeg(event, element, segment);
- }else{
- element[0]._fci = i; // for lazySegBind
- }
- });
-
- lazySegBind(segmentContainer, segments, bindDaySeg);
- }
-
-
- function bindDaySeg(event, eventElement, segment) {
-
- if (isEventDraggable(event)) {
- t.draggableDayEvent(event, eventElement, segment); // use `t` so subclasses can override
- }
-
- if (
- event.allDay &&
- segment.isEnd && // only allow resizing on the final segment for an event
- isEventResizable(event)
- ) {
- t.resizableDayEvent(event, eventElement, segment); // use `t` so subclasses can override
- }
-
- // attach all other handlers.
- // needs to be after, because resizableDayEvent might stopImmediatePropagation on click
- eventElementHandlers(event, eventElement);
- }
-
-
- function draggableDayEvent(event, eventElement) {
- var hoverListener = getHoverListener();
- var dayDelta;
- var eventStart;
- eventElement.draggable({
- delay: 50,
- opacity: opt('dragOpacity'),
- revertDuration: opt('dragRevertDuration'),
- start: function(ev, ui) {
- trigger('eventDragStart', eventElement, event, ev, ui);
- hideEvents(event, eventElement);
- hoverListener.start(function(cell, origCell, rowDelta, colDelta) {
- eventElement.draggable('option', 'revert', !cell || !rowDelta && !colDelta);
- clearOverlays();
- if (cell) {
- var origCellDate = cellToDate(origCell);
- var cellDate = cellToDate(cell);
- dayDelta = cellDate.diff(origCellDate, 'days');
- eventStart = event.start.clone().add('days', dayDelta);
- renderDayOverlay(
- eventStart,
- getEventEnd(event).add('days', dayDelta)
- );
- }
- else {
- dayDelta = 0;
- }
- }, ev, 'drag');
- },
- stop: function(ev, ui) {
- hoverListener.stop();
- clearOverlays();
- trigger('eventDragStop', eventElement, event, ev, ui);
- if (dayDelta) {
- eventDrop(
- this, // el
- event,
- eventStart,
- ev,
- ui
- );
- }
- else {
- eventElement.css('filter', ''); // clear IE opacity side-effects
- showEvents(event, eventElement);
- }
- }
- });
- }
-
-
- function resizableDayEvent(event, element, segment) {
- var isRTL = opt('isRTL');
- var direction = isRTL ? 'w' : 'e';
- var handle = element.find('.ui-resizable-' + direction); // TODO: stop using this class because we aren't using jqui for this
- var isResizing = false;
-
- // TODO: look into using jquery-ui mouse widget for this stuff
- disableTextSelection(element); // prevent native <a> selection for IE
- element
- .mousedown(function(ev) { // prevent native <a> selection for others
- ev.preventDefault();
- })
- .click(function(ev) {
- if (isResizing) {
- ev.preventDefault(); // prevent link from being visited (only method that worked in IE6)
- ev.stopImmediatePropagation(); // prevent fullcalendar eventClick handler from being called
- // (eventElementHandlers needs to be bound after resizableDayEvent)
- }
- });
-
- handle.mousedown(function(ev) {
- if (ev.which != 1) {
- return; // needs to be left mouse button
- }
- isResizing = true;
- var hoverListener = getHoverListener();
- var elementTop = element.css('top');
- var dayDelta;
- var eventEnd;
- var helpers;
- var eventCopy = $.extend({}, event);
- var minCellOffset = dayOffsetToCellOffset(dateToDayOffset(event.start));
- clearSelection();
- $('body')
- .css('cursor', direction + '-resize')
- .one('mouseup', mouseup);
- trigger('eventResizeStart', this, event, ev);
- hoverListener.start(function(cell, origCell) {
- if (cell) {
-
- var origCellOffset = cellToCellOffset(origCell);
- var cellOffset = cellToCellOffset(cell);
-
- // don't let resizing move earlier than start date cell
- cellOffset = Math.max(cellOffset, minCellOffset);
-
- dayDelta =
- cellOffsetToDayOffset(cellOffset) -
- cellOffsetToDayOffset(origCellOffset);
-
- eventEnd = getEventEnd(event).add('days', dayDelta); // assumed to already have a stripped time
-
- if (dayDelta) {
- eventCopy.end = eventEnd;
- var oldHelpers = helpers;
- helpers = renderTempDayEvent(eventCopy, segment.row, elementTop);
- helpers = $(helpers); // turn array into a jQuery object
- helpers.find('*').css('cursor', direction + '-resize');
- if (oldHelpers) {
- oldHelpers.remove();
- }
- hideEvents(event);
- }
- else {
- if (helpers) {
- showEvents(event);
- helpers.remove();
- helpers = null;
- }
- }
-
- clearOverlays();
- renderDayOverlay( // coordinate grid already rebuilt with hoverListener.start()
- event.start,
- eventEnd
- // TODO: instead of calling renderDayOverlay() with dates,
- // call _renderDayOverlay (or whatever) with cell offsets.
- );
- }
- }, ev);
-
- function mouseup(ev) {
- trigger('eventResizeStop', this, event, ev);
- $('body').css('cursor', '');
- hoverListener.stop();
- clearOverlays();
-
- if (dayDelta) {
- eventResize(
- this, // el
- event,
- eventEnd,
- ev
- );
- // event redraw will clear helpers
- }
- // otherwise, the drag handler already restored the old events
-
- setTimeout(function() { // make this happen after the element's click event
- isResizing = false;
- },0);
- }
- });
- }
-
-
- }
-
-
-
- /* Generalized Segment Utilities
- -------------------------------------------------------------------------------------------------*/
-
-
- function isDaySegmentCollision(segment, otherSegments) {
- for (var i=0; i<otherSegments.length; i++) {
- var otherSegment = otherSegments[i];
- if (
- otherSegment.leftCol <= segment.rightCol &&
- otherSegment.rightCol >= segment.leftCol
- ) {
- return true;
- }
- }
- return false;
- }
-
-
- function segmentElementEach(segments, callback) { // TODO: use in AgendaView?
- for (var i=0; i<segments.length; i++) {
- var segment = segments[i];
- var element = segment.element;
- if (element) {
- callback(segment, element, i);
- }
- }
- }
-
-
- // A cmp function for determining which segments should appear higher up
- function compareDaySegments(a, b) {
- return (b.rightCol - b.leftCol) - (a.rightCol - a.leftCol) || // put wider events first
- b.event.allDay - a.event.allDay || // if tie, put all-day events first (booleans cast to 0/1)
- a.event.start - b.event.start || // if a tie, sort by event start date
- (a.event.title || '').localeCompare(b.event.title); // if a tie, sort by event title
- }
-
-
- ;;
-
- //BUG: unselect needs to be triggered when events are dragged+dropped
-
- function SelectionManager() {
- var t = this;
-
-
- // exports
- t.select = select;
- t.unselect = unselect;
- t.reportSelection = reportSelection;
- t.daySelectionMousedown = daySelectionMousedown;
-
-
- // imports
- var calendar = t.calendar;
- var opt = t.opt;
- var trigger = t.trigger;
- var defaultSelectionEnd = t.defaultSelectionEnd;
- var renderSelection = t.renderSelection;
- var clearSelection = t.clearSelection;
-
-
- // locals
- var selected = false;
-
-
-
- // unselectAuto
- if (opt('selectable') && opt('unselectAuto')) {
- // TODO: unbind on destroy
- $(document).mousedown(function(ev) {
- var ignore = opt('unselectCancel');
- if (ignore) {
- if ($(ev.target).parents(ignore).length) { // could be optimized to stop after first match
- return;
- }
- }
- unselect(ev);
- });
- }
-
-
- function select(start, end) {
- unselect();
-
- start = calendar.moment(start);
- if (end) {
- end = calendar.moment(end);
- }
- else {
- end = defaultSelectionEnd(start);
- }
-
- renderSelection(start, end);
- reportSelection(start, end);
- }
-
-
- function unselect(ev) {
- if (selected) {
- selected = false;
- clearSelection();
- trigger('unselect', null, ev);
- }
- }
-
-
- function reportSelection(start, end, ev) {
- selected = true;
- trigger('select', null, start, end, ev);
- }
-
-
- function daySelectionMousedown(ev) { // not really a generic manager method, oh well
- var cellToDate = t.cellToDate;
- var getIsCellAllDay = t.getIsCellAllDay;
- var hoverListener = t.getHoverListener();
- var reportDayClick = t.reportDayClick; // this is hacky and sort of weird
-
- if (ev.which == 1 && opt('selectable')) { // which==1 means left mouse button
- unselect(ev);
- var dates;
- hoverListener.start(function(cell, origCell) { // TODO: maybe put cellToDate/getIsCellAllDay info in cell
- clearSelection();
- if (cell && getIsCellAllDay(cell)) {
- dates = [ cellToDate(origCell), cellToDate(cell) ].sort(dateCompare);
- renderSelection(
- dates[0],
- dates[1].clone().add('days', 1) // make exclusive
- );
- }else{
- dates = null;
- }
- }, ev);
- $(document).one('mouseup', function(ev) {
- hoverListener.stop();
- if (dates) {
- if (+dates[0] == +dates[1]) {
- reportDayClick(dates[0], ev);
- }
- reportSelection(
- dates[0],
- dates[1].clone().add('days', 1), // make exclusive
- ev
- );
- }
- });
- }
- }
-
-
- }
-
- ;;
-
- function OverlayManager() {
- var t = this;
-
-
- // exports
- t.renderOverlay = renderOverlay;
- t.clearOverlays = clearOverlays;
-
-
- // locals
- var usedOverlays = [];
- var unusedOverlays = [];
-
-
- function renderOverlay(rect, parent) {
- var e = unusedOverlays.shift();
- if (!e) {
- e = $("<div class='fc-cell-overlay' style='position:absolute;z-index:3'/>");
- }
- if (e[0].parentNode != parent[0]) {
- e.appendTo(parent);
- }
- usedOverlays.push(e.css(rect).show());
- return e;
- }
-
-
- function clearOverlays() {
- var e;
- while ((e = usedOverlays.shift())) {
- unusedOverlays.push(e.hide().unbind());
- }
- }
-
-
- }
-
- ;;
-
- function CoordinateGrid(buildFunc) {
-
- var t = this;
- var rows;
- var cols;
-
-
- t.build = function() {
- rows = [];
- cols = [];
- buildFunc(rows, cols);
- };
-
-
- t.cell = function(x, y) {
- var rowCnt = rows.length;
- var colCnt = cols.length;
- var i, r=-1, c=-1;
- for (i=0; i<rowCnt; i++) {
- if (y >= rows[i][0] && y < rows[i][1]) {
- r = i;
- break;
- }
- }
- for (i=0; i<colCnt; i++) {
- if (x >= cols[i][0] && x < cols[i][1]) {
- c = i;
- break;
- }
- }
- return (r>=0 && c>=0) ? { row: r, col: c } : null;
- };
-
-
- t.rect = function(row0, col0, row1, col1, originElement) { // row1,col1 is inclusive
- var origin = originElement.offset();
- return {
- top: rows[row0][0] - origin.top,
- left: cols[col0][0] - origin.left,
- width: cols[col1][1] - cols[col0][0],
- height: rows[row1][1] - rows[row0][0]
- };
- };
-
- }
-
- ;;
-
- function HoverListener(coordinateGrid) {
-
-
- var t = this;
- var bindType;
- var change;
- var firstCell;
- var cell;
-
-
- t.start = function(_change, ev, _bindType) {
- change = _change;
- firstCell = cell = null;
- coordinateGrid.build();
- mouse(ev);
- bindType = _bindType || 'mousemove';
- $(document).bind(bindType, mouse);
- };
-
-
- function mouse(ev) {
- _fixUIEvent(ev); // see below
- var newCell = coordinateGrid.cell(ev.pageX, ev.pageY);
- if (
- Boolean(newCell) !== Boolean(cell) ||
- newCell && (newCell.row != cell.row || newCell.col != cell.col)
- ) {
- if (newCell) {
- if (!firstCell) {
- firstCell = newCell;
- }
- change(newCell, firstCell, newCell.row-firstCell.row, newCell.col-firstCell.col);
- }else{
- change(newCell, firstCell);
- }
- cell = newCell;
- }
- }
-
-
- t.stop = function() {
- $(document).unbind(bindType, mouse);
- return cell;
- };
-
-
- }
-
-
-
- // this fix was only necessary for jQuery UI 1.8.16 (and jQuery 1.7 or 1.7.1)
- // upgrading to jQuery UI 1.8.17 (and using either jQuery 1.7 or 1.7.1) fixed the problem
- // but keep this in here for 1.8.16 users
- // and maybe remove it down the line
-
- function _fixUIEvent(event) { // for issue 1168
- if (event.pageX === undefined) {
- event.pageX = event.originalEvent.pageX;
- event.pageY = event.originalEvent.pageY;
- }
- }
- ;;
-
- function HorizontalPositionCache(getElement) {
-
- var t = this,
- elements = {},
- lefts = {},
- rights = {};
-
- function e(i) {
- return (elements[i] = (elements[i] || getElement(i)));
- }
-
- t.left = function(i) {
- return (lefts[i] = (lefts[i] === undefined ? e(i).position().left : lefts[i]));
- };
-
- t.right = function(i) {
- return (rights[i] = (rights[i] === undefined ? t.left(i) + e(i).width() : rights[i]));
- };
-
- t.clear = function() {
- elements = {};
- lefts = {};
- rights = {};
- };
-
- }
-
- ;;
-
- });
|