render_search = function(json){ $("#search_json").remove(); //top level containers var buffer = '
Search Results
'; //get count var count = 0; switch (json['mode']) { case 'single': count = json['count_single']; break; case 'global': count = json['count_global']; break; } //remove quotes from search query if (json['terms'] != '' || json['terms'] !== null) json['terms'].replace('"','', 'g'); //myFwerPlayer.setHighlightWord(json['terms']); //add header buffer += '
'; if (json['mode'] == 'single') { if (count > 0) { buffer += '“' + json['terms'] + '” appears in ' + count + ' places in this video.'; } else { buffer += '' + json['notice'] + ''; } if (json['count_global'] > 0) { buffer += '
Search All Videos
'; } } else { if (count > 0) { var mention_single = ''; if(json['count_single'] > 0) { mention_single = '' + json['count_single'] + ' places in this video and '; } buffer += '“' + json['terms'] + '” appears in ' + mention_single + '' + count + ' places in ' + (json['count_presentation'] - 1) + ' other videos.'; } else { buffer += '' + json['notice'] + ''; } if (json['count_single'] > 0) { buffer += '
Search Only This Video
'; } } if (json['correction'] && count < 1) { if (json['correction'].length > 0) { buffer += '
Did you mean: ' + json['correction'] + ''; } } if (json['back']) { if (json['back']['landing_page']) { if (json['back']['landing_page'].length > 0) { buffer += '
Back to: ' + json['back']['title'] + ''; } } } if (count > 0 && json['mode'] == 'single') { buffer += '

Relevance
Time
'; } buffer += '
'; //loop through rows var row = {}; var last_presentation_id = ''; var link = ''; var presentation_count = 0; var toggle_class = ''; var toggle_style = ''; for (var i = 0; i < json['rows'].length; i++) { row = json['rows'][i]; if (json['mode'] == 'single') { link = row['seconds']; if (row['presentation_id'] != json['presentation_id']) { continue; } } else { link = row['landing_page']; /* if (row['presentation_id'] == json['presentation_id']) { continue; } */ } if (json['mode'] == 'global') { if (row['presentation_id'] != last_presentation_id) { if (presentation_count > 3) { buffer += '
'; } presentation_count = 0; page_link = row['landing_page'].split('?'); buffer += '
'; } presentation_count++; if (presentation_count > 3) { toggle_class = ' hidden_row_' + last_presentation_id; toggle_style = ' style="display: none" '; } else { toggle_class = ''; toggle_style = ''; } last_presentation_id = row['presentation_id']; } buffer += '
'; buffer += '
'; buffer += '
'; buffer += '
' + row['blob_text'] + '
'; buffer += ''; buffer += '
' + row['seconds_display'] + '
'; buffer += '
'; buffer += '
'; } if (presentation_count > 3) { buffer += '
'; } //footer buffer += '
'; //add search div to page $("body").prepend('
'); //position the div var result_anchor = $("#result_anchor").val(); var offset = $("." + result_anchor).offset(); $("#search_json") .css({ top: (offset['top'] + 'px'), left: (offset['left'] + 'px')}) //add the html .html(buffer); $("#correction").click( function() { $(".search_input").val($(this).html()); $("#search_form").submit(); } ); //add drag behavior $("#search_json").draggable({ handle: '#handle'}); //add behavior to remove the div $("#search_json #close").click(function (e) { $("#search_json").remove(); }); //scroll to the top of the page $.scrollTo('#presentation_title', 1200); //add jumpto functionality to links $(".autojump") .click(function (e) { var altval = $(this).attr("tc"); if (altval.length < 20) { try { Main.setTimeCode("flash_player", altval); } catch (err) {} } else { var seconds = Main.getTimeCode("flash_player"); window.location = altval + '&from_presentation_offset=' + seconds; } }) .css({ cursor: 'pointer' }); //add switching functionality $("#search_toggle") .click(function (e) { var mode = ''; if (json['mode'] == 'single') { mode = 'global'; } else { mode = 'single'; } $.ajax({ type: "GET", url: "/ajax/search_json/index.php", data: {mode: mode, search: json['terms'], presentation_id: json['presentation_id'], minisite_id: json['minisite_id']}, dataType: "json", success: function(json) { render_search(json); }, error: function() { alert('error'); } }); }); $(".hidden_row") .click(function (e) { var hide_presentation_id = $(this).attr("alt"); var hide_class = 'hidden_row_' + hide_presentation_id; $("." + hide_class).css({ display: 'block' }); $(this).parent() .css({ display: 'none' }); }); if($("#sort_by").val() == "relevancy") { $("#relevance_radio").addClass("radio_on"); } else if($("#sort_by").val() == "time") { $("#time_radio").addClass("radio_on"); } $("#relevance_radio").click ( function() { if($("#sort_by").val() == "time") { $("#sort_by").val("relevancy"); $("#search_form").submit(); } } ); $("#time_radio").click ( function() { if($("#sort_by").val() == "relevancy") { $("#sort_by").val("time"); $("#search_form").submit(); } } ); };