Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Permalinks! #12

Closed
msiebuhr opened this issue Jul 6, 2012 · 4 comments
Closed

Permalinks! #12

msiebuhr opened this issue Jul 6, 2012 · 4 comments

Comments

@msiebuhr
Copy link
Owner

msiebuhr commented Jul 6, 2012

It's fun to find & share new characters - let's add some kind of permalinks so it's easy to share!

(Also, I should probably buy a dedicated domain for it!)

@Munter
Copy link
Collaborator

Munter commented Jul 15, 2012

This should be a bit easier now that I have fixed #17
We could just have the id in the fragment identifier and search for it when ready.

@msiebuhr
Copy link
Owner Author

So. I've played with variations over the following

window.onpopstate = function (e) {
    // Shamelessly stolen from MDN
    function loadPageVar (sVar) {
        return unescape(window.location.search.replace(new RegExp("^(?:.*[&\\?]" + escape(sVar).replace(/[\.\+\*]/g, "\\$&") + "(?:\\=([^&]*))?)?.*$", "i"), "$1"));
    }

    var query = loadPageVar("q");
    query = query.replace(/\/$/, ""); // Remove trailing slash

    searchAndShow(query);
    $("#searchField").val(query);
};

It decodes stuff on the form http://charcod.es/?q=QUERY/ and enters in the query-field - which is implicitly searched for when the data is done loading.

But. I can't get FF to fire window.onpopstate when it's loading the page, no matter where I put it. Chrome does it reliably.

My working hypothesis is that I'm hooking in the wrong place, but with my limited knowledge of browser internals, I probably missed something important somewhere else...

@msiebuhr
Copy link
Owner Author

Ah. Re-reading the MDN-article on window.onpopstate, yields the following:

Browsers tend to handle the popstate event differently on page load. Chrome and Safari always emit a popstate event on page load, but Firefox doesn't.

msiebuhr added a commit that referenced this issue Aug 28, 2012
@msiebuhr
Copy link
Owner Author

Commited draft patch in d6b63d3 (yes, yes - experimental stuff should go in a branch...)

@Munter Munter closed this as completed in 371ba83 Aug 29, 2012
Munter added a commit that referenced this issue Aug 29, 2012
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants