Skip to content

Commit

Permalink
Added .jshintrc and fixed lint errors.
Browse files Browse the repository at this point in the history
  • Loading branch information
scottgonzalez committed May 31, 2012
1 parent f1b964d commit 6d3c71f
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 35 deletions.
27 changes: 27 additions & 0 deletions .jshintrc
@@ -0,0 +1,27 @@
{
"boss": true,
"browser": true,
"curly": true,
"eqnull": true,
"eqeqeq": true,
"expr": true,
"jquery": true,
"latedef": true,
"noarg": true,
"smarttabs": true,
"trailing": true,
"undef": true,
"predef": [
"amplify",
"asyncTest",
"deepEqual",
"equal",
"expect",
"module",
"ok",
"start",
"strictEqual",
"stop",
"test"
]
}
62 changes: 31 additions & 31 deletions request/amplify.request.js
Expand Up @@ -116,7 +116,7 @@ amplify.request.types.ajax = function( defnSettings ) {
}, defnSettings );

return function( settings, request ) {
var xhr,
var xhr, handleResponse,
url = defnSettings.url,
abort = request.abort,
ajaxSettings = $.extend( true, {}, defnSettings, { data: settings.data } ),
Expand Down Expand Up @@ -151,28 +151,7 @@ amplify.request.types.ajax = function( defnSettings ) {
}
};

amplify.publish( "request.ajax.preprocess",
defnSettings, settings, ajaxSettings, ampXHR );

$.extend( ajaxSettings, {
success: function( data, status ) {
handleResponse( data, status );
},
error: function( _xhr, status ) {
handleResponse( null, status );
},
beforeSend: function( _xhr, _ajaxSettings ) {
xhr = _xhr;
ajaxSettings = _ajaxSettings;
var ret = defnSettings.beforeSend ?
defnSettings.beforeSend.call( this, ampXHR, ajaxSettings ) : true;
return ret && amplify.publish( "request.before.ajax",
defnSettings, settings, ajaxSettings, ampXHR );
}
});
$.ajax( ajaxSettings );

function handleResponse( data, status ) {
handleResponse = function( data, status ) {
$.each( xhrProps, function( i, key ) {
try {
ampXHR[ key ] = xhr[ key ];
Expand All @@ -199,7 +178,28 @@ amplify.request.types.ajax = function( defnSettings ) {
// this can happen if a request is aborted
// TODO: figure out if this breaks polling or multi-part responses
handleResponse = $.noop;
}
};

amplify.publish( "request.ajax.preprocess",
defnSettings, settings, ajaxSettings, ampXHR );

$.extend( ajaxSettings, {
success: function( data, status ) {
handleResponse( data, status );
},
error: function( _xhr, status ) {
handleResponse( null, status );
},
beforeSend: function( _xhr, _ajaxSettings ) {
xhr = _xhr;
ajaxSettings = _ajaxSettings;
var ret = defnSettings.beforeSend ?
defnSettings.beforeSend.call( this, ampXHR, ajaxSettings ) : true;
return ret && amplify.publish( "request.before.ajax",
defnSettings, settings, ajaxSettings, ampXHR );
}
});
$.ajax( ajaxSettings );

request.abort = function() {
ampXHR.abort();
Expand Down Expand Up @@ -262,6 +262,13 @@ amplify.subscribe( "request.ajax.preprocess", function( defnSettings, settings,

var cache = amplify.request.cache = {
_key: function( resourceId, url, data ) {
function chunk() {
return data.charCodeAt( i++ ) << 24 |
data.charCodeAt( i++ ) << 16 |
data.charCodeAt( i++ ) << 8 |
data.charCodeAt( i++ ) << 0;
}

data = url + data;
var length = data.length,
i = 0,
Expand All @@ -271,13 +278,6 @@ var cache = amplify.request.cache = {
checksum ^= chunk();
}

function chunk() {
return data.charCodeAt( i++ ) << 24 |
data.charCodeAt( i++ ) << 16 |
data.charCodeAt( i++ ) << 8 |
data.charCodeAt( i++ ) << 0;
}

return "request-" + resourceId + "-" + checksum;
},

Expand Down
4 changes: 2 additions & 2 deletions request/test/unit.js
Expand Up @@ -790,7 +790,7 @@ asyncTest( "cache: true", function() {
var ajaxCalls = 0;
$( "#ajax-listener" ).ajaxComplete(function( event, xhr ) {
if ( xhr.statusText !== "abort" ) {
ok( !ajaxCalls++, "ajax call completed" );
ok( !(ajaxCalls++), "ajax call completed" );
}
});
amplify.request.define( "memory-cache", "ajax", {
Expand Down Expand Up @@ -953,7 +953,7 @@ if ( amplify.store ) {
var ajaxCalls = 0;
$( "#ajax-listener" ).ajaxComplete(function( event, xhr ) {
if ( xhr.statusText !== "abort" ) {
ok( !ajaxCalls++, "ajax call completed" );
ok( !(ajaxCalls++), "ajax call completed" );
}
});
amplify.request.define( "persist-cache", "ajax", {
Expand Down
2 changes: 1 addition & 1 deletion store/amplify.store.js
Expand Up @@ -198,7 +198,7 @@ if ( !store.types.localStorage && window.globalStorage ) {
// http://www.w3.org/TR/REC-xml/#NT-Name
// simplified to assume the starting character is valid
// also removed colon as it is invalid in HTML attribute names
key = key.replace( /[^-._0-9A-Za-z\xb7\xc0-\xd6\xd8-\xf6\xf8-\u037d\u37f-\u1fff\u200c-\u200d\u203f\u2040\u2070-\u218f]/g, "-" );
key = key.replace( /[^\-._0-9A-Za-z\xb7\xc0-\xd6\xd8-\xf6\xf8-\u037d\u37f-\u1fff\u200c-\u200d\u203f\u2040\u2070-\u218f]/g, "-" );
// adjust invalid starting character to deal with our simplified sanitization
key = key.replace( /^-/, "_-" );

Expand Down
2 changes: 1 addition & 1 deletion store/test/unit.js
Expand Up @@ -166,7 +166,7 @@ if ( "globalStorage" in amplify.store.types ) {
module( "amplify.store.globalStorage", {
setup: function() {
var key,
store = globalStorage[ location.hostname ];
store = window.globalStorage[ location.hostname ];
try {
while ( key = store.key( 0 ) ) {
store.removeItem( key );
Expand Down

0 comments on commit 6d3c71f

Please sign in to comment.