#131 fix for default selected tab

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

@ -5,283 +5,294 @@
return opts.inverse(this); return opts.inverse(this);
}); });
var searchSource = $("#search-template").html(); $(function () {
var musicSource = $("#music-template").html();
var searchTemplate = Handlebars.compile(searchSource);
var musicTemplate = Handlebars.compile(musicSource);
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 var searchTimer = 0;
$("#movieSearchContent").on("input", function () {
if (searchTimer) { // fix for selecting a default tab
clearTimeout(searchTimer); 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');
} }
$('#movieSearchButton').attr("class","fa fa-spinner fa-spin");
searchTimer = setTimeout(movieSearch, 400);
});
$('#moviesComingSoon').on('click', function (e) { // Type in movie search
e.preventDefault(); $("#movieSearchContent").on("input", function () {
moviesComingSoon(); if (searchTimer) {
}); clearTimeout(searchTimer);
}
$('#movieSearchButton').attr("class", "fa fa-spinner fa-spin");
searchTimer = setTimeout(movieSearch, 400);
$('#moviesInTheaters').on('click', function (e) { });
e.preventDefault();
moviesInTheaters();
});
// Type in TV search $('#moviesComingSoon').on('click', function (e) {
$("#tvSearchContent").on("input", function () { e.preventDefault();
if (searchTimer) { moviesComingSoon();
clearTimeout(searchTimer); });
}
$('#tvSearchButton').attr("class", "fa fa-spinner fa-spin");
searchTimer = setTimeout(tvSearch, 400);
});
// Click TV dropdown option $('#moviesInTheaters').on('click', function (e) {
$(document).on("click", ".dropdownTv", function (e) { e.preventDefault();
e.preventDefault(); moviesInTheaters();
var buttonId = e.target.id; });
if ($("#" + buttonId).attr('disabled')) {
return; // Type in TV search
} $("#tvSearchContent").on("input", function () {
if (searchTimer) {
clearTimeout(searchTimer);
}
$('#tvSearchButton').attr("class", "fa fa-spinner fa-spin");
searchTimer = setTimeout(tvSearch, 400);
});
$("#" + buttonId).prop("disabled", true); // Click TV dropdown option
loadingButton(buttonId, "primary"); $(document).on("click", ".dropdownTv", function (e) {
e.preventDefault();
var buttonId = e.target.id;
if ($("#" + buttonId).attr('disabled')) {
return;
}
$("#" + buttonId).prop("disabled", true);
loadingButton(buttonId, "primary");
var $form = $('#form' + buttonId);
var data = $form.serialize();
var seasons = $(this).attr("season-select");
if (seasons === "2") {
// Send over the latest
data = data + "&seasons=latest";
}
if (seasons === "1") {
// Send over the first season
data = data + "&seasons=first";
} var $form = $('#form' + buttonId);
var data = $form.serialize();
var seasons = $(this).attr("season-select");
if (seasons === "2") {
// Send over the latest
data = data + "&seasons=latest";
}
if (seasons === "1") {
// Send over the first season
data = data + "&seasons=first";
var type = $form.prop('method'); }
var url = $form.prop('action');
sendRequestAjax(data, type, url, buttonId); var type = $form.prop('method');
}); var url = $form.prop('action');
// Search Music sendRequestAjax(data, type, url, buttonId);
$("#musicSearchContent").on("input", function () { });
if (searchTimer) {
clearTimeout(searchTimer);
}
$('#musicSearchButton').attr("class", "fa fa-spinner fa-spin");
searchTimer = setTimeout(musicSearch, 400);
}); // 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) {
e.preventDefault();
var buttonId = e.target.id;
if ($("#" + buttonId).attr('disabled')) {
return;
}
$("#" + buttonId).prop("disabled", true); // Click Request for movie
loadingButton(buttonId, "primary"); $(document).on("click", ".requestMovie", function (e) {
e.preventDefault();
var buttonId = e.target.id;
if ($("#" + buttonId).attr('disabled')) {
return;
}
$("#" + buttonId).prop("disabled", true);
loadingButton(buttonId, "primary");
var $form = $('#form' + buttonId);
var type = $form.prop('method'); var $form = $('#form' + buttonId);
var url = $form.prop('action');
var data = $form.serialize();
sendRequestAjax(data, type, url, buttonId); var type = $form.prop('method');
var url = $form.prop('action');
var data = $form.serialize();
}); sendRequestAjax(data, type, url, buttonId);
// Click Request for album });
$(document).on("click", ".requestAlbum", function (e) {
e.preventDefault();
var buttonId = e.target.id;
if ($("#" + buttonId).attr('disabled')) {
return;
}
$("#" + buttonId).prop("disabled", true); // Click Request for album
loadingButton(buttonId, "primary"); $(document).on("click", ".requestAlbum", function (e) {
e.preventDefault();
var buttonId = e.target.id;
if ($("#" + buttonId).attr('disabled')) {
return;
}
$("#" + buttonId).prop("disabled", true);
loadingButton(buttonId, "primary");
var $form = $('#form' + buttonId);
var type = $form.prop('method'); var $form = $('#form' + buttonId);
var url = $form.prop('action');
var data = $form.serialize();
sendRequestAjax(data, type, url, buttonId); var type = $form.prop('method');
var url = $form.prop('action');
var data = $form.serialize();
}); sendRequestAjax(data, type, url, buttonId);
function sendRequestAjax(data, type, url, buttonId) {
$.ajax({
type: type,
url: url,
data: data,
dataType: "json",
success: function (response) {
console.log(response);
if (response.result === true) {
generateNotify(response.message || "Success!", "success");
$('#' + buttonId).html("<i class='fa fa-check'></i> Requested");
$('#' + buttonId).removeClass("btn-primary-outline");
$('#' + buttonId).removeAttr("data-toggle");
$('#' + buttonId).addClass("btn-success-outline");
} else {
generateNotify(response.message, "warning");
$('#' + buttonId).html("<i class='fa fa-plus'></i> Request");
$('#' + buttonId).attr("data-toggle", "dropdown");
$("#" + buttonId).removeAttr("disabled");
}
},
error: function (e) {
console.log(e);
generateNotify("Something went wrong!", "danger");
}
}); });
}
function movieSearch() { function sendRequestAjax(data, type, url, buttonId) {
var query = $("#movieSearchContent").val(); $.ajax({
getMovies("/search/movie/" + query); type: type,
} url: url,
data: data,
dataType: "json",
success: function (response) {
console.log(response);
if (response.result === true) {
generateNotify(response.message || "Success!", "success");
$('#' + buttonId).html("<i class='fa fa-check'></i> Requested");
$('#' + buttonId).removeClass("btn-primary-outline");
$('#' + buttonId).removeAttr("data-toggle");
$('#' + buttonId).addClass("btn-success-outline");
} else {
generateNotify(response.message, "warning");
$('#' + buttonId).html("<i class='fa fa-plus'></i> Request");
$('#' + buttonId).attr("data-toggle", "dropdown");
$("#" + buttonId).removeAttr("disabled");
}
},
error: function (e) {
console.log(e);
generateNotify("Something went wrong!", "danger");
}
});
}
function moviesComingSoon() { function movieSearch() {
getMovies("/search/movie/upcoming"); var query = $("#movieSearchContent").val();
} getMovies("/search/movie/" + query);
}
function moviesInTheaters() { function moviesComingSoon() {
getMovies("/search/movie/playing"); getMovies("/search/movie/upcoming");
} }
function getMovies(url) { function moviesInTheaters() {
$("#movieList").html(""); getMovies("/search/movie/playing");
}
function getMovies(url) {
$("#movieList").html("");
$.ajax(url).success(function (results) {
if (results.length > 0) {
results.forEach(function(result) {
var context = buildMovieContext(result);
var html = searchTemplate(context); $.ajax(url).success(function (results) {
$("#movieList").append(html); if (results.length > 0) {
}); results.forEach(function (result) {
} var context = buildMovieContext(result);
else {
$("#movieList").html(noResultsHtml);
}
$('#movieSearchButton').attr("class","fa fa-search");
});
};
function tvSearch() {
var query = $("#tvSearchContent").val();
getTvShows("/search/tv/" + query);
}
function getTvShows(url) {
$("#tvList").html("");
$.ajax(url).success(function (results) {
if (results.length > 0) {
results.forEach(function(result) {
var context = buildTvShowContext(result);
var html = searchTemplate(context);
$("#tvList").append(html);
});
}
else {
$("#tvList").html(noResultsHtml);
}
$('#tvSearchButton').attr("class", "fa fa-search");
});
};
function musicSearch() { var html = searchTemplate(context);
var query = $("#musicSearchContent").val(); $("#movieList").append(html);
getMusic("/search/music/" + query); });
} }
else {
$("#movieList").html(noResultsHtml);
}
$('#movieSearchButton').attr("class", "fa fa-search");
});
};
function getMusic(url) { function tvSearch() {
$("#musicList").html(""); var query = $("#tvSearchContent").val();
getTvShows("/search/tv/" + query);
}
$.ajax(url).success(function (results) { function getTvShows(url) {
if (results.length > 0) { $("#tvList").html("");
results.forEach(function (result) {
var context = buildMusicContext(result);
var html = musicTemplate(context); $.ajax(url).success(function (results) {
$("#musicList").append(html); if (results.length > 0) {
}); results.forEach(function (result) {
} var context = buildTvShowContext(result);
else { var html = searchTemplate(context);
$("#musicList").html(noResultsMusic); $("#tvList").append(html);
} });
$('#musicSearchButton').attr("class", "fa fa-search"); }
}); else {
}; $("#tvList").html(noResultsHtml);
}
function buildMovieContext(result) { $('#tvSearchButton').attr("class", "fa fa-search");
var date = new Date(result.releaseDate); });
var year = date.getFullYear();
var context = {
posterPath: result.posterPath,
id: result.id,
title: result.title,
overview: result.overview,
voteCount: result.voteCount,
voteAverage: result.voteAverage,
year: year,
type: "movie",
imdb: result.imdbId
}; };
return context; function musicSearch() {
} var query = $("#musicSearchContent").val();
getMusic("/search/music/" + query);
function buildTvShowContext(result) { }
var date = new Date(result.firstAired);
var year = date.getFullYear(); function getMusic(url) {
var context = { $("#musicList").html("");
posterPath: result.banner,
id: result.id, $.ajax(url).success(function (results) {
title: result.seriesName, if (results.length > 0) {
overview: result.overview, results.forEach(function (result) {
year: year, var context = buildMusicContext(result);
type: "tv",
imdb: result.imdbId var html = musicTemplate(context);
}; $("#musicList").append(html);
return context; });
} }
else {
function buildMusicContext(result) { $("#musicList").html(noResultsMusic);
}
var context = { $('#musicSearchButton').attr("class", "fa fa-search");
id: result.id, });
title: result.title,
overview: result.overview,
year: result.releaseDate,
type: "album",
trackCount: result.trackCount,
coverArtUrl: result.coverArtUrl,
artist: result.artist,
releaseType: result.releaseType,
country: result.country
}; };
return context; function buildMovieContext(result) {
} var date = new Date(result.releaseDate);
var year = date.getFullYear();
var context = {
posterPath: result.posterPath,
id: result.id,
title: result.title,
overview: result.overview,
voteCount: result.voteCount,
voteAverage: result.voteAverage,
year: year,
type: "movie",
imdb: result.imdbId
};
return context;
}
function buildTvShowContext(result) {
var date = new Date(result.firstAired);
var year = date.getFullYear();
var context = {
posterPath: result.banner,
id: result.id,
title: result.seriesName,
overview: result.overview,
year: year,
type: "tv",
imdb: result.imdbId
};
return context;
}
function buildMusicContext(result) {
var context = {
id: result.id,
title: result.title,
overview: result.overview,
year: result.releaseDate,
type: "album",
trackCount: result.trackCount,
coverArtUrl: result.coverArtUrl,
artist: result.artist,
releaseType: result.releaseType,
country: result.country
};
return context;
}
});

Loading…
Cancel
Save