{"size": 2623, "ext": "js", "max_stars_repo_path": "master/jquery-in-action-master/jquery-in-action-master/js/jquery.jqia.photomatic.js", "max_stars_repo_name": "AlexRogalskiy/DevArtifacts", "max_stars_repo_stars_event_min_datetime": "2018-09-07T15:35:24.000Z", "max_stars_repo_stars_event_max_datetime": "2019-03-27T09:48:12.000Z", "max_issues_repo_path": "master/jQuery_3_SourceCode/js/jquery.jqia.photomatic.js", "max_issues_repo_name": "AlexRogalskiy/DevArtifacts", "max_issues_repo_issues_event_min_datetime": "2020-03-04T21:51:56.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-31T20:59:11.000Z", "max_forks_repo_path": "master/jquery-in-action-master/jquery-in-action-master/js/jquery.jqia.photomatic.js", "max_forks_repo_name": "AlexRogalskiy/DevArtifacts", "max_forks_repo_forks_event_min_datetime": "2019-06-18T19:57:17.000Z", "max_forks_repo_forks_event_max_datetime": "2020-11-06T03:55:08.000Z"}
{"max_stars_count": 4, "max_issues_count": 371, "max_forks_count": 3, "avg_line_length": 30.1494252874, "max_line_length": 109, "alphanum_fraction": 0.5104841784}
(function($) {

   function showPhoto(options, index) {
      $(options.photoElement).attr(
         'src',
         options.transformer(options.$thumbnails[index].src)
      );
      options.current = index;
   }

   var methods = {
      init: function(options) {
         options = $.extend(
            true,
            {},
            $.fn.jqiaPhotomatic.defaults,
            options,
            {
               current: 0,
               $thumbnails: this.filter('img')
            }
         );

         options.$thumbnails.click(function() {
            showPhoto(options, options.$thumbnails.index(this));
         });

         $(options.photoElement + ', ' + options.nextControl).click(function() {
            showPhoto(options, (options.current + 1) % options.$thumbnails.length);
         });

         $(options.previousControl).click(function() {
            showPhoto(options, options.current === 0 ? options.$thumbnails.length - 1 : options.current - 1);
         });

         $(options.firstControl).click(function() {
            showPhoto(options, 0);
         }).triggerHandler('click');

         $(options.lastControl).click(function() {
            showPhoto(options, options.$thumbnails.length - 1);
         });

         var tick;
         $(options.playControl).click(function() {
            var $this = $(this);
            if ($this.attr('src').indexOf('play') !== -1) {
               tick = window.setInterval(
                  function() {
                     $(options.nextControl).triggerHandler('click');
                  },
                  options.delay
               );
               $this.attr('src', $this.attr('src').replace('play', 'pause'));
            } else {
               window.clearInterval(tick);
               $this.attr('src', $this.attr('src').replace('pause', 'play'));
            }
         });

         return this;
      }
   };

   $.fn.jqiaPhotomatic = function(method) {
      if (methods[method]) {
         return methods[method].apply(this, Array.prototype.slice.call(arguments, 1));
      } else if ($.type(method) === 'object') {
         return methods.init.apply(this, arguments);
      } else {
         $.error('Method ' + method + ' does not exist on jQuery.jqiaPhotomatic');
      }
   };

   $.fn.jqiaPhotomatic.defaults = {
      photoElement: 'img.photomatic-photo',
      transformer: function(name) {
         return name.replace('thumbnail', 'photo');
      },
      nextControl: null,
      previousControl: null,
      firstControl: null,
      lastControl: null,
      playControl: null,
      delay: 3000
   };
})(jQuery);