Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Jul 18th, 2012  |  syntax: None  |  size: 1.53 KB  |  hits: 8  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. How to access 'this' inside my custom JQuery Widget callback
  2. (function ($, undefined) {
  3. $.widget('custom.MyCarousel', {
  4.    options: {
  5.         noOfVisibleItems: 2
  6.         },
  7.    _init: function () { this.BindCarosuel(); },
  8.    BindCarosuel: function () {
  9.    jQuery(this.element).jcarousel({
  10.         size: this.options.noOfVisibleItems.length,
  11.         itemLoadCallback: { this.mycarousel_itemLoadCallback }
  12.  
  13.         });
  14.    },
  15.    MyWidgetCustomMethod: function (index) {
  16.    },
  17.    mycarousel_itemLoadCallback: function (carousel, state) {
  18.         // How to get access to options object (noOfVisibleItems)
  19.         // and methods like MyWidgetCustomMethod ?
  20.    }
  21.    }
  22. )
  23. } (jQuery));
  24.        
  25. $(this)[0]
  26. or
  27. this[0]
  28.        
  29. (function ($, undefined)
  30. {
  31.     $.widget('custom.MyCarousel',
  32.     {
  33.         me: this,
  34.  
  35.         options: {
  36.             noOfVisibleItems: 2
  37.         },
  38.  
  39.         _init: function () { this.BindCarosuel(); },
  40.  
  41.         BindCarosuel: function ()
  42.         {
  43.             jQuery(this.element).jcarousel({
  44.                 size: this.options.noOfVisibleItems.length,
  45.                 itemLoadCallback: { this.mycarousel_itemLoadCallback }
  46.  
  47.             });
  48.         },
  49.  
  50.         MyWidgetCustomMethod: function (index) {
  51.  
  52.         },
  53.  
  54.         mycarousel_itemLoadCallback: function (carousel, state) {
  55.             // How to get access to options object (noOfVisibleItems)
  56.             // and methods like MyWidgetCustomMethod ?
  57.  
  58.             alert(me.options.noOfVisibileItems);
  59.         }
  60.     })
  61. }(jQuery));
  62.        
  63. itemLoadCallback: { $.proxy(Self.mycarousel_itemLoadCallback, this) }