Hey Marv,
This is looking better. I would pull all of the storing functionality
into storeLocation though:
this.uiDialog
.bind('dragstop resizestart', storeLocation)
.bind('resizestop', ...);
function storeLocation(event, ui) {
if (self.options.sticky) {
self.location = ui.position;
}
}
Does ui.position contain different information for draggable and
resizable? I see you're removing the scroll offset when handling
resizing, but not dragging. I would think they should be consistent,
seems like a bug if they're not.
On Jul 11, 11:26 pm, Marv <[email protected]> wrote:
> Thanks again Scott for your constructive comments! I understand that
> v1.8 should obsolete my need for this widget extension, but I created
> it for two reasons:
>
> 1) to learn how to properly create such an extension since I have
> never created a plugin or widget extension before
>
> 2) I need this functionality right now
>
> Here's my code with your suggestions implemented. I just couldn't get
> the syntax correct for your "You could also just bind to the
> dialogopen
> event in _init. " suggestion. As it turned out having the
> functionality I wanted in the open in the _init instead made more
> sense -- but that's a bit of a cop out since I haven't learned how to
> extend the dialog's open event yet!!!
>
> // This code block extends the uiDialog widget by adding a new boolean
> option 'sticky' which,
> // by default, is set to false. When set to true on a dialog instance,
> it will keep the dialog's
> // position 'anchored' regardless of window scrolling.
>
> /****************** Start of uiDialog widget extension
> ****************/
>
> (function($) {
> var _init = $.ui.dialog.prototype._init;
> $.ui.dialog.prototype._init = function() {
> var self = this;
> _init.apply(this, arguments);
> if (self.options.sticky) {
> self.uiDialog.css('position', 'fixed');
> };
> this.uiDialog
> .bind('dragstop', function(event, ui) {
> if (self.options.sticky)
> storeLocation(ui.position.left,
> ui.position.top);
> })
> .bind('resizestart', function(event, ui) {
> if (self.options.sticky)
> storeLocation(ui.position.left - $
> (window).scrollLeft(),
> ui.position.top - $(window).scrollTop
> ());
> })
> .bind('resizestop', function(event, ui) {
> if (self.options.sticky) {
> self.uiDialog.css({
> 'position': 'fixed',
> 'left': self.location.left,
> 'top': self.location.top
> });
> };
> });
> function storeLocation(_left, _top) {
> self.location = { left: _left, top: _top };
> };
> };
> $.ui.dialog.defaults.sticky = false;})(jQuery);
>
> /***************** End of uiDialog widget extension
> *********************/
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---