Learn how to use jQuery at the Blog

Vitsoe « visit

  • Added 10 months ago
  • 124 Lines of Code shown
  • 2 Links of Interest
http://vitsoe.com
This is my Source Code and I don't want to show it here
View Source Code only (as overlay)
// That code snippet belongs to Vitsoe - http://vitsoe.com

$(document).ready(function() {
  // do stuff when DOM is ready
  
  $('.flashvideo').each(function(){
    element = $(this);
    swfobject.registerObject(element.attr("id"), "9.0.0");
  });
  
  $(".caption.left, .caption.right, .caption.top, .caption.bottom").each(function(){
    var caption=$(this);
    var position = {"position" : "absolute","width" : "60px"};
    if (caption.hasClass('two')){
      position.width = "110px";
    }
    caption.css("width",position.width);
    if (caption.hasClass('top')){
      position.top = 0;
    }else if (caption.hasClass('bottom')){
      position.top = caption.prev().children('img').height()-caption.height();
    }
    if (caption.hasClass('left')){
      position.left = 0-(parseInt(position.width) + 10);
    }else if (caption.hasClass('right')){
      position.left = caption.prev().children('img').width() + 10; 
    }
    caption.css(position);
  })
  
  $(".links.columned").each(function(i){
    var ul=$(this);
    var newwidth=ul.width();
    if (ul.hasClass('two')){
      newwidth=(ul.width()-10)/2;
    }else if (ul.hasClass('three')){
      newwidth=(ul.width()-20)/3;
    }else if (ul.hasClass('four')){
      newwidth=(ul.width()-30)/4;
    }
    ul.children().each(function(i){
      $(this).css({"width":newwidth+'px', "float":"left"});
      if (i%2>0){
        $(this).css("margin-left","10px");
      }
    });
  })
  
  /*$(".gallery_image img").each(function(i){
    var image=$(this);
    image.css({"margin-top":(image.parent().parent().height()-image.height())/2})
  });*/
  
  var lang = $('#langs');
  var select= $('<select></select>').attr('id', 'langs_select');
  lang.find("li a").each(function(){
    var element = $(this);
    var option = $('<option></option>').attr('value', $(this).attr('href'));
    option.html(element.html())
    if(element.hasClass('selected')) {
        option.attr('selected','selected');
    }
    select.append(option);
  });
  select.change(function(event){
    document.location = event.target.value;
  });
  lang.replaceWith(select);
  
  
  $('.shadowcontent').each(function(){
    var playerVersion = swfobject.getFlashPlayerVersion();
    if ((playerVersion.major > 9) || (playerVersion.major == 9 && playerVersion.release > 45))
      element = $(this);
      element.attr('href', eval(element.attr("id")));
  });
  
  if ($('.shadowcontent').length > 0){
    Shadowbox.init();
  }

  
  $('.signup input[type="text"]').each(function(){
    $(this).focus(function(){
        var v = $(this).val();
        $(this).val( v === this.value ? '' : v );
    }).blur(function(){
        var v = $(this).val();
        $(this).val( v.match(/^\s+$|^$/) ? this.value : v );
    });
  });
  
  $('a[href^=http://]').each(function(link){
    $(this).attr({target:"_blank", title:"Javascript will open this external link in a new window."})
  });
  
  if ($('.google_map').length > 0){
    if (GBrowserIsCompatible()) {
      $('.google_map').each(function(){
        element = $(this);
        var address = [];
        element.find('.address li').each(function(){
          address.push($(this).html());
        });
        var map = new GMap2(this);
        var geocoder = new GClientGeocoder();
        geocoder.getLatLng(
          address.join(),
          function(point) {
            if (!point) {
              alert(address.join() + " not found");
            } else {
              map.setCenter(point, 15);
              var marker = new GMarker(point);
              map.addOverlay(marker);
              var mapControl = new GLargeMapControl();
              //map.addControl(mapControl);
              var mapControl = new GMapTypeControl();
              //map.addControl(mapControl);
              //marker.openInfoWindowHtml('<h2>Address: </h2>'+add[0]+'<br/>'+add[1]+', '+add[2]);
            }
          });
      });
    }
  }
});