In an attempt to make a swipe-able slideshow for many images, I am attempting to stitch together two plugins, Swipe.js and lazyloader.js. I want to have the slideshow timer event from the Swipe plugin call the update function inside of Lazyloader. From researching, it seems my problem appears to be one of namespace; that is, Swipe doesn't know about the stuff inside Lazyloader, and therefore cannot call the function.
- Given the following code, am I understanding my problem correctly?
- If so, how can I get Swipe to access Lazyloader's functions?
Thank you.
FOLLOW UP: After Q&A with Cheeso, I see now that I was asking the wrong question in regard to what I ultimately needed to happen. I add this comment to avoid having any future readers getting confused because of my bad question. This is not about namespace or even about accessing a private function, which shouldn't be done. This thread is utimately about how inadvisable it may be to try and frankenstein libraries together if you don't really know what you're doing. ; ) END FOLLOW UP
The callback in swipe.js:
this.callback = this.options.callback || function() {
the script called inside the html:
<script src="js/jquery.js" type="text/javascript"></script>
<script src="js/jquery.lazyload.js" type="text/javascript"></script>
<script src='js/swipe.js' type="text/javascript"></script>
<script type="text/javascript">$(document).ready(function() {
function myAlert(){
//call a function from inside jquery.lazyload.js
alertMe();
}
//instantiate a swipe object and pass in a bunch of
//options, especially "callback" which fires on every slide change
window.mySwipe = new Swipe(document.getElementById('slider1'), {
startSlide: 0,
speed: 1000,
auto: 5000,
callback: function(){
myAlert();
}
});
// run lazyload on every VISIBLE image with the class "lazy" on load, and on every click
$("img.lazy").lazyload({event: "click", effect : "fadeIn", threshold: 0,});
});
</script>
jquery.lazyloader.js:
//outside of the container below, I can be called by myAlert()
function alertMe() {
alert("it worked!");
}
(function($, window) {
$window = $(window);
$.fn.lazyload = function(options) {
///
///Here be a bunch of lazyloader stuff
///
//I work when above, but once I am inside this container, I cannot be called by myAlert(),
//and I will error as 'not a valid function'
function alertMe() {
alert("it worked! Even inside of this container! ");
}
})(jQuery, window);