Skip to content

Instantly share code, notes, and snippets.

@RahulSaini91
Created May 3, 2018 10:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save RahulSaini91/cd89d726154829ad1490a9e9fc8b8693 to your computer and use it in GitHub Desktop.
Save RahulSaini91/cd89d726154829ad1490a9e9fc8b8693 to your computer and use it in GitHub Desktop.
Movie Project
//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 = &quot;<div class='movie-detail'>&quot;;
html += &quot;<img src='&quot;+thumb+&quot;'/>&quot;;
html += &quot;<h4>&quot;+obj.title+&quot;</h4></div>&quot;;
$(&#39;#&#39;+output).html(html);
}
function list_movies(obj,output){
if(!obj.length){
$(&#39;#&#39;+output).html("<div class='alert alert-danger'>No Movies Found</div>");
return;
}
var html = &quot;<div class='row'>&quot;;
$(obj).each(function(key,value){
var thumb = value.poster_path;
if(thumb==&quot;null&quot;||!thumb||thumb==&#39;undefined&#39;){
thumb=&#39;//placehold.it/200x200/?text=Coming%20Soon&#39;;
}else{
thumb=config.img_domain+&#39;/w200&#39;+thumb;
}
var link = window.location.protocol+&#39;//&#39;+window.location.hostname+&#39;/?movie/&#39;+value.id+&#39;/&#39;+convert_slug(value.title);
html+=&quot;<div class='col-sm-3'><div class='thumb'><img src='&quot;+thumb+&quot;'/></div><div class='info'><a class='title' href='&quot;+link+&quot;'>&quot;+value.title+&quot;</a></div></div>&quot;;
});
html+=&#39;</div>&#39;;
$(&#39;#&#39;+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 + &#39;=&#39;)[1] || &#39;&#39;).split(&#39;&amp;&#39;)[0];
}
function convert_slug(text){
return text.toString().toLowerCase()
.replace(/\s+/g, &#39;-&#39;) // Replace spaces with -
.replace(/[^\w\-]+/g, &#39;&#39;) // Remove all non-word chars
.replace(/\-\-+/g, &#39;-&#39;) // Replace multiple - with single -
.replace(/^-+/, &#39;&#39;) // Trim - from start of text
.replace(/-+$/, &#39;&#39;); // Trim - from end of text
}
function setcountry(code){
setCookie(&#39;language&#39;,code,2);
var path = window.location.protocol+&#39;//&#39;+window.location.hostname+&#39;/?list/upcoming&#39;
window.location = path;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment