Team:UT-Tokyo/Templates/BeginContent

From 2011.igem.org

(Difference between revisions)
Line 233: Line 233:
   margin: 0;
   margin: 0;
   padding-bottom: 3px;
   padding-bottom: 3px;
-
  cursor: pointer;
 
}
}
#navi #menu ul li a{
#navi #menu ul li a{
Line 312: Line 311:
   google.load("jquery", "1");
   google.load("jquery", "1");
</script>
</script>
 +
 +
<script type="text/javascript">
 +
/*
 +
* jQuery hashchange event - v1.3 - 7/21/2010
 +
* http://benalman.com/projects/jquery-hashchange-plugin/
 +
*
 +
* Copyright (c) 2010 "Cowboy" Ben Alman
 +
* Dual licensed under the MIT and GPL licenses.
 +
* http://benalman.com/about/license/
 +
*/
 +
(function($,e,b){var c="hashchange",h=document,f,g=$.event.special,i=h.documentMode,d="on"+c in e&&(i===b||i>7);function a(j){j=j||location.href;return"#"+j.replace(/^[^#]*#?(.*)$/,"$1")}$.fn[c]=function(j){return j?this.bind(c,j):this.trigger(c)};$.fn[c].delay=50;g[c]=$.extend(g[c],{setup:function(){if(d){return false}$(f.start)},teardown:function(){if(d){return false}$(f.stop)}});f=(function(){var j={},p,m=a(),k=function(q){return q},l=k,o=k;j.start=function(){p||n()};j.stop=function(){p&&clearTimeout(p);p=b};function n(){var r=a(),q=o(m);if(r!==m){l(m=r,q);$(e).trigger(c)}else{if(q!==m){location.href=location.href.replace(/#.*/,"")+q}}p=setTimeout(n,$.fn[c].delay)}$.browser.msie&&!d&&(function(){var q,r;j.start=function(){if(!q){r=$.fn[c].src;r=r&&r+a();q=$('<iframe tabindex="-1" title="empty"/>').hide().one("load",function(){r||l(a());n()}).attr("src",r||"javascript:0").insertAfter("body")[0].contentWindow;h.onpropertychange=function(){try{if(event.propertyName==="title"){q.document.title=h.title}}catch(s){}}}};j.stop=k;o=function(){return a(q.location.href)};l=function(v,s){var u=q.document,t=$.fn[c].domain;if(v!==s){u.title=h.title;u.open();t&&u.write('<script>document.domain="'+t+'"<\/script>');u.close();q.location.hash=v}}})();return j})()})(jQuery,this);
 +
</script>
 +
<script src="http://igem-ut.net/2011/jquery.nivo.slider_mod.js" type="text/javascript"></script>
<script src="http://igem-ut.net/2011/jquery.nivo.slider_mod.js" type="text/javascript"></script>
<script src="http://igem-ut.net/2011/jquery.blockUI.js" type="text/javascript"></script>
<script src="http://igem-ut.net/2011/jquery.blockUI.js" type="text/javascript"></script>
Line 344: Line 356:
UT_Tokyo.hasWebGL = !!window.WebGLRenderingContext;
UT_Tokyo.hasWebGL = !!window.WebGLRenderingContext;
-
UT_Tokyo.useAjaxLoading = !!(document.location.href.match('Team:UT-Tokyo/?$'));
+
UT_Tokyo.useAjaxLoading = true;//!!(document.location.href.match('Team:UT-Tokyo/?$'));
 +
UT_Tokyo.needHandling = true;
 +
UT_Tokyo.currentUrl = null;
UT_Tokyo.menuMap = UT_Tokyo.menuMap || {};
UT_Tokyo.menuMap = UT_Tokyo.menuMap || {};
UT_Tokyo.currentMenuEntry = UT_Tokyo.currentMenuEntry != null ? UT_Tokyo.currentMenuEntry : -1;
UT_Tokyo.currentMenuEntry = UT_Tokyo.currentMenuEntry != null ? UT_Tokyo.currentMenuEntry : -1;
-
 
-
UT_Tokyo.transit = function(toUrl) {
 
-
  // toUrl must start with '2011.igem.org/Team:UT-Tokyo'
 
-
  fullPageName = toUrl.match('2011.igem.org/(Team:UT-Tokyo.*)$');
 
-
  if (!fullPageName) {
 
-
    console.log('invalid url');
 
-
    return;
 
-
  }
 
-
  $('#pageContent').block();
 
-
  $.get(toUrl, function(html){
 
-
    var $new_page = $(html);
 
-
    // content
 
-
    $('#pageContent').html($('#pageContent', $new_page).html());
 
-
   
 
-
    // title
 
-
    var matches = html.match(/<title>(.*?)<\/title>/);
 
-
    document.title = matches[1];
 
-
   
 
-
    // title on the header
 
-
    $('#pageTitle').html($('#pageTitle', $new_page).html());
 
-
   
 
-
    // menu
 
-
    this.initMenu(fullPageName);
 
-
   
 
-
    // unblock
 
-
    $('#pageContent').unblock();
 
-
  });
 
-
};
 
UT_Tokyo.menuIndexFromFullPageName = function(fullPageName) {
UT_Tokyo.menuIndexFromFullPageName = function(fullPageName) {
Line 413: Line 399:
UT_Tokyo.leaveMenuEntry = function(idx) {
UT_Tokyo.leaveMenuEntry = function(idx) {
-
   if ((idx != this.currentMenuEntry) * (idx != 2)) { // using * instead of &&
+
   if ((idx != this.currentMenuEntry) * (idx != 2)) { // using * instead of &amp;&amp;
     $(this.menuMap[idx]).css('background-image', 'none');
     $(this.menuMap[idx]).css('background-image', 'none');
   }
   }
Line 422: Line 408:
   var idx = this.menuIndexFromFullPageName(fullPageName);
   var idx = this.menuIndexFromFullPageName(fullPageName);
   this.selectMenuEntry(idx);
   this.selectMenuEntry(idx);
 +
};
 +
 +
UT_Tokyo.transit = function(toUrl) {
 +
  // toUrl must start with '2011.igem.org/Team:UT-Tokyo'
 +
  var fullPageName = toUrl.match(/2011.igem.org\/(Team:UT-Tokyo.*)$/);
 +
  if (!fullPageName) {
 +
    console.log('invalid url');
 +
    return;
 +
  }
 +
  $('#pageContent').block({'message': null});
 +
  var title_timer = setInterval(function() {
 +
    h = $('#pageTitle').html();
 +
    m = h.match(/Loading(\.*)$/);
 +
    if (m) {
 +
      l = m[1].length;
 +
      if (l < 5) h += '.'
 +
      else h = 'Loading.';
 +
    } else {
 +
      h = 'Loading.';
 +
    }
 +
    $('#pageTitle').html(h);
 +
  }, 80);
 +
  $.ajax({
 +
    'url': toUrl,
 +
    'dataType': 'html',
 +
    'success': function(html){
 +
      var $new_page = $(html);
 +
      // content
 +
      $('#pageContent').html($('#pageContent', $new_page).html());
 +
   
 +
      // title
 +
      var matches = html.match(/<title>(.*?)<\/title>/);
 +
      document.title = matches[1];
 +
   
 +
      // title on the header
 +
      clearInterval(title_timer);
 +
      $('#pageTitle').html($('#pageTitle', $new_page).html());
 +
      // menu
 +
      UT_Tokyo.initMenu(fullPageName);
 +
   
 +
      // unblock
 +
      $('#pageContent').unblock();
 +
     
 +
      UT_Tokyo.needHandling = true;
 +
     
 +
    },
 +
    'error': function(XMLHttpRequest, textStatus, errorThrown) {
 +
      clearInterval(title_timer);
 +
    }
 +
  });
 +
};
 +
 +
UT_Tokyo.urlFromHash = function(hash) {
 +
  var BASE = 'https://2011.igem.org/Team:UT-Tokyo';
 +
  if (hash == '' || hash == '#' || hash == '#Top' || hash == '#/Top') {
 +
    return BASE;
 +
  } else {
 +
    return BASE + hash.substr(1)
 +
  }
 +
};
 +
 +
UT_Tokyo.hashFromUrl = function(url) {
 +
  match = url.match(/2011.igem.org\/Team:UT-Tokyo(.*)$/);
 +
  if (!match) return ''; // invalid
 +
  m = match[1];
 +
  if (m == '' || m == '/') {
 +
    return '#/Top';
 +
  } else {
 +
    return '#' + m;
 +
  }
};
};
Line 428: Line 484:
// setting slider and event handlers
// setting slider and event handlers
$(document).ready(function () {
$(document).ready(function () {
 +
  UT_Tokyo.currentUrl = 'https://2011.igem.org' + location.pathname;
 +
   $('#slider').nivoSlider({
   $('#slider').nivoSlider({
     directionNav: false,
     directionNav: false,
Line 446: Line 504:
    
    
   if (UT_Tokyo.useAjaxLoading) {
   if (UT_Tokyo.useAjaxLoading) {
-
     $('#menu ul li a').click(function(e) {
+
 
-
    alert(this.attr('href'));
+
     $('#navi #menu ul li a').click(function(e) {
-
       UT_Tokyo.transit(this.attr('href'));
+
      UT_Tokyo.needHandling = false;
 +
     
 +
      toUrl = $(this).attr('href');
 +
      if (toUrl == UT_Tokyo.currentUrl) return;
 +
       location.hash = UT_Tokyo.hashFromUrl(toUrl);
 +
      UT_Tokyo.transit(toUrl);
       e.preventDefault();
       e.preventDefault();
       return false;
       return false;
     });
     });
 +
   
 +
    $(window).hashchange(function() {
 +
      if (UT_Tokyo.needHandling) {
 +
        if (!location.hash) return;
 +
        toUrl = UT_Tokyo.urlFromHash(location.hash);
 +
        UT_Tokyo.transit(toUrl);
 +
      }
 +
    });
 +
   
 +
    $(window).hashchange();
   }
   }
    
    
Line 510: Line 583:
</div>
</div>
</div>
</div>
 +
<div id="pageContent">
<div id="pageContent">
</html>
</html>

Revision as of 09:34, 27 August 2011