Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2014-03-17 17:49:01

th3lonius
Member
From: Iowa City, IA
Registered: 2010-02-09
Posts: 67
Website

AJAX powered portfolio

Hi all. I am putting together a portfolio site for a friend who does various wood and metal sculpture work. Another friend has designed the site and coded it so it is now my task to integrate with TXP. It is a single page site. Biographical information resides in a fixed container that slides in from the right of the viewport. Only the portfolio section loads asynchronously.

AJAX functions properly right now. This guy used jQuery’s .load() function to pull it off, taking the href value of an anchor (which corresponds to a section ID), stripping the extension (.php) and returning the content of the page in to a container.

I have no idea where to start tying this in to TXP. I need to have clean URLs for this. Someone visiting tylercochran.com/portfolio/walnut-table for instance needs to be taken to the view of that particular work.

I was thinking that it would be nice and neat if it’s possible to use TXP tags in a jQuery script but I’m not sure about that. Someone point me in the right direction please!

Offline

#2 2014-03-17 20:56:57

etc
Developer
Registered: 2010-11-11
Posts: 5,053
Website GitHub

Re: AJAX powered portfolio

th3lonius wrote #279777:

I was thinking that it would be nice and neat if it’s possible to use TXP tags in a jQuery script but I’m not sure about that. Someone point me in the right direction please!

Hi th3lonius,

it’s certainly possible to inject txp data into jQuery scripts, e.g.

<txp:if_individual_article>
<script>
$(function () {
	alert("Currently viewing <txp:title />");
});
</script>
</txp:if_individual_article>

but it would help a lot to see your js code.

Offline

#3 2014-03-17 21:51:21

th3lonius
Member
From: Iowa City, IA
Registered: 2010-02-09
Posts: 67
Website

Re: AJAX powered portfolio

I’m happy to hear that! I should mention that I am principally a designer and frontend guy so my java skills are minimal. I understand how this is working and it seems like it may be overly complicated for the TXP integration. I think my friend how coded the whole site probably took this code from elsewhere and hacked it up.

$(document).ready(function(){      

var hash = window.location.hash.substr(1);  
var href = $('#work-grid li a, #about-thru, #menu a, #next-thru, #prev-thru').each(function(){  
    var href = $(this).attr('href');  
    if(hash==href.substr(0,href.length-4)){  
        var toLoad = hash+'.php #content-cont';  
        $('#content-cont').load(toLoad)  
    }   
}); 

$("body").on('click', '#work-grid li a, #about-thru, #menu a, #next-thru, #prev-thru', function(event) {

    var toLoad = $(this).attr('href')+' #content-cont';
    var bkgdLoad = $(this).attr('href')+' #viewport';
    var leftpos = parseInt($('#left').css('left'));

    if (leftpos == 0) {
        $('#left').animate({left: -600}),
        $('#main').animate({left: 0}),
        $('#main-menu, #right-tog, .bkgd-desc').fadeIn(300);
    };

    $('#content-cont').hide('fast', function(){
        var divpos = parseInt($('#right').css('right'));

        if (divpos == 0) {
            $('#right').animate({right: -600}),
            $('#main').animate({right: 0}),
            $('#main-menu, #right-tog, .bkgd-desc').fadeIn(300);
        };
    }); 
    $('#viewport').fadeOut('fast',loadContent);
    $('#load').remove();  
    $('#wrapper').append('<span id="load">LOADING...</span>');  
    $('#load').fadeIn('normal');


    window.location.hash = $(this).attr('href').substr(0,$(this).attr('href').length-4);


    function loadContent() {  
        $('#content-cont').load(toLoad,''),
        $('#viewport').load(bkgdLoad,'',showNewContent());   
    }  
    function showNewContent() {  
        $('#content-cont').show('normal'),
        $('#viewport').fadeIn('5000',hideLoader());
    }  
    function hideLoader() {  
        $('#load').fadeOut('normal');  
    }   
    return false;  

}); 

});

{Edited to add Textile’s bc.. for formatting. – Uli}

Last edited by uli (2014-03-17 21:53:25)

Offline

#4 2014-03-17 22:21:20

th3lonius
Member
From: Iowa City, IA
Registered: 2010-02-09
Posts: 67
Website

Re: AJAX powered portfolio

http://ericbailey.co/gehry/

Here’s a look at the live, static site.

Offline

#5 2014-03-17 23:01:55

bici
Member
From: vancouver
Registered: 2004-02-24
Posts: 2,075
Website Mastodon

