var baseVtabImageUrl = 'http://wds.mp.advection.net/mp/wncn/_dld/vms/'; vtab_current_tab = 0 function redrawVtabPagination(total, search_function) { $('#vtab_grid').createAppend( 'div', { className: "", id: "vtab_pagination" }, "" ); var num_pages = (total / vtab_per_page); var pagination = ""; // Prevent next page if there's none there if (num_pages == Math.round(num_pages)) num_pages--; if(vtab_page > 1) pagination += "Previous | " if (total > (vtab_page * vtab_per_page)) { p = parseInt(vtab_page ) + 1 pagination += "Next " } $("#vtab_pagination").html(pagination); } function vtabPaginate(p, search_function) { vtab_page = parseInt(p); eval(search_function+"();") } // Smooth out the container expansion/contraction w/search results poping in w/animation function vtabResizeResultsContainer(num_results) { num_rows = Math.ceil(Math.min(num_results, vtab_per_page) / 3); new_height = Math.round(num_rows) * 240 + 30; $("#photo_grid").animate({ height: new_height }, 400); } /* Util function that gets called to trigger animated search results */ function animVtabResult(count) { $("#vtab_video_container_"+count).fadeIn("slow") } function stripslashes(str) { str=str.replace(/\\'/g,'\''); str=str.replace(/\\"/g,'"'); str=str.replace(/\\\\/g,'\\'); str=str.replace(/\\0/g,'\0'); return str; } /* Parse json search results & animate the display */ function displayVtabSearchResults(msg, search_function) { // Evaluage the json array resultset = eval('(' + msg + ')'); data = resultset['results'] total = resultset['total'] // Iterate through array of results to build out a list var num_videos = data.length; vtabResizeResultsContainer(num_videos) $("#vtab_grid").html(""); var search_results = ''; num_display_videos = Math.min(num_videos, vtab_per_page) for (count = 0; count < num_display_videos; count++) { row = data[count]; image = baseVtabImageUrl + row['id'] + "/" + row['filename'].replace("'", "'") + '_'+row['thumbnail_seconds_in']+'_130x97.jpg'; create_timestamp = new Date(row['create_timestamp'] * 1000); video_url = vtab_video_page_url +row['id'] + "/" + stripslashes(row['title'])+"/"; // Build the row var video = "
" video += "" video += "
" video += "
" video += '

' + row['title'] + "

" video += '
' + row['author_screen_name'] + "
" video += '
'; $(video).appendTo("#vtab_grid") $("#vtab_video_container_"+count).css("display", "none"); setTimeout("animVtabResult("+count+");" , count*200) } if (total > 0) redrawVtabPagination(total, search_function) return num_display_videos } function yourVideosSearchPreset() { $("#pagination").html(""); vtabResizeResultsContainer(0) $("#photo_grid").html(""); $no_videos_message = "
You Haven't Uploaded Any Videos Yet.
"; if (contributor_member_id) { $.ajax({ type: "GET", url: json_search_server+"?contributor_member_id="+contributor_member_id +"&p=" + page + "&pp=" + (vtab_per_page + 1)+ "&approval_status=open|flagged&location="+vms_geo+"&file_upload_status=transcoded&order=create_timestamp&sort=desc", success: function(msg) { num_results = displayVtabSearchResults(msg, "yourVideosSearchPreset"); if (num_results == 0) { $("#photo_grid").html($no_videos_message); } } }); } else { $("#photo_grid").html($no_videos_message); } return false; } function ajaxSearchTab() { $("#pagination").html(""); vtabResizeResultsContainer(0) $("#vtab_grid").html(""); $.ajax({ type: "GET", url: json_search_server+"?p="+vtab_page+"&"+vtabs_options[vtab_current_tab]+"&format=json", success: function(msg) { num_results = displayVtabSearchResults(msg, "ajaxSearchTab"); if (num_results == 0) { $("#vtab_grid").html("
No Videos Yet For This Section
"); } } }); return false; } function vtabSearch() { $("#pagination").html(""); vtabResizeResultsContainer(0) $("#vtab_grid").html(""); params = "p="+vtab_page+"&pp=10&approval_status=open|flagged&file_upload_status=transcoded&order=create_timestamp&sort=desc&q="+$('#vtab-search-q').val(); $.ajax({ type: "GET", url: json_search_server+"?"+params+"&format=json", success: function(msg) { num_results = displayVtabSearchResults(msg, "vtabSearch"); if (num_results == 0) { $("#vtab_grid").html("
Sorry, no videos were found for that search.
"); } } }); return false; } function vtabClick(tab) { vtab_current_tab = tab vtab_page = 1; // Toggle css classes on tabs for (x = 0; x < vtabs_options.length; x++) $("#vtab_" + x).removeClass("active") $("#vtab_" + tab).addClass("active") ajaxSearchTab(); } function generateVtabs() { $('#'+vtab_container_id).createAppend( 'div', { className: "", id: "vtab_container_inner" }, "" ); search_html = "
" search_html += " " search_html += " " search_html += "
" $('#vtab_container_inner').append(search_html) // Create the ul for the tabs $('#vtab_container_inner').createAppend( 'ul', { id: "video_tabs" }, "" ); // Create each tab for (x = 0; x < vtabs_options.length; x++) { $('#video_tabs').createAppend( 'li', { className: 'result_date', id: "vtab_"+x }, [ 'a', { id:'video_tab_everything_link'}, vtab_names[x] ] ); $("#vtab_"+x).bind("click", function() { id = ((this.id).split("_"))[1]; vtabClick(id); }); } $("#vtab_0").addClass("active") $('#vtab_container_inner').createAppend( 'div', { className: "", id: "vtab_grid" }, "" ); } $(document).ready(function() { generateVtabs(); // Auto-load Tab 1 Search On Page Load ajaxSearchTab(0); });