Skip to content

Commit

Permalink
Current status of not working
Browse files Browse the repository at this point in the history
  • Loading branch information
iranzo committed Feb 5, 2020
1 parent af391bf commit 6c8aa34
Showing 1 changed file with 51 additions and 48 deletions.
99 changes: 51 additions & 48 deletions templates/article.html
Original file line number Diff line number Diff line change
Expand Up @@ -34,80 +34,83 @@
// This function grabs from instagram the data about images and returns HTML to show it in photoswipe
var mypics = []
var request = new XMLHttpRequest();
var data = "";
console.log(pic)
request.open('GET', `https://www.instagram.com/p/${pic}/?__a=1`, true);

request.onload = function() {
if (this.status >= 200 && this.status < 400) {
// Success!
var data = JSON.parse(this.response);
data = JSON.parse(this.response);
checkData(data);
} else {
// We reached our target server, but it returned an error
var data = undefined;
data = undefined;
}
}

console.log(data)

request.onerror = function() {
// There was a connection error of some sort
};

request.send();
if (data){
data.graphql.shortcode_media.forEach(function(key,val){
if (key == '__typename'){
var items = [];
if (val == 'GraphSidecar'){
data.graphql.shortcode_media.edge_sidecar_to_children.edges.forEach(function( key, val ) {
function checkData(data) {
console.log(data);
if (data){
data.graphql.shortcode_media.forEach(function(key,val){
if (key == '__typename'){
var items = [];
if (val == 'GraphSidecar'){
data.graphql.shortcode_media.edge_sidecar_to_children.edges.forEach(function( key, val ) {
var mynewitem = {};
mynewitem.image = val.node.display_url;
mynewitem.title = "";
mynewitem.height = val.node.dimensions.height;
mynewitem.width = val.node.dimensions.width;
// mynewitem.description = "A detailed description for picture";
// mynewitem.thumb = mynewitem.image;
mynewitem.big = val.node.display_url;
// mynewitem.layer = "<a href='https://www.instagram.com/p/" + pic + "/'>" + "https://www.instagram.com/p/" + pic + "/</a>";
// mynewitem.link = "https://www.instagram.com/p/" + pic + "/";
mynewitem.html = "<figure itemprop='associatedMedia' itemscope itemtype='http://schema.org/ImageObject'><a data-size='" + mynewitem.width + "x"+ mynewitem.height + "' itemprop='contentUrl' href='" + mynewitem.big + "' /'><img itemprop='thumbnail' src='" + mynewitem.image + "' /></a></figure>";
mypics.push(mynewitem);
});
}
if (val == 'GraphImage'){
var mynewitem = {};
mynewitem.image = val.node.display_url;
mynewitem.title = "";
mynewitem.height = val.node.dimensions.height;
mynewitem.width = val.node.dimensions.width;
mynewitem.image = data.graphql.shortcode_media.display_url;
mynewitem.title = "<a href='https://www.instagram.com/p/" + pic + "/'>" + "https://www.instagram.com/p/" + pic + "/</a>";
mynewitem.height = data.graphql.shortcode_media.dimensions.height;
mynewitem.width = data.graphql.shortcode_media.dimensions.width;
// mynewitem.description = "A detailed description for picture";
// mynewitem.thumb = mynewitem.image;
mynewitem.big = val.node.display_url;
mynewitem.big = mynewitem.image;
// mynewitem.layer = "<a href='https://www.instagram.com/p/" + pic + "/'>" + "https://www.instagram.com/p/" + pic + "/</a>";
// mynewitem.link = "https://www.instagram.com/p/" + pic + "/";
mynewitem.html = "<figure itemprop='associatedMedia' itemscope itemtype='http://schema.org/ImageObject'><a data-size='" + mynewitem.width + "x"+ mynewitem.height + "' itemprop='contentUrl' href='" + mynewitem.big + "' /'><img itemprop='thumbnail' src='" + mynewitem.image + "' /></a></figure>";
mypics.push(mynewitem);
});
}
if (val == 'GraphImage'){
var mynewitem = {};
mynewitem.image = data.graphql.shortcode_media.display_url;
mynewitem.title = "<a href='https://www.instagram.com/p/" + pic + "/'>" + "https://www.instagram.com/p/" + pic + "/</a>";
mynewitem.height = data.graphql.shortcode_media.dimensions.height;
mynewitem.width = data.graphql.shortcode_media.dimensions.width;
// mynewitem.description = "A detailed description for picture";
// mynewitem.thumb = mynewitem.image;
mynewitem.big = mynewitem.image;
// mynewitem.layer = "<a href='https://www.instagram.com/p/" + pic + "/'>" + "https://www.instagram.com/p/" + pic + "/</a>";
// mynewitem.link = "https://www.instagram.com/p/" + pic + "/";
mypics.push(mynewitem);
}
}
}
})
}
})
}

var myhtml = "";
mypics.forEach(function(item){
myhtml = myhtml + mypics[item].html;
});
if (myhtml) {
myhtml = '<div>' + myhtml + '</div>';
}
var myhtml = "";
mypics.forEach(function(item){
myhtml = myhtml + mypics[item].html;
});
if (myhtml) {
myhtml = '<div>' + myhtml + '</div>';
}

// Set innerHTML after we have got the result
// Set innerHTML after we have got the result

document.querySelectorAll('#photoswipe-instagram').forEach(function(divisor){
mygalleryid = divisor.getAttribute('data-gallery-id');
if (mygalleryid === pic) {
divisor.innerHTML = myhtml;
}
});
}
document.querySelectorAll('#photoswipe-instagram').forEach(function(divisor){
mygalleryid = divisor.getAttribute('data-gallery-id');
if (mygalleryid === pic) {
divisor.innerHTML = myhtml;
}
});
}
}

function updategalleries(){
document.querySelectorAll('#photoswipe-instagram').forEach(function(divisor){
Expand Down

0 comments on commit 6c8aa34

Please sign in to comment.