Core: Coding standards.

This commit is contained in:
Scott González 2010-07-22 19:26:37 -04:00
parent 59c9f75951
commit 27095ef8e1

61
ui/jquery.ui.core.js vendored
View File

@ -24,7 +24,7 @@ $.extend($.ui, {
// $.ui.plugin is deprecated. Use the proxy pattern instead.
plugin: {
add: function( module, option, set ) {
var proto = $.ui[module].prototype;
var proto = $.ui[ module ].prototype;
for ( var i in set ) {
proto.plugins[ i ] = proto.plugins[ i ] || [];
proto.plugins[ i ].push( [ option, set[ i ] ] );
@ -32,7 +32,9 @@ $.extend($.ui, {
},
call: function( instance, name, args ) {
var set = instance.plugins[ name ];
if(!set || !instance.element[0].parentNode) { return; }
if ( !set || !instance.element[ 0 ].parentNode ) {
return;
}
for ( var i = 0; i < set.length; i++ ) {
if ( instance.options[ set[ i ][ 0 ] ] ) {
@ -43,20 +45,24 @@ $.extend($.ui, {
},
contains: function( a, b ) {
return document.compareDocumentPosition
? a.compareDocumentPosition(b) & 16
: a !== b && a.contains(b);
return document.compareDocumentPosition ?
a.compareDocumentPosition( b ) & 16 :
a !== b && a.contains( b );
},
hasScroll: function( el, a ) {
//If overflow is hidden, the element might have extra content, but the user wants to hide it
if ($(el).css('overflow') == 'hidden') { return false; }
if ( $( el ).css( "overflow" ) === "hidden") {
return false;
}
var scroll = (a && a == 'left') ? 'scrollLeft' : 'scrollTop',
var scroll = ( a && a === "left" ) ? "scrollLeft" : "scrollTop",
has = false;
if (el[scroll] > 0) { return true; }
if ( el[ scroll ] > 0 ) {
return true;
}
// TODO: determine which cases actually cause this to happen
// if the element doesn't have the scroll set, see if it's possible to
@ -117,27 +123,29 @@ $.extend($.ui, {
$.fn.extend({
_focus: $.fn.focus,
focus: function( delay, fn ) {
return typeof delay === 'number'
? this.each(function() {
return typeof delay === "number" ?
this.each(function() {
var elem = this;
setTimeout(function() {
$( elem ).focus();
(fn && fn.call(elem));
if ( fn ) {
fn.call( elem );
}
}, delay );
})
: this._focus.apply(this, arguments);
}) :
this._focus.apply( this, arguments );
},
enableSelection: function() {
return this
.attr('unselectable', 'off')
.css('MozUserSelect', '');
.attr( "unselectable", "off" )
.css( "MozUserSelect", "" );
},
disableSelection: function() {
return this
.attr('unselectable', 'on')
.css('MozUserSelect', 'none');
.attr( "unselectable", "on" )
.css( "MozUserSelect", "none" );
},
scrollParent: function() {
@ -157,7 +165,7 @@ $.fn.extend({
zIndex: function( zIndex ) {
if ( zIndex !== undefined ) {
return this.css('zIndex', zIndex);
return this.css( "zIndex", zIndex );
}
if ( this.length ) {
@ -166,14 +174,13 @@ $.fn.extend({
// Ignore z-index if position is set to a value where z-index is ignored by the browser
// This makes behavior of this function consistent across browsers
// WebKit always returns auto if the element is positioned
position = elem.css('position');
if (position == 'absolute' || position == 'relative' || position == 'fixed')
{
position = elem.css( "position" );
if ( position === "absolute" || position === "relative" || position === "fixed" ) {
// IE returns 0 when zIndex is not specified
// other browsers return a string
// we ignore the case of nested elements with an explicit value of 0
// <div style="z-index: -10;"><div style="z-index: 0;"></div></div>
value = parseInt(elem.css('zIndex'));
value = parseInt( elem.css( "zIndex" ) );
if ( !isNaN( value ) && value != 0 ) {
return value;
}
@ -238,14 +245,14 @@ function visible( element ) {
}).length;
}
$.extend($.expr[':'], {
$.extend( $.expr[ ":" ], {
data: function( elem, i, match ) {
return !!$.data( elem, match[ 3 ] );
},
focusable: function( element ) {
var nodeName = element.nodeName.toLowerCase(),
tabIndex = $.attr(element, 'tabindex');
tabIndex = $.attr( element, "tabindex" );
if ( "area" === nodeName ) {
var map = element.parentNode,
mapName = map.name,
@ -258,7 +265,7 @@ $.extend($.expr[':'], {
}
return ( /input|select|textarea|button|object/.test( nodeName )
? !element.disabled
: 'a' == nodeName
: "a" == nodeName
? element.href || !isNaN( tabIndex )
: !isNaN( tabIndex ))
// the element and all of its ancestors must be visible
@ -266,8 +273,8 @@ $.extend($.expr[':'], {
},
tabbable: function( element ) {
var tabIndex = $.attr(element, 'tabindex');
return (isNaN(tabIndex) || tabIndex >= 0) && $(element).is(':focusable');
var tabIndex = $.attr( element, "tabindex" );
return ( isNaN( tabIndex ) || tabIndex >= 0 ) && $( element ).is( ":focusable" );
}
});