From aa6fb148540251eb981670643c03602ca6cbbbfe Mon Sep 17 00:00:00 2001 From: Richard Worth Date: Fri, 12 Mar 2010 01:10:57 +0000 Subject: [PATCH] Dialog: quiet JSLint --- ui/jquery.ui.dialog.js | 245 ++++++++++++++++++++++++++--------------- 1 file changed, 155 insertions(+), 90 deletions(-) diff --git a/ui/jquery.ui.dialog.js b/ui/jquery.ui.dialog.js index 7263d2cd5..0291c3da0 100644 --- a/ui/jquery.ui.dialog.js +++ b/ui/jquery.ui.dialog.js @@ -66,8 +66,8 @@ $.widget("ui.dialog", { // setting tabIndex makes the div focusable // setting outline to 0 prevents a border on focus in Mozilla .attr('tabIndex', -1).css('outline', 0).keydown(function(event) { - if (options.closeOnEscape && event.keyCode - && event.keyCode == $.ui.keyCode.ESCAPE) { + if (options.closeOnEscape && event.keyCode && + event.keyCode === $.ui.keyCode.ESCAPE) { self.close(event); event.preventDefault(); @@ -147,13 +147,19 @@ $.widget("ui.dialog", { uiDialogTitlebar.find("*").add(uiDialogTitlebar).disableSelection(); - (options.draggable && $.fn.draggable && self._makeDraggable()); - (options.resizable && $.fn.resizable && self._makeResizable()); + if (options.draggable && $.fn.draggable) { + self._makeDraggable(); + } + if (options.resizable && $.fn.resizable) { + self._makeResizable(); + } self._createButtons(options.buttons); self._isOpen = false; - ($.fn.bgiframe && uiDialog.bgiframe()); + if ($.fn.bgiframe) { + uiDialog.bgiframe(); + } }, _init: function() { if ( this.options.autoOpen ) { @@ -164,7 +170,9 @@ $.widget("ui.dialog", { destroy: function() { var self = this; - (self.overlay && self.overlay.destroy()); + if (self.overlay) { + self.overlay.destroy(); + } self.uiDialog.hide(); self.element .unbind('.dialog') @@ -173,7 +181,9 @@ $.widget("ui.dialog", { .hide().appendTo('body'); self.uiDialog.remove(); - (self.originalTitle && self.element.attr('title', self.originalTitle)); + if (self.originalTitle) { + self.element.attr('title', self.originalTitle); + } return self; }, @@ -183,30 +193,36 @@ $.widget("ui.dialog", { }, close: function(event) { - var self = this; + var self = this, + maxZ; if (false === self._trigger('beforeClose', event)) { return; } - (self.overlay && self.overlay.destroy()); + if (self.overlay) { + self.overlay.destroy(); + } self.uiDialog.unbind('keypress.ui-dialog'); self._isOpen = false; - (self.options.hide - ? self.uiDialog.hide(self.options.hide, function() { + if (self.options.hide) { + self.uiDialog.hide(self.options.hide, function() { self._trigger('close', event); - }) - : self.uiDialog.hide() && self._trigger('close', event)); + }); + } else { + self.uiDialog.hide(); + self._trigger('close', event); + } $.ui.dialog.overlay.resize(); // adjust the maxZ to allow other modal dialogs to continue to work (see #4309) if (self.options.modal) { - var maxZ = 0; + maxZ = 0; $('.ui-dialog').each(function() { - if (this != self.uiDialog[0]) { + if (this !== self.uiDialog[0]) { maxZ = Math.max(maxZ, $(this).css('z-index')); } }); @@ -224,22 +240,27 @@ $.widget("ui.dialog", { // position on open moveToTop: function(force, event) { var self = this, - options = self.options; + options = self.options, + saveScroll; - if ((options.modal && !force) - || (!options.stack && !options.modal)) { + if ((options.modal && !force) || + (!options.stack && !options.modal)) { return self._trigger('focus', event); } if (options.zIndex > $.ui.dialog.maxZ) { $.ui.dialog.maxZ = options.zIndex; } - (self.overlay && self.overlay.$el.css('z-index', $.ui.dialog.overlay.maxZ = ++$.ui.dialog.maxZ)); + if (self.overlay) { + $.ui.dialog.maxZ += 1; + self.overlay.$el.css('z-index', $.ui.dialog.overlay.maxZ = $.ui.dialog.maxZ); + } //Save and then restore scroll since Opera 9.5+ resets when parent z-Index is changed. // http://ui.jquery.com/bugs/ticket/3193 - var saveScroll = { scrollTop: self.element.attr('scrollTop'), scrollLeft: self.element.attr('scrollLeft') }; - self.uiDialog.css('z-index', ++$.ui.dialog.maxZ); + saveScroll = { scrollTop: self.element.attr('scrollTop'), scrollLeft: self.element.attr('scrollLeft') }; + $.ui.dialog.maxZ += 1; + self.uiDialog.css('z-index', $.ui.dialog.maxZ); self.element.attr(saveScroll); self._trigger('focus', event); @@ -254,30 +275,34 @@ $.widget("ui.dialog", { uiDialog = self.uiDialog; self.overlay = options.modal ? new $.ui.dialog.overlay(self) : null; - (uiDialog.next().length && uiDialog.appendTo('body')); + if (uiDialog.next().length) { + uiDialog.appendTo('body'); + } self._size(); self._position(options.position); uiDialog.show(options.show); self.moveToTop(true); // prevent tabbing out of modal dialogs - (options.modal && uiDialog.bind('keypress.ui-dialog', function(event) { - if (event.keyCode != $.ui.keyCode.TAB) { - return; - } - - var tabbables = $(':tabbable', this), - first = tabbables.filter(':first'), - last = tabbables.filter(':last'); - - if (event.target == last[0] && !event.shiftKey) { - first.focus(1); - return false; - } else if (event.target == first[0] && event.shiftKey) { - last.focus(1); - return false; - } - })); + if (options.modal) { + uiDialog.bind('keypress.ui-dialog', function(event) { + if (event.keyCode !== $.ui.keyCode.TAB) { + return; + } + + var tabbables = $(':tabbable', this), + first = tabbables.filter(':first'), + last = tabbables.filter(':last'); + + if (event.target === last[0] && !event.shiftKey) { + first.focus(1); + return false; + } else if (event.target === first[0] && event.shiftKey) { + last.focus(1); + return false; + } + }); + } // set focus to the first tabbable element in the content area or the first button // if there are no tabbable elements, set focus on the dialog itself @@ -307,15 +332,20 @@ $.widget("ui.dialog", { // if we already have a button pane, remove it self.uiDialog.find('.ui-dialog-buttonpane').remove(); - (typeof buttons == 'object' && buttons !== null && - $.each(buttons, function() { return !(hasButtons = true); })); + if (typeof buttons === 'object' && buttons !== null) { + $.each(buttons, function() { + return !(hasButtons = true); + }); + } if (hasButtons) { $.each(buttons, function(name, fn) { var button = $('') .text(name) .click(function() { fn.apply(self.element[0], arguments); }) .appendTo(uiDialogButtonPane); - ($.fn.button && button.button()); + if ($.fn.button) { + button.button(); + } }); uiDialogButtonPane.appendTo(self.uiDialog); } @@ -363,9 +393,10 @@ $.widget("ui.dialog", { // .ui-resizable has position: relative defined in the stylesheet // but dialogs have to use absolute or fixed positioning position = self.uiDialog.css('position'), - resizeHandles = typeof handles == 'string' - ? handles - : 'n,e,s,w,se,sw,ne,nw'; + resizeHandles = (typeof handles === 'string' ? + handles : + 'n,e,s,w,se,sw,ne,nw' + ); function filteredUi(ui) { return { @@ -407,14 +438,17 @@ $.widget("ui.dialog", { _minHeight: function() { var options = this.options; - return (options.height == 'auto' - ? options.minHeight - : Math.min(options.minHeight, options.height)); + if (options.height === 'auto') { + return options.minHeight; + } else { + return Math.min(options.minHeight, options.height); + } }, _position: function(position) { var myAt = [], - offset = [0, 0]; + offset = [0, 0], + isVisible; position = position || $.ui.dialog.prototype.options.position; @@ -422,19 +456,19 @@ $.widget("ui.dialog", { // if (typeof position == 'string' || $.isArray(position)) { // myAt = $.isArray(position) ? position : position.split(' '); - if (typeof position == 'string' || (typeof position == 'object' && '0' in position)) { + if (typeof position === 'string' || (typeof position === 'object' && '0' in position)) { myAt = position.split ? position.split(' ') : [position[0], position[1]]; - if (myAt.length == 1) { + if (myAt.length === 1) { myAt[1] = myAt[0]; } $.each(['left', 'top'], function(i, offsetPosition) { - if (+myAt[i] == myAt[i]) { + if (+myAt[i] === myAt[i]) { offset[i] = myAt[i]; myAt[i] = offsetPosition; } }); - } else if (typeof position == 'object') { + } else if (typeof position === 'object') { if ('left' in position) { myAt[0] = 'left'; offset[0] = position.left; @@ -453,7 +487,7 @@ $.widget("ui.dialog", { } // need to show the dialog to get the actual offset in the position plugin - var isVisible = this.uiDialog.is(':visible'); + isVisible = this.uiDialog.is(':visible'); if (!isVisible) { this.uiDialog.show(); } @@ -505,32 +539,44 @@ $.widget("ui.dialog", { .addClass(uiDialogClasses + value); break; case "disabled": - (value - ? uiDialog.addClass('ui-dialog-disabled') - : uiDialog.removeClass('ui-dialog-disabled')); + if (value) { + uiDialog.addClass('ui-dialog-disabled'); + } else { + uiDialog.removeClass('ui-dialog-disabled'); + } break; case "draggable": - (value - ? self._makeDraggable() - : uiDialog.draggable('destroy')); + if (value) { + self._makeDraggable(); + } else { + uiDialog.draggable('destroy'); + } break; case "height": resize = true; break; case "maxHeight": - (isResizable && uiDialog.resizable('option', 'maxHeight', value)); + if (isResizable) { + uiDialog.resizable('option', 'maxHeight', value); + } resize = true; break; case "maxWidth": - (isResizable && uiDialog.resizable('option', 'maxWidth', value)); + if (isResizable) { + uiDialog.resizable('option', 'maxWidth', value); + } resize = true; break; case "minHeight": - (isResizable && uiDialog.resizable('option', 'minHeight', value)); + if (isResizable) { + uiDialog.resizable('option', 'minHeight', value); + } resize = true; break; case "minWidth": - (isResizable && uiDialog.resizable('option', 'minWidth', value)); + if (isResizable) { + uiDialog.resizable('option', 'minWidth', value); + } resize = true; break; case "position": @@ -538,14 +584,19 @@ $.widget("ui.dialog", { break; case "resizable": // currently resizable, becoming non-resizable - (isResizable && !value && uiDialog.resizable('destroy')); + if (isResizable && !value) { + uiDialog.resizable('destroy'); + } // currently resizable, changing handles - (isResizable && typeof value == 'string' && - uiDialog.resizable('option', 'handles', value)); + if (isResizable && typeof value === 'string') { + uiDialog.resizable('option', 'handles', value); + } // currently non-resizable, becoming resizable - (isResizable || (value !== false && self._makeResizable(value))); + if (!isResizable && value !== false) { + self._makeResizable(value); + } break; case "title": // convert whatever was passed in o a string, for html() to not throw up @@ -557,14 +608,17 @@ $.widget("ui.dialog", { } $.Widget.prototype._setOption.apply(self, arguments); - (resize && self._size()); + if (resize) { + self._size(); + } }, _size: function() { /* If the user has resized the dialog, the .ui-dialog and .ui-dialog-content * divs will both have width and height set, so we need to reset them */ - var options = this.options; + var options = this.options, + nonContentHeight; // reset content sizing // hide for non content measurement because height: 0 doesn't work in IE quirks mode (see #4350) @@ -573,25 +627,25 @@ $.widget("ui.dialog", { // reset wrapper sizing // determine the height of all the non-content elements - var nonContentHeight = this.uiDialog.css({ + nonContentHeight = this.uiDialog.css({ height: 'auto', width: options.width }) .height(); - this.element.css(options.height == 'auto' - ? { - minHeight: Math.max(options.minHeight - nonContentHeight, 0), - height: 'auto' - } - : { - minHeight: 0, - height: Math.max(options.height - nonContentHeight, 0) + this.element + .css(options.height === 'auto' ? { + minHeight: Math.max(options.minHeight - nonContentHeight, 0), + height: 'auto' + } : { + minHeight: 0, + height: Math.max(options.height - nonContentHeight, 0) }) .show(); - (this.uiDialog.is(':data(resizable)') && - this.uiDialog.resizable('option', 'minHeight', this._minHeight())); + if (this.uiDialog.is(':data(resizable)')) { + this.uiDialog.resizable('option', 'minHeight', this._minHeight()); + } } }); @@ -602,7 +656,12 @@ $.extend($.ui.dialog, { maxZ: 0, getTitleId: function($el) { - return 'ui-dialog-title-' + ($el.attr('id') || ++this.uuid); + var id = $el.attr('id'); + if (!id) { + this.uuid += 1; + id = this.uuid; + } + return 'ui-dialog-title-' + id; }, overlay: function(dialog) { @@ -634,8 +693,8 @@ $.extend($.ui.dialog.overlay, { // allow closing by pressing the escape key $(document).bind('keydown.dialog-overlay', function(event) { - if (dialog.options.closeOnEscape && event.keyCode - && event.keyCode == $.ui.keyCode.ESCAPE) { + if (dialog.options.closeOnEscape && event.keyCode && + event.keyCode === $.ui.keyCode.ESCAPE) { dialog.close(event); event.preventDefault(); @@ -653,7 +712,9 @@ $.extend($.ui.dialog.overlay, { height: this.height() }); - ($.fn.bgiframe && $el.bgiframe()); + if ($.fn.bgiframe) { + $el.bgiframe(); + } this.instances.push($el); return $el; @@ -677,13 +738,15 @@ $.extend($.ui.dialog.overlay, { }, height: function() { + var scrollHeight, + offsetHeight; // handle IE 6 if ($.browser.msie && $.browser.version < 7) { - var scrollHeight = Math.max( + scrollHeight = Math.max( document.documentElement.scrollHeight, document.body.scrollHeight ); - var offsetHeight = Math.max( + offsetHeight = Math.max( document.documentElement.offsetHeight, document.body.offsetHeight ); @@ -700,13 +763,15 @@ $.extend($.ui.dialog.overlay, { }, width: function() { + var scrollWidth, + offsetWidth; // handle IE 6 if ($.browser.msie && $.browser.version < 7) { - var scrollWidth = Math.max( + scrollWidth = Math.max( document.documentElement.scrollWidth, document.body.scrollWidth ); - var offsetWidth = Math.max( + offsetWidth = Math.max( document.documentElement.offsetWidth, document.body.offsetWidth ); @@ -752,4 +817,4 @@ $.extend($.ui.dialog.overlay.prototype, { } }); -})(jQuery); +}(jQuery)); -- 2.39.5