Skip to content

Conversation

@WTVader
Copy link

@WTVader WTVader commented Jan 23, 2013

Compatibility with jQuery 1.9

Compatibility with jQuery 1.9
@beezee
Copy link
Owner

beezee commented Jan 26, 2013

Looks simple enough - is this all that's required? Does it maintain backwards compatibility?

@WTVader
Copy link
Author

WTVader commented Jan 26, 2013

Yes! I've tried it also with jQuery 1.8.3 and it worked well.

@beezee
Copy link
Owner

beezee commented Jan 26, 2013

Thanks- tested on my live demo (http://brianzeligson.com/djax) and it breaks (no $.parseHTML available in jQuery 1.4.4)

I realize that's a pretty old version, but the fix for me was as simple as

var result = (typeof $.parseHTML === 'function')
                ? $($.parseHTML(response)) : '"'+response+'"';

This has the advantage of using $.parseHTML when it's available, and falling back on the old method when it's not, and should keep things working in all versions. If you'd like to make this adjustment I'll be happy to merge the pull.

@WTVader
Copy link
Author

WTVader commented Jan 26, 2013

Sounds good. Thanks for that!
There is another issue I came across recently: djax doesn't usually work for (wordpress) search form submits. Do you have any idea how to modify djax so that it works also for search pages?

@beezee
Copy link
Owner

beezee commented Feb 10, 2013

Likely because djax is bound to links, as opposed to this context being a form submit.

The easiest solution is probably to update a hidden link based on the form input and trigger a click instead of allowing default form submission, something like this:

<form id="search" action="/">
    Search: <input id="search-term" type="text" />
</form>
<a id="search-submit" style="display:none;"></a>
<script type="text/javascript>
    function($, exports, undefined){
        $(document).ready(function() {
            $('#search').submit(function(e){
                e.preventDefault();
                $('#search-submit').attr('href', '/?s='+encodeURIComponent($('#search-term').val()))
                    .click();
            });
        });
    }(jQuery, window));
</script>

Keep me posted on your pull request and I'll merge once it's adjusted.

@kyleconrad
Copy link

For those wondering how to do search, here's how I got it working all nice and pretty inside djax.

HTML:

<form role="search" class="search" method="get" id="searchform" action="<?php echo home_url( '/' ); ?>" autocomplete="off">
    <input type="text" value="" name="s" id="search" class="searchbar" />
</form>
<a href="#" id="search-submit"/></a>

JQUERY:

$('#searchform').submit(function(e){
    event.preventDefault();
    $('#search-submit').attr('href', '<?php bloginfo('url');?>/?s='+encodeURIComponent($('#search').val())).trigger('click');
});

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants