/* * ELEMENT PROPERTY MANAGEMENT */ function splitProperties($s) { var $couples = new Array(); var $properties = new Array(); var $element = new Array(); var $y = 0; $couples = $s.split(','); for (var $i=0; $i < $couples.length; $i++) { if ($couples[$i] != undefined && $couples[$i] != '') { $element = $couples[$i].split(':'); $properties[$y] = { name: $element[0], value: $element[1] } $y++ } } return $properties; } function getProperties($p,$k) { for (var $i=0; $i < $p.length; $i++) { if ($p[$i].name == $k) { return $p[$i].value; } } return -1; } function fixImages() { $('.post .text img').each( function () { $w = $(this).width(); if ($w > 498) { $(this).css('width','498px'); } } ); } /* * NEW POSTS */ function newPostCallback(data) { setupNewPostForm(); if (data.id != 0) { $('#content #main .post:first').before(data.message); $('#post-' + data.id).hide().show(300); $('.notfound').remove(); } else { alert (data.message); } $('#newPostLoading').fadeOut(200, function() { $('#newPostForm').fadeIn(200); }); } function submitNewPost(text, tags) { var $posturl = $('#posturl').val(); if ($.trim(text) != '' && $.trim(tags) != '') { var $data = { text: text, tags: tags, postURI: $posturl } $('#newPostLoading').height($('#newPostForm').height()); $('#newPostForm').fadeOut(200, function () { $('#newPostLoading').fadeIn(200); }); $.post($posturl + '/ajax-add.php', $data, newPostCallback, 'json'); } else { setupNewPostForm(); } } function setupNewPostForm() { var $textareaText = 'What are you thinking?'; var $inputText = 'Enter tags...'; $('textarea#text').val($textareaText).focus( function () { if ($(this).val() == $textareaText) { $(this).val(''); } $(this).css('color','#333'); } ).blur( function () { if ($.trim($(this).val()) == '') { $(this).val($textareaText); } $(this).css('color','#aaa'); } ); $('input#tags').val($inputText).focus( function () { if ($(this).val() == $inputText) { $(this).val(''); } $(this).css('color','#333'); } ).blur( function () { if ($.trim($(this).val()) == '') { $(this).val($inputText); } $(this).css('color','#aaa'); } ); $('form#newPostForm').submit( function(e){ e.preventDefault(); if ($('textarea#text').val() == $textareaText) { $('textarea#text').val(''); } if ($('input#tags').val() == $inputText) { $('input#tags').val(''); } var $text = $('textarea#text').val(); $('textarea#text').val(''); var $tags = $('input#tags').val(); $('input#tags').val(''); submitNewPost($text, $tags); } ); } function setupSearch() { var $searchText = 'Search...'; $('form#search input[type=text]').css('color','#aaa').val($searchText).focus( function () { if ($(this).val() == $searchText) { $(this).val(''); } $(this).css('color','#333'); } ).blur( function(){ if ($.trim($(this).val()) == '') { $(this).val($searchText); } $(this).css('color', '#aaa'); } ); } function getArchivesCallback(data) { if (data.message == '') { $('#loadMore').hide(); } else { $('#content #main .post:last').after(data.message); $('#loadMore').removeAttr('disabled').css('background-image', 'none'); } } function getArchives() { var $offset = $('.post').length; var $posturl = $('#posturl').val(); $('#loadMore').attr("disabled", "disabled").css('background-image','url(' + $posturl + '/images/loading.gif)'); var $data = { offset: $offset, postURI: $posturl }; $.post($posturl + '/ajax-update.php', $data, getArchivesCallback, 'json'); } function setupArchives() { if ($('#loadMore').length > 0) { $('#loadMore').click( getArchives ); } } /* * DOCUMENT LOADING */ $(document).ready( function() { if ($('#newPost').length > 0) { setupNewPostForm(); } setupSearch(); setupArchives(); fixImages(); } );