Skip to content
This repository was archived by the owner on Oct 8, 2021. It is now read-only.

Commit 2373e30

Browse files
committed
Demos: Fix backbone-requirejs demo acc. to new api
Closes #8477
1 parent 7ac33e4 commit 2373e30

File tree

1 file changed

+58
-57
lines changed

1 file changed

+58
-57
lines changed

demos/backbone-requirejs/js/routers/mobileRouter.js

Lines changed: 58 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -10,90 +10,91 @@ define([
1010
"../views/CategoryView"
1111
], function( $, Backbone, CategoryModel, CategoriesCollection, CategoryView ) {
1212

13-
// Extends Backbone.Router
14-
var CategoryRouter = Backbone.Router.extend( {
13+
// Extends Backbone.Router
14+
var CategoryRouter = Backbone.Router.extend( {
15+
hasInitialized: false,
1516

16-
// The Router constructor
17-
initialize: function() {
17+
// The Router constructor
18+
initialize: function() {
1819

19-
this.pagecontainer = $( ".ui-pagecontainer" ).pagecontainer( "instance" );
20+
// Instantiates a new Animal Category View
21+
this.animalsView = new CategoryView( { el: "#animals", collection: new CategoriesCollection( [] , { type: "animals" } ) } );
2022

21-
// Instantiates a new Animal Category View
22-
this.animalsView = new CategoryView( { el: "#animals", collection: new CategoriesCollection( [] , { type: "animals" } ) } );
23+
// Instantiates a new Colors Category View
24+
this.colorsView = new CategoryView( { el: "#colors", collection: new CategoriesCollection( [] , { type: "colors" } ) } );
2325

24-
// Instantiates a new Colors Category View
25-
this.colorsView = new CategoryView( { el: "#colors", collection: new CategoriesCollection( [] , { type: "colors" } ) } );
26+
// Instantiates a new Vehicles Category View
27+
this.vehiclesView = new CategoryView( { el: "#vehicles", collection: new CategoriesCollection( [] , { type: "vehicles" } ) } );
2628

27-
// Instantiates a new Vehicles Category View
28-
this.vehiclesView = new CategoryView( { el: "#vehicles", collection: new CategoriesCollection( [] , { type: "vehicles" } ) } );
29+
// Tells Backbone to start watching for hashchange events
30+
Backbone.history.start();
2931

30-
// Tells Backbone to start watching for hashchange events
31-
Backbone.history.start();
32+
},
3233

33-
},
34+
// Backbone.js Routes
35+
routes: {
3436

35-
// Backbone.js Routes
36-
routes: {
37+
// When there is no hash bang on the url, the home method is called
38+
"": "home",
3739

38-
// When there is no hash bang on the url, the home method is called
39-
"": "home",
40+
// When #category? is on the url, the category method is called
41+
"category?:type": "category"
4042

41-
// When #category? is on the url, the category method is called
42-
"category?:type": "category"
43+
},
4344

44-
},
45+
// Home method
46+
home: function() {
4547

46-
// Home method
47-
home: function() {
48-
49-
// Programatically changes to the categories page
50-
this.pagecontainer.change( "#categories", {
51-
reverse: false,
52-
changeHash: false
53-
});
54-
55-
},
56-
57-
// Category method that passes in the type that is appended to the url hash
58-
category: function(type) {
48+
// Programatically changes to the categories page
49+
if (this.hasInitialized) {
50+
$( "body" ).pagecontainer( "change", "#categories", {
51+
reverse: false,
52+
changeUrl: false
53+
} );
54+
}
55+
},
5956

60-
// Stores the current Category View inside of the currentView variable
61-
var currentView = this[ type + "View" ];
57+
// Category method that passes in the type that is appended to the url hash
58+
category: function(type) {
59+
this.hasInitialized = true;
60+
// Stores the current Category View inside of the currentView variable
61+
var currentView = this[ type + "View" ];
62+
var that = this;
6263

63-
// If there are no collections in the current Category View
64-
if(!currentView.collection.length) {
64+
// If there are no collections in the current Category View
65+
if(!currentView.collection.length) {
6566

66-
// Show's the jQuery Mobile loading icon
67-
$.mobile.loading( "show" );
67+
// Show's the jQuery Mobile loading icon
68+
$.mobile.loading( "show" );
6869

69-
// Fetches the Collection of Category Models for the current Category View
70-
currentView.collection.fetch().done( function() {
70+
// Fetches the Collection of Category Models for the current Category View
71+
currentView.collection.fetch().done( function() {
7172

72-
// Programatically changes to the current categories page
73-
this.pagecontainer.change( "#" + type, {
73+
// Programatically changes to the current categories page
74+
$( "body" ).pagecontainer( "change", "#" + type, {
7475
reverse: false,
75-
changeHash: false
76+
changeUrl: false
7677
});
77-
} );
78+
} );
7879

79-
}
80+
}
8081

81-
// If there already collections in the current Category View
82-
else {
82+
// If there already collections in the current Category View
83+
else {
8384

84-
// Programatically changes to the current categories page
85-
this.pagecontainer.change( "#" + type, {
85+
// Programatically changes to the current categories page
86+
$( "body" ).pagecontainer( "change", "#" + type, {
8687
reverse: false,
87-
changeHash: false
88+
changeUrl: false
8889
});
8990

90-
}
91+
}
9192

92-
}
93+
}
9394

94-
} );
95+
} );
9596

96-
// Returns the Router class
97-
return CategoryRouter;
97+
// Returns the Router class
98+
return CategoryRouter;
9899

99100
} );

0 commit comments

Comments
 (0)