Re: AJAX powered portfolio

th3lonius wrote #279787:

http://ericbailey.co/gehry/

Here’s a look at the live, static site.

What. A. Cool. Site.

Hope you will consider writing up a tutorial on this fine work.


…. texted postive

Offline

#6 2014-03-17 23:03:59

etc
Developer
Registered: 2010-11-11
Posts: 5,053
Website GitHub

Re: AJAX powered portfolio

th3lonius wrote #279786:

I should mention that I am principally a designer and frontend guy so my java skills are minimal. I understand how this is working and it seems like it may be overly complicated for the TXP integration.

You seem to do a great job on the frontend, and txp integration shouldn’t be complicated at all, though you’ll have to import all site content as txp articles. I’m not sure I would just keep the existing structure, it’s unusable with js disabled, but well…

It’s getting late here in Europe, I couldn’t give you a tested solution right now (someone else?), but start by replacing var toLoad = $(this).attr('href')+' #content-cont'; with var toLoad = $(this).attr('href')+' #content-cont > *';, and so on. You will see no difference, but the current markup is invalid (multiply defined nested #content-cont ids).

Offline

#7 2014-03-20 19:10:01

th3lonius
Member
From: Iowa City, IA
Registered: 2010-02-09
Posts: 67
Website

Re: AJAX powered portfolio

Do you think there is a way to pull this off with clean URLs?

Offline

#8 2014-03-20 19:25:00

Gocom
Developer Emeritus
From: Helsinki, Finland
Registered: 2006-07-14
Posts: 4,533
Website

Re: AJAX powered portfolio

Before the world explodes, give parseInt() radix. E.g.

parseInt($('#right').css('right'), 10);

Otherwise you may get base 8 and 16 integers.

Offline

#9 2014-03-20 21:44:37

etc
Developer
Registered: 2010-11-11
Posts: 5,053
Website GitHub

Re: AJAX powered portfolio

th3lonius wrote #279852:

Do you think there is a way to pull this off with clean URLs?

Certainly, but if all you need is replacing tylercochran.com/#walnut-table with tylercochran.com/portfolio/walnut-table, you can do some .htaccess redirect, and just replace the line

var hash = window.location.hash.substr(1);

with

var path = window.pathname.split("/");
var hash = (path.length >= 2 && path[0] == "portfolio" ? path[1] : "");

and maybe window.location.hash = $(this).attr('href').substr(0,$(this).attr('href').length-4); with something similar.

Offline

#10 2014-04-01 15:24:10

th3lonius
Member
From: Iowa City, IA
Registered: 2010-02-09
Posts: 67
Website

Re: AJAX powered portfolio

etc wrote #279783:

Hi th3lonius,

it’s certainly possible to inject txp data into jQuery scripts, e.g.

<txp:if_individual_article>...

but it would help a lot to see your js code.

In this case you are using txp tags within a script but the script itself lay within a txp form. I’m wondering if it’s possible to inject txp data in to an external script. I don’t want to get in to the habit of inserting javascript in to HTML. I did try this method however and I can’t get it to work.

I appreciate all the feedback from everyone (I made some js changes) but I’m still no closer to implementing this. There must be a way to pare down the AJAX code as I have it above. That code relies on extracting the hashtag value from the url hash but with a CMS this wouldn’t be necessary right? So how do I use the jQuery .load() function to extract data from an article in the txp database? Isn’t that the best way to do this?

Offline

#11 2014-04-01 15:29:51

th3lonius
Member
From: Iowa City, IA
Registered: 2010-02-09
Posts: 67
Website

Re: AJAX powered portfolio

Or maybe I misunderstand the .load() function… is exploiting the hash value the only way to use it?

Offline

#12 2014-04-01 15:40:46

colak
Admin
From: Cyprus
Registered: 2004-11-20
Posts: 9,011
Website GitHub Mastodon Twitter

Re: AJAX powered portfolio

th3lonius wrote #280006:

I appreciate all the feedback from everyone (I made some js changes) but I’m still no closer to implementing this. There must be a way to pare down the AJAX code as I have it above. That code relies on extracting the hashtag value from the url hash but with a CMS this wouldn’t be necessary right? So how do I use the jQuery .load() function to extract data from an article in the txp database? Isn’t that the best way to do this?

Would external output work?


Yiannis
——————————
NeMe | hblack.art | EMAP | A Sea change | Toolkit of Care
I do my best editing after I click on the submit button.

Offline

Board footer

Powered by FluxBB