jquery.fancybox.js 150 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239
  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 ));