I work on a sandbox project which provides a Responsive Tabs to Accordion Panel style. Everything works fine except that once the page loaded, any Ajax callback (i.e add to cart or colorbox) seems to trigger the js function of my module.
The way js function is set in plugins/styles/reponsive_tabs.inc
function theme_responsive_tabstoaccordion_panels_style_render_region($vars) {
//...
$element = array(
//...
'#attached' => array(
'js' => array(
drupal_get_path('module', 'responsive_tabstoaccordion_panels') . '/plugins/styles/responsive_tabstoaccordion_panels.js' => array('type' => 'file'),
),
//...
),
);
//set the wrapper id to give to responsive_tabstoaccordion_panels.js
drupal_add_js(array('responsive_tabstoaccordion_panels' => array('tabstoaccordion_panel' => '#'.$tab_id)), array('type' => 'setting'));
Drupal behavior in responsive_tabstoaccordion_panels.js
(function ($) {
$.fn.extend({
easyResponsiveTabs: function (options) {
//the main js function which is triggered
//...
});
Drupal.behaviors.responsive_tabstoaccordion_panels = {
attach: function (context, settings) {
$(settings.responsive_tabstoaccordion_panels.tabstoaccordion_panel).easyResponsiveTabs({
//Set options
type: 'default',
//...
});
}
};
})(jQuery);
I guess it has to see with the way I attach my function to Drupal.behaviors ?
Drupal.attachBehaviors()
when its task has finished. What problem is this actually giving you, is your tab functionality being attached twice when you only want it attached once?$(settings.responsive_tabstoaccordion_panels.tabstoaccordion_panel).once('my_module').easyResponsiveTabs({...
should sort it