I seem to be getting this error(Uncaught TypeError: Cannot read property 'instances' of undefined) after adding flexslider_add(); to my template.php under themename_preprocess_page.
I seem to get this js error when I have a manually added flexslider instance in my theme WITHOUT any drupal flexslider module created flexslider instances.
For example, my site has a global header that contains a flexslider instance that is manually created in my themes javascript.
- On the homepage that instance is the only flexslider on the page. This page shows the error.
- On another page I have a TWO instances of flexslider. One comes from my global header that is manually created in my themes javascript and the other is created using the Drupal flexslider module. This page shows NO errors.
When I get this error the flexsliders still work, but it breaks other javascript from functioning. Example panels in place editor or ajax requests.
See attached image for the screenshot of the error.
Let me know if I can provide any more information to help
| Comment | File | Size | Author |
|---|---|---|---|
| #1 | Screenshot_3_10_13_12_33_AM.jpg | 103.25 KB | gmclelland |
Comments
Comment #1
gmclelland commentedSorry, I forgot the screenshot. Here you go.
Comment #2
minoroffense commentedHmm, I'll have to rethink how I check for flexslider instances. That should be populated with the list of flexsliders on the page but if you just use the library directly it makes sense that would be empty.
Maybe I can make it so that javascript isn't loaded when being called manually...
Comment #3
gmclelland commentedHmm.., I thought maybe I could use
drupal_add_library('flexslider', 'flexslider', TRUE);in my template.php preprocess_page, but that didn't work because the flexslider module doesn't include a hook_library.Maybe the flexslider module should declare a flexslider_library sort of like how Drupal core's system module declares the jqueryui libraries. Then the flexslider module inside of flexslider_add() could use drupal_add_library instead of drupal_add_js?
Then themes could load just the flexslider library with drupal_add_library to only load the flexslider library. If they wanted optionsets configured with flexslider, then they could use flexslider_add(id, optionset);
Just thinking out loud... I'm not sure, maybe this is possible, maybe not?
Anyways, thank you for responding.
Comment #4
gmclelland commentedOk, it looks like I can simply use libraries_load('flexslider'); in my template.php to load just the flexslider js library.
hook_library only works with non-external libraries. Disregard my last comment. I see now how everything in the module works.
So I guess you can marked this as issue as closed (works as designed) or you change the api docs to recommend using libraries_load('flexslider'); when you just want the library itself.
Thanks again
Comment #5
minoroffense commentedThere's another issue in the queue to restore the old hook_library functionality. There's a patch there.
I do want to switch to using libraries_load for the core functionality but I do want to continue to support core library hooks. I though hook_libraries_info would automatically define the core hook_library for me. Turns out no.
I'll close this as duplicate as the other issue should fix any warnings here.
#1929696: drupal_add_library('flexslider', 'flexslider') no longer works.
Comment #6
alexkb commentedIf anyone else comes across something like this, or the javascript error
Double check to make sure your flexslider default settings are set correctly. We had them exported to a feature, and somehow I had overridden them to be empty. When I reverted them, it all started working again for my custom rendered flexslider slideshow.