forked from yairEO/photobox
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
87 lines (78 loc) · 2.89 KB
/
main.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
//-------------------------------------------------------------------------------------
//
// THIS FILE IS NOT A PART OF THE PLUGIN, IT'S ONLY FOR THE DEMO
//
//-------------------------------------------------------------------------------------
!(function(){
'use strict';
var numOfImages = window.location.search ? parseInt(window.location.search.match(/\d+$/)[0]) : 70,
gallery = $('#gallery'),
videos = [
{
title: "Victoria's Secret",
url: "http://player.vimeo.com/video/8974462?byline=0&portrait=0",
thumb: "http://b.vimeocdn.com/ts/432/699/43269900_100.jpg"
},
{
title: "PEOPLE ARE AWESOME 2013 FULL HD ",
url: "http://www.youtube.com/embed/W3OQgh_h4U4",
thumb: "http://img.youtube.com/vi/W3OQgh_h4U4/0.jpg"
},
{
title: "Biting Elbows - 'Bad Motherfucker' Official Music Video",
url: "http://player.vimeo.com/video/62092214?byline=0&portrait=0",
thumb: "http://b.vimeocdn.com/ts/431/797/431797120_100.jpg"
}
];
// Get some photos from Flickr for the demo
$.ajax({
url: 'https://api.flickr.com/services/rest/',
data: {
format: 'json',
method: 'flickr.interestingness.getList',
per_page : numOfImages,
api_key: 'b51d3a7c3988ba6052e25cb152aecba2' // this is my own API key, please use yours
},
dataType: 'jsonp',
jsonp: 'jsoncallback'
})
.done(function (data){
var loadedIndex = 1, isVideo;
// add the videos to the collection
data.photos.photo = data.photos.photo.concat(videos);
$.each( data.photos.photo, function(index, photo){
isVideo = photo.thumb ? true : false;
// http://www.flickr.com/services/api/misc.urls.html
var url = 'http://farm' + photo.farm + '.static.flickr.com/' + photo.server + '/' + photo.id + '_' + photo.secret,
img = document.createElement('img');
// lazy show the photos one by one
img.onload = function(e){
img.onload = null;
var link = document.createElement('a'),
li = document.createElement('li')
link.href = this.largeUrl;
link.appendChild(this);
if( this.isVideo ){
link.rel = 'video';
li.className = 'video'
}
li.appendChild(link);
gallery[0].appendChild(li);
setTimeout( function(){
$(li).addClass('loaded');
}, 25*loadedIndex++);
};
img['largeUrl'] = isVideo ? photo.url : url + '_b.jpg';
img['isVideo'] = isVideo;
img.src = isVideo ? photo.thumb : url + '_t.jpg';
img.title = photo.title;
});
// finally, initialize photobox on all retrieved images
$('#gallery').photobox('a', { thumbs:true, loop:false }, callback);
// using setTimeout to make sure all images were in the DOM, before the history.load() function is looking them up to match the url hash
setTimeout(window._photobox.history.load, 1000);
function callback(){
console.log('callback for loaded content:', this);
};
});
})();