Skip to content

Commit

Permalink
wishlist plugin v1.0.0
Browse files Browse the repository at this point in the history
This is the first commit of working copy. Initially managed on private gitlab repo, now moved to github public repo.
  • Loading branch information
uday-kokitkar committed Mar 9, 2020
1 parent ac42b2a commit c7f579b
Show file tree
Hide file tree
Showing 32 changed files with 2,830 additions and 0 deletions.
1 change: 1 addition & 0 deletions assets/css/admin/wlffwc-admin-main.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 11 additions & 0 deletions assets/css/dev/admin/wlffwc-admin-main.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#poststuffIE {
background-color: #fff;
padding: 20px;
}
#wlffwc_global_settings .hr {
border-top: solid 1px #ccc;
margin: 10px 0;
}
.#wlffwc_global_settings input {
width: 400px;
}
101 changes: 101 additions & 0 deletions assets/css/dev/public/wlffwc-wishlist.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
/* Hide page title of shortcode page. */
#main .entry-title {
display: none;
}
/* However, do not hide title of wc account page as we are using shortcode there too. */
.woocommerce-account #main .entry-title {
display: inherit !important;
}
#wlffwc-wishlist-wrapper .wlffwc-wishlist-tbl {
border-collapse: collapse;
text-align: left;
width: 100%;
font-size: 0.8rem;
}
#wlffwc-wishlist-wrapper .wlffwc-wishlist-tbl .mobile-th {
background: #eee;
color: dimgrey;
display: none;
font-weight: bold;
padding: 5px;
position: absolute;
text-transform: uppercase;
top: 0;
left: 0;
}
#wlffwc-wishlist-wrapper .wlffwc-wishlist-tbl .product-thumbnail img {
max-width: 50px;
}
#wlffwc-wishlist-wrapper .wlffwc-wishlist-tbl .price-increase {
font-size: 0.75rem;
color: #bb5e5e;
}
#wlffwc-wishlist-wrapper .wlffwc-wishlist-tbl .price-decrease {
font-size: 0.75rem;
color: #306f35;
}
#wlffwc-wishlist-wrapper .wlffwc-wishlist-tbl .product-actions .date-added {
display: block;
}
#wlffwc-wishlist-wrapper .wlffwc-wishlist-tbl .product-actions .add_to_cart_inline {
display: inline-block;
}
#wlffwc-wishlist-wrapper .wlffwc-wishlist-tbl .product-actions .add_to_cart_inline a {
padding: 0.5em 2em;
}
#wlffwc-wishlist-wrapper .wlffwc-wishlist-tbl .product-actions .remove-from-wishlist {
margin-left: 5px;
}
#wlffwc-wishlist-wrapper .wlffwc-wishlist-tbl .product-actions .woocommerce-message {
display: none !important;
}
#wlffwc-wishlist-wrapper .wlffwc-wishlist-tbl .mobile-display {
display: none;
}
#wlffwc-wishlist-wrapper .wlffwc-wishlist-tbl .no-data-found-row td {
text-align: center;
}
#wlffwc-wishlist-wrapper .wlffwc-wishlist-tbl .no-data-found-row.hide {
display: none;
}
/* Hide wishlist shortcode title on wc my account page */
.woocommerce-MyAccount-content #wlffwc-wishlist-wrapper h2 {
display: none;
}
/* Simple CSS for flexbox table on mobile */
@media(max-width: 800px) {
#wlffwc-wishlist-wrapper .wlffwc-wishlist-tbl thead {
left: -9999px;
position: absolute;
visibility: hidden;
}
#wlffwc-wishlist-wrapper .wlffwc-wishlist-tbl tr {
border-bottom: 0;
display: flex;
flex-direction: row;
flex-wrap: wrap;
margin-bottom: 40px;
}
#wlffwc-wishlist-wrapper .wlffwc-wishlist-tbl td {
border: 1px solid #ccc;
margin: 0 -1px -1px 0;
padding-top: 35px;
padding-bottom: 0.875em;
position: relative;
width: 50%;
text-align: center;
}
#wlffwc-wishlist-wrapper .wlffwc-wishlist-tbl .no-data-found-row td {
padding-top: 0.875em;
border: none;
}
#wlffwc-wishlist-wrapper .wlffwc-wishlist-tbl .mobile-th {
display: block;
}
#wlffwc-wishlist-wrapper .wlffwc-wishlist-tbl .mobile-display {
display: inherit;
}
#wlffwc-wishlist-wrapper .wlffwc-wishlist-tbl .not-mobile-display {
display: none;
}
}
1 change: 1 addition & 0 deletions assets/css/public/wlffwc-wishlist.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

