Skip to content
Browse files

updating API params, switching to data obj, minor other adjustments

  • Loading branch information...
1 parent d29472d commit 555bb02c665490e48bfc81984487b20ec437beb3 @addyosmani committed Apr 4, 2012
Showing with 35 additions and 13 deletions.
  1. +2 −1 app/app.js
  2. +0 −1 app/models/PhotoCollection.js
  3. +1 −1 app/routers/workspace.js
  4. +32 −10 app/utils.js
View
3 app/app.js
@@ -1,7 +1,7 @@
/*!
* Flickly - Backbone jQuery Mobile demo
* http://addyosmani.com
- * Copyright (c) 2011 Addy Osmani
+ * Copyright (c) 2012 Addy Osmani
* Dual licensed under the MIT and GPL licenses.
*
*/
@@ -31,6 +31,7 @@ define( ['backbone', 'views/appview', 'routers/workspace', 'utils', 'ui'],
window.mobileSearch.utils.toggleNavigation( false );
+
Backbone.history.start();
});
View
1 app/models/PhotoCollection.js
@@ -3,7 +3,6 @@ define( ['jquery', 'backbone', 'models/ResultEntry'],
// Using ECMAScript 5 strict mode during development. By default r.js will ignore that.
"use strict";
-
var PhotoCollection = Backbone.Collection.extend( {
model: ResultEntry
} );
View
2 app/routers/workspace.js
@@ -11,7 +11,7 @@ define( ['jquery', 'backbone'],
routes: {
"search/:query": "search", // #search/kiwis
"search/:query/s:sort/p:page": "search", // #search/kiwis/srelevance/p7
- "photo/:id": "photo", //#photo/93839
+ "photo/:id": "photo", // #photo/93839
"" : "root" //
},
search: function( query, sort, page ) {
View
42 app/utils.js
@@ -24,9 +24,10 @@ define( ['jquery' ],
utils.dfdQuery = function( searchType, ctx, query, sort, page ) {
- if(!(query==undefined || query == "")){
+ if(!(query == undefined || query == "" )){
var entries = null;
+
page = (page == undefined) ? 1 : page;
utils.loadPrompt( 'Querying Flickr API...' );
@@ -112,13 +113,14 @@ define( ['jquery' ],
utils.fetchResults = function( searchType, query, sort, page ) {
- var serviceUrl = "http://api.flickr.com/services/rest/?format=json&jsoncallback=?",
+ var serviceUrl = "http://api.flickr.com/services/rest/",
apiKey = "8662e376985445d92a07c79ff7d12ff8",
geoTagged = null,
quantity = 0,
safeSearch = '',
minDate = "",
- maxDate = "";
+ maxDate = "",
+ data = {};
if ( searchType == 'search' || searchType == undefined ) {
@@ -133,14 +135,34 @@ define( ['jquery' ],
($( '#geo-choice-z1' ).prop( 'checked' ) || mobileSearch.defaults.geoTagged) ? geoTagged = 0 : geoTagged = 1;
page = (page == undefined) ? 0 : page;
sort = (sort == undefined) ? ($( '#sortBy' ).val()) : sort;
- serviceUrl += "&method=flickr.photos.search" + "&per_page=" + quantity + "&page=" + page + "&is_geo=" + geoTagged + "&safe_search=" + safeSearch + "&sort=" + sort + "&min_taken_date=" + minDate + "&max_taken_date=" + maxDate + "&text=" + encodeURIComponent(query) + "&api_key=" + apiKey;
+
+ data = {
+ format: 'json',
+ nojsoncallback: '1',
+ method: 'flickr.photos.search',
+ per_page: quantity,
+ page: page,
+ is_geo: geoTagged,
+ safe_search: safeSearch,
+ sort: sort,
+ min_taken_date: minDate,
+ max_taken_date: maxDate,
+ text: encodeURIComponent(query),
+ api_key: apiKey
+ };
} else if ( searchType == 'photo' ) {
- serviceUrl += "&method=flickr.photos.getInfo&photo_id=" + encodeURIComponent(query) + "&api_key=" + apiKey;
- }
+ data = {
+ format: 'json',
+ nojsoncallback: '1',
+ method: 'flickr.photos.getInfo',
+ photo_id: encodeURIComponent(query),
+ api_key: apiKey
+ };
+ }
- return $.ajax( serviceUrl, { dataType: "json" } );
+ return $.ajax({ url: serviceUrl, dataType: "json", data: data } );
};
@@ -167,9 +189,9 @@ define( ['jquery' ],
var sortQuery,
hashQuery = "", pageQuery = 0, increment = 0;
- (mobileSearch.routers.workspace.q == undefined) ? hashQuery = '' : hashQuery = mobileSearch.routers.workspace.q;
- (mobileSearch.routers.workspace.p == undefined) ? pageQuery = 1 : pageQuery = mobileSearch.routers.workspace.p;
- (mobileSearch.routers.workspace.s == undefined) ? sortQuery = 'relevance' : sortQuery = mobileSearch.routers.workspace.s;
+ (mobileSearch.routers.workspace.q === undefined) ? hashQuery = '' : hashQuery = mobileSearch.routers.workspace.q;
+ (mobileSearch.routers.workspace.p === undefined) ? pageQuery = 1 : pageQuery = mobileSearch.routers.workspace.p;
+ (mobileSearch.routers.workspace.s === undefined) ? sortQuery = 'relevance' : sortQuery = mobileSearch.routers.workspace.s;
pageQuery = parseInt( pageQuery );
(state == 'next') ? pageQuery += 1 : pageQuery -= 1;

0 comments on commit 555bb02

Please sign in to comment.
Something went wrong with that request. Please try again.