{"size": 2079, "ext": "js", "max_stars_repo_path": "app/assets/js/menu.js", "max_stars_repo_name": "codingphil/dmpster", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "app/assets/js/menu.js", "max_issues_repo_name": "codingphil/dmpster", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "app/assets/js/menu.js", "max_forks_repo_name": "codingphil/dmpster", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 31.0298507463, "max_line_length": 95, "alphanum_fraction": 0.556036556}
define("menu", ['jquery'],
function($) {
  //Create a clone of the menu, right next to original.
  $('.menu').addClass('menu-original')
    .clone()
    .hide()
    .insertAfter('.menu-original')
    .addClass('cloned')
    .removeClass('menu-original')
    .css('position','fixed')
    .css('left','0')
    .css('top','0');

  $('.menu-original > .logo').hide();

  stickMenu();
  jQuery( window ).resize(function() {stickMenu();});
  jQuery( window ).scroll(function() {stickMenu();});

  $( "#search-form" ).on( "submit", function(event) {
    event.preventDefault();
    var searchText = $('#search').val();
    window.location.href = '/dmpster/search/' + encodeURIComponent(searchText);
  });

  function stickMenu() {

    var orgElementPos = $('.menu-original').offset();
    if(!orgElementPos) return;
    
    orgElementTop = orgElementPos.top;

    stickyTop = 0;


    if ($(window).scrollTop() >= (orgElementTop - stickyTop)) {
      // scrolled past the original position; now only show the cloned, sticky element.

      if($('.menu-original').css('visibility') === 'visible') {
        // Cloned element should always have same left position and width as original element.
        orgElement = $('.menu-original');
        coordsOrgElement = orgElement.offset();
        leftOrgElement = coordsOrgElement.left;
        widthOrgElement = orgElement.width();

        $('.cloned').css('left',leftOrgElement+'px')
          .css('top',stickyTop+'px')
          .css('width',widthOrgElement+'px')
          .show();
        $('.menu-original').css('visibility','hidden');
        var logo = $('.cloned > .logo');
        logo.animate({ marginLeft: '0' }, 500);
      }
    } else {
      // not scrolled past the menu; only show the original menu.
      if($('.cloned').is(':visible')) {
        $('.cloned > .logo').animate({ marginLeft: '-5em' }, 100, 'swing', function() {
          $('.cloned').hide();
          $('.menu-original').css('visibility','visible');
        });

      }
    }
  }
}
);
