code in one plugin accessing features/functions in another plugin ?
well what my title says .. is that possible . i am pritty much almost sure its possible , i don't know if its a common use case , but is it possible ?
I came across an interesting case recently , i was going the source of a simple carousel plugin : unslider.js .
the carousel is a lightweight one , it says the following about adding mobile , touch , swipe support :
If you want to add mobile/touch/swipe/whatever support to Unslider, you’ll need to include the
jQuery.event.swipe
plugin, then it’ll work out the box. Easy! .
now going through the unslider.js code , i came across the following peice of code :
- if ($.event.special['move'] || $.Event('move')) {
- el.on('movestart', function(e) {
- if ((e.distX > e.distY && e.distX < -e.distY) || (e.distX < e.distY && e.distX > -e.distY)) {
- e.preventDefault();
- }else{
- el.data("left", _.ul.offset().left / el.width() * 100);
- }
- }).on('move', function(e) {
- var left = 100 * e.distX / el.width();
- var leftDelta = 100 * e.deltaX / el.width();
- _.ul[0].style.left = parseInt(_.ul[0].style.left.replace("%", ""))+leftDelta+"%";
-
- _.ul.data("left", left);
- }).on('moveend', function(e) {
- var left = _.ul.data("left");
- if (Math.abs(left) > 30){
- var i = left > 0 ? _.i-1 : _.i+1;
- if (i < 0 || i >= len) i = _.i;
- _.to(i);
- }else{
- _.to(_.i);
- }
- });
- };
-
- return _;
- };
now is that peice code interacting with the functionality of an external plugin ?? i mean Jquery.event.swipe.js ?? also i guess since both are separate plugins and they have thier code enclosed within themselves , , how does the functionality of Jquery.event.swipe.js become available to unslider.js ??
also if i don't load Jquery.event.swipe.js in the script tags before unslider.js , is the above peice of code rendered usless ??
Thank you.
gautam.