Difference between revisions of "Team:CityU HK/Design"

Line 791: Line 791:
 
var IS_ARCHIVE = 1;
 
var IS_ARCHIVE = 1;
 
 
(function(jQuery){
+
jQuery(function($) {
function initFlyouts(){
+
 
initPublishedFlyoutMenus(
+
  // Mobile sidebars
[{"id":"125179881719007230","title":"Home","url":"index.html","target":""},{"id":"117564151509922601","title":"Team","url":"team.html","target":""},{"id":"392475496104510282","title":"Project","url":"project.html","target":""},{"id":"719611068520302903","title":"Characterisation","url":"characterisation.html","target":""},{"id":"375771293147075277","title":"Attributions","url":"attributions.html","target":""},{"id":"290391284397012185","title":"Collaboration","url":"collaboration.html","target":""},{"id":"595526209520916103","title":"Human Practices","url":"human-practices.html","target":""}],
+
  $.fn.expandableSidebar = function(expandedClass) {
"117564151509922601",
+
    var $me = this;
"<li class=\"wsite-menu-item-wrap\"><a href=\"#\"class=\"wsite-menu-item\">{{title}}<\/a><\/li>",
+
 
'active',
+
    $me.on('click', function() {
false,
+
      if(!$me.hasClass(expandedClass)) {
{"navigation\/flyout\/list":"{{!\n\tNOTES:\n\t- \"wsite-menu-wrap\" required on submenu wrapper\n\t- \"wsite-menu\" required on submenu element\n}}\n\n<div class=\"wsite-menu-wrap\" style=\"display:none\">\n\t<ul class=\"wsite-menu\">\n\t\t{{#children}}{{> navigation\/flyout\/item}}{{\/children}}\n\t<\/ul>\n<\/div>\n","navigation\/flyout\/item":"{{!\n\tNOTES:\n\t- an id and \"wsite-menu-subitem-wrap\" class are required on the item wrap\n\t- a \"wsite-menu-subitem\" class is required on the item link\n}}\n\n<li {{#id}}id=\"{{id}}\"{{\/id}}\n\tclass=\"wsite-menu-subitem-wrap {{#is_current}}wsite-nav-current{{\/is_current}}\"\n\t>\n\t<a href=\"{{url}}\"\n\t\t{{#target}}target=\"{{target}}\"{{\/target}}\n\t\tclass=\"wsite-menu-subitem\"\n\t\t>\n\t\t<span class=\"wsite-menu-title\">\n\t\t\t{{{title_html}}}\n\t\t<\/span>{{#has_children}}<span class=\"wsite-menu-arrow\">&gt;<\/span>{{\/has_children}}\n\t<\/a>\n\t{{#has_children}}{{> navigation\/flyout\/list}}{{\/has_children}}\n<\/li>\n"},
+
        $me.addClass(expandedClass);
{}
+
      } else {
)
+
        $me.removeClass(expandedClass);
}
+
      }
if (jQuery) {
+
    });
jQuery(document).ready(function() { jQuery(initFlyouts); });
+
  }
}else{
+
 
if (Prototype.Browser.IE) window.onload = initFlyouts;
+
  // Interval loop
else document.observe('dom:loaded', initFlyouts);
+
  $.fn.intervalLoop = function(condition, action, duration, limit) {
}
+
    var counter = 0;
})(window._W && _W.jQuery)
+
    var looper = setInterval(function(){
 +
      if (counter >= limit || $.fn.checkIfElementExists(condition)) {
 +
        clearInterval(looper);
 +
      } else {
 +
        action();
 +
        counter++;
 +
      }
 +
    }, duration);
 +
  }
 +
 
 +
  // Check if element exists
 +
  $.fn.checkIfElementExists = function(selector) {
 +
    return $(selector).length;
 +
  }
 +
 
 +
  var parisController = {
 +
 
 +
    init: function(opts) {
 +
      var base = this;
 +
 
 +
      // Add classes to elements
 +
      base._addClasses();
 +
 
 +
      setTimeout(function(){
 +
        base._checkCartItems();
 +
        base._attachEvents();
 +
      }, 1000);
 +
    },
 +
 
 +
    _addClasses: function() {
 +
      var base = this;
 +
 
 +
      // Add fade in class to nav + logo
 +
      $('.landing-page').addClass('fade-in');
 +
 
 +
      // Add class to nav items with subnav
 +
      $('.wsite-menu-default').find('li.wsite-menu-item-wrap').each(function(){
 +
        var $me = $(this);
 +
 
 +
        if($me.children('.wsite-menu-wrap').length > 0) {
 +
 
 +
          $me.addClass('has-submenu');
 +
          $('<span class="icon-caret"></span>').insertAfter($me.children('a.wsite-menu-item'));
 +
        }
 +
      });
 +
 
 +
      // ADd class to subnav items with subnav
 +
      $('.wsite-menu').find('li.wsite-menu-subitem-wrap').each(function(){
 +
        var $me = $(this);
 +
 
 +
        if($me.children('.wsite-menu-wrap').length > 0) {
 +
 
 +
          $me.addClass('has-submenu');
 +
          $('<span class="icon-caret"></span>').insertAfter($me.children('a.wsite-menu-subitem'));
 +
        }
 +
      });
 +
 
 +
      // Keep subnav open if submenu item is active
 +
      $('.wsite-menu-wrap').find('li.wsite-menu-subitem-wrap').each(function(){
 +
        var $me = $(this);
 +
 
 +
        if($me.hasClass('wsite-nav-current')) {
 +
          $me.parents().addClass('open');
 +
        }
 +
      });
 +
 
 +
      // Add placeholder text to inputs
 +
      $('.wsite-form-sublabel').each(function(){
 +
        var sublabel = $(this).text();
 +
        $(this).prev('.wsite-form-input').attr('placeholder', sublabel);
 +
      });
 +
 
 +
      // Add fullwidth class to gallery thumbs if less than 6
 +
      $('.imageGallery').each(function(){
 +
        if ($(this).children('div').length <= 6) {
 +
          $(this).children('div').addClass('fullwidth-mobile');
 +
        }
 +
      });
 +
    },
 +
 
 +
    _checkCartItems: function() {
 +
      var base = this;
 +
     
 +
      if($('#wsite-mini-cart').find('li.wsite-product-item').length > 0) {
 +
        $('body').addClass('cart-full');
 +
      } else {
 +
        $('body').removeClass('cart-full');
 +
      }
 +
    },
 +
 
 +
    _moveLogin: function() {
 +
      var loginDetach = $('#member-login').detach();
 +
      $('.mobile-nav .wsite-menu-default li:last-child').after(loginDetach);
 +
    },
 +
 
 +
    _attachEvents: function() {
 +
      var base = this;
 +
 
 +
      // Move cart + login
 +
      if ($(window).width() <= 992) {
 +
        $.fn.intervalLoop('.mobile-nav #member-login', base._moveLogin, 800, 5);
 +
      }
 +
 
 +
      // Subnav toggle
 +
      $('li.has-submenu').each(function(){
 +
        var $me = $(this);
 +
        var caret = $me.children('span.icon-caret');
 +
 
 +
        caret.on('click', function(){         
 +
          if($me.children('.wsite-menu-wrap.open').length > 0) {
 +
            caret.siblings('.wsite-menu-wrap').removeClass('open');
 +
          } else {
 +
            caret.siblings('.wsite-menu-wrap').addClass('open');
 +
          }
 +
        });
 +
      });
 +
 
 +
      // Scroll on landing page
 +
      $('#contentArrow').on('click', function() {
 +
        $('html, body').animate({
 +
          scrollTop: $('.main-wrap').offset().top - $('.paris-header').outerHeight()
 +
        }, 500);
 +
      });
 +
 
 +
      // Store category dropdown
 +
      $('.wsite-com-sidebar').expandableSidebar('sidebar-expanded');
 +
 
 +
      // Search filters dropdown
 +
      $('#wsite-search-sidebar').expandableSidebar('sidebar-expanded');
 +
 
 +
      // Init fancybox swipe on mobile
 +
      if ('ontouchstart' in window) {
 +
        $('body').on('click', 'a.w-fancybox', function() {
 +
          base._initSwipeGallery();
 +
        });
 +
      }
 +
    },
 +
 
 +
    _initSwipeGallery: function() {
 +
      var base = this;
 +
 
 +
      setTimeout(function(){
 +
        var touchGallery = document.getElementsByClassName('fancybox-wrap')[0];
 +
        var mc = new Hammer(touchGallery);
 +
        mc.on("panleft panright", function(ev) {
 +
          if (ev.type == "panleft") {
 +
            $("a.fancybox-next").trigger("click");
 +
          } else if (ev.type == "panright") {
 +
            $("a.fancybox-prev").trigger("click");
 +
          }
 +
          base._initSwipeGallery();
 +
        });
 +
      }, 500);
 +
    }
 +
  }  
 +
 
 +
 
 +
  $(document).ready(function(){
 +
    parisController.init();
 +
  });
 +
});
 +
 
  
 
</script>
 
</script>

Revision as of 04:22, 27 August 2015

Team - iGEM2015 wiki