Team:Cambridge/static/wiki.js

From 2011.igem.org

(Difference between revisions)
Line 29: Line 29:
}
}
-
jQuery.extend(
+
 
-
   jQuery.expr[ ":" ],
+
var is_internal: function(obj)
 +
{
 +
   var href = $(obj).attr("href");
 +
  if(/:\/\//.test(href))
   {
   {
-
    external: function(obj, index, meta, stack)
+
console.log('is_internal href="' + href + '" found "://", returning ' + /http:\/\/2011.igem.org\/Team:Cambridge/i.test(href)););
-
    {
+
     return /http:\/\/2011.igem.org\/Team:Cambridge/i.test(href);
-
      var href = $(obj).attr("href");
+
-
      if(/:\/\//.test(href))
+
-
      {
+
-
console.log(':external href="' + href + '" found "://", returning ' + !/http:\/\/2011.igem.org\/Team:Cambridge/i.test(href));
+
-
        return !/http:\/\/2011.igem.org\/Team:Cambridge/i.test(href);
+
-
      }
+
-
console.log(':external href="' + href + '", "://" not found, returning false');
+
-
      return false;
+
-
     },
+
-
    internal: function(obj, index, meta, stack)
+
-
    {
+
-
      var href = $(obj).attr("href");
+
-
      if(/:\/\//.test(href))
+
-
      {
+
-
console.log(':internal href="' + href + '" found "://", returning ' + /http:\/\/2011.igem.org\/Team:Cambridge/i.test(href)););
+
-
        return /http:\/\/2011.igem.org\/Team:Cambridge/i.test(href);
+
-
      }
+
-
console.log(':internal href="' + href + '", "://" not found, returning true');
+
-
      return true;
+
-
    }
+
   }
   }
-
);
+
console.log('is_internal href="' + href + '", "://" not found, returning true');
 +
  return true;
 +
}
 +
 
var areas = [  
var areas = [  
Line 203: Line 189:
set_area();
set_area();
-
$('a:internal').live('click', function(event) {
+
$('a').live('click', function(event) {
 +
          if(is_internal(this))
 +
          {
event.preventDefault();
event.preventDefault();
load_url($(this).attr('href'));
load_url($(this).attr('href'));
return false;
return false;
 +
          }
 +
          return true;
});
});

Revision as of 09:50, 8 September 2011

console.log('/Team:Cambridge/static/wiki.js being Loaded.');

/*

*  Variables.
* 
* */

//current area/subarea var area = 'overview'; var subarea = 'home';

//the url that's loaded var current_url = window.location.pathname; //the interval var int;


var check_hash = function() { if((current_url != window.location.hash.substr(1)) && window.location.hash) { console.log('check_hash: current_url != window.location.hash.substr(1): ' + current_url + ' != ' + window.location.hash.substr(1)); int = clearInterval(int);//pause //current_url != window.location.hash.substr(1); load_url(window.location.hash.substr(1));

int = setInterval('check_hash();', 500); } }


var is_internal: function(obj) {

 var href = $(obj).attr("href");
 if(/:\/\//.test(href))
 {

console.log('is_internal href="' + href + '" found "://", returning ' + /http:\/\/2011.igem.org\/Team:Cambridge/i.test(href)););

   return /http:\/\/2011.igem.org\/Team:Cambridge/i.test(href);
 }

console.log('is_internal href="' + href + '", "://" not found, returning true');

 return true;

}


var areas = [ [/\/Team:Cambridge\/project/i, 'project',], [/\/Team:Cambridge\/(experiments|constructs|protocols|safety|labwork)/i, 'labwork',], [/\/Team:Cambridge\/society/i, 'society',], [/\/Team:Cambridge\/team/i, 'team',], [/\/Team:Cambridge/i, 'overview'], [/./i, 'overview'], ];

var subareas = { 'overview': [ [/\/Team:Cambridge\/Media/i, 'media'], [/\/Team:Cambridge\/Reflectin/i, 'reflectin'], [/\/Team:Cambridge\/Blog/i, 'blog'], [/./i, 'home'], ], 'project': [ [/\/Team:Cambridge\/Project\/prelim/i, 'preliminary'], [/\/Team:Cambridge\/Project\/in_vitro/i, 'invitro'], [/\/Team:Cambridge\/Project\/in_vivo/i, 'invivo'], [/\/Team:Cambridge\/Project\/gibthon/i, 'gibthon'], [/\/Team:Cambridge\/Project\/conclusion/i, 'conclusion'], [/\/Team:Cambridge\/Project/i, 'overview'], ], 'labwork': [ [/\/Team:Cambridge\/experiments/i, 'experiments'], [/\/Team:Cambridge\/constructs/i, 'constructs'], [/\/Team:Cambridge\/protocols/i, 'protocols'], [/\/Team:Cambridge\/safety/i, 'safety'], [/\/Team:Cambridge\/labwork/i, 'overview'], ], 'society': [ [/\/Team:Cambridge\/Society\/igem/i, 'igem'], [/\/Team:Cambridge\/Society\/future_applications/i, 'future'], [/\/Team:Cambridge\/Society/i, 'overview'], ], 'team': [ [/\/Team:Cambridge\/Team\/Students/i, 'students'], [/\/Team:Cambridge\/Team\/Academics/i, 'academics'], [/\/Team:Cambridge\/Team\/Sponsors/i, 'sponsors'], [/\/Team:Cambridge\/Team/i, 'overview'], ], }

var get_area = function(path) { //figure out which area of the site we are in var ar = ; var sub = ; if(path == undefined) var path = location.pathname;

for ( var a in areas) { if(areas[a][0].test(path)) { ar = areas[a][1]; break; } } for ( var a in subareas[ar]) { if(subareas[ar][a][0].test(path)) { sub = subareas[ar][a][1]; break; } } console.log('area/subarea: ' + ar + '/' + sub); return [ar, sub]; }

var apply_area = function() { $('.cam-selected').removeClass('cam-selected'); $('.cam-menu-item.cam-' + area).addClass('cam-selected'); $('.cam-' + area + '-' + subarea).addClass('cam-selected'); }

var set_area = function(path) { var as = get_area(path); area = as[0]; subarea = as[1]; apply_area(); }

var set_url = function(path) { console.log('set_url(' + path + ')'); current_url = path; if(current_url != window.location.pathname) window.location.hash = path;

       else
               window.location.hash = ;

}

var baseurl = ;//'//2011.igem.org';

var load_url = function(url) { console.log('load_url( ' + url + ') current_url: ' + current_url); if(url == undefined) url = '/Team:Cambridge';

var load = url + '?action=render';

$.ajax({ 'url': load, 'dataType': 'html', 'error': function(jqXHR, textStatus, errorThrown) {

var $c = $('

AjaxError!

Status: ' + textStatus + '

' + errorThrown + '

');

$('#cam_pagecontent').fadeOut('fast', function() { $(this).html($c).fadeIn('fast'); }); }, 'success': function(data){ var $c = $(data).find('#wiki_content'); $('#cam_pagecontent').fadeOut('fast', function() {

$(this).html($c).append('
').fadeIn('fast');

}); }, }); set_url(url); set_area(url); };

$(window).ready(function() { console.log('static/wiki.js::$(window).ready()'); $('.cam-menu-item a').mouseenter( function(event) {//in $(event.currentTarget).next().children('.cam-menu-drop').slideDown('fast'); }); $('.cam-menu-item').mouseleave( function(event) {//out $(event.currentTarget).find('.cam-menu-drop').slideUp('fast'); });

$('.cam-social-link').hover( function(event) {; $(this).children().animate({top:0}, 75); }, function(event) { $(this).children().animate({'top':12}, 250); } );

set_area();

$('a').live('click', function(event) {

         if(is_internal(this))
         {

event.preventDefault(); load_url($(this).attr('href')); return false;

         }
         return true;

});

$('#cam_topbar a').hover( function() { $(this).prev('.cam-ui-icon').addClass('cam-hover'); }, function() { $(this).prev('.cam-ui-icon').removeClass('cam-hover'); } );

int = window.setInterval('check_hash();', 500); });