Flexslider in MD-Portfolio content is not displayed

FrancescoR's picture
FrancescoR
Thu, 04/12/2018 - 12:18
#1
Flexslider in MD-Portfolio content is not displayed

Hello team.

I would like to show a gallery of images with the flexslider module in the md-portfolio content

I added two files in the function "function md_portfolio_library ()":

 - jquery.flexslider-min.js

 - flexslider.load.js

and in the function "function md_portfolio_load_content" I entered

 - <script>Drupal.behaviors.flexslider.attach();</script>

done this when I view the contents md-portfolio is blocked and nothing is displayed.

Firebug tells me that there is an error in flexslider.load.js "TypeError: settings is undefined" but I do not have the devout abilities to solve the problem !!

How can I solve the problem and activate flexslider?

Thanks in advance.

cindy's picture
cindy
Sat, 04/14/2018 - 00:15

Hi,

Please check code file flexslider.load.js, you will see that function attach is declared with 2 parameters: context and settings which are automatically passed in drupal 7 
In case you want to call function attach, these 2 parameters should be passed also
For example, Drupal.behaviors.flexslider.attach(document, Drupal.settings);

FrancescoR's picture
FrancescoR
Sat, 04/14/2018 - 12:56

Hello Cindy,

I did some tests but I did not solve it!

what parameters should I pass to the attach function?

Drupal.behaviors.flexslider.attach(? , ?);

this is the flexslider.load.js

Thank You So Much.

(function($) {

  // Behavior to load FlexSlider
  Drupal.behaviors.flexslider = {
    attach: function(context, settings) {
      var id;
      var sliders = [];
      if ($.type(settings.flexslider) !== 'undefined' && $.type(settings.flexslider.instances) !== 'undefined') {

        for (id in settings.flexslider.instances) {

          if (settings.flexslider.optionsets[settings.flexslider.instances[id]] !== undefined) {
            if (settings.flexslider.optionsets[settings.flexslider.instances[id]].asNavFor !== '') {
              // We have to initialize all the sliders which are "asNavFor" first.
              _flexslider_init(id, settings.flexslider.optionsets[settings.flexslider.instances[id]], context);
            } else {
              // Everyone else is second
              sliders[id] = settings.flexslider.optionsets[settings.flexslider.instances[id]];
            }
          }
        }
      }
      // Slider set
      for (id in sliders) {
        _flexslider_init(id, settings.flexslider.optionsets[settings.flexslider.instances[id]], context);
      }
    }
  };

  /**
   * Initialize the flexslider instance
   */

  function _flexslider_init(id, optionset, context) {
    $('#' + id, context).once('flexslider', function() {
      // Remove width/height attributes
      // @todo load the css path from the settings
      $(this).find('ul.slides > li *').removeAttr('width').removeAttr('height');

      if (optionset) {
        // Add events that developers can use to interact.
        $(this).flexslider($.extend(optionset, {
          start: function(slider) {
            slider.trigger('start', [slider]);
          },
          before: function(slider) {
            slider.trigger('before', [slider]);
          },
          after: function(slider) {
            slider.trigger('after', [slider]);
          },
          end: function(slider) {
            slider.trigger('end', [slider]);
          },
          added: function(slider) {
            slider.trigger('added', [slider]);
          },
          removed: function(slider) {
            slider.trigger('removed', [slider]);
          },
          init: function(slider) {
            slider.trigger('init', [slider]);
          }
        }));
      } else {
        $(this).flexslider();
      }
    });
  }

}(jQuery));

cindy's picture
cindy
Sun, 04/15/2018 - 23:00

You can send us your site url, admin account and FTP account

We will check for you!

cindy's picture
cindy
Mon, 04/16/2018 - 23:08

We could not log in your FTp account

However, we check page www.officina.pg.it/officina/livevideo and see no problem with the slider in portfolio 

http://prntscr.com/j68j4o

http://prntscr.com/j68j9n

cindy's picture
cindy
Tue, 04/17/2018 - 23:04

Hi,

In function md_portfolio_load_content, we replace:

$flexs = '<script>Drupal.behaviors.flexslider.attach();</script>';  $content_view = '<div class="cbp-l-project-container">' . $content . $script . /** $flexs . */'</div>';

with:

$flexs = '<script>Drupal.behaviors.flexslider.attach(document, Drupal.settings);</script>';  $content_view = '<div class="cbp-l-project-container">' . $content . $script . $flexs . '</div>';

Check front-end and see no JS error, no blank page

=>slider works correctly now

FrancescoR's picture
FrancescoR
Wed, 04/18/2018 - 04:04

hi Cindy

I saw that there are no more errors of js, but unfortunately, flexslider still does not work.

with firebug I saw that the images are there but they are all with css rules "display: none;"

I assume that the js files when loading the dom do not work properly.

can you tell me how I can solve?

Thank you.

P:S. if it can help, I noticed that in the file js "Drupal.setting" in the <head>, the fexslider setting references are missing.

cindy's picture
cindy
Wed, 04/18/2018 - 23:51

Hi,

We check module flexslider and see that there is extra flexslider attribute for object Drupal.settings in function flexslider_add:

if (!empty($optionset) && !in_array($optionset->name, $cache)) {
$cache[] = $optionset->name;
$js_setting['optionsets'] = array(
$optionset->name => $optionset->options,
);
drupal_add_js(array('flexslider' => $js_setting), 'setting');
}


if (!empty($id)) {
// JavaScript settings
$js_settings = array(
'instances' => array(
$id => $optionset->name,
),
);
// @todo add alter hook for optionset
drupal_add_js(array('flexslider' => $js_settings), 'setting');
}

You need to add flexslider attribute for cho object Drupal.settings in function md_portfolio_load_content.

We transfered value of Drupal.settings.flexslider in page http://www.officina.pg.it/officina-blog/156 then paste => script $flexs in function  md_portfolio_load_content adn the Flexslider works correctly.

Please check the code :

"instances":{
"flexslider-1":"blognode"
}

flexslider-1 is the id of tag <div> wrap flexslider

The slider will not work if id is not flexslider-1

You can check function flexslider_add and set value for flexslider attribute for object Drupal.settings in function md_portfolio_load_content

http://www.officina.pg.it/officina-blog/156

FrancescoR's picture
FrancescoR
Thu, 04/19/2018 - 15:50

WOW is great!! you did it !!

Thanks a lot Cindy

Log in or register to post comments
Have More Idea?

We are here to build your website!

No Universal solution fits all special business requirements. Our experienced team is ready with ideas and state-of-the-art technical solutions to consult the best solution within your budget.