(function(){
var photoTemplate, resource;
function init(){
bindEventHandlers();
photoTemplate = _.template($('#photo-template').html());
}
function toTemplate(photo){
photo = {
count: photo.likes.count,
avatar: photo.user.profile_picture,
photo: photo.images.low_resolution.url,
url: photo.link
};
return photoTemplate(photo);
}
function toScreen(photos){
var photos_html = '';
$('.paginate a').attr('data-max-tag-id', photos.pagination.next_max_id)
.fadeIn();
$.each(photos.data, function(index, photo){
photos_html += toTemplate(photo);
});
$('div#photos-wrap').append(photos_html);
}
function generateResource(tag){
var config = Instagram.Config, url;
if(typeof tag === 'undefined'){
throw new Error("Resource requires a tag. Try searching for cats.");
} else {
// Make sure tag is a string, trim any trailing/leading whitespace and take only the first
// word, if there are multiple.
tag = String(tag).trim().split(" ")[0];
}
url = config.apiHost + "/v1/tags/" + tag + "/media/recent?callback=?&client_id=" + config.clientID;
return function(max_id){
var next_page;
if(typeof max_id === 'string' && max_id.trim() !== '') {
next_page = url + "&max_id=" + max_id;
}
return next_page || url;
};
}
function paginate(max_id){
$.getJSON(generateUrl(tag), toScreen);
}
function search(tag){
resource = generateResource(tag);
$('.paginate a').hide();
$('#photos-wrap *').remove();
fetchPhotos();
}
function fetchPhotos(max_id){
$.getJSON(resource(max_id), toScreen);
}
function bindEventHandlers(){
$('body').on('click', '.paginate a.btn', function(){
var tagID = $(this).attr('data-max-tag-id');
fetchPhotos(tagID);
return false;
});
// Bind an event handler to the `submit` event on the form
$('form').on('submit', function(e){
// Stop the form from fulfilling its destinty.
e.preventDefault();
// Extract the value of the search input text field.
var tag = $('input.search-tag').val().trim();
// Invoke `search`, passing `tag` (unless tag is an empty string).
if(tag) {
search(tag);
};
});
}
function showPhoto(p){
$(p).fadeIn();
}
// Public API
Instagram.App = {
search: search,
showPhoto: showPhoto,
init: init
};
}());
$(function(){
Instagram.App.init();
// Start with a search on yogofactory; we all love frozen yogurt :).
Instagram.App.search('yogofactory');
});
它,然後轉到HTML文件,並圍繞此添加一類特定的圖像
<script type="text/template" id="photo-template">
<div class='photo'>
<img class='main' src='<%= photo %>' width='250' height='250' style='display:none;' onload='Instagram.App.showPhoto(this);' />
<img class='avatar' width='40' height='40' src='<%= avatar %>' />
<span class='heart'><strong><%= count %></strong></span>
</div>
</script>
畫廊我不是當它涉及到JS或jQuery的經歷的父母DIV 。我正在尋找一種方法來向父代添加一個類,當內部圖像是src="http://image.com/onlythisone.jpg"
並且只有當它的圖像。
我有一個畫廊是從instagram數據庫動態拉動的大型畫廊,我基本上希望能夠隱藏某些不遵循我爲我的宣傳創建的哈希標記規則的照片。
任何幫助將是真棒!提前致謝!
獲得經驗唯一的辦法是嘗試在你自己的事情。 – 2013-05-17 20:32:33
'$('img [src =「http://image.com/onlythisone.jpg」]')。parent()。addClass('your_class')'? –
toScreen()函數在哪裏? – adeneo