#131 fix for default selected tab

pull/140/head
Drewster727 9 years ago
parent c52ca41e32
commit 96fde83488

@ -5,44 +5,53 @@
return opts.inverse(this);
});
var searchSource = $("#search-template").html();
var musicSource = $("#music-template").html();
var searchTemplate = Handlebars.compile(searchSource);
var musicTemplate = Handlebars.compile(musicSource);
$(function () {
var searchTimer = 0;
var searchSource = $("#search-template").html();
var musicSource = $("#music-template").html();
var searchTemplate = Handlebars.compile(searchSource);
var musicTemplate = Handlebars.compile(musicSource);
// Type in movie search
$("#movieSearchContent").on("input", function () {
var searchTimer = 0;
// fix for selecting a default tab
var $tabs = $('#nav-tabs').children('li');
if ($tabs.filter(function (li) { return $(li).hasClass('active') }).length <= 0) {
$tabs.first().children('a:first-child').tab('show');
}
// Type in movie search
$("#movieSearchContent").on("input", function () {
if (searchTimer) {
clearTimeout(searchTimer);
}
$('#movieSearchButton').attr("class","fa fa-spinner fa-spin");
$('#movieSearchButton').attr("class", "fa fa-spinner fa-spin");
searchTimer = setTimeout(movieSearch, 400);
});
});
$('#moviesComingSoon').on('click', function (e) {
$('#moviesComingSoon').on('click', function (e) {
e.preventDefault();
moviesComingSoon();
});
});
$('#moviesInTheaters').on('click', function (e) {
$('#moviesInTheaters').on('click', function (e) {
e.preventDefault();
moviesInTheaters();
});
});
// Type in TV search
$("#tvSearchContent").on("input", function () {
// Type in TV search
$("#tvSearchContent").on("input", function () {
if (searchTimer) {
clearTimeout(searchTimer);
}
$('#tvSearchButton').attr("class", "fa fa-spinner fa-spin");
searchTimer = setTimeout(tvSearch, 400);
});
});
// Click TV dropdown option
$(document).on("click", ".dropdownTv", function (e) {
// Click TV dropdown option
$(document).on("click", ".dropdownTv", function (e) {
e.preventDefault();
var buttonId = e.target.id;
if ($("#" + buttonId).attr('disabled')) {
@ -70,20 +79,20 @@ $(document).on("click", ".dropdownTv", function (e) {
var url = $form.prop('action');
sendRequestAjax(data, type, url, buttonId);
});
});
// Search Music
$("#musicSearchContent").on("input", function () {
// Search Music
$("#musicSearchContent").on("input", function () {
if (searchTimer) {
clearTimeout(searchTimer);
}
$('#musicSearchButton').attr("class", "fa fa-spinner fa-spin");
searchTimer = setTimeout(musicSearch, 400);
});
});
// Click Request for movie
$(document).on("click", ".requestMovie", function (e) {
// Click Request for movie
$(document).on("click", ".requestMovie", function (e) {
e.preventDefault();
var buttonId = e.target.id;
if ($("#" + buttonId).attr('disabled')) {
@ -102,10 +111,10 @@ $(document).on("click", ".requestMovie", function (e) {
sendRequestAjax(data, type, url, buttonId);
});
});
// Click Request for album
$(document).on("click", ".requestAlbum", function (e) {
// Click Request for album
$(document).on("click", ".requestAlbum", function (e) {
e.preventDefault();
var buttonId = e.target.id;
if ($("#" + buttonId).attr('disabled')) {
@ -124,9 +133,9 @@ $(document).on("click", ".requestAlbum", function (e) {
sendRequestAjax(data, type, url, buttonId);
});
});
function sendRequestAjax(data, type, url, buttonId) {
function sendRequestAjax(data, type, url, buttonId) {
$.ajax({
type: type,
url: url,
@ -153,28 +162,28 @@ function sendRequestAjax(data, type, url, buttonId) {
generateNotify("Something went wrong!", "danger");
}
});
}
}
function movieSearch() {
function movieSearch() {
var query = $("#movieSearchContent").val();
getMovies("/search/movie/" + query);
}
}
function moviesComingSoon() {
function moviesComingSoon() {
getMovies("/search/movie/upcoming");
}
}
function moviesInTheaters() {
function moviesInTheaters() {
getMovies("/search/movie/playing");
}
}
function getMovies(url) {
function getMovies(url) {
$("#movieList").html("");
$.ajax(url).success(function (results) {
if (results.length > 0) {
results.forEach(function(result) {
results.forEach(function (result) {
var context = buildMovieContext(result);
var html = searchTemplate(context);
@ -184,21 +193,21 @@ function getMovies(url) {
else {
$("#movieList").html(noResultsHtml);
}
$('#movieSearchButton').attr("class","fa fa-search");
$('#movieSearchButton').attr("class", "fa fa-search");
});
};
};
function tvSearch() {
function tvSearch() {
var query = $("#tvSearchContent").val();
getTvShows("/search/tv/" + query);
}
}
function getTvShows(url) {
function getTvShows(url) {
$("#tvList").html("");
$.ajax(url).success(function (results) {
if (results.length > 0) {
results.forEach(function(result) {
results.forEach(function (result) {
var context = buildTvShowContext(result);
var html = searchTemplate(context);
$("#tvList").append(html);
@ -209,14 +218,14 @@ function getTvShows(url) {
}
$('#tvSearchButton').attr("class", "fa fa-search");
});
};
};
function musicSearch() {
function musicSearch() {
var query = $("#musicSearchContent").val();
getMusic("/search/music/" + query);
}
}
function getMusic(url) {
function getMusic(url) {
$("#musicList").html("");
$.ajax(url).success(function (results) {
@ -233,9 +242,9 @@ function getMusic(url) {
}
$('#musicSearchButton').attr("class", "fa fa-search");
});
};
};
function buildMovieContext(result) {
function buildMovieContext(result) {
var date = new Date(result.releaseDate);
var year = date.getFullYear();
var context = {
@ -251,9 +260,9 @@ function buildMovieContext(result) {
};
return context;
}
}
function buildTvShowContext(result) {
function buildTvShowContext(result) {
var date = new Date(result.firstAired);
var year = date.getFullYear();
var context = {
@ -266,9 +275,9 @@ function buildTvShowContext(result) {
imdb: result.imdbId
};
return context;
}
}
function buildMusicContext(result) {
function buildMusicContext(result) {
var context = {
id: result.id,
@ -284,4 +293,6 @@ function buildMusicContext(result) {
};
return context;
}
}
});

Loading…
Cancel
Save