{"size": 2702, "ext": "js", "max_stars_repo_path": "js/pagify.js", "max_stars_repo_name": "kevinelam/hello-03", "max_stars_repo_stars_event_min_datetime": "2018-07-08T18:59:45.000Z", "max_stars_repo_stars_event_max_datetime": "2018-07-08T18:59:45.000Z", "max_issues_repo_path": "js/pagify.js", "max_issues_repo_name": "kevinelam/sandbox", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "js/pagify.js", "max_forks_repo_name": "kevinelam/sandbox", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": 1, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 32.5542168675, "max_line_length": 129, "alphanum_fraction": 0.5914137676}
/*
 * Pagify - A jquery plugin for effortlessly creating single page web sites.
 *
 * Licensed under the MIT:
 * http://www.opensource.org/licenses/mit-license.php
 *
 * Copyright (c) 2011, Chris Polis
 */

(function($) {
  $.fn.pagify = function(options) {
    var self = this;

    this.defaults = {
      'pages': [],
      'default': null,
      'animation': 'show',
      'animationSpeed': 'normal',
      'animationOut': 'hide',
      'animationOutSpeed': 0,
      'onChange': function (page) {},
      'cache': false,
      'basePagePath': '//kevinelam.github.io/sandbox/'
    };
    this.settings = $.extend({}, this.defaults, options);

    // Run after loading if caching, otherwise run immediately
    var runAfterLoading = function() {
      self.switchPage = function(page) {
        // Page is selected from: passed in value, window.location, default
        if(!page) {
          page = window.location.hash.replace('#','') || self.settings['default'];
        }

        if(self.settings.cache) {
          // Load page content from cache
          $(self)[self.settings.animationOut](self.settings.animationOutSpeed, function() {
            $(self).html(self.pages[page])[self.settings.animation](self.settings.animationSpeed);
          })
          self.settings.onChange(page);
        }
        else {
          // Fetch page content
          $.get(self.settings.basePagePath+page+'.html', function(content) {
            $(self)[self.settings.animationOut](self.settings.animationOutSpeed, function() {
              $(self).html(content)[self.settings.animation](self.settings.animationSpeed);
            })
            self.settings.onChange(page);
          }, 'text');
        }
      }

      // Respond to hash changes
      $(window).bind('hashchange', function() {
        self.switchPage();
      });

      // Load initial page - current hash or default page
      if(window.location.hash) self.switchPage();
      else if(self.settings['default']) self.switchPage(self.settings['default']);
    };

    // Clean our base page path. Ensure it has a trailing slash.
    if (self.settings.basePagePath.indexOf('/', self.settings.basePagePath.length - 2) === -1) self.settings.basePagePath += '/';

    // Cache pages
    if(self.settings.cache) {
      self.pages = {};
      var pageLoads = self.settings.pages.length;
      $.each(self.settings.pages, function(ndx, page) {
        $.get(self.settings.basePagePath+page+'.html', function(content) {
          self.pages[page] = content;
          pageLoads--;
          //alert(pageLoads);
          if(!pageLoads) runAfterLoading();
        }, 'text');
      });
    } 
    else runAfterLoading();
  };

})(jQuery);
