Skip to content

Commit 8aff509

Browse files
author
Shiva Poudel
committedJun 10, 2015
Tweaks JSHint for cart and cart fragments
1 parent 157a22a commit 8aff509

File tree

3 files changed

+12
-14
lines changed

3 files changed

+12
-14
lines changed
 

‎.jshintrc

+1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
"_": false,
2020
"Backbone": false,
2121
"jQuery": false,
22+
"JSON": false,
2223
"wp": false
2324
}
2425
}

‎assets/js/frontend/cart-fragments.js

+8-7
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
1+
/* global wc_cart_fragments_params */
12
jQuery( function( $ ) {
23

34
// wc_cart_fragments_params is required to continue, ensure the object exists
45
if ( typeof wc_cart_fragments_params === 'undefined' ) {
56
return false;
67
}
78

8-
/** Cart Handling */
9+
/* Storage Handling */
10+
var $supports_html5_storage;
911
try {
1012
$supports_html5_storage = ( 'sessionStorage' in window && window.sessionStorage !== null );
1113

@@ -15,7 +17,7 @@ jQuery( function( $ ) {
1517
$supports_html5_storage = false;
1618
}
1719

18-
$fragment_refresh = {
20+
var $fragment_refresh = {
1921
url: wc_cart_fragments_params.wc_ajax_url + 'get_refreshed_fragments',
2022
type: 'POST',
2123
success: function( data ) {
@@ -35,6 +37,7 @@ jQuery( function( $ ) {
3537
}
3638
};
3739

40+
/* Cart Handling */
3841
if ( $supports_html5_storage ) {
3942

4043
$( document.body ).bind( 'added_to_cart', function( event, fragments, cart_hash ) {
@@ -55,14 +58,13 @@ jQuery( function( $ ) {
5558
cookie_hash = '';
5659
}
5760

58-
if ( wc_fragments && wc_fragments['div.widget_shopping_cart_content'] && cart_hash == cookie_hash ) {
61+
if ( wc_fragments && wc_fragments['div.widget_shopping_cart_content'] && cart_hash === cookie_hash ) {
5962

6063
$.each( wc_fragments, function( key, value ) {
6164
$( key ).replaceWith(value);
6265
});
6366

6467
$( document.body ).trigger( 'wc_fragments_loaded' );
65-
6668
} else {
6769
throw 'No fragment';
6870
}
@@ -75,7 +77,7 @@ jQuery( function( $ ) {
7577
$.ajax( $fragment_refresh );
7678
}
7779

78-
/* Cart hiding */
80+
/* Cart Hiding */
7981
if ( $.cookie( 'woocommerce_items_in_cart' ) > 0 ) {
8082
$( '.hide_cart_widget_if_empty' ).closest( '.widget_shopping_cart' ).show();
8183
} else {
@@ -84,6 +86,5 @@ jQuery( function( $ ) {
8486

8587
$( document.body ).bind( 'adding_to_cart', function() {
8688
$( '.hide_cart_widget_if_empty' ).closest( '.widget_shopping_cart' ).show();
87-
} );
88-
89+
});
8990
});

‎assets/js/frontend/cart.js

+3-7
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
/* global wc_cart_params */
12
jQuery( function( $ ) {
23

34
// wc_cart_params is required to continue, ensure the object exists
@@ -8,15 +9,13 @@ jQuery( function( $ ) {
89
// Shipping calculator
910
$( document ).on( 'click', '.shipping-calculator-button', function() {
1011
$( '.shipping-calculator-form' ).slideToggle( 'slow' );
11-
1212
return false;
1313
}).on( 'change', 'select.shipping_method, input[name^=shipping_method]', function() {
14-
1514
var shipping_methods = [];
1615

17-
$( 'select.shipping_method, input[name^=shipping_method][type=radio]:checked, input[name^=shipping_method][type=hidden]' ).each( function( index, input ) {
16+
$( 'select.shipping_method, input[name^=shipping_method][type=radio]:checked, input[name^=shipping_method][type=hidden]' ).each( function() {
1817
shipping_methods[ $( this ).data( 'index' ) ] = $( this ).val();
19-
} );
18+
});
2019

2120
$( 'div.cart_totals' ).block({
2221
message: null,
@@ -32,13 +31,10 @@ jQuery( function( $ ) {
3231
};
3332

3433
$.post( wc_cart_params.wc_ajax_url + 'update_shipping_method', data, function( response ) {
35-
3634
$( 'div.cart_totals' ).replaceWith( response );
3735
$( document.body ).trigger( 'updated_shipping_method' );
38-
3936
});
4037
});
4138

4239
$( '.shipping-calculator-form' ).hide();
43-
4440
});

0 commit comments

Comments
 (0)
Please sign in to comment.