Skip to content

Commit

Permalink
replace self with that
Browse files Browse the repository at this point in the history
  • Loading branch information
David Murdoch committed May 17, 2011
1 parent 1bd139a commit 1d530a1
Show file tree
Hide file tree
Showing 16 changed files with 488 additions and 489 deletions.
56 changes: 28 additions & 28 deletions ui/jquery.ui.accordion.js
Expand Up @@ -33,20 +33,20 @@ $.widget( "ui.accordion", {
},

_create: function() {
var self = this,
options = self.options;
var that = this,
options = that.options;

self.running = false;
that.running = false;

self.element.addClass( "ui-accordion ui-widget ui-helper-reset" );
that.element.addClass( "ui-accordion ui-widget ui-helper-reset" );

self.headers = self.element.find( options.header )
that.headers = that.element.find( options.header )
.addClass( "ui-accordion-header ui-helper-reset ui-state-default ui-corner-all" );
self._hoverable( self.headers );
self._focusable( self.headers );
self.headers.find( ":first-child" ).addClass( "ui-accordion-heading" );
that._hoverable( that.headers );
that._focusable( that.headers );
that.headers.find( ":first-child" ).addClass( "ui-accordion-heading" );

self.headers.next()
that.headers.next()
.addClass( "ui-accordion-content ui-helper-reset ui-widget-content ui-corner-bottom" );

// don't allow collapsible: false and active: false
Expand All @@ -57,26 +57,26 @@ $.widget( "ui.accordion", {
if ( options.active < 0 ) {
options.active += this.headers.length;
}
self.active = self._findActive( options.active )
that.active = that._findActive( options.active )
.addClass( "ui-state-default ui-state-active" )
.toggleClass( "ui-corner-all" )
.toggleClass( "ui-corner-top" );
self.active.next().addClass( "ui-accordion-content-active" );
that.active.next().addClass( "ui-accordion-content-active" );

self._createIcons();
self.refresh();
that._createIcons();
that.refresh();

// ARIA
self.element.attr( "role", "tablist" );
that.element.attr( "role", "tablist" );

self.headers
that.headers
.attr( "role", "tab" )
.bind( "keydown.accordion", $.proxy( self, "_keydown" ) )
.bind( "keydown.accordion", $.proxy( that, "_keydown" ) )
.next()
.attr( "role", "tabpanel" );

self.headers
.not( self.active )
that.headers
.not( that.active )
.attr({
"aria-expanded": "false",
"aria-selected": "false",
Expand All @@ -86,10 +86,10 @@ $.widget( "ui.accordion", {
.hide();

// make sure at least one header is in the tab order
if ( !self.active.length ) {
self.headers.eq( 0 ).attr( "tabIndex", 0 );
if ( !that.active.length ) {
that.headers.eq( 0 ).attr( "tabIndex", 0 );
} else {
self.active
that.active
.attr({
"aria-expanded": "true",
"aria-selected": "true",
Expand All @@ -99,7 +99,7 @@ $.widget( "ui.accordion", {

// only need links in tab order for Safari
if ( !$.browser.safari ) {
self.headers.find( "a" ).attr( "tabIndex", -1 );
that.headers.find( "a" ).attr( "tabIndex", -1 );
}

this._setupEvents( options.event );
Expand Down Expand Up @@ -355,14 +355,14 @@ $.widget( "ui.accordion", {
},

_toggle: function( data ) {
var self = this,
options = self.options,
var that = this,
options = that.options,
toShow = data.newContent,
toHide = data.oldContent;

self.running = true;
that.running = true;
function complete() {
self._completed( data );
that._completed( data );
}

if ( options.animated ) {
Expand Down Expand Up @@ -549,7 +549,7 @@ if ( $.uiBackCompat !== false ) {
var _create = prototype._create;
prototype._create = function() {
if ( this.options.navigation ) {
var self = this,
var that = this,
headers = this.element.find( this.options.header ),
content = headers.next(),
current = headers.add( content )
Expand All @@ -559,7 +559,7 @@ if ( $.uiBackCompat !== false ) {
if ( current ) {
headers.add( content ).each( function( index ) {
if ( $.contains( this, current ) ) {
self.options.active = Math.floor( index / 2 );
that.options.active = Math.floor( index / 2 );
return false;
}
});
Expand Down
112 changes: 56 additions & 56 deletions ui/jquery.ui.autocomplete.js
Expand Up @@ -45,7 +45,7 @@ $.widget( "ui.autocomplete", {
pending: 0,

_create: function() {
var self = this,
var that = this,
doc = this.element[ 0 ].ownerDocument,
suppressKeyPress;

Expand All @@ -61,7 +61,7 @@ $.widget( "ui.autocomplete", {
"aria-haspopup": "true"
})
.bind( "keydown.autocomplete", function( event ) {
if ( self.options.disabled || self.element.attr( "readonly" ) ) {
if ( that.options.disabled || that.element.attr( "readonly" ) ) {
suppressKeyPress = true;
return;
}
Expand All @@ -71,54 +71,54 @@ $.widget( "ui.autocomplete", {
switch( event.keyCode ) {
case keyCode.PAGE_UP:
suppressKeyPress = true;
self._move( "previousPage", event );
that._move( "previousPage", event );
break;
case keyCode.PAGE_DOWN:
suppressKeyPress = true;
self._move( "nextPage", event );
that._move( "nextPage", event );
break;
case keyCode.UP:
suppressKeyPress = true;
self._move( "previous", event );
that._move( "previous", event );
// prevent moving cursor to beginning of text field in some browsers
event.preventDefault();
break;
case keyCode.DOWN:
suppressKeyPress = true;
self._move( "next", event );
that._move( "next", event );
// prevent moving cursor to end of text field in some browsers
event.preventDefault();
break;
case keyCode.ENTER:
case keyCode.NUMPAD_ENTER:
// when menu is open and has focus
if ( self.menu.active ) {
if ( that.menu.active ) {
// #6055 - Opera still allows the keypress to occur
// which causes forms to submit
suppressKeyPress = true;
event.preventDefault();
}
//passthrough - ENTER and TAB both select the current element
case keyCode.TAB:
if ( !self.menu.active ) {
if ( !that.menu.active ) {
return;
}
self.menu.select( event );
that.menu.select( event );
break;
case keyCode.ESCAPE:
self._value( self.term );
self.close( event );
that._value( that.term );
that.close( event );
break;
default:
// keypress is triggered before the input value is changed
clearTimeout( self.searching );
self.searching = setTimeout(function() {
clearTimeout( that.searching );
that.searching = setTimeout(function() {
// only search if the value has changed
if ( self.term != self._value() ) {
self.selectedItem = null;
self.search( null, event );
if ( that.term != that._value() ) {
that.selectedItem = null;
that.search( null, event );
}
}, self.options.delay );
}, that.options.delay );
break;
}
})
Expand All @@ -133,46 +133,46 @@ $.widget( "ui.autocomplete", {
var keyCode = $.ui.keyCode;
switch( event.keyCode ) {
case keyCode.PAGE_UP:
self._move( "previousPage", event );
that._move( "previousPage", event );
break;
case keyCode.PAGE_DOWN:
self._move( "nextPage", event );
that._move( "nextPage", event );
break;
case keyCode.UP:
self._move( "previous", event );
that._move( "previous", event );
// prevent moving cursor to beginning of text field in some browsers
event.preventDefault();
break;
case keyCode.DOWN:
self._move( "next", event );
that._move( "next", event );
// prevent moving cursor to end of text field in some browsers
event.preventDefault();
break;
}
})
.bind( "focus.autocomplete", function() {
if ( self.options.disabled ) {
if ( that.options.disabled ) {
return;
}

self.selectedItem = null;
self.previous = self._value();
that.selectedItem = null;
that.previous = that._value();
})
.bind( "blur.autocomplete", function( event ) {
if ( self.options.disabled ) {
if ( that.options.disabled ) {
return;
}

clearTimeout( self.searching );
clearTimeout( that.searching );
// clicks on the menu (or a button to trigger a search) will cause a blur event
self.closing = setTimeout(function() {
self.close( event );
self._change( event );
that.closing = setTimeout(function() {
that.close( event );
that._change( event );
}, 150 );
});
this._initSource();
this.response = function() {
return self._response.apply( self, arguments );
return that._response.apply( that, arguments );
};
this.menu = $( "<ul></ul>" )
.addClass( "ui-autocomplete" )
Expand All @@ -183,69 +183,69 @@ $.widget( "ui.autocomplete", {
// but we can't detect a mouseup or a click immediately afterward
// so we have to track the next mousedown and close the menu if
// the user clicks somewhere outside of the autocomplete
var menuElement = self.menu.element[ 0 ];
var menuElement = that.menu.element[ 0 ];
if ( !$( event.target ).closest( ".ui-menu-item" ).length ) {
setTimeout(function() {
$( document ).one( 'mousedown', function( event ) {
if ( event.target !== self.element[ 0 ] &&
if ( event.target !== that.element[ 0 ] &&
event.target !== menuElement &&
!$.contains( menuElement, event.target ) ) {
self.close();
that.close();
}
});
}, 1 );
}

// use another timeout to make sure the blur-event-handler on the input was already triggered
setTimeout(function() {
clearTimeout( self.closing );
clearTimeout( that.closing );
}, 13);
})
.menu({
// custom key handling for now
input: $(),
focus: function( event, ui ) {
var item = ui.item.data( "item.autocomplete" );
if ( false !== self._trigger( "focus", event, { item: item } ) ) {
if ( false !== that._trigger( "focus", event, { item: item } ) ) {
// use value to match what will end up in the input, if it was a key event
if ( /^key/.test(event.originalEvent.type) ) {
self._value( item.value );
that._value( item.value );
}
}
},
select: function( event, ui ) {
var item = ui.item.data( "item.autocomplete" ),
previous = self.previous;
previous = that.previous;

// only trigger when focus was lost (click on menu)
if ( self.element[0] !== doc.activeElement ) {
self.element.focus();
self.previous = previous;
if ( that.element[0] !== doc.activeElement ) {
that.element.focus();
that.previous = previous;
// #6109 - IE triggers two focus events and the second
// is asynchronous, so we need to reset the previous
// term synchronously and asynchronously :-(
setTimeout(function() {
self.previous = previous;
self.selectedItem = item;
that.previous = previous;
that.selectedItem = item;
}, 1);
}

if ( false !== self._trigger( "select", event, { item: item } ) ) {
self._value( item.value );
if ( false !== that._trigger( "select", event, { item: item } ) ) {
that._value( item.value );
}
// reset the term after the select event
// this allows custom select handling to work properly
self.term = self._value();
that.term = that._value();

self.close( event );
self.selectedItem = item;
that.close( event );
that.selectedItem = item;
},
blur: function( event, ui ) {
// don't set the value of the text field if it's already correct
// this prevents moving the cursor unnecessarily
if ( self.menu.element.is(":visible") &&
( self._value() !== self.term ) ) {
self._value( self.term );
if ( that.menu.element.is(":visible") &&
( that._value() !== that.term ) ) {
that._value( that.term );
}
}
})
Expand Down Expand Up @@ -281,7 +281,7 @@ $.widget( "ui.autocomplete", {
},

_initSource: function() {
var self = this,
var that = this,
array,
url;
if ( $.isArray(this.options.source) ) {
Expand All @@ -292,10 +292,10 @@ $.widget( "ui.autocomplete", {
} else if ( typeof this.options.source === "string" ) {
url = this.options.source;
this.source = function( request, response ) {
if ( self.xhr ) {
self.xhr.abort();
if ( that.xhr ) {
that.xhr.abort();
}
self.xhr = $.ajax({
that.xhr = $.ajax({
url: url,
data: request,
dataType: "json",
Expand Down Expand Up @@ -423,9 +423,9 @@ $.widget( "ui.autocomplete", {
},

_renderMenu: function( ul, items ) {
var self = this;
var that = this;
$.each( items, function( index, item ) {
self._renderItem( ul, item );
that._renderItem( ul, item );
});
},

Expand Down

0 comments on commit 1d530a1

Please sign in to comment.