Browse Source

Include upstream JS+CSS

master
Sam Black 2 years ago
parent
commit
35256c4c95
Signed by: samwwwblack GPG Key ID: 0FF0223994EA47D8
  1. 50
      assets/css/backend.css
  2. 48
      assets/css/dashboard.css
  3. 81
      assets/css/frontend.css
  4. 667
      assets/js/backend.js
  5. 822
      assets/js/frontend.js

50
assets/css/backend.css

@ -55,7 +55,7 @@
color: #999999;
}
.woosb_results li .move {
.woosb_results li .move, .woosb_results li .qty {
display: none;
}
@ -104,15 +104,37 @@
font-size: 10px;
height: 18px;
line-height: 18px;
color: #999;
background-color: #fafafa;
text-decoration: none;
padding: 0 6px;
border-radius: 2px;
color: #999;
position: absolute;
top: 10px;
right: 45px;
}
.woosb_selected li span.info, .woosb_results li span.info {
font-size: 12px;
font-style: italic;
height: 18px;
line-height: 18px;
color: #999;
background-color: #fafafa;
text-decoration: none;
padding: 0 6px;
border-radius: 2px;
}
.woosb_results li span.type a {
font-size: 10px;
height: 18px;
line-height: 18px;
color: #999;
background-color: #fafafa;
text-decoration: none;
}
.woosb_selected li span.type {
right: 35px;
}
@ -127,6 +149,10 @@
opacity: .5;
}
.woosb_selected li del .amount, .woosb_results li del .amount {
text-decoration: line-through;
}
.woosb_selected li ins, .woosb_results li ins {
text-decoration: none;
}
@ -159,6 +185,7 @@
font-size: 13px;
height: 28px;
line-height: 1;
float: none;
}
#woosb_settings .w100 {
@ -208,6 +235,16 @@
text-align: left;
}
.woosb_table table tr td label {
float: none;
margin: 0;
width: auto;
}
.woosb_table .woocommerce-help-tip {
margin: 0 !important;
}
#woosb_set_regular_price, #woosb_set_sale_price, #woosb_set_shipping_class {
cursor: pointer;
}
@ -216,6 +253,10 @@
display: none !important;
}
.woosb_tab a:before {
content: '\f480' !important;
}
table.wp-list-table span.product-type.woosb:before {
content: '\e003';
color: #96588a;
@ -229,4 +270,9 @@ table.wp-list-table span.product-type.woosb:before {
#woosb_meta_box .inside ul {
list-style: circle;
margin-left: 18px;
}
.woosb-state {
font-weight: normal;
font-style: italic;
}

48
assets/css/dashboard.css

@ -1,18 +1,23 @@
/* Dashboard Widget */
#wpclever_dashboard_widget .inside {
padding: 0 12px;
padding: 0;
margin: 0;
max-height: 365px;
display: inline-block;
width: 100%;
overflow-y: auto;
}
#wpclever_dashboard_widget.closed .inside {
display: none;
}
#wpclever_dashboard_widget .item {
border-bottom: 1px solid #eee;
margin: 0 -12px;
margin: 0;
padding: 10px 12px;
display: inline-block;
width: 100%;
display: block;
}
#wpclever_dashboard_widget .item:hover {
@ -29,6 +34,7 @@
color: #23282d;
outline: none;
box-shadow: none;
text-decoration: none;
}
#wpclever_dashboard_widget .item img {
@ -39,6 +45,18 @@
border-radius: 2px;
}
#wpclever_dashboard_widget .item .num {
width: 40px;
height: 40px;
float: left;
margin-right: 10px;
border-radius: 20px;
background-color: #b05d93;
text-align: center;
line-height: 40px;
color: #ffffff;
}
#wpclever_dashboard_widget .item .info {
opacity: .5;
}
@ -108,6 +126,7 @@
.wpclever_settings_page .wpclever_settings_page_content table tr.heading {
border-bottom: 1px dashed #eee;
border-left: 4px solid #23282d;
}
.wpclever_settings_page .wpclever_settings_page_content table {
@ -165,15 +184,18 @@
border-radius: 2px;
}
.wpclever_plugins .item .info {
opacity: .5;
.wpclever_plugins .item .num {
width: 40px;
height: 40px;
float: left;
margin-right: 10px;
border-radius: 20px;
background-color: #b05d93;
text-align: center;
line-height: 40px;
color: #ffffff;
}
/* Plugin List */
tr[data-slug^="wpc-"] .plugin-description strong {
display: block;
font-weight: 400;
font-size: 10px;
color: #a00;
.wpclever_plugins .item .info {
opacity: .5;
}

81
assets/css/frontend.css

@ -1,4 +1,9 @@
.woosb-wrap .woosb-text, .woosb-wrap .woosb-table {
.woosb-wrap {
display: block;
clear: both;
}
.woosb-wrap .woosb-text, .woosb-wrap .woosb-products {
margin: 0 0 15px 0;
}
@ -6,8 +11,20 @@
white-space: pre-line;
}
.woosb-products tr th, .woosb-products tr td {
vertical-align: middle;
.woosb-products .woosb-product {
display: flex;
align-items: center;
padding: 10px 0;
border-bottom: 1px dotted #e5e5e5;
}
.woosb-products .woosb-product > div {
padding-right: 10px;
}
.woosb-products .woosb-product > div:last-child {
padding-right: 0;
text-align: right;
}
.woosb-products .woosb-product .woosb-thumb {
@ -16,18 +33,31 @@
.woosb-products .woosb-product .woosb-thumb img {
width: 40px;
height: 40px;
max-width: 40px;
height: auto;
display: block;
}
.woosb-products .woosb-product .woosb-qty {
width: 80px;
flex: 0 0 80px;
}
.woosb-products .woosb-product .woosb-qty label {
display: none;
}
.woosb-products .woosb-product .woosb-qty input {
width: 60px;
width: 100%;
}
.woosb-products .woosb-product .woosb-price {
min-width: 100px;
text-align: right;
width: 100px;
flex: 0 0 100px;
}
.woosb-products .woosb-product .woosb-price * {
font-size: inherit !important;
}
.woosb-products .woosb-product .woosb-price del {
@ -47,6 +77,10 @@
display: inline-block;
}
.woosb-products .woosb-product .woosb-title {
flex-grow: 1;
}
.woosb-products .woosb-product .woosb-title .woosb-title-inner {
display: block;
overflow: hidden;
@ -57,24 +91,26 @@
box-shadow: none;
}
.woosb-products .woosb-product form.variations_form {
.woosb-products .woosb-product .variations_form {
margin: 0;
padding: 0;
}
.woosb-products .woosb-product form.variations_form .stock.in-stock {
.woosb-products .woosb-product .woosb-title .stock.in-stock {
color: green;
}
.woosb-products .woosb-product form.variations_form .stock {
.woosb-products .woosb-product .woosb-title .stock {
font-size: 14px;
margin: 0;
padding: 0;
}
.woosb-products .woosb-product form.variations_form .stock.available-on-backorder {
.woosb-products .woosb-product .woosb-title .stock.available-on-backorder {
color: orange;
}
.woosb-products .woosb-product form.variations_form .stock.out-of-stock {
.woosb-products .woosb-product .woosb-title .stock.out-of-stock {
color: red;
}
@ -100,20 +136,20 @@
padding-right: 0;
}
.woosb-products .woosb-product form.variations_form .variations {
.woosb-products .woosb-product .variations_form .variations {
display: inline-block;
margin: 0;
padding: 0;
}
.woosb-products .woosb-product form.variations_form .variations .variation {
.woosb-products .woosb-product .variations_form .variations .variation {
}
.woosb-products .woosb-product form.variations_form .variations .variation > div {
.woosb-products .woosb-product .variations_form .variations .variation > div {
display: block;
}
.woosb-products .woosb-product form.variations_form .variations .variation {
.woosb-products .woosb-product .variations_form .variations .variation {
display: inline-block;
float: left;
border-width: 1px;
@ -121,29 +157,28 @@
border-color: #e5e5e5;
padding: 5px 10px;
margin: 5px 5px 0 0;
min-width: 200px;
max-width: 100%;
border-radius: 2px;
}
.woosb-products .woosb-product form.variations_form .variations .reset {
.woosb-products .woosb-product .variations_form .variations .reset {
display: inline-block;
}
.woosb-products .woosb-product form.variations_form .variations .variation:last-child {
.woosb-products .woosb-product .variations_form .variations .variation:last-child {
margin-bottom: 0;
}
.woosb-products .woosb-product form.variations_form .variations .variation .label {
.woosb-products .woosb-product .variations_form .variations .variation .label {
font-size: 12px;
line-height: 1;
}
.woosb-products .woosb-product form.variations_form .variations .variation .select {
.woosb-products .woosb-product .variations_form .variations .variation .select {
line-height: 1;
}
.woosb-products .woosb-product form.variations_form .variations .variation .select select {
.woosb-products .woosb-product .variations_form .variations .variation .select select {
width: 100%;
line-height: 1;
padding: 0 16px 0 0;
@ -159,7 +194,7 @@
background-size: auto;
}
.woosb-products .woosb-product form.variations_form .variations a.reset_variations {
.woosb-products .woosb-product .variations_form .variations a.reset_variations {
margin: 0;
font-size: 12px;
}

667
assets/js/backend.js

@ -1,318 +1,353 @@
'use strict';
jQuery( document ).ready( function( $ ) {
var woosb_timeout = null;
woosb_active_settings();
$( '#product-type' ).on( 'change', function() {
woosb_active_settings();
} );
// hide search result box by default
$( '#woosb_results' ).hide();
$( '#woosb_loading' ).hide();
// total price
if ( $( '#product-type' ).val() == 'woosb' ) {
woosb_change_regular_price();
}
// set regular price
$( '#woosb_set_regular_price' ).on( 'click', function() {
if ( $( '#woosb_disable_auto_price' ).is( ':checked' ) ) {
$( 'li.general_tab a' ).trigger( 'click' );
$( '#_regular_price' ).focus();
} else {
alert( 'You must disable auto calculate price first!' );
}
} );
// set optional
$( '#woosb_optional_products' ).on( 'click', function() {
if ( $( this ).is( ':checked' ) ) {
$( '.woosb_tr_show_if_optional_products' ).show();
} else {
$( '.woosb_tr_show_if_optional_products' ).hide();
}
} );
// checkbox
$( '#woosb_disable_auto_price' ).on( 'change', function() {
if ( $( this ).is( ':checked' ) ) {
$( '#_regular_price' ).prop( 'readonly', false );
$( '#_sale_price' ).prop( 'readonly', false );
$( '.woosb_tr_show_if_auto_price' ).hide();
} else {
$( '#_regular_price' ).prop( 'readonly', true );
$( '#_sale_price' ).prop( 'readonly', true );
$( '.woosb_tr_show_if_auto_price' ).show();
}
if ( $( '#product-type' ).val() == 'woosb' ) {
woosb_change_regular_price();
}
} );
// search input
$( '#woosb_keyword' ).keyup( function() {
if ( $( '#woosb_keyword' ).val() != '' ) {
$( '#woosb_loading' ).show();
if ( woosb_timeout != null ) {
clearTimeout( woosb_timeout );
}
woosb_timeout = setTimeout( woosb_ajax_get_data, 300 );
return false;
}
} );
// actions on search result items
$( '#woosb_results' ).on( 'click', 'li', function() {
$( this ).children( 'span.qty' ).html( '<input type="number" value="1" min="0"/>' );
$( this ).children( 'span.remove' ).html( '×' );
$( '#woosb_selected ul' ).append( $( this ) );
$( '#woosb_results' ).hide();
$( '#woosb_keyword' ).val( '' );
woosb_get_ids();
woosb_change_regular_price();
woosb_set_min_max();
woosb_arrange();
return false;
} );
// change qty of each item
$( '#woosb_selected' ).on( 'keyup change', '.qty input', function() {
woosb_get_ids();
woosb_change_regular_price();
return false;
} );
// change shipping fee
$( '#woosb_shipping_fee' ).on( 'change', function() {
if ( $( this ).val() == 'whole' ) {
$( '#woosb_set_shipping_class' ).show();
} else {
$( '#woosb_set_shipping_class' ).hide();
}
} );
$( document ).on( 'click', '#woosb_set_shipping_class', function( e ) {
$( 'li.shipping_options a' ).trigger( 'click' );
e.preventDefault();
} );
// actions on selected items
$( '#woosb_selected' ).on( 'click', 'span.remove', function() {
$( this ).parent().remove();
woosb_get_ids();
woosb_change_regular_price();
return false;
} );
// hide search result box if click outside
$( document ).on( 'click', function( e ) {
if ( $( e.target ).closest( $( '#woosb_results' ) ).length == 0 ) {
$( '#woosb_results' ).hide();
}
} );
// arrange
woosb_arrange();
$( document ).on( 'woosb_drag_event', function() {
woosb_get_ids();
} );
// hide updated
setTimeout( function() {
$( '.woosb_updated_price' ).slideUp();
}, 3000 );
// ajax update price
$( '.woosb-update-price-btn' ).on( 'click', function( e ) {
var this_btn = $( this );
if ( !this_btn.hasClass( 'disabled' ) ) {
this_btn.addClass( 'disabled' );
var count = 0;
(
function woosb_update_price() {
var data = {
action: 'woosb_update_price',
woosb_nonce: woosb_vars.woosb_nonce
};
setTimeout( function() {
jQuery.post( ajaxurl, data, function( response ) {
var response_num = Number( response );
if ( response_num != 0 ) {
count += response_num;
woosb_update_price();
$( '.woosb_updated_price_ajax' ).html( 'Updating... ' + count );
} else {
$( '.woosb_updated_price_ajax' ).html( 'Finished! ' + count + ' updated.' );
this_btn.removeClass( 'disabled' );
}
} );
}, 1000 );
}
)();
}
e.preventDefault();
} );
// metabox
$( '#woosb_meta_box_update_price' ).on( 'click', function( e ) {
var btn = $( this );
if ( !btn.hasClass( 'disabled' ) ) {
var btn_text = btn.val();
var product_id = btn.attr( 'data-id' );
btn.val( btn_text + '...' ).addClass( 'disabled' );
$( '#woosb_meta_box_update_price_result' ).html( '' ).prepend( '<li>Start!</li>' );
var count = 0;
(
function woosb_metabox_update_price() {
var data = {
action: 'woosb_metabox_update_price',
product_id: product_id,
count: count,
woosb_nonce: woosb_vars.woosb_nonce
};
setTimeout( function() {
jQuery.post( ajaxurl, data, function( response ) {
if ( response != 0 ) {
$( '#woosb_meta_box_update_price_result' ).prepend( response );
count ++;
woosb_metabox_update_price();
} else {
$( '#woosb_meta_box_update_price_result' ).prepend( '<li>Finished!</li>' );
btn.val( btn_text ).removeClass( 'disabled' );
}
} );
}, 100 );
}
)();
}
} );
function woosb_arrange() {
$( '#woosb_selected li' ).arrangeable( {
dragEndEvent: 'woosb_drag_event',
dragSelector: '.move'
} );
}
function woosb_get_ids() {
var listId = new Array();
$( '#woosb_selected li' ).each( function() {
listId.push( $( this ).data( 'id' ) + '/' + $( this ).find( 'input' ).val() );
} );
if ( listId.length > 0 ) {
$( '#woosb_ids' ).val( listId.join( ',' ) );
} else {
$( '#woosb_ids' ).val( '' );
}
}
function woosb_active_settings() {
if ( $( '#product-type' ).val() == 'woosb' ) {
$( 'li.general_tab' ).addClass( 'show_if_woosb' );
$( '#general_product_data .pricing' ).addClass( 'show_if_woosb' );
$( '._tax_status_field' ).closest( '.options_group' ).addClass( 'show_if_woosb' );
$( '#_downloadable' ).closest( 'label' ).addClass( 'show_if_woosb' ).removeClass( 'show_if_simple' );
$( '#_virtual' ).closest( 'label' ).addClass( 'show_if_woosb' ).removeClass( 'show_if_simple' );
$( '.show_if_external' ).hide();
$( '.show_if_simple' ).show();
$( '.show_if_woosb' ).show();
$( '.product_data_tabs li' ).removeClass( 'active' );
$( '.product_data_tabs li.woosb_tab' ).addClass( 'active' );
$( '.panel-wrap .panel' ).hide();
$( '#woosb_settings' ).show();
if ( $( '#woosb_optional_products' ).is( ':checked' ) ) {
$( '.woosb_tr_show_if_optional_products' ).show();
} else {
$( '.woosb_tr_show_if_optional_products' ).hide();
}
if ( $( '#woosb_disable_auto_price' ).is( ':checked' ) ) {
$( '.woosb_tr_show_if_auto_price' ).hide();
} else {
$( '.woosb_tr_show_if_auto_price' ).show();
}
if ( $( '#woosb_shipping_fee' ).val() == 'whole' ) {
$( '#woosb_set_shipping_class' ).show();
} else {
$( '#woosb_set_shipping_class' ).hide();
}
woosb_change_regular_price();
woosb_set_min_max();
} else {
$( 'li.general_tab' ).removeClass( 'show_if_woosb' );
$( '#general_product_data .pricing' ).removeClass( 'show_if_woosb' );
$( '._tax_status_field' ).closest( '.options_group' ).removeClass( 'show_if_woosb' );
$( '#_downloadable' ).closest( 'label' ).removeClass( 'show_if_woosb' ).addClass( 'show_if_simple' );
$( '#_virtual' ).closest( 'label' ).removeClass( 'show_if_woosb' ).addClass( 'show_if_simple' );
$( '#_regular_price' ).prop( 'readonly', false );
$( '#_sale_price' ).prop( 'readonly', false );
if ( $( '#product-type' ).val() != 'grouped' ) {
$( '.general_tab' ).show();
}
if ( $( '#product-type' ).val() == 'simple' ) {
$( '#_downloadable' ).closest( 'label' ).show();
$( '#_virtual' ).closest( 'label' ).show();
}
}
}
function woosb_set_min_max() {
$( '#woosb_selected li' ).each( function() {
var self = $(this),
product_input = self.find('input');
product_input.attr("min", self.data("min"));
product_input.attr("max", self.data("max"));
product_input.attr("step", self.data("step"));
} );
}
function woosb_change_regular_price() {
var total = 0;
var total_max = 0;
$( '#woosb_selected li' ).each( function() {
total += $( this ).data( 'price' ) * $( this ).find( 'input' ).val();
total_max += $( this ).data( 'price-max' ) * $( this ).find( 'input' ).val();
} );
total = accounting.formatMoney( total, '', woosb_vars.price_decimals, woosb_vars.price_thousand_separator, woosb_vars.price_decimal_separator );
total_max = accounting.formatMoney( total_max, '', woosb_vars.price_decimals, woosb_vars.price_thousand_separator, woosb_vars.price_decimal_separator );
if ( total == total_max ) {
$( '#woosb_regular_price' ).html( total );
} else {
$( '#woosb_regular_price' ).html( total + ' - ' + total_max );
}
if ( !$( '#woosb_disable_auto_price' ).is( ':checked' ) ) {
$( '#_regular_price' ).prop( 'readonly', true ).val( total ).trigger( 'change' );
$( '#_sale_price' ).prop( 'readonly', true );
}
}
function woosb_ajax_get_data() {
// ajax search product
woosb_timeout = null;
var data = {
action: 'woosb_get_search_results',
keyword: $( '#woosb_keyword' ).val(),
ids: $( '#woosb_ids' ).val(),
nonce: woosb_vars.nonce
};
jQuery.post( ajaxurl, data, function( response ) {
$( '#woosb_results' ).show();
$( '#woosb_results' ).html( response );
$( '#woosb_loading' ).hide();
} );
}
} );
jQuery(document).ready(function($) {
var woosb_timeout = null;
// options page
woosb_active_options();
$('select[name="_woosb_change_price"]').on('change', function() {
woosb_active_options();
});
// product page
woosb_active_settings();
$('#product-type').on('change', function() {
woosb_active_settings();
});
// hide search result box by default
$('#woosb_results').hide();
$('#woosb_loading').hide();
// total price
if ($('#product-type').val() == 'woosb') {
woosb_change_regular_price();
}
// set regular price
$('#woosb_set_regular_price').on('click', function() {
if ($('#woosb_disable_auto_price').is(':checked')) {
$('li.general_tab a').trigger('click');
$('#_regular_price').focus();
} else {
alert('You must disable auto calculate price first!');
}
});
// set optional
$('#woosb_optional_products').on('click', function() {
if ($(this).is(':checked')) {
$('.woosb_tr_show_if_optional_products').show();
} else {
$('.woosb_tr_show_if_optional_products').hide();
}
});
// checkbox
$('#woosb_disable_auto_price').on('change', function() {
if ($(this).is(':checked')) {
$('#_regular_price').prop('readonly', false);
$('#_sale_price').prop('readonly', false);
$('.woosb_tr_show_if_auto_price').hide();
} else {
$('#_regular_price').prop('readonly', true);
$('#_sale_price').prop('readonly', true);
$('.woosb_tr_show_if_auto_price').show();
}
if ($('#product-type').val() == 'woosb') {
woosb_change_regular_price();
}
});
// search input
$('#woosb_keyword').keyup(function() {
if ($('#woosb_keyword').val() != '') {
$('#woosb_loading').show();
if (woosb_timeout != null) {
clearTimeout(woosb_timeout);
}
woosb_timeout = setTimeout(woosb_ajax_get_data, 300);
return false;
}
});
// actions on search result items
$('#woosb_results').on('click', 'li', function() {
$(this).children('span.remove').attr('aria-label', 'Remove').html('×');
$('#woosb_selected ul').append($(this));
$('#woosb_results').hide();
$('#woosb_keyword').val('');
woosb_get_ids();
woosb_change_regular_price();
woosb_arrange();
return false;
});
// change qty of each item
$('#woosb_selected').on('keyup change', '.qty input', function() {
woosb_get_ids();
woosb_change_regular_price();
return false;
});
// actions on selected items
$('#woosb_selected').on('click', 'span.remove', function() {
$(this).parent().remove();
woosb_get_ids();
woosb_change_regular_price();
return false;
});
// hide search result box if click outside
$(document).on('click', function(e) {
if ($(e.target).closest($('#woosb_results')).length == 0) {
$('#woosb_results').hide();
}
});
// arrange
woosb_arrange();
$(document).on('woosb_drag_event', function() {
woosb_get_ids();
});
// hide updated
setTimeout(function() {
$('.woosb_updated_price').slideUp();
}, 3000);
// ajax update price
$('.woosb-update-price-btn').on('click', function(e) {
var this_btn = $(this);
if (!this_btn.hasClass('disabled')) {
this_btn.addClass('disabled');
var count = 0;
(
function woosb_update_price() {
var data = {
action: 'woosb_update_price',
woosb_nonce: woosb_vars.woosb_nonce,
};
setTimeout(function() {
jQuery.post(ajaxurl, data, function(response) {
var response_num = Number(response);
if (response_num != 0) {
count += response_num;
woosb_update_price();
$('.woosb_updated_price_ajax').html('Updating... ' + count);
} else {
$('.woosb_updated_price_ajax').
html('Finished! ' + count + ' updated.');
this_btn.removeClass('disabled');
}
});
}, 1000);
}
)();
}
e.preventDefault();
});
// metabox
$('#woosb_meta_box_update_price').on('click', function(e) {
var btn = $(this);
if (!btn.hasClass('disabled')) {
var btn_text = btn.val();
var product_id = btn.attr('data-id');
btn.val(btn_text + '...').addClass('disabled');
$('#woosb_meta_box_update_price_result').
html('').
prepend('<li>Start!</li>');
var count = 0;
(
function woosb_metabox_update_price() {
var data = {
action: 'woosb_metabox_update_price',
product_id: product_id,
count: count,
woosb_nonce: woosb_vars.woosb_nonce,
};
setTimeout(function() {
jQuery.post(ajaxurl, data, function(response) {
if (response != 0) {
$('#woosb_meta_box_update_price_result').prepend(response);
count++;
woosb_metabox_update_price();
} else {
$('#woosb_meta_box_update_price_result').
prepend('<li>Finished!</li>');
btn.val(btn_text).removeClass('disabled');
}
});
}, 100);
}
)();
}
});
function woosb_arrange() {
$('#woosb_selected li').arrangeable({
dragEndEvent: 'woosb_drag_event',
dragSelector: '.move',
});
}
function woosb_get_ids() {
var listId = new Array();
$('#woosb_selected li').each(function() {
listId.push($(this).data('id') + '/' + $(this).find('input').val());
});
if (listId.length > 0) {
$('#woosb_ids').val(listId.join(','));
} else {
$('#woosb_ids').val('');
}
}
function woosb_active_options() {
if ($('select[name="_woosb_change_price"]').val() == 'yes_custom') {
$('input[name="_woosb_change_price_custom"]').show();
} else {
$('input[name="_woosb_change_price_custom"]').hide();
}
}
function woosb_active_settings() {
if ($('#product-type').val() == 'woosb') {
$('li.general_tab').addClass('show_if_woosb');
$('#general_product_data .pricing').addClass('show_if_woosb');
$('._tax_status_field').
closest('.options_group').
addClass('show_if_woosb');
$('#_downloadable').
closest('label').
addClass('show_if_woosb').
removeClass('show_if_simple');
$('#_virtual').
closest('label').
addClass('show_if_woosb').
removeClass('show_if_simple');
$('.show_if_external').hide();
$('.show_if_simple').show();
$('.show_if_woosb').show();
$('.product_data_tabs li').removeClass('active');
$('.product_data_tabs li.woosb_tab').addClass('active');
$('.panel-wrap .panel').hide();
$('#woosb_settings').show();
if ($('#woosb_optional_products').is(':checked')) {
$('.woosb_tr_show_if_optional_products').show();
} else {
$('.woosb_tr_show_if_optional_products').hide();
}
if ($('#woosb_disable_auto_price').is(':checked')) {
$('.woosb_tr_show_if_auto_price').hide();
} else {
$('.woosb_tr_show_if_auto_price').show();
}
woosb_change_regular_price();
} else {
$('li.general_tab').removeClass('show_if_woosb');
$('#general_product_data .pricing').removeClass('show_if_woosb');
$('._tax_status_field').
closest('.options_group').
removeClass('show_if_woosb');
$('#_downloadable').
closest('label').
removeClass('show_if_woosb').
addClass('show_if_simple');
$('#_virtual').
closest('label').
removeClass('show_if_woosb').
addClass('show_if_simple');
$('#_regular_price').prop('readonly', false);
$('#_sale_price').prop('readonly', false);
if ($('#product-type').val() != 'grouped') {
$('.general_tab').show();
}
if ($('#product-type').val() == 'simple') {
$('#_downloadable').closest('label').show();
$('#_virtual').closest('label').show();
}
}
}
function woosb_round(value, decimals) {
return Number(Math.round(value + 'e' + decimals) + 'e-' + decimals);
}
function woosb_format_money(number, places, symbol, thousand, decimal) {
number = number || 0;
places = !isNaN(places = Math.abs(places)) ? places : 2;
symbol = symbol !== undefined ? symbol : '$';
thousand = thousand || ',';
decimal = decimal || '.';
var negative = number < 0 ? '-' : '',
i = parseInt(
number = woosb_round(Math.abs(+number || 0), places).
toFixed(places),
10) + '',
j = 0;
if (i.length > 3) {
j = i.length % 3;
}
return symbol + negative + (
j ? i.substr(0, j) + thousand : ''
) + i.substr(j).replace(/(\d{3})(?=\d)/g, '$1' + thousand) + (
places ?
decimal +
woosb_round(Math.abs(number - i), places).toFixed(places).slice(2) :
''
);
}
function woosb_change_regular_price() {
var total = 0;
var total_max = 0;
$('#woosb_selected li').each(function() {
total += $(this).data('price') * $(this).find('input').val();
total_max += $(this).data('price-max') * $(this).find('input').val();
});
total = woosb_format_money(total, woosb_vars.price_decimals, '',
woosb_vars.price_thousand_separator,
woosb_vars.price_decimal_separator);
total_max = woosb_format_money(total_max, woosb_vars.price_decimals, '',
woosb_vars.price_thousand_separator,
woosb_vars.price_decimal_separator);
if (total == total_max) {
$('#woosb_regular_price').html(total);
} else {
$('#woosb_regular_price').html(total + ' - ' + total_max);
}
if (!$('#woosb_disable_auto_price').is(':checked')) {
$('#_regular_price').prop('readonly', true).val(total).trigger('change');
$('#_sale_price').prop('readonly', true);
}
}
function woosb_ajax_get_data() {
// ajax search product
woosb_timeout = null;
var data = {
action: 'woosb_get_search_results',
keyword: $('#woosb_keyword').val(),
ids: $('#woosb_ids').val(),
};
jQuery.post(ajaxurl, data, function(response) {
$('#woosb_results').show();
$('#woosb_results').html(response);
$('#woosb_loading').hide();
});
}
});

822
assets/js/frontend.js

<
@ -1,292 +1,534 @@
'use strict';
jQuery( document ).ready( function( $ ) {
if ( !$( '.woosb-wrap' ).length ) {
return;
}
var $woosb_wrap = $( '.woosb-wrap' ).eq( 0 );
var $woosb_products = $( '.woosb-products' ).eq( 0 );
var $woosb_ids = $( '.woosb-ids' ).eq( 0 );
var $woosb_total = $( '.woosb-total' ).eq( 0 );
var $woosb_btn = $woosb_ids.closest( 'form.cart' ).find( '.single_add_to_cart_button' );
if ( !$woosb_btn.length ) {
$woosb_btn = $woosb_wrap.closest( '.summary' ).find( '.single_add_to_cart_button' );
}
if ( !$woosb_btn.length ) {
console.log( 'Have an issue with your template, so might WPC Product Bundles doesn\'t work completely. Please contact us via email contact@wpclever.net to get the help.' );
}
woosb_check_ready();
$( document ).on( 'found_variation', function( e, t ) {
var $woosb_product = $( e['target'] ).closest( '.woosb-product' );
if ( t['image']['url'] && t['image']['srcset'] ) {
// change image
$woosb_product.find( '.woosb-thumb-ori' ).hide();
$woosb_product.find( '.woosb-thumb-new' ).html( '<img src="' + t['image']['url'] + '" srcset="' + t['image']['srcset'] + '"/>' ).show();
}
if ( t['price_html'] ) {
// change price
$woosb_product.find( '.woosb-price-ori' ).hide();
$woosb_product.find( '.woosb-price-new' ).html( t['price_html'] ).show();
}
if ( t['is_purchasable'] ) {
// change stock notice
if ( t['is_in_stock'] ) {
$woosb_products.next( 'p.stock' ).show();
$woosb_product.attr( 'data-id', t['variation_id'] );
$woosb_product.attr( 'data-price', t['display_price'] );
} else {
$woosb_products.next( 'p.stock' ).hide();
$woosb_product.attr( 'data-id', 0 );
$woosb_product.attr( 'data-price', 0 );
}
// change availability text
$( e['target'] ).closest( '.variations_form' ).find( 'p.stock' ).remove();
if ( t['availability_html'] != '' ) {
$( e['target'] ).closest( '.variations_form' ).append( t['availability_html'] );
}
}
if ( t['variation_description'] != '' ) {
$woosb_product.find( '.woosb-variation-description' ).html( t['variation_description'] ).show();
} else {
$woosb_product.find( '.woosb-variation-description' ).html( '' ).hide();
}
if ( woosb_vars.change_image == 'no' ) {
// prevent changing the main image
$( e['target'] ).closest( '.variations_form' ).trigger( 'reset_image' );
}
woosb_check_ready();
} );
$( document ).on( 'reset_data', function( e ) {
var $woosb_product = $( e['target'] ).closest( '.woosb-product' );
// reset thumb
$woosb_product.find( '.woosb-thumb-new' ).hide();
$woosb_product.find( '.woosb-thumb-ori' ).show();
// reset price
$woosb_product.find( '.woosb-price-new' ).hide();
$woosb_product.find( '.woosb-price-ori' ).show();
// reset stock
$( e['target'] ).closest( '.variations_form' ).find( 'p.stock' ).remove();
// reset desc
$woosb_product.find( '.woosb-variation-description' ).html( '' ).hide();
// reset id
$woosb_product.attr( 'data-id', 0 );
$woosb_product.attr( 'data-price', 0 );
woosb_check_ready();
} );
$woosb_btn.on( 'click touch', function( e ) {
if ( $( this ).hasClass( 'woosb-disabled' ) ) {
if ( $( this ).hasClass( 'woosb-selection' ) ) {
alert( woosb_vars.alert_selection );
} else if ( $( this ).hasClass( 'woosb-empty' ) ) {
alert( woosb_vars.alert_empty );
} else if ( $( this ).hasClass( 'woosb-min' ) ) {
alert( woosb_vars.alert_min.replace( '[min]', $woosb_products.attr( 'data-min' ) ) );
} else if ( $( this ).hasClass( 'woosb-max' ) ) {
alert( woosb_vars.alert_max.replace( '[max]', $woosb_products.attr( 'data-max' ) ) );
}
e.preventDefault();
} else {
jQuery.ajax( {
url: woosb_vars.ajax_url,
type: "POST",
data: {
action: 'woosb_custom_data',
ids: $woosb_ids.val(),
nonce: woosb_vars.nonce
},
async: false
} );
}
} );
$woosb_products.on( 'keyup change', '.woosb-qty input', function() {
var qty = parseFloat( $( this ).val() );
var min_qty = parseInt( $( this ).attr( 'min' ) );
var max_qty = parseInt( $( this ).attr( 'max' ) );
if ( !isNaN( min_qty ) && (
qty < min_qty
) ) {
qty = min_qty;
}
if ( !isNaN( max_qty ) && (
qty > max_qty
) ) {
qty = max_qty;
}
$( this ).val( qty );
$( this ).closest( '.woosb-product' ).attr( 'data-qty', qty );
woosb_check_ready();
} );
function woosb_check_ready() {
var total = 0;
var is_selection = false;
var is_empty = true;
var is_min = false;
var is_max = false;
$woosb_products.find( '.woosb-product' ).each( function() {
if ( (
$( this ).attr( 'data-qty' ) > 0
) && (
$( this ).attr( 'data-id' ) == 0
) ) {
is_selection = true;
}
if ( $( this ).attr( 'data-qty' ) > 0 ) {
is_empty = false;
total += parseFloat( $( this ).attr( 'data-qty' ) );
}
} );
// check min
if ( (
$woosb_products.attr( 'data-optional' ) == 'yes'
) && $woosb_products.attr( 'data-min' ) && (
total < parseInt( $woosb_products.attr( 'data-min' ) )
) ) {
is_min = true;
}
// check max
if ( (
$woosb_products.attr( 'data-optional' ) == 'yes'
) && $woosb_products.attr( 'data-max' ) && (
total > parseInt( $woosb_products.attr( 'data-max' ) )
) ) {
is_max = true;
}
if ( is_selection || is_empty || is_min || is_max ) {
$woosb_btn.addClass( 'woosb-disabled' );
if ( is_selection ) {
$woosb_btn.addClass( 'woosb-selection' );
} else {
$woosb_btn.removeClass( 'woosb-selection' );
}
if ( is_empty ) {
$woosb_btn.addClass( 'woosb-empty' );
} else {
$woosb_btn.removeClass( 'woosb-empty' );
}
if ( is_min ) {
$woosb_btn.addClass( 'woosb-min' );
} else {
$woosb_btn.removeClass( 'woosb-min' );
}
if ( is_max ) {
$woosb_btn.addClass( 'woosb-max' );
} else {
$woosb_btn.removeClass( 'woosb-max' );
}
} else {
$woosb_btn.removeClass( 'woosb-disabled woosb-selection woosb-empty woosb-min woosb-max' );
}
woosb_calc_price();
woosb_save_ids();
}
function woosb_calc_price() {
var total = 0;
var total_html = '';
$woosb_products.find( '.woosb-product' ).each( function() {
if ( $( this ).attr( 'data-price' ) > 0 ) {
total += $( this ).attr( 'data-price' ) * $( this ).attr( 'data-qty' );
}
} );
if ( (
$woosb_products.attr( 'data-discount' ) > 0
) && (
$woosb_products.attr( 'data-discount' ) < 100
) ) {
total = total * (
100 - $woosb_products.attr( 'data-discount' )
) / 100;
}
var total_formatted = woosb_format_money( total, woosb_vars.price_decimals, '', woosb_vars.price_thousand_separator, woosb_vars.price_decimal_separator );
switch ( woosb_vars.price_format ) {
case '%1$s%2$s':
//left
total_html += woosb_vars.currency_symbol + '' + total_formatted;
break;
case '%1$s %2$s':
//left with space
total_html += woosb_vars.currency_symbol + ' ' + total_formatted;
break;
case '%2$s%1$s':
//right
total_html += total_formatted + '' + woosb_vars.currency_symbol;
break;
case '%2$s %1$s':
//right with space
total_html += total_formatted + ' ' + woosb_vars.currency_symbol;
break;
default:
//default
total_html += woosb_vars.currency_symbol + '' + total_formatted;
}
if ( (
parseFloat( $woosb_products.attr( 'data-discount' ) ) > 0
) && (
parseFloat( $woosb_products.attr( 'data-discount' ) ) < 100
) ) {
var saved = woosb_round( parseFloat( $woosb_products.attr( 'data-discount' ) ) );
total_html += ' (' + woosb_vars.price_saved + ' ' + saved + '%)';
}
$woosb_total.html( woosb_vars.bundle_price_text + ' ' + total_html ).slideDown();
$( document ).trigger( 'woosb_calc_price', [total, total_formatted, total_html] );
}
function woosb_save_ids() {
var woosb_ids = Array();
$woosb_products.find( '.woosb-product' ).each( function() {
if ( (
$( this ).attr( 'data-id' ) > 0
) && (
$( this ).attr( 'data-qty' ) > 0
) ) {
woosb_ids.push( $( this ).attr( 'data-id' ) + '/' + $( this ).attr( 'data-qty' ) );
}
} );
$woosb_ids.val( woosb_ids.join( ',' ) );
}
function woosb_round( num ) {
return + (
Math.round( num + "e+2" ) + "e-2"
);
}
function woosb_format_money( number, places, symbol, thousand, decimal ) {
number = number || 0;
places = !isNaN( places = Math.abs( places ) ) ? places : 2;
symbol = symbol !== undefined ? symbol : "$";
thousand = thousand || ",";
decimal = decimal || ".";
var negative = number < 0 ? "-" : "",
i = parseInt( number = Math.abs( + number || 0 ).toFixed( places ), 10 ) + "",
j = 0;
if ( i.length > 3 ) {
j = i.length % 3;
}
return symbol + negative + (
j ? i.substr( 0, j ) + thousand : ""
) + i.substr( j ).replace( /(\d{3})(?=\d)/g, "$1" + thousand ) + (
places ? decimal + Math.abs( number - i ).toFixed( places ).slice( 2 ) : ""
);
}
} );
var woosb_timeout = null;
jQuery(document).ready(function($) {
if (!$('.woosb-wrap').length) {
return;
}
$('.woosb-wrap').each(function() {
woosb_init($(this).closest(woosb_vars.wrap_selector));
});
});
jQuery(document).on('click touch', '.woosb-plus, .woosb-minus', function() {
// get values
var $number = jQuery(this).closest('.woosb-qty').find('.qty'),
number_val = parseFloat($number.val()),
max = parseFloat($number.attr('max')),
min = parseFloat($number.attr('min')),
step = $number.attr('step');
// format values
if (!number_val || number_val === '' || number_val === 'NaN') {
number_val = 0;
}
if (max === '' || max === 'NaN') {
max = '';
}
if (min === '' || min === 'NaN') {
min = 0;
}
if (step === 'any' || step === '' || step === undefined ||
parseFloat(step) === 'NaN') {
step = 1;
}
// change the value
if (jQuery(this).is('.woosb-plus')) {
if (max && (
max == number_val || number_val > max
)) {
$number.val(max);
} else {
if (woosb_is_int(step)) {
$number.val(number_val + parseFloat(step));
} else {
$number.val((
number_val + parseFloat(step)
).toFixed(1));
}
}
} else {
if (min && (
min == number_val || number_val < min
)) {
$number.val(min);
} else if (number_val > 0) {
if (woosb_is_int(step)) {
$number.val(number_val - parseFloat(step));
} else {
$number.val((
number_val - parseFloat(step)
).toFixed(1));
}
}
}
// trigger change event
$number.trigger('change');
});
jQuery(document).on('found_variation', function(e, t) {
var $woosb_wrap = jQuery(e['target']).closest(woosb_vars.wrap_selector);
var $woosb_products = jQuery(e['target']).closest('.woosb-products');
var $woosb_product = jQuery(e['target']).closest('.woosb-product');
if ($woosb_product.length) {
if (t['image']['url'] && t['image']['srcset']) {
// change image
$woosb_product.find('.woosb-thumb-ori').hide();
$woosb_product.find('.woosb-thumb-new').
html('<img src="' + t['image']['url'] + '" srcset="' +
t['image']['srcset'] + '"/>').
show();
}
if (t['price_html']) {
// change price
$woosb_product.find('.woosb-price-ori').hide();
$woosb_product.find('.woosb-price-new').html(t['price_html']).show();
}
if (t['is_purchasable']) {
// change the price
$woosb_product.attr('data-price', t['display_price']);
// change stock notice
if (t['is_in_stock']) {
$woosb_products.next('p.stock').show();
$woosb_product.attr('data-id', t['variation_id']);
} else {
$woosb_products.next('p.stock').hide();
$woosb_product.attr('data-id', 0);
}
// change availability text
jQuery(e['target']).closest('.variations_form').find('p.stock').remove();
if (t['availability_html'] !== '') {
jQuery(e['target']).
closest('.variations_form').
append(t['availability_html']);
}
}
if (t['variation_description'] !== '') {
$woosb_product.find('.woosb-variation-description').
html(t['variation_description']).
show();
} else {
$woosb_product.find('.woosb-variation-description').html('').hide();
}
if (woosb_vars.change_image === 'no') {
// prevent changing the main image
jQuery(e['target']).closest('.variations_form').trigger('reset_image');
}
jQuery(document).trigger('woosb_found_variation', [$woosb_product, t]);
woosb_init($woosb_wrap);
}
});
jQuery(document).on('reset_data', function(e) {
var $woosb_wrap = jQuery(e['target']).closest(woosb_vars.wrap_selector);
var $woosb_product = jQuery(e['target']).closest('.woosb-product');
if ($woosb_product.length) {
// reset thumb
$woosb_product.find('.woosb-thumb-new').hide();
$woosb_product.find('.woosb-thumb-ori').show();
// reset price
$woosb_product.find('.woosb-price-new').hide();
$woosb_product.find('.woosb-price-ori').show();
// reset stock
jQuery(e['target']).closest('.variations_form').find('p.stock').remove();
// reset desc
$woosb_product.find('.woosb-variation-description').html('').hide();
// reset id
$woosb_product.attr('data-id', 0);
// reset price
$woosb_product.attr('data-price', 0);
jQuery(document).trigger('woosb_reset_data', [$woosb_product]);
woosb_init($woosb_wrap);
}
});
jQuery(document).on('click touch', '.single_add_to_cart_button', function(e) {
var $this = jQuery(this);
var $woosb_wrap = $this.closest(woosb_vars.wrap_selector);
var $woosb_products = $woosb_wrap.find('.woosb-products');
if ($this.hasClass('woosb-disabled')) {
if ($this.hasClass('woosb-selection')) {
alert(woosb_vars.alert_selection);
} else if ($this.hasClass('woosb-empty')) {
alert(woosb_vars.alert_empty);
} else if ($this.hasClass('woosb-min')) {