goodpic / frickr-to-blog

Javascript library to integrate Flickr to your own blog. Display pisctures, comments from flickr to your blog.

This URL has Read+Write access

frickr-to-blog / my.flickr.js
100644 128 lines (102 sloc) 5.173 kb
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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
$.flickr = {
    s: {
        api_key: 'e87e482f5fdc62d84389b0555aeb3754',
        type: 'search', // allowed values: 'photoset', 'search'
        user_id: null,
        api_url: null,
        callback: null,
        photoset_id: null,
        group_id: null,
        tags: null, // comma separated list
        tag_mode: null, // allowed values: 'any' (OR), 'all' (AND)
        text: null,
        sort: null, // date-posted-asc, date-posted-desc, date-taken-asc, date-taken-desc, interestingness-desc, interestingness-asc, relevance
        thumb_size: 's', // allowed values: s (75x75), t (100x?), m (240x?)
        size: 'm', // default: (500x?), allowed values: m (240x?), o (original)
        per_page: null, // default: 100, max: 500
        litebox: false // boolean, if true requires jquery.litebox.js
},
 
    format: function(){
 
        if (this.s.url) return this.s.url;
        if (!this.s.callback) this.s.callback = 'jQuery.flickr.response';
        var url = 'http://api.flickr.com/services/rest/?format=json&jsoncallback='+this.s.callback+'&api_key='+this.s.api_key;
 
        switch (this.s.type){
            case 'photoset':
                url += '&method=flickr.photosetthis.s.getPhotos&photoset_id=' + this.s.photoset_id;
                break;
            case 'search':
                url += '&method=flickr.photos.search';
                if (this.s.user_id) url += '&user_id=' + this.s.user_id;
                if (this.s.group_id) url += '&group_id=' + this.s.group_id;
                if (this.s.tags) url += '&tags=' + this.s.tags;
                if (this.s.tag_mode) url += '&tag_mode=' + this.s.tag_mode;
                if (this.s.text) url += '&text=' + this.s.text;
                if (this.s.sort) url += '&sort=' + this.s.sort;
                break;
            default:
                url += '&method=flickr.photothis.s.getRecent';
        }
        if (this.s.per_page) url += '&per_page=' + this.s.per_page;
        if (this.s.size == 'o') url += '&extras=original_format';
        return url;
    },
    request: function(){
var url = this.format();
 
        var script = document.createElement('script');
        script.type = 'text/javascript';
        script.src = url;
 
        $('head').append(script);
    },
 
    response: function(r){
 
// Flickr img URL sample
// http://farm3.static.flickr.com/2166/2300707514_1cd9a7b2b4_s.jpg = 75x75
// http://farm3.static.flickr.com/2166/2300707514_1cd9a7b2b4_t.jpg = 100x67
// http://farm3.static.flickr.com/2166/2300707514_1cd9a7b2b4_m.jpg = 240x160
// http://farm3.static.flickr.com/2166/2300707514_1cd9a7b2b4.jpg = 500x333
// http://farm3.static.flickr.com/2166/2300707514_1cd9a7b2b4_b.jpg = 1024x653
 
// 初期化
$('#flickr').html("");
$.stokeshot.images = [];
$.stokeshot.order = [];
 
        if (r.stat != "ok"){
            $('#flickr').append('Flickr error<br />');
            for (i in r){
                $('#flickr').append(''+i+': '+i[r]+'<br />');
            }
        } else {
 
            if ( this.s.type == 'photoset' ) {
                r.photos = r.photoset;
            }
 
 
 
// console.debug(r.photos);
            for (var i=0; i<r.photos.photo.length; i++ ) {
                                                   
                var photo = r.photos.photo[i];
                var id = "img" + photo['id'];
                                                   
                var thumb = 'http://farm'+photo['farm']+'.static.flickr.com/'+photo['server']+'/'+photo['id']+'_'+photo['secret']+'_'+this.s.thumb_size+'.jpg';
                                                   
                var h = 'http://farm'+photo['farm']+'.static.flickr.com/'+photo['server']+'/'+photo['id']+'_';
 
var small = h + photo['secret']+'_m.jpg';
var medium = h + photo['secret']+'.jpg';
                var large = h + photo['secret']+'_b.jpg';
 
                $.stokeshot.images[id] = {
                    title: id,
                    large_url: large,
medium_url: medium,
                    small_url: small,
                    icon_url: thumb,
                    width: "0",
                    height: "0"
                };
 
                $('#flickr').append('<div class="float" ><img src="'+ thumb +'" /><br /><input type="checkbox" class="imagechoice" value="img' + photo['id'] + '" />写真 <input type="checkbox" class="iconchoice" value="img' + photo['id'] + '" />Icon</div>');
                                                   
            }
        };
 
        $("input[@type=checkbox].imagechoice").change(function(){
          $.stokeshot.showOrder(this.value);
          $.stokeshot.refreshTextarea();
 
        // console.debug(myalbum.order);
        });
 
        $("input[@type=checkbox].iconchoice").change(function(){
          $.stokeshot.showIcons("#tab-order div#preview-icon");
          $.stokeshot.refreshTextarea();
 
         // console.debug(myalbum.order);
        });
                                   
    }
};