Бібліотека FullAjax дозволяє оновлювати більше як один контейнер, завдяки реалізації в ній двох моделей запиту – один запит для одного блоку, та один – для декількох блоків. В плаґіні Add FullAjax (2011.01.10) ця можливість використовується для оновлення модуля “хлібних крихт”. Звичайно замість цього модуля можна підставити будь який інший, але лише один – це пов’язано з тим, що я ще не придумав як автоматизувати процес налаштування для оновлення декількох модулів/позицій.
Нижче маленька інструкція як налаштувати оновлення декількох модулів через Ajax.

Теорія, як це реалізовано в FullAjax.

Припустимо, що в нас є три блоки, які потрібно одночасно оновлювати з допомогою Ajax.

1
2
3
<div id="menu">Тут HTML код меню</div>
<div id="content">Тут HTML код вмісту</div>
<div id="baner_img">Тут HTML код картинки</div>

Для початку потрібно вказати для FullAjax які блоки потрібно оновлювати. Для цього додамо, в налаштування цієї бібліотеки, модель:

1
2
3
4
5
6
7
8
9
/* базове налаштування */
SRAX.Filter.add({url:'/', id:'content'});
SRAX.directLink();
/* модель */
SRAX.Model2Blocks['content'] = {
   'menu':'menu',
   'content':'content',
   'baner_img':'baner_img'
}

Для того, що це все щастя працювало, потрібно щоб вміст, який буде віддавати нам сервер, мав наступний вигляд:

1
2
3
4
5
6
7
8
9
10
11
12
13
<!-- :ax:menu:begin: //-->
HTML код меню
<!-- :ax:menu:end: //-->
 
Все що знаходиться між цими блоками буде проігноровано при показі.
 
<!-- :ax:content:begin: //-->
HTML код вмісту
<!-- :ax:content:end: //-->
 
<!-- :ax:baner_img:begin: //-->
HTML код картинки банера
<!-- :ax:baner_img:end: //-->

Ось так просто, ми маємо змогу оновлювати декілька блоків одночасно.

Практика, як реалізувати оновлення декількох модулів в плаґіні Add FullAjax .

Маленька покрокова інструкція :)

1. Потрібно встановити шаблон “fullajax_tmpl”, якщо не встановлено.

2. В налаштуваннях плаґіну встановити оновлення модулів в ручну.

3. Далі, потрібно зайти в Module Manager та дізнатись позиції які бажаємо оновлювати. Для прикладу візьмемо: position-3, position-1, та user3.

4. Відкриваємо index.php нашого шаблону, та додаємо кожній цій позиції унікальний ідентифікатор(якщо цього не зроблено при створенні шаблону).
Приклад:

1
2
3
4
5
6
7
8
9
10
11
<div id="id-for-pos-three">
	<jdoc:include type="modules" name="position-3" />
</div>
	...
<div id="id-for-pos-user">
	<jdoc:include type="modules" name="user3" />
</div>
	...
<div id="id-for-pos-one">
	<jdoc:include type="modules" name="position-1" />
</div>

5. Заходимо в налаштування плаґіну, та в полі “Js code, parameters for FullAjax” додаємо модель для щойно створених блоків.

1
2
3
4
5
6
7
/* модель */
SRAX.Model2Blocks['forajax'] = {
   'id-for-pos-one':'id-for-pos-one',
   'id-for-pos-user':'id-for-pos-user',
   'id-for-pos-three':'id-for-pos-three',
   'forajax':'forajax'
}

forajax – це ідентифікатор вмісту.

6. Відкриваємо файл /templates/fullajax_tmpl/index.php та додаємо туди відсутні позиції.

1
2
3
4
5
6
7
8
9
10
11
<!-- :ax:id-for-pos-three:begin: //-->
	<jdoc:include type="modules" name="position-3" />
<!-- :ax:id-for-pos-three:end: //-->
 
<!-- :ax:id-for-pos-user:begin: //-->
	<jdoc:include type="modules" name="user3" />
<!-- :ax:id-for-pos-user:end: //-->
 
<!-- :ax:id-for-pos-one:begin: //-->
	<jdoc:include type="modules" name="position-1" />
<!-- :ax:id-for-pos-one:end: //-->

7. От і все :)

