Created
May 3, 2018 10:27
-
-
Save RahulSaini91/cd89d726154829ad1490a9e9fc8b8693 to your computer and use it in GitHub Desktop.
Movie Project
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//functions | |
function setCookie(cname, cvalue, exdays) { | |
var d = new Date(); | |
d.setTime(d.getTime() + (exdays*24*60*60*1000)); | |
var expires = "expires="+ d.toUTCString(); | |
document.cookie = cname + "=" + cvalue + ";" + expires + ";path=/"; | |
} | |
function getCookie(cname) { | |
var name = cname + "="; | |
var decodedCookie = decodeURIComponent(document.cookie); | |
var ca = decodedCookie.split(';'); | |
for(var i = 0; i < ca.length; i++) { | |
var c = ca[i]; | |
while (c.charAt(0) == ' ') { | |
c = c.substring(1); | |
} | |
if (c.indexOf(name) == 0) { | |
return c.substring(name.length, c.length); | |
} | |
} | |
return ""; | |
} | |
function checkCookie() { | |
var username = getCookie("username"); | |
if (username != "") { | |
alert("Welcome again " + username); | |
} else { | |
username = prompt("Please enter your name:", ""); | |
if (username != "" && username != null) { | |
setCookie("username", username, 365); | |
} | |
} | |
} | |
function movie_detail(obj,output){ | |
if(!obj) | |
return; | |
console.log(obj); | |
var html=''; | |
var thumb = obj.backdrop_path; | |
if(thumb=="null"||!thumb||thumb=='undefined'){ | |
thumb='//placehold.it/200x200/?text=Coming%20Soon'; | |
}else{ | |
thumb=config.img_domain+'/w500'+obj.backdrop_path; | |
} | |
html = "<div class='movie-detail'>"; | |
html += "<img src='"+thumb+"'/>"; | |
html += "<h4>"+obj.title+"</h4></div>"; | |
$('#'+output).html(html); | |
} | |
function list_movies(obj,output){ | |
if(!obj.length){ | |
$('#'+output).html("<div class='alert alert-danger'>No Movies Found</div>"); | |
return; | |
} | |
var html = "<div class='row'>"; | |
$(obj).each(function(key,value){ | |
var thumb = value.poster_path; | |
if(thumb=="null"||!thumb||thumb=='undefined'){ | |
thumb='//placehold.it/200x200/?text=Coming%20Soon'; | |
}else{ | |
thumb=config.img_domain+'/w200'+thumb; | |
} | |
var link = window.location.protocol+'//'+window.location.hostname+'/?movie/'+value.id+'/'+convert_slug(value.title); | |
html+="<div class='col-sm-3'><div class='thumb'><img src='"+thumb+"'/></div><div class='info'><a class='title' href='"+link+"'>"+value.title+"</a></div></div>"; | |
}); | |
html+='</div>'; | |
$('#'+output).html(html); | |
} | |
function get_slug(url,query) { | |
if(!url) | |
return; | |
url = url.split(/[?#]/); | |
if(url[1]){ | |
url = url[1].split(/[\/]/); | |
return url; | |
} | |
} | |
function param(name) { | |
return (location.search.split(name + '=')[1] || '').split('&')[0]; | |
} | |
function convert_slug(text){ | |
return text.toString().toLowerCase() | |
.replace(/\s+/g, '-') // Replace spaces with - | |
.replace(/[^\w\-]+/g, '') // Remove all non-word chars | |
.replace(/\-\-+/g, '-') // Replace multiple - with single - | |
.replace(/^-+/, '') // Trim - from start of text | |
.replace(/-+$/, ''); // Trim - from end of text | |
} | |
function setcountry(code){ | |
setCookie('language',code,2); | |
var path = window.location.protocol+'//'+window.location.hostname+'/?list/upcoming' | |
window.location = path; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment