curzonj
3 Apr 2008, 3:54 PM
I have made an adapter for Really Simple History. As the user moves through your app, you call
Ext.ux.HistoryMgr.track(location, extraData);and then when the user uses the back and forward buttons the 'change' event will fire:
Ext.ux.HistoryMgr.on('change', function(location, extraData) {
alert('moving to ' + location);
});location is like an anchor or any other url safe string that will go after a '#' on the url. It up to you to decide what mnemonics to use to to indicate where the user is, but as they move you just call track() with the location and any extra data you want associated with it. Keep in mind that the extra data won't be available if someone comes back to the application with a #location on their url, it's only available in the current session.
When someone enters "http://server/myapp#bookmarkedlocation" HistoryMgr will fire the 'initial' event with the location (bookmarkedlocation) as the only parameter. If there is no # on the end of your url, then it will fire the event with an empty string.
Ext.onReady runs before window.onload so you can put listeners on the 'initial' event from inside your onReady methods and they will fire when the doc is loaded.
Here is the adapter code, you'll need the rsh.js file from http://code.google.com/p/reallysimplehistory/
Ext.ux.HistoryMgr = (function() {
var PrivateClass = function() {
// Be aware, you may get a change event with the
// initial location in addition to the initial event
this.addEvents('initial', 'change');
}
Ext.extend(PrivateClass, Ext.util.Observable, {
track: function(name, data) {
dhtmlHistory.add(name, data);
},
currentLocation: function() {
return dhtmlHistory.getCurrentLocation();
}
});
return new PrivateClass();
})();
dhtmlHistory.create({
toJSON: function(o) {
return Ext.util.JSON.encode(o);
},
fromJSON: function(s) {
return Ext.util.JSON.decode(s);
}
});
dhtmlHistory.ExtBridge = function() {
if (typeof dhtmlHistory.ExtBridge.previousOnLoad == 'function') {
dhtmlHistory.ExtBridge.previousOnLoad.call(window);
}
dhtmlHistory.initialize();
dhtmlHistory.addListener(function(newLocation, historyData) {
Ext.ux.HistoryMgr.fireEvent('change', newLocation, historyData);
});
var initialLocation = dhtmlHistory.getCurrentLocation();
Ext.ux.HistoryMgr.fireEvent('initial', initialLocation);
}
dhtmlHistory.ExtBridge.previousOnLoad = window.onload;
window.onload = dhtmlHistory.ExtBridge;
Check out http://code.google.com/p/reallysimplehistory/ for more details about the library.
Ext.ux.HistoryMgr.track(location, extraData);and then when the user uses the back and forward buttons the 'change' event will fire:
Ext.ux.HistoryMgr.on('change', function(location, extraData) {
alert('moving to ' + location);
});location is like an anchor or any other url safe string that will go after a '#' on the url. It up to you to decide what mnemonics to use to to indicate where the user is, but as they move you just call track() with the location and any extra data you want associated with it. Keep in mind that the extra data won't be available if someone comes back to the application with a #location on their url, it's only available in the current session.
When someone enters "http://server/myapp#bookmarkedlocation" HistoryMgr will fire the 'initial' event with the location (bookmarkedlocation) as the only parameter. If there is no # on the end of your url, then it will fire the event with an empty string.
Ext.onReady runs before window.onload so you can put listeners on the 'initial' event from inside your onReady methods and they will fire when the doc is loaded.
Here is the adapter code, you'll need the rsh.js file from http://code.google.com/p/reallysimplehistory/
Ext.ux.HistoryMgr = (function() {
var PrivateClass = function() {
// Be aware, you may get a change event with the
// initial location in addition to the initial event
this.addEvents('initial', 'change');
}
Ext.extend(PrivateClass, Ext.util.Observable, {
track: function(name, data) {
dhtmlHistory.add(name, data);
},
currentLocation: function() {
return dhtmlHistory.getCurrentLocation();
}
});
return new PrivateClass();
})();
dhtmlHistory.create({
toJSON: function(o) {
return Ext.util.JSON.encode(o);
},
fromJSON: function(s) {
return Ext.util.JSON.decode(s);
}
});
dhtmlHistory.ExtBridge = function() {
if (typeof dhtmlHistory.ExtBridge.previousOnLoad == 'function') {
dhtmlHistory.ExtBridge.previousOnLoad.call(window);
}
dhtmlHistory.initialize();
dhtmlHistory.addListener(function(newLocation, historyData) {
Ext.ux.HistoryMgr.fireEvent('change', newLocation, historyData);
});
var initialLocation = dhtmlHistory.getCurrentLocation();
Ext.ux.HistoryMgr.fireEvent('initial', initialLocation);
}
dhtmlHistory.ExtBridge.previousOnLoad = window.onload;
window.onload = dhtmlHistory.ExtBridge;
Check out http://code.google.com/p/reallysimplehistory/ for more details about the library.