Advertisement
Guest User

Untitled

a guest
Jan 6th, 2012
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.28 KB | None | 0 0
  1. // rsGalleries.js by Dennis Amrouche | www.screenlabor.de | freie media hamburg
  2.  
  3. // this script was written with friendly support of ...
  4. // - atula from NYC/USA @ #jquery irc-channel/freenode/europe
  5. // - sven lauritzen @ www.sven-lauritzen.de, freelance coder located in hamburg
  6. // - some beer in café miller / st. pauli hamburg
  7.  
  8. $(function() {
  9. rsGalleries.init();
  10. });
  11.  
  12. if (typeof console == "undefined") {
  13. console = {
  14. log:function() {
  15.  
  16. }
  17. }
  18. }
  19.  
  20.  
  21. rsGalleries = {
  22. scrollerHeight: 330,
  23.  
  24. init:function() {
  25. this.initStart();
  26. this.initTabs();
  27. this.initScrollers();
  28. this.initSwap();
  29. },
  30.  
  31. initStart:function() {
  32. //enable all starting categories
  33. $(".tabs").addClass("hide");
  34. $("#start").addClass("show");
  35. $("#food").addClass("show");
  36. },
  37. initTabs:function() {
  38. // change categories
  39. $("a.switch").click(function() {
  40. var cat = $(this).attr("href").substr(1);
  41. $(this).parents(".tabholder").find(".tab").addClass("hide");
  42. $(this).parents(".tabholder").find("#"+cat).addClass("show");
  43.  
  44. // $(this).parents(".tabholder").find("a.switch").removeClass("selected");
  45. // $(this).parents(".tabholder").find("a.switch").addClass("selected");
  46. return false;
  47. });
  48.  
  49. },
  50.  
  51. initSwap:function() {
  52. // find all images with the class thumb and bind a click event to it
  53. $("a.thumb").click(function() {
  54. $(this).parents(".thumbrow").find("a.thumb").removeClass("selected");
  55. $(this).addClass("selected");
  56.  
  57. // getting the src text and getting the number out..
  58. var path = $(this).find("img").attr("src").replace("-thmb-","-photo-");
  59.  
  60. // grabbing the photo that's being displayed
  61. var photo = $(this).parents(".gallery").find(".photo img");
  62. // the same procedure to get the number in the image name
  63. var curr = photo.attr("src");
  64.  
  65. // here I'm comparing, if the image displayed is not equal to the thumb I'm clicking (!=) do this
  66. if (path != curr) {
  67.  
  68. // photo is the variable I created to reference the photo being displayed
  69. // fadeOut("fast") is a jquery effect
  70. // .attr( is changing the attribute.. src of the image... then fadeIn(
  71. photo.fadeOut("fast", function() {
  72. photo.attr("src", path).fadeIn("slow");
  73. });
  74. }
  75.  
  76. return false;
  77. });
  78.  
  79. },
  80.  
  81. initScrollers:function(gallery) {
  82. // OnClick-Event auf den down-Pfeil
  83. if((typeof gallery)=="undefined") {
  84. gallery=$(".gallery")
  85. }
  86.  
  87. $(gallery).each(function() {
  88. var position = parseInt($(this).find(".thumbrow").css("margin-top").replace("px",""));
  89. var up=$(this).find("li.up");
  90. var down=$(this).find("li.down");
  91.  
  92. if(-position/rsGalleries.scrollerHeight < Math.ceil($(this).find("a.thumb").length/5)-1) {
  93. $(down).find("img").wrap('<a href="#" class="down"></a>');
  94.  
  95. $(down).find("a").click(function() {
  96. // Suche und finde die thumbrow die animiert werden soll
  97. var currGallery=$(this).parents(".gallery");
  98. var thumbrow = currGallery.find(".thumbrow");
  99.  
  100. // disable all scroll links
  101. $(this).parents("ul").find("li").each(function(i) {
  102. var anchor=$(this).find("a");
  103. if(anchor.length>0) {
  104. $(this).html($(anchor).html());
  105. }
  106. });
  107.  
  108. // grabbing value of margin
  109. var position = parseInt($(thumbrow).css("margin-top").replace("px",""));
  110.  
  111. // animate thumbrow vertically via CSS margin-top
  112. $(thumbrow).animate({marginTop:position-rsGalleries.scrollerHeight}, "slow", function() {
  113. rsGalleries.initScrollers(currGallery);
  114. });
  115.  
  116. return false;
  117. });
  118. }
  119.  
  120. if(position<0) {
  121. $(up).find("img").wrap('<a href="#" class="up"></a>');
  122.  
  123. $(up).find("a").click(function() {
  124. var currGallery=$(this).parents(".gallery");
  125. var thumbrow = currGallery.find(".thumbrow");
  126. // disable all scroll links
  127. $(this).parents("ul").find("li").each(function(i) {
  128. var anchor=$(this).find("a");
  129. if(anchor.length>0) {
  130. $(this).html($(anchor).html());
  131. }
  132. });
  133. var position = parseInt($(thumbrow).css("margin-top").replace("px",""));
  134. $(thumbrow).animate({marginTop:position+rsGalleries.scrollerHeight}, "slow", function() {
  135. rsGalleries.initScrollers(currGallery);
  136. });
  137. return false;
  138. });
  139. }
  140. });
  141.  
  142. }
  143. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement