Skip to content

Pjax breaks my javascript plugins #560

@Eschwinm

Description

@Eschwinm

Good afternoon,

I was implementing Pjax into my website but whenever I add it to a #pjax-container it will break my javascript.

I have come to the conclusion because I Have one main.js where every plugin will be initialized within a document.ready function. When a Pjax page will get loaded from the source the document will not reload so the document ready won't fire a second time.

When I make one large function from all the initializing plugins called Init(); and I will call this on pjax:success it will initialize every plugin again and again on every page visit. This will cause some errors with some of my plugins.

My plugins contain of custom plugins (I make a plugin for the smallest chunks of codes and I will initialize is after in main.js).

Well, now there is only content in #pjax-container containing html, ckeditor stuff, some datatables stuff etc.

Whenever Pjax gets content from a new page from the corresponding page's #pjax-container it will not initialize all the elements on the corresponding page's contents.

Also when I got back and forward in my website the website breaks and all plugins won't work anymore.

There are no errors generated but every element just does nothing because there is nothing binded to all those 'new' elements from the Pjax corresponding page.

Is there any info about this ? I couldn't find any info about this on the web.

If anyone has suggestions about how to tackle these problems please let me know.

My structure is:

[head]
-- head stuff including some css and font files
[/head]
[body]
[div id="pjax-container"]
-- random stuff from my plugins and ckeditor stuff
[/div]

-- all javascript files being included here
[/body]

[] are replaced with <>

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions