Created
March 8, 2018 08:52
-
-
Save atauenis/b71a4eebcc2299e5d54c95ffbd50ad96 to your computer and use it in GitHub Desktop.
Скрипт для работы с Яндекс.Фотками
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
//ФоткоАльбом v0.3. (C) 2013-15; Alexander Tauenis | atauenis.ru. | |
//https://tech.yandex.ru/fotki/ - RTFM!!! | |
var user="atauenis"; | |
function getUserHTML(){ | |
//инициализация, вызывается при загрузке страницы | |
document.getElementById("photoframe").style.display = "none"; | |
document.getElementById("output").style.display = "block"; | |
$("#output").empty(); | |
//общая информация и оглавление по альбомам | |
$.getJSON("https://api-fotki.yandex.ru/api/users/"+user+"/albums/?format=json&callback=?", | |
function(res) { | |
$("#output").append("<h1><a href='"+res.links.alternate+"'>"+res.title+"</a></h1>"); | |
$.each(res.entries, | |
function(key,val){ | |
var output="<div class='fotkabox' onclick='ProcessJson(\""+val.links.self+"\",\"ShowAlbum\")'><table style='display: inline-block;' width='350px'><tr><td><a href='"+val.links.alternate+"'><img border='0' src='"+val.img.S.href+"'></a></td><td><a href='"+val.links.alternate+"'><b>"+val.title+"</a></b>"; | |
if(val.summary !== undefined) | |
output += "<br>"+val.summary+"<br>Изменено: " + val.updated + "</td></tr></table></div>"; | |
else | |
output += "<br>Изменено: " + val.updated + "</td></tr></table></div>"; | |
$("#output").append(output); | |
} | |
); | |
}); | |
} | |
function ShowAlbum(json){ //показать информацию об альбоме | |
$("#output").empty(); | |
$("#output").append("<a href='javascript:getUserHTML()'>Назад</a><br><h1>Альбом ""+json.title+""</h1>"); | |
if(json.summary !== undefined) | |
$("#output").append(json.summary+"<div id='TheFotki'>Одну минуточку!..</div>"); | |
else | |
$("#output").append("<div id='TheFotki'>Одну минуточку!..</div>"); | |
ProcessJson(json.links.photos,"ShowAlbumPhotos"); | |
} | |
function ShowAlbumPhotos(json){ //показать содержимое альбома | |
$("#TheFotki").empty(); | |
$.each(json.entries, | |
function(key,val){ | |
$("#TheFotki").append("<div class='fotkabox' onclick='ProcessJson(\""+val.links.self+"\",\"ShowPhoto\")'><a href='"+val.links.alternate+"'><img src='"+val.img.L.href+"'></a><br>"+val.title+"</div>"); | |
}) | |
} | |
function ShowPhoto(json){ //показать яндекс-фотку | |
$("#photoframe").empty(); | |
$("#photoframe").append("<a href='javascript:HidePhotoFrame()'>Назад</a>"); | |
$("#photoframe").append("<center><h1>"+json.title+"</h1><img style=\"max-height: 100%;\" src=\""+json.img.orig.href+"\"></center>"); | |
if(json.summary !== undefined) | |
$("#photoframe").append("<center><br>"+json.summary+"</center>"); | |
//меняем экраны | |
document.getElementById("photoframe").style.display = "block"; | |
document.getElementById("output").style.display = "none"; | |
} | |
function showAlbumInfo(json){ //0.3 вывод полученных данных альбома в нужный div | |
var id = "#" + json.id.replace(/:/g,"_"); //id div'а | |
$(id).empty(); | |
$(id).append("Альбом <b>" + json.title + "</b>"); | |
$(id).append("<div id='" + json.id.replace(/:/g,"_") + "_photos'>Ожидайте загрузки фотографий...</div>"); | |
var photosURL = json.links.photos.replace(/photos/,"photos/manual"); // вывод фоток в порядке, указанном в веб-интерфейсе | |
processJSON(photosURL, "showAlbumPhotos"); | |
} | |
function showAlbumPhotos(json){ //0.3 вывод полученного содержимого альбома | |
var id = "#" + json.id.replace(/:/g,"_"); //id div'а | |
$(id).empty(); | |
$.each(json.entries, function(key,val) | |
{ | |
$(id).append("<a href='" + val.links.alternate + "'><img src='" + val.img.S.href + "' title='" + val.title + "'></a> "); | |
}); | |
} | |
function processJSON(jsonurl, processwith){ //0.3 упрощённый вызов калбачнуемного джейсона | |
$("body").append("<script src='"+jsonurl+"&callback="+processwith+"'></"+"script>"); | |
} | |
function insertAlbum(user, album){ //0.3 вставка фоткоальбома в произвольное место страницы | |
var id = "urn_yandex_fotki_" + user + "_album_" + album; | |
var URL = "http://api-fotki.yandex.ru/api/users/" + user + "/album/" + album + "/?format=json"; | |
var div = "<div id=" + id + ">Идёт загрузка альбома, подождите, пожалуйста...</div>"; | |
document.write(div); | |
processJSON(URL, "showAlbumInfo"); | |
} | |
function ProcessJson(jsonurl, processwith){ //упрощённый вызов калбачнуемного джейсона | |
$("#output").append("<script src='"+jsonurl+"&callback="+processwith+"'></"+"script>"); | |
} | |
function HidePhotoFrame(){ //убрать фоторамку и заменить на предыдущий экран | |
document.getElementById("photoframe").style.display = "none"; | |
document.getElementById("output").style.display = "block"; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment