Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
js refactoring; possible regressions in IE behavior
(which seems to behave differently offline than online...) Squashed commit of the following: commit b30a9a6d4cd9d9c132da3d42587bb0fa479ba287 Author: Eric Liang <forward.eric@gmail.com> Date: Thu Feb 19 01:03:16 2009 -0800 Thu Feb 19 01:03:16 PST 2009 commit 7d8654cd4d324359bba784de0dd9feeee72afd98 Author: Eric Liang <forward.eric@gmail.com> Date: Thu Feb 19 00:25:40 2009 -0800 Thu Feb 19 00:25:40 PST 2009 commit eae09a45b4d35be84874deea047d8abeca548224 Author: Eric Liang <forward.eric@gmail.com> Date: Thu Feb 19 00:15:30 2009 -0800 Thu Feb 19 00:15:30 PST 2009 commit 8cbdfa871184c83b1ce7f137f2d5286e04b5455a Author: Eric Liang <forward.eric@gmail.com> Date: Wed Feb 18 23:39:34 2009 -0800 Wed Feb 18 23:39:34 PST 2009 commit 919c1c3d72143250029924163c6f8f961df9c583 Author: Eric Liang <forward.eric@gmail.com> Date: Wed Feb 18 23:33:28 2009 -0800 Wed Feb 18 23:33:28 PST 2009 commit 953608008a244cb7041c1be329329c084b9588a8 Author: Eric Liang <forward.eric@gmail.com> Date: Wed Feb 18 23:31:40 2009 -0800 Wed Feb 18 23:31:40 PST 2009 commit 0b7faf594bebb8b7a4e41dbe6b8357cdcadfaa78 Author: Eric Liang <forward.eric@gmail.com> Date: Wed Feb 18 23:12:42 2009 -0800 Wed Feb 18 23:12:42 PST 2009 commit 53de5a7b9d1e3e4ee01a94ab553fe583591381e9 Author: Eric Liang <forward.eric@gmail.com> Date: Wed Feb 18 22:39:42 2009 -0800 Wed Feb 18 22:39:42 PST 2009 commit 5badbc3714203594c81b67a4ba56dfc0df3d37ef Author: Eric Liang <forward.eric@gmail.com> Date: Wed Feb 18 22:31:52 2009 -0800 Wed Feb 18 22:31:52 PST 2009 commit a998e2281fc9502cf124fab813c446909e8f3035 Author: Eric Liang <forward.eric@gmail.com> Date: Wed Feb 18 21:24:00 2009 -0800 Wed Feb 18 21:24:00 PST 2009
- Loading branch information
Eric Liang
committed
Feb 19, 2009
1 parent
22c5304
commit 9947dde
Showing
5 changed files
with
358 additions
and
382 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
var DATE_MIN = 100001; | ||
var DATE_MAX = 300001; | ||
var DEFAULT_PAGE = 1; | ||
var DEFAULT_URL = ''; | ||
var FS = ','; | ||
var FS2 = '.'; | ||
|
||
if (location.pathname != "/") { | ||
var page_match = location.pathname.match(/^\/[0-9]+$/); | ||
if (page_match) | ||
DEFAULT_PAGE = page_match.toString().substring(1); | ||
else { | ||
DEFAULT_URL = location.pathname; | ||
if (DEFAULT_URL.charAt(DEFAULT_URL.length-1) == '/') | ||
DEFAULT_URL = DEFAULT_URL.substring(0, DEFAULT_URL.length-1); | ||
} | ||
} else if (STATIC_FRONTPAGE) | ||
DEFAULT_URL = '/cover'; | ||
|
||
function Repr(dict) { | ||
this.query = ''; | ||
this.url = ''; | ||
this.page = DEFAULT_PAGE; | ||
this.tags = []; | ||
this.date_min = DATE_MIN; | ||
this.date_max = DATE_MAX; | ||
|
||
for (var i in dict) | ||
this[i] = dict[i]; | ||
|
||
if (!this.url && this.tags.length === 0 && this.date_min == DATE_MIN && this.date_max == DATE_MAX && this.page == DEFAULT_PAGE && !this.query) | ||
this.url = DEFAULT_URL; | ||
|
||
this.toString = function() { | ||
return 'Repr Object ' + this.serialize(); | ||
}; | ||
|
||
this.serialize = function(nav_attrs_only) { | ||
var output = []; | ||
var have_embed = false; | ||
if (!nav_attrs_only && this.url) { | ||
if (this.url != DEFAULT_URL) | ||
output[output.length] = this.url; | ||
have_embed = true; | ||
} | ||
if (this.tags.length > 0) | ||
output[output.length] = 'tags=' + this.tags.join(FS2); | ||
if (this.date_min == this.date_max) | ||
output[output.length] = 'month=' + this.date_min; | ||
else { | ||
if (this.date_min != DATE_MIN) | ||
output[output.length] = 'min=' + this.date_min; | ||
if (this.date_max != DATE_MAX) | ||
output[output.length] = 'max=' + this.date_max; | ||
} | ||
if (!nav_attrs_only && !have_embed) { | ||
if (this.query) | ||
output[output.length] = 'query=' + this.query; | ||
else if (output.length === 0 && this.page != DEFAULT_PAGE) | ||
output[output.length] = 'page=' + this.page; | ||
} | ||
return '#' + output.join(FS); | ||
}; | ||
} | ||
|
||
Repr.deserialize = function(hash) { | ||
var attrs = {}; | ||
if (hash.charAt(0) == '#') | ||
hash = hash.substring(1); | ||
var chunks = hash.split(FS); | ||
for (var i in chunks) { | ||
var chunk = chunks[i]; | ||
if (attrs['query']) | ||
attrs['query'] += ',' + chunk; | ||
else if (chunk.substring(0,1) == '/') | ||
attrs['url'] = chunk; | ||
else if (chunk.substring(0,5) == 'tags=') | ||
attrs['tags'] = chunk.substring(5).split(FS2); | ||
else if (chunk.substring(0,5) == 'page=') | ||
attrs['page'] = chunk.substring(5); | ||
else if (chunk.substring(0,6) == 'month=') | ||
attrs['date_min'] = attrs['date_max'] = chunk.substring(6); | ||
else if (chunk.substring(0,4) == 'min=') | ||
attrs['date_min'] = chunk.substring(4); | ||
else if (chunk.substring(0,4) == 'max=') | ||
attrs['date_max'] = chunk.substring(4); | ||
else if (chunk.substring(0,6) == 'query=') | ||
attrs['query'] = chunk.substring(6); | ||
} | ||
return new Repr(attrs); | ||
}; |
Oops, something went wrong.