If all you're doing is adding a new option, why not just modify the
existing plugin instead of creating a new plugin?

Something like this should work:

var _init = $.ui.dialog.prototype._init;
$.ui.dialog.prototype._init = function() {
    var self = this;
    _init.apply(this, arguments);
    this.uiDialog.bind('dragstop', function() {
        if (self.options.sticky) {
            // handle actions on drag stop
        }
    });
};

$.ui.dialog.deafults.sticky = true;


On Jun 24, 6:58 am, Marv <[email protected]> wrote:
> Having fun writing my first plugin (isrDialog) which simply extends
> the jquery.ui.dialog widget to include an option for a boolean
> 'sticky' that when 'true' repositions the dialog on window scroll --
> creating an anchored effect. The dialog can be dragged and when at
> 'dragStop' the position is saved so that it will be anchored at this
> spot during window scroll.
>
>  I obviously supplied an internal dragStop event option to the dialog
> widget, but now if the caller of my plugin wants to supply a dragStop
> option I ignore it. Here are my questions:
>
> 1)  How do I "merge" my dragStop functionality with that of the
> plugin's invoker?
> 2)  Have I gone about implementing this plugin in a "proper way"? Are
> there any "gotchas" to the approach I taken?
>
> Here is the whole plugin's code (40 lines) -- jQuery is great!!!!
>
> ===================================================================================
>
> (function($) {
>     $.fn.isrDialog = function(options) {
>         var defaults = {
>             sticky: true
>         },
>         overrides = {
>             dragStop: function(e, ui) {
>                 if (isSticky(this)) {
>                     var left = Math.floor(ui.position.left) - $
> (window).scrollLeft();
>                     var top = Math.floor(ui.position.top) - $
> (window).scrollTop();
>                     $(this).dialog('option', 'position', [left, top]);
>                 };
>             }
>         },
>         settings = $.extend({}, defaults, options, overrides);
>
>         this.each(function() {
>             if ($(this).is('div')) {
>                 if ($(this).hasClass('ui-dialog-content'))
>                     $(this).dialog(options);
>                 else
>                     $(this).dialog(settings);
>             };
>         });
>         if (window.__isrDialogWindowScrollHandled === undefined) {
>             window.__isrDialogWindowScrollHandled = true;
>             $(window).scroll(function(e) {
>                 $('.ui-dialog-content').each(function() {
>                     if (isSticky(this)) {
>                         var position = $(this).dialog('option',
> 'position');
>                         $(this).dialog('option', 'position',
> position);
>                     };
>                 });
>             });
>         };
>         function isSticky(el) {
>             return $(el).dialog('option', 'sticky') && $(el).dialog
> ('isOpen');
>         };
>     };
>
> })(jQuery);
>
> ======================================================================
>
> Thanks in advance for your time developing a reply!
>
> Marv
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"jQuery UI" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/jquery-ui?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to