<commit_before>/* jslint browser: true, jquery: true, asi: true */
/* globals google: false, Tablesort, DocumentTouch */
(function($) {
  'use strict'

  // Feature detection ////////////////////////////////////

  var reduceMotion = window.matchMedia("(prefers-reduced-motion)").matches

  // Touch: from https://github.com/Modernizr/Modernizr/blob/master/feature-detects/touchevents.js
  if (('ontouchstart' in window) || window.DocumentTouch && document instanceof DocumentTouch) {
    $('html').addClass('touch')
  }

  // Animation ////////////////////////////////////////////
  //
  // Appear-on-scroll Animation Support
  //
  // Requires:
  // Animate.css - https://daneden.github.io/animate.css/
  // jquery.appear - https://github.com/bas2k/jquery.appear/
  // jquery.countTo - https://github.com/mhuggins/jquery-countTo/
  //
  // Define animation blocks like so:
  //
  //

  //
  // Count to a number using this inside .animated like this:
  //
  //

  //       4800
  //

  //
  // The block will animate when it is scrolled into view.
  function disableAnimations() {
    $('.animated').removeClass('animated transparent')
  }

  // Stop animations on small screens, or if disabled, or if user
  // is asking to reduce motion
  if ($(window).width() < 768 || !$('body.animations-on') || reduceMotion) {
    disableAnimations()
  }

  function animate(element, animation) {
    element.addClass(animation + " opaque").removeClass('transparent')
    if (element.hasClass('counter')) {
      element.find('.timer').countTo()
    }
  }

  $('body.animations-on .animated').addClass('transparent').appear(function() {
    var element = $(this)
    var animation = element.data('animation')
    var animationDelay = element.data('delay')

    if (animationDelay) {
      setTimeout(function() {
        animate(element, animation)
      }, animationDelay)
    } else {
      animate(element, animation)
    }
  }, {accY: -150})

  // jQuery for page scrolling feature - requires jQuery Easing plugin
  if (!reduceMotion) {
    $('a.page-scroll').bind('click', function(event) {
      var anchor = $(this)
      $('html, body').stop().animate({
        scrollTop: $(anchor.attr('href')).offset().top - $('.navbar-custom').height() * 1.2
      }, 1000, 'easeInOutExpo')
      event.preventDefault()
    })
  }

  // Add print callbacks //////////////////////////////////
  window.onbeforeprint = function() {
    disableAnimations()
    $('#qrcode:empty').qrcode({width: '64', height: '64', correctLevel: 0, text: window.location.href})
  }
  if (window.matchMedia) {
    window.matchMedia('print').addListener(function(mql) {
      if (mql.matches) {
        window.onbeforeprint()
      }
    })
  }

  // Closes the Responsive Menu on Menu Item Click
  $('.navbar-collapse ul li a').click(function() {
    if ($(this).attr('class') !== 'dropdown-toggle active' &&
        $(this).attr('class') !== 'dropdown-toggle') {
      $('.navbar-toggle:visible').click()
    }
  })

  // Google Maps //////////////////////////////////////////
  if (typeof google !== 'undefined') {
    var map = null
    var mapMarker = null

    // When the window has finished loading create our google map below
    google.maps.event.addDomListener(window, 'load', function() {
      // Get the HTML DOM elements for all maps
      $('.canvas-map').each(function() {
        var mapElement = this

        // Get the marker's lat and long from the DOM
        var mapData = $(mapElement).data()
        mapMarker = new google.maps.LatLng(
          parseFloat(mapData.markerLat || -25.608539),
          parseFloat(mapData.markerLng || 134.361731)
        )

        // Basic options for a simple Google Map
        // For more options see: https://developers.google.com/maps/documentation/javascript/reference#MapOptions
        var mapOptions = {
          zoom: mapData.initialZoom || 6,
          center: mapMarker,
          mapTypeId: mapData.mapTypeId || google.maps.MapTypeId.HYBRID,
          disableDefaultUI: mapData.disableDefaultUI !== false,
          scrollwheel: mapData.scrollwheel !== false,
          draggable: mapData.draggable !== false,
          styles: [
            {featureType: 'poi.business', stylers: [{visibility: 'off'}]}
          ]
        }

        // Create the Google Map using out element and options defined above
        map = new google.maps.Map(mapElement, mapOptions)

        // Save into the window for later
        map._ourMarker = mapMarker
        if (!window.maps) {
          window.maps = {}
        }
        window.maps[mapElement.id] = map

        // Custom Map Marker icon
        var image = mapData.markerUrl || 'https://www.jcu.edu.au/__data/assets/file/0007/285460/marker.svg'  // Mega hack for quick Squiz Matrix URL
        var locationMarker = new google.maps.Marker({
          position: mapMarker,
          map: map,
          icon: image
        })
        locationMarker.addListener('click', function() {
          map.setCenter(mapMarker)
          map.setZoom(mapData.fullZoom || 16)
        })
        google.maps.event.addDomListener(window, 'resize', function() {
          map.setCenter(mapMarker)

          // If loaded in an iframe, wait and recentre
          if (window.frameElement && window.frameElement.nodeName === 'IFRAME') {
            setTimeout(function() { map.setCenter(mapMarker) }, 1000)
          }
        })
      })
    })
  }

  // Table sorting ////////////////////////////////////////
  $('table.table-sortable').each(function () { new Tablesort(this) })

  // Galleries and lightboxes /////////////////////////////
  var magnificConfig = {
    type: 'image',
    image: {
        cursor: null,
        verticalFit: true,
        titleSrc: 'data-mfp-caption'
    },
    gallery: { enabled: true }
  }

  // find every lightboxable image
  var $boxables = $('.link-gallery')

  // boxables inside a "parent" should share a lightbox gallery
  $('.link-gallery-parent').each( function(index, parent) {
    var $children = $(parent).find('.link-gallery') // this parent's boxables
    $children.magnificPopup(magnificConfig) // make a lightbox for them
    $boxables = $boxables.not($children) // remove them from the Big List
  })

  // anything left without a parent goes into "dregs" lightbox gallery
  $boxables.magnificPopup(magnificConfig)

  // Link rewriting ///////////////////////////////////////
  // Retarget external links to specific types of browser-viewable files
  $('a[href$=".pdf"],a[href$=".PDF"]').each(function() {
    // Only rewrite if we don't have a target already
    if (!this.target) {
      this.target = '_blank'
      $(this).append('')
    }
  })

})(jQuery)
<commit_msg>Don't add new window icons to btn or to links marked .no-change<commit_after>/* jslint browser: true, jquery: true, asi: true */
/* globals google: false, Tablesort, DocumentTouch */
(function($) {
  'use strict'

  // Feature detection ////////////////////////////////////

  var reduceMotion = window.matchMedia("(prefers-reduced-motion)").matches

  // Touch: from https://github.com/Modernizr/Modernizr/blob/master/feature-detects/touchevents.js
  if (('ontouchstart' in window) || window.DocumentTouch && document instanceof DocumentTouch) {
    $('html').addClass('touch')
  }

  // Animation ////////////////////////////////////////////
  //
  // Appear-on-scroll Animation Support
  //
  // Requires:
  // Animate.css - https://daneden.github.io/animate.css/
  // jquery.appear - https://github.com/bas2k/jquery.appear/
  // jquery.countTo - https://github.com/mhuggins/jquery-countTo/
  //
  // Define animation blocks like so:
  //
  //

  //
  // Count to a number using this inside .animated like this:
  //
  //

  //       4800
  //

  //
  // The block will animate when it is scrolled into view.
  function disableAnimations() {
    $('.animated').removeClass('animated transparent')
  }

  // Stop animations on small screens, or if disabled, or if user
  // is asking to reduce motion
  if ($(window).width() < 768 || !$('body.animations-on') || reduceMotion) {
    disableAnimations()
  }

  function animate(element, animation) {
    element.addClass(animation + " opaque").removeClass('transparent')
    if (element.hasClass('counter')) {
      element.find('.timer').countTo()
    }
  }

  $('body.animations-on .animated').addClass('transparent').appear(function() {
    var element = $(this)
    var animation = element.data('animation')
    var animationDelay = element.data('delay')

    if (animationDelay) {
      setTimeout(function() {
        animate(element, animation)
      }, animationDelay)
    } else {
      animate(element, animation)
    }
  }, {accY: -150})

  // jQuery for page scrolling feature - requires jQuery Easing plugin
  if (!reduceMotion) {
    $('a.page-scroll').bind('click', function(event) {
      var anchor = $(this)
      $('html, body').stop().animate({
        scrollTop: $(anchor.attr('href')).offset().top - $('.navbar-custom').height() * 1.2
      }, 1000, 'easeInOutExpo')
      event.preventDefault()
    })
  }

  // Add print callbacks //////////////////////////////////
  window.onbeforeprint = function() {
    disableAnimations()
    $('#qrcode:empty').qrcode({width: '64', height: '64', correctLevel: 0, text: window.location.href})
  }
  if (window.matchMedia) {
    window.matchMedia('print').addListener(function(mql) {
      if (mql.matches) {
        window.onbeforeprint()
      }
    })
  }

  // Closes the Responsive Menu on Menu Item Click
  $('.navbar-collapse ul li a').click(function() {
    if ($(this).attr('class') !== 'dropdown-toggle active' &&
        $(this).attr('class') !== 'dropdown-toggle') {
      $('.navbar-toggle:visible').click()
    }
  })

  // Google Maps //////////////////////////////////////////
  if (typeof google !== 'undefined') {
    var map = null
    var mapMarker = null

    // When the window has finished loading create our google map below
    google.maps.event.addDomListener(window, 'load', function() {
      // Get the HTML DOM elements for all maps
      $('.canvas-map').each(function() {
        var mapElement = this

        // Get the marker's lat and long from the DOM
        var mapData = $(mapElement).data()
        mapMarker = new google.maps.LatLng(
          parseFloat(mapData.markerLat || -25.608539),
          parseFloat(mapData.markerLng || 134.361731)
        )

        // Basic options for a simple Google Map
        // For more options see: https://developers.google.com/maps/documentation/javascript/reference#MapOptions
        var mapOptions = {
          zoom: mapData.initialZoom || 6,
          center: mapMarker,
          mapTypeId: mapData.mapTypeId || google.maps.MapTypeId.HYBRID,
          disableDefaultUI: mapData.disableDefaultUI !== false,
          scrollwheel: mapData.scrollwheel !== false,
          draggable: mapData.draggable !== false,
          styles: [
            {featureType: 'poi.business', stylers: [{visibility: 'off'}]}
          ]
        }

        // Create the Google Map using out element and options defined above
        map = new google.maps.Map(mapElement, mapOptions)

        // Save into the window for later
        map._ourMarker = mapMarker
        if (!window.maps) {
          window.maps = {}
        }
        window.maps[mapElement.id] = map

        // Custom Map Marker icon
        var image = mapData.markerUrl || 'https://www.jcu.edu.au/__data/assets/file/0007/285460/marker.svg'  // Mega hack for quick Squiz Matrix URL
        var locationMarker = new google.maps.Marker({
          position: mapMarker,
          map: map,
          icon: image
        })
        locationMarker.addListener('click', function() {
          map.setCenter(mapMarker)
          map.setZoom(mapData.fullZoom || 16)
        })
        google.maps.event.addDomListener(window, 'resize', function() {
          map.setCenter(mapMarker)

          // If loaded in an iframe, wait and recentre
          if (window.frameElement && window.frameElement.nodeName === 'IFRAME') {
            setTimeout(function() { map.setCenter(mapMarker) }, 1000)
          }
        })
      })
    })
  }

  // Table sorting ////////////////////////////////////////
  $('table.table-sortable').each(function () { new Tablesort(this) })

  // Galleries and lightboxes /////////////////////////////
  var magnificConfig = {
    type: 'image',
    image: {
        cursor: null,
        verticalFit: true,
        titleSrc: 'data-mfp-caption'
    },
    gallery: { enabled: true }
  }

  // find every lightboxable image
  var $boxables = $('.link-gallery')

  // boxables inside a "parent" should share a lightbox gallery
  $('.link-gallery-parent').each( function(index, parent) {
    var $children = $(parent).find('.link-gallery') // this parent's boxables
    $children.magnificPopup(magnificConfig) // make a lightbox for them
    $boxables = $boxables.not($children) // remove them from the Big List
  })

  // anything left without a parent goes into "dregs" lightbox gallery
  $boxables.magnificPopup(magnificConfig)

  // Link rewriting ///////////////////////////////////////
  // Retarget external links to specific types of browser-viewable files
  $('a[href$=".pdf"],a[href$=".PDF"]').not('.btn,.no-change').each(function() {
    // Only rewrite if we don't have a target already
    if (!this.target) {
      this.target = '_blank'
      $(this).append('')
    }
  })

})(jQuery)
<|endoftext|>


