• C
  • G

RETURN TO PROJECT

DanceCentral.com


jquery.dancecentral.js

jQuery / JavaScript

  
    $(document).ready(function(){
        var current;
        var songlist;
        var filteredlist;
        var filters = {
            format: null,
            decade: null,
            difficulty: null,
            released: null,
            count: null,
            sorting: null,
            exception: null
        }

        initHomeSongs = function () {
            $.get('/wp-content/themes/turbo/songs-helper.php', function(data) {
                songlist = jQuery.parseJSON(data);

                filters.format = "Downloadable";
                filters.sorting = "release";
                filters.count = 4;

                filterData();
                drawHomeSongs();
                pageInit();
            });
        }

        initSongGrid = function () {
            $.get('/wp-content/themes/turbo/songs-helper.php', function(data) {
                songlist = jQuery.parseJSON(data);

                $(".song-grid").tablesorter();

                filterData();
                drawSongGrid();
                drawSongFilterMenu();
                pageInit();
            });
        }

        updateSongGrid = function (name, setting) {
            resetFilters();

            if(name != undefined) {
                filters[name] = setting;
            }

            filterData();
            drawSongGrid();
        }

        initLatestSongs = function () {
            $.get('/wp-content/themes/turbo/songs-helper.php', function(data) {

                songlist = jQuery.parseJSON(data);

                filters.format = "Downloadable";
                filters.sorting = "release";
                filters.count = 4;

                filterData();
                drawLatestSongs();
                pageInit();
            });
        }

        initLatestSongsSidebar = function (exception) {
            $.get('/wp-content/themes/turbo/songs-helper.php', function(data) {
                songlist = jQuery.parseJSON(data);

                filters.exception = exception;
                filters.format = "Downloadable";
                filters.sorting = "release";
                filters.count = 3;

                filterData();
                drawLatestSongsSidebar();
                pageInit();
            });
        }

        initGamePageDC1SongList = function () {
            $.get('/wp-content/themes/turbo/songs-helper.php', function(data) {
                songlist = jQuery.parseJSON(data);

                filters.format = "On Disc - DC 1";
                filters.sorting = "artist";

                filterData();

                drawGamePageDC1SongList();
                pageInit();
            });
        }
        initGamePageDC2SongList = function () {
            $.get('/wp-content/themes/turbo/songs-helper.php', function(data) {
                songlist = jQuery.parseJSON(data);

                filters.format = "On Disc - DC 2";
                filters.sorting = "artist";

                filterData();

                drawGamePageDC2SongList();
                pageInit();
            });
        }
        initGamePageDC3SongList = function () {
            $.get('/wp-content/themes/turbo/songs-helper.php', function(data) {
                songlist = jQuery.parseJSON(data);

                filters.format = "On Disc - DC 3";
                filters.sorting = "artist";

                filterData();

                drawGamePageDC3SongList();
                pageInit();
            });
        }


        filterData = function () {
            filteredlist = new Array();

            // Check against filter parameters.
            $.each(songlist,function(i,songitem){
                var is_match = true;

                if(filters.format != null && filters.format != songitem.format) {
                    is_match = false;
                }

                if(filters.decade != null && filters.decade != songitem.decade) {
                    is_match = false;
                }

                if(filters.difficulty != null && filters.difficulty != songitem.difficulty) {
                    is_match = false;
                }

                if(filters.exception != null && filters.exception == songitem.shortname) {
                    is_match = false;
                }

                if(is_match) {
                    filteredlist.push(songitem);
                }
            });

            // Sort on desired field.
            if(filters.sorting != null) {
                if(filters.sorting = "release") {
                    filteredlist.sort(sortbydate);
                    filteredlist.reverse();
                } else if(filters.sorting = "artist") {
                    filteredlist.sort(sortbyartist);
                }
            }

            // Only return the desired number of items.
            if(filters.count != null) {
                filteredlist = filteredlist.slice(0, filters.count);
            }


        }

        drawHomeSongs = function () {
            var draw = "";

            $.each(filteredlist,function(i,songitem){

                draw += "<li>";
                draw +=		"<a href='" + songitem.url + "'>";
                draw +=			"<div class='album-home'>";
                draw +=         	"<img class='inside glow' src='" + songitem.artwork + "'>";
                draw +=			"</div>"
                draw +=			"<p class='song-artist'>" + songitem.artist + "</p>";
                draw +=			"<p class='song-title'>" + songitem.title + "</p>";
                draw +=		"</a>";

                draw += "</li>";
            });

            $(".home-songs").html(draw);

            setReflect();
        }


        drawSongGrid = function () {

            $(".song-data").html("");

            var draw = "";

            if(filteredlist.length == "0") {
                $('.no-results').show();	
            } else {
                $('.no-results').hide();	
            }

            $.each(filteredlist,function(i,songitem){

                draw += "<tr url=" + songitem.url + ">";
                draw +=	"<td class='song'>" + songitem.title + "</td>";
                draw +=	"<td class='artist'>" + songitem.artist + "</td>";
                draw +=	"<td class='year'>" + songitem.decade + "</td>";
                draw +=	"<td class='rating'><span class='stars-" + songitem.rating + "'></span></td>";
                draw +=	"<td class='difficulty'>" + songitem.difficulty + "</td>";

                if (songitem.format == 'On Disc - DC 1')
                    draw +=	"<td class='format'>Dance Central</td>";
                else if (songitem.format == 'On Disc - DC 2')
                    draw +=	"<td class='format'>Dance Central 2</td>";
                else if (songitem.format == 'On Disc - DC 3')
                    draw +=	"<td class='format'>Dance Central 3</td>";
                else
                    draw +=	"<td class='format'>" + songitem.format + "</td>";

                draw +=	"<td class='released'>" + songitem.release + "</td>";
                draw += "</tr>";
            });

            $(".song-data").html(draw);

            $(".song-list").trigger("update");
            var sorting = [[0,0]];
            $(".song-list").trigger("sorton", [sorting]);

            $("tr").click(function(){
                window.location = $(this).attr("url");
            });
        }

        drawSongFilterMenu = function () {
            $("div.drop-menu a.selected").click(function(){
                $(".drop-list").hide();
                $menu = $(this).next(".drop-list");
                $menu.show( );

                $(".drop-list li").click(function() {
                    $(this).siblings().removeClass("current");
                    $(this).addClass("current");
                    $(this).parent().prev().html($(this).find('a').html());	

                    $menu.hide();

                    filters = {
                        format: null,
                        decade: null,
                        difficulty: null,
                        released: null,
                        count: null,
                        sorting: null,
                        exception: null
                    }

                    var format = $("#format li.current a").attr("rel");
                    if (format == "null") { format = null; };
                    var decade = $("#decade li.current a").attr("rel");
                    if (decade == "null") { decade = null; };
                    var difficulty = $("#difficulty li.current a").attr("rel");
                    if (difficulty == "null") { difficulty = null; };

                    filters.format = format;
                    filters.decade = decade;
                    filters.difficulty = difficulty;

                    filterData();
                    drawSongGrid();

                    return false;

                });


                $( "body" ).click( function ( ) {
                    $menu.hide( );
                });

                return false;
            });
        }

        drawLatestSongs = function () {
            var draw = "";

            $.each(filteredlist,function(i,songitem){

                draw += "<div class='dlc-item'>";
                draw +=		"<a href='" + songitem.url + "'>";
                draw += 		"<img class='inside glow' src='" + songitem.artwork + "'>";
                draw += 		"<p class='song-artist'>" + songitem.artist + "</p>";
                draw += 		"<p class='song-title'>" + songitem.title + "</p>";
                draw +=		"</a>";
                draw += 	"<p><a class='xbox-action-button' href='" + songitem.xbox + "'>BUY IT NOW</a></p>";
                draw += "</div>";
            });

            $(".latest-dlc").html(draw);

            setReflect();
        }

        drawLatestSongsSidebar = function () {
            var draw = "";

            $.each(filteredlist,function(i,songitem){

                draw +=	"<li>";
                draw +=	"	<a href=" + songitem.url + ">";
                draw +=	"		<div class='album-small'>";
                draw +=	"			<img class='inside' src='" + songitem.artwork + "'>";
                draw +=	"		</div>";
                draw +=	"		<p class='song-artist'>" + songitem.artist + "</p>";
                draw +=	"		<p class='song-title'>" + songitem.title + "</p>";
                draw +=	"	</a>"
                draw +=	"	<p><a class='xbox-action-button' href='" + songitem.xbox + "'>BUY IT NOW</a></p>";
                draw += "</li>";

            });

            $(".songs-sidebar").html(draw);

            setReflect();
        }

        drawGamePageDC1SongList = function () {
            var draw = "";

            $.each(filteredlist,function(i,songitem){
                draw += "<li>";
                draw += 	"<a href='" + songitem.url + "'>";
                draw +=			"<p class='song-artist'>" + songitem.artist + "</p>";
                draw +=			"<p class='song-title'>" + songitem.title + "</p>";
                draw += 	"</a>";
                draw += "</li>";
            });

            $("#dc1-list").html(draw);

            //setReflect();
        }

        drawGamePageDC2SongList = function () {
            var draw = "";

            $.each(filteredlist,function(i,songitem){
                draw += "<li>";
                draw += 	"<a href='" + songitem.url + "'>";
                draw +=			"<p class='song-artist'>" + songitem.artist + "</p>";
                draw +=			"<p class='song-title'>" + songitem.title + "</p>";
                draw += 	"</a>";
                draw += "</li>";
            });

            $("#dc2-list").html(draw);

            //setReflect();
        }

        drawGamePageDC3SongList = function () {
            var draw = "";

            $.each(filteredlist,function(i,songitem){
                draw += "<li>";
                draw += 	"<a href='" + songitem.url + "'>";
                draw +=			"<p class='song-artist'>" + songitem.artist + "</p>";
                draw +=			"<p class='song-title'>" + songitem.title + "</p>";
                draw += 	"</a>";
                draw += "</li>";
            });

            $("#dc3-list").html(draw);

            //setReflect();
        }

        formatDate = function (date) {
            var datePart = date.match(/\d+/g);
            day = datePart[0];
            month = datePart[1];
            year = datePart[2];

            return year+'/'+day+'/'+month;
        }

        resetFilters = function () {
            filters = {
                format: null,
                released: null,
                decade: null,
                count: null,
                sorting: null,
                exception: null
            }
        }

        sortbydate = function (a, b){
            var aName = a.sortdate.toLowerCase();
            var bName = b.sortdate.toLowerCase();
            return ((aName < bName) ? -1 : ((aName > bName) ? 1 : 0));
        }

        sortbyartist = function (a, b){
            var aName = a.artist.toLowerCase();
            var bName = b.artist.toLowerCase();
            return ((aName < bName) ? -1 : ((aName > bName) ? 1 : 0));
        }

        setReflect = function () {
            var options = { height:0.3, opacity:0.2};
            $(".inside").reflect(options);
        }

        monthNameToNumber = function (monthName) {
            var monthNum;

            switch(monthName)
            {
                case "Jan": monthNum = "01"; break;
                case "Feb": monthNum = "02"; break;
                case "Mar": monthNum = "03"; break;
                case "Apr": monthNum = "04"; break;
                case "May": monthNum = "05"; break;
                case "Jun": monthNum = "06"; break;
                case "Jul": monthNum = "07"; break;
                case "Aug": monthNum = "08"; break;
                case "Sep": monthNum = "09"; break;
                case "Oct": monthNum = "10"; break;
                case "Nov": monthNum = "11"; break;
                case "Dec": monthNum = "12"; break;
            }

            return monthNum;
        };

    });
  

RETURN TO PROJECT

DanceCentral.com