wallgallery.js 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699
  1. /*
  2. * debouncedresize: special jQuery event that happens once after a window resize
  3. *
  4. * latest version and complete README available on Github:
  5. * https://github.com/louisremi/jquery-smartresize/blob/master/jquery.debouncedresize.js
  6. *
  7. * Copyright 2011 @louis_remi
  8. * Licensed under the MIT license.
  9. */
  10. var $event = $.event,
  11. $special,
  12. resizeTimeout;
  13. var $svgWall = '<img id="pared" src="img/secciones/galeria/pared.webp">';
  14. var $svgFloor = '';
  15. var $svgPrev = '<img src="img/secciones/galeria/prev.svg">';
  16. var $svgNext = '<img src="img/secciones/galeria/next.svg">';
  17. $special = $event.special.debouncedresize = {
  18. setup: function() {
  19. $( this ).on( "resize", $special.handler );
  20. },
  21. teardown: function() {
  22. $( this ).off( "resize", $special.handler );
  23. },
  24. handler: function( event, execAsap ) {
  25. // Save the context
  26. var context = this,
  27. args = arguments,
  28. dispatch = function() {
  29. // set correct event type
  30. event.type = "debouncedresize";
  31. $event.dispatch.apply( context, args );
  32. };
  33. if ( resizeTimeout ) {
  34. clearTimeout( resizeTimeout );
  35. }
  36. execAsap ?
  37. dispatch() :
  38. resizeTimeout = setTimeout( dispatch, $special.threshold );
  39. },
  40. threshold: 250
  41. };
  42. // ======================= imagesLoaded Plugin ===============================
  43. // https://github.com/desandro/imagesloaded
  44. // $('#my-container').imagesLoaded(myFunction)
  45. // execute a callback when all images have loaded.
  46. // needed because .load() doesn't work on cached images
  47. // callback function gets image collection as argument
  48. // this is the container
  49. // original: MIT license. Paul Irish. 2010.
  50. // contributors: Oren Solomianik, David DeSandro, Yiannis Chatzikonstantinou
  51. // blank image data-uri bypasses webkit log warning (thx doug jones)
  52. var BLANK = 'data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///ywAAAAAAQABAAACAUwAOw==';
  53. $.fn.imagesLoaded = function( callback ) {
  54. var $this = this,
  55. deferred = $.isFunction($.Deferred) ? $.Deferred() : 0,
  56. hasNotify = $.isFunction(deferred.notify),
  57. $images = $this.find('img').add( $this.filter('img') ),
  58. loaded = [],
  59. proper = [],
  60. broken = [];
  61. // Register deferred callbacks
  62. if ($.isPlainObject(callback)) {
  63. $.each(callback, function (key, value) {
  64. if (key === 'callback') {
  65. callback = value;
  66. } else if (deferred) {
  67. deferred[key](value);
  68. }
  69. });
  70. }
  71. function doneLoading() {
  72. var $proper = $(proper),
  73. $broken = $(broken);
  74. if ( deferred ) {
  75. if ( broken.length ) {
  76. deferred.reject( $images, $proper, $broken );
  77. } else {
  78. deferred.resolve( $images );
  79. }
  80. }
  81. if ( $.isFunction( callback ) ) {
  82. callback.call( $this, $images, $proper, $broken );
  83. }
  84. }
  85. function imgLoaded( img, isBroken ) {
  86. // don't proceed if BLANK image, or image is already loaded
  87. if ( img.src === BLANK || $.inArray( img, loaded ) !== -1 ) {
  88. return;
  89. }
  90. // store element in loaded images array
  91. loaded.push( img );
  92. // keep track of broken and properly loaded images
  93. if ( isBroken ) {
  94. broken.push( img );
  95. } else {
  96. proper.push( img );
  97. }
  98. // cache image and its state for future calls
  99. $.data( img, 'imagesLoaded', { isBroken: isBroken, src: img.src } );
  100. // trigger deferred progress method if present
  101. if ( hasNotify ) {
  102. deferred.notifyWith( $(img), [ isBroken, $images, $(proper), $(broken) ] );
  103. }
  104. // call doneLoading and clean listeners if all images are loaded
  105. if ( $images.length === loaded.length ){
  106. setTimeout( doneLoading );
  107. $images.unbind( '.imagesLoaded' );
  108. }
  109. }
  110. // if no images, trigger immediately
  111. if ( !$images.length ) {
  112. doneLoading();
  113. } else {
  114. $images.bind( 'load.imagesLoaded error.imagesLoaded', function( event ){
  115. // trigger imgLoaded
  116. imgLoaded( event.target, event.type === 'error' );
  117. }).each( function( i, el ) {
  118. var src = el.src;
  119. // find out if this image has been already checked for status
  120. // if it was, and src has not changed, call imgLoaded on it
  121. var cached = $.data( el, 'imagesLoaded' );
  122. if ( cached && cached.src === src ) {
  123. imgLoaded( el, cached.isBroken );
  124. return;
  125. }
  126. // if complete is true and browser supports natural sizes, try
  127. // to check for image status manually
  128. if ( el.complete && el.naturalWidth !== undefined ) {
  129. imgLoaded( el, el.naturalWidth === 0 || el.naturalHeight === 0 );
  130. return;
  131. }
  132. // cached images don't fire load sometimes, so we reset src, but only when
  133. // dealing with IE, or image is complete (loaded) and failed manual check
  134. // webkit hack from http://groups.google.com/group/jquery-dev/browse_thread/thread/eee6ab7b2da50e1f
  135. if ( el.readyState || el.complete ) {
  136. el.src = BLANK;
  137. el.src = src;
  138. }
  139. });
  140. }
  141. return deferred ? deferred.promise( $this ) : $this;
  142. };
  143. var Gallery = (function() {
  144. var $gallery = $( '#gr-gallery' ),
  145. $itemsContainer = $gallery.children( 'div.gr-main' ).hide(),
  146. $items = $itemsContainer.find( 'figure' ),
  147. $window = $( window ),
  148. winsize = getWindowSize(),
  149. defaults = {
  150. speed : 800,
  151. easing : 'ease-in-out',
  152. margin : 400
  153. },
  154. // css transitions and 3d transforms support
  155. support = { transitions : Modernizr.csstransitions, transforms3d : Modernizr.csstransforms3d },
  156. transEndEventNames = {
  157. 'WebkitTransition' : 'webkitTransitionEnd',
  158. 'MozTransition' : 'transitionend',
  159. 'OTransition' : 'oTransitionEnd',
  160. 'msTransition' : 'MSTransitionEnd',
  161. 'transition' : 'transitionend'
  162. },
  163. transformNames = {
  164. 'WebkitTransform' : '-webkit-transform',
  165. 'MozTransform' : '-moz-transform',
  166. 'OTransform' : '-o-transform',
  167. 'msTransform' : '-ms-transform',
  168. 'transform' : 'transform'
  169. },
  170. transEndEventName = transEndEventNames[ Modernizr.prefixed( 'transition' ) ] + '.cbpFWSlider',
  171. transformName = transformNames[ Modernizr.prefixed( 'transform' ) ];
  172. function init( settings ) {
  173. Gallery.settings = $.extend( true, {}, defaults, settings );
  174. // preload images
  175. $itemsContainer.imagesLoaded( buildRoom );
  176. }
  177. function buildRoom() {
  178. // create room with 4 walls
  179. Gallery.room = new Room( $items );
  180. // now show first wall (show elements of first wall)
  181. Gallery.room.renderWall();
  182. initEvents();
  183. }
  184. function Room( $items ) {
  185. //this.$el = $( '<div class="gr-room"><div class="gr-wall-main"><div class="gr-floor"></div></div></div>' ).insertAfter( $itemsContainer );
  186. this.$el = $( '<div class="gr-room"><div class="gr-wall-main">' + $svgWall +'<div class="gr-floor">' + $svgFloor + '</div></div></div>' ).insertAfter( $itemsContainer );
  187. // todo: check the real perspective value for widths > x
  188. // the problem here is that if the wall's width (window width) is too large, and the perspective value is too small.
  189. // We will see the background in a certain poitn of time when the wall is rotating (at least in firefox)
  190. // we need to adjust the value of the perspective according to the value of the current window's width
  191. if( winsize.width > 1300 ) {
  192. this.$el.css( 'perspective', 1700 );
  193. }
  194. this.transitionSettings = transformName + ' ' + Gallery.settings.speed + 'ms ' + Gallery.settings.easing;
  195. // element representing the wall
  196. this.$mainWall = this.$el.find( 'div.gr-wall-main' ).css( 'transition', this.transitionSettings );
  197. // 4 walls (or 1 if no support for 3dtransforms)
  198. this.walls = [];
  199. // current rendered wall
  200. this.currentWall = 0; // 0,1,2,3
  201. // current item being shown
  202. this.currentItem = 0;
  203. // total number of items
  204. this.totalItems = $items.length;
  205. // is walking
  206. this.walking = false;
  207. this.caption = -1;
  208. this.create();
  209. }
  210. Room.prototype = {
  211. create : function() {
  212. // check on settings.layout
  213. this.layout = typeof Gallery.settings.layout != 'undefined' && Gallery.settings.layout instanceof Array && support.transforms3d ? Gallery.settings.layout : this.getLayoutSettings();
  214. var pos = 0, max = 0, prev = 0,
  215. wallsCount = support.transforms3d ? 4 : 1;
  216. for( var i = 0; i < wallsCount; ++i ) {
  217. var nmb = this.layout[ i ];
  218. max = nmb + prev;
  219. prev += nmb;
  220. var wall = new Wall( $items.slice( pos, max ).clone() );
  221. pos = max;
  222. this.walls.push( wall );
  223. }
  224. // add navigation
  225. if( this.totalItems > 1 ) {
  226. /*this.$navPrev = $( '<span class="gr-prev">prev</span>' ).on( 'click', $.proxy( this.navigate, this, 'prev' ) );
  227. this.$navNext = $( '<span class="gr-next">next</span>' ).on( 'click', $.proxy( this.navigate, this, 'next' ) );*/
  228. this.$navPrev = $( '<span class="gr-prev">' + $svgPrev + '</span>' ).on( 'click', $.proxy( this.navigate, this, 'prev' ) );
  229. this.$navIndex = $( '<span class="gr-index">1/' + this.totalItems + '</span>' );
  230. this.$navNext = $( '<span class="gr-next">' + $svgNext + '</span>' ).on( 'click', $.proxy( this.navigate, this, 'next' ) );
  231. this.$nav = $( '<nav/>' ).append( this.$navPrev, this.$navIndex, this.$navNext ).appendTo( $gallery );
  232. }
  233. // add caption container
  234. this.$caption = $( '<div class="gr-caption"><span class="gr-caption-close">x</span></div>' ).appendTo( $gallery );
  235. this.$caption.find( 'span.gr-caption-close' ).on( 'click', $.proxy( this.hideDescription, this ) );
  236. // click on item's caption
  237. var self = this;
  238. /*this.$el.on( 'click', 'figure > figcaption', function() {
  239. var $caption = $( this ),
  240. $item = $caption.parent(),
  241. idx = $item.index() - 1;
  242. if( self.caption === self.currentItem && idx === self.currentItem ) {
  243. return false;
  244. }
  245. else if( idx !== self.currentItem ) {
  246. self.jump( idx, function() {
  247. self.showDescription( $caption, idx );
  248. } );
  249. }
  250. else {
  251. self.showDescription( $caption, idx );
  252. }
  253. } );*/
  254. // click items
  255. //this.$el.on( 'click', 'figure > div', function() {
  256. this.$el.on( 'click', 'figure > div.cartel', function() { //ADAPTADO
  257. abreModal(this); //AGREGADO para personalizar modal
  258. /*var $item = $( this ).parent(), idx = $item.index() - 1;
  259. if( idx === self.currentItem ) {
  260. return false;
  261. }
  262. self.jump( idx );*/
  263. } );
  264. },
  265. getLayoutSettings : function() {
  266. var perwall = Math.floor( this.totalItems / 4 ),
  267. lastwall = perwall + this.totalItems % 4;
  268. return support.transforms3d ? [perwall,perwall,perwall,lastwall] : [this.totalItems];
  269. },
  270. // displays the items of a wall on a container $wallElem
  271. renderWall : function( $wallElem ) {
  272. var $wallElem = $wallElem || this.$mainWall,
  273. wallH = $wallElem.height(),
  274. wallmargins = 150,
  275. wall = this.walls[ this.currentWall ],
  276. totalLeft = 0, lastItemW = 0,
  277. wallMarginLeft = 0, sumWidths = 0;
  278. for( var i = 0; i < wall.itemsCount; ++i ) {
  279. var $item = wall.$items.eq( i );
  280. $item.appendTo( $wallElem );
  281. //AGREGADO
  282. var itemH = $item.height(),
  283. figcaptionH = 0;
  284. /*if($item.find('img').parent('div').parent('div').parent('div.anuncio').length > 0)
  285. $item.find('img').css( 'width', $item.find('img').width());*/
  286. //FINAL AGREGADO
  287. if( itemH > wallH - wallmargins ) {
  288. $item.find('img').height( wallH - wallmargins - figcaptionH );
  289. $item.css( 'top', (( wallmargins / 2 ) - 20));
  290. }
  291. else {
  292. $item.css( 'top', ((( wallH - itemH ) / 2)-20) );
  293. }
  294. var itemW = wall.widths[i] || $item.width();
  295. sumWidths += itemW;
  296. if( i === 0 ) {
  297. totalLeft = winsize.width / 2 - itemW / 2;
  298. wallMarginLeft = Math.ceil(totalLeft);
  299. }
  300. else {
  301. totalLeft += lastItemW + Gallery.settings.margin;
  302. }
  303. lastItemW = itemW;
  304. $item.css( { left : totalLeft } );
  305. wall.widths[i] = itemW;
  306. };
  307. // update wall element's width
  308. var wallWidth = wallMarginLeft === 0 ? winsize.width : Math.ceil( wallMarginLeft + ( wall.itemsCount - 1 ) * Gallery.settings.margin + sumWidths + winsize.width / 2 - lastItemW / 2 );
  309. $wallElem.css( 'width', wallWidth ).find( 'div.gr-floor' ).css( 'width', wallWidth );
  310. },
  311. changeWall : function( dir ) {
  312. // set origins
  313. // change current wall's width to windows width and reorganize items accordingly:
  314. this.$mainWall.css( {
  315. transition : 'none',
  316. transformOrigin : dir === 'next' ? '100% 50%' : '0% 50%',
  317. width : winsize.width,
  318. transform : 'translateX(0px)',
  319. backgroundPosition : this.$mainWall.data( 'translationVal' ) + 'px 0px'
  320. } );
  321. this.walls[ this.lastWall ].$items.css( 'left','+=' + this.$mainWall.data( 'translationVal' ) );
  322. //INTENTAR PERSPECTIVA AQUI -ms-transform: scale(0.75); transform: scale(0.75);
  323. // update floor
  324. this.$mainWall.find( 'div.gr-floor' ).css( {
  325. width : winsize.width,
  326. backgroundPosition : this.$mainWall.data( 'translationVal' ) + 'px 0px'
  327. } );
  328. // set transition again
  329. this.$mainWall.css('transition', this.transitionSettings );
  330. // the incoming wall..
  331. //this.$auxWall = $( '<div class="gr-wall-other"><div class="gr-floor"></div></div>' ).insertAfter( this.$mainWall );
  332. this.$auxWall = $( '<div class="gr-wall-other">' + $svgWall + '<div class="gr-floor">' + $svgFloor + '</div></div>' ).insertAfter( this.$mainWall );
  333. var auxfloor = this.$auxWall.find( 'div.gr-floor' );
  334. // add next wall's items to $auxWall
  335. this.renderWall( this.$auxWall );
  336. var auxWallWidth = this.$auxWall.width(),
  337. auxWallInitialTranslationVal = dir === 'next' ? winsize.width : auxWallWidth * -1 + ( auxWallWidth - winsize.width ) * 1,
  338. auxWallInitialAngle = dir === 'next' ? -90 : 90,
  339. auxWallTransform = support.transforms3d ?
  340. 'translate3d(' + auxWallInitialTranslationVal + 'px,0px,0px) rotate3d(0,1,0,' + auxWallInitialAngle + 'deg)' :
  341. 'translate(' + auxWallInitialTranslationVal + 'px)';
  342. this.$auxWall.css( {
  343. transform : auxWallTransform,
  344. transformOrigin : dir === 'next' ? '0% 50%' : '100% 50%'
  345. } );
  346. // change aux wall's width to windows width and reorganize items accordingly:
  347. this.$auxWall.data( 'width', auxWallWidth ).css( 'width', winsize.width );
  348. auxfloor.css( 'width', winsize.width );
  349. if(dir === 'prev') {
  350. this.walls[ this.currentWall ].$items.css( 'left', '-=' + ( auxWallWidth - winsize.width ) );
  351. var bgpos = ( ( auxWallWidth - winsize.width ) * -1 ) + 'px 0px';
  352. this.$auxWall.css( 'background-position', bgpos );
  353. auxfloor.css( 'background-position', bgpos );
  354. }
  355. setTimeout( $.proxy( function() {
  356. var translationVal = this.$mainWall.data( 'translationVal' ) || 0,
  357. mainWallFinalTranslationVal = dir === 'next' ? - winsize.width : (translationVal - winsize.width) * -1,
  358. mainWallFinalAngle = dir === 'next' ? 90 : -90,
  359. mainWallFinalTransform = support.transforms3d ?
  360. 'translate3d(' + mainWallFinalTranslationVal + 'px,0px,0px) rotate3d(0,1,0,' + mainWallFinalAngle + 'deg)' :
  361. 'translate(' + mainWallFinalTranslationVal + 'px)';
  362. auxWallFinalTranslationVal = dir === 'next' ? 0 : 0,
  363. auxWallFinalAngle = 0,
  364. auxWallFinalTransform = support.transforms3d ?
  365. 'translate3d(' + auxWallFinalTranslationVal + 'px,0px,0px) rotate3d(0,1,0,' + auxWallFinalAngle + 'deg)' :
  366. 'translate(' + auxWallFinalTranslationVal + 'px)';
  367. this.$mainWall.css( 'transform', mainWallFinalTransform );
  368. this.$auxWall.css( {
  369. transition : this.transitionSettings,
  370. transform : auxWallFinalTransform
  371. } ).on( transEndEventName, $.proxy( function() {
  372. // set original width
  373. this.$auxWall.off( transEndEventName ).css( 'width', this.$auxWall.data( 'width' ) );
  374. auxfloor.css( 'width', this.$auxWall.data( 'width' ) );
  375. if( dir === 'prev' ) {
  376. // reset transform value and reorganize items accordingly
  377. this.$auxWall.css( {
  378. transition : 'none',
  379. transform : 'translateX(' + ( ( auxWallWidth - winsize.width ) * -1 ) + 'px)',
  380. backgroundPosition : '0px 0px'
  381. } );
  382. var wall = this.walls[ this.currentWall ],
  383. $lastItem = wall.$items.eq( wall.itemsCount - 1 );
  384. // reorganize items accordingly
  385. wall.$items.css( 'left', '+=' + ( auxWallWidth - winsize.width ) );
  386. auxfloor.css( 'background-position', '0px 0px' );
  387. // set transition again
  388. this.$auxWall.css( 'transition', this.transitionSettings );
  389. var translationVal = $lastItem.length > 0 ? - ( $lastItem.position().left + $lastItem.width() / 2 - winsize.width / 2 ) : 0;
  390. this.$auxWall.data( 'translationVal', translationVal );
  391. }
  392. this.switchWalls();
  393. this.walking = false;
  394. }, this ) );
  395. }, this ), 25 );
  396. },
  397. switchWalls : function() {
  398. this.$mainWall.remove();
  399. this.$mainWall = this.$auxWall.addClass( 'gr-wall-main' ).removeClass( 'gr-wall-other' );
  400. },
  401. navigate : function( dir ) {
  402. // if animating return
  403. if( this.walking ) {
  404. return false;
  405. }
  406. this.walking = true;
  407. var wall = this.walls[ this.currentWall ],
  408. wallItemsCount = wall.itemsCount,
  409. changeWall = false;
  410. // check on direction and update currentItem and currentWall value
  411. if( dir === 'next' ) {
  412. if( support.transforms3d ) {
  413. if( this.currentItem < wallItemsCount - 1 ) {
  414. ++this.currentItem;
  415. }
  416. else {
  417. this.lastWall = this.currentWall;
  418. // update current wall
  419. this.currentWall < 3 ? ++this.currentWall : this.currentWall = 0;
  420. // update wall
  421. wall = this.walls[ this.currentWall ];
  422. changeWall = true;
  423. // reset currentItem
  424. this.currentItem = 0;
  425. }
  426. }
  427. else if( this.currentItem < wallItemsCount - 1 ) {
  428. ++this.currentItem;
  429. }
  430. else {
  431. this.walking = false;
  432. return false;
  433. }
  434. }
  435. else if( dir === 'prev' ) {
  436. if( support.transforms3d ) {
  437. if( this.currentItem > 0 ) {
  438. --this.currentItem;
  439. }
  440. else {
  441. this.lastWall = this.currentWall;
  442. // update current wall
  443. this.currentWall > 0 ? --this.currentWall : this.currentWall = 3;
  444. // update wall
  445. wall = this.walls[ this.currentWall ];
  446. changeWall = true;
  447. // reset currentItem
  448. this.currentItem = wall.itemsCount - 1;
  449. }
  450. }
  451. else if( this.currentItem > 0 ) {
  452. --this.currentItem;
  453. }
  454. else {
  455. this.walking = false;
  456. return false;
  457. }
  458. }
  459. //Muestra item actual del total -- AGREGADO
  460. var cont = 0;
  461. for (var a = 0; a <= this.currentWall; a++){
  462. var tempWall = this.walls[a];
  463. var lim = tempWall.itemsCount-1;
  464. if (a == this.currentWall)
  465. lim = this.currentItem;
  466. for (var b = 0; b <= lim; b++){
  467. cont++;
  468. }
  469. }
  470. this.$navIndex.text(cont + '/' + this.totalItems);
  471. //Hasta aquí AGREGADO
  472. if( changeWall ) {
  473. changeWall = false;
  474. this.changeWall( dir );
  475. }
  476. else {
  477. this.jump();
  478. }
  479. },
  480. jump : function( pos, callback ) {
  481. var jumpnow = $.proxy( function() {
  482. if( typeof pos !== 'undefined' ) {
  483. this.currentItem = pos;
  484. }
  485. var $item = this.walls[ this.currentWall ].$items.eq( this.currentItem ),
  486. translationVal = - ( $item.position().left + $item.width() / 2 - winsize.width / 2 ),
  487. transformVal = 'translate3d(' + translationVal + 'px,0px,0px)',
  488. afterAnim = function() {
  489. this.$mainWall.off( transEndEventName );
  490. this.walking = false;
  491. if( callback ) {
  492. callback.call();
  493. }
  494. };
  495. this.$mainWall.data( 'translationVal', translationVal )
  496. if( support.transitions && support.transforms3d ) {
  497. this.$mainWall.css( 'transform', transformVal ).on( transEndEventName, $.proxy( afterAnim, this ) );
  498. }
  499. else {
  500. this.$mainWall.stop().animate( { left : translationVal }, Gallery.settings.speed, $.proxy( afterAnim, this ) );
  501. }
  502. }, this );
  503. if( this.caption !== -1 ) {
  504. this.hideDescription( jumpnow );
  505. }
  506. else {
  507. jumpnow.call();
  508. }
  509. },
  510. destroy : function() {
  511. this.$el.remove();
  512. this.hideDescription();
  513. this.$nav.remove();
  514. this.$caption.remove();
  515. Gallery.room = null;
  516. },
  517. showDescription : function( $descriptionEl, idx ) {
  518. var showdescfn = $.proxy( function() {
  519. this.$caption
  520. .find( 'div.gr-caption-inner' )
  521. .remove()
  522. .end()
  523. .append( '<div class="gr-caption-inner">' + $descriptionEl.html() + '</div>' )
  524. .css( 'transform', 'translateY(0px)' );
  525. this.caption = idx;
  526. }, this );
  527. if( this.caption !== -1 ) {
  528. this.hideDescription( showdescfn );
  529. }
  530. else {
  531. showdescfn.call();
  532. }
  533. },
  534. hideDescription : function( callback ) {
  535. this.$caption.css( 'transform', 'translateY(310px)' );
  536. var hidedescfn = $.proxy( function() {
  537. this.$caption.off( transEndEventName );
  538. this.caption = -1;
  539. if( callback && typeof callback === 'function' ) {
  540. callback.call();
  541. }
  542. }, this );
  543. if( support.transitions ) {
  544. this.$caption.on( transEndEventName, hidedescfn );
  545. }
  546. else {
  547. hidedescfn.call();
  548. }
  549. },
  550. removeDescription : function() {
  551. this.$caption.children( 'div' ).remove();
  552. this.caption = -1;
  553. }
  554. }
  555. function Wall( $items ) {
  556. this.$items = $items;
  557. this.itemsCount = this.$items.length;
  558. this.widths = [];
  559. }
  560. function initEvents() {
  561. $( window ).off( 'debouncedresize' ).on( 'debouncedresize', function() {
  562. winsize = getWindowSize();
  563. Gallery.room.destroy();
  564. buildRoom();
  565. } );
  566. }
  567. function getWindowSize() {
  568. return { width : $window.width(), height : $window.height() }
  569. }
  570. return { init : init };
  571. })();