<commit_before>// Typeforce Archive - Firebelly
/*jshint latedef:false*/

// Good Design for Good Reason for Good Namespace
var FBSage = (function($) {

  var screen_width = 0,
      breakpoint_small = false,
      breakpoint_medium = false,
      breakpoint_large = false,
      breakpoint_array = [480,768,1200],
      $document,
      $sidebar,
      loadingTimer,
      page_at;

  function _init() {
    // touch-friendly fast clicks
    FastClick.attach(document.body);

    // Cache some common DOM queries
    $document = $(document);
    $('body').addClass('loaded');

    // Set screen size vars
    _resize();

    // Fit them vids!
    $('main').fitVids();

    _initNav();
    _initSearch();
    _initLoadMore();

    // Set up the show/hide exhibition functionality;
    // _initExhibition();

    // Inject all of our svgs so we can grab them throughout the page with <use xlink:href="#..."> commands.
    _injectSvgSprite();

    // Give mouse over behavior to exhibit listings (e.g. duo images and other elements fade away)
    _exhibitListingMouseOver();

    // Fire up the Slick sliders
    _initSliders();

    // Give the header a .scrolled class when past a certain point
    _fixHeaderOnScroll();

    // Init lazyload images
    _initImages();

    // Add classes to make up for the lack of hover event on touch devices;
    _touchOnly();

    // Esc handlers
    $(document).keyup(function(e) {
      if (e.keyCode === 27) {
        _hideNav();
        _closeSearch();
      }
    });

    // Smoothscroll links
    $('a.smoothscroll').click(function(e) {
      e.preventDefault();
      var href = $(this).attr('href');
      _scrollBody($(href));
    });

    // Scroll down to hash afer page load
    $(window).load(function() {
      if (window.location.hash) {
        _scrollBody($(window.location.hash));
      }
    });

  } // end init()

  function _scrollBody(element, duration, delay) {
    if ($('#wpadminbar').length) {
      wpOffset = $('#wpadminbar').height();
    } else {
      wpOffset = 0;
    }
    element.velocity("scroll", {
      duration: duration,
      delay: delay,
      offset: -wpOffset
    }, "easeOutSine");
  }

  function _openSearch() {
    $('.site-header').addClass('search-active');
    $('.search-field:first').focus();
    $('.search-mask').addClass('search-active');
  }
  function _closeSearch() {
    $('.site-header').removeClass('search-active');
    $('.search-mask').removeClass('search-active');
  }

 function _initSearch() {
  $('<svg class="icon-search" role="img"><use xlink:href="#icon-search"></use></svg>')
    .prependTo('.search-toggle');
  $('.search-toggle').on('click', function (e) {
    if ( $('.site-header').hasClass('search-active') ) {
      $('.search-form').submit();
    } else {
      e.preventDefault();
      _openSearch();
    }
  });
  $('.site-header').before('

');
  $('.search-mask').click(function() {
    if($(this).hasClass('search-active')) {
      _closeSearch();
    }
  });
 }

  // Unfortunately the transition to hamburger nav cannot be made smoothely with breakpoints because of the variable number of menu items.
  // We'll use this function instead to check if the menu can fit in this screen size.
  function _resizeNav() {

    //If it's open, close it.
    _hideNav();

    //How wide am I?
    var $navWidth = 100 + $('.site-header .site-nav .menu-item').length*75 + (breakpoint_medium ? 75 : 25); // Num menu-items * 75px + 75/25 site padding

    //Compare sum of that and title's width to determine hamburger or no
    var $titleWidth = $('.site-header .title').outerWidth();
    var $windowWidth = $( window ).width();
    if (($navWidth+$titleWidth)<$windowWidth){
      $('.site-nav, .menu-toggle, .search-toggle').addClass('full-nav');
    } else {
      $('.site-nav, .menu-toggle, .search-toggle').removeClass('full-nav');
    }
  }

  function _showNav() {
    $('.menu-toggle').addClass('nav-active');
    $('.site-nav').addClass('nav-active');
    $('.nav-mask').addClass('nav-active');
  }

  function _hideNav() {
    $('.menu-toggle').removeClass('nav-active');
    $('.site-nav').removeClass('nav-active');
    $('.nav-mask').removeClass('nav-active');
  }

  // Handles main nav
  function _initNav() {
    // SEO-useless nav togglers
    $('<svg class="menu-toggle menu-toggle-close icon-x" role="img"><use xlink:href="#icon-x"></use></svg>')
      .prependTo('.site-nav')
      .on('click', function(e) {
        _hideNav();
      });
    $('<svg class="menu-toggle menu-toggle-open icon-hamburger" role="img"><use xlink:href="#icon-hamburger"></use></svg>')
      .prependTo('.site-header .wrapper')
      .on('click', function(e) {
        _showNav();
      });
    _resizeNav();
      $('.site-nav').before('

');
      $('.nav-mask').click(function() {
        if($(this).hasClass('nav-active')) {
          _hideNav();
        }
      });
  }

  // Create good experience for people with no mouse's to hover by triggering a faux 'hover' class as an exhibit in the grid passes to screen center
  function _touchOnly() {
    if(Modernizr.touchevents) {
      var $exhibits = $('.exhibit-list .exhibit .exhibit-listing-info');
      $(window).scroll(function() {
        var wintop = $(window).scrollTop();
        var winhalf = wintop + $(window).height()/2;
        $exhibits.each(function() {
          var top = $(this).offset().top;
          var height = parseInt($(this).closest('.exhibit').css('padding-bottom'));
          var bottom = height + top;
          if (winhalf > top && winhalf < bottom) {
            $(this).addClass('hover');
          } else {
            $(this).removeClass('hover');
          }
        });
      });
    }
  }

  function _initImages() {
    if (breakpoint_medium) {
      $('.lazy').each( function() {
        var bigUrl = $(this).attr('data-big-img-url');
        if( bigUrl && $(this).attr('data-current-img-size')==='tiny'){
          $(this).attr('data-current-img-size','big');
          $(this).removeClass('loaded');
          $(this).attr('data-original', bigUrl);
        }
      });
    }
    $('.lazy').lazyload({
      threshold: 200,
      failure_limit : 10,
      load : function() {
        $(this).addClass('loaded');
      }
    });
    $('.slide-item .lazy').trigger('appear'); // Force load of sliders
  }

  function _initLoadMore() {
    $('<svg class="icon-load-more" role="img"><use xlink:href="#icon-load-more"></use></svg>')
      .prependTo('.load-more a');

    // Hide load more if starting on last page
    $('.load-more').each(function() {
      $load_more = $(this);
      var page = parseInt($load_more.attr('data-page-at'));
      var tot_pages = parseInt($load_more.attr('data-total-pages'));
      if ( tot_pages <= page ) {
          $load_more.addClass('hide');
      }
    });

    $document.on('click', '.load-more a', function(e) {
      e.preventDefault();
      var $load_more = $(this).closest('.load-more');
      var post_type = $load_more.attr('data-post-type') ? $load_more.attr('data-post-type') : 'exhibit';
      var exhibition_id = $load_more.attr('data-exhibition-id');
      var search_query = $load_more.attr('data-search-query');
      var orderby = $load_more.attr('data-orderby');
      var page = parseInt($load_more.attr('data-page-at'));
      var per_page = parseInt($load_more.attr('data-per-page'));
      var $more_container = $load_more.parents('main').find('.load-more-container');
      loadingTimer = setTimeout(function() { $more_container.addClass('loading'); }, 0);

      var post__not_in = [];
      //We want to exclude the posts that are currently displayed if we are a random query.
      if(orderby === 'rand') {
        $('.load-more-container .exhibit .exhibit-listing-info').each(function() {
          post__not_in.push( $(this).attr('data-id') );
        });
      }

      $.ajax({
        url: wp_ajax_url,
        method: 'post',
        data: {
          action: 'load_more_posts',
          post_type: post_type,
          exhibition_id: exhibition_id,
          search_query: search_query,
          post__not_in: post__not_in,
          orderby: orderby,
          page: page+1,
          per_page: per_page,
        },
        success: function(data) {
          var $data = $(data);
          if (loadingTimer) { clearTimeout(loadingTimer); }
          $more_container.append($data).removeClass('loading');
          $load_more.attr('data-page-at', page+1);

          // Hide load more if last page
          if ($load_more.attr('data-total-pages') <= page + 1 ) {
              $load_more.addClass('hide');
          }

          // lazyload the new images
          _initImages();
        }
      });
    });
  }

  function _fixHeaderOnScroll() {
    $(window).scroll(function() {
      var wintop = $(window).scrollTop();
      var distance = 30; //distance = breakpoint_medium ? 50 : 30;
      if (wintop > distance) {
        $('.home .site-header').addClass('scrolled');
      } else {
        $('.home .site-header').removeClass('scrolled');
      }
    });
  }

  function _resizeSliders() {
      //find the widest width to height ratio for the images from data attr
      var widestRatio = 1;
      $('.slide-item').each(function() {
        var ratio = $(this).attr('data-width-height-ratio');
        widestRatio = Math.max(ratio,widestRatio);
      });

      //calculate maximum height and width
      var maxWidth = $(window).width()*0.8;
      var maxHeightFromRatio = maxWidth * (1/widestRatio);
      var maxHeightFromScreen = $(window).height()*0.5;
      var maxHeight = Math.max(maxHeightFromScreen,maxHeightFromRatio);

      //apply
      $('.slide-item, .intro-content').css('max-height',maxHeight+'px');
      $('.slide-item').css('max-width',maxWidth+'px');

      //give slides proper width (they do not have this on their own)
      $('.slide-item').each(function() {
        var ratio = $(this).attr('data-width-height-ratio');
        var h = $(this).height();
        var w = h*ratio;
        $(this).css('width',w+'px');
      });

      //re-goto the slide we are on already (this will recenter the track)
      if($('.slider.slick-slider').length){
        var currentSlide = $('.slider.slick-slider').slick('slickCurrentSlide');
        $('.slider.slick-slider').slick('slickGoTo',currentSlide);
      }
  }

  function _sliderArrowKeys() {
    $(document).keyup(function(e) {
      if (e.keyCode === 37) { // Left arrow
        // $('.slide-item.slick-center').removeClass('slick-center');
        $('.slider').slick('slickPrev');

      }
      if (e.keyCode === 39) { // Right arrow
        // $('.slide-item.slick-center').removeClass('slick-center');
        $('.slider').slick('slickNext');
      }
    });
  }

  function _initSliders(){
    $('.slide-item').addClass('site-just-loaded');
    $('.slider').slick({
      slide: '.slide-item',
      centerMode: true,
      centerPadding: '0',
      slidesToShow: 1,
      accessibility: true,
      autoplay: true,
      autoplaySpeed: 5000,
      speed: 500,
      variableWidth: true,
      prevArrow: '
<svg class="icon-caret-left" role="img"><use xlink:href="#icon-caret-left"></use></svg>
',
      nextArrow: '
<svg class="icon-caret-right" role="img"><use xlink:href="#icon-caret-right"></use></svg>
',
    }).on('beforeChange', function(event, slick, currentSlide, nextSlide){
        $(window).scroll();
    });
    _resizeSliders();

    $(window).load(function() {
      // Move slider-nav-left to after the track, so it can appear
      $('.slider-nav-left').each(function() {
          $mySlider = $(this).closest('.slider');
          $(this).detach().appendTo($mySlider);
        }
      );

      _resizeSliders();
      window.setTimeout(function() {
        $('.site-just-loaded').removeClass('site-just-loaded');
      },0);
      _sliderArrowKeys();
    });
  }

  function _injectSvgSprite() {
    boomsvgloader.load('/app/themes/typeforce/assets/svgs/build/svgs-defs.svg');
  }

  function _exhibitListingMouseOver() {
    // For exhibit listings in the slider...
    $('.intro-slider').each(function() {
      //... the desired behavior is to hide ...
      var $this = $(this);
      var $link = $this.find('.intro-link a');
      //... the duotone image of the slide, and the global headline and update...
      var $duo = $this.find('.duo');
      var $headline = $('.headline');
      var $update = $('.update');
      var $toDisappear = $duo.add($update).add($headline);
      //... on mouseover.
      $link.mouseenter(function() {
        $toDisappear.addClass('disappeared');
      }).mouseleave(function() {
        $toDisappear.removeClass('disappeared');
      });
    });

  }

  // Track ajax pages in Analytics
  function _trackPage() {
    if (typeof ga !== 'undefined') { ga('send', 'pageview', document.location.href); }
  }

  // Track events in Analytics
  function _trackEvent(category, action) {
    if (typeof ga !== 'undefined') { ga('send', 'event', category, action); }
  }

  // Called in quick succession as window is resized
  function _resize() {
    screenWidth = document.documentElement.clientWidth;
    breakpoint_small = (screenWidth >= breakpoint_array[0]);
    breakpoint_medium = (screenWidth >= breakpoint_array[1]);
    breakpoint_large = (screenWidth >= breakpoint_array[2]);

    _resizeSliders();
    _resizeNav();
    _initImages();

  }

  // Public functions
  return {
    init: _init,
    resize: _resize,
    scrollBody: function(section, duration, delay) {
      _scrollBody(section, duration, delay);
    }
  };

})(jQuery);

// Fire up the mothership
jQuery(document).ready(FBSage.init);

// Zig-zag the mothership
jQuery(window).resize(FBSage.resize);
<commit_msg>Pause sliders on touch or click<commit_after>// Typeforce Archive - Firebelly
/*jshint latedef:false*/

// Good Design for Good Reason for Good Namespace
var FBSage = (function($) {

  var screen_width = 0,
      breakpoint_small = false,
      breakpoint_medium = false,
      breakpoint_large = false,
      breakpoint_array = [480,768,1200],
      $document,
      $sidebar,
      loadingTimer,
      page_at;

  function _init() {
    // touch-friendly fast clicks
    FastClick.attach(document.body);

    // Cache some common DOM queries
    $document = $(document);
    $('body').addClass('loaded');

    // Set screen size vars
    _resize();

    // Fit them vids!
    $('main').fitVids();

    _initNav();
    _initSearch();
    _initLoadMore();

    // Set up the show/hide exhibition functionality;
    // _initExhibition();

    // Inject all of our svgs so we can grab them throughout the page with <use xlink:href="#..."> commands.
    _injectSvgSprite();

    // Give mouse over behavior to exhibit listings (e.g. duo images and other elements fade away)
    _exhibitListingMouseOver();

    // Fire up the Slick sliders
    _initSliders();

    // Give the header a .scrolled class when past a certain point
    _fixHeaderOnScroll();

    // Init lazyload images
    _initImages();

    // Add classes to make up for the lack of hover event on touch devices;
    _touchOnly();

    // Esc handlers
    $(document).keyup(function(e) {
      if (e.keyCode === 27) {
        _hideNav();
        _closeSearch();
      }
    });

    // Smoothscroll links
    $('a.smoothscroll').click(function(e) {
      e.preventDefault();
      var href = $(this).attr('href');
      _scrollBody($(href));
    });

    // Scroll down to hash afer page load
    $(window).load(function() {
      if (window.location.hash) {
        _scrollBody($(window.location.hash));
      }
    });

  } // end init()

  function _scrollBody(element, duration, delay) {
    if ($('#wpadminbar').length) {
      wpOffset = $('#wpadminbar').height();
    } else {
      wpOffset = 0;
    }
    element.velocity("scroll", {
      duration: duration,
      delay: delay,
      offset: -wpOffset
    }, "easeOutSine");
  }

  function _openSearch() {
    $('.site-header').addClass('search-active');
    $('.search-field:first').focus();
    $('.search-mask').addClass('search-active');
  }
  function _closeSearch() {
    $('.site-header').removeClass('search-active');
    $('.search-mask').removeClass('search-active');
  }

 function _initSearch() {
  $('<svg class="icon-search" role="img"><use xlink:href="#icon-search"></use></svg>')
    .prependTo('.search-toggle');
  $('.search-toggle').on('click', function (e) {
    if ( $('.site-header').hasClass('search-active') ) {
      $('.search-form').submit();
    } else {
      e.preventDefault();
      _openSearch();
    }
  });
  $('.site-header').before('

');
  $('.search-mask').click(function() {
    if($(this).hasClass('search-active')) {
      _closeSearch();
    }
  });
 }

  // Unfortunately the transition to hamburger nav cannot be made smoothely with breakpoints because of the variable number of menu items.
  // We'll use this function instead to check if the menu can fit in this screen size.
  function _resizeNav() {

    //If it's open, close it.
    _hideNav();

    //How wide am I?
    var $navWidth = 100 + $('.site-header .site-nav .menu-item').length*75 + (breakpoint_medium ? 75 : 25); // Num menu-items * 75px + 75/25 site padding

    //Compare sum of that and title's width to determine hamburger or no
    var $titleWidth = $('.site-header .title').outerWidth();
    var $windowWidth = $( window ).width();
    if (($navWidth+$titleWidth)<$windowWidth){
      $('.site-nav, .menu-toggle, .search-toggle').addClass('full-nav');
    } else {
      $('.site-nav, .menu-toggle, .search-toggle').removeClass('full-nav');
    }
  }

  function _showNav() {
    $('.menu-toggle').addClass('nav-active');
    $('.site-nav').addClass('nav-active');
    $('.nav-mask').addClass('nav-active');
  }

  function _hideNav() {
    $('.menu-toggle').removeClass('nav-active');
    $('.site-nav').removeClass('nav-active');
    $('.nav-mask').removeClass('nav-active');
  }

  // Handles main nav
  function _initNav() {
    // SEO-useless nav togglers
    $('<svg class="menu-toggle menu-toggle-close icon-x" role="img"><use xlink:href="#icon-x"></use></svg>')
      .prependTo('.site-nav')
      .on('click', function(e) {
        _hideNav();
      });
    $('<svg class="menu-toggle menu-toggle-open icon-hamburger" role="img"><use xlink:href="#icon-hamburger"></use></svg>')
      .prependTo('.site-header .wrapper')
      .on('click', function(e) {
        _showNav();
      });
    _resizeNav();
      $('.site-nav').before('

');
      $('.nav-mask').click(function() {
        if($(this).hasClass('nav-active')) {
          _hideNav();
        }
      });
  }

  // Create good experience for people with no mouse's to hover by triggering a faux 'hover' class as an exhibit in the grid passes to screen center
  function _touchOnly() {
    if(Modernizr.touchevents) {
      var $exhibits = $('.exhibit-list .exhibit .exhibit-listing-info');
      $(window).scroll(function() {
        var wintop = $(window).scrollTop();
        var winhalf = wintop + $(window).height()/2;
        $exhibits.each(function() {
          var top = $(this).offset().top;
          var height = parseInt($(this).closest('.exhibit').css('padding-bottom'));
          var bottom = height + top;
          if (winhalf > top && winhalf < bottom) {
            $(this).addClass('hover');
          } else {
            $(this).removeClass('hover');
          }
        });
      });
    }
  }

  function _initImages() {
    if (breakpoint_medium) {
      $('.lazy').each( function() {
        var bigUrl = $(this).attr('data-big-img-url');
        if( bigUrl && $(this).attr('data-current-img-size')==='tiny'){
          $(this).attr('data-current-img-size','big');
          $(this).removeClass('loaded');
          $(this).attr('data-original', bigUrl);
        }
      });
    }
    $('.lazy').lazyload({
      threshold: 200,
      failure_limit : 10,
      load : function() {
        $(this).addClass('loaded');
      }
    });
    $('.slide-item .lazy').trigger('appear'); // Force load of sliders
  }

  function _initLoadMore() {
    $('<svg class="icon-load-more" role="img"><use xlink:href="#icon-load-more"></use></svg>')
      .prependTo('.load-more a');

    // Hide load more if starting on last page
    $('.load-more').each(function() {
      $load_more = $(this);
      var page = parseInt($load_more.attr('data-page-at'));
      var tot_pages = parseInt($load_more.attr('data-total-pages'));
      if ( tot_pages <= page ) {
          $load_more.addClass('hide');
      }
    });

    $document.on('click', '.load-more a', function(e) {
      e.preventDefault();
      var $load_more = $(this).closest('.load-more');
      var post_type = $load_more.attr('data-post-type') ? $load_more.attr('data-post-type') : 'exhibit';
      var exhibition_id = $load_more.attr('data-exhibition-id');
      var search_query = $load_more.attr('data-search-query');
      var orderby = $load_more.attr('data-orderby');
      var page = parseInt($load_more.attr('data-page-at'));
      var per_page = parseInt($load_more.attr('data-per-page'));
      var $more_container = $load_more.parents('main').find('.load-more-container');
      loadingTimer = setTimeout(function() { $more_container.addClass('loading'); }, 0);

      var post__not_in = [];
      //We want to exclude the posts that are currently displayed if we are a random query.
      if(orderby === 'rand') {
        $('.load-more-container .exhibit .exhibit-listing-info').each(function() {
          post__not_in.push( $(this).attr('data-id') );
        });
      }

      $.ajax({
        url: wp_ajax_url,
        method: 'post',
        data: {
          action: 'load_more_posts',
          post_type: post_type,
          exhibition_id: exhibition_id,
          search_query: search_query,
          post__not_in: post__not_in,
          orderby: orderby,
          page: page+1,
          per_page: per_page,
        },
        success: function(data) {
          var $data = $(data);
          if (loadingTimer) { clearTimeout(loadingTimer); }
          $more_container.append($data).removeClass('loading');
          $load_more.attr('data-page-at', page+1);

          // Hide load more if last page
          if ($load_more.attr('data-total-pages') <= page + 1 ) {
              $load_more.addClass('hide');
          }

          // lazyload the new images
          _initImages();
        }
      });
    });
  }

  function _fixHeaderOnScroll() {
    $(window).scroll(function() {
      var wintop = $(window).scrollTop();
      var distance = 30; //distance = breakpoint_medium ? 50 : 30;
      if (wintop > distance) {
        $('.home .site-header').addClass('scrolled');
      } else {
        $('.home .site-header').removeClass('scrolled');
      }
    });
  }

  function _resizeSliders() {
      //find the widest width to height ratio for the images from data attr
      var widestRatio = 1;
      $('.slide-item').each(function() {
        var ratio = $(this).attr('data-width-height-ratio');
        widestRatio = Math.max(ratio,widestRatio);
      });

      //calculate maximum height and width
      var maxWidth = $(window).width()*0.8;
      var maxHeightFromRatio = maxWidth * (1/widestRatio);
      var maxHeightFromScreen = $(window).height()*0.5;
      var maxHeight = Math.max(maxHeightFromScreen,maxHeightFromRatio);

      //apply
      $('.slide-item, .intro-content').css('max-height',maxHeight+'px');
      $('.slide-item').css('max-width',maxWidth+'px');

      //give slides proper width (they do not have this on their own)
      $('.slide-item').each(function() {
        var ratio = $(this).attr('data-width-height-ratio');
        var h = $(this).height();
        var w = h*ratio;
        $(this).css('width',w+'px');
      });

      //re-goto the slide we are on already (this will recenter the track)
      if($('.slider.slick-slider').length){
        var currentSlide = $('.slider.slick-slider').slick('slickCurrentSlide');
        $('.slider.slick-slider').slick('slickGoTo',currentSlide);
      }
  }

  function _sliderArrowKeys() {
    $(document).keyup(function(e) {
      if (e.keyCode === 37) { // Left arrow
        // $('.slide-item.slick-center').removeClass('slick-center');
        $('.slider').slick('slickPrev');

      }
      if (e.keyCode === 39) { // Right arrow
        // $('.slide-item.slick-center').removeClass('slick-center');
        $('.slider').slick('slickNext');
      }
    });
  }

  function _initSliders(){
    $('.slide-item').addClass('site-just-loaded');
    $('.slider').slick({
      slide: '.slide-item',
      centerMode: true,
      centerPadding: '0',
      slidesToShow: 1,
      accessibility: true,
      autoplay: true,
      autoplaySpeed: 5000,
      speed: 500,
      variableWidth: true,
      prevArrow: '
<svg class="icon-caret-left" role="img"><use xlink:href="#icon-caret-left"></use></svg>
',
      nextArrow: '
<svg class="icon-caret-right" role="img"><use xlink:href="#icon-caret-right"></use></svg>
',
    }).on('beforeChange', function(event, slick, currentSlide, nextSlide){
        $(window).scroll();
    });
    _resizeSliders();

    // Move slider-nav-left to after the track, so it can appear
    $('.slider-nav-left').each(function() {
        $mySlider = $(this).closest('.slider');
        $(this).detach().appendTo($mySlider);
      }
    );

    // Tie sliders to arrow keys
    _sliderArrowKeys();

    // Pause on click or touch
    $('.slide-item').on('mousedown touchstart', function() {
      $(this).closest('.slider').slick('slickPause');
    });
    $('.slide-item').on('mouseup touchend', function() {
      $(this).closest('.slider').slick('slickPlay');
    });

    $(window).load(function() {

      _resizeSliders();

      window.setTimeout(function() {
        $('.site-just-loaded').removeClass('site-just-loaded'); // Removing this to trigger a css transition
      },0);

    });
  }

  function _injectSvgSprite() {
    boomsvgloader.load('/app/themes/typeforce/assets/svgs/build/svgs-defs.svg');
  }

  function _exhibitListingMouseOver() {
    // For exhibit listings in the slider...
    $('.intro-slider').each(function() {
      //... the desired behavior is to hide ...
      var $this = $(this);
      var $link = $this.find('.intro-link a');
      //... the duotone image of the slide, and the global headline and update...
      var $duo = $this.find('.duo');
      var $headline = $('.headline');
      var $update = $('.update');
      var $toDisappear = $duo.add($update).add($headline);
      //... on mouseover.
      $link.mouseenter(function() {
        $toDisappear.addClass('disappeared');
      }).mouseleave(function() {
        $toDisappear.removeClass('disappeared');
      });
    });

  }

  // Track ajax pages in Analytics
  function _trackPage() {
    if (typeof ga !== 'undefined') { ga('send', 'pageview', document.location.href); }
  }

  // Track events in Analytics
  function _trackEvent(category, action) {
    if (typeof ga !== 'undefined') { ga('send', 'event', category, action); }
  }

  // Called in quick succession as window is resized
  function _resize() {
    screenWidth = document.documentElement.clientWidth;
    breakpoint_small = (screenWidth >= breakpoint_array[0]);
    breakpoint_medium = (screenWidth >= breakpoint_array[1]);
    breakpoint_large = (screenWidth >= breakpoint_array[2]);

    _resizeSliders();
    _resizeNav();
    _initImages();

  }

  // Public functions
  return {
    init: _init,
    resize: _resize,
    scrollBody: function(section, duration, delay) {
      _scrollBody(section, duration, delay);
    }
  };

})(jQuery);

// Fire up the mothership
jQuery(document).ready(FBSage.init);

// Zig-zag the mothership
jQuery(window).resize(FBSage.resize);
<|endoftext|>


<commit_before>(function () {
    cinema.decorators.Composite = function (rootModel) {
        return _.extend(rootModel, this);
    };

    var prototype = cinema.decorators.Composite.prototype;

    // Public methods ---------------------------------------------------------

    prototype.getSpriteSize = function () {
        if (!this._spriteSize) {
            this._spriteSize = 0;
            var that = this;
            _.each(this.getOffset(), function(value, key) {
                that._spriteSize = (that._spriteSize < value) ? value : that._spriteSize;
            });
        }
        return this._spriteSize;
    };

    prototype.getOffset = function () {
        return this.get('metadata').offset;
    };

    prototype.getImageSize = function () {
        return this.get('metadata').dimensions;
    };

    prototype.getSpriteImageSize = function () {
        var baseSize = this.getImageSize();
        return [ baseSize[0], baseSize[1] * this.getSpriteSize() ];
    };

    prototype.getDefaultPipelineSetup = function () {
        // Not stored currently in data model
        if (_.has(this.get('metadata'), 'default_pipeline')) {
            return this.get('metadata').default_pipeline;
        }

        var layers = this.get('metadata').layers;
        var firstField = _.keys(this.get('metadata').fields)[0];

        var pipeline = '';
        for (var ch in layers) {
            pipeline += layers[ch];
            pipeline += firstField;
        }

        return pipeline;
    };
}());
<commit_msg>Fixed a bug in how default pipeline is created when not in info.json.<commit_after>(function () {
    cinema.decorators.Composite = function (rootModel) {
        return _.extend(rootModel, this);
    };

    var prototype = cinema.decorators.Composite.prototype;

    // Public methods ---------------------------------------------------------

    prototype.getSpriteSize = function () {
        if (!this._spriteSize) {
            this._spriteSize = 0;
            var that = this;
            _.each(this.getOffset(), function(value, key) {
                that._spriteSize = (that._spriteSize < value) ? value : that._spriteSize;
            });
        }
        return this._spriteSize;
    };

    prototype.getOffset = function () {
        return this.get('metadata').offset;
    };

    prototype.getImageSize = function () {
        return this.get('metadata').dimensions;
    };

    prototype.getSpriteImageSize = function () {
        var baseSize = this.getImageSize();
        return [ baseSize[0], baseSize[1] * this.getSpriteSize() ];
    };

    prototype.getDefaultPipelineSetup = function () {
        // Not stored currently in data model
        if (_.has(this.get('metadata'), 'default_pipeline')) {
            return this.get('metadata').default_pipeline;
        }

        var layers = this.get('metadata').layers;
        var layerFields = this.get('metadata').layer_fields;

        var pipeline = '';
        for (var ch in layers) {
            var fieldsForLayer = layerFields[layers[ch]];
            pipeline += layers[ch];
            pipeline += fieldsForLayer[0];
        }

        return pipeline;
    };
}());
<|endoftext|>


<commit_before>var PageTransitions = (function() {

	var $main = $( '#pt-main' ),
		$pages = $main.children( 'div.pt-page' ),
		$iterate = $( '#iterateEffects' ),
		animcursor = 1,
		pagesCount = $pages.length,
		current = 0,
		isAnimating = false,
		endCurrPage = false,
		endNextPage = false,
		animEndEventNames = {
			'WebkitAnimation' : 'webkitAnimationEnd',
			'OAnimation' : 'oAnimationEnd',
			'msAnimation' : 'MSAnimationEnd',
			'animation' : 'animationend'
		},
		// animation end event name
		animEndEventName = animEndEventNames[ Modernizr.prefixed( 'animation' ) ],
		// support css animations
		support = Modernizr.cssanimations;

	function init() {

		$pages.each( function() {
			var $page = $( this );
			$page.data( 'originalClassList', $page.attr( 'class' ) );
		} );

		$pages.eq( current ).addClass( 'pt-page-current' );

		/*
		$( '#dl-menu' ).dlmenu( {
			animationClasses : { in : 'dl-animate-in-2', out : 'dl-animate-out-2' },
			onLinkClick : function( el, ev ) {
				ev.preventDefault();
				nextPage( el.data( 'animation' ) );
			}
		} );
		*/

		$iterate.on( 'click', function() {
			if( isAnimating ) {
				return false;
			}
			if( animcursor > 67 ) {
				animcursor = 1;
			}
			nextPage( animcursor );
			++animcursor;
		} );

	}

	function nextPage(options ) {
		var animation = (options.animation) ? options.animation : options;

		if( isAnimating ) {
			return false;
		}

		isAnimating = true;

		var $currPage = $pages.eq( current );

		if(options.showPage){
			if( options.showPage < pagesCount - 1 ) {
				current = options.showPage;
			}
			else {
				current = 0;
			}
		}
		else{
			if( current < pagesCount - 1 ) {
				++current;
			}
			else {
				current = 0;
			}
		}

		var $nextPage = $pages.eq( current ).addClass( 'pt-page-current' ),
			outClass = '', inClass = '';

		switch( animation ) {

			case 1:
				outClass = 'pt-page-moveToLeft';
				inClass = 'pt-page-moveFromRight';
				break;
			case 2:
				outClass = 'pt-page-moveToRight';
				inClass = 'pt-page-moveFromLeft';
				break;
			case 3:
				outClass = 'pt-page-moveToTop';
				inClass = 'pt-page-moveFromBottom';
				break;
			case 4:
				outClass = 'pt-page-moveToBottom';
				inClass = 'pt-page-moveFromTop';
				break;
			case 5:
				outClass = 'pt-page-fade';
				inClass = 'pt-page-moveFromRight pt-page-ontop';
				break;
			case 6:
				outClass = 'pt-page-fade';
				inClass = 'pt-page-moveFromLeft pt-page-ontop';
				break;
			case 7:
				outClass = 'pt-page-fade';
				inClass = 'pt-page-moveFromBottom pt-page-ontop';
				break;
			case 8:
				outClass = 'pt-page-fade';
				inClass = 'pt-page-moveFromTop pt-page-ontop';
				break;
			case 9:
				outClass = 'pt-page-moveToLeftFade';
				inClass = 'pt-page-moveFromRightFade';
				break;
			case 10:
				outClass = 'pt-page-moveToRightFade';
				inClass = 'pt-page-moveFromLeftFade';
				break;
			case 11:
				outClass = 'pt-page-moveToTopFade';
				inClass = 'pt-page-moveFromBottomFade';
				break;
			case 12:
				outClass = 'pt-page-moveToBottomFade';
				inClass = 'pt-page-moveFromTopFade';
				break;
			case 13:
				outClass = 'pt-page-moveToLeftEasing pt-page-ontop';
				inClass = 'pt-page-moveFromRight';
				break;
			case 14:
				outClass = 'pt-page-moveToRightEasing pt-page-ontop';
				inClass = 'pt-page-moveFromLeft';
				break;
			case 15:
				outClass = 'pt-page-moveToTopEasing pt-page-ontop';
				inClass = 'pt-page-moveFromBottom';
				break;
			case 16:
				outClass = 'pt-page-moveToBottomEasing pt-page-ontop';
				inClass = 'pt-page-moveFromTop';
				break;
			case 17:
				outClass = 'pt-page-scaleDown';
				inClass = 'pt-page-moveFromRight pt-page-ontop';
				break;
			case 18:
				outClass = 'pt-page-scaleDown';
				inClass = 'pt-page-moveFromLeft pt-page-ontop';
				break;
			case 19:
				outClass = 'pt-page-scaleDown';
				inClass = 'pt-page-moveFromBottom pt-page-ontop';
				break;
			case 20:
				outClass = 'pt-page-scaleDown';
				inClass = 'pt-page-moveFromTop pt-page-ontop';
				break;
			case 21:
				outClass = 'pt-page-scaleDown';
				inClass = 'pt-page-scaleUpDown pt-page-delay300';
				break;
			case 22:
				outClass = 'pt-page-scaleDownUp';
				inClass = 'pt-page-scaleUp pt-page-delay300';
				break;
			case 23:
				outClass = 'pt-page-moveToLeft pt-page-ontop';
				inClass = 'pt-page-scaleUp';
				break;
			case 24:
				outClass = 'pt-page-moveToRight pt-page-ontop';
				inClass = 'pt-page-scaleUp';
				break;
			case 25:
				outClass = 'pt-page-moveToTop pt-page-ontop';
				inClass = 'pt-page-scaleUp';
				break;
			case 26:
				outClass = 'pt-page-moveToBottom pt-page-ontop';
				inClass = 'pt-page-scaleUp';
				break;
			case 27:
				outClass = 'pt-page-scaleDownCenter';
				inClass = 'pt-page-scaleUpCenter pt-page-delay400';
				break;
			case 28:
				outClass = 'pt-page-rotateRightSideFirst';
				inClass = 'pt-page-moveFromRight pt-page-delay200 pt-page-ontop';
				break;
			case 29:
				outClass = 'pt-page-rotateLeftSideFirst';
				inClass = 'pt-page-moveFromLeft pt-page-delay200 pt-page-ontop';
				break;
			case 30:
				outClass = 'pt-page-rotateTopSideFirst';
				inClass = 'pt-page-moveFromTop pt-page-delay200 pt-page-ontop';
				break;
			case 31:
				outClass = 'pt-page-rotateBottomSideFirst';
				inClass = 'pt-page-moveFromBottom pt-page-delay200 pt-page-ontop';
				break;
			case 32:
				outClass = 'pt-page-flipOutRight';
				inClass = 'pt-page-flipInLeft pt-page-delay500';
				break;
			case 33:
				outClass = 'pt-page-flipOutLeft';
				inClass = 'pt-page-flipInRight pt-page-delay500';
				break;
			case 34:
				outClass = 'pt-page-flipOutTop';
				inClass = 'pt-page-flipInBottom pt-page-delay500';
				break;
			case 35:
				outClass = 'pt-page-flipOutBottom';
				inClass = 'pt-page-flipInTop pt-page-delay500';
				break;
			case 36:
				outClass = 'pt-page-rotateFall pt-page-ontop';
				inClass = 'pt-page-scaleUp';
				break;
			case 37:
				outClass = 'pt-page-rotateOutNewspaper';
				inClass = 'pt-page-rotateInNewspaper pt-page-delay500';
				break;
			case 38:
				outClass = 'pt-page-rotatePushLeft';
				inClass = 'pt-page-moveFromRight';
				break;
			case 39:
				outClass = 'pt-page-rotatePushRight';
				inClass = 'pt-page-moveFromLeft';
				break;
			case 40:
				outClass = 'pt-page-rotatePushTop';
				inClass = 'pt-page-moveFromBottom';
				break;
			case 41:
				outClass = 'pt-page-rotatePushBottom';
				inClass = 'pt-page-moveFromTop';
				break;
			case 42:
				outClass = 'pt-page-rotatePushLeft';
				inClass = 'pt-page-rotatePullRight pt-page-delay180';
				break;
			case 43:
				outClass = 'pt-page-rotatePushRight';
				inClass = 'pt-page-rotatePullLeft pt-page-delay180';
				break;
			case 44:
				outClass = 'pt-page-rotatePushTop';
				inClass = 'pt-page-rotatePullBottom pt-page-delay180';
				break;
			case 45:
				outClass = 'pt-page-rotatePushBottom';
				inClass = 'pt-page-rotatePullTop pt-page-delay180';
				break;
			case 46:
				outClass = 'pt-page-rotateFoldLeft';
				inClass = 'pt-page-moveFromRightFade';
				break;
			case 47:
				outClass = 'pt-page-rotateFoldRight';
				inClass = 'pt-page-moveFromLeftFade';
				break;
			case 48:
				outClass = 'pt-page-rotateFoldTop';
				inClass = 'pt-page-moveFromBottomFade';
				break;
			case 49:
				outClass = 'pt-page-rotateFoldBottom';
				inClass = 'pt-page-moveFromTopFade';
				break;
			case 50:
				outClass = 'pt-page-moveToRightFade';
				inClass = 'pt-page-rotateUnfoldLeft';
				break;
			case 51:
				outClass = 'pt-page-moveToLeftFade';
				inClass = 'pt-page-rotateUnfoldRight';
				break;
			case 52:
				outClass = 'pt-page-moveToBottomFade';
				inClass = 'pt-page-rotateUnfoldTop';
				break;
			case 53:
				outClass = 'pt-page-moveToTopFade';
				inClass = 'pt-page-rotateUnfoldBottom';
				break;
			case 54:
				outClass = 'pt-page-rotateRoomLeftOut pt-page-ontop';
				inClass = 'pt-page-rotateRoomLeftIn';
				break;
			case 55:
				outClass = 'pt-page-rotateRoomRightOut pt-page-ontop';
				inClass = 'pt-page-rotateRoomRightIn';
				break;
			case 56:
				outClass = 'pt-page-rotateRoomTopOut pt-page-ontop';
				inClass = 'pt-page-rotateRoomTopIn';
				break;
			case 57:
				outClass = 'pt-page-rotateRoomBottomOut pt-page-ontop';
				inClass = 'pt-page-rotateRoomBottomIn';
				break;
			case 58:
				outClass = 'pt-page-rotateCubeLeftOut pt-page-ontop';
				inClass = 'pt-page-rotateCubeLeftIn';
				break;
			case 59:
				outClass = 'pt-page-rotateCubeRightOut pt-page-ontop';
				inClass = 'pt-page-rotateCubeRightIn';
				break;
			case 60:
				outClass = 'pt-page-rotateCubeTopOut pt-page-ontop';
				inClass = 'pt-page-rotateCubeTopIn';
				break;
			case 61:
				outClass = 'pt-page-rotateCubeBottomOut pt-page-ontop';
				inClass = 'pt-page-rotateCubeBottomIn';
				break;
			case 62:
				outClass = 'pt-page-rotateCarouselLeftOut pt-page-ontop';
				inClass = 'pt-page-rotateCarouselLeftIn';
				break;
			case 63:
				outClass = 'pt-page-rotateCarouselRightOut pt-page-ontop';
				inClass = 'pt-page-rotateCarouselRightIn';
				break;
			case 64:
				outClass = 'pt-page-rotateCarouselTopOut pt-page-ontop';
				inClass = 'pt-page-rotateCarouselTopIn';
				break;
			case 65:
				outClass = 'pt-page-rotateCarouselBottomOut pt-page-ontop';
				inClass = 'pt-page-rotateCarouselBottomIn';
				break;
			case 66:
				outClass = 'pt-page-rotateSidesOut';
				inClass = 'pt-page-rotateSidesIn pt-page-delay200';
				break;
			case 67:
				outClass = 'pt-page-rotateSlideOut';
				inClass = 'pt-page-rotateSlideIn';
				break;

		}

		$currPage.addClass( outClass ).on( animEndEventName, function() {
			$currPage.off( animEndEventName );
			endCurrPage = true;
			if( endNextPage ) {
				onEndAnimation( $currPage, $nextPage );
			}
		} );

		$nextPage.addClass( inClass ).on( animEndEventName, function() {
			$nextPage.off( animEndEventName );
			endNextPage = true;
			if( endCurrPage ) {
				onEndAnimation( $currPage, $nextPage );
			}
		} );

		if( !support ) {
			onEndAnimation( $currPage, $nextPage );
		}

	}

	function onEndAnimation( $outpage, $inpage ) {
		endCurrPage = false;
		endNextPage = false;
		resetPage( $outpage, $inpage );
		isAnimating = false;
	}

	function resetPage( $outpage, $inpage ) {
		$outpage.attr( 'class', $outpage.data( 'originalClassList' ) );
		$inpage.attr( 'class', $inpage.data( 'originalClassList' ) + ' pt-page-current' );
	}

	init();

	return {
		init : init,
		nextPage : nextPage,
	};

})();<commit_msg>Add transition move on keypress<commit_after>var PageTransitions = (function() {

	var $main = $( '#pt-main' ),
		$pages = $main.children( 'div.pt-page' ),
		$iterate = $( '#iterateEffects' ),
		animcursor = 1,
		pagesCount = $pages.length,
		current = 0,
		isAnimating = false,
		endCurrPage = false,
		endNextPage = false,
		animEndEventNames = {
			'WebkitAnimation' : 'webkitAnimationEnd',
			'OAnimation' : 'oAnimationEnd',
			'msAnimation' : 'MSAnimationEnd',
			'animation' : 'animationend'
		},
		// animation end event name
		animEndEventName = animEndEventNames[ Modernizr.prefixed( 'animation' ) ],
		// support css animations
		support = Modernizr.cssanimations;

	function init() {

		$pages.each( function() {
			var $page = $( this );
			$page.data( 'originalClassList', $page.attr( 'class' ) );
		} );

		$pages.eq( current ).addClass( 'pt-page-current' );

		/*
		$( '#dl-menu' ).dlmenu( {
			animationClasses : { in : 'dl-animate-in-2', out : 'dl-animate-out-2' },
			onLinkClick : function( el, ev ) {
				ev.preventDefault();
				nextPage( el.data( 'animation' ) );
			}
		} );
		*/

		// Move on keypress
		$("body").on('keydown',function(e){
		  if (e.keyCode == 37) { // left
		    nextPage(58);
		  } else if (e.keyCode == 39) { // right
		  	nextPage(59);
		  }
		});

		$iterate.on( 'click', function() {
			if( isAnimating ) {
				return false;
			}
			if( animcursor > 67 ) {
				animcursor = 1;
			}
			nextPage( animcursor );
			++animcursor;
		} );

	}

	function nextPage(options ) {
		var animation = (options.animation) ? options.animation : options;

		if( isAnimating ) {
			return false;
		}

		isAnimating = true;

		var $currPage = $pages.eq( current );

		if(options.showPage){
			if( options.showPage < pagesCount - 1 ) {
				current = options.showPage;
			}
			else {
				current = 0;
			}
		}
		else{
			if( current < pagesCount - 1 ) {
				++current;
			}
			else {
				current = 0;
			}
		}

		var $nextPage = $pages.eq( current ).addClass( 'pt-page-current' ),
			outClass = '', inClass = '';

		switch( animation ) {

			case 1:
				outClass = 'pt-page-moveToLeft';
				inClass = 'pt-page-moveFromRight';
				break;
			case 2:
				outClass = 'pt-page-moveToRight';
				inClass = 'pt-page-moveFromLeft';
				break;
			case 3:
				outClass = 'pt-page-moveToTop';
				inClass = 'pt-page-moveFromBottom';
				break;
			case 4:
				outClass = 'pt-page-moveToBottom';
				inClass = 'pt-page-moveFromTop';
				break;
			case 5:
				outClass = 'pt-page-fade';
				inClass = 'pt-page-moveFromRight pt-page-ontop';
				break;
			case 6:
				outClass = 'pt-page-fade';
				inClass = 'pt-page-moveFromLeft pt-page-ontop';
				break;
			case 7:
				outClass = 'pt-page-fade';
				inClass = 'pt-page-moveFromBottom pt-page-ontop';
				break;
			case 8:
				outClass = 'pt-page-fade';
				inClass = 'pt-page-moveFromTop pt-page-ontop';
				break;
			case 9:
				outClass = 'pt-page-moveToLeftFade';
				inClass = 'pt-page-moveFromRightFade';
				break;
			case 10:
				outClass = 'pt-page-moveToRightFade';
				inClass = 'pt-page-moveFromLeftFade';
				break;
			case 11:
				outClass = 'pt-page-moveToTopFade';
				inClass = 'pt-page-moveFromBottomFade';
				break;
			case 12:
				outClass = 'pt-page-moveToBottomFade';
				inClass = 'pt-page-moveFromTopFade';
				break;
			case 13:
				outClass = 'pt-page-moveToLeftEasing pt-page-ontop';
				inClass = 'pt-page-moveFromRight';
				break;
			case 14:
				outClass = 'pt-page-moveToRightEasing pt-page-ontop';
				inClass = 'pt-page-moveFromLeft';
				break;
			case 15:
				outClass = 'pt-page-moveToTopEasing pt-page-ontop';
				inClass = 'pt-page-moveFromBottom';
				break;
			case 16:
				outClass = 'pt-page-moveToBottomEasing pt-page-ontop';
				inClass = 'pt-page-moveFromTop';
				break;
			case 17:
				outClass = 'pt-page-scaleDown';
				inClass = 'pt-page-moveFromRight pt-page-ontop';
				break;
			case 18:
				outClass = 'pt-page-scaleDown';
				inClass = 'pt-page-moveFromLeft pt-page-ontop';
				break;
			case 19:
				outClass = 'pt-page-scaleDown';
				inClass = 'pt-page-moveFromBottom pt-page-ontop';
				break;
			case 20:
				outClass = 'pt-page-scaleDown';
				inClass = 'pt-page-moveFromTop pt-page-ontop';
				break;
			case 21:
				outClass = 'pt-page-scaleDown';
				inClass = 'pt-page-scaleUpDown pt-page-delay300';
				break;
			case 22:
				outClass = 'pt-page-scaleDownUp';
				inClass = 'pt-page-scaleUp pt-page-delay300';
				break;
			case 23:
				outClass = 'pt-page-moveToLeft pt-page-ontop';
				inClass = 'pt-page-scaleUp';
				break;
			case 24:
				outClass = 'pt-page-moveToRight pt-page-ontop';
				inClass = 'pt-page-scaleUp';
				break;
			case 25:
				outClass = 'pt-page-moveToTop pt-page-ontop';
				inClass = 'pt-page-scaleUp';
				break;
			case 26:
				outClass = 'pt-page-moveToBottom pt-page-ontop';
				inClass = 'pt-page-scaleUp';
				break;
			case 27:
				outClass = 'pt-page-scaleDownCenter';
				inClass = 'pt-page-scaleUpCenter pt-page-delay400';
				break;
			case 28:
				outClass = 'pt-page-rotateRightSideFirst';
				inClass = 'pt-page-moveFromRight pt-page-delay200 pt-page-ontop';
				break;
			case 29:
				outClass = 'pt-page-rotateLeftSideFirst';
				inClass = 'pt-page-moveFromLeft pt-page-delay200 pt-page-ontop';
				break;
			case 30:
				outClass = 'pt-page-rotateTopSideFirst';
				inClass = 'pt-page-moveFromTop pt-page-delay200 pt-page-ontop';
				break;
			case 31:
				outClass = 'pt-page-rotateBottomSideFirst';
				inClass = 'pt-page-moveFromBottom pt-page-delay200 pt-page-ontop';
				break;
			case 32:
				outClass = 'pt-page-flipOutRight';
				inClass = 'pt-page-flipInLeft pt-page-delay500';
				break;
			case 33:
				outClass = 'pt-page-flipOutLeft';
				inClass = 'pt-page-flipInRight pt-page-delay500';
				break;
			case 34:
				outClass = 'pt-page-flipOutTop';
				inClass = 'pt-page-flipInBottom pt-page-delay500';
				break;
			case 35:
				outClass = 'pt-page-flipOutBottom';
				inClass = 'pt-page-flipInTop pt-page-delay500';
				break;
			case 36:
				outClass = 'pt-page-rotateFall pt-page-ontop';
				inClass = 'pt-page-scaleUp';
				break;
			case 37:
				outClass = 'pt-page-rotateOutNewspaper';
				inClass = 'pt-page-rotateInNewspaper pt-page-delay500';
				break;
			case 38:
				outClass = 'pt-page-rotatePushLeft';
				inClass = 'pt-page-moveFromRight';
				break;
			case 39:
				outClass = 'pt-page-rotatePushRight';
				inClass = 'pt-page-moveFromLeft';
				break;
			case 40:
				outClass = 'pt-page-rotatePushTop';
				inClass = 'pt-page-moveFromBottom';
				break;
			case 41:
				outClass = 'pt-page-rotatePushBottom';
				inClass = 'pt-page-moveFromTop';
				break;
			case 42:
				outClass = 'pt-page-rotatePushLeft';
				inClass = 'pt-page-rotatePullRight pt-page-delay180';
				break;
			case 43:
				outClass = 'pt-page-rotatePushRight';
				inClass = 'pt-page-rotatePullLeft pt-page-delay180';
				break;
			case 44:
				outClass = 'pt-page-rotatePushTop';
				inClass = 'pt-page-rotatePullBottom pt-page-delay180';
				break;
			case 45:
				outClass = 'pt-page-rotatePushBottom';
				inClass = 'pt-page-rotatePullTop pt-page-delay180';
				break;
			case 46:
				outClass = 'pt-page-rotateFoldLeft';
				inClass = 'pt-page-moveFromRightFade';
				break;
			case 47:
				outClass = 'pt-page-rotateFoldRight';
				inClass = 'pt-page-moveFromLeftFade';
				break;
			case 48:
				outClass = 'pt-page-rotateFoldTop';
				inClass = 'pt-page-moveFromBottomFade';
				break;
			case 49:
				outClass = 'pt-page-rotateFoldBottom';
				inClass = 'pt-page-moveFromTopFade';
				break;
			case 50:
				outClass = 'pt-page-moveToRightFade';
				inClass = 'pt-page-rotateUnfoldLeft';
				break;
			case 51:
				outClass = 'pt-page-moveToLeftFade';
				inClass = 'pt-page-rotateUnfoldRight';
				break;
			case 52:
				outClass = 'pt-page-moveToBottomFade';
				inClass = 'pt-page-rotateUnfoldTop';
				break;
			case 53:
				outClass = 'pt-page-moveToTopFade';
				inClass = 'pt-page-rotateUnfoldBottom';
				break;
			case 54:
				outClass = 'pt-page-rotateRoomLeftOut pt-page-ontop';
				inClass = 'pt-page-rotateRoomLeftIn';
				break;
			case 55:
				outClass = 'pt-page-rotateRoomRightOut pt-page-ontop';
				inClass = 'pt-page-rotateRoomRightIn';
				break;
			case 56:
				outClass = 'pt-page-rotateRoomTopOut pt-page-ontop';
				inClass = 'pt-page-rotateRoomTopIn';
				break;
			case 57:
				outClass = 'pt-page-rotateRoomBottomOut pt-page-ontop';
				inClass = 'pt-page-rotateRoomBottomIn';
				break;
			case 58:
				outClass = 'pt-page-rotateCubeLeftOut pt-page-ontop';
				inClass = 'pt-page-rotateCubeLeftIn';
				break;
			case 59:
				outClass = 'pt-page-rotateCubeRightOut pt-page-ontop';
				inClass = 'pt-page-rotateCubeRightIn';
				break;
			case 60:
				outClass = 'pt-page-rotateCubeTopOut pt-page-ontop';
				inClass = 'pt-page-rotateCubeTopIn';
				break;
			case 61:
				outClass = 'pt-page-rotateCubeBottomOut pt-page-ontop';
				inClass = 'pt-page-rotateCubeBottomIn';
				break;
			case 62:
				outClass = 'pt-page-rotateCarouselLeftOut pt-page-ontop';
				inClass = 'pt-page-rotateCarouselLeftIn';
				break;
			case 63:
				outClass = 'pt-page-rotateCarouselRightOut pt-page-ontop';
				inClass = 'pt-page-rotateCarouselRightIn';
				break;
			case 64:
				outClass = 'pt-page-rotateCarouselTopOut pt-page-ontop';
				inClass = 'pt-page-rotateCarouselTopIn';
				break;
			case 65:
				outClass = 'pt-page-rotateCarouselBottomOut pt-page-ontop';
				inClass = 'pt-page-rotateCarouselBottomIn';
				break;
			case 66:
				outClass = 'pt-page-rotateSidesOut';
				inClass = 'pt-page-rotateSidesIn pt-page-delay200';
				break;
			case 67:
				outClass = 'pt-page-rotateSlideOut';
				inClass = 'pt-page-rotateSlideIn';
				break;

		}

		$currPage.addClass( outClass ).on( animEndEventName, function() {
			$currPage.off( animEndEventName );
			endCurrPage = true;
			if( endNextPage ) {
				onEndAnimation( $currPage, $nextPage );
			}
		} );

		$nextPage.addClass( inClass ).on( animEndEventName, function() {
			$nextPage.off( animEndEventName );
			endNextPage = true;
			if( endCurrPage ) {
				onEndAnimation( $currPage, $nextPage );
			}
		} );

		if( !support ) {
			onEndAnimation( $currPage, $nextPage );
		}

	}

	function onEndAnimation( $outpage, $inpage ) {
		endCurrPage = false;
		endNextPage = false;
		resetPage( $outpage, $inpage );
		isAnimating = false;
	}

	function resetPage( $outpage, $inpage ) {
		$outpage.attr( 'class', $outpage.data( 'originalClassList' ) );
		$inpage.attr( 'class', $inpage.data( 'originalClassList' ) + ' pt-page-current' );
	}

	init();

	return {
		init : init,
		nextPage : nextPage,
	};

})();<|endoftext|>


<commit_before>/**
 * Mentor help request view page
 */

(function($) {
    'use strict';

    var CRITERIA_TYPE_OVERALL = 0;
    var CRITERIA_TYPE_SUPERLATIVE = 1;

    var table = $('table#hacks');

    var COLS = {
        'Table Number': { data: 'table_number' },
        'Hack Name': { data: 'name' }
    };

    /**
     * Formats the table html
     */
    function createTable(table, colData) {
        var tableHead = $('

');
        var tableHeadRow = tableHead.find('tr');

        Object.keys(colData).forEach(function(columnName) {
            tableHeadRow.append(''+columnName+'	');
        });

        table.append(tableHead);
        table.append('

');
    }

    /**
     * Retrieves data
     */
    function getData() {
        var dfd = $.Deferred();

        $.ajaxGet({
            url: '/api/judge/get/grades'
        })
            .done(function(data) {
                dfd.resolve(data);
            })
            .fail(function(err) {
                dfd.reject(err);
            });

        return dfd.promise();
    }

    /**
     * Populates the DataTable with help requests
     */
    function populateTable(table, colData, data) {
        var colNames = Object.keys(colData);

        table.DataTable({
            dom:
                "<'row flex-align-center flex-wrap'<'col-sm-4'l><'col-sm-4'<'flex-center'B>><'col-sm-4'f>>" +
                "<'row'<'col-sm-12'tr>>" +
                "<'row'<'col-sm-5'i><'col-sm-7'p>>",
            responsive: true,
            lengthMenu: [[25, 50, 100, -1], [25, 50, 100, 'All']],
            data: data,
            columns: $.map(colData, function(data) {
                return data;
            }),
            order: [
                [colNames.indexOf('Table Number'), 'asc']
            ],
            select: {
                style: 'single'
            },
            buttons: [
                {
                    extend: 'selected',
                    text: 'Assign Hacks',
                    className: 'btn-form btn-form-sm',
                    action: function (e, dt) {
                        var row = dt.rows({selected: true}).data()[0];
                        hackUtil.ajaxJsonSubmit({
                            url: '/api/judge/assign_hacks',
                            data: JSON.stringify({
                                max_hacks: form.find('input[name="max_hacks"]').val(),
                                max_judge_count: form.find('input[name="max_judge_count"]').val(),
                                judge_info_id: row.id
                            })
                        }).done(function(res) {
                            alert('Assigned ' + res.new_assignments  + ' new hacks to ' + row.name);
                            window.location.reload(1);
                        });
                    }
                }
            ]
        });
    }

    console.log('Loading');
    // Create page
    getData().done(function(data) {
        var crits = data['criteria_names'];
        var hack_rows = [];
        console.log(data);
        // Create columns with order;
        var crit_id_order = [];
        var OVERALL_ID = 100;
        COLS['Overall Score'] = { data: function(row) {
            if (row[OVERALL_ID]) {
                return row[OVERALL_ID]
            } else {
                return 'N/A'
            }
        }};

        Object.keys(crits[CRITERIA_TYPE_OVERALL]).forEach(function(critId) {
            crit_id_order += critId;
            COLS[crits[CRITERIA_TYPE_OVERALL][critId]] = { data: function(row) {
                if (row[critId]) {
                    return row[critId]
                } else {
                    return 'N/A'
                }
            }};
        });
        Object.keys(crits[CRITERIA_TYPE_SUPERLATIVE]).forEach(function(critId) {
            crit_id_order += critId;
            COLS[crits[CRITERIA_TYPE_SUPERLATIVE][critId]] = { data: function(row) {
                if (row[critId]) {
                    return row[critId]
                } else {
                    return 'N/A'
                }
            }};
        });

        // Summarize data
        data['graded_hacks'].forEach(function(hack_result) {
            var results = hack_result.results;
            var hData = {
                name: hack_result.hack.name,
                table_number: hack_result.hack.table_number
            };

            Object.keys(results[CRITERIA_TYPE_OVERALL]).forEach(function(critId) {
                var result = results[CRITERIA_TYPE_OVERALL][critId];
                hData[critId] = result['contribution'] + ' of ' + result['times_graded'];
            });
            Object.keys(results[CRITERIA_TYPE_SUPERLATIVE]).forEach(function(critId) {
                var result = results[CRITERIA_TYPE_SUPERLATIVE][critId];
                hData[critId] = result['contribution'] + ' of ' + result['times_graded'];
            });

            hack_rows.push(hData);
        });

        // Convert dict to ordered rows
        createTable(table, COLS);
        populateTable(table, COLS, hack_rows);
    });

})(jQuery);
<commit_msg>can maybe get overall<commit_after>/**
 * Mentor help request view page
 */

(function($) {
    'use strict';

    var CRITERIA_TYPE_OVERALL = 0;
    var CRITERIA_TYPE_SUPERLATIVE = 1;

    var table = $('table#hacks');

    var COLS = {
        'Table Number': { data: 'table_number' },
        'Hack Name': { data: 'name' }
    };

    /**
     * Formats the table html
     */
    function createTable(table, colData) {
        var tableHead = $('

');
        var tableHeadRow = tableHead.find('tr');

        Object.keys(colData).forEach(function(columnName) {
            tableHeadRow.append(''+columnName+'	');
        });

        table.append(tableHead);
        table.append('

');
    }

    /**
     * Retrieves data
     */
    function getData() {
        var dfd = $.Deferred();

        $.ajaxGet({
            url: '/api/judge/get/grades'
        })
            .done(function(data) {
                dfd.resolve(data);
            })
            .fail(function(err) {
                dfd.reject(err);
            });

        return dfd.promise();
    }

    /**
     * Populates the DataTable with help requests
     */
    function populateTable(table, colData, data) {
        var colNames = Object.keys(colData);

        table.DataTable({
            dom:
                "<'row flex-align-center flex-wrap'<'col-sm-4'l><'col-sm-4'<'flex-center'B>><'col-sm-4'f>>" +
                "<'row'<'col-sm-12'tr>>" +
                "<'row'<'col-sm-5'i><'col-sm-7'p>>",
            responsive: true,
            lengthMenu: [[25, 50, 100, -1], [25, 50, 100, 'All']],
            data: data,
            columns: $.map(colData, function(data) {
                return data;
            }),
            order: [
                [colNames.indexOf('Table Number'), 'asc']
            ],
            select: {
                style: 'single'
            },
            buttons: [
                {
                    extend: 'selected',
                    text: 'Assign Hacks',
                    className: 'btn-form btn-form-sm',
                    action: function (e, dt) {
                        var row = dt.rows({selected: true}).data()[0];
                        hackUtil.ajaxJsonSubmit({
                            url: '/api/judge/assign_hacks',
                            data: JSON.stringify({
                                max_hacks: form.find('input[name="max_hacks"]').val(),
                                max_judge_count: form.find('input[name="max_judge_count"]').val(),
                                judge_info_id: row.id
                            })
                        }).done(function(res) {
                            alert('Assigned ' + res.new_assignments  + ' new hacks to ' + row.name);
                            window.location.reload(1);
                        });
                    }
                }
            ]
        });
    }

    console.log('Loading');
    // Create page
    getData().done(function(data) {
        var crits = data['criteria_names'];
        var hack_rows = [];
        console.log(data);
        // Create columns with order;
        var crit_id_order = [];
        var OVERALL_ID = 100;

        function getDataFunc(id) {
            return function(row, type) {
                var result = row[id];
                console.log(result);

                if (type === 'display') {
                    if (result) {
                        return result['contribution'] + ' of ' + result['times_graded'];
                    } else {
                        return 'N/A'
                    }
                }

                if (result) {
                    return result['contribution'];
                }
                return 0;
            };
        }

        COLS['Overall Score'] = { data: function(row, type) {
            var result = row[OVERALL_ID];

            if (type === 'display') {
                if (result) {
                    return result['contribution'] + ' of ' + result['times_graded'];
                } else {
                    return 'N/A'
                }
            }
            if (result) {
                return result['contribution'];
            }
            return 0;
        }};

        Object.keys(crits[CRITERIA_TYPE_OVERALL]).forEach(function(id, critId) {
            crit_id_order += critId;
            COLS[crits[CRITERIA_TYPE_OVERALL][critId]] = { data: getDataFunc(critId) };
        });
        Object.keys(crits[CRITERIA_TYPE_SUPERLATIVE]).forEach(function(critId) {
            crit_id_order += critId;
            COLS[crits[CRITERIA_TYPE_SUPERLATIVE][critId]] = { data: getDataFunc(critId) };
        });

        // Summarize data
        data['graded_hacks'].forEach(function(hack_result) {
            var results = hack_result.results;
            var hData = {
                name: hack_result.hack.name,
                table_number: hack_result.hack.table_number
            };

            Object.keys(results[CRITERIA_TYPE_OVERALL]).forEach(function(critId) {
                hData[critId] = results[CRITERIA_TYPE_OVERALL][critId];;
            });
            Object.keys(results[CRITERIA_TYPE_SUPERLATIVE]).forEach(function(critId) {
                hData[critId] = results[CRITERIA_TYPE_SUPERLATIVE][critId];;
            });

            hack_rows.push(hData);
        });

        // Convert dict to ordered rows
        createTable(table, COLS);
        populateTable(table, COLS, hack_rows);
    });

})(jQuery);
<|endoftext|>


<commit_before>var $ = require('jquery');
require('../vendor/bower_components/slickgrid/lib/jquery.event.drag-2.2.js');
var m = require('mithril');
var Treebeard = require('treebeard');

function resolveToggle(item) {
        var toggleMinus = m('i.icon-minus', ' '),
            togglePlus = m('i.icon-plus', ' ');

        if (item.children.length > 0) {
            if (item.open) {
                return toggleMinus;
            }
            return togglePlus;
        }
        item.open = true;
        return '';
    }

function resolveIcon(item) {
    // this = treebeard object;
    // Item = item acted on
    if (item.children.length > 0) {
        if (item.open) {
            return m("i.icon.icon-folder-open", " ");
        }
        return m("i.icon.icon-folder-close", " ");
    } else if (item.data.kind === 'node') {
            return m("i.icon.icon-folder-close", " ");
    }
    return m("i.icon.icon-circle-blank");
}

function ProjectNotifications(data) {
    //  Treebeard version
    var tbOptions = {
        divID: 'grid',
        filesData: data,
        rowHeight : 40,         // user can override or get from .tb-row height
        resolveToggle: resolveToggle,
        paginate : false,       // Whether the applet starts with pagination or not.
        paginateToggle : false, // Show the buttons that allow users to switch between scroll and paginate.
        uploads : false,         // Turns dropzone on/off.
        resolveIcon : resolveIcon,
        columnTitles : function _conferenceColumnTitles(item, col) {
             return [
                {
                    title: "Project",
                    width: "60%",
                    sortType : "text",
                    sort : true
                },
                {
                    title: "Notification Type",
                    width : "40%",
                    sort : true

                }
            ]},
        resolveRows : function _conferenceResolveRows(item){
            var default_columns = [];

            if (item.data.kind === 'folder' || item.data.kind === 'node') {
                default_columns.push({
                    data : 'project',  // Data field name
                    folderIcons : true,
                    filter : true,
                    sortInclude : true,
                    custom : function() {
                        return m('a', { href : item.data.nodeUrl, target : '_blank' }, item.data.title );
                    }
                });
            }
            else if (item.parent().data.kind === 'folder' && item.data.kind === 'event') {
                default_columns.push(
                {
                    data : 'project',  // Data field name
                    folderIcons : true,
                    filter : true,
                    sortInclude : true,
                    custom : function(item, col) {
                        return item.data.description;

                    }
                },
                {
                    data : 'notificationType',  // Data field name
                    folderIcons : false,
                    filter : false,
                    custom : function(item, col) {
                        return m("div[style='padding-right:10px']",
                            [m("select.form-control", {
                                id: item.parent().data.node_id,
                                name: item.data.title,
                                onchange: function(ev) {
                                    item.data.notificationType = ev.target.value;
                                }},
                                [
                                    m("option", {value: "none", selected : item.data.notificationType === "none" ? "selected": ""}, "None"),
                                    m("option", {value: "email_transactional", selected : item.data.notificationType === "email_transactional" ? "selected": ""}, "Emails"),
                                    m("option", {value: "email_digest", selected : item.data.notificationType === "email_digest" ? "selected": ""}, "Email Digest")
                            ])
                        ]);
                    }
                });
            }
            else {
                default_columns.push(
                {
                    data : 'project',  // Data field name
                    folderIcons : true,
                    filter : true,
                    sortInclude : true,
                    custom : function() {
                        return item.data.description;

                    }
                },
                {
                    data : 'notificationType',  // Data field name
                    folderIcons : false,
                    filter : false,
                    custom : function() {
                        return  m("div[style='padding-right:10px']",
                            [m("select.form-control", {
                                id: item.parent().data.node_id,
                                name: item.data.title,
                                onchange: function(ev) {
                                    item.data.notificationType = ev.target.value;
                                }},
                                [
                                    m("option", {value: "adopt_parent", selected: item.data.notificationType === "adopt_parent" ? "selected" : ""}, "Adopt setting from parent project"),
                                    m("option", {value: "none", selected : item.data.notificationType === "none" ? "selected": ""}, "None"),
                                    m("option", {value: "email_transactional",  selected : item.data.notificationType === "email_transactional" ? "selected": ""}, "Emails"),
                                    m("option", {value: "email_digest", selected : item.data.notificationType === "email_digest" ? "selected": ""}, "Email Digest")
                            ])
                        ])
                    }
                });
            }

            return default_columns;
        },
        sortButtonSelector : {
            up : 'i.icon-chevron-up',
            down : 'i.icon-chevron-down'
        },
        showFilter : false,     // Gives the option to filter by showing the filter box.
        allowMove : false,       // Turn moving on or off.
        hoverClass : 'fangorn-hover'
    };
    var grid = new Treebeard(tbOptions);
}

module.exports = ProjectNotifications;
<commit_msg>Open top-level folders & children that are not default onload<commit_after>var $ = require('jquery');
require('../vendor/bower_components/slickgrid/lib/jquery.event.drag-2.2.js');
var m = require('mithril');
var Treebeard = require('treebeard');

function resolveToggle(item) {
        var toggleMinus = m('i.icon-minus', ' '),
            togglePlus = m('i.icon-plus', ' ');

        if (item.children.length > 0) {
            if (item.open) {
                return toggleMinus;
            }
            return togglePlus;
        }
        item.open = true;
        return '';
    }

function resolveIcon(item) {
    // this = treebeard object;
    // Item = item acted on
    if (item.children.length > 0) {
        if (item.open) {
            return m("i.icon.icon-folder-open", " ");
        }
        return m("i.icon.icon-folder-close", " ");
    } else if (item.data.kind === 'node') {
            return m("i.icon.icon-folder-close", " ");
    }
    return m("i.icon.icon-circle-blank");
}

function expandOnLoad() {
    for (var i = 0; i < this.treeData.children.length; i++) {
        var parent = this.treeData.children[i];
        this.updateFolder(null, parent);
        for (var j = 0; j < parent.children.length; j++) {
            var child = parent.children[j];
            if (child.data.kind !== 'event') {
               for (var k = 0; k < child.children.length; k++)
                    if (child.children[k].data.notificationType !== "adopt_parent") {
                        this.updateFolder(null, child);
                }
            }
        }
    }
}

function ProjectNotifications(data) {
    //  Treebeard version
    var tbOptions = {
        divID: 'grid',
        filesData: data,
        rowHeight : 40,         // user can override or get from .tb-row height
        resolveToggle: resolveToggle,
        paginate : false,       // Whether the applet starts with pagination or not.
        paginateToggle : false, // Show the buttons that allow users to switch between scroll and paginate.
        uploads : false,         // Turns dropzone on/off.
        resolveIcon : resolveIcon,
        onload: function () {
            var tb = this;
            expandOnLoad.call(tb);
        },
        columnTitles : function _conferenceColumnTitles(item, col) {
             return [
                {
                    title: "Project",
                    width: "60%",
                    sortType : "text",
                    sort : true
                },
                {
                    title: "Notification Type",
                    width : "40%",
                    sort : false

                }
            ]},
        resolveRows : function _conferenceResolveRows(item){
            var default_columns = [];

            if (item.data.kind === 'folder' || item.data.kind === 'node') {
                default_columns.push({
                    data : 'project',  // Data field name
                    folderIcons : true,
                    filter : true,
                    sortInclude : true,
                    custom : function() {
                        return m('a', { href : item.data.nodeUrl, target : '_blank' }, item.data.title );
                    }
                });
            }
            else if (item.parent().data.kind === 'folder' && item.data.kind === 'event') {
                default_columns.push(
                {
                    data : 'project',  // Data field name
                    folderIcons : true,
                    filter : true,
                    sortInclude : true,
                    custom : function(item, col) {
                        return item.data.description;

                    }
                },
                {
                    data : 'notificationType',  // Data field name
                    folderIcons : false,
                    filter : false,
                    custom : function(item, col) {
                        return m("div[style='padding-right:10px']",
                            [m("select.form-control", {
                                id: item.parent().data.node_id,
                                name: item.data.title,
                                onchange: function(ev) {
                                    item.data.notificationType = ev.target.value;
                                }},
                                [
                                    m("option", {value: "none", selected : item.data.notificationType === "none" ? "selected": ""}, "None"),
                                    m("option", {value: "email_transactional", selected : item.data.notificationType === "email_transactional" ? "selected": ""}, "Emails"),
                                    m("option", {value: "email_digest", selected : item.data.notificationType === "email_digest" ? "selected": ""}, "Email Digest")
                            ])
                        ]);
                    }
                });
            }
            else {
                default_columns.push(
                {
                    data : 'project',  // Data field name
                    folderIcons : true,
                    filter : true,
                    sortInclude : true,
                    custom : function() {
                        return item.data.description;

                    }
                },
                {
                    data : 'notificationType',  // Data field name
                    folderIcons : false,
                    filter : false,
                    custom : function() {
                        return  m("div[style='padding-right:10px']",
                            [m("select.form-control", {
                                id: item.parent().data.node_id,
                                name: item.data.title,
                                onchange: function(ev) {
                                    item.data.notificationType = ev.target.value;
                                }},
                                [
                                    m("option", {value: "adopt_parent", selected: item.data.notificationType === "adopt_parent" ? "selected" : ""}, "Adopt setting from parent project"),
                                    m("option", {value: "none", selected : item.data.notificationType === "none" ? "selected": ""}, "None"),
                                    m("option", {value: "email_transactional",  selected : item.data.notificationType === "email_transactional" ? "selected": ""}, "Emails"),
                                    m("option", {value: "email_digest", selected : item.data.notificationType === "email_digest" ? "selected": ""}, "Email Digest")
                            ])
                        ])
                    }
                });
            }

            return default_columns;
        },
        sortButtonSelector : {
            up : 'i.icon-chevron-up',
            down : 'i.icon-chevron-down'
        },
        showFilter : false,     // Gives the option to filter by showing the filter box.
        allowMove : false,       // Turn moving on or off.
        hoverClass : 'fangorn-hover'
    };
    var grid = new Treebeard(tbOptions);
}

module.exports = ProjectNotifications;
<|endoftext|>