Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Your server needs to have url on it that returns a json array with three links for each image, or enough information to construct those three links. You could do this with nodejs, or asp.net mvc, or even a hard-coded response to start with. I'll give a quick explanation about what's going on:</p> <pre><code>var url = "http://api.flickr.com/services/rest/?method=flickr.interestingness.getList&amp;api_key=60746a125b4a901f2dbb6fc902d9a716&amp;per_page=21&amp;extras=url_o,url_m,url_s&amp;page=" + page + "&amp;format=json&amp;jsoncallback=?"; </code></pre> <p>This a "RESTful API endpoint" which returns images from flickr (basically a URL that you can call, that tells you about a bunch of images).</p> <pre><code>jQuery.getJSON(url, function(data) </code></pre> <p>Makes an ajax call to get the data from the url. It returns a whole bunch of json, but you'll see further below, that we're only after the <code>data.photos.photo</code> items, the data looks something like: </p> <pre><code>"photo": [ { "id":"8707154801", "owner":"38142969@N00", "secret":"64b33dfc7b", "server":"8401", "farm":9, "title":"Veyron", "ispublic":1, "isfriend":0, "isfamily":0, "url_m":"http:\/\/farm9.staticflickr.com\/8401\/8707154801_64b33dfc7b.jpg", "height_m":"332", "width_m":"500", "url_s":"http:\/\/farm9.staticflickr.com\/8401\/8707154801_64b33dfc7b_m.jpg", "height_s":"159", "width_s":"240" },// ... ] </code></pre> <p>The next bit of code consumes an array of these, and you can see that it doesn't use all the fields, just enough to create the links it needs. Your server could just return those links directly if you like.</p> <pre><code>var images = jQuery.map(data.photos.photo, function (item) { return { thumb: item.url_s, zoom: 'http://farm' + item.farm + '.static.flickr.com/' + item.server + '/' + item.id + '_' + item.secret + '.jpg', link: 'http://www.flickr.com/photos/' + item.owner + '/' + item.id }; }); </code></pre> <p>For each record in the array returned from the url, this code produces a new item, with three urls in it, one for the thumbnail (which you see by default), one for the "zoomed in thumbnail", which it seems you get by hitting space, and one for the link to take you to if you click. The <code>images</code> variable ends up being an array of these objects, which is passed to the callback function, which I presume generates the view:</p> <pre><code> callback(images); </code></pre> <p>So ultimately what you need to do is make a url on your server that returns enough information to construct three urls, and then have a similar function to map your returned data into a list of { thumb, zoom, link } objects. You could just make your server return that data directly, and then you wouldn't need the mapping function.</p> <p><strong>EDIT</strong></p> <p>Ok, so how would you return this data from a server? I'll use <a href="http://nodejs.org" rel="nofollow">node</a> as a quick and dirty example, we'll create a server that simply returns a couple of items that exactly fit the data needed.</p> <pre><code>var http = require('http'); http.createServer(function (req, res) { res.writeHead(200, {'Content-Type': 'text/plain'}); res.end(JSON.stringify([{ thumb: "http://example.com/image1_thumb.jpg", zoom: "http://example.com/image1_zoom.jpg", link: "http://example.com/image1.jpg" }, { thumb: "http://example.com/image2_thumb.jpg", zoom: "http://example.com/image2_zoom.jpg", link: "http://example.com/image2.jpg" }])); }).listen(1337, '127.0.0.1'); </code></pre> <p>With this data you could simply use the following code when getting the url:</p> <pre><code>var url = "http://127.0.0.1:1337"; jQuery.getJSON(url, function(data) { callback(data); }); </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload