Skip to content
This repository has been archived by the owner on Oct 8, 2021. It is now read-only.

navigation: Style fixes powered by esformatter #8097

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
696 changes: 352 additions & 344 deletions js/navigation.js

Large diffs are not rendered by default.

128 changes: 64 additions & 64 deletions js/navigation/base.js
Expand Up @@ -24,75 +24,75 @@
// Browser globals
factory( jQuery );
}
})( function( $ ) {
} )( function( $ ) {

var base,
var base,

// Existing base tag?
baseElement = $( "head" ).children( "base" ),
// Existing base tag?
baseElement = $( "head" ).children( "base" ),

// DEPRECATED as of 1.5.0 and will be removed in 1.6.0. As of 1.6.0 only
// base.dynamicBaseEnabled will be checked
getDynamicEnabled = function() {

// If a value has been set at the old, deprecated location, we return that value.
// Otherwise we return the value from the new location. We check explicitly for
// undefined because true and false are both valid values for dynamicBaseEnabled.
if ( $.mobile.dynamicBaseEnabled !== undefined ) {
return $.mobile.dynamicBaseEnabled;
}
return base.dynamicBaseEnabled;
};

// base element management, defined depending on dynamic base tag support
// TODO move to external widget
base = {

// Disable the alteration of the dynamic base tag or links
dynamicBaseEnabled: true,

// Make sure base element is defined, for use in routing asset urls that are referenced
// in Ajax-requested markup
element: function() {
if ( !( baseElement && baseElement.length ) ) {
baseElement = $( "<base>", { href: $.mobile.path.documentBase.hrefNoSearch } )
.prependTo( $( "head" ) );
}

return baseElement;
},

// set the generated BASE element's href to a new page's base path
set: function( href ) {

// We should do nothing if the user wants to manage their url base manually.
// Note: Our method of ascertaining whether the user wants to manager their url base
// manually is DEPRECATED as of 1.5.0 and will be removed in 1.6.0. As of 1.6.0 the
// flag base.dynamicBaseEnabled will be checked, so the function getDynamicEnabled()
// will be removed.
if ( !getDynamicEnabled() ) {
return;
}

// we should use the base tag if we can manipulate it dynamically
base.element().attr( "href",
$.mobile.path.makeUrlAbsolute( href, $.mobile.path.documentBase ) );
},

// set the generated BASE element's href to a new page's base path
reset: function( /* href */ ) {

// DEPRECATED as of 1.5.0 and will be removed in 1.6.0. As of 1.6.0 only
// base.dynamicBaseEnabled will be checked
getDynamicEnabled = function() {

// If a value has been set at the old, deprecated location, we return that value.
// Otherwise we return the value from the new location. We check explicitly for
// undefined because true and false are both valid values for dynamicBaseEnabled.
if ( $.mobile.dynamicBaseEnabled !== undefined ) {
return $.mobile.dynamicBaseEnabled;
}
return base.dynamicBaseEnabled;
};

// base element management, defined depending on dynamic base tag support
// TODO move to external widget
base = {

// Disable the alteration of the dynamic base tag or links
dynamicBaseEnabled: true,

// Make sure base element is defined, for use in routing asset urls that are referenced
// in Ajax-requested markup
element: function() {
if ( !( baseElement && baseElement.length ) ) {
baseElement = $( "<base>", { href: $.mobile.path.documentBase.hrefNoSearch } )
.prependTo( $( "head" ) );
}

return baseElement;
},

// set the generated BASE element's href to a new page's base path
set: function( href ) {

// We should do nothing if the user wants to manage their url base manually.
// Note: Our method of ascertaining whether the user wants to manager their url base
// manually is DEPRECATED as of 1.5.0 and will be removed in 1.6.0. As of 1.6.0 the
// flag base.dynamicBaseEnabled will be checked, so the function getDynamicEnabled()
// will be removed.
if ( !getDynamicEnabled() ) {
return;
}

// we should use the base tag if we can manipulate it dynamically
base.element().attr( "href",
$.mobile.path.makeUrlAbsolute( href, $.mobile.path.documentBase ) );
},

// set the generated BASE element's href to a new page's base path
reset: function(/* href */) {

// DEPRECATED as of 1.5.0 and will be removed in 1.6.0. As of 1.6.0 only
// base.dynamicBaseEnabled will be checked
if ( !getDynamicEnabled() ) {
return;
}

base.element().attr( "href", $.mobile.path.documentBase.hrefNoSearch );
if ( !getDynamicEnabled() ) {
return;
}
};

$.mobile.base = base;
base.element().attr( "href", $.mobile.path.documentBase.hrefNoSearch );
}
};

$.mobile.base = base;

return base;
});
return base;
} );
218 changes: 110 additions & 108 deletions js/navigation/history.js
Expand Up @@ -25,142 +25,144 @@
// Browser globals
factory( jQuery );
}
})( function( $ ) {
} )( function( $ ) {

$.mobile.History = function( stack, index ) {
this.stack = stack || [];
this.activeIndex = index || 0;
};
$.mobile.History = function( stack, index ) {
this.stack = stack || [];
this.activeIndex = index || 0;
};

$.extend($.mobile.History.prototype, {
getActive: function() {
return this.stack[ this.activeIndex ];
},
$.extend( $.mobile.History.prototype, {
getActive: function() {
return this.stack[ this.activeIndex ];
},

getLast: function() {
return this.stack[ this.previousIndex ];
},
getLast: function() {
return this.stack[ this.previousIndex ];
},

getNext: function() {
return this.stack[ this.activeIndex + 1 ];
},
getNext: function() {
return this.stack[ this.activeIndex + 1 ];
},

getPrev: function() {
return this.stack[ this.activeIndex - 1 ];
},
getPrev: function() {
return this.stack[ this.activeIndex - 1 ];
},

// addNew is used whenever a new page is added
add: function( url, data ) {
data = data || {};
// addNew is used whenever a new page is added
add: function( url, data ) {
data = data || {};

//if there's forward history, wipe it
if ( this.getNext() ) {
this.clearForward();
}
//if there's forward history, wipe it
if ( this.getNext() ) {
this.clearForward();
}

// if the hash is included in the data make sure the shape
// is consistent for comparison
if ( data.hash && data.hash.indexOf( "#" ) === -1) {
data.hash = "#" + data.hash;
}
// if the hash is included in the data make sure the shape
// is consistent for comparison
if ( data.hash && data.hash.indexOf( "#" ) === -1 ) {
data.hash = "#" + data.hash;
}

data.url = url;
this.stack.push( data );
this.activeIndex = this.stack.length - 1;
},
data.url = url;
this.stack.push( data );
this.activeIndex = this.stack.length - 1;
},

//wipe urls ahead of active index
clearForward: function() {
this.stack = this.stack.slice( 0, this.activeIndex + 1 );
},
//wipe urls ahead of active index
clearForward: function() {
this.stack = this.stack.slice( 0, this.activeIndex + 1 );
},

find: function( url, stack, earlyReturn ) {
stack = stack || this.stack;
find: function( url, stack, earlyReturn ) {
stack = stack || this.stack;

var entry, i, length = stack.length, index;
var entry, i,
length = stack.length, index;

for ( i = 0; i < length; i++ ) {
entry = stack[i];
for ( i = 0; i < length; i++ ) {
entry = stack[ i ];

if ( decodeURIComponent(url) === decodeURIComponent(entry.url) ||
decodeURIComponent(url) === decodeURIComponent(entry.hash) ) {
index = i;
if ( decodeURIComponent( url ) === decodeURIComponent( entry.url ) ||
decodeURIComponent( url ) === decodeURIComponent( entry.hash ) ) {
index = i;

if ( earlyReturn ) {
return index;
}
if ( earlyReturn ) {
return index;
}
}
}

return index;
},
return index;
},

_findById: function( id ) {
var stackIndex,
stackLength = this.stack.length;
_findById: function( id ) {
var stackIndex,
stackLength = this.stack.length;

for ( stackIndex = 0 ; stackIndex < stackLength ; stackIndex++ ) {
if ( this.stack[ stackIndex ].id === id ) {
break;
}
for ( stackIndex = 0; stackIndex < stackLength; stackIndex++ ) {
if ( this.stack[ stackIndex ].id === id ) {
break;
}
}

return ( stackIndex < stackLength ? stackIndex : undefined );
},
return ( stackIndex < stackLength ? stackIndex : undefined );
},

closest: function( url, id ) {
var closest = ( id === undefined ? undefined : this._findById( id ) ),
a = this.activeIndex;
closest: function( url, id ) {
var closest = ( id === undefined ? undefined : this._findById( id ) ),
a = this.activeIndex;

// First, we check whether we've found an entry by id. If so, we're done.
if ( closest !== undefined ) {
return closest;
}
// First, we check whether we've found an entry by id. If so, we're done.
if ( closest !== undefined ) {
return closest;
}

// Failing that take the slice of the history stack before the current index and search
// for a url match. If one is found, we'll avoid avoid looking through forward history
// NOTE the preference for backward history movement is driven by the fact that
// most mobile browsers only have a dedicated back button, and users rarely use
// the forward button in desktop browser anyhow
closest = this.find( url, this.stack.slice(0, a) );

// If nothing was found in backward history check forward. The `true`
// value passed as the third parameter causes the find method to break
// on the first match in the forward history slice. The starting index
// of the slice must then be added to the result to get the element index
// in the original history stack :( :(
//
// TODO this is hyper confusing and should be cleaned up (ugh so bad)
if ( closest === undefined ) {
closest = this.find( url, this.stack.slice(a), true );
closest = closest === undefined ? closest : closest + a;
}
// Failing that take the slice of the history stack before the current index and search
// for a url match. If one is found, we'll avoid avoid looking through forward history
// NOTE the preference for backward history movement is driven by the fact that
// most mobile browsers only have a dedicated back button, and users rarely use
// the forward button in desktop browser anyhow
closest = this.find( url, this.stack.slice( 0, a ) );

// If nothing was found in backward history check forward. The `true`
// value passed as the third parameter causes the find method to break
// on the first match in the forward history slice. The starting index
// of the slice must then be added to the result to get the element index
// in the original history stack :( :(
//
// TODO this is hyper confusing and should be cleaned up (ugh so bad)
if ( closest === undefined ) {
closest = this.find( url, this.stack.slice( a ), true );
closest = closest === undefined ? closest : closest + a;
}

return closest;
},
return closest;
},

direct: function( opts ) {
var newActiveIndex = this.closest( opts.url, opts.id ), a = this.activeIndex;
direct: function( opts ) {
var newActiveIndex = this.closest( opts.url, opts.id ),
a = this.activeIndex;

// save new page index, null check to prevent falsey 0 result
// record the previous index for reference
if ( newActiveIndex !== undefined ) {
this.activeIndex = newActiveIndex;
this.previousIndex = a;
}
// save new page index, null check to prevent falsey 0 result
// record the previous index for reference
if ( newActiveIndex !== undefined ) {
this.activeIndex = newActiveIndex;
this.previousIndex = a;
}

// invoke callbacks where appropriate
//
// TODO this is also convoluted and confusing
if ( newActiveIndex < a ) {
( opts.present || opts.back || $.noop )( this.getActive(), "back" );
} else if ( newActiveIndex > a ) {
( opts.present || opts.forward || $.noop )( this.getActive(), "forward" );
} else if ( newActiveIndex === undefined && opts.missing ) {
opts.missing( this.getActive() );
}
// invoke callbacks where appropriate
//
// TODO this is also convoluted and confusing
if ( newActiveIndex < a ) {
( opts.present || opts.back || $.noop )( this.getActive(), "back" );
} else if ( newActiveIndex > a ) {
( opts.present || opts.forward || $.noop )( this.getActive(), "forward" );
} else if ( newActiveIndex === undefined && opts.missing ) {
opts.missing( this.getActive() );
}
});
}
} );

return $.mobile.History;
});
return $.mobile.History;
} );