In this repo i store all my websites, each in a different branch
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

159 lines
6.5 KiB

  1. /*
  2. * Smoothproducts
  3. * http://kthornbloom.com/smoothproducts.php
  4. *
  5. * Copyright 2013, Kevin Thornbloom
  6. * Free to use and abuse under the MIT license.
  7. * http://www.opensource.org/licenses/mit-license.php
  8. */
  9. (function ($) {
  10. $.fn.extend({
  11. smoothproducts: function () {
  12. var slideTiming = 300
  13. // Add some markup & set some CSS
  14. $('.sp-wrap').append('<div class="sp-large"></div><div class="sp-thumbs sp-tb-active"></div>');
  15. $('.sp-wrap').each(function () {
  16. $('a', this).appendTo($('.sp-thumbs', this));
  17. $('.sp-thumbs a:first', this).addClass('sp-current').clone().removeClass('sp-current').appendTo($('.sp-large', this)).addClass('sp-current-big');
  18. $('.sp-wrap').css({
  19. display: 'inline-block'
  20. });
  21. });
  22. // Prevent clicking while things are happening
  23. $(document.body).on('click', '.sp-thumbs', function (event) {
  24. event.preventDefault();
  25. });
  26. // Clicking a thumbnail
  27. $(document.body).on('click', '.sp-tb-active a', function (event) {
  28. $(this).parent().find('.sp-current').removeClass();
  29. $(this).parent().parent().find('.sp-thumbs').removeClass('sp-tb-active');
  30. $(this).parent().parent().find('.sp-zoom').remove();
  31. $(this).parent().parent().find('.sp-full-screen').fadeOut(function () {
  32. $(this).remove();
  33. });
  34. var currentHeight = $(this).parent().parent().find('.sp-large').height(),
  35. currentWidth = $(this).parent().parent().find('.sp-large').width();
  36. $(this).parent().parent().find('.sp-large').css({
  37. overflow: 'hidden',
  38. height: currentHeight + 'px',
  39. width: currentWidth + 'px'
  40. });
  41. $(this).parent().parent().find('.sp-large a').remove();
  42. $(this).addClass('sp-current').clone().hide().removeClass('sp-current').appendTo($(this).parent().parent().find('.sp-large')).addClass('sp-current-big').fadeIn(slideTiming, function () {
  43. var autoHeight = $(this).parent().parent().find('.sp-large img').height();
  44. $(this).parent().parent().find('.sp-large').animate({
  45. height: autoHeight
  46. }, 'fast', function () {
  47. $('.sp-large').css({
  48. height: 'auto',
  49. width: 'auto',
  50. });
  51. });
  52. $(this).parent().parent().find('.sp-thumbs').addClass('sp-tb-active');
  53. });
  54. event.preventDefault();
  55. });
  56. // Zoom In
  57. $(document.body).on('mouseover', '.sp-large a', function (event) {
  58. var largeUrl = $(this).attr('href');
  59. $(this).parent().parent().find('.sp-large').append('<div class="sp-zoom"><img src="' + largeUrl + '"/></div>');
  60. $(this).parent().parent().find('.sp-zoom').fadeIn();
  61. $(this).parent().parent().find(".sp-zoom").draggable();
  62. //$(this).parent().parent().prepend('<div class="sp-full-screen"><a href="#">↕</a></div>');
  63. event.preventDefault();
  64. });
  65. // Click To Lightbox Popup Show
  66. var lightBoxUrl = $('.sp-thumbs a:first').attr('href');
  67. $('.sp-full-screen a').attr('href', lightBoxUrl)
  68. $(".sp-thumbs a").click(function () {
  69. var bg = $(this).attr('href');
  70. $('.sp-full-screen a').attr('href', bg)
  71. });
  72. // Panning zoomed PC
  73. $('.sp-large').mousemove(function (e) {
  74. var viewWidth = $(this).width(),
  75. viewHeight = $(this).height(),
  76. largeWidth = $(this).find('.sp-zoom').width(),
  77. largeHeight = $(this).find('.sp-zoom').height(),
  78. parentOffset = $(this).parent().offset(),
  79. relativeXPosition = (e.pageX - parentOffset.left),
  80. relativeYPosition = (e.pageY - parentOffset.top),
  81. moveX = Math.floor((relativeXPosition * (viewWidth - largeWidth) / viewWidth)),
  82. moveY = Math.floor((relativeYPosition * (viewHeight - largeHeight) / viewHeight));
  83. $(this).find('.sp-zoom').css({
  84. left: moveX,
  85. top: moveY
  86. });
  87. }).mouseout(function () {
  88. // Pause Panning
  89. });
  90. // Panning zoomed Mobile - inspired by http://popdevelop.com/2010/08/touching-the-web/
  91. $.fn.draggable = function () {
  92. var offset = null;
  93. var start = function (e) {
  94. var orig = e.originalEvent;
  95. var pos = $(this).position();
  96. offset = {
  97. x: orig.changedTouches[0].pageX - pos.left,
  98. y: orig.changedTouches[0].pageY - pos.top
  99. };
  100. };
  101. var moveMe = function (e) {
  102. e.preventDefault();
  103. var orig = e.originalEvent,
  104. newY = orig.changedTouches[0].pageY - offset.y,
  105. newX = orig.changedTouches[0].pageX - offset.x,
  106. maxY = (($('.sp-zoom').height()) - ($('.sp-large').height())) * -1,
  107. maxX = (($('.sp-zoom').width()) - ($('.sp-large').width())) * -1;
  108. if (newY > maxY && 0 > newY) {
  109. $(this).css({
  110. top: newY
  111. });
  112. }
  113. if (newX > maxX && 0 > newX) {
  114. $(this).css({
  115. left: newX
  116. });
  117. }
  118. };
  119. this.bind("touchstart", start);
  120. this.bind("touchmove", moveMe);
  121. };
  122. // Zoom Out
  123. $(document.body).on('mouseleave', '.sp-zoom', function (event) {
  124. $(this).fadeOut(function () {
  125. $(this).remove();
  126. });
  127. });
  128. }
  129. });
  130. })(jQuery);