jquery.fancybox.js 150 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238
  1. // ==================================================
  2. // fancyBox v3.2.10
  3. //
  4. // Licensed GPLv3 for open source use
  5. // or fancyBox Commercial License for commercial use
  6. //
  7. // http://fancyapps.com/fancybox/
  8. // Copyright 2017 fancyApps
  9. //
  10. // ==================================================
  11. ;(function (window, document, $, undefined) {
  12. 'use strict';
  13. // If there's no jQuery, fancyBox can't work
  14. // =========================================
  15. if ( !$ ) {
  16. return;
  17. }
  18. // Check if fancyBox is already initialized
  19. // ========================================
  20. if ( $.fn.fancybox ) {
  21. if ( 'console' in window ) {
  22. console.log( 'fancyBox already initialized' );
  23. }
  24. return;
  25. }
  26. // Private default settings
  27. // ========================
  28. var defaults = {
  29. // Enable infinite gallery navigation
  30. loop : false,
  31. // Space around image, ignored if zoomed-in or viewport width is smaller than 800px
  32. margin : [44, 0],
  33. // Horizontal space between slides
  34. gutter : 50,
  35. // Enable keyboard navigation
  36. keyboard : true,
  37. // Should display navigation arrows at the screen edges
  38. arrows : true,
  39. // Should display infobar (counter and arrows at the top)
  40. infobar : true,
  41. // Should display toolbar (buttons at the top)
  42. toolbar : true,
  43. // What buttons should appear in the top right corner.
  44. // Buttons will be created using templates from `btnTpl` option
  45. // and they will be placed into toolbar (class="fancybox-toolbar"` element)
  46. buttons : [
  47. 'slideShow',
  48. 'fullScreen',
  49. 'thumbs',
  50. 'share',
  51. //'download',
  52. //'zoom',
  53. 'close'
  54. ],
  55. // Detect "idle" time in seconds
  56. idleTime : 3,
  57. // Should display buttons at top right corner of the content
  58. // If 'auto' - they will be created for content having type 'html', 'inline' or 'ajax'
  59. // Use template from `btnTpl.smallBtn` for customization
  60. smallBtn : 'auto',
  61. // Disable right-click and use simple image protection for images
  62. protect : false,
  63. // Shortcut to make content "modal" - disable keyboard navigtion, hide buttons, etc
  64. modal : false,
  65. image : {
  66. // Wait for images to load before displaying
  67. // Requires predefined image dimensions
  68. // If 'auto' - will zoom in thumbnail if 'width' and 'height' attributes are found
  69. preload : "auto"
  70. },
  71. ajax : {
  72. // Object containing settings for ajax request
  73. settings : {
  74. // This helps to indicate that request comes from the modal
  75. // Feel free to change naming
  76. data : {
  77. fancybox : true
  78. }
  79. }
  80. },
  81. iframe : {
  82. // Iframe template
  83. tpl : '<iframe id="fancybox-frame{rnd}" name="fancybox-frame{rnd}" class="fancybox-iframe" frameborder="0" vspace="0" hspace="0" webkitAllowFullScreen mozallowfullscreen allowFullScreen allowtransparency="true" src=""></iframe>',
  84. // Preload iframe before displaying it
  85. // This allows to calculate iframe content width and height
  86. // (note: Due to "Same Origin Policy", you can't get cross domain data).
  87. preload : true,
  88. // Custom CSS styling for iframe wrapping element
  89. // You can use this to set custom iframe dimensions
  90. css : {},
  91. // Iframe tag attributes
  92. attr : {
  93. scrolling : 'auto'
  94. }
  95. },
  96. // Default content type if cannot be detected automatically
  97. defaultType : 'image',
  98. // Open/close animation type
  99. // Possible values:
  100. // false - disable
  101. // "zoom" - zoom images from/to thumbnail
  102. // "fade"
  103. // "zoom-in-out"
  104. //
  105. animationEffect : "zoom",
  106. // Duration in ms for open/close animation
  107. animationDuration : 500,
  108. // Should image change opacity while zooming
  109. // If opacity is "auto", then opacity will be changed if image and thumbnail have different aspect ratios
  110. zoomOpacity : "auto",
  111. // Transition effect between slides
  112. //
  113. // Possible values:
  114. // false - disable
  115. // "fade'
  116. // "slide'
  117. // "circular'
  118. // "tube'
  119. // "zoom-in-out'
  120. // "rotate'
  121. //
  122. transitionEffect : "fade",
  123. // Duration in ms for transition animation
  124. transitionDuration : 366,
  125. // Custom CSS class for slide element
  126. slideClass : '',
  127. // Custom CSS class for layout
  128. baseClass : '',
  129. // Base template for layout
  130. baseTpl :
  131. '<div class="fancybox-container" role="dialog" tabindex="-1">' +
  132. '<div class="fancybox-bg"></div>' +
  133. '<div class="fancybox-inner">' +
  134. '<div class="fancybox-infobar">' +
  135. '<span data-fancybox-index></span>&nbsp;/&nbsp;<span data-fancybox-count></span>' +
  136. '</div>' +
  137. '<div class="fancybox-toolbar">{{buttons}}</div>' +
  138. '<div class="fancybox-navigation">{{arrows}}</div>' +
  139. '<div class="fancybox-stage"></div>' +
  140. '<div class="fancybox-caption-wrap"><div class="fancybox-caption"></div></div>' +
  141. '</div>' +
  142. '</div>',
  143. // Loading indicator template
  144. spinnerTpl : '<div class="fancybox-loading"></div>',
  145. // Error message template
  146. errorTpl : '<div class="fancybox-error"><p>{{ERROR}}<p></div>',
  147. btnTpl : {
  148. download : '<a download data-fancybox-download class="fancybox-button fancybox-button--download" title="{{DOWNLOAD}}">' +
  149. '<svg viewBox="0 0 40 40">' +
  150. '<path d="M20,23 L20,8 L20,23 L13,16 L20,23 L27,16 L20,23 M26,28 L13,28 L27,28 L14,28" />' +
  151. '</svg>' +
  152. '</a>',
  153. zoom : '<button data-fancybox-zoom class="fancybox-button fancybox-button--zoom" title="{{ZOOM}}">' +
  154. '<svg viewBox="0 0 40 40">' +
  155. '<path d="M 18,17 m-8,0 a 8,8 0 1,0 16,0 a 8,8 0 1,0 -16,0 M25,23 L31,29 L25,23" />' +
  156. '</svg>' +
  157. '</button>',
  158. close : '<button data-fancybox-close class="fancybox-button fancybox-button--close" title="{{CLOSE}}">' +
  159. '<svg viewBox="0 0 40 40">' +
  160. '<path d="M10,10 L30,30 M30,10 L10,30" />' +
  161. '</svg>' +
  162. '</button>',
  163. // This small close button will be appended to your html/inline/ajax content by default,
  164. // if "smallBtn" option is not set to false
  165. smallBtn : '<button data-fancybox-close class="fancybox-close-small" title="{{CLOSE}}"></button>',
  166. // Arrows
  167. arrowLeft : '<button data-fancybox-prev class="fancybox-button fancybox-button--arrow_left" title="{{PREV}}">' +
  168. '<svg viewBox="0 0 40 40">' +
  169. '<path d="M10,20 L30,20 L10,20 L18,28 L10,20 L18,12 L10,20"></path>' +
  170. '</svg>' +
  171. '</button>',
  172. arrowRight : '<button data-fancybox-next class="fancybox-button fancybox-button--arrow_right" title="{{NEXT}}">' +
  173. '<svg viewBox="0 0 40 40">' +
  174. '<path d="M30,20 L10,20 L30,20 L22,28 L30,20 L22,12 L30,20"></path>' +
  175. '</svg>' +
  176. '</button>'
  177. },
  178. // Container is injected into this element
  179. parentEl : 'body',
  180. // Focus handling
  181. // ==============
  182. // Try to focus on the first focusable element after opening
  183. autoFocus : false,
  184. // Put focus back to active element after closing
  185. backFocus : true,
  186. // Do not let user to focus on element outside modal content
  187. trapFocus : true,
  188. // Module specific options
  189. // =======================
  190. fullScreen : {
  191. autoStart : false,
  192. },
  193. // Set `touch: false` to disable dragging/swiping
  194. touch : {
  195. vertical : true, // Allow to drag content vertically
  196. momentum : true // Continue movement after releasing mouse/touch when panning
  197. },
  198. // Hash value when initializing manually,
  199. // set `false` to disable hash change
  200. hash : null,
  201. // Customize or add new media types
  202. // Example:
  203. /*
  204. media : {
  205. youtube : {
  206. params : {
  207. autoplay : 0
  208. }
  209. }
  210. }
  211. */
  212. media : {},
  213. slideShow : {
  214. autoStart : false,
  215. speed : 4000
  216. },
  217. thumbs : {
  218. autoStart : false, // Display thumbnails on opening
  219. hideOnClose : true, // Hide thumbnail grid when closing animation starts
  220. parentEl : '.fancybox-container', // Container is injected into this element
  221. axis : 'y' // Vertical (y) or horizontal (x) scrolling
  222. },
  223. // Use mousewheel to navigate gallery
  224. // If 'auto' - enabled for images only
  225. wheel : 'auto',
  226. // Callbacks
  227. //==========
  228. // See Documentation/API/Events for more information
  229. // Example:
  230. /*
  231. afterShow: function( instance, current ) {
  232. console.info( 'Clicked element:' );
  233. console.info( current.opts.$orig );
  234. }
  235. */
  236. onInit : $.noop, // When instance has been initialized
  237. beforeLoad : $.noop, // Before the content of a slide is being loaded
  238. afterLoad : $.noop, // When the content of a slide is done loading
  239. beforeShow : $.noop, // Before open animation starts
  240. afterShow : $.noop, // When content is done loading and animating
  241. beforeClose : $.noop, // Before the instance attempts to close. Return false to cancel the close.
  242. afterClose : $.noop, // After instance has been closed
  243. onActivate : $.noop, // When instance is brought to front
  244. onDeactivate : $.noop, // When other instance has been activated
  245. // Interaction
  246. // ===========
  247. // Use options below to customize taken action when user clicks or double clicks on the fancyBox area,
  248. // each option can be string or method that returns value.
  249. //
  250. // Possible values:
  251. // "close" - close instance
  252. // "next" - move to next gallery item
  253. // "nextOrClose" - move to next gallery item or close if gallery has only one item
  254. // "toggleControls" - show/hide controls
  255. // "zoom" - zoom image (if loaded)
  256. // false - do nothing
  257. // Clicked on the content
  258. clickContent : function( current, event ) {
  259. return current.type === 'image' ? 'zoom' : false;
  260. },
  261. // Clicked on the slide
  262. clickSlide : 'close',
  263. // Clicked on the background (backdrop) element
  264. clickOutside : 'close',
  265. // Same as previous two, but for double click
  266. dblclickContent : false,
  267. dblclickSlide : false,
  268. dblclickOutside : false,
  269. // Custom options when mobile device is detected
  270. // =============================================
  271. mobile : {
  272. idleTime : false,
  273. margin : 0,
  274. clickContent : function( current, event ) {
  275. return current.type === 'image' ? 'toggleControls' : false;
  276. },
  277. clickSlide : function( current, event ) {
  278. return current.type === 'image' ? 'toggleControls' : 'close';
  279. },
  280. dblclickContent : function( current, event ) {
  281. return current.type === 'image' ? 'zoom' : false;
  282. },
  283. dblclickSlide : function( current, event ) {
  284. return current.type === 'image' ? 'zoom' : false;
  285. }
  286. },
  287. // Internationalization
  288. // ============
  289. lang : 'en',
  290. i18n : {
  291. 'en' : {
  292. CLOSE : 'Close',
  293. NEXT : 'Next',
  294. PREV : 'Previous',
  295. ERROR : 'The requested content cannot be loaded. <br/> Please try again later.',
  296. PLAY_START : 'Start slideshow',
  297. PLAY_STOP : 'Pause slideshow',
  298. FULL_SCREEN : 'Full screen',
  299. THUMBS : 'Thumbnails',
  300. DOWNLOAD : 'Download',
  301. SHARE : 'Share',
  302. ZOOM : 'Zoom'
  303. },
  304. 'de' : {
  305. CLOSE : 'Schliessen',
  306. NEXT : 'Weiter',
  307. PREV : 'Zurück',
  308. ERROR : 'Die angeforderten Daten konnten nicht geladen werden. <br/> Bitte versuchen Sie es später nochmal.',
  309. PLAY_START : 'Diaschau starten',
  310. PLAY_STOP : 'Diaschau beenden',
  311. FULL_SCREEN : 'Vollbild',
  312. THUMBS : 'Vorschaubilder',
  313. DOWNLOAD : 'Herunterladen',
  314. SHARE : 'Teilen',
  315. ZOOM : 'Maßstab'
  316. }
  317. }
  318. };
  319. // Few useful variables and methods
  320. // ================================
  321. var $W = $(window);
  322. var $D = $(document);
  323. var called = 0;
  324. // Check if an object is a jQuery object and not a native JavaScript object
  325. // ========================================================================
  326. var isQuery = function ( obj ) {
  327. return obj && obj.hasOwnProperty && obj instanceof $;
  328. };
  329. // Handle multiple browsers for "requestAnimationFrame" and "cancelAnimationFrame"
  330. // ===============================================================================
  331. var requestAFrame = (function () {
  332. return window.requestAnimationFrame ||
  333. window.webkitRequestAnimationFrame ||
  334. window.mozRequestAnimationFrame ||
  335. window.oRequestAnimationFrame ||
  336. // if all else fails, use setTimeout
  337. function (callback) {
  338. return window.setTimeout(callback, 1000 / 60);
  339. };
  340. })();
  341. // Detect the supported transition-end event property name
  342. // =======================================================
  343. var transitionEnd = (function () {
  344. var t, el = document.createElement("fakeelement");
  345. var transitions = {
  346. "transition" : "transitionend",
  347. "OTransition" : "oTransitionEnd",
  348. "MozTransition" : "transitionend",
  349. "WebkitTransition": "webkitTransitionEnd"
  350. };
  351. for (t in transitions) {
  352. if (el.style[t] !== undefined){
  353. return transitions[t];
  354. }
  355. }
  356. return 'transitionend';
  357. })();
  358. // Force redraw on an element.
  359. // This helps in cases where the browser doesn't redraw an updated element properly.
  360. // =================================================================================
  361. var forceRedraw = function( $el ) {
  362. return ( $el && $el.length && $el[0].offsetHeight );
  363. };
  364. // Class definition
  365. // ================
  366. var FancyBox = function( content, opts, index ) {
  367. var self = this;
  368. self.opts = $.extend( true, { index : index }, $.fancybox.defaults, opts || {} );
  369. if ( $.fancybox.isMobile ) {
  370. self.opts = $.extend( true, {}, self.opts, self.opts.mobile );
  371. }
  372. // Exclude buttons option from deep merging
  373. if ( opts && $.isArray( opts.buttons ) ) {
  374. self.opts.buttons = opts.buttons;
  375. }
  376. self.id = self.opts.id || ++called;
  377. self.group = [];
  378. self.currIndex = parseInt( self.opts.index, 10 ) || 0;
  379. self.prevIndex = null;
  380. self.prevPos = null;
  381. self.currPos = 0;
  382. self.firstRun = null;
  383. // Create group elements from original item collection
  384. self.createGroup( content );
  385. if ( !self.group.length ) {
  386. return;
  387. }
  388. // Save last active element and current scroll position
  389. self.$lastFocus = $(document.activeElement).blur();
  390. // Collection of gallery objects
  391. self.slides = {};
  392. self.init();
  393. };
  394. $.extend(FancyBox.prototype, {
  395. // Create DOM structure
  396. // ====================
  397. init : function() {
  398. var self = this,
  399. firstItem = self.group[ self.currIndex ],
  400. firstItemOpts = firstItem.opts,
  401. scrollbarWidth = $.fancybox.scrollbarWidth,
  402. $scrollDiv,
  403. $container,
  404. buttonStr;
  405. self.scrollTop = $D.scrollTop();
  406. self.scrollLeft = $D.scrollLeft();
  407. // Hide scrollbars
  408. // ===============
  409. if ( !$.fancybox.getInstance() ) {
  410. $( 'body' ).addClass( 'fancybox-active' );
  411. // iOS hack
  412. if ( /iPad|iPhone|iPod/.test(navigator.userAgent) && !window.MSStream ) {
  413. // iOS has problems for input elements inside fixed containers,
  414. // the workaround is to apply `position: fixed` to `<body>` element,
  415. // unfortunately, this makes it lose the scrollbars and forces address bar to appear.
  416. if ( firstItem.type !== 'image' ) {
  417. $( 'body' ).css( 'top', $( 'body' ).scrollTop() * -1 ).addClass( 'fancybox-iosfix' );
  418. }
  419. } else if ( !$.fancybox.isMobile && document.body.scrollHeight > window.innerHeight ) {
  420. if ( scrollbarWidth === undefined ) {
  421. $scrollDiv = $('<div style="width:50px;height:50px;overflow:scroll;" />').appendTo( 'body' );
  422. scrollbarWidth = $.fancybox.scrollbarWidth = $scrollDiv[0].offsetWidth - $scrollDiv[0].clientWidth;
  423. $scrollDiv.remove();
  424. }
  425. $( 'head' ).append( '<style id="fancybox-style-noscroll" type="text/css">.compensate-for-scrollbar { margin-right: ' + scrollbarWidth + 'px; }</style>' );
  426. $( 'body' ).addClass( 'compensate-for-scrollbar' );
  427. }
  428. }
  429. // Build html markup and set references
  430. // ====================================
  431. // Build html code for buttons and insert into main template
  432. buttonStr = '';
  433. $.each( firstItemOpts.buttons, function( index, value ) {
  434. buttonStr += ( firstItemOpts.btnTpl[ value ] || '' );
  435. });
  436. // Create markup from base template, it will be initially hidden to
  437. // avoid unnecessary work like painting while initializing is not complete
  438. $container = $(
  439. self.translate( self,
  440. firstItemOpts.baseTpl
  441. .replace( '\{\{buttons\}\}', buttonStr )
  442. .replace( '\{\{arrows\}\}', firstItemOpts.btnTpl.arrowLeft + firstItemOpts.btnTpl.arrowRight )
  443. )
  444. )
  445. .attr( 'id', 'fancybox-container-' + self.id )
  446. .addClass( 'fancybox-is-hidden' )
  447. .addClass( firstItemOpts.baseClass )
  448. .data( 'FancyBox', self )
  449. .appendTo( firstItemOpts.parentEl );
  450. // Create object holding references to jQuery wrapped nodes
  451. self.$refs = {
  452. container : $container
  453. };
  454. [ 'bg', 'inner', 'infobar', 'toolbar', 'stage', 'caption', 'navigation' ].forEach(function(item) {
  455. self.$refs[ item ] = $container.find( '.fancybox-' + item );
  456. });
  457. self.trigger( 'onInit' );
  458. // Enable events, deactive previous instances
  459. self.activate();
  460. // Build slides, load and reveal content
  461. self.jumpTo( self.currIndex );
  462. },
  463. // Simple i18n support - replaces object keys found in template
  464. // with corresponding values
  465. // ============================================================
  466. translate : function( obj, str ) {
  467. var arr = obj.opts.i18n[ obj.opts.lang ];
  468. return str.replace(/\{\{(\w+)\}\}/g, function(match, n) {
  469. var value = arr[n];
  470. if ( value === undefined ) {
  471. return match;
  472. }
  473. return value;
  474. });
  475. },
  476. // Create array of gally item objects
  477. // Check if each object has valid type and content
  478. // ===============================================
  479. createGroup : function ( content ) {
  480. var self = this;
  481. var items = $.makeArray( content );
  482. $.each(items, function( i, item ) {
  483. var obj = {},
  484. opts = {},
  485. $item,
  486. type,
  487. found,
  488. src,
  489. srcParts;
  490. // Step 1 - Make sure we have an object
  491. // ====================================
  492. if ( $.isPlainObject( item ) ) {
  493. // We probably have manual usage here, something like
  494. // $.fancybox.open( [ { src : "image.jpg", type : "image" } ] )
  495. obj = item;
  496. opts = item.opts || item;
  497. } else if ( $.type( item ) === 'object' && $( item ).length ) {
  498. // Here we probably have jQuery collection returned by some selector
  499. $item = $( item );
  500. opts = $item.data();
  501. opts = $.extend( {}, opts, opts.options || {} );
  502. // Here we store clicked element
  503. opts.$orig = $item;
  504. obj.src = opts.src || $item.attr( 'href' );
  505. // Assume that simple syntax is used, for example:
  506. // `$.fancybox.open( $("#test"), {} );`
  507. if ( !obj.type && !obj.src ) {
  508. obj.type = 'inline';
  509. obj.src = item;
  510. }
  511. } else {
  512. // Assume we have a simple html code, for example:
  513. // $.fancybox.open( '<div><h1>Hi!</h1></div>' );
  514. obj = {
  515. type : 'html',
  516. src : item + ''
  517. };
  518. }
  519. // Each gallery object has full collection of options
  520. obj.opts = $.extend( true, {}, self.opts, opts );
  521. // Do not merge buttons array
  522. if ( $.isArray( opts.buttons ) ) {
  523. obj.opts.buttons = opts.buttons;
  524. }
  525. // Step 2 - Make sure we have content type, if not - try to guess
  526. // ==============================================================
  527. type = obj.type || obj.opts.type;
  528. src = obj.src || '';
  529. if ( !type && src ) {
  530. if ( src.match(/(^data:image\/[a-z0-9+\/=]*,)|(\.(jp(e|g|eg)|gif|png|bmp|webp|svg|ico)((\?|#).*)?$)/i) ) {
  531. type = 'image';
  532. } else if ( src.match(/\.(pdf)((\?|#).*)?$/i) ) {
  533. type = 'pdf';
  534. } else if ( found = src.match(/\.(mp4|mov|ogv)((\?|#).*)?$/i) ) {
  535. type = 'video';
  536. if ( !obj.opts.videoFormat ) {
  537. obj.opts.videoFormat = 'video/' + ( found[1] === 'ogv' ? 'ogg' : found[1] );
  538. }
  539. } else if ( src.charAt(0) === '#' ) {
  540. type = 'inline';
  541. }
  542. }
  543. if ( type ) {
  544. obj.type = type;
  545. } else {
  546. self.trigger( 'objectNeedsType', obj );
  547. }
  548. // Step 3 - Some adjustments
  549. // =========================
  550. obj.index = self.group.length;
  551. // Check if $orig and $thumb objects exist
  552. if ( obj.opts.$orig && !obj.opts.$orig.length ) {
  553. delete obj.opts.$orig;
  554. }
  555. if ( !obj.opts.$thumb && obj.opts.$orig ) {
  556. obj.opts.$thumb = obj.opts.$orig.find( 'img:first' );
  557. }
  558. if ( obj.opts.$thumb && !obj.opts.$thumb.length ) {
  559. delete obj.opts.$thumb;
  560. }
  561. // "caption" is a "special" option, it can be used to customize caption per gallery item ..
  562. if ( $.type( obj.opts.caption ) === 'function' ) {
  563. obj.opts.caption = obj.opts.caption.apply( item, [ self, obj ] );
  564. }
  565. if ( $.type( self.opts.caption ) === 'function' ) {
  566. obj.opts.caption = self.opts.caption.apply( item, [ self, obj ] );
  567. }
  568. // Make sure we have caption as a string or jQuery object
  569. if ( !( obj.opts.caption instanceof $ ) ) {
  570. obj.opts.caption = obj.opts.caption === undefined ? '' : obj.opts.caption + '';
  571. }
  572. // Check if url contains "filter" used to filter the content
  573. // Example: "ajax.html #something"
  574. if ( type === 'ajax' ) {
  575. srcParts = src.split(/\s+/, 2);
  576. if ( srcParts.length > 1 ) {
  577. obj.src = srcParts.shift();
  578. obj.opts.filter = srcParts.shift();
  579. }
  580. }
  581. if ( obj.opts.smallBtn == 'auto' ) {
  582. if ( $.inArray( type, ['html', 'inline', 'ajax'] ) > -1 ) {
  583. obj.opts.toolbar = false;
  584. obj.opts.smallBtn = true;
  585. } else {
  586. obj.opts.smallBtn = false;
  587. }
  588. }
  589. // If the type is "pdf", then simply load file into iframe
  590. if ( type === 'pdf' ) {
  591. obj.type = 'iframe';
  592. obj.opts.iframe.preload = false;
  593. }
  594. // Hide all buttons and disable interactivity for modal items
  595. if ( obj.opts.modal ) {
  596. obj.opts = $.extend(true, obj.opts, {
  597. // Remove buttons
  598. infobar : 0,
  599. toolbar : 0,
  600. smallBtn : 0,
  601. // Disable keyboard navigation
  602. keyboard : 0,
  603. // Disable some modules
  604. slideShow : 0,
  605. fullScreen : 0,
  606. thumbs : 0,
  607. touch : 0,
  608. // Disable click event handlers
  609. clickContent : false,
  610. clickSlide : false,
  611. clickOutside : false,
  612. dblclickContent : false,
  613. dblclickSlide : false,
  614. dblclickOutside : false
  615. });
  616. }
  617. // Step 4 - Add processed object to group
  618. // ======================================
  619. self.group.push( obj );
  620. });
  621. },
  622. // Attach an event handler functions for:
  623. // - navigation buttons
  624. // - browser scrolling, resizing;
  625. // - focusing
  626. // - keyboard
  627. // - detect idle
  628. // ======================================
  629. addEvents : function() {
  630. var self = this;
  631. self.removeEvents();
  632. // Make navigation elements clickable
  633. self.$refs.container.on('click.fb-close', '[data-fancybox-close]', function(e) {
  634. e.stopPropagation();
  635. e.preventDefault();
  636. self.close( e );
  637. }).on( 'click.fb-prev touchend.fb-prev', '[data-fancybox-prev]', function(e) {
  638. e.stopPropagation();
  639. e.preventDefault();
  640. self.previous();
  641. }).on( 'click.fb-next touchend.fb-next', '[data-fancybox-next]', function(e) {
  642. e.stopPropagation();
  643. e.preventDefault();
  644. self.next();
  645. }).on( 'click.fb', '[data-fancybox-zoom]', function(e) {
  646. // Click handler for zoom button
  647. self[ self.isScaledDown() ? 'scaleToActual' : 'scaleToFit' ]();
  648. });
  649. // Handle page scrolling and browser resizing
  650. $W.on('orientationchange.fb resize.fb', function(e) {
  651. if ( e && e.originalEvent && e.originalEvent.type === "resize" ) {
  652. requestAFrame(function() {
  653. self.update();
  654. });
  655. } else {
  656. self.$refs.stage.hide();
  657. setTimeout(function() {
  658. self.$refs.stage.show();
  659. self.update();
  660. }, 600);
  661. }
  662. });
  663. // Trap keyboard focus inside of the modal, so the user does not accidentally tab outside of the modal
  664. // (a.k.a. "escaping the modal")
  665. $D.on('focusin.fb', function(e) {
  666. var instance = $.fancybox ? $.fancybox.getInstance() : null;
  667. if ( instance.isClosing || !instance.current || !instance.current.opts.trapFocus || $( e.target ).hasClass( 'fancybox-container' ) || $( e.target ).is( document ) ) {
  668. return;
  669. }
  670. if ( instance && $( e.target ).css( 'position' ) !== 'fixed' && !instance.$refs.container.has( e.target ).length ) {
  671. e.stopPropagation();
  672. instance.focus();
  673. // Sometimes page gets scrolled, set it back
  674. $W.scrollTop( self.scrollTop ).scrollLeft( self.scrollLeft );
  675. }
  676. });
  677. // Enable keyboard navigation
  678. $D.on('keydown.fb', function (e) {
  679. var current = self.current,
  680. keycode = e.keyCode || e.which;
  681. if ( !current || !current.opts.keyboard ) {
  682. return;
  683. }
  684. if ( $(e.target).is('input') || $(e.target).is('textarea') ) {
  685. return;
  686. }
  687. // Backspace and Esc keys
  688. if ( keycode === 8 || keycode === 27 ) {
  689. e.preventDefault();
  690. self.close( e );
  691. return;
  692. }
  693. // Left arrow and Up arrow
  694. if ( keycode === 37 || keycode === 38 ) {
  695. e.preventDefault();
  696. self.previous();
  697. return;
  698. }
  699. // Righ arrow and Down arrow
  700. if ( keycode === 39 || keycode === 40 ) {
  701. e.preventDefault();
  702. self.next();
  703. return;
  704. }
  705. self.trigger('afterKeydown', e, keycode);
  706. });
  707. // Hide controls after some inactivity period
  708. if ( self.group[ self.currIndex ].opts.idleTime ) {
  709. self.idleSecondsCounter = 0;
  710. $D.on('mousemove.fb-idle mouseleave.fb-idle mousedown.fb-idle touchstart.fb-idle touchmove.fb-idle scroll.fb-idle keydown.fb-idle', function(e) {
  711. self.idleSecondsCounter = 0;
  712. if ( self.isIdle ) {
  713. self.showControls();
  714. }
  715. self.isIdle = false;
  716. });
  717. self.idleInterval = window.setInterval(function() {
  718. self.idleSecondsCounter++;
  719. if ( self.idleSecondsCounter >= self.group[ self.currIndex ].opts.idleTime && !self.isDragging ) {
  720. self.isIdle = true;
  721. self.idleSecondsCounter = 0;
  722. self.hideControls();
  723. }
  724. }, 1000);
  725. }
  726. },
  727. // Remove events added by the core
  728. // ===============================
  729. removeEvents : function() {
  730. var self = this;
  731. $W.off( 'orientationchange.fb resize.fb' );
  732. $D.off( 'focusin.fb keydown.fb .fb-idle' );
  733. this.$refs.container.off( '.fb-close .fb-prev .fb-next' );
  734. if ( self.idleInterval ) {
  735. window.clearInterval( self.idleInterval );
  736. self.idleInterval = null;
  737. }
  738. },
  739. // Change to previous gallery item
  740. // ===============================
  741. previous : function( duration ) {
  742. return this.jumpTo( this.currPos - 1, duration );
  743. },
  744. // Change to next gallery item
  745. // ===========================
  746. next : function( duration ) {
  747. return this.jumpTo( this.currPos + 1, duration );
  748. },
  749. // Switch to selected gallery item
  750. // ===============================
  751. jumpTo : function ( pos, duration, slide ) {
  752. var self = this,
  753. firstRun,
  754. loop,
  755. current,
  756. previous,
  757. canvasWidth,
  758. currentPos,
  759. transitionProps;
  760. var groupLen = self.group.length;
  761. if ( self.isDragging || self.isClosing || ( self.isAnimating && self.firstRun ) ) {
  762. return;
  763. }
  764. pos = parseInt( pos, 10 );
  765. loop = self.current ? self.current.opts.loop : self.opts.loop;
  766. if ( !loop && ( pos < 0 || pos >= groupLen ) ) {
  767. return false;
  768. }
  769. firstRun = self.firstRun = ( self.firstRun === null );
  770. if ( groupLen < 2 && !firstRun && !!self.isDragging ) {
  771. return;
  772. }
  773. previous = self.current;
  774. self.prevIndex = self.currIndex;
  775. self.prevPos = self.currPos;
  776. // Create slides
  777. current = self.createSlide( pos );
  778. if ( groupLen > 1 ) {
  779. if ( loop || current.index > 0 ) {
  780. self.createSlide( pos - 1 );
  781. }
  782. if ( loop || current.index < groupLen - 1 ) {
  783. self.createSlide( pos + 1 );
  784. }
  785. }
  786. self.current = current;
  787. self.currIndex = current.index;
  788. self.currPos = current.pos;
  789. self.trigger( 'beforeShow', firstRun );
  790. self.updateControls();
  791. currentPos = $.fancybox.getTranslate( current.$slide );
  792. current.isMoved = ( currentPos.left !== 0 || currentPos.top !== 0 ) && !current.$slide.hasClass( 'fancybox-animated' );
  793. current.forcedDuration = undefined;
  794. if ( $.isNumeric( duration ) ) {
  795. current.forcedDuration = duration;
  796. } else {
  797. duration = current.opts[ firstRun ? 'animationDuration' : 'transitionDuration' ];
  798. }
  799. duration = parseInt( duration, 10 );
  800. // Fresh start - reveal container, current slide and start loading content
  801. if ( firstRun ) {
  802. if ( current.opts.animationEffect && duration ) {
  803. self.$refs.container.css( 'transition-duration', duration + 'ms' );
  804. }
  805. self.$refs.container.removeClass( 'fancybox-is-hidden' );
  806. forceRedraw( self.$refs.container );
  807. self.$refs.container.addClass( 'fancybox-is-open' );
  808. // Make first slide visible (to display loading icon, if needed)
  809. current.$slide.addClass( 'fancybox-slide--current' );
  810. self.loadSlide( current );
  811. self.preload( 'image' );
  812. return;
  813. }
  814. // Clean up
  815. $.each(self.slides, function( index, slide ) {
  816. $.fancybox.stop( slide.$slide );
  817. });
  818. // Make current that slide is visible even if content is still loading
  819. current.$slide.removeClass( 'fancybox-slide--next fancybox-slide--previous' ).addClass( 'fancybox-slide--current' );
  820. // If slides have been dragged, animate them to correct position
  821. if ( current.isMoved ) {
  822. canvasWidth = Math.round( current.$slide.width() );
  823. $.each(self.slides, function( index, slide ) {
  824. var pos = slide.pos - current.pos;
  825. $.fancybox.animate( slide.$slide, {
  826. top : 0,
  827. left : ( pos * canvasWidth ) + ( pos * slide.opts.gutter )
  828. }, duration, function() {
  829. slide.$slide.removeAttr('style').removeClass( 'fancybox-slide--next fancybox-slide--previous' );
  830. if ( slide.pos === self.currPos ) {
  831. current.isMoved = false;
  832. self.complete();
  833. }
  834. });
  835. });
  836. } else {
  837. self.$refs.stage.children().removeAttr( 'style' );
  838. }
  839. // Start transition that reveals current content
  840. // or wait when it will be loaded
  841. if ( current.isLoaded ) {
  842. self.revealContent( current );
  843. } else {
  844. self.loadSlide( current );
  845. }
  846. self.preload( 'image' );
  847. if ( previous.pos === current.pos ) {
  848. return;
  849. }
  850. // Handle previous slide
  851. // =====================
  852. transitionProps = 'fancybox-slide--' + ( previous.pos > current.pos ? 'next' : 'previous' );
  853. previous.$slide.removeClass( 'fancybox-slide--complete fancybox-slide--current fancybox-slide--next fancybox-slide--previous' );
  854. previous.isComplete = false;
  855. if ( !duration || ( !current.isMoved && !current.opts.transitionEffect ) ) {
  856. return;
  857. }
  858. if ( current.isMoved ) {
  859. previous.$slide.addClass( transitionProps );
  860. } else {
  861. transitionProps = 'fancybox-animated ' + transitionProps + ' fancybox-fx-' + current.opts.transitionEffect;
  862. $.fancybox.animate( previous.$slide, transitionProps, duration, function() {
  863. previous.$slide.removeClass( transitionProps ).removeAttr( 'style' );
  864. });
  865. }
  866. },
  867. // Create new "slide" element
  868. // These are gallery items that are actually added to DOM
  869. // =======================================================
  870. createSlide : function( pos ) {
  871. var self = this;
  872. var $slide;
  873. var index;
  874. index = pos % self.group.length;
  875. index = index < 0 ? self.group.length + index : index;
  876. if ( !self.slides[ pos ] && self.group[ index ] ) {
  877. $slide = $('<div class="fancybox-slide"></div>').appendTo( self.$refs.stage );
  878. self.slides[ pos ] = $.extend( true, {}, self.group[ index ], {
  879. pos : pos,
  880. $slide : $slide,
  881. isLoaded : false,
  882. });
  883. self.updateSlide( self.slides[ pos ] );
  884. }
  885. return self.slides[ pos ];
  886. },
  887. // Scale image to the actual size of the image
  888. // ===========================================
  889. scaleToActual : function( x, y, duration ) {
  890. var self = this;
  891. var current = self.current;
  892. var $what = current.$content;
  893. var imgPos, posX, posY, scaleX, scaleY;
  894. var canvasWidth = parseInt( current.$slide.width(), 10 );
  895. var canvasHeight = parseInt( current.$slide.height(), 10 );
  896. var newImgWidth = current.width;
  897. var newImgHeight = current.height;
  898. if ( !( current.type == 'image' && !current.hasError) || !$what || self.isAnimating ) {
  899. return;
  900. }
  901. $.fancybox.stop( $what );
  902. self.isAnimating = true;
  903. x = x === undefined ? canvasWidth * 0.5 : x;
  904. y = y === undefined ? canvasHeight * 0.5 : y;
  905. imgPos = $.fancybox.getTranslate( $what );
  906. scaleX = newImgWidth / imgPos.width;
  907. scaleY = newImgHeight / imgPos.height;
  908. // Get center position for original image
  909. posX = ( canvasWidth * 0.5 - newImgWidth * 0.5 );
  910. posY = ( canvasHeight * 0.5 - newImgHeight * 0.5 );
  911. // Make sure image does not move away from edges
  912. if ( newImgWidth > canvasWidth ) {
  913. posX = imgPos.left * scaleX - ( ( x * scaleX ) - x );
  914. if ( posX > 0 ) {
  915. posX = 0;
  916. }
  917. if ( posX < canvasWidth - newImgWidth ) {
  918. posX = canvasWidth - newImgWidth;
  919. }
  920. }
  921. if ( newImgHeight > canvasHeight) {
  922. posY = imgPos.top * scaleY - ( ( y * scaleY ) - y );
  923. if ( posY > 0 ) {
  924. posY = 0;
  925. }
  926. if ( posY < canvasHeight - newImgHeight ) {
  927. posY = canvasHeight - newImgHeight;
  928. }
  929. }
  930. self.updateCursor( newImgWidth, newImgHeight );
  931. $.fancybox.animate( $what, {
  932. top : posY,
  933. left : posX,
  934. scaleX : scaleX,
  935. scaleY : scaleY
  936. }, duration || 330, function() {
  937. self.isAnimating = false;
  938. });
  939. // Stop slideshow
  940. if ( self.SlideShow && self.SlideShow.isActive ) {
  941. self.SlideShow.stop();
  942. }
  943. },
  944. // Scale image to fit inside parent element
  945. // ========================================
  946. scaleToFit : function( duration ) {
  947. var self = this;
  948. var current = self.current;
  949. var $what = current.$content;
  950. var end;
  951. if ( !( current.type == 'image' && !current.hasError) || !$what || self.isAnimating ) {
  952. return;
  953. }
  954. $.fancybox.stop( $what );
  955. self.isAnimating = true;
  956. end = self.getFitPos( current );
  957. self.updateCursor( end.width, end.height );
  958. $.fancybox.animate( $what, {
  959. top : end.top,
  960. left : end.left,
  961. scaleX : end.width / $what.width(),
  962. scaleY : end.height / $what.height()
  963. }, duration || 330, function() {
  964. self.isAnimating = false;
  965. });
  966. },
  967. // Calculate image size to fit inside viewport
  968. // ===========================================
  969. getFitPos : function( slide ) {
  970. var self = this;
  971. var $what = slide.$content;
  972. var imgWidth = slide.width;
  973. var imgHeight = slide.height;
  974. var margin = slide.opts.margin;
  975. var canvasWidth, canvasHeight, minRatio, width, height;
  976. if ( !$what || !$what.length || ( !imgWidth && !imgHeight) ) {
  977. return false;
  978. }
  979. // Convert "margin to CSS style: [ top, right, bottom, left ]
  980. if ( $.type( margin ) === "number" ) {
  981. margin = [ margin, margin ];
  982. }
  983. if ( margin.length == 2 ) {
  984. margin = [ margin[0], margin[1], margin[0], margin[1] ];
  985. }
  986. // We can not use $slide width here, because it can have different diemensions while in transiton
  987. canvasWidth = parseInt( self.$refs.stage.width(), 10 ) - ( margin[ 1 ] + margin[ 3 ] );
  988. canvasHeight = parseInt( self.$refs.stage.height(), 10 ) - ( margin[ 0 ] + margin[ 2 ] );
  989. minRatio = Math.min(1, canvasWidth / imgWidth, canvasHeight / imgHeight );
  990. width = Math.floor( minRatio * imgWidth );
  991. height = Math.floor( minRatio * imgHeight );
  992. // Use floor rounding to make sure it really fits
  993. return {
  994. top : Math.floor( ( canvasHeight - height ) * 0.5 ) + margin[ 0 ],
  995. left : Math.floor( ( canvasWidth - width ) * 0.5 ) + margin[ 3 ],
  996. width : width,
  997. height : height
  998. };
  999. },
  1000. // Update content size and position for all slides
  1001. // ==============================================
  1002. update : function() {
  1003. var self = this;
  1004. $.each( self.slides, function( key, slide ) {
  1005. self.updateSlide( slide );
  1006. });
  1007. },
  1008. // Update slide content position and size
  1009. // ======================================
  1010. updateSlide : function( slide, duration ) {
  1011. var self = this,
  1012. $what = slide && slide.$content;
  1013. if ( $what && ( slide.width || slide.height ) ) {
  1014. self.isAnimating = false;
  1015. $.fancybox.stop( $what );
  1016. $.fancybox.setTranslate( $what, self.getFitPos( slide ) );
  1017. if ( slide.pos === self.currPos ) {
  1018. self.updateCursor();
  1019. }
  1020. }
  1021. slide.$slide.trigger( 'refresh' );
  1022. self.trigger( 'onUpdate', slide );
  1023. },
  1024. // Horizontally center slide
  1025. // =========================
  1026. centerSlide : function( slide, duration ) {
  1027. var self = this, canvasWidth, pos;
  1028. if ( self.current ) {
  1029. canvasWidth = Math.round( slide.$slide.width() );
  1030. pos = slide.pos - self.current.pos;
  1031. $.fancybox.animate( slide.$slide, {
  1032. top : 0,
  1033. left : ( pos * canvasWidth ) + ( pos * slide.opts.gutter ),
  1034. opacity : 1
  1035. }, duration === undefined ? 0 : duration, null, false);
  1036. }
  1037. },
  1038. // Update cursor style depending if content can be zoomed
  1039. // ======================================================
  1040. updateCursor : function( nextWidth, nextHeight ) {
  1041. var self = this;
  1042. var isScaledDown;
  1043. var $container = self.$refs.container.removeClass( 'fancybox-is-zoomable fancybox-can-zoomIn fancybox-can-drag fancybox-can-zoomOut' );
  1044. if ( !self.current || self.isClosing ) {
  1045. return;
  1046. }
  1047. if ( self.isZoomable() ) {
  1048. $container.addClass( 'fancybox-is-zoomable' );
  1049. if ( nextWidth !== undefined && nextHeight !== undefined ) {
  1050. isScaledDown = nextWidth < self.current.width && nextHeight < self.current.height;
  1051. } else {
  1052. isScaledDown = self.isScaledDown();
  1053. }
  1054. if ( isScaledDown ) {
  1055. // If image is scaled down, then, obviously, it can be zoomed to full size
  1056. $container.addClass( 'fancybox-can-zoomIn' );
  1057. } else {
  1058. if ( self.current.opts.touch ) {
  1059. // If image size ir largen than available available and touch module is not disable,
  1060. // then user can do panning
  1061. $container.addClass( 'fancybox-can-drag' );
  1062. } else {
  1063. $container.addClass( 'fancybox-can-zoomOut' );
  1064. }
  1065. }
  1066. } else if ( self.current.opts.touch ) {
  1067. $container.addClass( 'fancybox-can-drag' );
  1068. }
  1069. },
  1070. // Check if current slide is zoomable
  1071. // ==================================
  1072. isZoomable : function() {
  1073. var self = this;
  1074. var current = self.current;
  1075. var fitPos;
  1076. if ( !current || self.isClosing ) {
  1077. return;
  1078. }
  1079. // Assume that slide is zoomable if
  1080. // - image is loaded successfuly
  1081. // - click action is "zoom"
  1082. // - actual size of the image is smaller than available area
  1083. if ( current.type === 'image' && current.isLoaded && !current.hasError &&
  1084. ( current.opts.clickContent === 'zoom' || ( $.isFunction( current.opts.clickContent ) && current.opts.clickContent( current ) === "zoom" ) )
  1085. ) {
  1086. fitPos = self.getFitPos( current );
  1087. if ( current.width > fitPos.width || current.height > fitPos.height ) {
  1088. return true;
  1089. }
  1090. }
  1091. return false;
  1092. },
  1093. // Check if current image dimensions are smaller than actual
  1094. // =========================================================
  1095. isScaledDown : function() {
  1096. var self = this;
  1097. var current = self.current;
  1098. var $what = current.$content;
  1099. var rez = false;
  1100. if ( $what ) {
  1101. rez = $.fancybox.getTranslate( $what );
  1102. rez = rez.width < current.width || rez.height < current.height;
  1103. }
  1104. return rez;
  1105. },
  1106. // Check if image dimensions exceed parent element
  1107. // ===============================================
  1108. canPan : function() {
  1109. var self = this;
  1110. var current = self.current;
  1111. var $what = current.$content;
  1112. var rez = false;
  1113. if ( $what ) {
  1114. rez = self.getFitPos( current );
  1115. rez = Math.abs( $what.width() - rez.width ) > 1 || Math.abs( $what.height() - rez.height ) > 1;
  1116. }
  1117. return rez;
  1118. },
  1119. // Load content into the slide
  1120. // ===========================
  1121. loadSlide : function( slide ) {
  1122. var self = this, type, $slide;
  1123. var ajaxLoad;
  1124. if ( slide.isLoading ) {
  1125. return;
  1126. }
  1127. if ( slide.isLoaded ) {
  1128. return;
  1129. }
  1130. slide.isLoading = true;
  1131. self.trigger( 'beforeLoad', slide );
  1132. type = slide.type;
  1133. $slide = slide.$slide;
  1134. $slide
  1135. .off( 'refresh' )
  1136. .trigger( 'onReset' )
  1137. .addClass( 'fancybox-slide--' + ( type || 'unknown' ) )
  1138. .addClass( slide.opts.slideClass );
  1139. // Create content depending on the type
  1140. switch ( type ) {
  1141. case 'image':
  1142. self.setImage( slide );
  1143. break;
  1144. case 'iframe':
  1145. self.setIframe( slide );
  1146. break;
  1147. case 'html':
  1148. self.setContent( slide, slide.src || slide.content );
  1149. break;
  1150. case 'inline':
  1151. if ( $( slide.src ).length ) {
  1152. self.setContent( slide, $( slide.src ) );
  1153. } else {
  1154. self.setError( slide );
  1155. }
  1156. break;
  1157. case 'ajax':
  1158. self.showLoading( slide );
  1159. ajaxLoad = $.ajax( $.extend( {}, slide.opts.ajax.settings, {
  1160. url : slide.src,
  1161. success : function ( data, textStatus ) {
  1162. if ( textStatus === 'success' ) {
  1163. self.setContent( slide, data );
  1164. }
  1165. },
  1166. error : function ( jqXHR, textStatus ) {
  1167. if ( jqXHR && textStatus !== 'abort' ) {
  1168. self.setError( slide );
  1169. }
  1170. }
  1171. }));
  1172. $slide.one( 'onReset', function () {
  1173. ajaxLoad.abort();
  1174. });
  1175. break;
  1176. case 'video' :
  1177. self.setContent( slide,
  1178. '<video controls>' +
  1179. '<source src="' + slide.src + '" type="' + slide.opts.videoFormat + '">' +
  1180. 'Your browser doesn\'t support HTML5 video' +
  1181. '</video>'
  1182. );
  1183. break;
  1184. default:
  1185. self.setError( slide );
  1186. break;
  1187. }
  1188. return true;
  1189. },
  1190. // Use thumbnail image, if possible
  1191. // ================================
  1192. setImage : function( slide ) {
  1193. var self = this;
  1194. var srcset = slide.opts.srcset || slide.opts.image.srcset;
  1195. var found, temp, pxRatio, windowWidth;
  1196. // If we have "srcset", then we need to find matching "src" value.
  1197. // This is necessary, because when you set an src attribute, the browser will preload the image
  1198. // before any javascript or even CSS is applied.
  1199. if ( srcset ) {
  1200. pxRatio = window.devicePixelRatio || 1;
  1201. windowWidth = window.innerWidth * pxRatio;
  1202. temp = srcset.split(',').map(function ( el ) {
  1203. var ret = {};
  1204. el.trim().split(/\s+/).forEach(function ( el, i ) {
  1205. var value = parseInt( el.substring(0, el.length - 1), 10 );
  1206. if ( i === 0 ) {
  1207. return ( ret.url = el );
  1208. }
  1209. if ( value ) {
  1210. ret.value = value;
  1211. ret.postfix = el[ el.length - 1 ];
  1212. }
  1213. });
  1214. return ret;
  1215. });
  1216. // Sort by value
  1217. temp.sort(function (a, b) {
  1218. return a.value - b.value;
  1219. });
  1220. // Ok, now we have an array of all srcset values
  1221. for ( var j = 0; j < temp.length; j++ ) {
  1222. var el = temp[ j ];
  1223. if ( ( el.postfix === 'w' && el.value >= windowWidth ) || ( el.postfix === 'x' && el.value >= pxRatio ) ) {
  1224. found = el;
  1225. break;
  1226. }
  1227. }
  1228. // If not found, take the last one
  1229. if ( !found && temp.length ) {
  1230. found = temp[ temp.length - 1 ];
  1231. }
  1232. if ( found ) {
  1233. slide.src = found.url;
  1234. // If we have default width/height values, we can calculate height for matching source
  1235. if ( slide.width && slide.height && found.postfix == 'w' ) {
  1236. slide.height = ( slide.width / slide.height ) * found.value;
  1237. slide.width = found.value;
  1238. }
  1239. }
  1240. }
  1241. // This will be wrapper containing both ghost and actual image
  1242. slide.$content = $('<div class="fancybox-image-wrap"></div>')
  1243. .addClass( 'fancybox-is-hidden' )
  1244. .appendTo( slide.$slide );
  1245. // If we have a thumbnail, we can display it while actual image is loading
  1246. // Users will not stare at black screen and actual image will appear gradually
  1247. if ( slide.opts.preload !== false && slide.opts.width && slide.opts.height && ( slide.opts.thumb || slide.opts.$thumb ) ) {
  1248. slide.width = slide.opts.width;
  1249. slide.height = slide.opts.height;
  1250. slide.$ghost = $('<img />')
  1251. .one('error', function() {
  1252. $(this).remove();
  1253. slide.$ghost = null;
  1254. self.setBigImage( slide );
  1255. })
  1256. .one('load', function() {
  1257. self.afterLoad( slide );
  1258. self.setBigImage( slide );
  1259. })
  1260. .addClass( 'fancybox-image' )
  1261. .appendTo( slide.$content )
  1262. .attr( 'src', slide.opts.thumb || slide.opts.$thumb.attr( 'src' ) );
  1263. } else {
  1264. self.setBigImage( slide );
  1265. }
  1266. },
  1267. // Create full-size image
  1268. // ======================
  1269. setBigImage : function ( slide ) {
  1270. var self = this;
  1271. var $img = $('<img />');
  1272. slide.$image = $img
  1273. .one('error', function() {
  1274. self.setError( slide );
  1275. })
  1276. .one('load', function() {
  1277. // Clear timeout that checks if loading icon needs to be displayed
  1278. clearTimeout( slide.timouts );
  1279. slide.timouts = null;
  1280. if ( self.isClosing ) {
  1281. return;
  1282. }
  1283. slide.width = slide.opts.width || this.naturalWidth;
  1284. slide.height = slide.opts.height || this.naturalHeight;
  1285. if ( slide.opts.image.srcset ) {
  1286. $img.attr( 'sizes', '100vw' ).attr( 'srcset', slide.opts.image.srcset );
  1287. }
  1288. self.hideLoading( slide );
  1289. if ( slide.$ghost ) {
  1290. slide.timouts = setTimeout(function() {
  1291. slide.timouts = null;
  1292. slide.$ghost.hide();
  1293. }, Math.min( 300, Math.max( 1000, slide.height / 1600 ) ) );
  1294. } else {
  1295. self.afterLoad( slide );
  1296. }
  1297. })
  1298. .addClass( 'fancybox-image' )
  1299. .attr('src', slide.src)
  1300. .appendTo( slide.$content );
  1301. if ( ( $img[0].complete || $img[0].readyState == "complete" ) && $img[0].naturalWidth && $img[0].naturalHeight ) {
  1302. $img.trigger( 'load' );
  1303. } else if( $img[0].error ) {
  1304. $img.trigger( 'error' );
  1305. } else {
  1306. slide.timouts = setTimeout(function() {
  1307. if ( !$img[0].complete && !slide.hasError ) {
  1308. self.showLoading( slide );
  1309. }
  1310. }, 100);
  1311. }
  1312. },
  1313. // Create iframe wrapper, iframe and bindings
  1314. // ==========================================
  1315. setIframe : function( slide ) {
  1316. var self = this,
  1317. opts = slide.opts.iframe,
  1318. $slide = slide.$slide,
  1319. $iframe;
  1320. slide.$content = $('<div class="fancybox-content' + ( opts.preload ? ' fancybox-is-hidden' : '' ) + '"></div>')
  1321. .css( opts.css )
  1322. .appendTo( $slide );
  1323. $iframe = $( opts.tpl.replace(/\{rnd\}/g, new Date().getTime()) )
  1324. .attr( opts.attr )
  1325. .appendTo( slide.$content );
  1326. if ( opts.preload ) {
  1327. self.showLoading( slide );
  1328. // Unfortunately, it is not always possible to determine if iframe is successfully loaded
  1329. // (due to browser security policy)
  1330. $iframe.on('load.fb error.fb', function(e) {
  1331. this.isReady = 1;
  1332. slide.$slide.trigger( 'refresh' );
  1333. self.afterLoad( slide );
  1334. });
  1335. // Recalculate iframe content size
  1336. // ===============================
  1337. $slide.on('refresh.fb', function() {
  1338. var $wrap = slide.$content,
  1339. frameWidth = opts.css.width,
  1340. frameHeight = opts.css.height,
  1341. scrollWidth,
  1342. $contents,
  1343. $body;
  1344. if ( $iframe[0].isReady !== 1 ) {
  1345. return;
  1346. }
  1347. // Check if content is accessible,
  1348. // it will fail if frame is not with the same origin
  1349. try {
  1350. $contents = $iframe.contents();
  1351. $body = $contents.find('body');
  1352. } catch (ignore) {}
  1353. // Calculate dimensions for the wrapper
  1354. if ( $body && $body.length ) {
  1355. if ( frameWidth === undefined ) {
  1356. scrollWidth = $iframe[0].contentWindow.document.documentElement.scrollWidth;
  1357. frameWidth = Math.ceil( $body.outerWidth(true) + ( $wrap.width() - scrollWidth ) );
  1358. frameWidth += $wrap.outerWidth() - $wrap.innerWidth();
  1359. }
  1360. if ( frameHeight === undefined ) {
  1361. frameHeight = Math.ceil( $body.outerHeight(true) );
  1362. frameHeight += $wrap.outerHeight() - $wrap.innerHeight();
  1363. }
  1364. // Resize wrapper to fit iframe content
  1365. if ( frameWidth ) {
  1366. $wrap.width( frameWidth );
  1367. }
  1368. if ( frameHeight ) {
  1369. $wrap.height( frameHeight );
  1370. }
  1371. }
  1372. $wrap.removeClass( 'fancybox-is-hidden' );
  1373. });
  1374. } else {
  1375. this.afterLoad( slide );
  1376. }
  1377. $iframe.attr( 'src', slide.src );
  1378. if ( slide.opts.smallBtn === true ) {
  1379. slide.$content.prepend( self.translate( slide, slide.opts.btnTpl.smallBtn ) );
  1380. }
  1381. // Remove iframe if closing or changing gallery item
  1382. $slide.one( 'onReset', function () {
  1383. // This helps IE not to throw errors when closing
  1384. try {
  1385. $( this ).find( 'iframe' ).hide().attr( 'src', '//about:blank' );
  1386. } catch ( ignore ) {}
  1387. $( this ).empty();
  1388. slide.isLoaded = false;
  1389. });
  1390. },
  1391. // Wrap and append content to the slide
  1392. // ======================================
  1393. setContent : function ( slide, content ) {
  1394. var self = this;
  1395. if ( self.isClosing ) {
  1396. return;
  1397. }
  1398. self.hideLoading( slide );
  1399. slide.$slide.empty();
  1400. if ( isQuery( content ) && content.parent().length ) {
  1401. // If content is a jQuery object, then it will be moved to the slide.
  1402. // The placeholder is created so we will know where to put it back.
  1403. // If user is navigating gallery fast, then the content might be already inside fancyBox
  1404. // =====================================================================================
  1405. // Make sure content is not already moved to fancyBox
  1406. content.parent( '.fancybox-slide--inline' ).trigger( 'onReset' );
  1407. // Create temporary element marking original place of the content
  1408. slide.$placeholder = $( '<div></div>' ).hide().insertAfter( content );
  1409. // Make sure content is visible
  1410. content.css('display', 'inline-block');
  1411. } else if ( !slide.hasError ) {
  1412. // If content is just a plain text, try to convert it to html
  1413. if ( $.type( content ) === 'string' ) {
  1414. content = $('<div>').append( $.trim( content ) ).contents();
  1415. // If we have text node, then add wrapping element to make vertical alignment work
  1416. if ( content[0].nodeType === 3 ) {
  1417. content = $('<div>').html( content );
  1418. }
  1419. }
  1420. // If "filter" option is provided, then filter content
  1421. if ( slide.opts.filter ) {
  1422. content = $('<div>').html( content ).find( slide.opts.filter );
  1423. }
  1424. }
  1425. slide.$slide.one('onReset', function () {
  1426. // Pause all html5 video/audio
  1427. $( this ).find( 'video,audio' ).trigger( 'pause' );
  1428. // Put content back
  1429. if ( slide.$placeholder ) {
  1430. slide.$placeholder.after( content.hide() ).remove();
  1431. slide.$placeholder = null;
  1432. }
  1433. // Remove custom close button
  1434. if ( slide.$smallBtn ) {
  1435. slide.$smallBtn.remove();
  1436. slide.$smallBtn = null;
  1437. }
  1438. // Remove content and mark slide as not loaded
  1439. if ( !slide.hasError ) {
  1440. $(this).empty();
  1441. slide.isLoaded = false;
  1442. }
  1443. });
  1444. slide.$content = $( content ).appendTo( slide.$slide );
  1445. this.afterLoad( slide );
  1446. },
  1447. // Display error message
  1448. // =====================
  1449. setError : function ( slide ) {
  1450. slide.hasError = true;
  1451. slide.$slide.removeClass( 'fancybox-slide--' + slide.type );
  1452. this.setContent( slide, this.translate( slide, slide.opts.errorTpl ) );
  1453. },
  1454. // Show loading icon inside the slide
  1455. // ==================================
  1456. showLoading : function( slide ) {
  1457. var self = this;
  1458. slide = slide || self.current;
  1459. if ( slide && !slide.$spinner ) {
  1460. slide.$spinner = $( self.opts.spinnerTpl ).appendTo( slide.$slide );
  1461. }
  1462. },
  1463. // Remove loading icon from the slide
  1464. // ==================================
  1465. hideLoading : function( slide ) {
  1466. var self = this;
  1467. slide = slide || self.current;
  1468. if ( slide && slide.$spinner ) {
  1469. slide.$spinner.remove();
  1470. delete slide.$spinner;
  1471. }
  1472. },
  1473. // Adjustments after slide content has been loaded
  1474. // ===============================================
  1475. afterLoad : function( slide ) {
  1476. var self = this;
  1477. if ( self.isClosing ) {
  1478. return;
  1479. }
  1480. slide.isLoading = false;
  1481. slide.isLoaded = true;
  1482. self.trigger( 'afterLoad', slide );
  1483. self.hideLoading( slide );
  1484. if ( slide.opts.smallBtn && !slide.$smallBtn ) {
  1485. slide.$smallBtn = $( self.translate( slide, slide.opts.btnTpl.smallBtn ) ).appendTo( slide.$content.filter('div,form').first() );
  1486. }
  1487. if ( slide.opts.protect && slide.$content && !slide.hasError ) {
  1488. // Disable right click
  1489. slide.$content.on( 'contextmenu.fb', function( e ) {
  1490. if ( e.button == 2 ) {
  1491. e.preventDefault();
  1492. }
  1493. return true;
  1494. });
  1495. // Add fake element on top of the image
  1496. // This makes a bit harder for user to select image
  1497. if ( slide.type === 'image' ) {
  1498. $( '<div class="fancybox-spaceball"></div>' ).appendTo( slide.$content );
  1499. }
  1500. }
  1501. self.revealContent( slide );
  1502. },
  1503. // Make content visible
  1504. // This method is called right after content has been loaded or
  1505. // user navigates gallery and transition should start
  1506. // ============================================================
  1507. revealContent : function( slide ) {
  1508. var self = this;
  1509. var $slide = slide.$slide;
  1510. var effect, effectClassName, duration, opacity, end, start = false;
  1511. effect = slide.opts[ self.firstRun ? 'animationEffect' : 'transitionEffect' ];
  1512. duration = slide.opts[ self.firstRun ? 'animationDuration' : 'transitionDuration' ];
  1513. duration = parseInt( slide.forcedDuration === undefined ? duration : slide.forcedDuration, 10 );
  1514. if ( slide.isMoved || slide.pos !== self.currPos || !duration ) {
  1515. effect = false;
  1516. }
  1517. // Check if can zoom
  1518. if ( effect === 'zoom' && !( slide.pos === self.currPos && duration && slide.type === 'image' && !slide.hasError && ( start = self.getThumbPos( slide ) ) ) ) {
  1519. effect = 'fade';
  1520. }
  1521. // Zoom animation
  1522. // ==============
  1523. if ( effect === 'zoom' ) {
  1524. end = self.getFitPos( slide );
  1525. end.scaleX = end.width / start.width;
  1526. end.scaleY = end.height / start.height;
  1527. delete end.width;
  1528. delete end.height;
  1529. // Check if we need to animate opacity
  1530. opacity = slide.opts.zoomOpacity;
  1531. if ( opacity == 'auto' ) {
  1532. opacity = Math.abs( slide.width / slide.height - start.width / start.height ) > 0.1;
  1533. }
  1534. if ( opacity ) {
  1535. start.opacity = 0.1;
  1536. end.opacity = 1;
  1537. }
  1538. // Draw image at start position
  1539. $.fancybox.setTranslate( slide.$content.removeClass( 'fancybox-is-hidden' ), start );
  1540. forceRedraw( slide.$content );
  1541. // Start animation
  1542. $.fancybox.animate( slide.$content, end, duration, function() {
  1543. self.complete();
  1544. });
  1545. return;
  1546. }
  1547. self.updateSlide( slide );
  1548. // Simply show content
  1549. // ===================
  1550. if ( !effect ) {
  1551. forceRedraw( $slide );
  1552. slide.$content.removeClass( 'fancybox-is-hidden' );
  1553. if ( slide.pos === self.currPos ) {
  1554. self.complete();
  1555. }
  1556. return;
  1557. }
  1558. $.fancybox.stop( $slide );
  1559. effectClassName = 'fancybox-animated fancybox-slide--' + ( slide.pos >= self.prevPos ? 'next' : 'previous' ) + ' fancybox-fx-' + effect;
  1560. $slide.removeAttr( 'style' ).removeClass( 'fancybox-slide--current fancybox-slide--next fancybox-slide--previous' ).addClass( effectClassName );
  1561. slide.$content.removeClass( 'fancybox-is-hidden' );
  1562. //Force reflow for CSS3 transitions
  1563. forceRedraw( $slide );
  1564. $.fancybox.animate( $slide, 'fancybox-slide--current', duration, function(e) {
  1565. $slide.removeClass( effectClassName ).removeAttr( 'style' );
  1566. if ( slide.pos === self.currPos ) {
  1567. self.complete();
  1568. }
  1569. }, true);
  1570. },
  1571. // Check if we can and have to zoom from thumbnail
  1572. //================================================
  1573. getThumbPos : function( slide ) {
  1574. var self = this;
  1575. var rez = false;
  1576. // Check if element is inside the viewport by at least 1 pixel
  1577. var isElementVisible = function( $el ) {
  1578. var element = $el[0];
  1579. var elementRect = element.getBoundingClientRect();
  1580. var parentRects = [];
  1581. var visibleInAllParents;
  1582. while ( element.parentElement !== null ) {
  1583. if ( $(element.parentElement).css('overflow') === 'hidden' || $(element.parentElement).css('overflow') === 'auto' ) {
  1584. parentRects.push(element.parentElement.getBoundingClientRect());
  1585. }
  1586. element = element.parentElement;
  1587. }
  1588. visibleInAllParents = parentRects.every(function(parentRect){
  1589. var visiblePixelX = Math.min(elementRect.right, parentRect.right) - Math.max(elementRect.left, parentRect.left);
  1590. var visiblePixelY = Math.min(elementRect.bottom, parentRect.bottom) - Math.max(elementRect.top, parentRect.top);
  1591. return visiblePixelX > 0 && visiblePixelY > 0;
  1592. });
  1593. return visibleInAllParents &&
  1594. elementRect.bottom > 0 && elementRect.right > 0 &&
  1595. elementRect.left < $(window).width() && elementRect.top < $(window).height();
  1596. };
  1597. var $thumb = slide.opts.$thumb;
  1598. var thumbPos = $thumb ? $thumb.offset() : 0;
  1599. var slidePos;
  1600. if ( thumbPos && $thumb[0].ownerDocument === document && isElementVisible( $thumb ) ) {
  1601. slidePos = self.$refs.stage.offset();
  1602. rez = {
  1603. top : thumbPos.top - slidePos.top + parseFloat( $thumb.css( "border-top-width" ) || 0 ),
  1604. left : thumbPos.left - slidePos.left + parseFloat( $thumb.css( "border-left-width" ) || 0 ),
  1605. width : $thumb.width(),
  1606. height : $thumb.height(),
  1607. scaleX : 1,
  1608. scaleY : 1
  1609. };
  1610. }
  1611. return rez;
  1612. },
  1613. // Final adjustments after current gallery item is moved to position
  1614. // and it`s content is loaded
  1615. // ==================================================================
  1616. complete : function() {
  1617. var self = this,
  1618. current = self.current,
  1619. slides = {},
  1620. promise;
  1621. if ( current.isMoved || !current.isLoaded || current.isComplete ) {
  1622. return;
  1623. }
  1624. current.isComplete = true;
  1625. current.$slide.siblings().trigger( 'onReset' );
  1626. self.preload( 'inline' );
  1627. // Trigger any CSS3 transiton inside the slide
  1628. forceRedraw( current.$slide );
  1629. current.$slide.addClass( 'fancybox-slide--complete' );
  1630. // Remove unnecessary slides
  1631. $.each( self.slides, function( key, slide ) {
  1632. if ( slide.pos >= self.currPos - 1 && slide.pos <= self.currPos + 1 ) {
  1633. slides[ slide.pos ] = slide;
  1634. } else if ( slide ) {
  1635. $.fancybox.stop( slide.$slide );
  1636. slide.$slide.off().remove();
  1637. }
  1638. });
  1639. self.slides = slides;
  1640. self.updateCursor();
  1641. self.trigger( 'afterShow' );
  1642. // Play first html5 video/audio
  1643. current.$slide.find( 'video,audio' ).first().trigger( 'play' );
  1644. // Try to focus on the first focusable element
  1645. if ( $( document.activeElement ).is( '[disabled]' ) || ( current.opts.autoFocus && !( current.type == 'image' || current.type === 'iframe' ) ) ) {
  1646. self.focus();
  1647. }
  1648. },
  1649. // Preload next and previous slides
  1650. // ================================
  1651. preload : function( type ) {
  1652. var self = this,
  1653. next = self.slides[ self.currPos + 1 ],
  1654. prev = self.slides[ self.currPos - 1 ];
  1655. if ( next && next.type === type ) {
  1656. self.loadSlide( next );
  1657. }
  1658. if ( prev && prev.type === type ) {
  1659. self.loadSlide( prev );
  1660. }
  1661. },
  1662. // Try to find and focus on the first focusable element
  1663. // ====================================================
  1664. focus : function() {
  1665. var current = this.current;
  1666. var $el;
  1667. if ( this.isClosing ) {
  1668. return;
  1669. }
  1670. if ( current && current.isComplete ) {
  1671. // Look for first input with autofocus attribute
  1672. $el = current.$slide.find('input[autofocus]:enabled:visible:first');
  1673. if ( !$el.length ) {
  1674. $el = current.$slide.find('button,:input,[tabindex],a').filter(':enabled:visible:first');
  1675. }
  1676. }
  1677. $el = $el && $el.length ? $el : this.$refs.container;
  1678. $el.focus();
  1679. },
  1680. // Activates current instance - brings container to the front and enables keyboard,
  1681. // notifies other instances about deactivating
  1682. // =================================================================================
  1683. activate : function () {
  1684. var self = this;
  1685. // Deactivate all instances
  1686. $( '.fancybox-container' ).each(function () {
  1687. var instance = $(this).data( 'FancyBox' );
  1688. // Skip self and closing instances
  1689. if (instance && instance.id !== self.id && !instance.isClosing) {
  1690. instance.trigger( 'onDeactivate' );
  1691. instance.removeEvents();
  1692. instance.isVisible = false;
  1693. }
  1694. });
  1695. self.isVisible = true;
  1696. if ( self.current || self.isIdle ) {
  1697. self.update();
  1698. self.updateControls();
  1699. }
  1700. self.trigger( 'onActivate' );
  1701. self.addEvents();
  1702. },
  1703. // Start closing procedure
  1704. // This will start "zoom-out" animation if needed and clean everything up afterwards
  1705. // =================================================================================
  1706. close : function( e, d ) {
  1707. var self = this;
  1708. var current = self.current;
  1709. var effect, duration;
  1710. var $what, opacity, start, end;
  1711. var done = function() {
  1712. self.cleanUp( e );
  1713. };
  1714. if ( self.isClosing ) {
  1715. return false;
  1716. }
  1717. self.isClosing = true;
  1718. // If beforeClose callback prevents closing, make sure content is centered
  1719. if ( self.trigger( 'beforeClose', e ) === false ) {
  1720. self.isClosing = false;
  1721. requestAFrame(function() {
  1722. self.update();
  1723. });
  1724. return false;
  1725. }
  1726. // Remove all events
  1727. // If there are multiple instances, they will be set again by "activate" method
  1728. self.removeEvents();
  1729. if ( current.timouts ) {
  1730. clearTimeout( current.timouts );
  1731. }
  1732. $what = current.$content;
  1733. effect = current.opts.animationEffect;
  1734. duration = $.isNumeric( d ) ? d : ( effect ? current.opts.animationDuration : 0 );
  1735. // Remove other slides
  1736. current.$slide.off( transitionEnd ).removeClass( 'fancybox-slide--complete fancybox-slide--next fancybox-slide--previous fancybox-animated' );
  1737. current.$slide.siblings().trigger( 'onReset' ).remove();
  1738. // Trigger animations
  1739. if ( duration ) {
  1740. self.$refs.container.removeClass( 'fancybox-is-open' ).addClass( 'fancybox-is-closing' );
  1741. }
  1742. // Clean up
  1743. self.hideLoading( current );
  1744. self.hideControls();
  1745. self.updateCursor();
  1746. // Check if possible to zoom-out
  1747. if ( effect === 'zoom' && !( e !== true && $what && duration && current.type === 'image' && !current.hasError && ( end = self.getThumbPos( current ) ) ) ) {
  1748. effect = 'fade';
  1749. }
  1750. if ( effect === 'zoom' ) {
  1751. $.fancybox.stop( $what );
  1752. start = $.fancybox.getTranslate( $what );
  1753. start.width = start.width * start.scaleX;
  1754. start.height = start.height * start.scaleY;
  1755. // Check if we need to animate opacity
  1756. opacity = current.opts.zoomOpacity;
  1757. if ( opacity == 'auto' ) {
  1758. opacity = Math.abs( current.width / current.height - end.width / end.height ) > 0.1;
  1759. }
  1760. if ( opacity ) {
  1761. end.opacity = 0;
  1762. }
  1763. start.scaleX = start.width / end.width;
  1764. start.scaleY = start.height / end.height;
  1765. start.width = end.width;
  1766. start.height = end.height;
  1767. $.fancybox.setTranslate( current.$content, start );
  1768. forceRedraw( current.$content );
  1769. $.fancybox.animate( current.$content, end, duration, done );
  1770. return true;
  1771. }
  1772. if ( effect && duration ) {
  1773. // If skip animation
  1774. if ( e === true ) {
  1775. setTimeout( done, duration );
  1776. } else {
  1777. $.fancybox.animate( current.$slide.removeClass( 'fancybox-slide--current' ), 'fancybox-animated fancybox-slide--previous fancybox-fx-' + effect, duration, done );
  1778. }
  1779. } else {
  1780. done();
  1781. }
  1782. return true;
  1783. },
  1784. // Final adjustments after removing the instance
  1785. // =============================================
  1786. cleanUp : function( e ) {
  1787. var self = this,
  1788. $body = $( 'body' ),
  1789. instance,
  1790. offset;
  1791. self.current.$slide.trigger( 'onReset' );
  1792. self.$refs.container.empty().remove();
  1793. self.trigger( 'afterClose', e );
  1794. // Place back focus
  1795. if ( self.$lastFocus && !!self.current.opts.backFocus ) {
  1796. self.$lastFocus.focus();
  1797. }
  1798. self.current = null;
  1799. // Check if there are other instances
  1800. instance = $.fancybox.getInstance();
  1801. if ( instance ) {
  1802. instance.activate();
  1803. } else {
  1804. $W.scrollTop( self.scrollTop ).scrollLeft( self.scrollLeft );
  1805. $body.removeClass( 'fancybox-active compensate-for-scrollbar' );
  1806. if ( $body.hasClass( 'fancybox-iosfix' ) ) {
  1807. offset = parseInt(document.body.style.top, 10);
  1808. $body.removeClass( 'fancybox-iosfix' ).css( 'top', '' ).scrollTop( offset * -1 );
  1809. }
  1810. $( '#fancybox-style-noscroll' ).remove();
  1811. }
  1812. },
  1813. // Call callback and trigger an event
  1814. // ==================================
  1815. trigger : function( name, slide ) {
  1816. var args = Array.prototype.slice.call(arguments, 1),
  1817. self = this,
  1818. obj = slide && slide.opts ? slide : self.current,
  1819. rez;
  1820. if ( obj ) {
  1821. args.unshift( obj );
  1822. } else {
  1823. obj = self;
  1824. }
  1825. args.unshift( self );
  1826. if ( $.isFunction( obj.opts[ name ] ) ) {
  1827. rez = obj.opts[ name ].apply( obj, args );
  1828. }
  1829. if ( rez === false ) {
  1830. return rez;
  1831. }
  1832. if ( name === 'afterClose' || !self.$refs ) {
  1833. $D.trigger( name + '.fb', args );
  1834. } else {
  1835. self.$refs.container.trigger( name + '.fb', args );
  1836. }
  1837. },
  1838. // Update infobar values, navigation button states and reveal caption
  1839. // ==================================================================
  1840. updateControls : function ( force ) {
  1841. var self = this;
  1842. var current = self.current,
  1843. index = current.index,
  1844. caption = current.opts.caption,
  1845. $container = self.$refs.container,
  1846. $caption = self.$refs.caption;
  1847. // Recalculate content dimensions
  1848. current.$slide.trigger( 'refresh' );
  1849. self.$caption = caption && caption.length ? $caption.html( caption ) : null;
  1850. if ( !self.isHiddenControls && !self.isIdle ) {
  1851. self.showControls();
  1852. }
  1853. // Update info and navigation elements
  1854. $container.find('[data-fancybox-count]').html( self.group.length );
  1855. $container.find('[data-fancybox-index]').html( index + 1 );
  1856. $container.find('[data-fancybox-prev]').prop( 'disabled', ( !current.opts.loop && index <= 0 ) );
  1857. $container.find('[data-fancybox-next]').prop( 'disabled', ( !current.opts.loop && index >= self.group.length - 1 ) );
  1858. if ( current.type === 'image' ) {
  1859. // Update download button source
  1860. $container.find('[data-fancybox-download]').attr( 'href', current.opts.image.src || current.src ).show();
  1861. } else {
  1862. $container.find('[data-fancybox-download],[data-fancybox-zoom]').hide();
  1863. }
  1864. },
  1865. // Hide toolbar and caption
  1866. // ========================
  1867. hideControls : function () {
  1868. this.isHiddenControls = true;
  1869. this.$refs.container.removeClass( 'fancybox-show-infobar fancybox-show-toolbar fancybox-show-caption fancybox-show-nav' );
  1870. },
  1871. showControls : function() {
  1872. var self = this;
  1873. var opts = self.current ? self.current.opts : self.opts;
  1874. var $container = self.$refs.container;
  1875. self.isHiddenControls = false;
  1876. self.idleSecondsCounter = 0;
  1877. $container
  1878. .toggleClass( 'fancybox-show-toolbar', !!( opts.toolbar && opts.buttons ) )
  1879. .toggleClass( 'fancybox-show-infobar', !!( opts.infobar && self.group.length > 1 ) )
  1880. .toggleClass( 'fancybox-show-nav', !!( opts.arrows && self.group.length > 1 ) )
  1881. .toggleClass( 'fancybox-is-modal', !!opts.modal );
  1882. if ( self.$caption ) {
  1883. $container.addClass( 'fancybox-show-caption ');
  1884. } else {
  1885. $container.removeClass( 'fancybox-show-caption' );
  1886. }
  1887. },
  1888. // Toggle toolbar and caption
  1889. // ==========================
  1890. toggleControls : function() {
  1891. if ( this.isHiddenControls ) {
  1892. this.showControls();
  1893. } else {
  1894. this.hideControls();
  1895. }
  1896. },
  1897. });
  1898. $.fancybox = {
  1899. version : "3.2.10",
  1900. defaults : defaults,
  1901. // Get current instance and execute a command.
  1902. //
  1903. // Examples of usage:
  1904. //
  1905. // $instance = $.fancybox.getInstance();
  1906. // $.fancybox.getInstance().jumpTo( 1 );
  1907. // $.fancybox.getInstance( 'jumpTo', 1 );
  1908. // $.fancybox.getInstance( function() {
  1909. // console.info( this.currIndex );
  1910. // });
  1911. // ======================================================
  1912. getInstance : function ( command ) {
  1913. var instance = $('.fancybox-container:not(".fancybox-is-closing"):last').data( 'FancyBox' );
  1914. var args = Array.prototype.slice.call(arguments, 1);
  1915. if ( instance instanceof FancyBox ) {
  1916. if ( $.type( command ) === 'string' ) {
  1917. instance[ command ].apply( instance, args );
  1918. } else if ( $.type( command ) === 'function' ) {
  1919. command.apply( instance, args );
  1920. }
  1921. return instance;
  1922. }
  1923. return false;
  1924. },
  1925. // Create new instance
  1926. // ===================
  1927. open : function ( items, opts, index ) {
  1928. return new FancyBox( items, opts, index );
  1929. },
  1930. // Close current or all instances
  1931. // ==============================
  1932. close : function ( all ) {
  1933. var instance = this.getInstance();
  1934. if ( instance ) {
  1935. instance.close();
  1936. // Try to find and close next instance
  1937. if ( all === true ) {
  1938. this.close();
  1939. }
  1940. }
  1941. },
  1942. // Close instances and unbind all events
  1943. // ==============================
  1944. destroy : function() {
  1945. this.close( true );
  1946. $D.off( 'click.fb-start' );
  1947. },
  1948. // Try to detect mobile devices
  1949. // ============================
  1950. isMobile : document.createTouch !== undefined && /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent),
  1951. // Detect if 'translate3d' support is available
  1952. // ============================================
  1953. use3d : (function() {
  1954. var div = document.createElement('div');
  1955. return window.getComputedStyle && window.getComputedStyle( div ).getPropertyValue('transform') && !(document.documentMode && document.documentMode < 11);
  1956. }()),
  1957. // Helper function to get current visual state of an element
  1958. // returns array[ top, left, horizontal-scale, vertical-scale, opacity ]
  1959. // =====================================================================
  1960. getTranslate : function( $el ) {
  1961. var matrix;
  1962. if ( !$el || !$el.length ) {
  1963. return false;
  1964. }
  1965. matrix = $el.eq( 0 ).css('transform');
  1966. if ( matrix && matrix.indexOf( 'matrix' ) !== -1 ) {
  1967. matrix = matrix.split('(')[1];
  1968. matrix = matrix.split(')')[0];
  1969. matrix = matrix.split(',');
  1970. } else {
  1971. matrix = [];
  1972. }
  1973. if ( matrix.length ) {
  1974. // If IE
  1975. if ( matrix.length > 10 ) {
  1976. matrix = [ matrix[13], matrix[12], matrix[0], matrix[5] ];
  1977. } else {
  1978. matrix = [ matrix[5], matrix[4], matrix[0], matrix[3]];
  1979. }
  1980. matrix = matrix.map(parseFloat);
  1981. } else {
  1982. matrix = [ 0, 0, 1, 1 ];
  1983. var transRegex = /\.*translate\((.*)px,(.*)px\)/i;
  1984. var transRez = transRegex.exec( $el.eq( 0 ).attr('style') );
  1985. if ( transRez ) {
  1986. matrix[ 0 ] = parseFloat( transRez[2] );
  1987. matrix[ 1 ] = parseFloat( transRez[1] );
  1988. }
  1989. }
  1990. return {
  1991. top : matrix[ 0 ],
  1992. left : matrix[ 1 ],
  1993. scaleX : matrix[ 2 ],
  1994. scaleY : matrix[ 3 ],
  1995. opacity : parseFloat( $el.css('opacity') ),
  1996. width : $el.width(),
  1997. height : $el.height()
  1998. };
  1999. },
  2000. // Shortcut for setting "translate3d" properties for element
  2001. // Can set be used to set opacity, too
  2002. // ========================================================
  2003. setTranslate : function( $el, props ) {
  2004. var str = '';
  2005. var css = {};
  2006. if ( !$el || !props ) {
  2007. return;
  2008. }
  2009. if ( props.left !== undefined || props.top !== undefined ) {
  2010. str = ( props.left === undefined ? $el.position().left : props.left ) + 'px, ' + ( props.top === undefined ? $el.position().top : props.top ) + 'px';
  2011. if ( this.use3d ) {
  2012. str = 'translate3d(' + str + ', 0px)';
  2013. } else {
  2014. str = 'translate(' + str + ')';
  2015. }
  2016. }
  2017. if ( props.scaleX !== undefined && props.scaleY !== undefined ) {
  2018. str = (str.length ? str + ' ' : '') + 'scale(' + props.scaleX + ', ' + props.scaleY + ')';
  2019. }
  2020. if ( str.length ) {
  2021. css.transform = str;
  2022. }
  2023. if ( props.opacity !== undefined ) {
  2024. css.opacity = props.opacity;
  2025. }
  2026. if ( props.width !== undefined ) {
  2027. css.width = props.width;
  2028. }
  2029. if ( props.height !== undefined ) {
  2030. css.height = props.height;
  2031. }
  2032. return $el.css( css );
  2033. },
  2034. // Simple CSS transition handler
  2035. // =============================
  2036. animate : function ( $el, to, duration, callback, leaveAnimationName ) {
  2037. if ( $.isFunction( duration ) ) {
  2038. callback = duration;
  2039. duration = null;
  2040. }
  2041. if ( !$.isPlainObject( to ) ) {
  2042. $el.removeAttr( 'style' );
  2043. }
  2044. $el.on( transitionEnd, function(e) {
  2045. // Skip events from child elements and z-index change
  2046. if ( e && e.originalEvent && ( !$el.is( e.originalEvent.target ) || e.originalEvent.propertyName == 'z-index' ) ) {
  2047. return;
  2048. }
  2049. $.fancybox.stop( $el );
  2050. if ( $.isPlainObject( to ) ) {
  2051. if ( to.scaleX !== undefined && to.scaleY !== undefined ) {
  2052. $el.css( 'transition-duration', '' );
  2053. to.width = Math.round( $el.width() * to.scaleX );
  2054. to.height = Math.round( $el.height() * to.scaleY );
  2055. to.scaleX = 1;
  2056. to.scaleY = 1;
  2057. $.fancybox.setTranslate( $el, to );
  2058. }
  2059. if ( leaveAnimationName === false ) {
  2060. $el.removeAttr( 'style' );
  2061. }
  2062. } else if ( leaveAnimationName !== true ) {
  2063. $el.removeClass( to );
  2064. }
  2065. if ( $.isFunction( callback ) ) {
  2066. callback( e );
  2067. }
  2068. });
  2069. if ( $.isNumeric( duration ) ) {
  2070. $el.css( 'transition-duration', duration + 'ms' );
  2071. }
  2072. if ( $.isPlainObject( to ) ) {
  2073. $.fancybox.setTranslate( $el, to );
  2074. } else {
  2075. $el.addClass( to );
  2076. }
  2077. if ( to.scaleX && $el.hasClass( 'fancybox-image-wrap' ) ) {
  2078. $el.parent().addClass( 'fancybox-is-scaling' );
  2079. }
  2080. // Make sure that `transitionend` callback gets fired
  2081. $el.data("timer", setTimeout(function() {
  2082. $el.trigger( 'transitionend' );
  2083. }, duration + 16));
  2084. },
  2085. stop : function( $el ) {
  2086. clearTimeout( $el.data("timer") );
  2087. $el.off( 'transitionend' ).css( 'transition-duration', '' );
  2088. if ( $el.hasClass( 'fancybox-image-wrap' ) ) {
  2089. $el.parent().removeClass( 'fancybox-is-scaling' );
  2090. }
  2091. }
  2092. };
  2093. // Default click handler for "fancyboxed" links
  2094. // ============================================
  2095. function _run( e ) {
  2096. var $target = $( e.currentTarget ),
  2097. opts = e.data ? e.data.options : {},
  2098. value = $target.attr( 'data-fancybox' ) || '',
  2099. index = 0,
  2100. items = [];
  2101. // Avoid opening multiple times
  2102. if ( e.isDefaultPrevented() ) {
  2103. return;
  2104. }
  2105. e.preventDefault();
  2106. // Get all related items and find index for clicked one
  2107. if ( value ) {
  2108. items = opts.selector ? $( opts.selector ) : ( e.data ? e.data.items : [] );
  2109. items = items.length ? items.filter( '[data-fancybox="' + value + '"]' ) : $( '[data-fancybox="' + value + '"]' );
  2110. index = items.index( $target );
  2111. // Sometimes current item can not be found
  2112. // (for example, when slider clones items)
  2113. if ( index < 0 ) {
  2114. index = 0;
  2115. }
  2116. } else {
  2117. items = [ $target ];
  2118. }
  2119. $.fancybox.open( items, opts, index );
  2120. }
  2121. // Create a jQuery plugin
  2122. // ======================
  2123. $.fn.fancybox = function (options) {
  2124. var selector;
  2125. options = options || {};
  2126. selector = options.selector || false;
  2127. if ( selector ) {
  2128. $( 'body' ).off( 'click.fb-start', selector ).on( 'click.fb-start', selector, {
  2129. options : options
  2130. }, _run );
  2131. } else {
  2132. this.off( 'click.fb-start' ).on( 'click.fb-start', {
  2133. items : this,
  2134. options : options
  2135. }, _run);
  2136. }
  2137. return this;
  2138. };
  2139. // Self initializing plugin
  2140. // ========================
  2141. $D.on( 'click.fb-start', '[data-fancybox]', _run );
  2142. }( window, document, window.jQuery || jQuery ));
  2143. // ==========================================================================
  2144. //
  2145. // Media
  2146. // Adds additional media type support
  2147. //
  2148. // ==========================================================================
  2149. ;(function ($) {
  2150. 'use strict';
  2151. // Formats matching url to final form
  2152. var format = function (url, rez, params) {
  2153. if ( !url ) {
  2154. return;
  2155. }
  2156. params = params || '';
  2157. if ( $.type(params) === "object" ) {
  2158. params = $.param(params, true);
  2159. }
  2160. $.each(rez, function (key, value) {
  2161. url = url.replace('$' + key, value || '');
  2162. });
  2163. if (params.length) {
  2164. url += (url.indexOf('?') > 0 ? '&' : '?') + params;
  2165. }
  2166. return url;
  2167. };
  2168. // Object containing properties for each media type
  2169. var defaults = {
  2170. youtube : {
  2171. matcher : /(youtube\.com|youtu\.be|youtube\-nocookie\.com)\/(watch\?(.*&)?v=|v\/|u\/|embed\/?)?(videoseries\?list=(.*)|[\w-]{11}|\?listType=(.*)&list=(.*))(.*)/i,
  2172. params : {
  2173. autoplay : 1,
  2174. autohide : 1,
  2175. fs : 1,
  2176. rel : 0,
  2177. hd : 1,
  2178. wmode : 'transparent',
  2179. enablejsapi : 1,
  2180. html5 : 1
  2181. },
  2182. paramPlace : 8,
  2183. type : 'iframe',
  2184. url : '//www.youtube.com/embed/$4',
  2185. thumb : '//img.youtube.com/vi/$4/hqdefault.jpg'
  2186. },
  2187. vimeo : {
  2188. matcher : /^.+vimeo.com\/(.*\/)?([\d]+)(.*)?/,
  2189. params : {
  2190. autoplay : 1,
  2191. hd : 1,
  2192. show_title : 1,
  2193. show_byline : 1,
  2194. show_portrait : 0,
  2195. fullscreen : 1,
  2196. api : 1
  2197. },
  2198. paramPlace : 3,
  2199. type : 'iframe',
  2200. url : '//player.vimeo.com/video/$2'
  2201. },
  2202. metacafe : {
  2203. matcher : /metacafe.com\/watch\/(\d+)\/(.*)?/,
  2204. type : 'iframe',
  2205. url : '//www.metacafe.com/embed/$1/?ap=1'
  2206. },
  2207. dailymotion : {
  2208. matcher : /dailymotion.com\/video\/(.*)\/?(.*)/,
  2209. params : {
  2210. additionalInfos : 0,
  2211. autoStart : 1
  2212. },
  2213. type : 'iframe',
  2214. url : '//www.dailymotion.com/embed/video/$1'
  2215. },
  2216. vine : {
  2217. matcher : /vine.co\/v\/([a-zA-Z0-9\?\=\-]+)/,
  2218. type : 'iframe',
  2219. url : '//vine.co/v/$1/embed/simple'
  2220. },
  2221. instagram : {
  2222. matcher : /(instagr\.am|instagram\.com)\/p\/([a-zA-Z0-9_\-]+)\/?/i,
  2223. type : 'image',
  2224. url : '//$1/p/$2/media/?size=l'
  2225. },
  2226. // Examples:
  2227. // http://maps.google.com/?ll=48.857995,2.294297&spn=0.007666,0.021136&t=m&z=16
  2228. // https://www.google.com/maps/@37.7852006,-122.4146355,14.65z
  2229. // https://www.google.com/maps/place/Googleplex/@37.4220041,-122.0833494,17z/data=!4m5!3m4!1s0x0:0x6c296c66619367e0!8m2!3d37.4219998!4d-122.0840572
  2230. gmap_place : {
  2231. matcher : /(maps\.)?google\.([a-z]{2,3}(\.[a-z]{2})?)\/(((maps\/(place\/(.*)\/)?\@(.*),(\d+.?\d+?)z))|(\?ll=))(.*)?/i,
  2232. type : 'iframe',
  2233. url : function (rez) {
  2234. return '//maps.google.' + rez[2] + '/?ll=' + ( rez[9] ? rez[9] + '&z=' + Math.floor( rez[10] ) + ( rez[12] ? rez[12].replace(/^\//, "&") : '' ) : rez[12] ) + '&output=' + ( rez[12] && rez[12].indexOf('layer=c') > 0 ? 'svembed' : 'embed' );
  2235. }
  2236. },
  2237. // Examples:
  2238. // https://www.google.com/maps/search/Empire+State+Building/
  2239. // https://www.google.com/maps/search/?api=1&query=centurylink+field
  2240. // https://www.google.com/maps/search/?api=1&query=47.5951518,-122.3316393
  2241. gmap_search : {
  2242. matcher : /(maps\.)?google\.([a-z]{2,3}(\.[a-z]{2})?)\/(maps\/search\/)(.*)/i,
  2243. type : 'iframe',
  2244. url : function (rez) {
  2245. return '//maps.google.' + rez[2] + '/maps?q=' + rez[5].replace('query=', 'q=').replace('api=1', '') + '&output=embed';
  2246. }
  2247. }
  2248. };
  2249. $(document).on('objectNeedsType.fb', function (e, instance, item) {
  2250. var url = item.src || '',
  2251. type = false,
  2252. media,
  2253. thumb,
  2254. rez,
  2255. params,
  2256. urlParams,
  2257. paramObj,
  2258. provider;
  2259. media = $.extend( true, {}, defaults, item.opts.media );
  2260. // Look for any matching media type
  2261. $.each(media, function ( providerName, providerOpts ) {
  2262. rez = url.match( providerOpts.matcher );
  2263. if ( !rez ) {
  2264. return;
  2265. }
  2266. type = providerOpts.type;
  2267. paramObj = {};
  2268. if ( providerOpts.paramPlace && rez[ providerOpts.paramPlace ] ) {
  2269. urlParams = rez[ providerOpts.paramPlace ];
  2270. if ( urlParams[ 0 ] == '?' ) {
  2271. urlParams = urlParams.substring(1);
  2272. }
  2273. urlParams = urlParams.split('&');
  2274. for ( var m = 0; m < urlParams.length; ++m ) {
  2275. var p = urlParams[ m ].split('=', 2);
  2276. if ( p.length == 2 ) {
  2277. paramObj[ p[0] ] = decodeURIComponent( p[1].replace(/\+/g, " ") );
  2278. }
  2279. }
  2280. }
  2281. params = $.extend( true, {}, providerOpts.params, item.opts[ providerName ], paramObj );
  2282. url = $.type( providerOpts.url ) === "function" ? providerOpts.url.call( this, rez, params, item ) : format( providerOpts.url, rez, params );
  2283. thumb = $.type( providerOpts.thumb ) === "function" ? providerOpts.thumb.call( this, rez, params, item ) : format( providerOpts.thumb, rez );
  2284. if ( providerName === 'vimeo' ) {
  2285. url = url.replace('&%23', '#');
  2286. }
  2287. return false;
  2288. });
  2289. // If it is found, then change content type and update the url
  2290. if ( type ) {
  2291. item.src = url;
  2292. item.type = type;
  2293. if ( !item.opts.thumb && !( item.opts.$thumb && item.opts.$thumb.length ) ) {
  2294. item.opts.thumb = thumb;
  2295. }
  2296. if ( type === 'iframe' ) {
  2297. $.extend(true, item.opts, {
  2298. iframe : {
  2299. preload : false,
  2300. attr : {
  2301. scrolling : "no"
  2302. }
  2303. }
  2304. });
  2305. item.contentProvider = provider;
  2306. item.opts.slideClass += ' fancybox-slide--' + ( provider == 'gmap_place' || provider == 'gmap_search' ? 'map' : 'video' );
  2307. }
  2308. } else if ( url ) {
  2309. item.type = item.opts.defaultType;
  2310. }
  2311. });
  2312. }( window.jQuery || jQuery ));
  2313. // ==========================================================================
  2314. //
  2315. // Guestures
  2316. // Adds touch guestures, handles click and tap events
  2317. //
  2318. // ==========================================================================
  2319. ;(function (window, document, $) {
  2320. 'use strict';
  2321. var requestAFrame = (function () {
  2322. return window.requestAnimationFrame ||
  2323. window.webkitRequestAnimationFrame ||
  2324. window.mozRequestAnimationFrame ||
  2325. window.oRequestAnimationFrame ||
  2326. // if all else fails, use setTimeout
  2327. function (callback) {
  2328. return window.setTimeout(callback, 1000 / 60);
  2329. };
  2330. })();
  2331. var cancelAFrame = (function () {
  2332. return window.cancelAnimationFrame ||
  2333. window.webkitCancelAnimationFrame ||
  2334. window.mozCancelAnimationFrame ||
  2335. window.oCancelAnimationFrame ||
  2336. function (id) {
  2337. window.clearTimeout(id);
  2338. };
  2339. })();
  2340. var pointers = function( e ) {
  2341. var result = [];
  2342. e = e.originalEvent || e || window.e;
  2343. e = e.touches && e.touches.length ? e.touches : ( e.changedTouches && e.changedTouches.length ? e.changedTouches : [ e ] );
  2344. for ( var key in e ) {
  2345. if ( e[ key ].pageX ) {
  2346. result.push( { x : e[ key ].pageX, y : e[ key ].pageY } );
  2347. } else if ( e[ key ].clientX ) {
  2348. result.push( { x : e[ key ].clientX, y : e[ key ].clientY } );
  2349. }
  2350. }
  2351. return result;
  2352. };
  2353. var distance = function( point2, point1, what ) {
  2354. if ( !point1 || !point2 ) {
  2355. return 0;
  2356. }
  2357. if ( what === 'x' ) {
  2358. return point2.x - point1.x;
  2359. } else if ( what === 'y' ) {
  2360. return point2.y - point1.y;
  2361. }
  2362. return Math.sqrt( Math.pow( point2.x - point1.x, 2 ) + Math.pow( point2.y - point1.y, 2 ) );
  2363. };
  2364. var isClickable = function( $el ) {
  2365. if ( $el.is('a,area,button,[role="button"],input,label,select,summary,textarea') || $.isFunction( $el.get(0).onclick ) || $el.data('selectable') ) {
  2366. return true;
  2367. }
  2368. // Check for attributes like data-fancybox-next or data-fancybox-close
  2369. for ( var i = 0, atts = $el[0].attributes, n = atts.length; i < n; i++ ) {
  2370. if ( atts[i].nodeName.substr(0, 14) === 'data-fancybox-' ) {
  2371. return true;
  2372. }
  2373. }
  2374. return false;
  2375. };
  2376. var hasScrollbars = function( el ) {
  2377. var overflowY = window.getComputedStyle( el )['overflow-y'];
  2378. var overflowX = window.getComputedStyle( el )['overflow-x'];
  2379. var vertical = (overflowY === 'scroll' || overflowY === 'auto') && el.scrollHeight > el.clientHeight;
  2380. var horizontal = (overflowX === 'scroll' || overflowX === 'auto') && el.scrollWidth > el.clientWidth;
  2381. return vertical || horizontal;
  2382. };
  2383. var isScrollable = function ( $el ) {
  2384. var rez = false;
  2385. while ( true ) {
  2386. rez = hasScrollbars( $el.get(0) );
  2387. if ( rez ) {
  2388. break;
  2389. }
  2390. $el = $el.parent();
  2391. if ( !$el.length || $el.hasClass( 'fancybox-stage' ) || $el.is( 'body' ) ) {
  2392. break;
  2393. }
  2394. }
  2395. return rez;
  2396. };
  2397. var Guestures = function ( instance ) {
  2398. var self = this;
  2399. self.instance = instance;
  2400. self.$bg = instance.$refs.bg;
  2401. self.$stage = instance.$refs.stage;
  2402. self.$container = instance.$refs.container;
  2403. self.destroy();
  2404. self.$container.on( 'touchstart.fb.touch mousedown.fb.touch', $.proxy(self, 'ontouchstart') );
  2405. };
  2406. Guestures.prototype.destroy = function() {
  2407. this.$container.off( '.fb.touch' );
  2408. };
  2409. Guestures.prototype.ontouchstart = function( e ) {
  2410. var self = this;
  2411. var $target = $( e.target );
  2412. var instance = self.instance;
  2413. var current = instance.current;
  2414. var $content = current.$content;
  2415. var isTouchDevice = ( e.type == 'touchstart' );
  2416. // Do not respond to both (touch and mouse) events
  2417. if ( isTouchDevice ) {
  2418. self.$container.off( 'mousedown.fb.touch' );
  2419. }
  2420. // Ignore right click
  2421. if ( e.originalEvent && e.originalEvent.button == 2 ) {
  2422. return;
  2423. }
  2424. // Ignore taping on links, buttons, input elements
  2425. if ( !$target.length || isClickable( $target ) || isClickable( $target.parent() ) ) {
  2426. return;
  2427. }
  2428. // Ignore clicks on the scrollbar
  2429. if ( !$target.is('img') && e.originalEvent.clientX > $target[0].clientWidth + $target.offset().left ) {
  2430. return;
  2431. }
  2432. // Ignore clicks while zooming or closing
  2433. if ( !current || self.instance.isAnimating || self.instance.isClosing ) {
  2434. e.stopPropagation();
  2435. e.preventDefault();
  2436. return;
  2437. }
  2438. self.realPoints = self.startPoints = pointers( e );
  2439. if ( !self.startPoints ) {
  2440. return;
  2441. }
  2442. e.stopPropagation();
  2443. self.startEvent = e;
  2444. self.canTap = true;
  2445. self.$target = $target;
  2446. self.$content = $content;
  2447. self.opts = current.opts.touch;
  2448. self.isPanning = false;
  2449. self.isSwiping = false;
  2450. self.isZooming = false;
  2451. self.isScrolling = false;
  2452. self.sliderStartPos = self.sliderLastPos || { top: 0, left: 0 };
  2453. self.contentStartPos = $.fancybox.getTranslate( self.$content );
  2454. self.contentLastPos = null;
  2455. self.startTime = new Date().getTime();
  2456. self.distanceX = self.distanceY = self.distance = 0;
  2457. self.canvasWidth = Math.round( current.$slide[0].clientWidth );
  2458. self.canvasHeight = Math.round( current.$slide[0].clientHeight );
  2459. $(document)
  2460. .off( '.fb.touch' )
  2461. .on( isTouchDevice ? 'touchend.fb.touch touchcancel.fb.touch' : 'mouseup.fb.touch mouseleave.fb.touch', $.proxy(self, "ontouchend"))
  2462. .on( isTouchDevice ? 'touchmove.fb.touch' : 'mousemove.fb.touch', $.proxy(self, "ontouchmove"));
  2463. if ( $.fancybox.isMobile ) {
  2464. document.addEventListener('scroll', self.onscroll, true);
  2465. }
  2466. if ( !(self.opts || instance.canPan() ) || !( $target.is( self.$stage ) || self.$stage.find( $target ).length ) ) {
  2467. // Prevent image ghosting while dragging
  2468. if ( $target.is('img') ) {
  2469. e.preventDefault();
  2470. }
  2471. return;
  2472. }
  2473. if ( !( $.fancybox.isMobile && ( isScrollable( $target ) || isScrollable( $target.parent() ) ) ) ) {
  2474. e.preventDefault();
  2475. }
  2476. if ( self.startPoints.length === 1 ) {
  2477. if ( current.type === 'image' && ( self.contentStartPos.width > self.canvasWidth + 1 || self.contentStartPos.height > self.canvasHeight + 1 ) ) {
  2478. $.fancybox.stop( self.$content );
  2479. self.$content.css( 'transition-duration', '' );
  2480. self.isPanning = true;
  2481. } else {
  2482. self.isSwiping = true;
  2483. }
  2484. self.$container.addClass( 'fancybox-controls--isGrabbing' );
  2485. }
  2486. if ( self.startPoints.length === 2 && !instance.isAnimating && !current.hasError && current.type === 'image' && ( current.isLoaded || current.$ghost ) ) {
  2487. self.canTap = false;
  2488. self.isSwiping = false;
  2489. self.isPanning = false;
  2490. self.isZooming = true;
  2491. $.fancybox.stop( self.$content );
  2492. self.$content.css( 'transition-duration', '' );
  2493. self.centerPointStartX = ( ( self.startPoints[0].x + self.startPoints[1].x ) * 0.5 ) - $(window).scrollLeft();
  2494. self.centerPointStartY = ( ( self.startPoints[0].y + self.startPoints[1].y ) * 0.5 ) - $(window).scrollTop();
  2495. self.percentageOfImageAtPinchPointX = ( self.centerPointStartX - self.contentStartPos.left ) / self.contentStartPos.width;
  2496. self.percentageOfImageAtPinchPointY = ( self.centerPointStartY - self.contentStartPos.top ) / self.contentStartPos.height;
  2497. self.startDistanceBetweenFingers = distance( self.startPoints[0], self.startPoints[1] );
  2498. }
  2499. };
  2500. Guestures.prototype.onscroll = function(e) {
  2501. self.isScrolling = true;
  2502. };
  2503. Guestures.prototype.ontouchmove = function( e ) {
  2504. var self = this,
  2505. $target = $(e.target);
  2506. if ( self.isScrolling || !( $target.is( self.$stage ) || self.$stage.find( $target ).length ) ) {
  2507. self.canTap = false;
  2508. return;
  2509. }
  2510. self.newPoints = pointers( e );
  2511. if ( !( self.opts || self.instance.canPan() ) || !self.newPoints || !self.newPoints.length ) {
  2512. return;
  2513. }
  2514. if ( !(self.isSwiping && self.isSwiping === true) ) {
  2515. e.preventDefault();
  2516. }
  2517. self.distanceX = distance( self.newPoints[0], self.startPoints[0], 'x' );
  2518. self.distanceY = distance( self.newPoints[0], self.startPoints[0], 'y' );
  2519. self.distance = distance( self.newPoints[0], self.startPoints[0] )
  2520. // Skip false ontouchmove events (Chrome)
  2521. if ( self.distance > 0 ) {
  2522. if ( self.isSwiping ) {
  2523. self.onSwipe(e);
  2524. } else if ( self.isPanning ) {
  2525. self.onPan();
  2526. } else if ( self.isZooming ) {
  2527. self.onZoom();
  2528. }
  2529. }
  2530. };
  2531. Guestures.prototype.onSwipe = function(e) {
  2532. var self = this,
  2533. swiping = self.isSwiping,
  2534. left = self.sliderStartPos.left || 0,
  2535. angle;
  2536. // If direction is not yet determined
  2537. if ( swiping === true ) {
  2538. // We need at least 10px distance to correctly calculate an angle
  2539. if ( Math.abs( self.distance ) > 10 ) {
  2540. self.canTap = false;
  2541. if ( self.instance.group.length < 2 && self.opts.vertical ) {
  2542. self.isSwiping = 'y';
  2543. } else if ( self.instance.isDragging || self.opts.vertical === false || ( self.opts.vertical === 'auto' && $( window ).width() > 800 ) ) {
  2544. self.isSwiping = 'x';
  2545. } else {
  2546. angle = Math.abs( Math.atan2( self.distanceY, self.distanceX ) * 180 / Math.PI );
  2547. self.isSwiping = ( angle > 45 && angle < 135 ) ? 'y' : 'x';
  2548. }
  2549. self.canTap = false;
  2550. if ( self.isSwiping === 'y' && $.fancybox.isMobile && ( isScrollable( self.$target ) || isScrollable( self.$target.parent() ) ) ) {
  2551. self.isScrolling = true;
  2552. return;
  2553. }
  2554. self.instance.isDragging = self.isSwiping;
  2555. // Reset points to avoid jumping, because we dropped first swipes to calculate the angle
  2556. self.startPoints = self.newPoints;
  2557. $.each(self.instance.slides, function( index, slide ) {
  2558. $.fancybox.stop( slide.$slide );
  2559. slide.$slide.css( 'transition-duration', '' );
  2560. slide.inTransition = false;
  2561. if ( slide.pos === self.instance.current.pos ) {
  2562. self.sliderStartPos.left = $.fancybox.getTranslate( slide.$slide ).left;
  2563. }
  2564. });
  2565. // Stop slideshow
  2566. if ( self.instance.SlideShow && self.instance.SlideShow.isActive ) {
  2567. self.instance.SlideShow.stop();
  2568. }
  2569. }
  2570. return;
  2571. }
  2572. // Sticky edges
  2573. if ( swiping == 'x' ) {
  2574. if ( self.distanceX > 0 && ( self.instance.group.length < 2 || ( self.instance.current.index === 0 && !self.instance.current.opts.loop ) ) ) {
  2575. left = left + Math.pow( self.distanceX, 0.8 );
  2576. } else if ( self.distanceX < 0 && ( self.instance.group.length < 2 || ( self.instance.current.index === self.instance.group.length - 1 && !self.instance.current.opts.loop ) ) ) {
  2577. left = left - Math.pow( -self.distanceX, 0.8 );
  2578. } else {
  2579. left = left + self.distanceX;
  2580. }
  2581. }
  2582. self.sliderLastPos = {
  2583. top : swiping == 'x' ? 0 : self.sliderStartPos.top + self.distanceY,
  2584. left : left
  2585. };
  2586. if ( self.requestId ) {
  2587. cancelAFrame( self.requestId );
  2588. self.requestId = null;
  2589. }
  2590. self.requestId = requestAFrame(function() {
  2591. if ( self.sliderLastPos ) {
  2592. $.each(self.instance.slides, function( index, slide ) {
  2593. var pos = slide.pos - self.instance.currPos;
  2594. $.fancybox.setTranslate( slide.$slide, {
  2595. top : self.sliderLastPos.top,
  2596. left : self.sliderLastPos.left + ( pos * self.canvasWidth ) + ( pos * slide.opts.gutter )
  2597. });
  2598. });
  2599. self.$container.addClass( 'fancybox-is-sliding' );
  2600. }
  2601. });
  2602. };
  2603. Guestures.prototype.onPan = function() {
  2604. var self = this;
  2605. // Sometimes, when tapping causally, image can move a bit and that breaks double tapping
  2606. if ( distance( self.newPoints[0], self.realPoints[0] ) < ($.fancybox.isMobile ? 10 : 5) ) {
  2607. self.startPoints = self.newPoints;
  2608. return;
  2609. }
  2610. self.canTap = false;
  2611. self.contentLastPos = self.limitMovement();
  2612. if ( self.requestId ) {
  2613. cancelAFrame( self.requestId );
  2614. self.requestId = null;
  2615. }
  2616. self.requestId = requestAFrame(function() {
  2617. $.fancybox.setTranslate( self.$content, self.contentLastPos );
  2618. });
  2619. };
  2620. // Make panning sticky to the edges
  2621. Guestures.prototype.limitMovement = function() {
  2622. var self = this;
  2623. var canvasWidth = self.canvasWidth;
  2624. var canvasHeight = self.canvasHeight;
  2625. var distanceX = self.distanceX;
  2626. var distanceY = self.distanceY;
  2627. var contentStartPos = self.contentStartPos;
  2628. var currentOffsetX = contentStartPos.left;
  2629. var currentOffsetY = contentStartPos.top;
  2630. var currentWidth = contentStartPos.width;
  2631. var currentHeight = contentStartPos.height;
  2632. var minTranslateX, minTranslateY,
  2633. maxTranslateX, maxTranslateY,
  2634. newOffsetX, newOffsetY;
  2635. if ( currentWidth > canvasWidth ) {
  2636. newOffsetX = currentOffsetX + distanceX;
  2637. } else {
  2638. newOffsetX = currentOffsetX;
  2639. }
  2640. newOffsetY = currentOffsetY + distanceY;
  2641. // Slow down proportionally to traveled distance
  2642. minTranslateX = Math.max( 0, canvasWidth * 0.5 - currentWidth * 0.5 );
  2643. minTranslateY = Math.max( 0, canvasHeight * 0.5 - currentHeight * 0.5 );
  2644. maxTranslateX = Math.min( canvasWidth - currentWidth, canvasWidth * 0.5 - currentWidth * 0.5 );
  2645. maxTranslateY = Math.min( canvasHeight - currentHeight, canvasHeight * 0.5 - currentHeight * 0.5 );
  2646. if ( currentWidth > canvasWidth ) {
  2647. // ->
  2648. if ( distanceX > 0 && newOffsetX > minTranslateX ) {
  2649. newOffsetX = minTranslateX - 1 + Math.pow( -minTranslateX + currentOffsetX + distanceX, 0.8 ) || 0;
  2650. }
  2651. // <-
  2652. if ( distanceX < 0 && newOffsetX < maxTranslateX ) {
  2653. newOffsetX = maxTranslateX + 1 - Math.pow( maxTranslateX - currentOffsetX - distanceX, 0.8 ) || 0;
  2654. }
  2655. }
  2656. if ( currentHeight > canvasHeight ) {
  2657. // \/
  2658. if ( distanceY > 0 && newOffsetY > minTranslateY ) {
  2659. newOffsetY = minTranslateY - 1 + Math.pow(-minTranslateY + currentOffsetY + distanceY, 0.8 ) || 0;
  2660. }
  2661. // /\
  2662. if ( distanceY < 0 && newOffsetY < maxTranslateY ) {
  2663. newOffsetY = maxTranslateY + 1 - Math.pow ( maxTranslateY - currentOffsetY - distanceY, 0.8 ) || 0;
  2664. }
  2665. }
  2666. return {
  2667. top : newOffsetY,
  2668. left : newOffsetX,
  2669. scaleX : contentStartPos.scaleX,
  2670. scaleY : contentStartPos.scaleY
  2671. };
  2672. };
  2673. Guestures.prototype.limitPosition = function( newOffsetX, newOffsetY, newWidth, newHeight ) {
  2674. var self = this;
  2675. var canvasWidth = self.canvasWidth;
  2676. var canvasHeight = self.canvasHeight;
  2677. if ( newWidth > canvasWidth ) {
  2678. newOffsetX = newOffsetX > 0 ? 0 : newOffsetX;
  2679. newOffsetX = newOffsetX < canvasWidth - newWidth ? canvasWidth - newWidth : newOffsetX;
  2680. } else {
  2681. // Center horizontally
  2682. newOffsetX = Math.max( 0, canvasWidth / 2 - newWidth / 2 );
  2683. }
  2684. if ( newHeight > canvasHeight ) {
  2685. newOffsetY = newOffsetY > 0 ? 0 : newOffsetY;
  2686. newOffsetY = newOffsetY < canvasHeight - newHeight ? canvasHeight - newHeight : newOffsetY;
  2687. } else {
  2688. // Center vertically
  2689. newOffsetY = Math.max( 0, canvasHeight / 2 - newHeight / 2 );
  2690. }
  2691. return {
  2692. top : newOffsetY,
  2693. left : newOffsetX
  2694. };
  2695. };
  2696. Guestures.prototype.onZoom = function() {
  2697. var self = this;
  2698. // Calculate current distance between points to get pinch ratio and new width and height
  2699. var currentWidth = self.contentStartPos.width;
  2700. var currentHeight = self.contentStartPos.height;
  2701. var currentOffsetX = self.contentStartPos.left;
  2702. var currentOffsetY = self.contentStartPos.top;
  2703. var endDistanceBetweenFingers = distance( self.newPoints[0], self.newPoints[1] );
  2704. var pinchRatio = endDistanceBetweenFingers / self.startDistanceBetweenFingers;
  2705. var newWidth = Math.floor( currentWidth * pinchRatio );
  2706. var newHeight = Math.floor( currentHeight * pinchRatio );
  2707. // This is the translation due to pinch-zooming
  2708. var translateFromZoomingX = (currentWidth - newWidth) * self.percentageOfImageAtPinchPointX;
  2709. var translateFromZoomingY = (currentHeight - newHeight) * self.percentageOfImageAtPinchPointY;
  2710. //Point between the two touches
  2711. var centerPointEndX = ((self.newPoints[0].x + self.newPoints[1].x) / 2) - $(window).scrollLeft();
  2712. var centerPointEndY = ((self.newPoints[0].y + self.newPoints[1].y) / 2) - $(window).scrollTop();
  2713. // And this is the translation due to translation of the centerpoint
  2714. // between the two fingers
  2715. var translateFromTranslatingX = centerPointEndX - self.centerPointStartX;
  2716. var translateFromTranslatingY = centerPointEndY - self.centerPointStartY;
  2717. // The new offset is the old/current one plus the total translation
  2718. var newOffsetX = currentOffsetX + ( translateFromZoomingX + translateFromTranslatingX );
  2719. var newOffsetY = currentOffsetY + ( translateFromZoomingY + translateFromTranslatingY );
  2720. var newPos = {
  2721. top : newOffsetY,
  2722. left : newOffsetX,
  2723. scaleX : self.contentStartPos.scaleX * pinchRatio,
  2724. scaleY : self.contentStartPos.scaleY * pinchRatio
  2725. };
  2726. self.canTap = false;
  2727. self.newWidth = newWidth;
  2728. self.newHeight = newHeight;
  2729. self.contentLastPos = newPos;
  2730. if ( self.requestId ) {
  2731. cancelAFrame( self.requestId );
  2732. self.requestId = null;
  2733. }
  2734. self.requestId = requestAFrame(function() {
  2735. $.fancybox.setTranslate( self.$content, self.contentLastPos );
  2736. });
  2737. };
  2738. Guestures.prototype.ontouchend = function( e ) {
  2739. var self = this;
  2740. var dMs = Math.max( (new Date().getTime() ) - self.startTime, 1);
  2741. var swiping = self.isSwiping;
  2742. var panning = self.isPanning;
  2743. var zooming = self.isZooming;
  2744. var scrolling = self.isScrolling;
  2745. self.endPoints = pointers( e );
  2746. self.$container.removeClass( 'fancybox-controls--isGrabbing' );
  2747. $(document).off( '.fb.touch' );
  2748. document.removeEventListener('scroll', self.onscroll, true);
  2749. if ( self.requestId ) {
  2750. cancelAFrame( self.requestId );
  2751. self.requestId = null;
  2752. }
  2753. self.isSwiping = false;
  2754. self.isPanning = false;
  2755. self.isZooming = false;
  2756. self.isScrolling = false;
  2757. self.instance.isDragging = false;
  2758. if ( self.canTap ) {
  2759. return self.onTap( e );
  2760. }
  2761. self.speed = 366;
  2762. // Speed in px/ms
  2763. self.velocityX = self.distanceX / dMs * 0.5;
  2764. self.velocityY = self.distanceY / dMs * 0.5;
  2765. self.speedX = Math.max( self.speed * 0.5, Math.min( self.speed * 1.5, ( 1 / Math.abs( self.velocityX ) ) * self.speed ) );
  2766. if ( panning ) {
  2767. self.endPanning();
  2768. } else if ( zooming ) {
  2769. self.endZooming();
  2770. } else {
  2771. self.endSwiping( swiping, scrolling );
  2772. }
  2773. return;
  2774. };
  2775. Guestures.prototype.endSwiping = function( swiping, scrolling ) {
  2776. var self = this,
  2777. ret = false,
  2778. len = self.instance.group.length;
  2779. self.sliderLastPos = null;
  2780. // Close if swiped vertically / navigate if horizontally
  2781. if ( swiping == 'y' && !scrolling && Math.abs( self.distanceY ) > 50 ) {
  2782. // Continue vertical movement
  2783. $.fancybox.animate( self.instance.current.$slide, {
  2784. top : self.sliderStartPos.top + self.distanceY + ( self.velocityY * 150 ),
  2785. opacity : 0
  2786. }, 150 );
  2787. ret = self.instance.close( true, 300 );
  2788. } else if ( swiping == 'x' && self.distanceX > 50 && len > 1 ) {
  2789. ret = self.instance.previous( self.speedX );
  2790. } else if ( swiping == 'x' && self.distanceX < -50 && len > 1 ) {
  2791. ret = self.instance.next( self.speedX );
  2792. }
  2793. if ( ret === false && ( swiping == 'x' || swiping == 'y' ) ) {
  2794. if ( scrolling || len < 2 ) {
  2795. self.instance.centerSlide( self.instance.current, 150 );
  2796. } else {
  2797. self.instance.jumpTo( self.instance.current.index );
  2798. }
  2799. }
  2800. self.$container.removeClass( 'fancybox-is-sliding' );
  2801. };
  2802. // Limit panning from edges
  2803. // ========================
  2804. Guestures.prototype.endPanning = function() {
  2805. var self = this;
  2806. var newOffsetX, newOffsetY, newPos;
  2807. if ( !self.contentLastPos ) {
  2808. return;
  2809. }
  2810. if ( self.opts.momentum === false ) {
  2811. newOffsetX = self.contentLastPos.left;
  2812. newOffsetY = self.contentLastPos.top;
  2813. } else {
  2814. // Continue movement
  2815. newOffsetX = self.contentLastPos.left + ( self.velocityX * self.speed );
  2816. newOffsetY = self.contentLastPos.top + ( self.velocityY * self.speed );
  2817. }
  2818. newPos = self.limitPosition( newOffsetX, newOffsetY, self.contentStartPos.width, self.contentStartPos.height );
  2819. newPos.width = self.contentStartPos.width;
  2820. newPos.height = self.contentStartPos.height;
  2821. $.fancybox.animate( self.$content, newPos, 330 );
  2822. };
  2823. Guestures.prototype.endZooming = function() {
  2824. var self = this;
  2825. var current = self.instance.current;
  2826. var newOffsetX, newOffsetY, newPos, reset;
  2827. var newWidth = self.newWidth;
  2828. var newHeight = self.newHeight;
  2829. if ( !self.contentLastPos ) {
  2830. return;
  2831. }
  2832. newOffsetX = self.contentLastPos.left;
  2833. newOffsetY = self.contentLastPos.top;
  2834. reset = {
  2835. top : newOffsetY,
  2836. left : newOffsetX,
  2837. width : newWidth,
  2838. height : newHeight,
  2839. scaleX : 1,
  2840. scaleY : 1
  2841. };
  2842. // Reset scalex/scaleY values; this helps for perfomance and does not break animation
  2843. $.fancybox.setTranslate( self.$content, reset );
  2844. if ( newWidth < self.canvasWidth && newHeight < self.canvasHeight ) {
  2845. self.instance.scaleToFit( 150 );
  2846. } else if ( newWidth > current.width || newHeight > current.height ) {
  2847. self.instance.scaleToActual( self.centerPointStartX, self.centerPointStartY, 150 );
  2848. } else {
  2849. newPos = self.limitPosition( newOffsetX, newOffsetY, newWidth, newHeight );
  2850. // Switch from scale() to width/height or animation will not work correctly
  2851. $.fancybox.setTranslate( self.content, $.fancybox.getTranslate( self.$content ) );
  2852. $.fancybox.animate( self.$content, newPos, 150 );
  2853. }
  2854. };
  2855. Guestures.prototype.onTap = function(e) {
  2856. var self = this;
  2857. var $target = $( e.target );
  2858. var instance = self.instance;
  2859. var current = instance.current;
  2860. var endPoints = ( e && pointers( e ) ) || self.startPoints;
  2861. var tapX = endPoints[0] ? endPoints[0].x - self.$stage.offset().left : 0;
  2862. var tapY = endPoints[0] ? endPoints[0].y - self.$stage.offset().top : 0;
  2863. var where;
  2864. var process = function ( prefix ) {
  2865. var action = current.opts[ prefix ];
  2866. if ( $.isFunction( action ) ) {
  2867. action = action.apply( instance, [ current, e ] );
  2868. }
  2869. if ( !action) {
  2870. return;
  2871. }
  2872. switch ( action ) {
  2873. case "close" :
  2874. instance.close( self.startEvent );
  2875. break;
  2876. case "toggleControls" :
  2877. instance.toggleControls( true );
  2878. break;
  2879. case "next" :
  2880. instance.next();
  2881. break;
  2882. case "nextOrClose" :
  2883. if ( instance.group.length > 1 ) {
  2884. instance.next();
  2885. } else {
  2886. instance.close( self.startEvent );
  2887. }
  2888. break;
  2889. case "zoom" :
  2890. if ( current.type == 'image' && ( current.isLoaded || current.$ghost ) ) {
  2891. if ( instance.canPan() ) {
  2892. instance.scaleToFit();
  2893. } else if ( instance.isScaledDown() ) {
  2894. instance.scaleToActual( tapX, tapY );
  2895. } else if ( instance.group.length < 2 ) {
  2896. instance.close( self.startEvent );
  2897. }
  2898. }
  2899. break;
  2900. }
  2901. };
  2902. // Ignore right click
  2903. if ( e.originalEvent && e.originalEvent.button == 2 ) {
  2904. return;
  2905. }
  2906. // Skip if clicked on the scrollbar
  2907. if ( !$target.is('img') && tapX > $target[0].clientWidth + $target.offset().left ) {
  2908. return;
  2909. }
  2910. // Check where is clicked
  2911. if ( $target.is( '.fancybox-bg,.fancybox-inner,.fancybox-outer,.fancybox-container' ) ) {
  2912. where = 'Outside';
  2913. } else if ( $target.is( '.fancybox-slide' ) ) {
  2914. where = 'Slide';
  2915. } else if ( instance.current.$content && instance.current.$content.find( $target ).addBack().filter( $target ).length ) {
  2916. where = 'Content';
  2917. } else {
  2918. return;
  2919. }
  2920. // Check if this is a double tap
  2921. if ( self.tapped ) {
  2922. // Stop previously created single tap
  2923. clearTimeout( self.tapped );
  2924. self.tapped = null;
  2925. // Skip if distance between taps is too big
  2926. if ( Math.abs( tapX - self.tapX ) > 50 || Math.abs( tapY - self.tapY ) > 50 ) {
  2927. return this;
  2928. }
  2929. // OK, now we assume that this is a double-tap
  2930. process( 'dblclick' + where );
  2931. } else {
  2932. // Single tap will be processed if user has not clicked second time within 300ms
  2933. // or there is no need to wait for double-tap
  2934. self.tapX = tapX;
  2935. self.tapY = tapY;
  2936. if ( current.opts[ 'dblclick' + where ] && current.opts[ 'dblclick' + where ] !== current.opts[ 'click' + where ] ) {
  2937. self.tapped = setTimeout(function() {
  2938. self.tapped = null;
  2939. process( 'click' + where );
  2940. }, 500);
  2941. } else {
  2942. process( 'click' + where );
  2943. }
  2944. }
  2945. return this;
  2946. };
  2947. $(document).on('onActivate.fb', function (e, instance) {
  2948. if ( instance && !instance.Guestures ) {
  2949. instance.Guestures = new Guestures( instance );
  2950. }
  2951. });
  2952. }( window, document, window.jQuery || jQuery ));
  2953. // ==========================================================================
  2954. //
  2955. // SlideShow
  2956. // Enables slideshow functionality
  2957. //
  2958. // Example of usage:
  2959. // $.fancybox.getInstance().SlideShow.start()
  2960. //
  2961. // ==========================================================================
  2962. ;(function (document, $) {
  2963. 'use strict';
  2964. $.extend(true, $.fancybox.defaults, {
  2965. btnTpl : {
  2966. slideShow :
  2967. '<button data-fancybox-play class="fancybox-button fancybox-button--play" title="{{PLAY_START}}">' +
  2968. '<svg viewBox="0 0 40 40">' +
  2969. '<path d="M13,12 L27,20 L13,27 Z" />' +
  2970. '<path d="M15,10 v19 M23,10 v19" />' +
  2971. '</svg>' +
  2972. '</button>'
  2973. },
  2974. slideShow : {
  2975. autoStart : false,
  2976. speed : 3000
  2977. }
  2978. });
  2979. var SlideShow = function( instance ) {
  2980. this.instance = instance;
  2981. this.init();
  2982. };
  2983. $.extend( SlideShow.prototype, {
  2984. timer : null,
  2985. isActive : false,
  2986. $button : null,
  2987. init : function() {
  2988. var self = this;
  2989. self.$button = self.instance.$refs.toolbar.find('[data-fancybox-play]').on('click', function() {
  2990. self.toggle();
  2991. });
  2992. if ( self.instance.group.length < 2 || !self.instance.group[ self.instance.currIndex ].opts.slideShow ) {
  2993. self.$button.hide();
  2994. }
  2995. },
  2996. set : function( force ) {
  2997. var self = this;
  2998. // Check if reached last element
  2999. if ( self.instance && self.instance.current && (force === true || self.instance.current.opts.loop || self.instance.currIndex < self.instance.group.length - 1 )) {
  3000. self.timer = setTimeout(function() {
  3001. if ( self.isActive ) {
  3002. self.instance.jumpTo( (self.instance.currIndex + 1) % self.instance.group.length );
  3003. }
  3004. }, self.instance.current.opts.slideShow.speed);
  3005. } else {
  3006. self.stop();
  3007. self.instance.idleSecondsCounter = 0;
  3008. self.instance.showControls();
  3009. }
  3010. },
  3011. clear : function() {
  3012. var self = this;
  3013. clearTimeout( self.timer );
  3014. self.timer = null;
  3015. },
  3016. start : function() {
  3017. var self = this;
  3018. var current = self.instance.current;
  3019. if ( current ) {
  3020. self.isActive = true;
  3021. self.$button
  3022. .attr( 'title', current.opts.i18n[ current.opts.lang ].PLAY_STOP )
  3023. .removeClass( 'fancybox-button--play' )
  3024. .addClass( 'fancybox-button--pause' );
  3025. self.set( true );
  3026. }
  3027. },
  3028. stop : function() {
  3029. var self = this;
  3030. var current = self.instance.current;
  3031. self.clear();
  3032. self.$button
  3033. .attr( 'title', current.opts.i18n[ current.opts.lang ].PLAY_START )
  3034. .removeClass( 'fancybox-button--pause' )
  3035. .addClass( 'fancybox-button--play' );
  3036. self.isActive = false;
  3037. },
  3038. toggle : function() {
  3039. var self = this;
  3040. if ( self.isActive ) {
  3041. self.stop();
  3042. } else {
  3043. self.start();
  3044. }
  3045. }
  3046. });
  3047. $(document).on({
  3048. 'onInit.fb' : function(e, instance) {
  3049. if ( instance && !instance.SlideShow ) {
  3050. instance.SlideShow = new SlideShow( instance );
  3051. }
  3052. },
  3053. 'beforeShow.fb' : function(e, instance, current, firstRun) {
  3054. var SlideShow = instance && instance.SlideShow;
  3055. if ( firstRun ) {
  3056. if ( SlideShow && current.opts.slideShow.autoStart ) {
  3057. SlideShow.start();
  3058. }
  3059. } else if ( SlideShow && SlideShow.isActive ) {
  3060. SlideShow.clear();
  3061. }
  3062. },
  3063. 'afterShow.fb' : function(e, instance, current) {
  3064. var SlideShow = instance && instance.SlideShow;
  3065. if ( SlideShow && SlideShow.isActive ) {
  3066. SlideShow.set();
  3067. }
  3068. },
  3069. 'afterKeydown.fb' : function(e, instance, current, keypress, keycode) {
  3070. var SlideShow = instance && instance.SlideShow;
  3071. // "P" or Spacebar
  3072. if ( SlideShow && current.opts.slideShow && ( keycode === 80 || keycode === 32 ) && !$(document.activeElement).is( 'button,a,input' ) ) {
  3073. keypress.preventDefault();
  3074. SlideShow.toggle();
  3075. }
  3076. },
  3077. 'beforeClose.fb onDeactivate.fb' : function(e, instance) {
  3078. var SlideShow = instance && instance.SlideShow;
  3079. if ( SlideShow ) {
  3080. SlideShow.stop();
  3081. }
  3082. }
  3083. });
  3084. // Page Visibility API to pause slideshow when window is not active
  3085. $(document).on("visibilitychange", function() {
  3086. var instance = $.fancybox.getInstance();
  3087. var SlideShow = instance && instance.SlideShow;
  3088. if ( SlideShow && SlideShow.isActive ) {
  3089. if ( document.hidden ) {
  3090. SlideShow.clear();
  3091. } else {
  3092. SlideShow.set();
  3093. }
  3094. }
  3095. });
  3096. }( document, window.jQuery || jQuery ));
  3097. // ==========================================================================
  3098. //
  3099. // FullScreen
  3100. // Adds fullscreen functionality
  3101. //
  3102. // ==========================================================================
  3103. ;(function (document, $) {
  3104. 'use strict';
  3105. // Collection of methods supported by user browser
  3106. var fn = (function () {
  3107. var fnMap = [
  3108. [
  3109. 'requestFullscreen',
  3110. 'exitFullscreen',
  3111. 'fullscreenElement',
  3112. 'fullscreenEnabled',
  3113. 'fullscreenchange',
  3114. 'fullscreenerror'
  3115. ],
  3116. // new WebKit
  3117. [
  3118. 'webkitRequestFullscreen',
  3119. 'webkitExitFullscreen',
  3120. 'webkitFullscreenElement',
  3121. 'webkitFullscreenEnabled',
  3122. 'webkitfullscreenchange',
  3123. 'webkitfullscreenerror'
  3124. ],
  3125. // old WebKit (Safari 5.1)
  3126. [
  3127. 'webkitRequestFullScreen',
  3128. 'webkitCancelFullScreen',
  3129. 'webkitCurrentFullScreenElement',
  3130. 'webkitCancelFullScreen',
  3131. 'webkitfullscreenchange',
  3132. 'webkitfullscreenerror'
  3133. ],
  3134. [
  3135. 'mozRequestFullScreen',
  3136. 'mozCancelFullScreen',
  3137. 'mozFullScreenElement',
  3138. 'mozFullScreenEnabled',
  3139. 'mozfullscreenchange',
  3140. 'mozfullscreenerror'
  3141. ],
  3142. [
  3143. 'msRequestFullscreen',
  3144. 'msExitFullscreen',
  3145. 'msFullscreenElement',
  3146. 'msFullscreenEnabled',
  3147. 'MSFullscreenChange',
  3148. 'MSFullscreenError'
  3149. ]
  3150. ];
  3151. var val;
  3152. var ret = {};
  3153. var i, j;
  3154. for ( i = 0; i < fnMap.length; i++ ) {
  3155. val = fnMap[ i ];
  3156. if ( val && val[ 1 ] in document ) {
  3157. for ( j = 0; j < val.length; j++ ) {
  3158. ret[ fnMap[ 0 ][ j ] ] = val[ j ];
  3159. }
  3160. return ret;
  3161. }
  3162. }
  3163. return false;
  3164. })();
  3165. // If browser does not have Full Screen API, then simply unset default button template and stop
  3166. if ( !fn ) {
  3167. if ( $ && $.fancybox ) {
  3168. $.fancybox.defaults.btnTpl.fullScreen = false;
  3169. }
  3170. return;
  3171. }
  3172. var FullScreen = {
  3173. request : function ( elem ) {
  3174. elem = elem || document.documentElement;
  3175. elem[ fn.requestFullscreen ]( elem.ALLOW_KEYBOARD_INPUT );
  3176. },
  3177. exit : function () {
  3178. document[ fn.exitFullscreen ]();
  3179. },
  3180. toggle : function ( elem ) {
  3181. elem = elem || document.documentElement;
  3182. if ( this.isFullscreen() ) {
  3183. this.exit();
  3184. } else {
  3185. this.request( elem );
  3186. }
  3187. },
  3188. isFullscreen : function() {
  3189. return Boolean( document[ fn.fullscreenElement ] );
  3190. },
  3191. enabled : function() {
  3192. return Boolean( document[ fn.fullscreenEnabled ] );
  3193. }
  3194. };
  3195. $.extend(true, $.fancybox.defaults, {
  3196. btnTpl : {
  3197. fullScreen :
  3198. '<button data-fancybox-fullscreen class="fancybox-button fancybox-button--fullscreen" title="{{FULL_SCREEN}}">' +
  3199. '<svg viewBox="0 0 40 40">' +
  3200. '<path d="M9,12 h22 v16 h-22 v-16 v16 h22 v-16 Z" />' +
  3201. '</svg>' +
  3202. '</button>'
  3203. },
  3204. fullScreen : {
  3205. autoStart : false
  3206. }
  3207. });
  3208. $(document).on({
  3209. 'onInit.fb' : function(e, instance) {
  3210. var $container;
  3211. if ( instance && instance.group[ instance.currIndex ].opts.fullScreen ) {
  3212. $container = instance.$refs.container;
  3213. $container.on('click.fb-fullscreen', '[data-fancybox-fullscreen]', function(e) {
  3214. e.stopPropagation();
  3215. e.preventDefault();
  3216. FullScreen.toggle( $container[ 0 ] );
  3217. });
  3218. if ( instance.opts.fullScreen && instance.opts.fullScreen.autoStart === true ) {
  3219. FullScreen.request( $container[ 0 ] );
  3220. }
  3221. // Expose API
  3222. instance.FullScreen = FullScreen;
  3223. } else if ( instance ) {
  3224. instance.$refs.toolbar.find('[data-fancybox-fullscreen]').hide();
  3225. }
  3226. },
  3227. 'afterKeydown.fb' : function(e, instance, current, keypress, keycode) {
  3228. // "P" or Spacebar
  3229. if ( instance && instance.FullScreen && keycode === 70 ) {
  3230. keypress.preventDefault();
  3231. instance.FullScreen.toggle( instance.$refs.container[ 0 ] );
  3232. }
  3233. },
  3234. 'beforeClose.fb' : function( instance ) {
  3235. if ( instance && instance.FullScreen ) {
  3236. FullScreen.exit();
  3237. }
  3238. }
  3239. });
  3240. $(document).on(fn.fullscreenchange, function() {
  3241. var isFullscreen = FullScreen.isFullscreen(),
  3242. instance = $.fancybox.getInstance();
  3243. if ( instance ) {
  3244. // If image is zooming, then force to stop and reposition properly
  3245. if ( instance.current && instance.current.type === 'image' && instance.isAnimating ) {
  3246. instance.current.$content.css( 'transition', 'none' );
  3247. instance.isAnimating = false;
  3248. instance.update( true, true, 0 );
  3249. }
  3250. instance.trigger( 'onFullscreenChange', isFullscreen );
  3251. instance.$refs.container.toggleClass( 'fancybox-is-fullscreen', isFullscreen );
  3252. }
  3253. });
  3254. }( document, window.jQuery || jQuery ));
  3255. // ==========================================================================
  3256. //
  3257. // Thumbs
  3258. // Displays thumbnails in a grid
  3259. //
  3260. // ==========================================================================
  3261. ;(function (document, $) {
  3262. 'use strict';
  3263. // Make sure there are default values
  3264. $.fancybox.defaults = $.extend(true, {
  3265. btnTpl : {
  3266. thumbs :
  3267. '<button data-fancybox-thumbs class="fancybox-button fancybox-button--thumbs" title="{{THUMBS}}">' +
  3268. '<svg viewBox="0 0 120 120">' +
  3269. '<path d="M30,30 h14 v14 h-14 Z M50,30 h14 v14 h-14 Z M70,30 h14 v14 h-14 Z M30,50 h14 v14 h-14 Z M50,50 h14 v14 h-14 Z M70,50 h14 v14 h-14 Z M30,70 h14 v14 h-14 Z M50,70 h14 v14 h-14 Z M70,70 h14 v14 h-14 Z" />' +
  3270. '</svg>' +
  3271. '</button>'
  3272. },
  3273. thumbs : {
  3274. autoStart : false, // Display thumbnails on opening
  3275. hideOnClose : true, // Hide thumbnail grid when closing animation starts
  3276. parentEl : '.fancybox-container', // Container is injected into this element
  3277. axis : 'y' // Vertical (y) or horizontal (x) scrolling
  3278. }
  3279. }, $.fancybox.defaults);
  3280. var FancyThumbs = function( instance ) {
  3281. this.init( instance );
  3282. };
  3283. $.extend( FancyThumbs.prototype, {
  3284. $button : null,
  3285. $grid : null,
  3286. $list : null,
  3287. isVisible : false,
  3288. isActive : false,
  3289. init : function( instance ) {
  3290. var self = this;
  3291. self.instance = instance;
  3292. instance.Thumbs = self;
  3293. // Enable thumbs if at least two group items have thumbnails
  3294. var first = instance.group[0],
  3295. second = instance.group[1];
  3296. self.opts = instance.group[ instance.currIndex ].opts.thumbs;
  3297. self.$button = instance.$refs.toolbar.find( '[data-fancybox-thumbs]' );
  3298. if ( self.opts && first && second && (
  3299. ( first.type == 'image' || first.opts.thumb || first.opts.$thumb ) &&
  3300. ( second.type == 'image' || second.opts.thumb || second.opts.$thumb )
  3301. )) {
  3302. self.$button.show().on('click', function() {
  3303. self.toggle();
  3304. });
  3305. self.isActive = true;
  3306. } else {
  3307. self.$button.hide();
  3308. }
  3309. },
  3310. create : function() {
  3311. var self = this,
  3312. instance = self.instance,
  3313. parentEl = self.opts.parentEl,
  3314. list,
  3315. src;
  3316. self.$grid = $('<div class="fancybox-thumbs fancybox-thumbs-' + self.opts.axis + '"></div>').appendTo( instance.$refs.container.find( parentEl ).addBack().filter( parentEl ) );
  3317. // Build list HTML
  3318. list = '<ul>';
  3319. $.each(instance.group, function( i, item ) {
  3320. src = item.opts.thumb || ( item.opts.$thumb ? item.opts.$thumb.attr( 'src' ) : null );
  3321. if ( !src && item.type === 'image' ) {
  3322. src = item.src;
  3323. }
  3324. if ( src && src.length ) {
  3325. list += '<li data-index="' + i + '" tabindex="0" class="fancybox-thumbs-loading"><img data-src="' + src + '" /></li>';
  3326. }
  3327. });
  3328. list += '</ul>';
  3329. self.$list = $( list ).appendTo( self.$grid ).on('click', 'li', function() {
  3330. instance.jumpTo( $(this).data('index') );
  3331. });
  3332. self.$list.find( 'img' ).hide().one('load', function() {
  3333. var $parent = $(this).parent().removeClass( 'fancybox-thumbs-loading' ),
  3334. thumbWidth = $parent.outerWidth(),
  3335. thumbHeight = $parent.outerHeight(),
  3336. width,
  3337. height,
  3338. widthRatio,
  3339. heightRatio;
  3340. width = this.naturalWidth || this.width;
  3341. height = this.naturalHeight || this.height;
  3342. // Calculate thumbnail dimensions; center vertically and horizontally
  3343. widthRatio = width / thumbWidth;
  3344. heightRatio = height / thumbHeight;
  3345. if (widthRatio >= 1 && heightRatio >= 1) {
  3346. if (widthRatio > heightRatio) {
  3347. width = width / heightRatio;
  3348. height = thumbHeight;
  3349. } else {
  3350. width = thumbWidth;
  3351. height = height / widthRatio;
  3352. }
  3353. }
  3354. $(this).css({
  3355. width : Math.floor(width),
  3356. height : Math.floor(height),
  3357. 'margin-top' : height > thumbHeight ? ( Math.floor(thumbHeight * 0.3 - height * 0.3 ) ) : Math.floor(thumbHeight * 0.5 - height * 0.5 ),
  3358. 'margin-left' : Math.floor(thumbWidth * 0.5 - width * 0.5 )
  3359. }).show();
  3360. })
  3361. .each(function() {
  3362. this.src = $( this ).data( 'src' );
  3363. });
  3364. if ( self.opts.axis === 'x' ) {
  3365. self.$list.width( parseInt( self.$grid.css("padding-right") ) + ( instance.group.length * self.$list.children().eq(0).outerWidth(true) ) + 'px' );
  3366. }
  3367. },
  3368. focus : function( duration ) {
  3369. var self = this,
  3370. $list = self.$list,
  3371. thumb,
  3372. thumbPos;
  3373. if ( self.instance.current ) {
  3374. thumb = $list.children()
  3375. .removeClass( 'fancybox-thumbs-active' )
  3376. .filter('[data-index="' + self.instance.current.index + '"]')
  3377. .addClass('fancybox-thumbs-active');
  3378. thumbPos = thumb.position();
  3379. // Check if need to scroll to make current thumb visible
  3380. if ( self.opts.axis === 'y' && ( thumbPos.top < 0 || thumbPos.top > ( $list.height() - thumb.outerHeight() ) ) ) {
  3381. $list.stop().animate({ 'scrollTop' : $list.scrollTop() + thumbPos.top }, duration);
  3382. } else if ( self.opts.axis === 'x' && (
  3383. thumbPos.left < $list.parent().scrollLeft() ||
  3384. thumbPos.left > ( $list.parent().scrollLeft() + ( $list.parent().width() - thumb.outerWidth() ) )
  3385. )
  3386. ) {
  3387. $list.parent().stop().animate({ 'scrollLeft' : thumbPos.left }, duration);
  3388. }
  3389. }
  3390. },
  3391. update : function() {
  3392. this.instance.$refs.container.toggleClass( 'fancybox-show-thumbs', this.isVisible );
  3393. if ( this.isVisible ) {
  3394. if ( !this.$grid ) {
  3395. this.create();
  3396. }
  3397. this.instance.trigger( 'onThumbsShow' );
  3398. this.focus( 0 );
  3399. } else if ( this.$grid ) {
  3400. this.instance.trigger( 'onThumbsHide' );
  3401. }
  3402. // Update content position
  3403. this.instance.update();
  3404. },
  3405. hide : function() {
  3406. this.isVisible = false;
  3407. this.update();
  3408. },
  3409. show : function() {
  3410. this.isVisible = true;
  3411. this.update();
  3412. },
  3413. toggle : function() {
  3414. this.isVisible = !this.isVisible;
  3415. this.update();
  3416. }
  3417. });
  3418. $(document).on({
  3419. 'onInit.fb' : function(e, instance) {
  3420. var Thumbs;
  3421. if ( instance && !instance.Thumbs ) {
  3422. Thumbs = new FancyThumbs( instance );
  3423. if ( Thumbs.isActive && Thumbs.opts.autoStart === true ) {
  3424. Thumbs.show();
  3425. }
  3426. }
  3427. },
  3428. 'beforeShow.fb' : function(e, instance, item, firstRun) {
  3429. var Thumbs = instance && instance.Thumbs;
  3430. if ( Thumbs && Thumbs.isVisible ) {
  3431. Thumbs.focus( firstRun ? 0 : 250 );
  3432. }
  3433. },
  3434. 'afterKeydown.fb' : function(e, instance, current, keypress, keycode) {
  3435. var Thumbs = instance && instance.Thumbs;
  3436. // "G"
  3437. if ( Thumbs && Thumbs.isActive && keycode === 71 ) {
  3438. keypress.preventDefault();
  3439. Thumbs.toggle();
  3440. }
  3441. },
  3442. 'beforeClose.fb' : function( e, instance ) {
  3443. var Thumbs = instance && instance.Thumbs;
  3444. if ( Thumbs && Thumbs.isVisible && Thumbs.opts.hideOnClose !== false ) {
  3445. Thumbs.$grid.hide();
  3446. }
  3447. }
  3448. });
  3449. }(document, window.jQuery));
  3450. //// ==========================================================================
  3451. //
  3452. // Share
  3453. // Displays simple form for sharing current url
  3454. //
  3455. // ==========================================================================
  3456. ;(function (document, $) {
  3457. 'use strict';
  3458. $.extend(true, $.fancybox.defaults, {
  3459. btnTpl : {
  3460. share :
  3461. '<button data-fancybox-share class="fancybox-button fancybox-button--share" title="{{SHARE}}">' +
  3462. '<svg viewBox="0 0 40 40">' +
  3463. '<path d="M6,30 C8,18 19,16 23,16 L23,16 L23,10 L33,20 L23,29 L23,24 C19,24 8,27 6,30 Z">' +
  3464. '</svg>' +
  3465. '</button>'
  3466. },
  3467. share : {
  3468. tpl :
  3469. '<div class="fancybox-share">' +
  3470. '<h1>{{SHARE}}</h1>' +
  3471. '<p class="fancybox-share__links">' +
  3472. '<a class="fancybox-share__button fancybox-share__button--fb" href="https://www.facebook.com/sharer/sharer.php?u={{url}}">' +
  3473. '<svg viewBox="0 0 512 512" xmlns="http://www.w3.org/2000/svg"><path d="m287 456v-299c0-21 6-35 35-35h38v-63c-7-1-29-3-55-3-54 0-91 33-91 94v306m143-254h-205v72h196" /></svg>' +
  3474. '<span>Facebook</span>' +
  3475. '</a>' +
  3476. '<a class="fancybox-share__button fancybox-share__button--pt" href="https://www.pinterest.com/pin/create/button/?url={{url}}&description={{descr}}&media={{media}}">' +
  3477. '<svg viewBox="0 0 512 512" xmlns="http://www.w3.org/2000/svg"><path d="m265 56c-109 0-164 78-164 144 0 39 15 74 47 87 5 2 10 0 12-5l4-19c2-6 1-8-3-13-9-11-15-25-15-45 0-58 43-110 113-110 62 0 96 38 96 88 0 67-30 122-73 122-24 0-42-19-36-44 6-29 20-60 20-81 0-19-10-35-31-35-25 0-44 26-44 60 0 21 7 36 7 36l-30 125c-8 37-1 83 0 87 0 3 4 4 5 2 2-3 32-39 42-75l16-64c8 16 31 29 56 29 74 0 124-67 124-157 0-69-58-132-146-132z" fill="#fff"/></svg>' +
  3478. '<span>Pinterest</span>' +
  3479. '</a>' +
  3480. '<a class="fancybox-share__button fancybox-share__button--tw" href="https://twitter.com/intent/tweet?url={{url}}&text={{descr}}">' +
  3481. '<svg viewBox="0 0 512 512" xmlns="http://www.w3.org/2000/svg"><path d="m456 133c-14 7-31 11-47 13 17-10 30-27 37-46-15 10-34 16-52 20-61-62-157-7-141 75-68-3-129-35-169-85-22 37-11 86 26 109-13 0-26-4-37-9 0 39 28 72 65 80-12 3-25 4-37 2 10 33 41 57 77 57-42 30-77 38-122 34 170 111 378-32 359-208 16-11 30-25 41-42z" /></svg>' +
  3482. '<span>Twitter</span>' +
  3483. '</a>' +
  3484. '</p>' +
  3485. '<p><input class="fancybox-share__input" type="text" value="{{url_raw}}" /></p>' +
  3486. '</div>'
  3487. }
  3488. });
  3489. function escapeHtml(string) {
  3490. var entityMap = {
  3491. '&': '&amp;',
  3492. '<': '&lt;',
  3493. '>': '&gt;',
  3494. '"': '&quot;',
  3495. "'": '&#39;',
  3496. '/': '&#x2F;',
  3497. '`': '&#x60;',
  3498. '=': '&#x3D;'
  3499. };
  3500. return String(string).replace(/[&<>"'`=\/]/g, function (s) {
  3501. return entityMap[s];
  3502. });
  3503. }
  3504. $(document).on('click', '[data-fancybox-share]', function() {
  3505. var f = $.fancybox.getInstance(),
  3506. url,
  3507. tpl;
  3508. if ( f ) {
  3509. url = f.current.opts.hash === false ? f.current.src : window.location;
  3510. tpl = f.current.opts.share.tpl
  3511. .replace( /\{\{media\}\}/g, f.current.type === 'image' ? encodeURIComponent( f.current.src ) : '' )
  3512. .replace( /\{\{url\}\}/g, encodeURIComponent( url ) )
  3513. .replace( /\{\{url_raw\}\}/g, escapeHtml( url ) )
  3514. .replace( /\{\{descr\}\}/g, f.$caption ? encodeURIComponent( f.$caption.text() ) : '' );
  3515. $.fancybox.open({
  3516. src : f.translate( f, tpl ),
  3517. type : 'html',
  3518. opts : {
  3519. animationEffect : "fade",
  3520. animationDuration : 250,
  3521. afterLoad : function(instance, current) {
  3522. // Opening links in a popup window
  3523. current.$content.find('.fancybox-share__links a').click(function() {
  3524. window.open(this.href, "Share", "width=550, height=450");
  3525. return false;
  3526. });
  3527. }
  3528. }
  3529. });
  3530. }
  3531. });
  3532. }( document, window.jQuery || jQuery ));
  3533. // ==========================================================================
  3534. //
  3535. // Hash
  3536. // Enables linking to each modal
  3537. //
  3538. // ==========================================================================
  3539. ;(function (document, window, $) {
  3540. 'use strict';
  3541. // Simple $.escapeSelector polyfill (for jQuery prior v3)
  3542. if ( !$.escapeSelector ) {
  3543. $.escapeSelector = function( sel ) {
  3544. var rcssescape = /([\0-\x1f\x7f]|^-?\d)|^-$|[^\x80-\uFFFF\w-]/g;
  3545. var fcssescape = function( ch, asCodePoint ) {
  3546. if ( asCodePoint ) {
  3547. // U+0000 NULL becomes U+FFFD REPLACEMENT CHARACTER
  3548. if ( ch === "\0" ) {
  3549. return "\uFFFD";
  3550. }
  3551. // Control characters and (dependent upon position) numbers get escaped as code points
  3552. return ch.slice( 0, -1 ) + "\\" + ch.charCodeAt( ch.length - 1 ).toString( 16 ) + " ";
  3553. }
  3554. // Other potentially-special ASCII characters get backslash-escaped
  3555. return "\\" + ch;
  3556. };
  3557. return ( sel + "" ).replace( rcssescape, fcssescape );
  3558. };
  3559. }
  3560. // Create new history entry only once
  3561. var shouldCreateHistory = true;
  3562. // Variable containing last hash value set by fancyBox
  3563. // It will be used to determine if fancyBox needs to close after hash change is detected
  3564. var currentHash = null;
  3565. // Throttling the history change
  3566. var timerID = null;
  3567. // Get info about gallery name and current index from url
  3568. function parseUrl() {
  3569. var hash = window.location.hash.substr( 1 );
  3570. var rez = hash.split( '-' );
  3571. var index = rez.length > 1 && /^\+?\d+$/.test( rez[ rez.length - 1 ] ) ? parseInt( rez.pop( -1 ), 10 ) || 1 : 1;
  3572. var gallery = rez.join( '-' );
  3573. // Index is starting from 1
  3574. if ( index < 1 ) {
  3575. index = 1;
  3576. }
  3577. return {
  3578. hash : hash,
  3579. index : index,
  3580. gallery : gallery
  3581. };
  3582. }
  3583. // Trigger click evnt on links to open new fancyBox instance
  3584. function triggerFromUrl( url ) {
  3585. var $el;
  3586. if ( url.gallery !== '' ) {
  3587. // If we can find element matching 'data-fancybox' atribute, then trigger click event for that ..
  3588. $el = $( "[data-fancybox='" + $.escapeSelector( url.gallery ) + "']" ).eq( url.index - 1 );
  3589. if ( !$el.length ) {
  3590. // .. if not, try finding element by ID
  3591. $el = $( "#" + $.escapeSelector( url.gallery ) + "" );
  3592. }
  3593. if ( $el.length ) {
  3594. shouldCreateHistory = false;
  3595. $el.trigger( 'click' );
  3596. }
  3597. }
  3598. }
  3599. // Get gallery name from current instance
  3600. function getGalleryID( instance ) {
  3601. var opts;
  3602. if ( !instance ) {
  3603. return false;
  3604. }
  3605. opts = instance.current ? instance.current.opts : instance.opts;
  3606. return opts.hash || ( opts.$orig ? opts.$orig.data( 'fancybox' ) : '' );
  3607. }
  3608. // Start when DOM becomes ready
  3609. $(function() {
  3610. // Check if user has disabled this module
  3611. if ( $.fancybox.defaults.hash === false ) {
  3612. return;
  3613. }
  3614. // Update hash when opening/closing fancyBox
  3615. $(document).on({
  3616. 'onInit.fb' : function( e, instance ) {
  3617. var url, gallery;
  3618. if ( instance.group[ instance.currIndex ].opts.hash === false ) {
  3619. return;
  3620. }
  3621. url = parseUrl();
  3622. gallery = getGalleryID( instance );
  3623. // Make sure gallery start index matches index from hash
  3624. if ( gallery && url.gallery && gallery == url.gallery ) {
  3625. instance.currIndex = url.index - 1;
  3626. }
  3627. },
  3628. 'beforeShow.fb' : function( e, instance, current ) {
  3629. var gallery;
  3630. if ( !current || current.opts.hash === false ) {
  3631. return;
  3632. }
  3633. gallery = getGalleryID( instance );
  3634. // Update window hash
  3635. if ( gallery && gallery !== '' ) {
  3636. if ( window.location.hash.indexOf( gallery ) < 0 ) {
  3637. instance.opts.origHash = window.location.hash;
  3638. }
  3639. currentHash = gallery + ( instance.group.length > 1 ? '-' + ( current.index + 1 ) : '' );
  3640. if ( 'replaceState' in window.history ) {
  3641. if ( timerID ) {
  3642. clearTimeout( timerID );
  3643. }
  3644. timerID = setTimeout(function() {
  3645. window.history[ shouldCreateHistory ? 'pushState' : 'replaceState' ]( {} , document.title, window.location.pathname + window.location.search + '#' + currentHash );
  3646. timerID = null;
  3647. shouldCreateHistory = false;
  3648. }, 300);
  3649. } else {
  3650. window.location.hash = currentHash;
  3651. }
  3652. }
  3653. },
  3654. 'beforeClose.fb' : function( e, instance, current ) {
  3655. var gallery, origHash;
  3656. if ( timerID ) {
  3657. clearTimeout( timerID );
  3658. }
  3659. if ( current.opts.hash === false ) {
  3660. return;
  3661. }
  3662. gallery = getGalleryID( instance );
  3663. origHash = instance && instance.opts.origHash ? instance.opts.origHash : '';
  3664. // Remove hash from location bar
  3665. if ( gallery && gallery !== '' ) {
  3666. if ( 'replaceState' in history ) {
  3667. window.history.replaceState( {} , document.title, window.location.pathname + window.location.search + origHash );
  3668. } else {
  3669. window.location.hash = origHash;
  3670. // Keep original scroll position
  3671. $( window ).scrollTop( instance.scrollTop ).scrollLeft( instance.scrollLeft );
  3672. }
  3673. }
  3674. currentHash = null;
  3675. }
  3676. });
  3677. // Check if need to close after url has changed
  3678. $(window).on('hashchange.fb', function() {
  3679. var url = parseUrl();
  3680. if ( $.fancybox.getInstance() ) {
  3681. if ( currentHash && currentHash !== url.gallery + '-' + url.index && !( url.index === 1 && currentHash == url.gallery ) ) {
  3682. currentHash = null;
  3683. $.fancybox.close();
  3684. }
  3685. } else if ( url.gallery !== '' ) {
  3686. triggerFromUrl( url );
  3687. }
  3688. });
  3689. // Check current hash and trigger click event on matching element to start fancyBox, if needed
  3690. setTimeout(function() {
  3691. triggerFromUrl( parseUrl() );
  3692. }, 50);
  3693. });
  3694. }( document, window, window.jQuery || jQuery ));
  3695. ;(function (document, $) {
  3696. 'use strict';
  3697. var prevTime = new Date().getTime();
  3698. $(document).on({
  3699. 'onInit.fb' : function( e, instance, current ) {
  3700. instance.$refs.stage.on('mousewheel DOMMouseScroll wheel MozMousePixelScroll', function(e) {
  3701. var current = instance.current,
  3702. currTime = new Date().getTime();
  3703. if ( instance.group.length < 1 || current.opts.wheel === false || ( current.opts.wheel === 'auto' && current.type !== 'image' ) ) {
  3704. return;
  3705. }
  3706. e.preventDefault();
  3707. e.stopPropagation();
  3708. if ( current.$slide.hasClass( 'fancybox-animated' ) ) {
  3709. return;
  3710. }
  3711. e = e.originalEvent || e;
  3712. if ( currTime - prevTime < 250 ) {
  3713. return;
  3714. }
  3715. prevTime = currTime;
  3716. instance[ ( -e.deltaY || -e.deltaX || e.wheelDelta || -e.detail ) < 0 ? 'next' : 'previous' ]();
  3717. });
  3718. }
  3719. });
  3720. }( document, window.jQuery || jQuery ));