JavaScript Java Script Revealing Module Pattern create multiple objects javascript revealing module pattern,javascript revealing pattern,javascript revealing module

I need suggestions about writing better code in Revealing Module Pattern way. I have followed tutorial http://weblogs.asp.net/dwahlin/archive/2011/09/05/creating-multiple-javascript-objects-when-using-the-revealing-module-pattern.aspx which help me a lot to understand basics of this pattern. I am trying to create basic image slider. Please check jsfiddle link,

http://jsfiddle.net/sWtDf/

var Slider = window.Slider = window.Slider || {};

    Slider = (function($){

        var $reelWrap = $('.fnSlider'),
            $reel = $('.fnSlider').children('ul'),
            $slide = $reel.children('li'),
            slideWidth = $slide.width(),
            numSlides = $slide.length,                
            reelWidth = numSlides*slideWidth,
            $prev = $('.prev'),
            $next = $('.next'),

            init = function(){   
                pageLoad();               
                nextSlide();
                prevSlide();
            },

            pageLoad = function(){
                var index = 2;                                  
                $reel.css('width', reelWidth);
                $slide.eq(index).addClass('fnActive');     
                $reel.css('left', -(index*slideWidth));
            }

            nextSlide = function(){ 

                $next.click(function(e){
                    e.preventDefault();

                    var index = $reel.children('.fnActive').index() + 1;
                    var scroll = index * slideWidth;

                    if(index < numSlides){
                        $reel.animate({left: -(scroll)}).children().removeClass('fnActive');
                        $slide.eq(index).addClass('fnActive');
                    }else{
                       $reel.animate({left: 0}).children().removeClass('fnActive'); 
                       $slide.eq(0).addClass('fnActive');
                    }

                });

            },

            prevSlide = function(){ 

                $prev.click(function(e){
                    e.preventDefault();

                    var index = $reel.children('.fnActive').index() - 1;
                    var scroll = index * slideWidth;
                    var lastScroll = (numSlides-1) * slideWidth;

                    if(index == "-1"){
                         $reel.animate({left: -(lastScroll)}).children().removeClass('fnActive');
                         $slide.eq(-1).addClass('fnActive');
                    }else{
                        $reel.animate({left: -(scroll)}).children().removeClass('fnActive');
                        $slide.eq(index).addClass('fnActive');  
                    }

                });

            }

            return {
                init: init
            }


    })(jQuery);

    $(function(){

        Slider.init();

    });

What I want to know is -

1) is there better way to write same carousel functionality after code review

2) how to create multiple objects (instances) I tried -

        var slider1, slider2;

        slider1 = Slider();
        slider2 = Slider();

        slider1.init();
        slider2.init();

which causes error TypeError: Slider is not a function

3) is it a correct way to keep global and private functions

4) suggestios if any

Thanks for your time going through this :)

Answer:1

I need to use addEventListener for automatically updating the values typed into different input text (actually 4 input tags) Here's the HTML code : <td class="col-md-4"> <label for="...

I need to use addEventListener for automatically updating the values typed into different input text (actually 4 input tags) Here's the HTML code : <td class="col-md-4"> <label for="...

  1. javascript addeventlistener with parameters
  2. javascript addeventlistener with this
  3. javascript addeventlistener with event
  4. javascript addeventlistener with params
  5. js addeventlistener with parameter
  6. js addeventlistener with this
  7. js addeventlistener with param
  8. js addeventlistener with arguments
  9. javascript addeventlistener to class
  10. javascript addeventlistener to dynamically created element
  11. javascript addeventlistener to multiple elements
  12. javascript addeventlistener to element
  13. javascript addeventlistener to button
  14. javascript addeventlistener to div
  15. javascript addeventlistener to all elements
  16. javascript addeventlistener to all buttons
  17. javascript addeventlistener to object
  18. javascript addeventlistener in loop
  19. javascript addeventlistener to input
  20. javascript addeventlistener to list of elements

I've got an event listener in my Collection which listens for the 'add' event, which only seems to fire when the sample data I add in my router is added, but not when I add more models in my view, the ...

I've got an event listener in my Collection which listens for the 'add' event, which only seems to fire when the sample data I add in my router is added, but not when I add more models in my view, the ...

  1. backbone collection fetch
  2. backbone collection reset
  3. backbone collection add
  4. backbone collection filter
  5. backbone collection sort
  6. backbone collection events
  7. backbone collection each
  8. backbone collection set
  9. backbone collection get
  10. backbone collection comparator
  11. backbone collection length
  12. backbone collection to array
  13. backbone collection find by id
  14. backbone collection save
  15. backbone collection extend
  16. backbone collection foreach
  17. backbone collection parse
  18. backbone collection remove
  19. backbone collection where
  20. backbone collection first

I need to open a .html file upon password being entered correctly, the file is in the same folder. I have gotten most of it to work but it now says that my password function is not a function. Any ...

I need to open a .html file upon password being entered correctly, the file is in the same folder. I have gotten most of it to work but it now says that my password function is not a function. Any ...

  1. javascript password check
  2. javascript password check strength
  3. javascript password check regex
  4. javascript check password match
  5. javascript check password complexity
  6. javascript check password length
  7. javascript check password for special characters
  8. javascript check password equal
  9. javascript check password letters numbers
  10. javascript check password input
  11. javascript check password validation
  12. javascript check password while typing
  13. javascript check password characters
  14. javascript check password format
  15. javascript check password fields match
  16. javascript check password pattern
  17. javascript check password field
  18. javascript check password values
  19. javascript password confirmation check
  20. javascript password policy check

I have a web design question that I'm trying to puzzle out. Essentially I'm looking to design a navbar such that it will change what buttons/links are displayed in the navbar based on what type of ...

I have a web design question that I'm trying to puzzle out. Essentially I'm looking to design a navbar such that it will change what buttons/links are displayed in the navbar based on what type of ...