Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

manual merge of changes from @zonak

  • Loading branch information...
commit d29472d7e280ba3dd519f38c28a915c9d0895dc6 1 parent bac199b
@addyosmani authored
View
7 app/collections/photos.js → app/models/PhotoCollection.js
@@ -3,13 +3,10 @@ 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,
- initialize:function(){
- this.bind( "reset", window.renderPhoto);
- }
+ model: ResultEntry
} );
return PhotoCollection;
} );
-
View
7 app/collections/results.js → app/models/ResultCollection.js
@@ -1,5 +1,5 @@
define( ['jquery', 'backbone', 'models/ResultEntry'],
- function( $, Backbone, ResultEntry) {
+ function( $, Backbone, ResultEntry ) {
// Using ECMAScript 5 strict mode during development. By default r.js will ignore that.
"use strict";
@@ -7,11 +7,8 @@ define( ['jquery', 'backbone', 'models/ResultEntry'],
model: ResultEntry,
parse: function( response ) {
return response;
- },
- initialize:function(){
- this.bind( "reset", window.renderResults);
}
- });
+ } );
return ResultCollection;
} );
View
11 app/utils.js
@@ -5,7 +5,6 @@ define( ['jquery' ],
var utils = {};
-
// summary:
// Manage passing search queries to the necessary handlers and the UI
// changes that are required based on query-type.
@@ -35,7 +34,6 @@ define( ['jquery' ],
$.when( utils.fetchResults( searchType, query, sort, page ) )
.then( $.proxy( function( response ) {
-
ctx.setView( searchType );
// The application can handle routes that come in
@@ -53,9 +51,8 @@ define( ['jquery' ],
$( '.search-meta p' ).html( 'Page: ' + response.photos.page + ' / ' + response.photos.pages );
-
- ctx.resultView.collection.reset(entries);
-
+ ctx.result_view.collection.reset( entries );
+
// switch to search results view
utils.changePage( "#search", "slide", false, false );
@@ -66,9 +63,7 @@ define( ['jquery' ],
else {
entries = response.photo;
- //ctx.photo_collection.reset( entries );
- ctx.photoView.collection.reset(entries);
-
+ ctx.photo_view.collection.reset( entries );
// switch to the individual photo viewer
utils.changePage( "#photo", "slide", false, false );
View
28 app/views/appview.js
@@ -1,15 +1,12 @@
-define( ['jquery', 'backbone', 'utils', 'collections/photos','collections/results', 'views/photoList', 'views/resultList'],
- function( $, Backbone, utils, PhotoCollection, ResultCollection, PhotoList, ResultList ) {
+define( ['jquery', 'backbone', 'utils', 'views/resultList', 'views/photoList'],
+ function( $, Backbone, utils, ResultList, PhotoList ) {
// Using ECMAScript 5 strict mode during development. By default r.js will ignore that.
"use strict";
-
var AppView = Backbone.View.extend( {
el: $( "#appview" ),
-
- initialize: function() {
- },
+
events: {
"submit #queryForm" : "keyLoadResults",
"change #sortBy": "keyLoadResults",
@@ -18,16 +15,10 @@ define( ['jquery', 'backbone', 'utils', 'collections/photos','collections/result
setView: function( option ) {
if ( option == 'search' ) {
-
- mobileSearch.utils.loadPrompt( "Loading results..." );
- mobileSearch.utils.toggleNavigation( true );
- this.resultView = new ResultList;
+ this.result_view = new ResultList;
}
else {
-
- mobileSearch.utils.loadPrompt( "Loading photo..." );
- $( '#photo .ui-title' ).html( 'Photo view' );
- this.photoView = new PhotoList;
+ this.photo_view = new PhotoList;
}
},
@@ -54,12 +45,7 @@ define( ['jquery', 'backbone', 'utils', 'collections/photos','collections/result
return AppView;
} );
- /* Due to deep namespacing, these render helpers are currently necessary*/
- window.renderResults = function(){
- window.mobileSearch.views.appview.resultView.render();
- }
- window.renderPhoto = function(){
- window.mobileSearch.views.appview.photoView.render();
- }
+
+
View
21 app/views/photoList.js
@@ -1,4 +1,4 @@
-define( ['jquery', 'backbone', 'underscore', 'collections/photos', 'text!templates/photoview.html'],
+define( ['jquery', 'backbone', 'underscore', 'models/PhotoCollection', 'text!templates/photoview.html'],
function( $, Backbone, _ , PhotoCollection, photoTemplate) {
// Using ECMAScript 5 strict mode during development. By default r.js will ignore that.
"use strict";
@@ -8,20 +8,23 @@ define( ['jquery', 'backbone', 'underscore', 'collections/photos', 'text!templat
initialize: function() {
this.collection = new PhotoCollection;
- //this.render();
+ _.bindAll(this, "renderList");
+ this.collection.bind( "reset", this.renderList );
},
+ renderList: function( collection ) {
- render: function() {
+ var compiled_template = _.template(photoTemplate),
+ collection = this.collection,
+ $el = $(this.el);
+
+ mobileSearch.utils.loadPrompt( "Loading photo..." );
+ $( '#photo .ui-title' ).html( 'Photo view' );
+ $el.html( compiled_template( { results: collection.models } ) );
- var compiledTemplate = _.template(photoTemplate, { results: this.collection.models });
- this.el.html(compiledTemplate);
-
setTimeout( function() {
- $('#photoviewholder').listview('refresh');
+ $el.listview('refresh');
}, 0 );
-
-
}
} );
View
27 app/views/resultList.js
@@ -1,32 +1,33 @@
-define( ['jquery', 'backbone', 'underscore','collections/results', 'text!templates/listview.html'],
- function( $, Backbone, _, ResultCollection, resultTemplate ) {
+define( ['jquery', 'backbone', 'underscore', 'models/ResultCollection', 'text!templates/listview.html'],
+ function( $, Backbone, _, ResultCollection, listTemplate ) {
// Using ECMAScript 5 strict mode during development. By default r.js will ignore that.
"use strict";
-
var ResultList = Backbone.View.extend( {
el: $( "#listviewholder" ),
initialize: function() {
this.collection = new ResultCollection;
- //this.render();
+ _.bindAll(this, "renderList");
+ this.collection.bind( "reset", this.renderList );
},
- render: function() {
+ renderList: function() {
+
+ var compiled_template = _.template( listTemplate ),
+ collection = this.collection,
+ $el = $(this.el);
+
+ mobileSearch.utils.loadPrompt( "Loading results..." );
+ mobileSearch.utils.toggleNavigation( true );
+ $el.html( compiled_template( { results: collection.models } ) );
- var compiledTemplate = _.template(resultTemplate, { results: this.collection.models });
- this.el.html(compiledTemplate);
-
-
setTimeout( function() {
- $('#listviewholder').listview('refresh');
+ $el.listview('refresh');
}, 0 );
-
}
} );
return ResultList;
});
-
-
Please sign in to comment.
Something went wrong with that request. Please try again.