K
K
Kirill Mikhailovich2016-08-28 07:01:10
JavaScript
Kirill Mikhailovich, 2016-08-28 07:01:10

How to make scripts with ajax enabled when returning back in the Bitrix directory?

The problem itself, over which I have been fighting for more than a month. The page contains the bitrix.catalog complex component. In the settings, I enable the use of AJAX-mode with "browser navigation emulation" to connect the "back" and "forward" buttons in the browser. Being in the catalog (catalog.section) I click on any element, in ajax-mode I go to the detailed page - then I press the back button in the browser - I return to the original page with the catalog and Bitrix scripts of the catalog completely fall off. No errors, no reaction, no response. additional JQuery, but "smart filter" with INSTANCE_RELOAD enabled and all other scripts, not related to the catalog.section template - work.
I roughly understand the essence of the problem, that when switching to another page, BX.Ajax reloads and changes the id of the container. Partially solved the problem on jQuery through delegation

$("body").on("click",".catalog .item", function()
{
  $(this).addClass("test"); //
});

After comparing the scripts of the smart filter (which works) and the directory, I found significant differences, namely, the filter works through onclick in tags passing this, and the directory uses the global window without passing parameters. So the question is - is there any simple method to fix the problem without rewriting the component's scripts? How to delegate events in native BX.js directory? In JS, I understand, but knowledge is lame with the object model.

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question