Changeset 5672
- Timestamp:
- 01/07/08 13:57:38 (1 year ago)
- Files:
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
sandbox/tschaub/history/examples/navigation-history.html
r5671 r5672 30 30 type: OpenLayers.Control.BUTTON, 31 31 trigger: function() {nav.previous();}, 32 active: true33 32 }); 33 nav.onPreviousChange = function(state, length) { 34 if(state) { 35 prev.activate(); 36 document.getElementById("previous").disabled = false; 37 } else { 38 prev.deactivate(); 39 document.getElementById("previous").disabled = true; 40 } 41 OpenLayers.Console.log( 42 length + " items remaining in previous history" 43 ); 44 } 34 45 map.addControl(prev); 35 46 36 47 next = new OpenLayers.Control({ 37 48 type: OpenLayers.Control.BUTTON, 38 trigger: function() {nav.next();}, 39 active: true 49 trigger: function() {nav.next();} 40 50 }); 51 nav.onNextChange = function(state, length) { 52 if(state) { 53 next.activate(); 54 document.getElementById("next").disabled = false; 55 } else { 56 next.deactivate(); 57 document.getElementById("next").disabled = true; 58 } 59 OpenLayers.Console.log( 60 length + " items remaining in next history" 61 ); 62 } 41 63 map.addControl(next); 42 64 … … 55 77 56 78 <div id="map"></div> 57 zoom to <button onclick="prev.trigger();" >previous</button>58 <button onclick="next.trigger();" >next</button><br />79 zoom to <button onclick="prev.trigger();" id="previous" disabled="disabled">previous</button> 80 <button onclick="next.trigger();" id="next" disabled="disabled">next</button><br /> 59 81 60 82 <div id="docs"></div> sandbox/tschaub/history/lib/OpenLayers/Control/NavigationHistory.js
r5671 r5672 112 112 this.clear(); 113 113 }, 114 115 /** 116 * APIMethod: onPreviousChange 117 * Called when the previous history stack changes. This function will 118 * be called with two arguments, the state ({Object}) that will be 119 * restored if previous is called and the number ({Integer}) of items 120 * remaining in the previous history. 121 */ 122 onPreviousChange: function(state, length) {}, 123 124 /** 125 * APIMethod: onNextChange 126 * Called when the next history stack changes. This function will 127 * be called with two arguments, the state ({Object}) that will be 128 * restored if next is called and the number ({Integer}) of items 129 * remaining in the next history. 130 */ 131 onNextChange: function(state, length) {}, 114 132 115 133 /** … … 174 192 this.restore(state); 175 193 this.restoring = false; 194 this.onNextChange(this.nextStack[0], this.nextStack.length); 195 this.onPreviousChange( 196 this.previousStack[1], this.previousStack.length - 1 197 ); 176 198 } else { 177 199 this.previousStack.unshift(current); … … 197 219 this.restore(state); 198 220 this.restoring = false; 221 this.onNextChange(this.nextStack[0], this.nextStack.length); 222 this.onPreviousChange( 223 this.previousStack[1], this.previousStack.length - 1 224 ); 199 225 } 200 226 return state; … … 233 259 var state = this.on[type].apply(this, arguments); 234 260 this.previousStack.unshift(state); 261 if(this.previousStack.length > 1) { 262 this.onPreviousChange( 263 this.previousStack[1], this.previousStack.length - 1 264 ); 265 } 235 266 if(this.previousStack.length > (this.limit + 1)) { 236 267 this.previousStack.pop(); … … 238 269 if(this.nextStack.length > 0) { 239 270 this.nextStack = []; 271 this.onNextChange(null, 0); 240 272 } 241 273 }
