Reputation: 909
I have a JavaScript file with jQuery.pep (Drag and Drop jQuery plugin). I'm starting the plugin With this code:
Drag.pep();
Now, I don't know how to disable/stop it. Here is a code section from the file: jquery.pep.js
. I think it might help you to answer:
$[pluginName] = {
stopAll: function () {
disable = true;
return this;
},
startAll: function () {
disable = false;
return this;
}
};
The Variable "pluginName" is "pep". Here is the full jQuery pep code (github):
Please help.
Thank you!
Upvotes: 0
Views: 470
Reputation: 14434
that should probably do it:
$.pep.stopAll(); // stops all peps
edit:
in the code there is a function which could be called on an instance object:
Pep.prototype.forceStop = function(){
$(this.el).trigger( this._endTrigger );
};
the instance is built here and saved into the data-attribute:
// A really lightweight plugin wrapper around the constructor,
// preventing against multiple instantiations
$.fn[pluginName] = function ( options ) {
return this.each(function () {
if (!$.data(this, 'plugin_' + pluginName)) {
$.data(this, 'plugin_' + pluginName, new Pep( this, options ));
}
});
};
$('your-selector').data('plugin_pep').forceStop();
i tried to do that, it called the forceStop method, but it did not end up doing that. i researched and think what it does is to stop an animation which is currently in progress.
what you could do now is to override the drag-method which could be given with the options when you need it, and immediatly force the stop when the animation is triggered.
i do not like that much, but as i see the code right now, i dont see any chance of doing it another way (docs are missing here ;-()
this should work:
var myPep = $('your-selector').data('plugin_pep');
myPep.options.drag = function(ev, obj) {
obj.forceStop();
};
edit2: if you want to make it draggable again, just override the function again with an empty function:
myPep.options.drag = function() {};
Upvotes: 3