Posted by Adam S on May 16, 2012 at 1:56am
14 followers
| Project: | Flex Slider |
| Version: | 7.x-1.x-dev |
| Component: | Code |
| Category: | feature request |
| Priority: | normal |
| Assigned: | Unassigned |
| Status: | needs review |
Issue Summary
There is a form for configuring options for the flexslider. It would be great if it allowed for adding callback functions. Is there a way to override the ctools plugin? Or, does the module need a patch to accomplish that?
Comments
#1
What kind of callback are you looking for? Do you mean in javascript when certain actions occur in the slideshow? Or a hook of some kind in PHP to act on something?
#2
There are 4 callback functions in flexslider configuration:
start: function(){}, //Callback: function(slider) - Fires when the slider loads the first slide
before: function(){}, //Callback: function(slider) - Fires asynchronously with each slider animation
after: function(){}, //Callback: function(slider) - Fires after each slider animation completes
end: function(){} //Callback: function(slider) - Fires when the slider reaches the last slide
but you can't setup it in current release unless you hack the module. It would be nice if I can add js file with callback functions to theme, and then specify functions names in configuration set admin/config/media/flexslider/edit/set_name
#3
They are js functions that come standard with flexslider... any plans to integrate them?
#4
I'm a little hesitant adding a set of text areas where a user can enter arbitrary javascript to be executed.
I'll give it some thought, see how I might be able to get this in.
#5
I was just wondering if there was a way to do this in code? I'm sure there is a way but I couldn't figure it out.
#6
I was also looking for more than a month a way to use the after callback function, and right now I have just got it working. I'm using Flexslider Views Slideshow module for creating the sliders.
I edited the file flexslider/flexslider_views_slideshow/js/flexslider_views_slideshow.js in this file you can find all the current options, I added the after callback. In that file there is a variable called fullId which can be used to know which code to add to each slider:
...manualControls:settings.manualcontrols,
start: function(slider) {
flexslider_views_slideshow_register(fullId, slider);
},
after: function(slider){
if(fullId == "#slider1"){
// some code
}
else{
// other code
}
}
...
this worked for me very well,
hope this can help you,
Eduardo
#7
I made a patch which adds callbacks settings to optionset.
#8
#9
Has there been any update to this? I tried running the patch in #7, which gave me the options in the drupal interface, but as far as I could tell, they didn't actually work
#10
We can't add the callbacks to the UI. The function drupal_json_encode takes any javascript and converts it to a string value. Which means the browser won't treat the text as "code" and you'll get errors.
If you want to use the callbacks, you'll have to use the library the old fashioned way. I'm keeping my eye on a module which offers a replacement for the default drupal_json_encode function which allows "code" text to be sent, but it's got some show-stopping issues at the moment.
#11
Why don't you forward the events to the dom container so one can delegate multiple event handlers to it from anywhere?
I changed my flexslider.load.js in this way:
var optionset = settings.flexslider.optionsets[settings.flexslider.instances[id]];to
var optionset = settings.flexslider.optionsets[settings.flexslider.instances[id]];optionset = $.extend(optionset || {}, {
before: function(slider) {
slider.trigger('before');
},
after: function(slider) {
slider.trigger('after');
}
});
and then use:
$('.flexslider').on('after', function () {}
You could also add the flexslider object as parameter.
I know this might not be the best implementation on my side, but i think you get the idea.
#12
I think a configurable UI might be too complicated, but #11 is a good solution for anyone want to implement it in code.
Can we get it committed?
#13
convert #11 to a patch
#14
There's no means of rendering the js from a text area in drupal to the browser (filters automatically kill that option).
But I do want to implement something like what you've done in that patch. Reading this post from lullabot http://www.lullabot.com/articles/your-javascript-should-expose-apis-too I just need time/feedback on which technique would work best.
Btw, I don't think we can use the
.onmethod with jquery 1.4.4. But I could be wrong.#15
it looks like you can catch the event using .on() after jQuery 1.7 (that's the way the official jQuery doc uses), but before that you can use .bind() to catch an event (that's the way done in the lullabot article).
In both case the event can be send by .trigger(), so I don't think it's a problem to put the trigger function in here, it's added since jQuery 1.0 with the ability to trigger default javascript events, and in 1.3 you can trigger custom events.
#16
The views slideshow cycle module allows you to enter js code for callbacks via the slideshow display setting in the views configuration. - However I believe it only lets you add, not edit, so to edit a snippet you have to remove it and re-enter it.
Having said that, I am also not a fan of the idea of entering code snippets into the database via the UI.
It introduces a possible world of pain.
I would love a solution where I can just integrate via javascript in a module or theme, either like #13 or like #14.
#17
New version of patch in #13.
Also supports the views slideshow implementation.
Use bind() instead of on() with the default drupal jQuery, as mentioned in #14.
#18
rooby, exactly what i was thinking.
agree with minorOffense, providing events to act on makes this easily extensible.
keep js out of text inputs.
maybe the events should be more uniquely identified though, a preface of "flexslider_" ought to do the job
#19
I've implemented the patch from #17, working great!
#20
Any chance this patch could be re-rolled for 7.x-2.x-dev version. Thanks in advance