$(document).ready(function(){ //activar os links todos os menus $("#m_inicial").click(function(){ // $(".menu_selected").removeClass("menu_selected"); // $("#m_inicial").addClass("menu_selected"); // $("table[id^='sub_']").hide(); top.location="index.php?m_inicial"; }); $("#titulo_noticias").click(function(){ // $(".menu_selected").removeClass("menu_selected"); // $("#titulo_noticias").addClass("menu_selected"); // $("table[id^='sub_']").hide(); top.location=""; }); $("#m_noticias_das_freguesias").click(function(){ // $(".menu_selected").removeClass("menu_selected"); // $(this).addClass("menu_selected"); // $("table[id^='sub_']").hide(); // $("#sub_m_noticias_das_freguesias").show(); top.location="index2.php?m_noticias_das_freguesias&sm_ultimas"; }); $("#sm_ultimas").click(function(){ $(".bolder").removeClass("bolder"); $("#sm_ultimas").addClass("bolder"); top.location="index2.php?m_noticias_das_freguesias&sm_ultimas"; }); //mouseovers / mouseouts $("#sm_ultimas").mouseover(function(){ $("#sm_ultimas").addClass("bold"); }); $("#sm_ultimas").mouseout(function(){ $("#sm_ultimas").removeClass("bold"); }); $("#sm_consulta").click(function(){ $(".bolder").removeClass("bolder"); $("#sm_consulta").addClass("bolder"); top.location="index2.php?m_noticias_das_freguesias&sm_consulta"; }); //mouseovers / mouseouts $("#sm_consulta").mouseover(function(){ $("#sm_consulta").addClass("bold"); }); $("#sm_consulta").mouseout(function(){ $("#sm_consulta").removeClass("bold"); }); $("#m_noticias_para_as_freguesias").click(function(){ // $(".menu_selected").removeClass("menu_selected"); // $(this).addClass("menu_selected"); // $("table[id^='sub_']").hide(); // $("#sub_m_noticias_para_as_freguesias").show(); top.location="index2.php?m_noticias_para_as_freguesias&sm_ultimas_para_as_freguesias"; }); $("#sm_ultimas_para_as_freguesias").click(function(){ $(".bolder").removeClass("bolder"); $("#sm_ultimas_para_as_freguesias").addClass("bolder"); top.location="index2.php?m_noticias_para_as_freguesias&sm_ultimas_para_as_freguesias"; }); //mouseovers / mouseouts $("#sm_ultimas_para_as_freguesias").mouseover(function(){ $("#sm_ultimas_para_as_freguesias").addClass("bold"); }); $("#sm_ultimas_para_as_freguesias").mouseout(function(){ $("#sm_ultimas_para_as_freguesias").removeClass("bold"); }); $("#sm_consulta").click(function(){ $(".bolder").removeClass("bolder"); $("#sm_consulta").addClass("bolder"); top.location="index2.php?m_noticias_para_as_freguesias&sm_consulta"; }); //mouseovers / mouseouts $("#sm_consulta").mouseover(function(){ $("#sm_consulta").addClass("bold"); }); $("#sm_consulta").mouseout(function(){ $("#sm_consulta").removeClass("bold"); }); $("#m_noticias_do_portal").click(function(){ // $(".menu_selected").removeClass("menu_selected"); // $(this).addClass("menu_selected"); // $("table[id^='sub_']").hide(); // $("#sub_m_noticias_do_portal").show(); top.location="index.php?m_noticias_do_portal&sm_ultimas_do_portal"; }); $("#sm_ultimas_do_portal").click(function(){ $(".bolder").removeClass("bolder"); $("#sm_ultimas_do_portal").addClass("bolder"); top.location="index.php?m_noticias_do_portal&sm_ultimas_do_portal"; }); //mouseovers / mouseouts $("#sm_ultimas_do_portal").mouseover(function(){ $("#sm_ultimas_do_portal").addClass("bold"); }); $("#sm_ultimas_do_portal").mouseout(function(){ $("#sm_ultimas_do_portal").removeClass("bold"); }); $("#sm_consulta").click(function(){ $(".bolder").removeClass("bolder"); $("#sm_consulta").addClass("bolder"); top.location="index.php?m_noticias_do_portal&sm_consulta"; }); //mouseovers / mouseouts $("#sm_consulta").mouseover(function(){ $("#sm_consulta").addClass("bold"); }); $("#sm_consulta").mouseout(function(){ $("#sm_consulta").removeClass("bold"); }); $("#titulo_info").click(function(){ // $(".menu_selected").removeClass("menu_selected"); // $("#titulo_info").addClass("menu_selected"); // $("table[id^='sub_']").hide(); top.location=""; }); $("#m_legislacao").click(function(){ // $(".menu_selected").removeClass("menu_selected"); // $(this).addClass("menu_selected"); // $("table[id^='sub_']").hide(); // $("#sub_m_legislacao").show(); top.location="index2.php?m_legislacao&sm_legislacao_autarquica"; }); $("#sm_legislacao_autarquica").click(function(){ $(".bolder").removeClass("bolder"); $("#sm_legislacao_autarquica").addClass("bolder"); top.location="index2.php?m_legislacao&sm_legislacao_autarquica"; }); //mouseovers / mouseouts $("#sm_legislacao_autarquica").mouseover(function(){ $("#sm_legislacao_autarquica").addClass("bold"); }); $("#sm_legislacao_autarquica").mouseout(function(){ $("#sm_legislacao_autarquica").removeClass("bold"); }); $("#sm_legislacao_outra").click(function(){ $(".bolder").removeClass("bolder"); $("#sm_legislacao_outra").addClass("bolder"); top.location="index2.php?m_legislacao&sm_legislacao_outra"; }); //mouseovers / mouseouts $("#sm_legislacao_outra").mouseover(function(){ $("#sm_legislacao_outra").addClass("bold"); }); $("#sm_legislacao_outra").mouseout(function(){ $("#sm_legislacao_outra").removeClass("bold"); }); $("#m_pocal").click(function(){ // $(".menu_selected").removeClass("menu_selected"); // $(this).addClass("menu_selected"); // $("table[id^='sub_']").hide(); // $("#sub_m_pocal").show(); top.location="index2.php?m_pocal&sm_enquadramento_legal"; }); $("#sm_enquadramento_legal").click(function(){ $(".bolder").removeClass("bolder"); $("#sm_enquadramento_legal").addClass("bolder"); top.location="index2.php?m_pocal&sm_enquadramento_legal"; }); //mouseovers / mouseouts $("#sm_enquadramento_legal").mouseover(function(){ $("#sm_enquadramento_legal").addClass("bold"); }); $("#sm_enquadramento_legal").mouseout(function(){ $("#sm_enquadramento_legal").removeClass("bold"); }); $("#sm_sistemas_contabilisticos").click(function(){ $(".bolder").removeClass("bolder"); $("#sm_sistemas_contabilisticos").addClass("bolder"); top.location="index2.php?m_pocal&sm_sistemas_contabilisticos"; }); //mouseovers / mouseouts $("#sm_sistemas_contabilisticos").mouseover(function(){ $("#sm_sistemas_contabilisticos").addClass("bold"); }); $("#sm_sistemas_contabilisticos").mouseout(function(){ $("#sm_sistemas_contabilisticos").removeClass("bold"); }); $("#sm_classificador_economico").click(function(){ $(".bolder").removeClass("bolder"); $("#sm_classificador_economico").addClass("bolder"); top.location="index2.php?m_pocal&sm_classificador_economico"; }); //mouseovers / mouseouts $("#sm_classificador_economico").mouseover(function(){ $("#sm_classificador_economico").addClass("bold"); }); $("#sm_classificador_economico").mouseout(function(){ $("#sm_classificador_economico").removeClass("bold"); }); $("#sm_classificacao_orcamental").click(function(){ $(".bolder").removeClass("bolder"); $("#sm_classificacao_orcamental").addClass("bolder"); top.location="index2.php?m_pocal&sm_classificacao_orcamental"; }); //mouseovers / mouseouts $("#sm_classificacao_orcamental").mouseover(function(){ $("#sm_classificacao_orcamental").addClass("bold"); }); $("#sm_classificacao_orcamental").mouseout(function(){ $("#sm_classificacao_orcamental").removeClass("bold"); }); $("#sm_documentos_previsionais").click(function(){ $(".bolder").removeClass("bolder"); $("#sm_documentos_previsionais").addClass("bolder"); top.location="index2.php?m_pocal&sm_documentos_previsionais"; }); //mouseovers / mouseouts $("#sm_documentos_previsionais").mouseover(function(){ $("#sm_documentos_previsionais").addClass("bold"); }); $("#sm_documentos_previsionais").mouseout(function(){ $("#sm_documentos_previsionais").removeClass("bold"); }); $("#sm_alteracoes_orcamentais").click(function(){ $(".bolder").removeClass("bolder"); $("#sm_alteracoes_orcamentais").addClass("bolder"); top.location="index2.php?m_pocal&sm_alteracoes_orcamentais"; }); //mouseovers / mouseouts $("#sm_alteracoes_orcamentais").mouseover(function(){ $("#sm_alteracoes_orcamentais").addClass("bold"); }); $("#sm_alteracoes_orcamentais").mouseout(function(){ $("#sm_alteracoes_orcamentais").removeClass("bold"); }); $("#sm_revisoes_orcamentais").click(function(){ $(".bolder").removeClass("bolder"); $("#sm_revisoes_orcamentais").addClass("bolder"); top.location="index2.php?m_pocal&sm_revisoes_orcamentais"; }); //mouseovers / mouseouts $("#sm_revisoes_orcamentais").mouseover(function(){ $("#sm_revisoes_orcamentais").addClass("bold"); }); $("#sm_revisoes_orcamentais").mouseout(function(){ $("#sm_revisoes_orcamentais").removeClass("bold"); }); $("#sm_modificacoes_ppi").click(function(){ $(".bolder").removeClass("bolder"); $("#sm_modificacoes_ppi").addClass("bolder"); top.location="index2.php?m_pocal&sm_modificacoes_ppi"; }); //mouseovers / mouseouts $("#sm_modificacoes_ppi").mouseover(function(){ $("#sm_modificacoes_ppi").addClass("bold"); }); $("#sm_modificacoes_ppi").mouseout(function(){ $("#sm_modificacoes_ppi").removeClass("bold"); }); $("#sm_prestacao_contas").click(function(){ $(".bolder").removeClass("bolder"); $("#sm_prestacao_contas").addClass("bolder"); top.location="index2.php?m_pocal&sm_prestacao_contas"; }); //mouseovers / mouseouts $("#sm_prestacao_contas").mouseover(function(){ $("#sm_prestacao_contas").addClass("bold"); }); $("#sm_prestacao_contas").mouseout(function(){ $("#sm_prestacao_contas").removeClass("bold"); }); $("#sm_controlo_interno").click(function(){ $(".bolder").removeClass("bolder"); $("#sm_controlo_interno").addClass("bolder"); top.location="index2.php?m_pocal&sm_controlo_interno"; }); //mouseovers / mouseouts $("#sm_controlo_interno").mouseover(function(){ $("#sm_controlo_interno").addClass("bold"); }); $("#sm_controlo_interno").mouseout(function(){ $("#sm_controlo_interno").removeClass("bold"); }); $("#sm_inventario").click(function(){ $(".bolder").removeClass("bolder"); $("#sm_inventario").addClass("bolder"); top.location="index2.php?m_pocal&sm_inventario"; }); //mouseovers / mouseouts $("#sm_inventario").mouseover(function(){ $("#sm_inventario").addClass("bold"); }); $("#sm_inventario").mouseout(function(){ $("#sm_inventario").removeClass("bold"); }); $("#sm_inventario_enquadramento").click(function(){ $(".bolder").removeClass("bolder"); $("#sm_inventario_enquadramento").addClass("bolder"); top.location="index2.php?m_pocal&sm_inventario_enquadramento"; }); //mouseovers / mouseouts $("#sm_inventario_enquadramento").mouseover(function(){ $("#sm_inventario_enquadramento").addClass("bold"); }); $("#sm_inventario_enquadramento").mouseout(function(){ $("#sm_inventario_enquadramento").removeClass("bold"); }); $("#m_canideos").click(function(){ // $(".menu_selected").removeClass("menu_selected"); // $(this).addClass("menu_selected"); // $("table[id^='sub_']").hide(); // $("#sub_m_canideos").show(); top.location="index2.php?m_canideos&sm_registro_licenca"; }); $("#sm_registro_licenca").click(function(){ $(".bolder").removeClass("bolder"); $("#sm_registro_licenca").addClass("bolder"); top.location="index2.php?m_canideos&sm_registro_licenca"; }); //mouseovers / mouseouts $("#sm_registro_licenca").mouseover(function(){ $("#sm_registro_licenca").addClass("bold"); }); $("#sm_registro_licenca").mouseout(function(){ $("#sm_registro_licenca").removeClass("bold"); }); $("#m_cemiterios").click(function(){ // $(".menu_selected").removeClass("menu_selected"); // $(this).addClass("menu_selected"); // $("table[id^='sub_']").hide(); // $("#sub_m_cemiterios").show(); top.location="index2.php?m_cemiterios&sm_descricao"; }); $("#sm_descricao").click(function(){ $(".bolder").removeClass("bolder"); $("#sm_descricao").addClass("bolder"); top.location="index2.php?m_cemiterios&sm_descricao"; }); //mouseovers / mouseouts $("#sm_descricao").mouseover(function(){ $("#sm_descricao").addClass("bold"); }); $("#sm_descricao").mouseout(function(){ $("#sm_descricao").removeClass("bold"); }); $("#m_organismos").click(function(){ // $(".menu_selected").removeClass("menu_selected"); // $(this).addClass("menu_selected"); // $("table[id^='sub_']").hide(); // $("#sub_m_organismos").show(); top.location="index2.php?m_organismos&sm_links0"; }); $("#sm_links0").click(function(){ $(".bolder").removeClass("bolder"); $("#sm_links0").addClass("bolder"); top.location="index2.php?m_organismos&sm_links0"; }); //mouseovers / mouseouts $("#sm_links0").mouseover(function(){ $("#sm_links0").addClass("bold"); }); $("#sm_links0").mouseout(function(){ $("#sm_links0").removeClass("bold"); }); $("#sm_links1").click(function(){ $(".bolder").removeClass("bolder"); $("#sm_links1").addClass("bolder"); top.location="index2.php?m_organismos&sm_links1"; }); //mouseovers / mouseouts $("#sm_links1").mouseover(function(){ $("#sm_links1").addClass("bold"); }); $("#sm_links1").mouseout(function(){ $("#sm_links1").removeClass("bold"); }); $("#sm_links2").click(function(){ $(".bolder").removeClass("bolder"); $("#sm_links2").addClass("bolder"); top.location="index2.php?m_organismos&sm_links2"; }); //mouseovers / mouseouts $("#sm_links2").mouseover(function(){ $("#sm_links2").addClass("bold"); }); $("#sm_links2").mouseout(function(){ $("#sm_links2").removeClass("bold"); }); $("#sm_links3").click(function(){ $(".bolder").removeClass("bolder"); $("#sm_links3").addClass("bolder"); top.location="index2.php?m_organismos&sm_links3"; }); //mouseovers / mouseouts $("#sm_links3").mouseover(function(){ $("#sm_links3").addClass("bold"); }); $("#sm_links3").mouseout(function(){ $("#sm_links3").removeClass("bold"); }); $("#sm_links4").click(function(){ $(".bolder").removeClass("bolder"); $("#sm_links4").addClass("bolder"); top.location="index2.php?m_organismos&sm_links4"; }); //mouseovers / mouseouts $("#sm_links4").mouseover(function(){ $("#sm_links4").addClass("bold"); }); $("#sm_links4").mouseout(function(){ $("#sm_links4").removeClass("bold"); }); $("#sm_links5").click(function(){ $(".bolder").removeClass("bolder"); $("#sm_links5").addClass("bolder"); top.location="index2.php?m_organismos&sm_links5"; }); //mouseovers / mouseouts $("#sm_links5").mouseover(function(){ $("#sm_links5").addClass("bold"); }); $("#sm_links5").mouseout(function(){ $("#sm_links5").removeClass("bold"); }); $("#sm_links6").click(function(){ $(".bolder").removeClass("bolder"); $("#sm_links6").addClass("bolder"); top.location="index2.php?m_organismos&sm_links6"; }); //mouseovers / mouseouts $("#sm_links6").mouseover(function(){ $("#sm_links6").addClass("bold"); }); $("#sm_links6").mouseout(function(){ $("#sm_links6").removeClass("bold"); }); $("#painel_informativo").click(function(){ // $(".menu_selected").removeClass("menu_selected"); // $("#painel_informativo").addClass("menu_selected"); // $("table[id^='sub_']").hide(); top.location=""; }); $("#m_informacoes_uteis").click(function(){ // $(".menu_selected").removeClass("menu_selected"); // $(this).addClass("menu_selected"); // $("table[id^='sub_']").hide(); // $("#sub_m_informacoes_uteis").show(); top.location="index.php?m_informacoes_uteis&sm_ultimas_informacoes_uteis"; }); $("#sm_ultimas_informacoes_uteis").click(function(){ $(".bolder").removeClass("bolder"); $("#sm_ultimas_informacoes_uteis").addClass("bolder"); top.location="index.php?m_informacoes_uteis&sm_ultimas_informacoes_uteis"; }); //mouseovers / mouseouts $("#sm_ultimas_informacoes_uteis").mouseover(function(){ $("#sm_ultimas_informacoes_uteis").addClass("bold"); }); $("#sm_ultimas_informacoes_uteis").mouseout(function(){ $("#sm_ultimas_informacoes_uteis").removeClass("bold"); }); $("#sm_links").click(function(){ $(".bolder").removeClass("bolder"); $("#sm_links").addClass("bolder"); top.location="index.php?m_informacoes_uteis&sm_links"; }); //mouseovers / mouseouts $("#sm_links").mouseover(function(){ $("#sm_links").addClass("bold"); }); $("#sm_links").mouseout(function(){ $("#sm_links").removeClass("bold"); }); $("#sm_consulta").click(function(){ $(".bolder").removeClass("bolder"); $("#sm_consulta").addClass("bolder"); top.location="index.php?m_informacoes_uteis&sm_consulta"; }); //mouseovers / mouseouts $("#sm_consulta").mouseover(function(){ $("#sm_consulta").addClass("bold"); }); $("#sm_consulta").mouseout(function(){ $("#sm_consulta").removeClass("bold"); }); $("#m_livrariaonline").click(function(){ // $(".menu_selected").removeClass("menu_selected"); // $("#m_livrariaonline").addClass("menu_selected"); // $("table[id^='sub_']").hide(); top.location="index2.php?m_livrariaonline"; }); $("#sm_carrinho").click(function(){ // $(".menu_selected").removeClass("menu_selected"); // $("#sm_carrinho").addClass("menu_selected"); // $("table[id^='sub_']").hide(); top.location=""; }); $("#sm_carrinho_confirmar").click(function(){ // $(".menu_selected").removeClass("menu_selected"); // $("#sm_carrinho_confirmar").addClass("menu_selected"); // $("table[id^='sub_']").hide(); top.location=""; }); $("#m_newsletter").click(function(){ // $(".menu_selected").removeClass("menu_selected"); // $("#m_newsletter").addClass("menu_selected"); // $("table[id^='sub_']").hide(); top.location="index.php?m_newsletter"; }); $("#m_newsletter_cp").click(function(){ // $(".menu_selected").removeClass("menu_selected"); // $("#m_newsletter_cp").addClass("menu_selected"); // $("table[id^='sub_']").hide(); top.location="index.php?m_newsletter_cp"; }); $("#m_pesquisa").click(function(){ // $(".menu_selected").removeClass("menu_selected"); // $("#m_pesquisa").addClass("menu_selected"); // $("table[id^='sub_']").hide(); top.location="index.php?m_pesquisa"; }); $("#m_farmacias").click(function(){ // $(".menu_selected").removeClass("menu_selected"); // $("#m_farmacias").addClass("menu_selected"); // $("table[id^='sub_']").hide(); top.location="index.php?m_farmacias"; }); $("#m_jogos").click(function(){ // $(".menu_selected").removeClass("menu_selected"); // $("#m_jogos").addClass("menu_selected"); // $("table[id^='sub_']").hide(); top.location="index.php?m_jogos"; }); //activar os links das noticias index $(".news_click").click(function(){ top.location=$(this).find(".news_link").attr("href"); }); $(".news_click").mouseover(function(){ $(this).addClass("news_click_over"); }); $(".news_click").mouseout(function(){ $(this).removeClass("news_click_over"); }); //activar os links das noticias listas $(".news_list_click").click(function(event){ var $target = $(event.target); if ($target.is("a")){ return true; }else{ if ($(this).find('.short').css("display")=="none"){ $(".news_list_click_over2").removeClass("news_list_click_over2"); $(this).find('.full').hide(1,function(){ $('.short').show(); }); }else{ $(".news_list_click_over2").removeClass("news_list_click_over2"); $(this).addClass("news_list_click_over2"); $(".news_list_click").find('.short').show(); $(".news_list_click").find('.full').hide(); $(this).find('.short').hide(); $(this).find('.full').show(); $.scrollTo("#"+$(this).find(".news_list_link").attr("name"), {axis:'y', duration: '500', offset:-20}); } } }); $(".news_list_click").mouseover(function(){ $(this).addClass("news_list_click_over"); }); $(".news_list_click").mouseout(function(){ $(this).removeClass("news_list_click_over"); }); //livraria $(".descr_livro").click(function(event){ var $target = $(event.target); if ($target.is("a")){ return true; }else{ if ($(this).find('.short').css("display")=="none"){ $(this).find('.full').hide(1,function(){ $('.short').show(); }); }else{ $(".descr_livro").find('.short').show(); $(".descr_livro").find('.full').hide(); $(this).find('.short').hide(); $(this).find('.full').show(); $.scrollTo("#"+$(this).find(".top").attr("name"), {axis:'y', duration: '500', offset:-60}); } } }); $("#filtro_concelhos").change(function(){ if($("#filtro_concelhos").val()!='0'){ $.ajax({ url: "php/ajax.freguesias.php", type: "GET", cache: false, data: 'concelho='+$("#filtro_concelhos").val(), success: function(html){ $("#filtro_juntas").html(html); $("#filtro_juntas").removeAttr("disabled"); } }); }else{ $("#filtro_juntas").attr("disabled","disabled"); } }); $("#filtro_juntas").change(function(){ top.location.href="?m_noticias_das_freguesias&sm_ultimas&f="+$("#filtro_juntas").val(); }); $("#pesquisar").focus(function(){ $("#pesquisar").val(""); }); $("#pesquisar").blur(function(){ if($("#pesquisar").val()==""){ $("#pesquisar").val("pesquisar..."); }; }); $("#pesquisar").keyup(function(event){ if(event.keyCode == 13){ //if generated character code is equal to ascii 13 (if enter key) var s = $(this).attr("value"); document.location.href="index.php?m_noticias_das_freguesias&sm_ultimas&s="+s; } }); }); /** * jQuery.ScrollTo * Copyright (c) 2007-2008 Ariel Flesler - aflesler(at)gmail(dot)com | http://flesler.blogspot.com * Dual licensed under MIT and GPL. * Date: 9/11/2008 * * @projectDescription Easy element scrolling using jQuery. * http://flesler.blogspot.com/2007/10/jqueryscrollto.html * Tested with jQuery 1.2.6. On FF 2/3, IE 6/7, Opera 9.2/5 and Safari 3. on Windows. * * @author Ariel Flesler * @version 1.4 * * @id jQuery.scrollTo * @id jQuery.fn.scrollTo * @param {String, Number, DOMElement, jQuery, Object} target Where to scroll the matched elements. * The different options for target are: * - A number position (will be applied to all axes). * - A string position ('44', '100px', '+=90', etc ) will be applied to all axes * - A jQuery/DOM element ( logically, child of the element to scroll ) * - A string selector, that will be relative to the element to scroll ( 'li:eq(2)', etc ) * - A hash { top:x, left:y }, x and y can be any kind of number/string like above. * @param {Number} duration The OVERALL length of the animation, this argument can be the settings object instead. * @param {Object,Function} settings Optional set of settings or the onAfter callback. * @option {String} axis Which axis must be scrolled, use 'x', 'y', 'xy' or 'yx'. * @option {Number} duration The OVERALL length of the animation. * @option {String} easing The easing method for the animation. * @option {Boolean} margin If true, the margin of the target element will be deducted from the final position. * @option {Object, Number} offset Add/deduct from the end position. One number for both axes or { top:x, left:y }. * @option {Object, Number} over Add/deduct the height/width multiplied by 'over', can be { top:x, left:y } when using both axes. * @option {Boolean} queue If true, and both axis are given, the 2nd axis will only be animated after the first one ends. * @option {Function} onAfter Function to be called after the scrolling ends. * @option {Function} onAfterFirst If queuing is activated, this function will be called after the first scrolling ends. * @return {jQuery} Returns the same jQuery object, for chaining. * * @desc Scroll to a fixed position * @example $('div').scrollTo( 340 ); * * @desc Scroll relatively to the actual position * @example $('div').scrollTo( '+=340px', { axis:'y' } ); * * @dec Scroll using a selector (relative to the scrolled element) * @example $('div').scrollTo( 'p.paragraph:eq(2)', 500, { easing:'swing', queue:true, axis:'xy' } ); * * @ Scroll to a DOM element (same for jQuery object) * @example var second_child = document.getElementById('container').firstChild.nextSibling; * $('#container').scrollTo( second_child, { duration:500, axis:'x', onAfter:function(){ * alert('scrolled!!'); * }}); * * @desc Scroll on both axes, to different values * @example $('div').scrollTo( { top: 300, left:'+=200' }, { axis:'xy', offset:-20 } ); */ ;(function( $ ){ var $scrollTo = $.scrollTo = function( target, duration, settings ){ $(window).scrollTo( target, duration, settings ); }; $scrollTo.defaults = { axis:'y', duration:1 }; // Returns the element that needs to be animated to scroll the window. // Kept for backwards compatibility (specially for localScroll & serialScroll) $scrollTo.window = function( scope ){ return $(window).scrollable(); }; // Hack, hack, hack... stay away! // Returns the real elements to scroll (supports window/iframes, documents and regular nodes) $.fn.scrollable = function(){ return this.map(function(){ // Just store it, we might need it var win = this.parentWindow || this.defaultView, // If it's a document, get its iframe or the window if it's THE document elem = this.nodeName == '#document' ? win.frameElement || win : this, // Get the corresponding document doc = elem.contentDocument || (elem.contentWindow || elem).document, isWin = elem.setInterval; return elem.nodeName == 'IFRAME' || isWin && $.browser.safari ? doc.body : isWin ? doc.documentElement : this; }); }; $.fn.scrollTo = function( target, duration, settings ){ if( typeof duration == 'object' ){ settings = duration; duration = 0; } if( typeof settings == 'function' ) settings = { onAfter:settings }; settings = $.extend( {}, $scrollTo.defaults, settings ); // Speed is still recognized for backwards compatibility duration = duration || settings.speed || settings.duration; // Make sure the settings are given right settings.queue = settings.queue && settings.axis.length > 1; if( settings.queue ) // Let's keep the overall duration duration /= 2; settings.offset = both( settings.offset ); settings.over = both( settings.over ); return this.scrollable().each(function(){ var elem = this, $elem = $(elem), targ = target, toff, attr = {}, win = $elem.is('html,body'); switch( typeof targ ){ // A number will pass the regex case 'number': case 'string': if( /^([+-]=)?\d+(px)?$/.test(targ) ){ targ = both( targ ); // We are done break; } // Relative selector, no break! targ = $(targ,this); case 'object': // DOMElement / jQuery if( targ.is || targ.style ) // Get the real position of the target toff = (targ = $(targ)).offset(); } $.each( settings.axis.split(''), function( i, axis ){ var Pos = axis == 'x' ? 'Left' : 'Top', pos = Pos.toLowerCase(), key = 'scroll' + Pos, old = elem[key], Dim = axis == 'x' ? 'Width' : 'Height', dim = Dim.toLowerCase(); if( toff ){// jQuery / DOMElement attr[key] = toff[pos] + ( win ? 0 : old - $elem.offset()[pos] ); // If it's a dom element, reduce the margin if( settings.margin ){ attr[key] -= parseInt(targ.css('margin'+Pos)) || 0; attr[key] -= parseInt(targ.css('border'+Pos+'Width')) || 0; } attr[key] += settings.offset[pos] || 0; if( settings.over[pos] ) // Scroll to a fraction of its width/height attr[key] += targ[dim]() * settings.over[pos]; }else attr[key] = targ[pos]; // Number or 'number' if( /^\d+$/.test(attr[key]) ) // Check the limits attr[key] = attr[key] <= 0 ? 0 : Math.min( attr[key], max(Dim) ); // Queueing axes if( !i && settings.queue ){ // Don't waste time animating, if there's no need. if( old != attr[key] ) // Intermediate animation animate( settings.onAfterFirst ); // Don't animate this axis again in the next iteration. delete attr[key]; } }); animate( settings.onAfter ); function animate( callback ){ $elem.animate( attr, duration, settings.easing, callback && function(){ callback.call(this, target, settings); }); }; function max( Dim ){ var attr ='scroll'+Dim, doc = elem.ownerDocument; return win ? Math.max( doc.documentElement[attr], doc.body[attr] ) : elem[attr]; }; }).end(); }; function both( val ){ return typeof val == 'object' ? val : { top:val, left:val }; }; })( jQuery );