49 changes: 49 additions & 0 deletions assets/images/ajax-loader.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/images/wishlist-icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
224 changes: 224 additions & 0 deletions assets/js/dev/public/wlffwc-wishlist.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,224 @@
jQuery( function( $ ) {

// console.log( wlffwc_wishlist );

if ( 'undefined' === typeof wlffwc_wishlist ) {
return false;
}

/**
* WishList.
*/
var WLFFWCWishlist = function() {

$( document )
.on( 'click', '.wlffwc-add-to-wishlist-wrap .add-to-wishlist-link', { WLFFWCWishlist: this }, this.addToWishlist )
.on( 'adding_to_cart', 'body', { WLFFWCWishlist: this }, this.adding_to_cart )
.on( 'added_to_cart', 'body', { WLFFWCWishlist: this }, this.added_to_cart )
.on( 'click', '.remove-from-wishlist', { WLFFWCWishlist: this }, this.remove_from_wishlist )
};

/**
* Sends request to add product to wishlist.
*
* @since 1.0.0
*
* @param jQuery object el Add to wishlist link.
*/
WLFFWCWishlist.prototype.addToWishlist = function( el ) {

var that = $( this),
product_id = that.attr( 'data-product_id' ),
data = {
product_id: product_id,
wlffwc_add_nonce: wlffwc_wishlist.wlffwc_add_nonce,
action: wlffwc_wishlist.actions.add_to_wishlist_action,
};

el.preventDefault();

// console.log( data );

$( document.body ).trigger( 'before_adding_to_wishlist' );

$.ajax({
type: 'POST',
url: wlffwc_wishlist.ajax_url,
data: data,
dataType: 'json',
beforeSend: function(){
WLFFWCWishlistObj.block( that );
},
complete: function(){
WLFFWCWishlistObj.unblock( that );
},
success: function( response ) {
var response_result = response.success,
response_message = response.message;

// if( true === response_result ) {
$( '.wlffwc-add-to-wishlist-wrap' ).html( response_message );
// console.log( 'yeh, true!' );
// }
if( true === response_result ) {
$( document.body ).trigger('after_adding_to_wishlist', [ that, data ] );
}
}
});

return false;
}; // ! addToWishlist

/**
* Appends data to send to add to cart ajax request along with WC data.
*
* @since 1.0.0
*
* @param object ev Event object.
* @param object button jQuery add to cart button object.
* @param object data WC Ajax add to cart data.
*
* @return void.
*/
WLFFWCWishlist.prototype.adding_to_cart = function( ev, button, data ) {
if( button.hasClass( 'wlffwc-wishlist-add-to-cart' ) ){
data.wlffwc_remove_after_adding_cart = button.attr( 'data-product_id' );
}
}; // ! adding_to_cart

/**
* Remove item from the list after adding to the cart.
*
* @since 1.0.0
*
* @param object ev Event object.
* @param object fragments WC Cart fragements.
* @param string carthash Cart hash value.
* @param object button jQuery add to cart button object.
*
* @return void.
*/
WLFFWCWishlist.prototype.added_to_cart = function( ev, fragments, carthash, button ) {
$( button ).closest('tr').remove();
var messages = $( '#wlffwc-wishlist-wrapper .wlffwc-wc-alert.woocommerce');

if( messages.length === 0 ){
messages.html( wlffwc_wishlist.labels.added_to_cart_message ).fadeIn();
} else {
messages.fadeOut( 300, function(){
messages.html( wlffwc_wishlist.labels.added_to_cart_message ).fadeIn();
} );
}
WLFFWCWishlistObj.maybe_show_no_data_message();
}; // ! added_to_cart

/**
* Removes item from the wishlist.
*
* @since 1.0.0
*
* @param jQuery object el Remove element to remove the product from the list.
*
* @return void.
*/
WLFFWCWishlist.prototype.remove_from_wishlist = function( el ) {
var that = $( this ).closest( 'tr' ),
product_id = that.attr( 'data-product_id' ),
data = {
product_id : product_id,
wlffwc_remove_nonce : wlffwc_wishlist.wlffwc_remove_nonce,
action : wlffwc_wishlist.actions.remove_from_wishlist_action,
};

el.preventDefault();

$( document.body ).trigger( 'before_removing_from_wishlist' );

$.ajax({
type: 'POST',
url: wlffwc_wishlist.ajax_url,
data: data,
dataType: 'json',
beforeSend: function(){
WLFFWCWishlistObj.block( that );
},
complete: function(){
WLFFWCWishlistObj.unblock( that );
},
success: function( response ) {
var response_result = response.success,
response_message = response.message;

// if( true === response_result ) {
$( '.wlffwc-add-to-wishlist-wrap' ).html( response_message );
// }
if( true === response_result ) {
that.remove();
WLFFWCWishlistObj.maybe_show_no_data_message();
$( document.body ).trigger('after_removing_from_wishlist', [ that, data ] );
}
}
});

return false;
}; // ! remove_from_wishlist


/************************
| |
| UTILITY FUNCTIONS |
| |
************************/

/**
* Checks how many items in the list. If found zero, shows "no data" row.
*
* @since 1.0.0
*
* @return void.
*/
WLFFWCWishlist.prototype.maybe_show_no_data_message = function() {
if ( $( '#wlffwc-wishlist-wrapper .wishlist-item' ).length == 0 ) {
$( '#wlffwc-wishlist-wrapper .no-data-found-row' ).removeClass('hide');
}
}

/**
* Block item if possible.
*
* @since 1.0.0
*
* @param item jQuery object
*
* @return void
*/
WLFFWCWishlist.prototype.block = function( item ) {
if( typeof $.fn.block != 'undefined' ) {
item.fadeTo( '400', '0.6' ).block( {
message: null,
overlayCSS : {
background : 'transparent url(' + wlffwc_wishlist.ajax_loader + ') no-repeat center',
backgroundSize: '40px 40px',
opacity : 1
}
} );
}
} // ! block

/**
* Unblock item if possible
*
* @since 1.0.0
*
* @param item jQuery object
*
* @return void
*/
WLFFWCWishlist.prototype.unblock = function( item ) {
if( typeof $.fn.unblock != 'undefined' ) {
item.stop( true ).css( 'opacity', '1' ).unblock();
}
} // ! unblock

var WLFFWCWishlistObj = new WLFFWCWishlist();
});
Loading

0 comments on commit c7f579b

Please sign in to comment.