(function (){
'use strict';
jQuery.extend({
rightpress: {
sanitize_json_response: function(response){
try {
jQuery.parseJSON(response);
return response;
}
catch (e){
var valid_response=response.match(/{"result.*]}/);
if(valid_response!==null){
return valid_response[0];
}}
},
parse_json_response: function (response, return_raw_data){
var return_raw_data=(typeof return_raw_data!=='undefined') ?  return_raw_data:false;
try {
var parsed=jQuery.parseJSON(response);
return return_raw_data ? response:parsed;
}
catch (e){
var regex=return_raw_data ? /{"result.*"}]}/:/{"result.*"}/;
var valid_response=response.match(regex);
if(valid_response!==null){
response=valid_response[0];
}}
return return_raw_data ? response:jQuery.parseJSON(response);
},
add_nested_object_value: function (object, path, value){
var last_key_index=path.length - 1;
for (var i=0; i < last_key_index; ++ i){
var key=jQuery.isNumeric(path[i]) ? parseInt(path[i]):path[i];
if(jQuery.isNumeric(path[i + 1])){
if(typeof object[key]==='undefined'){
object[key]=[];
}}
else if(!(key in object)){
object[key]={};}
object=object[key];
}
object[path[last_key_index]]=value;
},
object_key_check: function (object ){
var keys=Array.prototype.slice.call(arguments, 1);
var current=object;
for (var i=0; i < keys.length; i++){
if(typeof current[keys[i]]==='undefined'){
return false;
}
if(i < (keys.length - 1)&&typeof current[keys[i]]!=='object'){
return false;
}
current=current[keys[i]];
}
return true;
},
clear_field_value: function (field){
if(field.is('select')){
field.prop('selectedIndex', 0);
if(field.hasClass('rightpress_select2')){
field.val('').change();
}}
else if(field.is(':radio, :checkbox')){
field.removeAttr('checked');
}else{
field.val('');
}},
field_is_multiselect: function (field){
return (field.is('select')&&typeof field.attr('multiple')!=='undefined'&&field.attr('multiple')!==false);
},
field_is_empty: function (field){
if(field.length > 1){
return !field.filter(':checked').length;
}
else if(field.length < 1){
return true;
}else{
var value=field.val();
if(jQuery.rightpress.field_is_multiselect(field)){
value=value||[];
return !value.length;
}
else if(field.is(':radio, :checkbox')){
return !field.is(':checked');
}else{
return (value===''||value===null||value===undefined);
}}
},
get_current_url_with_query_var: function(key, value){
var url=window.location.href;
var has_query=url.indexOf('?') > -1;
var operator=has_query ? '&':'?';
if(!has_query||(url.indexOf(('?' + key + '='))===-1&&url.indexOf(('&' + key + '='))===-1)){
url +=operator + key + '=' + value;
}
return url;
},
serialize_including_disabled: function(form, selector){
var disabled=form.find(':input:disabled').filter(selector).removeAttr('disabled');
var serialized=form.serialize();
disabled.attr('disabled', 'disabled');
return serialized;
},
escape_html: function(html){
return document.createElement('div').appendChild(document.createTextNode(html)).parentNode.innerHTML;
}}
});
}());
(function (){
'use strict';
var delay=(function(){
var timers={};
return function(callback, ms, unique){
clearTimeout(timers[unique]);
timers[unique]=setTimeout(callback, ms);
};})();
jQuery.fn.rightpress_live_product_update=function(params){
var self=this;
var form=this.closest('.product').find('form.cart');
var unique=Math.random().toString(36).slice(2);
form.find(':input').on('change keyup', function(){
queue();
});
form.on('rightpress_live_product_update_attach_input', function(event, element){
jQuery(element).find(':input').on('change keyup', function(){
queue();
});
});
form.on('found_variation, rightpress_live_product_update_trigger', function(){
queue();
});
queue();
function call(){
var form_data=form.serialize();
var product_id=params.product_id!==undefined ? params.product_id:form.find('button[type="submit"][name="add-to-cart"]').val();
if(product_id){
form_data +=(form_data!=='' ? '&':'') + 'rightpress_reference_product_id=' + product_id;
}
form.find('input, textarea, select').each(function(){
if(jQuery(this).is(':visible')&&typeof jQuery(this).prop('name')!=='undefined'){
form_data +=(form_data!=='' ? '&':'') + 'rightpress_complete_input_list[]=' + jQuery(this).prop('name');
}});
jQuery.ajax({
type: 'POST',
url: params.ajax_url,
context: self,
data: {
action: params.action,
data:   form_data
},
dataType: 'json',
dataFilter: jQuery.rightpress.sanitize_json_response,
beforeSend: params.before_send,
success: params.response_handler
});
}
function queue(){
delay(function(){
call();
}, 500, unique);
}};}());
jQuery(document).ready(function(){
'use strict';
jQuery('#rp_wcdpd_promotion_product_banners_container').rightpress_live_product_update({
ajax_url:   rp_wcdpd_promotion_product_banners_scripts_vars.ajaxurl,
action:     'rp_wcdpd_load_product_banner',
before_send: function(xhr){
var container=jQuery(this);
container.css('opacity', '0.25');
},
response_handler: function(response){
var container=jQuery(this);
if(typeof response==='object'&&typeof response.result!=='undefined'&&response.result==='success'&&response.display){
if(typeof container.data('rp_wcdpd_banners_hash')==='undefined'||container.data('rp_wcdpd_banners_hash')!==response.banners_hash){
container.html('');
jQuery.each(response.banners, function(banner_hash, banner){
container.append(banner.html);
});
container.data('rp_wcdpd_banners_hash', response.banners_hash);
container.show();
jQuery('body').trigger('rp_wcdpd_promotion_product_banners_updated', response);
}
container.css('opacity', '1.0');
}else{
container.hide();
container.removeData('rp_wcdpd_banners_hash');
}}
});
});
jQuery(document).ready(function(){
'use strict';
var inhibit_live_product_update=false;
jQuery('#rp_wcdpd_pricing_table_variation_container').rightpress_live_product_update({
ajax_url:   rp_wcdpd_promotion_volume_pricing_table_scripts_vars.ajaxurl,
action:     'rp_wcdpd_load_variation_pricing_table',
before_send: function(xhr){
if(inhibit_live_product_update){
xhr.abort();
inhibit_live_product_update=false;
return;
}
jQuery(this).css('opacity', '0.25');
},
response_handler: function(response){
if(typeof response==='object'&&typeof response.result!=='undefined'&&response.result==='success'&&response.display){
if(typeof jQuery(this).data('rp_wcdpd_html_hash')==='undefined'||jQuery(this).data('rp_wcdpd_html_hash')!==response.html_hash){
jQuery(this).html(response.html);
jQuery(this).data('rp_wcdpd_html_hash', response.html_hash);
jQuery(this).show();
set_up_pricing_table_controls();
jQuery('body').trigger('rp_wcdpd_volume_pricing_table_updated', response);
}
jQuery(this).css('opacity', '1.0');
}else{
jQuery(this).hide();
jQuery(this).removeData('rp_wcdpd_html_hash');
}}
});
function set_up_pricing_table_controls(){
jQuery('.rp_wcdpd_pricing_table_quantity[data-rp-wcdpd-from], .rp_wcdpd_pricing_table_product_price[data-rp-wcdpd-from]').on('click', function(){
inhibit_live_product_update=true;
jQuery('form.cart input[name="quantity"]').val(jQuery(this).data('rp-wcdpd-from')).change();
});
jQuery('.rp_wcdpd_pricing_table_product_name[data-rp-wcdpd-variation-attributes], .rp_wcdpd_pricing_table_product_price[data-rp-wcdpd-variation-attributes]').on('click', function(){
if(jQuery(this).data('rp-wcdpd-variation-attributes')===''){
return;
}
var attributes={};
var attributes_raw=jQuery(this).data('rp-wcdpd-variation-attributes').split('&');
jQuery.each(attributes_raw, function(index, attribute_raw){
var parts=attribute_raw.split('=');
attributes[parts[0]]=parts[1];
});
jQuery.each(attributes, function(attribute, value){
jQuery('form.cart .variations select[name="' + attribute + '"]').each(function(){
jQuery(this).val('').change();
});
});
jQuery.each(attributes, function(attribute, value){
jQuery('form.cart .variations select[name="' + attribute + '"]').each(function(){
var select=jQuery(this);
if(value!==''){
select.val(value);
}else{
select.find('option').each(function(){
if(jQuery(this).val()!==''){
select.val(jQuery(this).val());
return false;
}});
}
window.setTimeout(function(){
select.change();
}, 50);
});
});
});
jQuery('.rp_wcdpd_product_page_modal_link span').on('click', function(){
if(!jQuery('#rp_wcdpd_modal_overlay').length){
jQuery('body').append('<div id="rp_wcdpd_modal_overlay" class="rp_wcdpd_modal_overlay"></div>');
}
jQuery('#rp_wcdpd_modal_overlay').on('click', function(){
jQuery('#rp_wcdpd_modal_overlay').fadeOut();
jQuery('.rp_wcdpd_modal').fadeOut();
});
var pricing_table=jQuery(this).closest('.rp_wcdpd_product_page').parent().find('.rp_wcdpd_modal');
jQuery('#rp_wcdpd_modal_overlay').fadeIn();
pricing_table.css('top', '50%').css('left', '50%').css('margin-top', -pricing_table.outerHeight()/2).css('margin-left', -pricing_table.outerWidth()/2).fadeIn();
return false;
});
}
set_up_pricing_table_controls();
});