Browse Source

Use hash for IDs rather than GET params

Change the URL when you save, handle forward/back navigation
master
Chris Smith 12 years ago
parent
commit
e498bb6ecf
1 changed files with 12 additions and 6 deletions
  1. 12
    6
      res/js/viewer.js

+ 12
- 6
res/js/viewer.js View File

@@ -174,7 +174,8 @@ $(function() {
174 174
    url: 'res/data/layouts/new',
175 175
    data: {layout: JSON.stringify(layout)},
176 176
    success: function(res) {
177
-    var url = window.location.href + "?id=" + res;
177
+    window.location.hash = res;
178
+    var url = window.location.href;
178 179
     $('#link').children().remove();
179 180
     $('<a>').attr('href', url).text(url).appendTo($('#link'));
180 181
     $('#save_inprogress').hide();
@@ -211,10 +212,15 @@ $(function() {
211 212
   $.getJSON('res/data/layouts/' + id + '.js', updateLayout);
212 213
  }
213 214
 
214
- var id = getURLParameter('id');
215
- if (id === null || id === 'null') {
216
-  updateLayout({level: key + 1, towers:[]});
217
- } else {
218
-  getLayout(id);
215
+ function updateFromHash() {
216
+  var id = window.location.hash;
217
+  if (id === '') {
218
+   updateLayout({level: 1, towers:[]});
219
+  } else {
220
+   getLayout(id.substr(1));
221
+  }
219 222
  }
223
+
224
+ $(window).bind('hashchange', updateFromHash);
225
+ updateFromHash();
220 226
 });

Loading…
Cancel
Save