Learn how to use jQuery at the Blog

Cloudspeakers « visit

  • Added 5 months ago
  • 128 Lines of Code shown
  • 1 Links of Interest
http://cloudspeakers.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 Cloudspeakers - http://cloudspeakers.com

//==============================================================================
// $Id: site.js 1733 2009-07-07 19:17:38Z charlie $
//==============================================================================
$(document).ready(function()
{
    $.ajaxSetup({
        global:     false,
        dataType:   'html',
        type:       'POST'
    });
    // birthday
    if ($("#UserBirthday").val() == "") {
        $("#UserBirthday").css({"color":"#999999"}).val("YYYY-mm-dd");
    }
    $('#UserBirthday').focus(function(){
        if (this.value=="YYYY-mm-dd") {
            this.value='';
             this.style.color = '#16304B';
        }
    }).blur(function(){
        if (this.value=='') {
            this.value="YYYY-mm-dd";
            this.style.color = '#999999';
        }
    });
    // prevent submits when default text is in register or update form
    $('#UserAddForm').submit(function() {
        if ($('#UserBirthday').val() == "YYYY-mm-dd") {
            $('#UserBirthday').val('');
        }
        return true;
    });
    // other files startup sequences on document ready
    if (startup.length > 0) {
        for(i=0; i<startup.length; i++) {
            startup[i].apply(this);
        }
    }
    
    // check if this artist is already followed by this user
    if (logged_in_user && g_artist_gid != '') {
        $.getJSON('/'+language+'/subscriptions/isFollowing/'+g_artist_gid, function(data){
           if (data.ok == '1') {
               var c = _t('UNFOLLOW');
               $('.follow').html(c).addClass('unfollow').removeClass('follow');
           }
           $('.follow,.unfollow').css({'display':'block'});
       });
   }
   else if (g_artist_gid != '') {
       $('.follow,.unfollow').css({'display':'block'});
   }
    
    // click events on follow button
    $('.follow').live('click', function() {
        if (!logged_in_user) {
            flashMsg(_t('ERR_ADD_FAVORITES'),true);
        }
        else {
            g_artist_gid = $(this).attr('id');
            $.ajax({
                url: '/'+language+'/subscriptions/follow/'+g_artist_gid,
                data: {},
                dataType: 'json',
                error: function(){
                    flashMsg('Error occurred',true);
                },
                success: function(json) {
                    if (json.error != true) {
                        flashMsg(json.msg);                
                        var c = _t('UNFOLLOW');
                        $('.follow').html(c).addClass('unfollow').removeClass('follow');
                    }
                }
            });
        }
    });
    
    // click events on unfollow button
    $('.unfollow').live('click', function() {
        g_artist_gid = $(this).attr('id');
        $.ajax({
            url: '/'+language+'/subscriptions/unfollow/0/'+g_artist_gid,
            data: {},
            dataType: 'json',
            error: function(){
                flashMsg('Error occurred',true);
            },
            success: function(json) {
                if (json.error != true) {
                    flashMsg(json.msg);
                    var c = _t('FOLLOW');
                    $('.unfollow').html(c).addClass('follow').removeClass('unfollow');
                }
            }
        });
    });
    
    $('.flashmsg').click(function(){
        $(this).fadeOut();
    });
});

flashMsg = function(msg, error) {
    var cls = 'highlight';
    var icn = 'info';
    if (error == true) {
        cls = 'error';
        icn = 'alert';
    }
    $('.flashmsg > div')
        .removeClass('ui-state-highlight').addClass('ui-state-'+cls)
        .children().html('<span style="float: left; margin-right: 0.3em;" class="ui-icon ui-icon-'+icn+'"></span>'+msg)
        .parent().parent().show();
};

name2seo = function(s) {
    s=s.replace(/[\s\W  ]/g,'-');
    return s;
};

// translate the constant to current language
_t = function(c) {
    if (typeof txt[c] != 'undefined') {
        return txt[c];
    }
    return c;
};