djax icon indicating copy to clipboard operation
djax copied to clipboard

Auto Update HTML Head Elements

Open legenderrys opened this issue 11 years ago • 9 comments

Would be a good feature to have djax update all HTML Head Elements after ajaxing a new page.

title element meta description meta keywords ( optional ) body class Pjax does this out the box and I would assume this would as well. with exception to changing body class

legenderrys avatar Feb 21 '14 23:02 legenderrys

@hyperking agreed, this is definitely on the up and coming list. Not sure when I will have time to spend next but these changes should be pretty simple, I'd be happy to accept a pull request.

beezee avatar Feb 22 '14 01:02 beezee

Im not to savvy with github pull request, but here is a gist i came up with that achieves what I'm looking for. https://gist.github.com/hyperking/9177864#file-djax-body-class-update

legenderrys avatar Feb 23 '14 21:02 legenderrys

Thanks for sharing @hyperking but this looks like it's referencing some globally defined functions that aren't even included in the gist content.

I think this is at most two new lines of code to grab the page title and meta description, maybe a third for keywords, placed in the right spot of the djax source. No worries if you aren't comfortable forking and opening a PR, this is high on my list of priorities the next time I find some time to update.

beezee avatar Feb 24 '14 00:02 beezee

which functions? Im using animate css and transit jquery plugin.

legenderrys avatar Feb 24 '14 11:02 legenderrys

Hi beezee, I am also looking around for a way to update the page title and body class. What do you mean - will this be in some of the next updates? .. You wrote about it ;-) Thank much! p ".. this is high on my list of priorities the next time I find some time to update..... "

infosion avatar Mar 19 '14 16:03 infosion

@infosion have u could try my gist method?

legenderrys avatar Mar 19 '14 20:03 legenderrys

at first it didnt work for me - Ill give it another try tomorrow.

infosion avatar Mar 20 '14 08:03 infosion

@infosion @beezee I updated my gist to reflect the example you provided using DOM replacement callbacks.

I defined the body class value based on the page title value. Assuming most sites format the title attribute as "Site Name|Page Name".

hope that helps. also, you could replace var pageTitle = window.location.pathname.split('/')[1]; from the gist however, for landing pages the body class will be empty.

legenderrys avatar Mar 20 '14 14:03 legenderrys

Has there been any progress with this @beezee? All I really need is a way to reload the body classes as I'm working with a Drupal site where flexibility is not always possible so sometimes I have to rely on the body classes for styling purposes. The method suggested by hyperking could work but it is not a bulletproof as I would like.

Any help would be much appreciated!

ConnorHome avatar Aug 05 '15 15:08 ConnorHome