new to this... how to call a method in a method (solved)

new to this... how to call a method in a method (solved)

hi

i have problem understanding how i can call moveItems.

i traid  this:

this.moveItems;      
$(this).moveItems;     
methods.moveItems;  
methods.moveItems;
videoribbon.moveItems;

this works.. but that's a bad one i think
$(this).videoribbon('moveItems');


  1. (function( $ ) {

  2. var methods = {
  3.         init : function(options) {

  4. $('#ribbon ul li').find('video').on('ended', function(event)
  5. {
  6. //$("#ribbon ul").moveItems();
  7. //methods.moveItems;
  8. //videoribbon.moveItems;
  9. //$(this).videoribbon('moveItems');

  10. $('#ribbon ul li').find('video').get(1).play();

  11. });
  12.         },


  13.         moveItems : function( ) {

  14. alert('test');             
  15.                                 
  16.         },



  17.     };

  18.     $.fn.videoribbon = function(methodOrOptions) {
  19.         if ( methods[methodOrOptions] ) {
  20.             return methods[ methodOrOptions ].apply( this, Array.prototype.slice.call( arguments, 1 ));
  21.         } else if ( typeof methodOrOptions === 'object' || ! methodOrOptions ) {
  22.             // Default to "init"
  23.             return methods.init.apply( this, arguments );
  24.         } else {
  25.             $.error( 'Method ' +  method + ' does not exist on jQuery.videoribbon' );
  26.         }    
  27.     };




  28. })( jQuery );

solution:



  1. (function( $ ) {

  2. var methods = {
  3.         init : function(options) {
  4.             $objectc = $(this);

  5. $('#ribbon ul li').find('video').on('ended', function(event)
  6. {
  7. //$("#ribbon ul").moveItems();
  8. //methods.moveItems;
  9. //videoribbon.moveItems;
  10. //$(this).videoribbon('moveItems');

    methods.moveItems($objectc);


  11. $('#ribbon ul li').find('video').get(1).play();

  12. });
  13.         },


  14.         moveItems : function($objectp) { 
  15. $objectp.dosometthing
  16. alert('test');             
  17.                                 
  18.         },



  19.     };

  20.     $.fn.videoribbon = function(methodOrOptions) {
  21.         if ( methods[methodOrOptions] ) {
  22.             return methods[ methodOrOptions ].apply( this, Array.prototype.slice.call( arguments, 1 ));
  23.         } else if ( typeof methodOrOptions === 'object' || ! methodOrOptions ) {
  24.             // Default to "init"
  25.             return methods.init.apply( this, arguments );
  26.         } 
  27.     };




  28. })( jQuery );

a other solution

  1. (function( $ ) {

  2. var methods = {
  3.         init : function(options) {
  4.              $objectc = $(this);

  5. $('#ribbon ul li').find('video').on('ended', function(event)
  6. {
  7. //$("#ribbon ul").moveItems();
  8. //methods.moveItems;
  9. //videoribbon.moveItems;
  10. //$(this).videoribbon('moveItems');

    $.fn.videoribbon.moveItems();


  11. $('#ribbon ul li').find('video').get(1).play();

  12. });
  13.         },


  14.         



  15.     };


  16. $.fn.videoribbon.moveItems = function(){

    return $objectc.dosomething

    }


















  17.     $.fn.videoribbon = function(methodOrOptions) {
  18.         if ( methods[methodOrOptions] ) {
  19.             return methods[ methodOrOptions ].apply( this, Array.prototype.slice.call( arguments, 1 ));
  20.         } else if ( typeof methodOrOptions === 'object' || ! methodOrOptions ) {
  21.             // Default to "init"
  22.             return methods.init.apply( this, arguments );
  23.         } 
  24.     };




  25. })( jQuery );