Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function titulo(title) {
- var titulo = $('#site-title').html();
- if (title !== undefined) {
- $('#site-title').html(titulo['split']('SergioPiza')[0] + 'SergioPiza - ' + title);
- } else {
- $('#site-title').html('SergioPiza' + titulo['split']('SergioPiza')[1]);
- }
- }
- function TitleNotifyPrepend(n) {
- var titulo = $('#site-title').html();
- $('#site-title').html('(' + $.trim(n) + ') SergioPiza' + titulo['split']('SergioPiza')[1]);
- }
- function goTo(href) {
- location.href='#!/' + href + '/';
- }
- var lr = {
- f: function(a) {
- Messi.load('lib/'+a+'.php', {
- title: a.capitalize(),
- modal: true,
- titleClass: 'info anim'
- });
- }
- }
- function MyHash() {
- var mh = location.hash['split']('#!/')[1]['split']('/');
- mh[0] = mh[0].toLowerCase();
- return mh;
- }
- function LoadPage(query) {
- if (location.hash == null || location.hash == '') {
- return false;
- }
- $('.loading-page').slideDown();
- $.ajax({
- url: 'files/' + MyHash()[0] + '.php',
- type: 'POST',
- data: (query? query : ''),
- success: function (content) {
- $('#page-content').html(content);
- },
- error: function(xhr, textStatus, errorThrown){
- if (xhr.status == '404') {
- $('#page-content').html('<div class="erro"><h1>404 - Not Found</h1><p>Esta url não existe</p></div>');
- } else {
- $('#page-content').html('<div class="erro"><h1>'+errorThrown+'</h1><p>Ocorreu um erro inexperado. Código do erro: <b>'+xhr.status+'</b></p></div>');
- }
- },
- complete: function(){
- $('.loading-page').slideUp();
- }
- });
- }
- function OnHashChange() {
- messidebug(0);
- HideSearch();
- if (MyHash()[1] == undefined) {
- location.hash = location.hash + '/';
- }
- if (MyHash()[1].length > 0) {
- switch (MyHash()[0]) {
- case 'mensagens':
- if (MyHash()[1] == 'new' && MyHash()[2].length > 0) {
- LoadPage('new=' + encodeURIComponent( MyHash()[2] ));
- break;
- } else
- if (MyHash()[1] == 'view' && MyHash()[2].length > 0) {
- LoadPage('view=' + encodeURIComponent( MyHash()[2] ));
- break;
- } else
- if (MyHash()[1] == 'list') {
- LoadPage('list=1');
- break;
- } else {
- LoadPage();
- break;
- }
- case 'news':
- LoadPage('id=' + encodeURIComponent( MyHash()[1] ));
- break;
- case 'user':
- LoadPage('user=' + encodeURIComponent( MyHash()[1] ));
- break;
- case 'edit':
- LoadPage('action=edit&id=' + encodeURIComponent( MyHash()[1] ));
- break;
- case 'forgot':
- if (MyHash()[2] !== undefined && MyHash()[3] !== undefined) {
- LoadPage('change=1&h1=' + MyHash()[1] + '&h2=' + MyHash()[2] + '&email=' + MyHash()[3]);
- break;
- } else {
- LoadPage();
- break;
- }
- case 'contato':
- LoadPage('query=' + encodeURIComponent( MyHash()[1] ));
- break;
- case 'welcome':
- LoadPage('p=' + encodeURIComponent( MyHash()[1] ));
- break;
- default:
- LoadPage();
- break;
- }
- } else {
- LoadPage();
- }
- }
- function OnResize() {
- var elem = [$('#content'), $('#right'), $('#news-bottom'), $('.news-bottom')];
- for (i=0; i<elem.length; i++) {
- if (document.width <= 1135) {
- elem[i].addClass('small');
- } else {
- elem[i].removeClass('small');
- }
- }
- }
- $(document).ready(function () {
- if (location.hash == null || location.hash == '') {
- location.hash = '!/home/';
- } else {
- OnHashChange();
- }
- })
- window.onhashchange = OnHashChange;
- window.onresize = OnResize;
- // Debug Messi
- function messidebug(messisleft) {
- var elements = $('[messi=true]');
- var arr = jQuery.makeArray(elements);
- $(arr).each(function (index, value) {
- for (i = messisleft; i < arr.length; ++i) {
- $(arr[i]).remove();
- }
- })
- }
- // Functions
- function LoadingSuspensionPts() {
- var sp = $('.loading-sp-pts');
- switch (sp.html()) {
- case '.':
- sp.html('..');
- break;
- case '..':
- sp.html('...');
- break;
- case '...':
- sp.html('');
- break;
- default:
- sp.html('.');
- break;
- }
- }
- function NotificationDiv(type) {
- var not = $('#notification-div');
- if (type == 'open') {
- if (not.attr('class') == '') {
- window.setTimeout(function() {not.attr('class', 'open');}, 50);
- }
- } else
- if (type == 'close') {
- not.attr('class', '');
- $.ajax({
- url: "notifications.php",
- type: 'POST',
- data: 'clear=1'
- });
- }
- }
- function GSDiv() {
- $('#global-search-div').toggle();
- $('#global-search-div input').focus();
- }
- function GlobalSearch() {
- _gs_val = $.trim($('#global-search').val());
- _gs_content = $('#global-search-content');
- _pg_content = $('#page-content');
- function __GS__SHOW() {
- _gs_content.load('globalsearch.php?term=' + encodeURIComponent(_gs_val), function() {
- _pg_content.fadeOut(500, function() {
- _gs_content.fadeIn(500, function() {
- if ($(_pg_content).is(':visible')) {
- _pg_content.fadeOut(500, function() {
- if (_gs_val == '') {
- __GS__HIDE();
- }
- });
- }
- });
- });
- });
- }
- function __GS__HIDE() {
- _gs_content.fadeOut(500, function() {
- _pg_content.fadeIn();
- });
- }
- if (_gs_val !== '') {
- __GS__SHOW();
- } else if (_gs_val == '') {
- __GS__HIDE();
- }
- }
- function HideSearch() {
- $('#global-search-content').fadeOut(500, function() {
- $('#global-search').val('');
- $('#page-content').fadeIn();
- });
- }
- $(document).ready(function() {
- $(document).click(function() {
- if ($('#notification-div').attr('class') == '' || $('#notification-div').attr('class') == undefined) {
- //return false;
- } else {
- NotificationDiv('close');
- }
- });
- $('a').click(function() {
- if ($(this).attr('target') !== "_blank") {
- window.location.href = $(this).attr('href');
- }
- })
- })
- function preview(textarea, div) {
- var content = $(textarea).val();
- $(div).load('lib/preview_msg.php?preview=' + encodeURIComponent(content));
- }
- function go2home(nick) {
- if (nick.length > 0) {
- location.hash = '!/user/' + nick + '/';
- } else {
- return false;
- }
- }
- function phpTime() {
- var mydate = new Date().getTime() + '';
- return mydate.replace(/[0-9]{3}$/, '');
- }
- function notifications() {
- $.ajax({
- url: "notifications.php",
- type: 'POST',
- data: 'n=1',
- success: function (lol) {
- if (lol > 0) {
- TitleNotifyPrepend(lol);
- $('.nb-counter').html('(' + $.trim(lol) + ')');
- } else {
- titulo();
- $('.nb-counter').html('');
- }
- },
- complete: function() {
- setTimeout(notifications, 10000);
- }
- });
- $('#notification-div').load('notifications.php');
- }
- // Tab na <textarea>
- function TextAreaTab(id) {
- $(document).delegate('textarea#' + id, 'keydown', function (e) {
- var keyCode = e.keyCode || e.which;
- if (keyCode == 9) {
- e.preventDefault();
- var start = $(this).get(0).selectionStart;
- var end = $(this).get(0).selectionEnd;
- // set textarea value to: text before caret + tab + text after caret
- $(this).val($(this).val().substring(0, start) + "\t" + $(this).val().substring(end));
- // put caret at right position again
- $(this).get(0).selectionStart = $(this).get(0).selectionEnd = start + 1;
- }
- });
- }
- TextAreaTab('conteudo');
- $.get("js/BBCodeFunc.js");
- //Ctrl Shortcuts
- function shortcut(key, link) {
- Mousetrap.bind(['command+'+key+'', 'ctrl+'+key+''], function(e) {
- location.href = '#!/' + link + '/';
- return false;
- });
- }
- shortcut(1, 'home');
- shortcut(2, 'news');
- shortcut(3, 'account');
- shortcut(4, 'mensagens');
- shortcut(5, 'mensagens/list');
- shortcut(6, 'user');
- shortcut(7, 'contato');
- shortcut(8, 'loopsounds');
- shortcut(9, 'termosdeuso');
- shortcut(0, 'welcome');
- Mousetrap.bind(['command+r', 'ctrl+r'], function(e) {
- OnHashChange();
- return false;
- });
- // [Votos]
- function StarHover(n, txt, color) {
- var d = $('.voting-dialog');
- var img_p = 'images/voting/star_gold_';
- for (i=1;i<=n;i++) {
- $('.v-star.' + i).attr('src', img_p + 'full_hover.png');
- }
- for (i=5; i>n; i--) {
- $('.v-star.' + i).attr('hovered', 'false');
- $('.v-star.' + i).attr('src', img_p + $('.v-star.' + i).attr('star') + '.png');
- }
- $('.voting-dialog').attr('style', 'color:' + color).html(txt);
- }
- function LoadRating(element, type, id) {
- $.ajax({
- url: 'lib/voting.php',
- type: "POST",
- data: "view=1&type=" + type + "&id=" + id,
- success: function(r) {
- $(element).html(r).fadeIn();
- }
- });
- }
- function SendVote(element, type, id, value, session) {
- $(element).fadeOut();
- $.ajax({
- url: 'lib/voting.php',
- type: "POST",
- data: "vote=1&type=" + type + "&id=" + id + "&value=" + value + "&cookie=" + session,
- success: function(r) {
- LoadRating(element, type, id);
- }
- });
- }
- // [/Votos]
- //ShoutBox
- function mountmsg(nick, color, msg, time, date, id) {
- if ($.trim(msg) !== '') {
- $('#shoutbox-msgs').append('<div class="msg-'+id+'" style="width:350px;padding:1px;"><span style="float:left;margin-right:2px;"><a href="#!/user/'+nick+'/" style="color:'+color+';"><b>'+nick+':</b></a></span><span>'+msg+'</span><span title="'+time+' '+date+'" style="color:#666;text-align:right;display:block;margin-bottom:1px;">['+time+']</span>');
- }
- }
- function ShoutBox(load) {
- var lastmsg = $.cookie("msgid");
- if (load == true) {
- lastmsg = 'false';
- }
- $.ajax({
- url: "lib/shoutbox.php",
- type: "POST",
- data: 'getlastmsg=' + lastmsg,
- success: function(lm) {
- if (parseInt(lastmsg) !== parseInt(lm)) {
- $.ajax({
- url: 'lib/shoutbox.php',
- type: 'POST',
- data: 'json=' + lastmsg,
- dataType: 'json',
- success: function(json) {
- for (o = 0; o <= Object.size(json) - 1; o++) {
- /*if (load !== true) {
- alert('lastmsg(' + (parseInt(lastmsg) + 1) + ') lm(' + lm + ')' );
- console.log(json);
- }*/
- if (!$('.msg-' + json[o].id).length) {
- if ($('.msg-ex').length) {
- $('.msg-ex').slideUp(250, function() {
- $('.msg-ex').remove();
- mountmsg(json[o].nick, json[o].color, json[o].msg, json[o].time, json[o].date, json[o].id);
- });
- } else {
- mountmsg(json[o].nick, json[o].color, json[o].msg, json[o].time, json[o].date, json[o].id);
- }
- }
- setTimeout('ShoutBoxScroll(1000)', 100);
- }
- if (load == true) {
- ShoutBoxScroll(500);
- }
- }
- });
- $.cookie("msgid", lm - 1);
- }
- window.setTimeout(ShoutBox, 2500);
- },
- error: function(jqXHR, textStatus, errorThrown){
- //alert("Ocorreu um erro.\nCertifique-se de que você está conectado à internet.");
- }
- });
- }
- function ShoutBoxScroll(time) {
- $('#shoutbox-msgs').stop().animate({
- scrollTop: $("#shoutbox-msgs")[0].scrollHeight
- }, time);
- }
- function ShoutBoxEnviar() {
- var sessao = $.cookie("sessionid");
- var msg = encodeURIComponent($('#shoutbox-msg').val());
- $.ajax({
- url: "lib/shoutbox.php",
- type: 'POST',
- data: 'cookie=' + sessao + '&msg=' + msg,
- success: function() {
- ShoutBox();
- }
- });
- $('#shoutbox-msg').val('');
- }
- function OnlineUsers(n) {
- var o = n;
- var msg = '';
- $.ajax({
- url: "lib/onlineusers.php",
- type: 'POST',
- data: 'o=' + o,
- success: function (ou) {
- switch(ou) {
- case '0':
- msg += 'Nenhum usuário';
- break;
- case '1':
- msg += 'Um usuário';
- break;
- default:
- msg += ou + ' usuários';
- break;
- }
- msg += ' online';
- $('#online-users').html('<a class="a" onclick="WhoIsOnline()" href="javascript:void(\'Online Users\')" style="text-decoration:none !important;">' + msg + '</a>');
- o = ou;
- },
- complete: function() {
- setTimeout(OnlineUsers, 10000);
- }
- });
- }
- function WhoIsOnline() {
- Messi.load('lib/onlineusers.php?v=list', {
- buttons: [{
- id: 0,
- label: 'Fechar',
- val: ''
- }],
- modal: true,
- width: '300px'
- });
- }
- function sbDragging(toggle) {
- d = $('#bottom');
- if (toggle == 'disable') {
- d.draggable("destroy")
- } else {
- d.draggable({
- handle: '#d-sb-a',
- containment: 'document',
- start: function(event, ui) {
- $('#sb-b-reload').show();
- }
- });
- }
- }
- function sbReplace() {
- $('#bottom').attr('style', '');
- $('#sb-b-reload').hide();
- }
- function sbDragToggle() {
- var sb = $('#sb-b-drag');
- switch (sb.attr('dragging')) {
- case "true":
- sb.attr('dragging', 'false').attr('class', 'ui-icon ui-icon-locked');
- sbDragging('disable');
- break;
- case "false":
- sb.attr('dragging', 'true').attr('class', 'ui-icon ui-icon-unlocked');
- sbDragging('enable');
- break;
- }
- }
- String.prototype.capitalize = function() {
- return this.charAt(0).toUpperCase() + this.slice(1);
- }
- Object.size = function(obj) {
- var size = 0, key;
- for (key in obj) {
- if (obj.hasOwnProperty(key)) size++;
- }
- return size;
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement