themeswitcher onSelect triggers continuously

themeswitcher onSelect triggers continuously

Since the recent hotlinking policy updates on the jquery / jquery-ui domains, I have downloaded a local copy of the themeswitcher code, and I have thus discovered the event handlers.

I thought I'd try implementing the "onSelect" handler by popping up a div similar to a dialog every time the theme is changed with a message: "The new theme has been applied!". It works fine, the problem is it works too much. Even when not selecting anything from the themeswitcher. On every page refresh, or every time I login-logout, or every time I navigate to a new page I get this message box "The new theme has been applied!".

How does the "onSelect" handler work then? It seems to extend beyond the actual theme selection from the widget.

Here is my code:

  1. var options = jQuery.extend({
  2. loadTheme: null,
  3. initialText: 'Switch Theme',
  4. width: 150,
  5. height: 200,
  6. buttonPreText: 'Theme: ',
  7. closeOnSelect: true,
  8. buttonHeight: 14,
  9. cookieName: 'jquery-ui-theme',
  10. onOpen: function(){},
  11. onClose: function(){},
  12. onSelect: function(){ 
  13.       $('<div id="effect" class="ui-widget-content ui-corner-all" style="display:none;position:absolute;height:100px;width:200px;top:50%;margin-top:-50px;left:50%;margin-left:-100px;text-align:center;"><h3 class="ui-widget-header ui-corner-all">Glorioso Message</h3><p>A new theme has been applied.</p></div>').appendTo('body').fadeIn(1000).fadeTo(1000,1).fadeOut(1000,function(){ $(this).remove(); });
  14.     }
  15. }, settings);

EDIT:

I think I see why this is happening, basically towards the end of the themeswitcher code it checks if there is a cookie, and if there is a cookie then it triggers a click on the themeswitcher element with the same theme name as the cookie:
  
  1. if( $.cookie(options.cookieName) || options.loadTheme ){
  2. var themeName = $.cookie(options.cookieName) || options.loadTheme;
  3. switcherpane.find('a:contains('+ themeName +')').trigger('click');
  4. }

Is there any way to avoid the onSelect event from triggering when the click is triggered and not user-generated?
         
    John R. D'Orazio