$(document).ready(function() { /** * Inserir noticias relacionadas apos primeiro paragrafo */ if($('.texto-artigo').length > 0) $(".texto-artigo > p:nth-child("+pMoreNews+"").append($("#more-news")); /** * Aumentar e diminuir fontes */ $(".font").click(function(){ var size = $("#main p").css('font-size'); size = size.replace('px', ''); if(this.id == "fonte_mais"){ size = parseInt(size) + 2; }else if(this.id == "fonte_menos"){ size = parseInt(size) - 2; }else{ size = 17; } $("#main p").animate({'font-size' : size + 'px'}); }); /** * Imprimir */ $("#imprimir").click(function(){ $('.btn-info').hide(); $('.logo').show(); var url = window.location; $('#single_article').printElement({pageTitle:'Jornal O Tempo Online - Link: '+url}); $('.btn-info').show(); $('.logo').hide(); }); /** * Email */ $("#email").click(function() { $("#inline_poster").dialog({ closeText: "", position: { my: "center", at: "top", of: "#atf-article" } }); }); $("#fechar").click(function() { $("#inline_poster").dialog( "close" ); }); /** * Caracteres Restantes */ $("#inline_poster textarea").keyup(function(event){ var target = $("#countdown"); var max = $(this).attr('maxlength'); var len = $(this).val().length; var remain = max - len; if(len > max) { var val = $(this).val(); $(this).val(val.substr(0, max)); remain = 0; } target.html(remain); }); /** * Compartilhar texto selecionado no Facebook e Twitter */ //verifica se o objeto foi criado if(!window.CurrentSelection){ CurrentSelection = {}; } //define o objeto seletor CurrentSelection.Selector = {}; //obtém o texto selecionado CurrentSelection.Selector.getSelected = function(){ var sel = ''; if(window.getSelection){ sel = window.getSelection(); } else if(document.getSelection){ sel = document.getSelection(); } else if(document.selection){ sel = document.selection.createRange(); } return sel; }; var texto = ''; //função a ser chamada no mouseup CurrentSelection.Selector.mouseup = function(){ var st = CurrentSelection.Selector.getSelected(); if (st == "") { return false; } var info_text = st.getRangeAt(0); //texto selecionado var text = info_text.commonAncestorContainer; //paragráfo referente ao texto selecionado var text_inicio = info_text.startOffset; //inicio do texto selecionado var text_fim = info_text.endOffset; //fim do texto selecionado var texto_selecionado = text_fim - text_inicio; //fim do texto selecionado texto = text.substringData(text_inicio,texto_selecionado); //texto selecionado; //Twitter e Facebook $('.popupTwitter,.popupFacebook').click(function(event) { var width = 460, height = 450, left = 5 , top = ($(window).height() - height)/2, url = this.href +'?text='+texto, opts = 'status=1' + ',width=' + width + ',height=' + height + ',top=' + top + ',left=' + left; window.open(url, 'share', opts); return false; }); }; //função mouseup $(function() { $(".texto-artigo").bind("mouseup", CurrentSelection.Selector.mouseup); $(".texto-artigo").mouseup(function (e) { var selection = CurrentSelection.Selector.getSelected(); if (selection && (selection = new String(selection).replace(/^\s+|\s+$/g, ''))) { $(".shareBox").css({ position: "absolute", top: (e.pageY + 5) + "px", left: (e.pageX + 5) + "px" }).show(); } else { $(".shareBox").hide(); } }); $(".shareFacebook,.shareTwitter").mouseup(function() { $(".shareBox").hide(); }); }); });