HTML and CSS Reference
In-Depth Information
Table 11-2 provides a brief explanation of the URL parameters.
TABLE 11-2
Query string parameters for the Flickr public web service
Parameter
Description
This parameter can take the value
all
or
any
; and indicates whether any selected photos must
match all or just any of the specified tags.
tagmode
Set this parameter to
json
if you want to get a JSON response. You can also specify that the call
should return RSS or a variety of other formats as listed here:
http://www.flickr.com/services/
feeds/docs/photos_public
.
format
In a Windows Store application, this parameter is
required
and must be set to
1
. You don't need
this parameter if you're calling the Flickr API from within a JavaScript web application. It is a
setting that relates to how the host environment actually places the call to the remote site.
nojsoncallback
You can set this parameter to a comma-separated list of keywords to match appropriate
photos.
tags
As you may have noticed, the
flickrApp.Source
property is set to a string that contains a
placeholder—the
{0}
item. In .NET programming, this type of notation is used to format strings
dynamically. The idea is that when the user clicks the Search button, the handler will read the typed
tags and insert them in the URL string, replacing the placeholder.
The
{0}
notation is common in .NET Windows programming, but it isn't in JavaScript. So you need
to create a helper function that does the replacement. This is interesting because it shows you a
powerful JavaScript technique—manipulating object prototypes.
preparing the Flickr UrL
It is advisable that you create yet another JavaScript file; call it
helpers.js
. Add a reference to that file
in your
default.html
file and make sure that the
helpers.js
reference precedes the
flickrApp.js
reference.
Here's the initial content for
helpers.js
:
////////////////////////////////////////////////////////////
// Applies the .NET {n} convention to format strings
//
String.prototype.format = function () {
var theString = this,
count = arguments.length;
while (count--) {
theString = theString.replace(
new RegExp('\\{' + count + '\\}', 'gm'), arguments[count]);
};
return theString;
};
Search WWH ::
Custom Search