7 Replies - 2544 Views - Last Post: 01 August 2013 - 05:28 PM

#1 StealthRT   User is offline

  • D.I.C Head

Reputation: 2
  • View blog
  • Posts: 96
  • Joined: 29-September 08

Jquery Calling a function within a function

Posted 31 July 2013 - 06:09 PM

Hey all i am trying to find a way to add a call to pause this image slider. Currently it only pauses when you roll you mouse over the image. Once you roll off the image the slide show continues.

The start of the slider code is:
;(function($) {
    $.fn.leanSlider = function(options) {
    
    // Defaults
        var defaults = {
            pauseTime: 4000,
            pauseOnHover: true,
            startSlide: 0,
            directionNav: '',
            directionNavPrevBuilder: '',
            directionNavNextBuilder: '',
            controlNav: '',
            controlNavBuilder: '',
            prevText: 'Prev',
            nextText: 'Next',
            beforeChange: function(){},
            afterChange: function(){},
            afterLoad: function(){}
        };

        var init = function() {

        // Set up pauseOnHover
            if(settings.pauseOnHover && settings.pauseTime && settings.pauseTime > 0){
                slider.hover(
                    function () {
                        clearTimeout(timer);
                    },
                    function () {
                        doTimer();
                    }
                );
            }
       };
       
       //More code here....
   };    
})(jQuery);



I've been trying to call it from a onclick button like so:
    $.fn.init.slider.clearTimeout();



But that just throws an error... What am i missing?

Is This A Good Question/Topic? 0
  • +

Replies To: Jquery Calling a function within a function

#2 andrewsw   User is offline

  • no more Mr Potato Head
  • member icon

Reputation: 6957
  • View blog
  • Posts: 28,696
  • Joined: 12-December 12

Re: Jquery Calling a function within a function

Posted 31 July 2013 - 06:17 PM

Which image slider is it and have you read the documentation for it?
Was This Post Helpful? 0
  • +
  • -

#3 laytonsdad   User is offline

  • I identify as an attack helicopter!
  • member icon

Reputation: 467
  • View blog
  • Posts: 1,998
  • Joined: 30-April 10

Re: Jquery Calling a function within a function

Posted 31 July 2013 - 06:19 PM

You may want to post the error and the remainder of the code.
Was This Post Helpful? 0
  • +
  • -

#4 StealthRT   User is offline

  • D.I.C Head

Reputation: 2
  • View blog
  • Posts: 96
  • Joined: 29-September 08

Re: Jquery Calling a function within a function

Posted 31 July 2013 - 06:24 PM

https://github.com/g...ron/Lean-Slider
Was This Post Helpful? 0
  • +
  • -

#5 laytonsdad   User is offline

  • I identify as an attack helicopter!
  • member icon

Reputation: 467
  • View blog
  • Posts: 1,998
  • Joined: 30-April 10

Re: Jquery Calling a function within a function

Posted 31 July 2013 - 08:53 PM

I do believe that you will need to create a new method for you to stop the timer.

Take a look at the section in this about public functions.
Was This Post Helpful? 0
  • +
  • -

#6 andrewsw   User is offline

  • no more Mr Potato Head
  • member icon

Reputation: 6957
  • View blog
  • Posts: 28,696
  • Joined: 12-December 12

Re: Jquery Calling a function within a function

Posted 01 August 2013 - 01:19 PM

If you really want to tinker with the plug-in then you could try reaching-out (to jQuery) rather than reaching-in (to latch on to a method or object):

        var init = function() {

            $('#someid').click(function () {
                 clearTimeout(timer);
            });

I suggest, however, that it might be worth your time to try and contact the author via their GitHub page.

Another option is to find an equivalent add-in that already has the methods you need available from its API.

This post has been edited by andrewsw: 01 August 2013 - 01:21 PM

Was This Post Helpful? 1
  • +
  • -

#7 andrewsw   User is offline

  • no more Mr Potato Head
  • member icon

Reputation: 6957
  • View blog
  • Posts: 28,696
  • Joined: 12-December 12

Re: Jquery Calling a function within a function

Posted 01 August 2013 - 01:42 PM

I should stress, that I'm not recommending the approach I suggested! :whistling:
Was This Post Helpful? 0
  • +
  • -

#8 StealthRT   User is offline

  • D.I.C Head

Reputation: 2
  • View blog
  • Posts: 96
  • Joined: 29-September 08

Re: Jquery Calling a function within a function

Posted 01 August 2013 - 05:28 PM

Got it
plugin.pause = function() {
    clearTimeout(timer);
}

plugin.resume = function() {
   doTimer();
}

Then you can call those methods from outside the plugin.
var $slider = $('sliderSelectorHere').leanSlider({
    //plugin options here
});

//call pause() and resume() whenever you want; example below
$slider.pause(); //pause slideshow
$slider.resume(); //resume slideshow

This post has been edited by StealthRT: 01 August 2013 - 05:29 PM

Was This Post Helpful? 1
  • +
  • -

Page 1 of 1