mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-06-23 15:30:45 -04:00
Encode local state using # instead of ? in URLS
Needed for appcache (appcache caches URLs with different ? query parameters separately). Also probably semantically more correct, since the query data represents local state.
This commit is contained in:
parent
3d63a57ff4
commit
5db33faeb8
@ -2,7 +2,7 @@
|
|||||||
# License: GPL v3 Copyright: 2017, Kovid Goyal <kovid at kovidgoyal.net>
|
# License: GPL v3 Copyright: 2017, Kovid Goyal <kovid at kovidgoyal.net>
|
||||||
from __python__ import hash_literals, bound_methods
|
from __python__ import hash_literals, bound_methods
|
||||||
|
|
||||||
from ajax import encode_query
|
from ajax import encode_query as ajax_encode_query
|
||||||
|
|
||||||
from book_list.constants import read_book_container_id, book_list_container_id
|
from book_list.constants import read_book_container_id, book_list_container_id
|
||||||
from book_list.globals import get_current_query
|
from book_list.globals import get_current_query
|
||||||
@ -54,11 +54,16 @@ def open_book(book_id, fmt, library_id=None, replace=False):
|
|||||||
push_state({'book_id':book_id, 'fmt':fmt, 'library_id':library_id}, replace=replace, mode=read_book_mode)
|
push_state({'book_id':book_id, 'fmt':fmt, 'library_id':library_id}, replace=replace, mode=read_book_mode)
|
||||||
|
|
||||||
|
|
||||||
|
def encode_query(query):
|
||||||
|
ans = ajax_encode_query(query)
|
||||||
|
return '#' + ans[1:]
|
||||||
|
|
||||||
|
|
||||||
def push_state(query, replace=False, mode='book_list', call_handler=True):
|
def push_state(query, replace=False, mode='book_list', call_handler=True):
|
||||||
query = {k:query[k] for k in query}
|
query = {k:query[k] for k in query}
|
||||||
if mode is not 'book_list':
|
if mode is not 'book_list':
|
||||||
query.mode = mode
|
query.mode = mode
|
||||||
query = encode_query(query) or '?'
|
query = encode_query(query)
|
||||||
if replace:
|
if replace:
|
||||||
window.history.replaceState(None, '', query)
|
window.history.replaceState(None, '', query)
|
||||||
else:
|
else:
|
||||||
|
@ -29,12 +29,12 @@ def parse_url_params(url=None, allow_multiple=False):
|
|||||||
url = url or window.location.href
|
url = url or window.location.href
|
||||||
if cache[url]:
|
if cache[url]:
|
||||||
return parse_url_params.cache[url]
|
return parse_url_params.cache[url]
|
||||||
qs = url.indexOf('?')
|
qs = url.indexOf('#')
|
||||||
ans = {}
|
ans = {}
|
||||||
if qs < 0:
|
if qs < 0:
|
||||||
cache[url] = ans
|
cache[url] = ans
|
||||||
return ans
|
return ans
|
||||||
q = url.slice(qs + 1, ((url.indexOf('#') + 1) or (url.length + 1)))
|
q = url.slice(qs + 1, (url.length + 1))
|
||||||
if not q:
|
if not q:
|
||||||
cache[url] = ans
|
cache[url] = ans
|
||||||
return ans
|
return ans
|
||||||
|
Loading…
x
Reference in New Issue
Block a user