57s коментарів to “ Як оновлювати більше як один модуль з допомогою Ajax ”

  1. popo коментує:

    that’s right.
    I did it and works. but my modules, not loading in correct positions!
    It creates something below positions (modules not reloaded).

    Modules load under not their own so they have no class – no style. I have 2 module! one here:
    (I hope works!)

    main page


    another here:

    main page

    • popo коментує:

      again:
      Modules load under #div id=”forajax”# not their own #div id=”something”# so they have no class – no style. I have 2 module! one here:

    • Fedik коментує:

      think something missed …
      you not forgot about:

      /* model */
      SRAX.Model2Blocks['forajax'] = {
         'id-where-module':'id-where-module',
         'forajax':'forajax'
      }
      • popo коментує:

        Thank you for your answers!

        Wow!
        I must change “FullAjaxId” to “forajax”! May I need to change any other “FullAjaxId”? :) Should not it set automatically?
        I did some corrections to DIVs I added to template. Now, it works and homepage loads correctly (as before) and modules are in true IDs bet links, again, loads the “forajax” ID but positions loads without syling(no class=””). my right sidebar which should not be shown in some pages are visible(even empty).
        my breadcrumb not loading! :)

      • Fedik коментує:

        no, other “FullAjaxId” no need change .. in this article it was as example :)
        for sidebar you need use some HTM&CSS trick for hide it when there no content
        about breadcrumb have no idea :)

  2. popo коментує:

    Thank you again.
    I decided not to use FullAjax for Artister templates because modules without css styling are not good :) and I have no other free time to do experiment.
    I replaced FullAjaxId with forajax (my main ID) in Model2Blocks and It worked. but one empty Div pairs are responsible for my side bar.
    breadcrumb problem resolved adding aditional Div to it separating it from one other position.
    One major difference between artister (and some others) templates and simple ons, also, what I think make FullAjax load component and messages correctly and positions without css class (in their DIV) is that artister ask for components using
    #Jdoc:include type=”component”#
    and for positions (modules):

    #?php
    if ($view->containsModules('breadcrumb'))
    echo
    artxPost($view->position('breadcrumb')); ?#

    ( replaced with #) :)

    and FullAjax not!
    Maybe, later.
    Regards.
    Maybe it is true or not! I don't know.

  3. Alexander коментує:

    I guess there is much to do and no free time right? :D
    Anyway i have noticed a bug with non utf-8 urls and 404 errors with full ajax… the urls was with Greek chars, if you would like i can give u url…

    There is also one question i have about the plugin, i have a module that places links like your blogs reply ones.. mine have id like “idname”++number (each time the element gets new uniue id). How could i block these from fullaxaj? is there a way to block via class? or something like “return ops.el.id != ‘idname*'; “

    • Fedik коментує:

      yes, you are right .. I have not to much free time now ;)
      problem with some special chars I noted only in IE, in this time .. but maybe will need more test

      about ignore some link by block id, try something like:

      ...
      var parent = ops.el.parentNode.parentNode.id;
      if(parent.indexOf('idname-') !== -1){
                  return false;
              }  
      ...

      here is need check, how much “parentNode” you need …

      about, “by class” not sure, but can be something similar

  4. carlos коментує:

    Fedir, okay, so I explained to you, but not updated the modules, I’m using templante beez20 joomla 2.5. The code I’m using and the following

    / * Basic Configuration * /
    SRAX.Filter.add ({url: ‘/’, id: ‘forajax’});
    SRAX.directLink ();
    / * Model * /
    SRAX.Model2Blocks [‘forajax’] = {
    ‘main’, ‘main’,
    ‘top’, ‘top’,
    ‘forajax': ‘forajax’
    }
    ————————————————– ————————————
    the template tmpl put right after the code

    <-: X: get (‘fullAjaxContId’, ‘forajax’);?>: End: / / -> then put this

    and the modules do not update at all
    What can I do for this to work?

  5. Dan коментує:

    Hi,

    and thanks alot for this nice plug-in.

    Unfortunately I’ve got the problem, that the module “showplus”, which I use for a gallery, doesn’t load properly since I’ve istalled fullajax.

    Whenever I reload the page with F5 the showplus gallery loads correctly and works just fine, but opening this page via menu-item, it won’t.

    The showplus module is placed via {loadposition}.

    Do you have any suggestions?

    Many thanks in advance,
    Dan

  6. Fettbein коментує:

    Thanks a lot for this great plugin!!
    I’m just in trouble with the semi automatically update of my position. My breadcrump is updated but empty instead of being chaged to the right path.
    Any suggestions?

  7. JCC коментує:

    Hi im joomla newbie and im starting to create a website but really like your plugin and wanna implement it , but so can u tell me the easiest joomla framework that u have tested to use your plugin. so i could get a template of that framework.

    im going to create a music site and need my mp3 player keep playing while the user navegate without using iframes or a popup player.

    ty

    • Fedik коментує:

      worked with the default template, as you can see on demo site…
      you will get less problem with self made template or with a template created by Joomla way Template_Development

      • JCC коментує:

        Ty for your fast reply, thats a great idea but the default template doesnt look ok and create a new one is mmmmm i think i will try using a framework template but looking for the want that will get me less problems?

      • Fedik коментує:

        unfortunately I cannot tell you what framework will make a less problem … cause I do not know ;)

  8. Дмитрий коментує:

    Здравствуйте.

    Будьте добры, подскажите, в чем я ошибаюсь? Перерыл уже все что можно – не могу найти причину.

    Дано:

    Стандартный сайт с демо-данными – http://test.skmaximum.ru.preview.ihc.ru/ .

    Установленный addfullajax_2012.10.14. Контент находится в id=”main”

    Настройки плагина:

    Enable Positions update – Yes, semi-automatically
    Content CSS id – main

    Ignore menu items – Home
    Do not use FullAjax on – Home

    Область контента подгружается с шаблоном. Для пункта меню Home аякс отключен, однако все равно срабатывает.

    Подскажите пожалуйста, куда копать? Уже все поперепробовал что можно.

    Спасибо.

    • Fedik коментує:

      ошибка: “Ignore menu items – Home”
      Home – ето корень сайта, по етому, если SEF включено то будут игнорироваться все дочерние страници,

Напишіть відгук

Ваша пошт@ не публікуватиметься. Обов’язкові поля позначені *

Можна використовувати XHTML теґи та атрибути: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>