initial commit
This commit is contained in:
158
assets/js/admin/api-keys.js
Normal file
158
assets/js/admin/api-keys.js
Normal file
@ -0,0 +1,158 @@
|
||||
/*global jQuery, Backbone, _, woocommerce_admin_api_keys, wcSetClipboard, wcClearClipboard */
|
||||
(function( $ ) {
|
||||
|
||||
var APIView = Backbone.View.extend({
|
||||
/**
|
||||
* Element
|
||||
*
|
||||
* @param {Object} '#key-fields'
|
||||
*/
|
||||
el: $( '#key-fields' ),
|
||||
|
||||
/**
|
||||
* Events
|
||||
*
|
||||
* @type {Object}
|
||||
*/
|
||||
events: {
|
||||
'click input#update_api_key': 'saveKey'
|
||||
},
|
||||
|
||||
/**
|
||||
* Initialize actions
|
||||
*/
|
||||
initialize: function(){
|
||||
_.bindAll( this, 'saveKey' );
|
||||
},
|
||||
|
||||
/**
|
||||
* Init jQuery.BlockUI
|
||||
*/
|
||||
block: function() {
|
||||
$( this.el ).block({
|
||||
message: null,
|
||||
overlayCSS: {
|
||||
background: '#fff',
|
||||
opacity: 0.6
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
/**
|
||||
* Remove jQuery.BlockUI
|
||||
*/
|
||||
unblock: function() {
|
||||
$( this.el ).unblock();
|
||||
},
|
||||
|
||||
/**
|
||||
* Init TipTip
|
||||
*/
|
||||
initTipTip: function( css_class ) {
|
||||
$( document.body )
|
||||
.on( 'click', css_class, function( evt ) {
|
||||
evt.preventDefault();
|
||||
if ( ! document.queryCommandSupported( 'copy' ) ) {
|
||||
$( css_class ).parent().find( 'input' ).trigger( 'focus' ).trigger( 'select' );
|
||||
$( '#copy-error' ).text( woocommerce_admin_api_keys.clipboard_failed );
|
||||
} else {
|
||||
$( '#copy-error' ).text( '' );
|
||||
wcClearClipboard();
|
||||
wcSetClipboard( $( this ).prev( 'input' ).val().trim(), $( css_class ) );
|
||||
}
|
||||
} )
|
||||
.on( 'aftercopy', css_class, function() {
|
||||
$( '#copy-error' ).text( '' );
|
||||
$( css_class ).tipTip( {
|
||||
'attribute': 'data-tip',
|
||||
'activation': 'focus',
|
||||
'fadeIn': 50,
|
||||
'fadeOut': 50,
|
||||
'delay': 0
|
||||
} ).trigger( 'focus' );
|
||||
} )
|
||||
.on( 'aftercopyerror', css_class, function() {
|
||||
$( css_class ).parent().find( 'input' ).trigger( 'focus' ).trigger( 'select' );
|
||||
$( '#copy-error' ).text( woocommerce_admin_api_keys.clipboard_failed );
|
||||
} );
|
||||
},
|
||||
|
||||
/**
|
||||
* Create qrcode
|
||||
*
|
||||
* @param {string} consumer_key
|
||||
* @param {string} consumer_secret
|
||||
*/
|
||||
createQRCode: function( consumer_key, consumer_secret ) {
|
||||
$( '#keys-qrcode' ).qrcode({
|
||||
text: consumer_key + '|' + consumer_secret,
|
||||
width: 120,
|
||||
height: 120
|
||||
});
|
||||
},
|
||||
|
||||
/**
|
||||
* Save API Key using ajax
|
||||
*
|
||||
* @param {Object} e
|
||||
*/
|
||||
saveKey: function( e ) {
|
||||
e.preventDefault();
|
||||
|
||||
var self = this;
|
||||
|
||||
self.block();
|
||||
|
||||
Backbone.ajax({
|
||||
method: 'POST',
|
||||
dataType: 'json',
|
||||
url: woocommerce_admin_api_keys.ajax_url,
|
||||
data: {
|
||||
action: 'woocommerce_update_api_key',
|
||||
security: woocommerce_admin_api_keys.update_api_nonce,
|
||||
key_id: $( '#key_id', self.el ).val(),
|
||||
description: $( '#key_description', self.el ).val(),
|
||||
user: $( '#key_user', self.el ).val(),
|
||||
permissions: $( '#key_permissions', self.el ).val()
|
||||
},
|
||||
success: function( response ) {
|
||||
$( '.wc-api-message', self.el ).remove();
|
||||
|
||||
if ( response.success ) {
|
||||
var data = response.data;
|
||||
|
||||
$( 'h2, h3', self.el ).first().append( '<div class="wc-api-message updated"><p>' + data.message + '</p></div>' );
|
||||
|
||||
if ( 0 < data.consumer_key.length && 0 < data.consumer_secret.length ) {
|
||||
$( '#api-keys-options', self.el ).remove();
|
||||
$( 'p.submit', self.el ).empty().append( data.revoke_url );
|
||||
|
||||
var template = wp.template( 'api-keys-template' );
|
||||
|
||||
$( 'p.submit', self.el ).before( template({
|
||||
consumer_key: data.consumer_key,
|
||||
consumer_secret: data.consumer_secret
|
||||
}) );
|
||||
self.createQRCode( data.consumer_key, data.consumer_secret );
|
||||
self.initTipTip( '.copy-key' );
|
||||
self.initTipTip( '.copy-secret' );
|
||||
} else {
|
||||
$( '#key_description', self.el ).val( data.description );
|
||||
$( '#key_user', self.el ).val( data.user_id );
|
||||
$( '#key_permissions', self.el ).val( data.permissions );
|
||||
}
|
||||
} else {
|
||||
$( 'h2, h3', self.el )
|
||||
.first()
|
||||
.append( '<div class="wc-api-message error"><p>' + response.data.message + '</p></div>' );
|
||||
}
|
||||
|
||||
self.unblock();
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
new APIView();
|
||||
|
||||
})( jQuery );
|
1
assets/js/admin/api-keys.min.js
vendored
Normal file
1
assets/js/admin/api-keys.min.js
vendored
Normal file
@ -0,0 +1 @@
|
||||
!function(r){new(Backbone.View.extend({el:r("#key-fields"),events:{"click input#update_api_key":"saveKey"},initialize:function(){_.bindAll(this,"saveKey")},block:function(){r(this.el).block({message:null,overlayCSS:{background:"#fff",opacity:.6}})},unblock:function(){r(this.el).unblock()},initTipTip:function(i){r(document.body).on("click",i,function(e){e.preventDefault(),document.queryCommandSupported("copy")?(r("#copy-error").text(""),wcClearClipboard(),wcSetClipboard(r(this).prev("input").val().trim(),r(i))):(r(i).parent().find("input").trigger("focus").trigger("select"),r("#copy-error").text(woocommerce_admin_api_keys.clipboard_failed))}).on("aftercopy",i,function(){r("#copy-error").text(""),r(i).tipTip({attribute:"data-tip",activation:"focus",fadeIn:50,fadeOut:50,delay:0}).trigger("focus")}).on("aftercopyerror",i,function(){r(i).parent().find("input").trigger("focus").trigger("select"),r("#copy-error").text(woocommerce_admin_api_keys.clipboard_failed)})},createQRCode:function(e,i){r("#keys-qrcode").qrcode({text:e+"|"+i,width:120,height:120})},saveKey:function(e){e.preventDefault();var o=this;o.block(),Backbone.ajax({method:"POST",dataType:"json",url:woocommerce_admin_api_keys.ajax_url,data:{action:"woocommerce_update_api_key",security:woocommerce_admin_api_keys.update_api_nonce,key_id:r("#key_id",o.el).val(),description:r("#key_description",o.el).val(),user:r("#key_user",o.el).val(),permissions:r("#key_permissions",o.el).val()},success:function(e){var i,t;r(".wc-api-message",o.el).remove(),e.success?(i=e.data,r("h2, h3",o.el).first().append('<div class="wc-api-message updated"><p>'+i.message+"</p></div>"),0<i.consumer_key.length&&0<i.consumer_secret.length?(r("#api-keys-options",o.el).remove(),r("p.submit",o.el).empty().append(i.revoke_url),t=wp.template("api-keys-template"),r("p.submit",o.el).before(t({consumer_key:i.consumer_key,consumer_secret:i.consumer_secret})),o.createQRCode(i.consumer_key,i.consumer_secret),o.initTipTip(".copy-key"),o.initTipTip(".copy-secret")):(r("#key_description",o.el).val(i.description),r("#key_user",o.el).val(i.user_id),r("#key_permissions",o.el).val(i.permissions))):r("h2, h3",o.el).first().append('<div class="wc-api-message error"><p>'+e.data.message+"</p></div>"),o.unblock()}})}}))}(jQuery);
|
147
assets/js/admin/backbone-modal.js
Normal file
147
assets/js/admin/backbone-modal.js
Normal file
@ -0,0 +1,147 @@
|
||||
/*global jQuery, Backbone, _ */
|
||||
( function( $, Backbone, _ ) {
|
||||
'use strict';
|
||||
|
||||
/**
|
||||
* WooCommerce Backbone Modal plugin
|
||||
*
|
||||
* @param {object} options
|
||||
*/
|
||||
$.fn.WCBackboneModal = function( options ) {
|
||||
return this.each( function() {
|
||||
( new $.WCBackboneModal( $( this ), options ) );
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* Initialize the Backbone Modal
|
||||
*
|
||||
* @param {object} element [description]
|
||||
* @param {object} options [description]
|
||||
*/
|
||||
$.WCBackboneModal = function( element, options ) {
|
||||
// Set settings
|
||||
var settings = $.extend( {}, $.WCBackboneModal.defaultOptions, options );
|
||||
|
||||
if ( settings.template ) {
|
||||
new $.WCBackboneModal.View({
|
||||
target: settings.template,
|
||||
string: settings.variable
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Set default options
|
||||
*
|
||||
* @type {object}
|
||||
*/
|
||||
$.WCBackboneModal.defaultOptions = {
|
||||
template: '',
|
||||
variable: {}
|
||||
};
|
||||
|
||||
/**
|
||||
* Create the Backbone Modal
|
||||
*
|
||||
* @return {null}
|
||||
*/
|
||||
$.WCBackboneModal.View = Backbone.View.extend({
|
||||
tagName: 'div',
|
||||
id: 'wc-backbone-modal-dialog',
|
||||
_target: undefined,
|
||||
_string: undefined,
|
||||
events: {
|
||||
'click .modal-close': 'closeButton',
|
||||
'click #btn-ok' : 'addButton',
|
||||
'touchstart #btn-ok': 'addButton',
|
||||
'keydown' : 'keyboardActions'
|
||||
},
|
||||
resizeContent: function() {
|
||||
var $content = $( '.wc-backbone-modal-content' ).find( 'article' );
|
||||
var max_h = $( window ).height() * 0.75;
|
||||
|
||||
$content.css({
|
||||
'max-height': max_h + 'px'
|
||||
});
|
||||
},
|
||||
initialize: function( data ) {
|
||||
var view = this;
|
||||
this._target = data.target;
|
||||
this._string = data.string;
|
||||
_.bindAll( this, 'render' );
|
||||
this.render();
|
||||
|
||||
$( window ).on( 'resize', function() {
|
||||
view.resizeContent();
|
||||
});
|
||||
},
|
||||
render: function() {
|
||||
var template = wp.template( this._target );
|
||||
|
||||
this.$el.append(
|
||||
template( this._string )
|
||||
);
|
||||
|
||||
$( document.body ).css({
|
||||
'overflow': 'hidden'
|
||||
}).append( this.$el );
|
||||
|
||||
this.resizeContent();
|
||||
this.$( '.wc-backbone-modal-content' ).attr( 'tabindex' , '0' ).trigger( 'focus' );
|
||||
|
||||
$( document.body ).trigger( 'init_tooltips' );
|
||||
|
||||
$( document.body ).trigger( 'wc_backbone_modal_loaded', this._target );
|
||||
},
|
||||
closeButton: function( e ) {
|
||||
e.preventDefault();
|
||||
$( document.body ).trigger( 'wc_backbone_modal_before_remove', this._target );
|
||||
this.undelegateEvents();
|
||||
$( document ).off( 'focusin' );
|
||||
$( document.body ).css({
|
||||
'overflow': 'auto'
|
||||
});
|
||||
this.remove();
|
||||
$( document.body ).trigger( 'wc_backbone_modal_removed', this._target );
|
||||
},
|
||||
addButton: function( e ) {
|
||||
$( document.body ).trigger( 'wc_backbone_modal_response', [ this._target, this.getFormData() ] );
|
||||
this.closeButton( e );
|
||||
},
|
||||
getFormData: function() {
|
||||
var data = {};
|
||||
|
||||
$( document.body ).trigger( 'wc_backbone_modal_before_update', this._target );
|
||||
|
||||
$.each( $( 'form', this.$el ).serializeArray(), function( index, item ) {
|
||||
if ( item.name.indexOf( '[]' ) !== -1 ) {
|
||||
item.name = item.name.replace( '[]', '' );
|
||||
data[ item.name ] = $.makeArray( data[ item.name ] );
|
||||
data[ item.name ].push( item.value );
|
||||
} else {
|
||||
data[ item.name ] = item.value;
|
||||
}
|
||||
});
|
||||
|
||||
return data;
|
||||
},
|
||||
keyboardActions: function( e ) {
|
||||
var button = e.keyCode || e.which;
|
||||
|
||||
// Enter key
|
||||
if (
|
||||
13 === button &&
|
||||
! ( e.target.tagName && ( e.target.tagName.toLowerCase() === 'input' || e.target.tagName.toLowerCase() === 'textarea' ) )
|
||||
) {
|
||||
this.addButton( e );
|
||||
}
|
||||
|
||||
// ESC key
|
||||
if ( 27 === button ) {
|
||||
this.closeButton( e );
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
}( jQuery, Backbone, _ ));
|
1
assets/js/admin/backbone-modal.min.js
vendored
Normal file
1
assets/js/admin/backbone-modal.min.js
vendored
Normal file
@ -0,0 +1 @@
|
||||
!function(o,e,n){"use strict";o.fn.WCBackboneModal=function(e){return this.each(function(){new o.WCBackboneModal(o(this),e)})},o.WCBackboneModal=function(e,t){t=o.extend({},o.WCBackboneModal.defaultOptions,t);t.template&&new o.WCBackboneModal.View({target:t.template,string:t.variable})},o.WCBackboneModal.defaultOptions={template:"",variable:{}},o.WCBackboneModal.View=e.View.extend({tagName:"div",id:"wc-backbone-modal-dialog",_target:undefined,_string:undefined,events:{"click .modal-close":"closeButton","click #btn-ok":"addButton","touchstart #btn-ok":"addButton",keydown:"keyboardActions"},resizeContent:function(){var e=o(".wc-backbone-modal-content").find("article"),t=.75*o(window).height();e.css({"max-height":t+"px"})},initialize:function(e){var t=this;this._target=e.target,this._string=e.string,n.bindAll(this,"render"),this.render(),o(window).on("resize",function(){t.resizeContent()})},render:function(){var e=wp.template(this._target);this.$el.append(e(this._string)),o(document.body).css({overflow:"hidden"}).append(this.$el),this.resizeContent(),this.$(".wc-backbone-modal-content").attr("tabindex","0").trigger("focus"),o(document.body).trigger("init_tooltips"),o(document.body).trigger("wc_backbone_modal_loaded",this._target)},closeButton:function(e){e.preventDefault(),o(document.body).trigger("wc_backbone_modal_before_remove",this._target),this.undelegateEvents(),o(document).off("focusin"),o(document.body).css({overflow:"auto"}),this.remove(),o(document.body).trigger("wc_backbone_modal_removed",this._target)},addButton:function(e){o(document.body).trigger("wc_backbone_modal_response",[this._target,this.getFormData()]),this.closeButton(e)},getFormData:function(){var n={};return o(document.body).trigger("wc_backbone_modal_before_update",this._target),o.each(o("form",this.$el).serializeArray(),function(e,t){-1!==t.name.indexOf("[]")?(t.name=t.name.replace("[]",""),n[t.name]=o.makeArray(n[t.name]),n[t.name].push(t.value)):n[t.name]=t.value}),n},keyboardActions:function(e){var t=e.keyCode||e.which;13!==t||e.target.tagName&&("input"===e.target.tagName.toLowerCase()||"textarea"===e.target.tagName.toLowerCase())||this.addButton(e),27===t&&this.closeButton(e)}})}(jQuery,Backbone,_);
|
450
assets/js/admin/marketplace-suggestions.js
Normal file
450
assets/js/admin/marketplace-suggestions.js
Normal file
@ -0,0 +1,450 @@
|
||||
/* global marketplace_suggestions, ajaxurl, Cookies */
|
||||
( function( $, marketplace_suggestions, ajaxurl ) {
|
||||
$( function() {
|
||||
if ( 'undefined' === typeof marketplace_suggestions ) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Stand-in wcTracks.recordEvent in case tracks is not available (for any reason).
|
||||
window.wcTracks = window.wcTracks || {};
|
||||
window.wcTracks.recordEvent = window.wcTracks.recordEvent || function() { };
|
||||
|
||||
// Tracks events sent in this file:
|
||||
// - marketplace_suggestion_displayed
|
||||
// - marketplace_suggestion_clicked
|
||||
// - marketplace_suggestion_dismissed
|
||||
// All are prefixed by {WC_Tracks::PREFIX}.
|
||||
// All have one property for `suggestionSlug`, to identify the specific suggestion message.
|
||||
|
||||
// Dismiss the specified suggestion from the UI, and save the dismissal in settings.
|
||||
function dismissSuggestion( context, product, promoted, url, suggestionSlug ) {
|
||||
// hide the suggestion in the UI
|
||||
var selector = '[data-suggestion-slug=' + suggestionSlug + ']';
|
||||
$( selector ).fadeOut( function() {
|
||||
$( this ).remove();
|
||||
tidyProductEditMetabox();
|
||||
} );
|
||||
|
||||
// save dismissal in user settings
|
||||
jQuery.post(
|
||||
ajaxurl,
|
||||
{
|
||||
'action': 'woocommerce_add_dismissed_marketplace_suggestion',
|
||||
'_wpnonce': marketplace_suggestions.dismiss_suggestion_nonce,
|
||||
'slug': suggestionSlug
|
||||
}
|
||||
);
|
||||
|
||||
// if this is a high-use area, delay new suggestion that area for a short while
|
||||
var highUseSuggestionContexts = [ 'products-list-inline' ];
|
||||
if ( _.contains( highUseSuggestionContexts, context ) ) {
|
||||
// snooze suggestions in that area for 2 days
|
||||
var contextSnoozeCookie = 'woocommerce_snooze_suggestions__' + context;
|
||||
Cookies.set( contextSnoozeCookie, 'true', { expires: 2 } );
|
||||
|
||||
// keep track of how often this area gets dismissed in a cookie
|
||||
var contextDismissalCountCookie = 'woocommerce_dismissed_suggestions__' + context;
|
||||
var previousDismissalsInThisContext = parseInt( Cookies.get( contextDismissalCountCookie ), 10 ) || 0;
|
||||
Cookies.set( contextDismissalCountCookie, previousDismissalsInThisContext + 1, { expires: 31 } );
|
||||
}
|
||||
|
||||
window.wcTracks.recordEvent( 'marketplace_suggestion_dismissed', {
|
||||
suggestion_slug: suggestionSlug,
|
||||
context: context,
|
||||
product: product || '',
|
||||
promoted: promoted || '',
|
||||
target: url || ''
|
||||
} );
|
||||
}
|
||||
|
||||
// Render DOM element for suggestion dismiss button.
|
||||
function renderDismissButton( context, product, promoted, url, suggestionSlug ) {
|
||||
var dismissButton = document.createElement( 'a' );
|
||||
|
||||
dismissButton.classList.add( 'suggestion-dismiss' );
|
||||
dismissButton.setAttribute( 'title', marketplace_suggestions.i18n_marketplace_suggestions_dismiss_tooltip );
|
||||
dismissButton.setAttribute( 'href', '#' );
|
||||
dismissButton.onclick = function( event ) {
|
||||
event.preventDefault();
|
||||
dismissSuggestion( context, product, promoted, url, suggestionSlug );
|
||||
};
|
||||
|
||||
return dismissButton;
|
||||
}
|
||||
|
||||
function addURLParameters( context, url ) {
|
||||
var urlParams = marketplace_suggestions.in_app_purchase_params;
|
||||
urlParams.utm_source = 'unknown';
|
||||
urlParams.utm_campaign = 'marketplacesuggestions';
|
||||
urlParams.utm_medium = 'product';
|
||||
|
||||
var sourceContextMap = {
|
||||
'productstable': [
|
||||
'products-list-inline'
|
||||
],
|
||||
'productsempty': [
|
||||
'products-list-empty-header',
|
||||
'products-list-empty-footer',
|
||||
'products-list-empty-body'
|
||||
],
|
||||
'ordersempty': [
|
||||
'orders-list-empty-header',
|
||||
'orders-list-empty-footer',
|
||||
'orders-list-empty-body'
|
||||
],
|
||||
'editproduct': [
|
||||
'product-edit-meta-tab-header',
|
||||
'product-edit-meta-tab-footer',
|
||||
'product-edit-meta-tab-body'
|
||||
]
|
||||
};
|
||||
var utmSource = _.findKey( sourceContextMap, function( sourceInfo ) {
|
||||
return _.contains( sourceInfo, context );
|
||||
} );
|
||||
if ( utmSource ) {
|
||||
urlParams.utm_source = utmSource;
|
||||
}
|
||||
|
||||
return url + '?' + jQuery.param( urlParams );
|
||||
}
|
||||
|
||||
// Render DOM element for suggestion linkout, optionally with button style.
|
||||
function renderLinkout( context, product, promoted, slug, url, text, isButton ) {
|
||||
var linkoutButton = document.createElement( 'a' );
|
||||
|
||||
var utmUrl = addURLParameters( context, url );
|
||||
linkoutButton.setAttribute( 'href', utmUrl );
|
||||
|
||||
// By default, CTA links should open in same tab (and feel integrated with Woo).
|
||||
// Exception: when editing products, use new tab. User may have product edits
|
||||
// that need to be saved.
|
||||
var newTabContexts = [
|
||||
'product-edit-meta-tab-header',
|
||||
'product-edit-meta-tab-footer',
|
||||
'product-edit-meta-tab-body',
|
||||
'products-list-empty-footer'
|
||||
];
|
||||
if ( _.includes( newTabContexts, context ) ) {
|
||||
linkoutButton.setAttribute( 'target', 'blank' );
|
||||
}
|
||||
|
||||
linkoutButton.textContent = text;
|
||||
|
||||
linkoutButton.onclick = function() {
|
||||
window.wcTracks.recordEvent( 'marketplace_suggestion_clicked', {
|
||||
suggestion_slug: slug,
|
||||
context: context,
|
||||
product: product || '',
|
||||
promoted: promoted || '',
|
||||
target: url || ''
|
||||
} );
|
||||
};
|
||||
|
||||
if ( isButton ) {
|
||||
linkoutButton.classList.add( 'button' );
|
||||
} else {
|
||||
linkoutButton.classList.add( 'linkout' );
|
||||
var linkoutIcon = document.createElement( 'span' );
|
||||
linkoutIcon.classList.add( 'dashicons', 'dashicons-external' );
|
||||
linkoutButton.appendChild( linkoutIcon );
|
||||
}
|
||||
|
||||
return linkoutButton;
|
||||
}
|
||||
|
||||
// Render DOM element for suggestion icon image.
|
||||
function renderSuggestionIcon( iconUrl ) {
|
||||
if ( ! iconUrl ) {
|
||||
return null;
|
||||
}
|
||||
|
||||
var image = document.createElement( 'img' );
|
||||
image.src = iconUrl;
|
||||
image.classList.add( 'marketplace-suggestion-icon' );
|
||||
|
||||
return image;
|
||||
}
|
||||
|
||||
// Render DOM elements for suggestion content.
|
||||
function renderSuggestionContent( slug, title, copy ) {
|
||||
var container = document.createElement( 'div' );
|
||||
|
||||
container.classList.add( 'marketplace-suggestion-container-content' );
|
||||
|
||||
if ( title ) {
|
||||
var titleHeading = document.createElement( 'h4' );
|
||||
titleHeading.textContent = title;
|
||||
container.appendChild( titleHeading );
|
||||
}
|
||||
|
||||
if ( copy ) {
|
||||
var body = document.createElement( 'p' );
|
||||
body.textContent = copy;
|
||||
container.appendChild( body );
|
||||
}
|
||||
|
||||
// Conditionally add in a Manage suggestions link to product edit
|
||||
// metabox footer (based on suggestion slug).
|
||||
var slugsWithManage = [
|
||||
'product-edit-empty-footer-browse-all',
|
||||
'product-edit-meta-tab-footer-browse-all'
|
||||
];
|
||||
if ( -1 !== slugsWithManage.indexOf( slug ) ) {
|
||||
container.classList.add( 'has-manage-link' );
|
||||
|
||||
var manageSuggestionsLink = document.createElement( 'a' );
|
||||
manageSuggestionsLink.classList.add( 'marketplace-suggestion-manage-link', 'linkout' );
|
||||
manageSuggestionsLink.setAttribute(
|
||||
'href',
|
||||
marketplace_suggestions.manage_suggestions_url
|
||||
);
|
||||
manageSuggestionsLink.textContent = marketplace_suggestions.i18n_marketplace_suggestions_manage_suggestions;
|
||||
|
||||
container.appendChild( manageSuggestionsLink );
|
||||
}
|
||||
|
||||
return container;
|
||||
}
|
||||
|
||||
// Render DOM elements for suggestion call-to-action – button or link with dismiss 'x'.
|
||||
function renderSuggestionCTA( context, product, promoted, slug, url, linkText, linkIsButton, allowDismiss ) {
|
||||
var container = document.createElement( 'div' );
|
||||
|
||||
if ( ! linkText ) {
|
||||
linkText = marketplace_suggestions.i18n_marketplace_suggestions_default_cta;
|
||||
}
|
||||
|
||||
container.classList.add( 'marketplace-suggestion-container-cta' );
|
||||
if ( url && linkText ) {
|
||||
var linkoutElement = renderLinkout( context, product, promoted, slug, url, linkText, linkIsButton );
|
||||
container.appendChild( linkoutElement );
|
||||
}
|
||||
|
||||
if ( allowDismiss ) {
|
||||
container.appendChild( renderDismissButton( context, product, promoted, url, slug ) );
|
||||
}
|
||||
|
||||
return container;
|
||||
}
|
||||
|
||||
// Render a "list item" style suggestion.
|
||||
// These are used in onboarding style contexts, e.g. products list empty state.
|
||||
function renderListItem( context, product, promoted, slug, iconUrl, title, copy, url, linkText, linkIsButton, allowDismiss ) {
|
||||
var container = document.createElement( 'div' );
|
||||
container.classList.add( 'marketplace-suggestion-container' );
|
||||
container.dataset.suggestionSlug = slug;
|
||||
|
||||
var icon = renderSuggestionIcon( iconUrl );
|
||||
if ( icon ) {
|
||||
container.appendChild( icon );
|
||||
}
|
||||
container.appendChild(
|
||||
renderSuggestionContent( slug, title, copy )
|
||||
);
|
||||
container.appendChild(
|
||||
renderSuggestionCTA( context, product, promoted, slug, url, linkText, linkIsButton, allowDismiss )
|
||||
);
|
||||
|
||||
return container;
|
||||
}
|
||||
|
||||
// Filter suggestion data to remove less-relevant suggestions.
|
||||
function getRelevantPromotions( marketplaceSuggestionsApiData, displayContext ) {
|
||||
// select based on display context
|
||||
var promos = _.filter( marketplaceSuggestionsApiData, function( promo ) {
|
||||
if ( _.isArray( promo.context ) ) {
|
||||
return _.contains( promo.context, displayContext );
|
||||
}
|
||||
return ( displayContext === promo.context );
|
||||
} );
|
||||
|
||||
// hide promos the user has dismissed
|
||||
promos = _.filter( promos, function( promo ) {
|
||||
return ! _.contains( marketplace_suggestions.dismissed_suggestions, promo.slug );
|
||||
} );
|
||||
|
||||
// hide promos for things the user already has installed
|
||||
promos = _.filter( promos, function( promo ) {
|
||||
return ! _.contains( marketplace_suggestions.active_plugins, promo.product );
|
||||
} );
|
||||
|
||||
// hide promos that are not applicable based on user's installed extensions
|
||||
promos = _.filter( promos, function( promo ) {
|
||||
if ( ! promo['show-if-active'] ) {
|
||||
// this promotion is relevant to all
|
||||
return true;
|
||||
}
|
||||
|
||||
// if the user has any of the prerequisites, show the promo
|
||||
return ( _.intersection( marketplace_suggestions.active_plugins, promo['show-if-active'] ).length > 0 );
|
||||
} );
|
||||
|
||||
return promos;
|
||||
}
|
||||
|
||||
// Show and hide page elements dependent on suggestion state.
|
||||
function hidePageElementsForSuggestionState( usedSuggestionsContexts ) {
|
||||
var showingEmptyStateSuggestions = _.intersection(
|
||||
usedSuggestionsContexts,
|
||||
[ 'products-list-empty-body', 'orders-list-empty-body' ]
|
||||
).length > 0;
|
||||
|
||||
// Streamline onboarding UI if we're in 'empty state' welcome mode.
|
||||
if ( showingEmptyStateSuggestions ) {
|
||||
$( '#screen-meta-links' ).hide();
|
||||
$( '#wpfooter' ).hide();
|
||||
}
|
||||
|
||||
// Hide the header & footer, they don't make sense without specific promotion content
|
||||
if ( ! showingEmptyStateSuggestions ) {
|
||||
$( '.marketplace-suggestions-container[data-marketplace-suggestions-context="products-list-empty-header"]' ).hide();
|
||||
$( '.marketplace-suggestions-container[data-marketplace-suggestions-context="products-list-empty-footer"]' ).hide();
|
||||
$( '.marketplace-suggestions-container[data-marketplace-suggestions-context="orders-list-empty-header"]' ).hide();
|
||||
$( '.marketplace-suggestions-container[data-marketplace-suggestions-context="orders-list-empty-footer"]' ).hide();
|
||||
}
|
||||
}
|
||||
|
||||
// Streamline the product edit suggestions tab dependent on what's visible.
|
||||
function tidyProductEditMetabox() {
|
||||
var productMetaboxSuggestions = $(
|
||||
'.marketplace-suggestions-container[data-marketplace-suggestions-context="product-edit-meta-tab-body"]'
|
||||
).children();
|
||||
if ( 0 >= productMetaboxSuggestions.length ) {
|
||||
var metaboxSuggestionsUISelector =
|
||||
'.marketplace-suggestions-container[data-marketplace-suggestions-context="product-edit-meta-tab-body"]';
|
||||
metaboxSuggestionsUISelector +=
|
||||
', .marketplace-suggestions-container[data-marketplace-suggestions-context="product-edit-meta-tab-header"]';
|
||||
metaboxSuggestionsUISelector +=
|
||||
', .marketplace-suggestions-container[data-marketplace-suggestions-context="product-edit-meta-tab-footer"]';
|
||||
$( metaboxSuggestionsUISelector ).fadeOut( {
|
||||
complete: function() {
|
||||
$( '.marketplace-suggestions-metabox-nosuggestions-placeholder' ).fadeIn();
|
||||
}
|
||||
} );
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
function addManageSuggestionsTracksHandler() {
|
||||
$( 'a.marketplace-suggestion-manage-link' ).on( 'click', function() {
|
||||
window.wcTracks.recordEvent( 'marketplace_suggestions_manage_clicked' );
|
||||
} );
|
||||
}
|
||||
|
||||
function isContextHiddenOnPageLoad( context ) {
|
||||
// Some suggestions are not visible on page load;
|
||||
// e.g. the user reveals them by selecting a tab.
|
||||
var revealableSuggestionsContexts = [
|
||||
'product-edit-meta-tab-header',
|
||||
'product-edit-meta-tab-body',
|
||||
'product-edit-meta-tab-footer'
|
||||
];
|
||||
return _.includes( revealableSuggestionsContexts, context );
|
||||
}
|
||||
|
||||
// track the current product data tab to avoid over-tracking suggestions
|
||||
var currentTab = false;
|
||||
|
||||
// Render suggestion data in appropriate places in UI.
|
||||
function displaySuggestions( marketplaceSuggestionsApiData ) {
|
||||
var usedSuggestionsContexts = [];
|
||||
|
||||
// iterate over all suggestions containers, rendering promos
|
||||
$( '.marketplace-suggestions-container' ).each( function() {
|
||||
// determine the context / placement we're populating
|
||||
var context = this.dataset.marketplaceSuggestionsContext;
|
||||
|
||||
// find promotions that target this context
|
||||
var promos = getRelevantPromotions( marketplaceSuggestionsApiData, context );
|
||||
|
||||
// shuffle/randomly select five suggestions to display
|
||||
var suggestionsToDisplay = _.sample( promos, 5 );
|
||||
|
||||
// render the promo content
|
||||
for ( var i in suggestionsToDisplay ) {
|
||||
|
||||
var linkText = suggestionsToDisplay[ i ]['link-text'];
|
||||
var linkoutIsButton = true;
|
||||
if ( suggestionsToDisplay[ i ]['link-text'] ) {
|
||||
linkText = suggestionsToDisplay[ i ]['link-text'];
|
||||
linkoutIsButton = false;
|
||||
}
|
||||
|
||||
// dismiss is allowed by default
|
||||
var allowDismiss = true;
|
||||
if ( suggestionsToDisplay[ i ]['allow-dismiss'] === false ) {
|
||||
allowDismiss = false;
|
||||
}
|
||||
|
||||
var content = renderListItem(
|
||||
context,
|
||||
suggestionsToDisplay[ i ].product,
|
||||
suggestionsToDisplay[ i ].promoted,
|
||||
suggestionsToDisplay[ i ].slug,
|
||||
suggestionsToDisplay[ i ].icon,
|
||||
suggestionsToDisplay[ i ].title,
|
||||
suggestionsToDisplay[ i ].copy,
|
||||
suggestionsToDisplay[ i ].url,
|
||||
linkText,
|
||||
linkoutIsButton,
|
||||
allowDismiss
|
||||
);
|
||||
$( this ).append( content );
|
||||
$( this ).addClass( 'showing-suggestion' );
|
||||
usedSuggestionsContexts.push( context );
|
||||
|
||||
if ( ! isContextHiddenOnPageLoad( context ) ) {
|
||||
// Fire 'displayed' tracks events for immediately visible suggestions.
|
||||
window.wcTracks.recordEvent( 'marketplace_suggestion_displayed', {
|
||||
suggestion_slug: suggestionsToDisplay[ i ].slug,
|
||||
context: context,
|
||||
product: suggestionsToDisplay[ i ].product || '',
|
||||
promoted: suggestionsToDisplay[ i ].promoted || '',
|
||||
target: suggestionsToDisplay[ i ].url || ''
|
||||
} );
|
||||
}
|
||||
}
|
||||
|
||||
// Track when suggestions are displayed (and not already visible).
|
||||
$( 'ul.product_data_tabs li.marketplace-suggestions_options a' ).on( 'click', function( e ) {
|
||||
e.preventDefault();
|
||||
|
||||
if ( '#marketplace_suggestions' === currentTab ) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ( ! isContextHiddenOnPageLoad( context ) ) {
|
||||
// We've already fired 'displayed' event above.
|
||||
return;
|
||||
}
|
||||
|
||||
for ( var i in suggestionsToDisplay ) {
|
||||
window.wcTracks.recordEvent( 'marketplace_suggestion_displayed', {
|
||||
suggestion_slug: suggestionsToDisplay[ i ].slug,
|
||||
context: context,
|
||||
product: suggestionsToDisplay[ i ].product || '',
|
||||
promoted: suggestionsToDisplay[ i ].promoted || '',
|
||||
target: suggestionsToDisplay[ i ].url || ''
|
||||
} );
|
||||
}
|
||||
} );
|
||||
} );
|
||||
|
||||
hidePageElementsForSuggestionState( usedSuggestionsContexts );
|
||||
tidyProductEditMetabox();
|
||||
}
|
||||
|
||||
if ( marketplace_suggestions.suggestions_data ) {
|
||||
displaySuggestions( marketplace_suggestions.suggestions_data );
|
||||
|
||||
// track the current product data tab to avoid over-reporting suggestion views
|
||||
$( 'ul.product_data_tabs' ).on( 'click', 'li a', function( e ) {
|
||||
e.preventDefault();
|
||||
currentTab = $( this ).attr( 'href' );
|
||||
} );
|
||||
}
|
||||
|
||||
addManageSuggestionsTracksHandler();
|
||||
});
|
||||
|
||||
})( jQuery, marketplace_suggestions, ajaxurl );
|
1
assets/js/admin/marketplace-suggestions.min.js
vendored
Normal file
1
assets/js/admin/marketplace-suggestions.min.js
vendored
Normal file
File diff suppressed because one or more lines are too long
70
assets/js/admin/meta-boxes-coupon.js
Normal file
70
assets/js/admin/meta-boxes-coupon.js
Normal file
@ -0,0 +1,70 @@
|
||||
/* global woocommerce_admin_meta_boxes_coupon */
|
||||
jQuery(function( $ ) {
|
||||
|
||||
/**
|
||||
* Coupon actions
|
||||
*/
|
||||
var wc_meta_boxes_coupon_actions = {
|
||||
|
||||
/**
|
||||
* Initialize variations actions
|
||||
*/
|
||||
init: function() {
|
||||
$( 'select#discount_type' )
|
||||
.on( 'change', this.type_options )
|
||||
.trigger( 'change' );
|
||||
|
||||
this.insert_generate_coupon_code_button();
|
||||
$( '.button.generate-coupon-code' ).on( 'click', this.generate_coupon_code );
|
||||
},
|
||||
|
||||
/**
|
||||
* Show/hide fields by coupon type options
|
||||
*/
|
||||
type_options: function() {
|
||||
// Get value
|
||||
var select_val = $( this ).val();
|
||||
|
||||
if ( 'percent' === select_val ) {
|
||||
$( '#coupon_amount' ).removeClass( 'wc_input_price' ).addClass( 'wc_input_decimal' );
|
||||
} else {
|
||||
$( '#coupon_amount' ).removeClass( 'wc_input_decimal' ).addClass( 'wc_input_price' );
|
||||
}
|
||||
|
||||
if ( select_val !== 'fixed_cart' ) {
|
||||
$( '.limit_usage_to_x_items_field' ).show();
|
||||
} else {
|
||||
$( '.limit_usage_to_x_items_field' ).hide();
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* Insert generate coupon code buttom HTML.
|
||||
*/
|
||||
insert_generate_coupon_code_button: function() {
|
||||
$( '.post-type-shop_coupon' ).find( '#title' ).after(
|
||||
'<a href="#" class="button generate-coupon-code">' + woocommerce_admin_meta_boxes_coupon.generate_button_text + '</a>'
|
||||
);
|
||||
},
|
||||
|
||||
/**
|
||||
* Generate a random coupon code
|
||||
*/
|
||||
generate_coupon_code: function( e ) {
|
||||
e.preventDefault();
|
||||
var $coupon_code_field = $( '#title' ),
|
||||
$coupon_code_label = $( '#title-prompt-text' ),
|
||||
$result = '';
|
||||
for ( var i = 0; i < woocommerce_admin_meta_boxes_coupon.char_length; i++ ) {
|
||||
$result += woocommerce_admin_meta_boxes_coupon.characters.charAt(
|
||||
Math.floor( Math.random() * woocommerce_admin_meta_boxes_coupon.characters.length )
|
||||
);
|
||||
}
|
||||
$result = woocommerce_admin_meta_boxes_coupon.prefix + $result + woocommerce_admin_meta_boxes_coupon.suffix;
|
||||
$coupon_code_field.trigger( 'focus' ).val( $result );
|
||||
$coupon_code_label.addClass( 'screen-reader-text' );
|
||||
}
|
||||
};
|
||||
|
||||
wc_meta_boxes_coupon_actions.init();
|
||||
});
|
1
assets/js/admin/meta-boxes-coupon.min.js
vendored
Normal file
1
assets/js/admin/meta-boxes-coupon.min.js
vendored
Normal file
@ -0,0 +1 @@
|
||||
jQuery(function(_){({init:function(){_("select#discount_type").on("change",this.type_options).trigger("change"),this.insert_generate_coupon_code_button(),_(".button.generate-coupon-code").on("click",this.generate_coupon_code)},type_options:function(){var e=_(this).val();"percent"===e?_("#coupon_amount").removeClass("wc_input_price").addClass("wc_input_decimal"):_("#coupon_amount").removeClass("wc_input_decimal").addClass("wc_input_price"),"fixed_cart"!==e?_(".limit_usage_to_x_items_field").show():_(".limit_usage_to_x_items_field").hide()},insert_generate_coupon_code_button:function(){_(".post-type-shop_coupon").find("#title").after('<a href="#" class="button generate-coupon-code">'+woocommerce_admin_meta_boxes_coupon.generate_button_text+"</a>")},generate_coupon_code:function(e){e.preventDefault();for(var o=_("#title"),e=_("#title-prompt-text"),t="",n=0;n<woocommerce_admin_meta_boxes_coupon.char_length;n++)t+=woocommerce_admin_meta_boxes_coupon.characters.charAt(Math.floor(Math.random()*woocommerce_admin_meta_boxes_coupon.characters.length));t=woocommerce_admin_meta_boxes_coupon.prefix+t+woocommerce_admin_meta_boxes_coupon.suffix,o.trigger("focus").val(t),e.addClass("screen-reader-text")}}).init()});
|
1504
assets/js/admin/meta-boxes-order.js
Normal file
1504
assets/js/admin/meta-boxes-order.js
Normal file
File diff suppressed because it is too large
Load Diff
1
assets/js/admin/meta-boxes-order.min.js
vendored
Normal file
1
assets/js/admin/meta-boxes-order.min.js
vendored
Normal file
File diff suppressed because one or more lines are too long
1092
assets/js/admin/meta-boxes-product-variation.js
Normal file
1092
assets/js/admin/meta-boxes-product-variation.js
Normal file
File diff suppressed because it is too large
Load Diff
1
assets/js/admin/meta-boxes-product-variation.min.js
vendored
Normal file
1
assets/js/admin/meta-boxes-product-variation.min.js
vendored
Normal file
File diff suppressed because one or more lines are too long
697
assets/js/admin/meta-boxes-product.js
Normal file
697
assets/js/admin/meta-boxes-product.js
Normal file
@ -0,0 +1,697 @@
|
||||
/*global woocommerce_admin_meta_boxes */
|
||||
jQuery( function( $ ) {
|
||||
|
||||
// Scroll to first checked category
|
||||
// https://github.com/scribu/wp-category-checklist-tree/blob/d1c3c1f449e1144542efa17dde84a9f52ade1739/category-checklist-tree.php
|
||||
$( function() {
|
||||
$( '[id$="-all"] > ul.categorychecklist' ).each( function() {
|
||||
var $list = $( this );
|
||||
var $firstChecked = $list.find( ':checked' ).first();
|
||||
|
||||
if ( ! $firstChecked.length ) {
|
||||
return;
|
||||
}
|
||||
|
||||
var pos_first = $list.find( 'input' ).position().top;
|
||||
var pos_checked = $firstChecked.position().top;
|
||||
|
||||
$list.closest( '.tabs-panel' ).scrollTop( pos_checked - pos_first + 5 );
|
||||
});
|
||||
});
|
||||
|
||||
// Prevent enter submitting post form.
|
||||
$( '#upsell_product_data' ).on( 'keypress', function( e ) {
|
||||
if ( e.keyCode === 13 ) {
|
||||
return false;
|
||||
}
|
||||
});
|
||||
|
||||
// Type box.
|
||||
if ( $( 'body' ).hasClass( 'wc-wp-version-gte-55' ) ) {
|
||||
$( '.type_box' ).appendTo( '#woocommerce-product-data .hndle' );
|
||||
} else {
|
||||
$( '.type_box' ).appendTo( '#woocommerce-product-data .hndle span' );
|
||||
}
|
||||
|
||||
$( function() {
|
||||
var woocommerce_product_data = $( '#woocommerce-product-data' );
|
||||
|
||||
// Prevent inputs in meta box headings opening/closing contents.
|
||||
woocommerce_product_data.find( '.hndle' ).off( 'click.postboxes' );
|
||||
|
||||
woocommerce_product_data.on( 'click', '.hndle', function( event ) {
|
||||
|
||||
// If the user clicks on some form input inside the h3 the box should not be toggled.
|
||||
if ( $( event.target ).filter( 'input, option, label, select' ).length ) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ( woocommerce_product_data.hasClass( 'closed' ) ) {
|
||||
woocommerce_product_data.removeClass( 'closed' );
|
||||
} else {
|
||||
woocommerce_product_data.addClass( 'closed' );
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
// Catalog Visibility.
|
||||
$( '#catalog-visibility' ).find( '.edit-catalog-visibility' ).on( 'click', function() {
|
||||
if ( $( '#catalog-visibility-select' ).is( ':hidden' ) ) {
|
||||
$( '#catalog-visibility-select' ).slideDown( 'fast' );
|
||||
$( this ).hide();
|
||||
}
|
||||
return false;
|
||||
});
|
||||
$( '#catalog-visibility' ).find( '.save-post-visibility' ).on( 'click', function() {
|
||||
$( '#catalog-visibility-select' ).slideUp( 'fast' );
|
||||
$( '#catalog-visibility' ).find( '.edit-catalog-visibility' ).show();
|
||||
|
||||
var label = $( 'input[name=_visibility]:checked' ).attr( 'data-label' );
|
||||
|
||||
if ( $( 'input[name=_featured]' ).is( ':checked' ) ) {
|
||||
label = label + ', ' + woocommerce_admin_meta_boxes.featured_label;
|
||||
$( 'input[name=_featured]' ).attr( 'checked', 'checked' );
|
||||
}
|
||||
|
||||
$( '#catalog-visibility-display' ).text( label );
|
||||
return false;
|
||||
});
|
||||
$( '#catalog-visibility' ).find( '.cancel-post-visibility' ).on( 'click', function() {
|
||||
$( '#catalog-visibility-select' ).slideUp( 'fast' );
|
||||
$( '#catalog-visibility' ).find( '.edit-catalog-visibility' ).show();
|
||||
|
||||
var current_visibility = $( '#current_visibility' ).val();
|
||||
var current_featured = $( '#current_featured' ).val();
|
||||
|
||||
$( 'input[name=_visibility]' ).prop( 'checked', false );
|
||||
$( 'input[name=_visibility][value=' + current_visibility + ']' ).attr( 'checked', 'checked' );
|
||||
|
||||
var label = $( 'input[name=_visibility]:checked' ).attr( 'data-label' );
|
||||
|
||||
if ( 'yes' === current_featured ) {
|
||||
label = label + ', ' + woocommerce_admin_meta_boxes.featured_label;
|
||||
$( 'input[name=_featured]' ).attr( 'checked', 'checked' );
|
||||
} else {
|
||||
$( 'input[name=_featured]' ).prop( 'checked', false );
|
||||
}
|
||||
|
||||
$( '#catalog-visibility-display' ).text( label );
|
||||
return false;
|
||||
});
|
||||
|
||||
// Product type specific options.
|
||||
$( 'select#product-type' ).on( 'change', function() {
|
||||
|
||||
// Get value.
|
||||
var select_val = $( this ).val();
|
||||
|
||||
if ( 'variable' === select_val ) {
|
||||
$( 'input#_manage_stock' ).trigger( 'change' );
|
||||
$( 'input#_downloadable' ).prop( 'checked', false );
|
||||
$( 'input#_virtual' ).prop( 'checked', false );
|
||||
} else if ( 'grouped' === select_val ) {
|
||||
$( 'input#_downloadable' ).prop( 'checked', false );
|
||||
$( 'input#_virtual' ).prop( 'checked', false );
|
||||
} else if ( 'external' === select_val ) {
|
||||
$( 'input#_downloadable' ).prop( 'checked', false );
|
||||
$( 'input#_virtual' ).prop( 'checked', false );
|
||||
}
|
||||
|
||||
show_and_hide_panels();
|
||||
|
||||
$( 'ul.wc-tabs li:visible' ).eq( 0 ).find( 'a' ).trigger( 'click' );
|
||||
|
||||
$( document.body ).trigger( 'woocommerce-product-type-change', select_val, $( this ) );
|
||||
|
||||
}).trigger( 'change' );
|
||||
|
||||
$( 'input#_downloadable, input#_virtual' ).on( 'change', function() {
|
||||
show_and_hide_panels();
|
||||
});
|
||||
|
||||
function show_and_hide_panels() {
|
||||
var product_type = $( 'select#product-type' ).val();
|
||||
var is_virtual = $( 'input#_virtual:checked' ).length;
|
||||
var is_downloadable = $( 'input#_downloadable:checked' ).length;
|
||||
|
||||
// Hide/Show all with rules.
|
||||
var hide_classes = '.hide_if_downloadable, .hide_if_virtual';
|
||||
var show_classes = '.show_if_downloadable, .show_if_virtual';
|
||||
|
||||
$.each( woocommerce_admin_meta_boxes.product_types, function( index, value ) {
|
||||
hide_classes = hide_classes + ', .hide_if_' + value;
|
||||
show_classes = show_classes + ', .show_if_' + value;
|
||||
});
|
||||
|
||||
$( hide_classes ).show();
|
||||
$( show_classes ).hide();
|
||||
|
||||
// Shows rules.
|
||||
if ( is_downloadable ) {
|
||||
$( '.show_if_downloadable' ).show();
|
||||
}
|
||||
if ( is_virtual ) {
|
||||
$( '.show_if_virtual' ).show();
|
||||
|
||||
// If user enables virtual while on shipping tab, switch to general tab.
|
||||
if ( $( '.shipping_options.shipping_tab' ).hasClass( 'active' ) ) {
|
||||
$( '.general_options.general_tab > a' ).trigger( 'click' );
|
||||
}
|
||||
}
|
||||
|
||||
$( '.show_if_' + product_type ).show();
|
||||
|
||||
// Hide rules.
|
||||
if ( is_downloadable ) {
|
||||
$( '.hide_if_downloadable' ).hide();
|
||||
}
|
||||
if ( is_virtual ) {
|
||||
$( '.hide_if_virtual' ).hide();
|
||||
}
|
||||
|
||||
$( '.hide_if_' + product_type ).hide();
|
||||
|
||||
$( 'input#_manage_stock' ).trigger( 'change' );
|
||||
|
||||
// Hide empty panels/tabs after display.
|
||||
$( '.woocommerce_options_panel' ).each( function() {
|
||||
var $children = $( this ).children( '.options_group' );
|
||||
|
||||
if ( 0 === $children.length ) {
|
||||
return;
|
||||
}
|
||||
|
||||
var $invisble = $children.filter( function() {
|
||||
return 'none' === $( this ).css( 'display' );
|
||||
});
|
||||
|
||||
// Hide panel.
|
||||
if ( $invisble.length === $children.length ) {
|
||||
var $id = $( this ).prop( 'id' );
|
||||
$( '.product_data_tabs' ).find( 'li a[href="#' + $id + '"]' ).parent().hide();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// Sale price schedule.
|
||||
$( '.sale_price_dates_fields' ).each( function() {
|
||||
var $these_sale_dates = $( this );
|
||||
var sale_schedule_set = false;
|
||||
var $wrap = $these_sale_dates.closest( 'div, table' );
|
||||
|
||||
$these_sale_dates.find( 'input' ).each( function() {
|
||||
if ( '' !== $( this ).val() ) {
|
||||
sale_schedule_set = true;
|
||||
}
|
||||
});
|
||||
|
||||
if ( sale_schedule_set ) {
|
||||
$wrap.find( '.sale_schedule' ).hide();
|
||||
$wrap.find( '.sale_price_dates_fields' ).show();
|
||||
} else {
|
||||
$wrap.find( '.sale_schedule' ).show();
|
||||
$wrap.find( '.sale_price_dates_fields' ).hide();
|
||||
}
|
||||
});
|
||||
|
||||
$( '#woocommerce-product-data' ).on( 'click', '.sale_schedule', function() {
|
||||
var $wrap = $( this ).closest( 'div, table' );
|
||||
|
||||
$( this ).hide();
|
||||
$wrap.find( '.cancel_sale_schedule' ).show();
|
||||
$wrap.find( '.sale_price_dates_fields' ).show();
|
||||
|
||||
return false;
|
||||
});
|
||||
$( '#woocommerce-product-data' ).on( 'click', '.cancel_sale_schedule', function() {
|
||||
var $wrap = $( this ).closest( 'div, table' );
|
||||
|
||||
$( this ).hide();
|
||||
$wrap.find( '.sale_schedule' ).show();
|
||||
$wrap.find( '.sale_price_dates_fields' ).hide();
|
||||
$wrap.find( '.sale_price_dates_fields' ).find( 'input' ).val('');
|
||||
|
||||
return false;
|
||||
});
|
||||
|
||||
// File inputs.
|
||||
$( '#woocommerce-product-data' ).on( 'click','.downloadable_files a.insert', function() {
|
||||
$( this ).closest( '.downloadable_files' ).find( 'tbody' ).append( $( this ).data( 'row' ) );
|
||||
return false;
|
||||
});
|
||||
$( '#woocommerce-product-data' ).on( 'click','.downloadable_files a.delete',function() {
|
||||
$( this ).closest( 'tr' ).remove();
|
||||
return false;
|
||||
});
|
||||
|
||||
// Stock options.
|
||||
$( 'input#_manage_stock' ).on( 'change', function() {
|
||||
if ( $( this ).is( ':checked' ) ) {
|
||||
$( 'div.stock_fields' ).show();
|
||||
$( 'p.stock_status_field' ).hide();
|
||||
} else {
|
||||
var product_type = $( 'select#product-type' ).val();
|
||||
|
||||
$( 'div.stock_fields' ).hide();
|
||||
$( 'p.stock_status_field:not( .hide_if_' + product_type + ' )' ).show();
|
||||
}
|
||||
|
||||
$( 'input.variable_manage_stock' ).trigger( 'change' );
|
||||
}).trigger( 'change' );
|
||||
|
||||
// Date picker fields.
|
||||
function date_picker_select( datepicker ) {
|
||||
var option = $( datepicker ).next().is( '.hasDatepicker' ) ? 'minDate' : 'maxDate',
|
||||
otherDateField = 'minDate' === option ? $( datepicker ).next() : $( datepicker ).prev(),
|
||||
date = $( datepicker ).datepicker( 'getDate' );
|
||||
|
||||
$( otherDateField ).datepicker( 'option', option, date );
|
||||
$( datepicker ).trigger( 'change' );
|
||||
}
|
||||
|
||||
$( '.sale_price_dates_fields' ).each( function() {
|
||||
$( this ).find( 'input' ).datepicker({
|
||||
defaultDate: '',
|
||||
dateFormat: 'yy-mm-dd',
|
||||
numberOfMonths: 1,
|
||||
showButtonPanel: true,
|
||||
onSelect: function() {
|
||||
date_picker_select( $( this ) );
|
||||
}
|
||||
});
|
||||
$( this ).find( 'input' ).each( function() { date_picker_select( $( this ) ); } );
|
||||
});
|
||||
|
||||
// Attribute Tables.
|
||||
|
||||
// Initial order.
|
||||
var woocommerce_attribute_items = $( '.product_attributes' ).find( '.woocommerce_attribute' ).get();
|
||||
|
||||
woocommerce_attribute_items.sort( function( a, b ) {
|
||||
var compA = parseInt( $( a ).attr( 'rel' ), 10 );
|
||||
var compB = parseInt( $( b ).attr( 'rel' ), 10 );
|
||||
return ( compA < compB ) ? -1 : ( compA > compB ) ? 1 : 0;
|
||||
});
|
||||
$( woocommerce_attribute_items ).each( function( index, el ) {
|
||||
$( '.product_attributes' ).append( el );
|
||||
});
|
||||
|
||||
function attribute_row_indexes() {
|
||||
$( '.product_attributes .woocommerce_attribute' ).each( function( index, el ) {
|
||||
$( '.attribute_position', el ).val( parseInt( $( el ).index( '.product_attributes .woocommerce_attribute' ), 10 ) );
|
||||
});
|
||||
}
|
||||
|
||||
$( '.product_attributes .woocommerce_attribute' ).each( function( index, el ) {
|
||||
if ( $( el ).css( 'display' ) !== 'none' && $( el ).is( '.taxonomy' ) ) {
|
||||
$( 'select.attribute_taxonomy' ).find( 'option[value="' + $( el ).data( 'taxonomy' ) + '"]' ).attr( 'disabled', 'disabled' );
|
||||
}
|
||||
});
|
||||
|
||||
// Add rows.
|
||||
$( 'button.add_attribute' ).on( 'click', function() {
|
||||
var size = $( '.product_attributes .woocommerce_attribute' ).length;
|
||||
var attribute = $( 'select.attribute_taxonomy' ).val();
|
||||
var $wrapper = $( this ).closest( '#product_attributes' );
|
||||
var $attributes = $wrapper.find( '.product_attributes' );
|
||||
var product_type = $( 'select#product-type' ).val();
|
||||
var data = {
|
||||
action: 'woocommerce_add_attribute',
|
||||
taxonomy: attribute,
|
||||
i: size,
|
||||
security: woocommerce_admin_meta_boxes.add_attribute_nonce
|
||||
};
|
||||
|
||||
$wrapper.block({
|
||||
message: null,
|
||||
overlayCSS: {
|
||||
background: '#fff',
|
||||
opacity: 0.6
|
||||
}
|
||||
});
|
||||
|
||||
$.post( woocommerce_admin_meta_boxes.ajax_url, data, function( response ) {
|
||||
$attributes.append( response );
|
||||
|
||||
if ( 'variable' !== product_type ) {
|
||||
$attributes.find( '.enable_variation' ).hide();
|
||||
}
|
||||
|
||||
$( document.body ).trigger( 'wc-enhanced-select-init' );
|
||||
|
||||
attribute_row_indexes();
|
||||
|
||||
$attributes.find( '.woocommerce_attribute' ).last().find( 'h3' ).trigger( 'click' );
|
||||
|
||||
$wrapper.unblock();
|
||||
|
||||
$( document.body ).trigger( 'woocommerce_added_attribute' );
|
||||
});
|
||||
|
||||
if ( attribute ) {
|
||||
$( 'select.attribute_taxonomy' ).find( 'option[value="' + attribute + '"]' ).attr( 'disabled','disabled' );
|
||||
$( 'select.attribute_taxonomy' ).val( '' );
|
||||
}
|
||||
|
||||
return false;
|
||||
});
|
||||
|
||||
$( '.product_attributes' ).on( 'blur', 'input.attribute_name', function() {
|
||||
$( this ).closest( '.woocommerce_attribute' ).find( 'strong.attribute_name' ).text( $( this ).val() );
|
||||
});
|
||||
|
||||
$( '.product_attributes' ).on( 'click', 'button.select_all_attributes', function() {
|
||||
$( this ).closest( 'td' ).find( 'select option' ).prop( 'selected', 'selected' );
|
||||
$( this ).closest( 'td' ).find( 'select' ).trigger( 'change' );
|
||||
return false;
|
||||
});
|
||||
|
||||
$( '.product_attributes' ).on( 'click', 'button.select_no_attributes', function() {
|
||||
$( this ).closest( 'td' ).find( 'select option' ).prop( 'selected', false );
|
||||
$( this ).closest( 'td' ).find( 'select' ).trigger( 'change' );
|
||||
return false;
|
||||
});
|
||||
|
||||
$( '.product_attributes' ).on( 'click', '.remove_row', function() {
|
||||
if ( window.confirm( woocommerce_admin_meta_boxes.remove_attribute ) ) {
|
||||
var $parent = $( this ).parent().parent();
|
||||
|
||||
if ( $parent.is( '.taxonomy' ) ) {
|
||||
$parent.find( 'select, input[type=text]' ).val( '' );
|
||||
$parent.hide();
|
||||
$( 'select.attribute_taxonomy' ).find( 'option[value="' + $parent.data( 'taxonomy' ) + '"]' ).prop( 'disabled', false );
|
||||
} else {
|
||||
$parent.find( 'select, input[type=text]' ).val( '' );
|
||||
$parent.hide();
|
||||
attribute_row_indexes();
|
||||
}
|
||||
}
|
||||
return false;
|
||||
});
|
||||
|
||||
// Attribute ordering.
|
||||
$( '.product_attributes' ).sortable({
|
||||
items: '.woocommerce_attribute',
|
||||
cursor: 'move',
|
||||
axis: 'y',
|
||||
handle: 'h3',
|
||||
scrollSensitivity: 40,
|
||||
forcePlaceholderSize: true,
|
||||
helper: 'clone',
|
||||
opacity: 0.65,
|
||||
placeholder: 'wc-metabox-sortable-placeholder',
|
||||
start: function( event, ui ) {
|
||||
ui.item.css( 'background-color', '#f6f6f6' );
|
||||
},
|
||||
stop: function( event, ui ) {
|
||||
ui.item.removeAttr( 'style' );
|
||||
attribute_row_indexes();
|
||||
}
|
||||
});
|
||||
|
||||
// Add a new attribute (via ajax).
|
||||
$( '.product_attributes' ).on( 'click', 'button.add_new_attribute', function() {
|
||||
|
||||
$( '.product_attributes' ).block({
|
||||
message: null,
|
||||
overlayCSS: {
|
||||
background: '#fff',
|
||||
opacity: 0.6
|
||||
}
|
||||
});
|
||||
|
||||
var $wrapper = $( this ).closest( '.woocommerce_attribute' );
|
||||
var attribute = $wrapper.data( 'taxonomy' );
|
||||
var new_attribute_name = window.prompt( woocommerce_admin_meta_boxes.new_attribute_prompt );
|
||||
|
||||
if ( new_attribute_name ) {
|
||||
|
||||
var data = {
|
||||
action: 'woocommerce_add_new_attribute',
|
||||
taxonomy: attribute,
|
||||
term: new_attribute_name,
|
||||
security: woocommerce_admin_meta_boxes.add_attribute_nonce
|
||||
};
|
||||
|
||||
$.post( woocommerce_admin_meta_boxes.ajax_url, data, function( response ) {
|
||||
|
||||
if ( response.error ) {
|
||||
// Error.
|
||||
window.alert( response.error );
|
||||
} else if ( response.slug ) {
|
||||
// Success.
|
||||
$wrapper.find( 'select.attribute_values' )
|
||||
.append( '<option value="' + response.term_id + '" selected="selected">' + response.name + '</option>' );
|
||||
$wrapper.find( 'select.attribute_values' ).trigger( 'change' );
|
||||
}
|
||||
|
||||
$( '.product_attributes' ).unblock();
|
||||
});
|
||||
|
||||
} else {
|
||||
$( '.product_attributes' ).unblock();
|
||||
}
|
||||
|
||||
return false;
|
||||
});
|
||||
|
||||
// Save attributes and update variations.
|
||||
$( '.save_attributes' ).on( 'click', function() {
|
||||
|
||||
$( '.product_attributes' ).block({
|
||||
message: null,
|
||||
overlayCSS: {
|
||||
background: '#fff',
|
||||
opacity: 0.6
|
||||
}
|
||||
});
|
||||
var original_data = $( '.product_attributes' ).find( 'input, select, textarea' );
|
||||
var data = {
|
||||
post_id : woocommerce_admin_meta_boxes.post_id,
|
||||
product_type: $( '#product-type' ).val(),
|
||||
data : original_data.serialize(),
|
||||
action : 'woocommerce_save_attributes',
|
||||
security : woocommerce_admin_meta_boxes.save_attributes_nonce
|
||||
};
|
||||
|
||||
$.post( woocommerce_admin_meta_boxes.ajax_url, data, function( response ) {
|
||||
if ( response.error ) {
|
||||
// Error.
|
||||
window.alert( response.error );
|
||||
} else if ( response.data ) {
|
||||
// Success.
|
||||
$( '.product_attributes' ).html( response.data.html );
|
||||
$( '.product_attributes' ).unblock();
|
||||
|
||||
// Hide the 'Used for variations' checkbox if not viewing a variable product
|
||||
show_and_hide_panels();
|
||||
|
||||
// Make sure the dropdown is not disabled for empty value attributes.
|
||||
$( 'select.attribute_taxonomy' ).find( 'option' ).prop( 'disabled', false );
|
||||
|
||||
$( '.product_attributes .woocommerce_attribute' ).each( function( index, el ) {
|
||||
if ( $( el ).css( 'display' ) !== 'none' && $( el ).is( '.taxonomy' ) ) {
|
||||
$( 'select.attribute_taxonomy' )
|
||||
.find( 'option[value="' + $( el ).data( 'taxonomy' ) + '"]' )
|
||||
.prop( 'disabled', true );
|
||||
}
|
||||
});
|
||||
|
||||
// Reload variations panel.
|
||||
var this_page = window.location.toString();
|
||||
this_page = this_page.replace( 'post-new.php?', 'post.php?post=' + woocommerce_admin_meta_boxes.post_id + '&action=edit&' );
|
||||
|
||||
$( '#variable_product_options' ).load( this_page + ' #variable_product_options_inner', function() {
|
||||
$( '#variable_product_options' ).trigger( 'reload' );
|
||||
} );
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
// Uploading files.
|
||||
var downloadable_file_frame;
|
||||
var file_path_field;
|
||||
|
||||
$( document.body ).on( 'click', '.upload_file_button', function( event ) {
|
||||
var $el = $( this );
|
||||
|
||||
file_path_field = $el.closest( 'tr' ).find( 'td.file_url input' );
|
||||
|
||||
event.preventDefault();
|
||||
|
||||
// If the media frame already exists, reopen it.
|
||||
if ( downloadable_file_frame ) {
|
||||
downloadable_file_frame.open();
|
||||
return;
|
||||
}
|
||||
|
||||
var downloadable_file_states = [
|
||||
// Main states.
|
||||
new wp.media.controller.Library({
|
||||
library: wp.media.query(),
|
||||
multiple: true,
|
||||
title: $el.data('choose'),
|
||||
priority: 20,
|
||||
filterable: 'uploaded'
|
||||
})
|
||||
];
|
||||
|
||||
// Create the media frame.
|
||||
downloadable_file_frame = wp.media.frames.downloadable_file = wp.media({
|
||||
// Set the title of the modal.
|
||||
title: $el.data('choose'),
|
||||
library: {
|
||||
type: ''
|
||||
},
|
||||
button: {
|
||||
text: $el.data('update')
|
||||
},
|
||||
multiple: true,
|
||||
states: downloadable_file_states
|
||||
});
|
||||
|
||||
// When an image is selected, run a callback.
|
||||
downloadable_file_frame.on( 'select', function() {
|
||||
var file_path = '';
|
||||
var selection = downloadable_file_frame.state().get( 'selection' );
|
||||
|
||||
selection.map( function( attachment ) {
|
||||
attachment = attachment.toJSON();
|
||||
if ( attachment.url ) {
|
||||
file_path = attachment.url;
|
||||
}
|
||||
});
|
||||
|
||||
file_path_field.val( file_path ).trigger( 'change' );
|
||||
});
|
||||
|
||||
// Set post to 0 and set our custom type.
|
||||
downloadable_file_frame.on( 'ready', function() {
|
||||
downloadable_file_frame.uploader.options.uploader.params = {
|
||||
type: 'downloadable_product'
|
||||
};
|
||||
});
|
||||
|
||||
// Finally, open the modal.
|
||||
downloadable_file_frame.open();
|
||||
});
|
||||
|
||||
// Download ordering.
|
||||
$( '.downloadable_files tbody' ).sortable({
|
||||
items: 'tr',
|
||||
cursor: 'move',
|
||||
axis: 'y',
|
||||
handle: 'td.sort',
|
||||
scrollSensitivity: 40,
|
||||
forcePlaceholderSize: true,
|
||||
helper: 'clone',
|
||||
opacity: 0.65
|
||||
});
|
||||
|
||||
// Product gallery file uploads.
|
||||
var product_gallery_frame;
|
||||
var $image_gallery_ids = $( '#product_image_gallery' );
|
||||
var $product_images = $( '#product_images_container' ).find( 'ul.product_images' );
|
||||
|
||||
$( '.add_product_images' ).on( 'click', 'a', function( event ) {
|
||||
var $el = $( this );
|
||||
|
||||
event.preventDefault();
|
||||
|
||||
// If the media frame already exists, reopen it.
|
||||
if ( product_gallery_frame ) {
|
||||
product_gallery_frame.open();
|
||||
return;
|
||||
}
|
||||
|
||||
// Create the media frame.
|
||||
product_gallery_frame = wp.media.frames.product_gallery = wp.media({
|
||||
// Set the title of the modal.
|
||||
title: $el.data( 'choose' ),
|
||||
button: {
|
||||
text: $el.data( 'update' )
|
||||
},
|
||||
states: [
|
||||
new wp.media.controller.Library({
|
||||
title: $el.data( 'choose' ),
|
||||
filterable: 'all',
|
||||
multiple: true
|
||||
})
|
||||
]
|
||||
});
|
||||
|
||||
// When an image is selected, run a callback.
|
||||
product_gallery_frame.on( 'select', function() {
|
||||
var selection = product_gallery_frame.state().get( 'selection' );
|
||||
var attachment_ids = $image_gallery_ids.val();
|
||||
|
||||
selection.map( function( attachment ) {
|
||||
attachment = attachment.toJSON();
|
||||
|
||||
if ( attachment.id ) {
|
||||
attachment_ids = attachment_ids ? attachment_ids + ',' + attachment.id : attachment.id;
|
||||
var attachment_image = attachment.sizes && attachment.sizes.thumbnail ? attachment.sizes.thumbnail.url : attachment.url;
|
||||
|
||||
$product_images.append(
|
||||
'<li class="image" data-attachment_id="' + attachment.id + '"><img src="' + attachment_image +
|
||||
'" /><ul class="actions"><li><a href="#" class="delete" title="' + $el.data('delete') + '">' +
|
||||
$el.data('text') + '</a></li></ul></li>'
|
||||
);
|
||||
}
|
||||
});
|
||||
|
||||
$image_gallery_ids.val( attachment_ids );
|
||||
});
|
||||
|
||||
// Finally, open the modal.
|
||||
product_gallery_frame.open();
|
||||
});
|
||||
|
||||
// Image ordering.
|
||||
$product_images.sortable({
|
||||
items: 'li.image',
|
||||
cursor: 'move',
|
||||
scrollSensitivity: 40,
|
||||
forcePlaceholderSize: true,
|
||||
forceHelperSize: false,
|
||||
helper: 'clone',
|
||||
opacity: 0.65,
|
||||
placeholder: 'wc-metabox-sortable-placeholder',
|
||||
start: function( event, ui ) {
|
||||
ui.item.css( 'background-color', '#f6f6f6' );
|
||||
},
|
||||
stop: function( event, ui ) {
|
||||
ui.item.removeAttr( 'style' );
|
||||
},
|
||||
update: function() {
|
||||
var attachment_ids = '';
|
||||
|
||||
$( '#product_images_container' ).find( 'ul li.image' ).css( 'cursor', 'default' ).each( function() {
|
||||
var attachment_id = $( this ).attr( 'data-attachment_id' );
|
||||
attachment_ids = attachment_ids + attachment_id + ',';
|
||||
});
|
||||
|
||||
$image_gallery_ids.val( attachment_ids );
|
||||
}
|
||||
});
|
||||
|
||||
// Remove images.
|
||||
$( '#product_images_container' ).on( 'click', 'a.delete', function() {
|
||||
$( this ).closest( 'li.image' ).remove();
|
||||
|
||||
var attachment_ids = '';
|
||||
|
||||
$( '#product_images_container' ).find( 'ul li.image' ).css( 'cursor', 'default' ).each( function() {
|
||||
var attachment_id = $( this ).attr( 'data-attachment_id' );
|
||||
attachment_ids = attachment_ids + attachment_id + ',';
|
||||
});
|
||||
|
||||
$image_gallery_ids.val( attachment_ids );
|
||||
|
||||
// Remove any lingering tooltips.
|
||||
$( '#tiptip_holder' ).removeAttr( 'style' );
|
||||
$( '#tiptip_arrow' ).removeAttr( 'style' );
|
||||
|
||||
return false;
|
||||
});
|
||||
});
|
1
assets/js/admin/meta-boxes-product.min.js
vendored
Normal file
1
assets/js/admin/meta-boxes-product.min.js
vendored
Normal file
File diff suppressed because one or more lines are too long
80
assets/js/admin/meta-boxes.js
Normal file
80
assets/js/admin/meta-boxes.js
Normal file
@ -0,0 +1,80 @@
|
||||
jQuery( function ( $ ) {
|
||||
|
||||
// Run tipTip
|
||||
function runTipTip() {
|
||||
// Remove any lingering tooltips
|
||||
$( '#tiptip_holder' ).removeAttr( 'style' );
|
||||
$( '#tiptip_arrow' ).removeAttr( 'style' );
|
||||
$( '.tips' ).tipTip({
|
||||
'attribute': 'data-tip',
|
||||
'fadeIn': 50,
|
||||
'fadeOut': 50,
|
||||
'delay': 200,
|
||||
'keepAlive': true
|
||||
});
|
||||
}
|
||||
|
||||
runTipTip();
|
||||
|
||||
$( '.wc-metaboxes-wrapper' ).on( 'click', '.wc-metabox > h3', function() {
|
||||
var metabox = $( this ).parent( '.wc-metabox' );
|
||||
|
||||
if ( metabox.hasClass( 'closed' ) ) {
|
||||
metabox.removeClass( 'closed' );
|
||||
} else {
|
||||
metabox.addClass( 'closed' );
|
||||
}
|
||||
|
||||
if ( metabox.hasClass( 'open' ) ) {
|
||||
metabox.removeClass( 'open' );
|
||||
} else {
|
||||
metabox.addClass( 'open' );
|
||||
}
|
||||
});
|
||||
|
||||
// Tabbed Panels
|
||||
$( document.body ).on( 'wc-init-tabbed-panels', function() {
|
||||
$( 'ul.wc-tabs' ).show();
|
||||
$( 'ul.wc-tabs a' ).on( 'click', function( e ) {
|
||||
e.preventDefault();
|
||||
var panel_wrap = $( this ).closest( 'div.panel-wrap' );
|
||||
$( 'ul.wc-tabs li', panel_wrap ).removeClass( 'active' );
|
||||
$( this ).parent().addClass( 'active' );
|
||||
$( 'div.panel', panel_wrap ).hide();
|
||||
$( $( this ).attr( 'href' ) ).show();
|
||||
});
|
||||
$( 'div.panel-wrap' ).each( function() {
|
||||
$( this ).find( 'ul.wc-tabs li' ).eq( 0 ).find( 'a' ).trigger( 'click' );
|
||||
});
|
||||
}).trigger( 'wc-init-tabbed-panels' );
|
||||
|
||||
// Date Picker
|
||||
$( document.body ).on( 'wc-init-datepickers', function() {
|
||||
$( '.date-picker-field, .date-picker' ).datepicker({
|
||||
dateFormat: 'yy-mm-dd',
|
||||
numberOfMonths: 1,
|
||||
showButtonPanel: true
|
||||
});
|
||||
}).trigger( 'wc-init-datepickers' );
|
||||
|
||||
// Meta-Boxes - Open/close
|
||||
$( '.wc-metaboxes-wrapper' ).on( 'click', '.wc-metabox h3', function( event ) {
|
||||
// If the user clicks on some form input inside the h3, like a select list (for variations), the box should not be toggled
|
||||
if ( $( event.target ).filter( ':input, option, .sort' ).length ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$( this ).next( '.wc-metabox-content' ).stop().slideToggle();
|
||||
})
|
||||
.on( 'click', '.expand_all', function() {
|
||||
$( this ).closest( '.wc-metaboxes-wrapper' ).find( '.wc-metabox > .wc-metabox-content' ).show();
|
||||
return false;
|
||||
})
|
||||
.on( 'click', '.close_all', function() {
|
||||
$( this ).closest( '.wc-metaboxes-wrapper' ).find( '.wc-metabox > .wc-metabox-content' ).hide();
|
||||
return false;
|
||||
});
|
||||
$( '.wc-metabox.closed' ).each( function() {
|
||||
$( this ).find( '.wc-metabox-content' ).hide();
|
||||
});
|
||||
});
|
1
assets/js/admin/meta-boxes.min.js
vendored
Normal file
1
assets/js/admin/meta-boxes.min.js
vendored
Normal file
@ -0,0 +1 @@
|
||||
jQuery(function(t){t("#tiptip_holder").removeAttr("style"),t("#tiptip_arrow").removeAttr("style"),t(".tips").tipTip({attribute:"data-tip",fadeIn:50,fadeOut:50,delay:200,keepAlive:!0}),t(".wc-metaboxes-wrapper").on("click",".wc-metabox > h3",function(){var e=t(this).parent(".wc-metabox");e.hasClass("closed")?e.removeClass("closed"):e.addClass("closed"),e.hasClass("open")?e.removeClass("open"):e.addClass("open")}),t(document.body).on("wc-init-tabbed-panels",function(){t("ul.wc-tabs").show(),t("ul.wc-tabs a").on("click",function(e){e.preventDefault();e=t(this).closest("div.panel-wrap");t("ul.wc-tabs li",e).removeClass("active"),t(this).parent().addClass("active"),t("div.panel",e).hide(),t(t(this).attr("href")).show()}),t("div.panel-wrap").each(function(){t(this).find("ul.wc-tabs li").eq(0).find("a").trigger("click")})}).trigger("wc-init-tabbed-panels"),t(document.body).on("wc-init-datepickers",function(){t(".date-picker-field, .date-picker").datepicker({dateFormat:"yy-mm-dd",numberOfMonths:1,showButtonPanel:!0})}).trigger("wc-init-datepickers"),t(".wc-metaboxes-wrapper").on("click",".wc-metabox h3",function(e){t(e.target).filter(":input, option, .sort").length||t(this).next(".wc-metabox-content").stop().slideToggle()}).on("click",".expand_all",function(){return t(this).closest(".wc-metaboxes-wrapper").find(".wc-metabox > .wc-metabox-content").show(),!1}).on("click",".close_all",function(){return t(this).closest(".wc-metaboxes-wrapper").find(".wc-metabox > .wc-metabox-content").hide(),!1}),t(".wc-metabox.closed").each(function(){t(this).find(".wc-metabox-content").hide()})});
|
90
assets/js/admin/network-orders.js
Normal file
90
assets/js/admin/network-orders.js
Normal file
@ -0,0 +1,90 @@
|
||||
/*global woocommerce_network_orders */
|
||||
(function( $, _, undefined ) {
|
||||
|
||||
if ( 'undefined' === typeof woocommerce_network_orders ) {
|
||||
return;
|
||||
}
|
||||
|
||||
var orders = [],
|
||||
promises = [], // Track completion (pass or fail) of ajax requests.
|
||||
deferred = [], // Tracks the ajax deferreds.
|
||||
$tbody = $( document.getElementById( 'network-orders-tbody' ) ),
|
||||
template = _.template( $( document.getElementById( 'network-orders-row-template') ).text() ),
|
||||
$loadingIndicator = $( document.getElementById( 'woocommerce-network-order-table-loading' ) ),
|
||||
$orderTable = $( document.getElementById( 'woocommerce-network-order-table' ) ),
|
||||
$noneFound = $( document.getElementById( 'woocommerce-network-orders-no-orders' ) );
|
||||
|
||||
// No sites, so bail.
|
||||
if ( ! woocommerce_network_orders.sites.length ) {
|
||||
$loadingIndicator.removeClass( 'is-active' );
|
||||
$orderTable.removeClass( 'is-active' );
|
||||
$noneFound.addClass( 'is-active' );
|
||||
return;
|
||||
}
|
||||
|
||||
$.each( woocommerce_network_orders.sites, function( index, value ) {
|
||||
promises[ index ] = $.Deferred();
|
||||
deferred.push( $.ajax( {
|
||||
url : woocommerce_network_orders.order_endpoint,
|
||||
data: {
|
||||
_wpnonce: woocommerce_network_orders.nonce,
|
||||
network_orders: true,
|
||||
blog_id: value
|
||||
},
|
||||
type: 'GET'
|
||||
} ).success(function( response ) {
|
||||
var orderindex;
|
||||
|
||||
for ( orderindex in response ) {
|
||||
orders.push( response[ orderindex ] );
|
||||
}
|
||||
|
||||
promises[ index ].resolve();
|
||||
}).fail(function (){
|
||||
promises[ index ].resolve();
|
||||
}) );
|
||||
} );
|
||||
|
||||
if ( promises.length > 0 ) {
|
||||
$.when.apply( $, promises ).done( function() {
|
||||
var orderindex,
|
||||
currentOrder;
|
||||
|
||||
// Sort orders, newest first
|
||||
orders.sort(function( a, b ) {
|
||||
var adate, bdate;
|
||||
|
||||
adate = Date.parse( a.date_created_gmt );
|
||||
bdate = Date.parse( b.date_created_gmt );
|
||||
|
||||
if ( adate === bdate ) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
if ( adate < bdate ) {
|
||||
return 1;
|
||||
} else {
|
||||
return -1;
|
||||
}
|
||||
});
|
||||
|
||||
if ( orders.length > 0 ) {
|
||||
for ( orderindex in orders ) {
|
||||
currentOrder = orders[ orderindex ];
|
||||
|
||||
$tbody.append( template( currentOrder ) );
|
||||
}
|
||||
|
||||
$noneFound.removeClass( 'is-active' );
|
||||
$loadingIndicator.removeClass( 'is-active' );
|
||||
$orderTable.addClass( 'is-active' );
|
||||
} else {
|
||||
$noneFound.addClass( 'is-active' );
|
||||
$loadingIndicator.removeClass( 'is-active' );
|
||||
$orderTable.removeClass( 'is-active' );
|
||||
}
|
||||
|
||||
} );
|
||||
}
|
||||
|
||||
})( jQuery, _ );
|
1
assets/js/admin/network-orders.min.js
vendored
Normal file
1
assets/js/admin/network-orders.min.js
vendored
Normal file
@ -0,0 +1 @@
|
||||
!function(o,e){if("undefined"!=typeof woocommerce_network_orders){var t=[],n=[],s=[],r=o(document.getElementById("network-orders-tbody")),a=e.template(o(document.getElementById("network-orders-row-template")).text()),c=o(document.getElementById("woocommerce-network-order-table-loading")),d=o(document.getElementById("woocommerce-network-order-table")),i=o(document.getElementById("woocommerce-network-orders-no-orders"));if(!woocommerce_network_orders.sites.length)return c.removeClass("is-active"),d.removeClass("is-active"),i.addClass("is-active");o.each(woocommerce_network_orders.sites,function(r,e){n[r]=o.Deferred(),s.push(o.ajax({url:woocommerce_network_orders.order_endpoint,data:{_wpnonce:woocommerce_network_orders.nonce,network_orders:!0,blog_id:e},type:"GET"}).success(function(e){for(var o in e)t.push(e[o]);n[r].resolve()}).fail(function(){n[r].resolve()}))}),0<n.length&&o.when.apply(o,n).done(function(){var e,o;if(t.sort(function(e,o){e=Date.parse(e.date_created_gmt),o=Date.parse(o.date_created_gmt);return e===o?0:e<o?1:-1}),0<t.length){for(e in t)o=t[e],r.append(a(o));i.removeClass("is-active"),c.removeClass("is-active"),d.addClass("is-active")}else i.addClass("is-active"),c.removeClass("is-active"),d.removeClass("is-active")})}}(jQuery,_);
|
71
assets/js/admin/product-ordering.js
Normal file
71
assets/js/admin/product-ordering.js
Normal file
@ -0,0 +1,71 @@
|
||||
/*global ajaxurl */
|
||||
|
||||
/**
|
||||
* Based on Simple Page Ordering by 10up (https://wordpress.org/plugins/simple-page-ordering/)
|
||||
*
|
||||
* Modified - products have no children (non hierarchical)
|
||||
*/
|
||||
jQuery( function( $ ) {
|
||||
$( 'table.widefat tbody th, table.widefat tbody td' ).css( 'cursor', 'move' );
|
||||
|
||||
$( 'table.widefat tbody' ).sortable({
|
||||
items: 'tr:not(.inline-edit-row)',
|
||||
cursor: 'move',
|
||||
axis: 'y',
|
||||
containment: 'table.widefat',
|
||||
scrollSensitivity: 40,
|
||||
helper: function( event, ui ) {
|
||||
ui.each( function() {
|
||||
$( this ).width( $( this ).width() );
|
||||
});
|
||||
return ui;
|
||||
},
|
||||
start: function( event, ui ) {
|
||||
ui.item.css( 'background-color', '#ffffff' );
|
||||
ui.item.children( 'td, th' ).css( 'border-bottom-width', '0' );
|
||||
ui.item.css( 'outline', '1px solid #dfdfdf' );
|
||||
},
|
||||
stop: function( event, ui ) {
|
||||
ui.item.removeAttr( 'style' );
|
||||
ui.item.children( 'td,th' ).css( 'border-bottom-width', '1px' );
|
||||
},
|
||||
update: function( event, ui ) {
|
||||
$( 'table.widefat tbody th, table.widefat tbody td' ).css( 'cursor', 'default' );
|
||||
$( 'table.widefat tbody' ).sortable( 'disable' );
|
||||
|
||||
var postid = ui.item.find( '.check-column input' ).val();
|
||||
var prevpostid = ui.item.prev().find( '.check-column input' ).val();
|
||||
var nextpostid = ui.item.next().find( '.check-column input' ).val();
|
||||
|
||||
// Show Spinner
|
||||
ui.item
|
||||
.find( '.check-column input' )
|
||||
.hide()
|
||||
.after( '<img alt="processing" src="images/wpspin_light.gif" class="waiting" style="margin-left: 6px;" />' );
|
||||
|
||||
// Go do the sorting stuff via ajax
|
||||
$.post(
|
||||
ajaxurl,
|
||||
{ action: 'woocommerce_product_ordering', id: postid, previd: prevpostid, nextid: nextpostid },
|
||||
function( response ) {
|
||||
$.each( response, function( key, value ) {
|
||||
$( '#inline_' + key + ' .menu_order' ).html( value );
|
||||
});
|
||||
ui.item.find( '.check-column input' ).show().siblings( 'img' ).remove();
|
||||
$( 'table.widefat tbody th, table.widefat tbody td' ).css( 'cursor', 'move' );
|
||||
$( 'table.widefat tbody' ).sortable( 'enable' );
|
||||
}
|
||||
);
|
||||
|
||||
// fix cell colors
|
||||
$( 'table.widefat tbody tr' ).each( function() {
|
||||
var i = $( 'table.widefat tbody tr' ).index( this );
|
||||
if ( i%2 === 0 ) {
|
||||
$( this ).addClass( 'alternate' );
|
||||
} else {
|
||||
$( this ).removeClass( 'alternate' );
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
1
assets/js/admin/product-ordering.min.js
vendored
Normal file
1
assets/js/admin/product-ordering.min.js
vendored
Normal file
@ -0,0 +1 @@
|
||||
jQuery(function(d){d("table.widefat tbody th, table.widefat tbody td").css("cursor","move"),d("table.widefat tbody").sortable({items:"tr:not(.inline-edit-row)",cursor:"move",axis:"y",containment:"table.widefat",scrollSensitivity:40,helper:function(t,e){return e.each(function(){d(this).width(d(this).width())}),e},start:function(t,e){e.item.css("background-color","#ffffff"),e.item.children("td, th").css("border-bottom-width","0"),e.item.css("outline","1px solid #dfdfdf")},stop:function(t,e){e.item.removeAttr("style"),e.item.children("td,th").css("border-bottom-width","1px")},update:function(t,e){d("table.widefat tbody th, table.widefat tbody td").css("cursor","default"),d("table.widefat tbody").sortable("disable");var i=e.item.find(".check-column input").val(),o=e.item.prev().find(".check-column input").val(),n=e.item.next().find(".check-column input").val();e.item.find(".check-column input").hide().after('<img alt="processing" src="images/wpspin_light.gif" class="waiting" style="margin-left: 6px;" />'),d.post(ajaxurl,{action:"woocommerce_product_ordering",id:i,previd:o,nextid:n},function(t){d.each(t,function(t,e){d("#inline_"+t+" .menu_order").html(e)}),e.item.find(".check-column input").show().siblings("img").remove(),d("table.widefat tbody th, table.widefat tbody td").css("cursor","move"),d("table.widefat tbody").sortable("enable")}),d("table.widefat tbody tr").each(function(){d("table.widefat tbody tr").index(this)%2==0?d(this).addClass("alternate"):d(this).removeClass("alternate")})}})});
|
167
assets/js/admin/quick-edit.js
Normal file
167
assets/js/admin/quick-edit.js
Normal file
@ -0,0 +1,167 @@
|
||||
/*global inlineEditPost, woocommerce_admin, woocommerce_quick_edit */
|
||||
jQuery(
|
||||
function( $ ) {
|
||||
$( '#the-list' ).on(
|
||||
'click',
|
||||
'.editinline',
|
||||
function() {
|
||||
|
||||
inlineEditPost.revert();
|
||||
|
||||
var post_id = $( this ).closest( 'tr' ).attr( 'id' );
|
||||
|
||||
post_id = post_id.replace( 'post-', '' );
|
||||
|
||||
var $wc_inline_data = $( '#woocommerce_inline_' + post_id );
|
||||
|
||||
var sku = $wc_inline_data.find( '.sku' ).text(),
|
||||
regular_price = $wc_inline_data.find( '.regular_price' ).text(),
|
||||
sale_price = $wc_inline_data.find( '.sale_price ' ).text(),
|
||||
weight = $wc_inline_data.find( '.weight' ).text(),
|
||||
length = $wc_inline_data.find( '.length' ).text(),
|
||||
width = $wc_inline_data.find( '.width' ).text(),
|
||||
height = $wc_inline_data.find( '.height' ).text(),
|
||||
shipping_class = $wc_inline_data.find( '.shipping_class' ).text(),
|
||||
visibility = $wc_inline_data.find( '.visibility' ).text(),
|
||||
stock_status = $wc_inline_data.find( '.stock_status' ).text(),
|
||||
stock = $wc_inline_data.find( '.stock' ).text(),
|
||||
featured = $wc_inline_data.find( '.featured' ).text(),
|
||||
manage_stock = $wc_inline_data.find( '.manage_stock' ).text(),
|
||||
menu_order = $wc_inline_data.find( '.menu_order' ).text(),
|
||||
tax_status = $wc_inline_data.find( '.tax_status' ).text(),
|
||||
tax_class = $wc_inline_data.find( '.tax_class' ).text(),
|
||||
backorders = $wc_inline_data.find( '.backorders' ).text(),
|
||||
product_type = $wc_inline_data.find( '.product_type' ).text();
|
||||
|
||||
var formatted_regular_price = regular_price.replace( '.', woocommerce_admin.mon_decimal_point ),
|
||||
formatted_sale_price = sale_price.replace( '.', woocommerce_admin.mon_decimal_point );
|
||||
|
||||
$( 'input[name="_sku"]', '.inline-edit-row' ).val( sku );
|
||||
$( 'input[name="_regular_price"]', '.inline-edit-row' ).val( formatted_regular_price );
|
||||
$( 'input[name="_sale_price"]', '.inline-edit-row' ).val( formatted_sale_price );
|
||||
$( 'input[name="_weight"]', '.inline-edit-row' ).val( weight );
|
||||
$( 'input[name="_length"]', '.inline-edit-row' ).val( length );
|
||||
$( 'input[name="_width"]', '.inline-edit-row' ).val( width );
|
||||
$( 'input[name="_height"]', '.inline-edit-row' ).val( height );
|
||||
|
||||
$( 'select[name="_shipping_class"] option:selected', '.inline-edit-row' ).attr( 'selected', false ).trigger( 'change' );
|
||||
$( 'select[name="_shipping_class"] option[value="' + shipping_class + '"]' ).attr( 'selected', 'selected' )
|
||||
.trigger( 'change' );
|
||||
|
||||
$( 'input[name="_stock"]', '.inline-edit-row' ).val( stock );
|
||||
$( 'input[name="menu_order"]', '.inline-edit-row' ).val( menu_order );
|
||||
|
||||
$(
|
||||
'select[name="_tax_status"] option, ' +
|
||||
'select[name="_tax_class"] option, ' +
|
||||
'select[name="_visibility"] option, ' +
|
||||
'select[name="_stock_status"] option, ' +
|
||||
'select[name="_backorders"] option'
|
||||
).prop( 'selected', false ).removeAttr( 'selected' );
|
||||
|
||||
var is_variable_product = 'variable' === product_type;
|
||||
$( 'select[name="_stock_status"] ~ .wc-quick-edit-warning', '.inline-edit-row' ).toggle( is_variable_product );
|
||||
$( 'select[name="_stock_status"] option[value="' + (is_variable_product ? '' : stock_status) + '"]', '.inline-edit-row' )
|
||||
.attr( 'selected', 'selected' );
|
||||
|
||||
$( 'select[name="_tax_status"] option[value="' + tax_status + '"]', '.inline-edit-row' ).attr( 'selected', 'selected' );
|
||||
$( 'select[name="_tax_class"] option[value="' + tax_class + '"]', '.inline-edit-row' ).attr( 'selected', 'selected' );
|
||||
$( 'select[name="_visibility"] option[value="' + visibility + '"]', '.inline-edit-row' ).attr( 'selected', 'selected' );
|
||||
$( 'select[name="_backorders"] option[value="' + backorders + '"]', '.inline-edit-row' ).attr( 'selected', 'selected' );
|
||||
|
||||
if ( 'yes' === featured ) {
|
||||
$( 'input[name="_featured"]', '.inline-edit-row' ).prop( 'checked', true );
|
||||
} else {
|
||||
$( 'input[name="_featured"]', '.inline-edit-row' ).prop( 'checked', false );
|
||||
}
|
||||
|
||||
// Conditional display.
|
||||
var product_is_virtual = $wc_inline_data.find( '.product_is_virtual' ).text();
|
||||
|
||||
var product_supports_stock_status = 'external' !== product_type;
|
||||
var product_supports_stock_fields = 'external' !== product_type && 'grouped' !== product_type;
|
||||
|
||||
$( '.stock_fields, .manage_stock_field, .stock_status_field, .backorder_field' ).show();
|
||||
|
||||
if ( product_supports_stock_fields ) {
|
||||
if ( 'yes' === manage_stock ) {
|
||||
$( '.stock_qty_field, .backorder_field', '.inline-edit-row' ).show().removeAttr( 'style' );
|
||||
$( '.stock_status_field' ).hide();
|
||||
$( '.manage_stock_field input' ).prop( 'checked', true );
|
||||
} else {
|
||||
$( '.stock_qty_field, .backorder_field', '.inline-edit-row' ).hide();
|
||||
$( '.stock_status_field' ).show().removeAttr( 'style' );
|
||||
$( '.manage_stock_field input' ).prop( 'checked', false );
|
||||
}
|
||||
} else if ( product_supports_stock_status ) {
|
||||
$( '.stock_fields, .manage_stock_field, .backorder_field' ).hide();
|
||||
} else {
|
||||
$( '.stock_fields, .manage_stock_field, .stock_status_field, .backorder_field' ).hide();
|
||||
}
|
||||
|
||||
if ( 'simple' === product_type || 'external' === product_type ) {
|
||||
$( '.price_fields', '.inline-edit-row' ).show().removeAttr( 'style' );
|
||||
} else {
|
||||
$( '.price_fields', '.inline-edit-row' ).hide();
|
||||
}
|
||||
|
||||
if ( 'yes' === product_is_virtual ) {
|
||||
$( '.dimension_fields', '.inline-edit-row' ).hide();
|
||||
} else {
|
||||
$( '.dimension_fields', '.inline-edit-row' ).show().removeAttr( 'style' );
|
||||
}
|
||||
|
||||
// Rename core strings.
|
||||
$( 'input[name="comment_status"]' ).parent().find( '.checkbox-title' ).text( woocommerce_quick_edit.strings.allow_reviews );
|
||||
}
|
||||
);
|
||||
|
||||
$( '#the-list' ).on(
|
||||
'change',
|
||||
'.inline-edit-row input[name="_manage_stock"]',
|
||||
function() {
|
||||
|
||||
if ( $( this ).is( ':checked' ) ) {
|
||||
$( '.stock_qty_field, .backorder_field', '.inline-edit-row' ).show().removeAttr( 'style' );
|
||||
$( '.stock_status_field' ).hide();
|
||||
} else {
|
||||
$( '.stock_qty_field, .backorder_field', '.inline-edit-row' ).hide();
|
||||
$( '.stock_status_field' ).show().removeAttr( 'style' );
|
||||
}
|
||||
|
||||
}
|
||||
);
|
||||
|
||||
$( '#wpbody' ).on(
|
||||
'click',
|
||||
'#doaction, #doaction2',
|
||||
function() {
|
||||
$( 'input.text', '.inline-edit-row' ).val( '' );
|
||||
$( '#woocommerce-fields' ).find( 'select' ).prop( 'selectedIndex', 0 );
|
||||
$( '#woocommerce-fields-bulk' ).find( '.inline-edit-group .change-input' ).hide();
|
||||
}
|
||||
);
|
||||
|
||||
$( '#wpbody' ).on(
|
||||
'change',
|
||||
'#woocommerce-fields-bulk .inline-edit-group .change_to',
|
||||
function() {
|
||||
|
||||
if ( 0 < $( this ).val() ) {
|
||||
$( this ).closest( 'div' ).find( '.change-input' ).show();
|
||||
} else {
|
||||
$( this ).closest( 'div' ).find( '.change-input' ).hide();
|
||||
}
|
||||
|
||||
}
|
||||
);
|
||||
|
||||
$( '#wpbody' ).on(
|
||||
'click',
|
||||
'.trash-product',
|
||||
function() {
|
||||
return window.confirm( woocommerce_admin.i18n_delete_product_notice );
|
||||
}
|
||||
);
|
||||
}
|
||||
);
|
1
assets/js/admin/quick-edit.min.js
vendored
Normal file
1
assets/js/admin/quick-edit.min.js
vendored
Normal file
@ -0,0 +1 @@
|
||||
jQuery(function(g){g("#the-list").on("click",".editinline",function(){inlineEditPost.revert();var e=(e=g(this).closest("tr").attr("id")).replace("post-",""),t=g("#woocommerce_inline_"+e),i=t.find(".sku").text(),n=t.find(".regular_price").text(),o=t.find(".sale_price ").text(),d=t.find(".weight").text(),s=t.find(".length").text(),l=t.find(".width").text(),c=t.find(".height").text(),a=t.find(".shipping_class").text(),r=t.find(".visibility").text(),_=t.find(".stock_status").text(),p=t.find(".stock").text(),m=t.find(".featured").text(),u=t.find(".manage_stock").text(),f=t.find(".menu_order").text(),w=t.find(".tax_status").text(),h=t.find(".tax_class").text(),k=t.find(".backorders").text(),e=t.find(".product_type").text(),n=n.replace(".",woocommerce_admin.mon_decimal_point),o=o.replace(".",woocommerce_admin.mon_decimal_point);g('input[name="_sku"]',".inline-edit-row").val(i),g('input[name="_regular_price"]',".inline-edit-row").val(n),g('input[name="_sale_price"]',".inline-edit-row").val(o),g('input[name="_weight"]',".inline-edit-row").val(d),g('input[name="_length"]',".inline-edit-row").val(s),g('input[name="_width"]',".inline-edit-row").val(l),g('input[name="_height"]',".inline-edit-row").val(c),g('select[name="_shipping_class"] option:selected',".inline-edit-row").attr("selected",!1).trigger("change"),g('select[name="_shipping_class"] option[value="'+a+'"]').attr("selected","selected").trigger("change"),g('input[name="_stock"]',".inline-edit-row").val(p),g('input[name="menu_order"]',".inline-edit-row").val(f),g('select[name="_tax_status"] option, select[name="_tax_class"] option, select[name="_visibility"] option, select[name="_stock_status"] option, select[name="_backorders"] option').prop("selected",!1).removeAttr("selected");f="variable"===e;g('select[name="_stock_status"] ~ .wc-quick-edit-warning',".inline-edit-row").toggle(f),g('select[name="_stock_status"] option[value="'+(f?"":_)+'"]',".inline-edit-row").attr("selected","selected"),g('select[name="_tax_status"] option[value="'+w+'"]',".inline-edit-row").attr("selected","selected"),g('select[name="_tax_class"] option[value="'+h+'"]',".inline-edit-row").attr("selected","selected"),g('select[name="_visibility"] option[value="'+r+'"]',".inline-edit-row").attr("selected","selected"),g('select[name="_backorders"] option[value="'+k+'"]',".inline-edit-row").attr("selected","selected"),"yes"===m?g('input[name="_featured"]',".inline-edit-row").prop("checked",!0):g('input[name="_featured"]',".inline-edit-row").prop("checked",!1);k=t.find(".product_is_virtual").text(),m="external"!==e,t="external"!==e&&"grouped"!==e;g(".stock_fields, .manage_stock_field, .stock_status_field, .backorder_field").show(),t?"yes"===u?(g(".stock_qty_field, .backorder_field",".inline-edit-row").show().removeAttr("style"),g(".stock_status_field").hide(),g(".manage_stock_field input").prop("checked",!0)):(g(".stock_qty_field, .backorder_field",".inline-edit-row").hide(),g(".stock_status_field").show().removeAttr("style"),g(".manage_stock_field input").prop("checked",!1)):g(m?".stock_fields, .manage_stock_field, .backorder_field":".stock_fields, .manage_stock_field, .stock_status_field, .backorder_field").hide(),"simple"===e||"external"===e?g(".price_fields",".inline-edit-row").show().removeAttr("style"):g(".price_fields",".inline-edit-row").hide(),"yes"===k?g(".dimension_fields",".inline-edit-row").hide():g(".dimension_fields",".inline-edit-row").show().removeAttr("style"),g('input[name="comment_status"]').parent().find(".checkbox-title").text(woocommerce_quick_edit.strings.allow_reviews)}),g("#the-list").on("change",'.inline-edit-row input[name="_manage_stock"]',function(){g(this).is(":checked")?(g(".stock_qty_field, .backorder_field",".inline-edit-row").show().removeAttr("style"),g(".stock_status_field").hide()):(g(".stock_qty_field, .backorder_field",".inline-edit-row").hide(),g(".stock_status_field").show().removeAttr("style"))}),g("#wpbody").on("click","#doaction, #doaction2",function(){g("input.text",".inline-edit-row").val(""),g("#woocommerce-fields").find("select").prop("selectedIndex",0),g("#woocommerce-fields-bulk").find(".inline-edit-group .change-input").hide()}),g("#wpbody").on("change","#woocommerce-fields-bulk .inline-edit-group .change_to",function(){0<g(this).val()?g(this).closest("div").find(".change-input").show():g(this).closest("div").find(".change-input").hide()}),g("#wpbody").on("click",".trash-product",function(){return window.confirm(woocommerce_admin.i18n_delete_product_notice)})});
|
257
assets/js/admin/reports.js
Normal file
257
assets/js/admin/reports.js
Normal file
@ -0,0 +1,257 @@
|
||||
jQuery(function( $ ) {
|
||||
|
||||
function showTooltip( x, y, contents ) {
|
||||
$( '<div class="chart-tooltip">' + contents + '</div>' ).css( {
|
||||
top: y - 16,
|
||||
left: x + 20
|
||||
}).appendTo( 'body' ).fadeIn( 200 );
|
||||
}
|
||||
|
||||
var prev_data_index = null;
|
||||
var prev_series_index = null;
|
||||
|
||||
$( '.chart-placeholder' ).on( 'plothover', function ( event, pos, item ) {
|
||||
if ( item ) {
|
||||
if ( prev_data_index !== item.dataIndex || prev_series_index !== item.seriesIndex ) {
|
||||
prev_data_index = item.dataIndex;
|
||||
prev_series_index = item.seriesIndex;
|
||||
|
||||
$( '.chart-tooltip' ).remove();
|
||||
|
||||
if ( item.series.points.show || item.series.enable_tooltip ) {
|
||||
|
||||
var y = item.series.data[item.dataIndex][1],
|
||||
tooltip_content = '';
|
||||
|
||||
if ( item.series.prepend_label ) {
|
||||
tooltip_content = tooltip_content + item.series.label + ': ';
|
||||
}
|
||||
|
||||
if ( item.series.prepend_tooltip ) {
|
||||
tooltip_content = tooltip_content + item.series.prepend_tooltip;
|
||||
}
|
||||
|
||||
tooltip_content = tooltip_content + y;
|
||||
|
||||
if ( item.series.append_tooltip ) {
|
||||
tooltip_content = tooltip_content + item.series.append_tooltip;
|
||||
}
|
||||
|
||||
if ( item.series.pie.show ) {
|
||||
showTooltip( pos.pageX, pos.pageY, tooltip_content );
|
||||
} else {
|
||||
showTooltip( item.pageX, item.pageY, tooltip_content );
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
$( '.chart-tooltip' ).remove();
|
||||
prev_data_index = null;
|
||||
}
|
||||
});
|
||||
|
||||
$( '.wc_sparkline.bars' ).each( function() {
|
||||
var chart_data = $( this ).data( 'sparkline' );
|
||||
|
||||
var options = {
|
||||
grid: {
|
||||
show: false
|
||||
}
|
||||
};
|
||||
|
||||
// main series
|
||||
var series = [{
|
||||
data: chart_data,
|
||||
color: $( this ).data( 'color' ),
|
||||
bars: {
|
||||
fillColor: $( this ).data( 'color' ),
|
||||
fill: true,
|
||||
show: true,
|
||||
lineWidth: 1,
|
||||
barWidth: $( this ).data( 'barwidth' ),
|
||||
align: 'center'
|
||||
},
|
||||
shadowSize: 0
|
||||
}];
|
||||
|
||||
// draw the sparkline
|
||||
$.plot( $( this ), series, options );
|
||||
});
|
||||
|
||||
$( '.wc_sparkline.lines' ).each( function() {
|
||||
var chart_data = $( this ).data( 'sparkline' );
|
||||
|
||||
var options = {
|
||||
grid: {
|
||||
show: false
|
||||
}
|
||||
};
|
||||
|
||||
// main series
|
||||
var series = [{
|
||||
data: chart_data,
|
||||
color: $( this ).data( 'color' ),
|
||||
lines: {
|
||||
fill: false,
|
||||
show: true,
|
||||
lineWidth: 1,
|
||||
align: 'center'
|
||||
},
|
||||
shadowSize: 0
|
||||
}];
|
||||
|
||||
// draw the sparkline
|
||||
$.plot( $( this ), series, options );
|
||||
});
|
||||
|
||||
var dates = $( '.range_datepicker' ).datepicker({
|
||||
changeMonth: true,
|
||||
changeYear: true,
|
||||
defaultDate: '',
|
||||
dateFormat: 'yy-mm-dd',
|
||||
numberOfMonths: 1,
|
||||
minDate: '-20Y',
|
||||
maxDate: '+1D',
|
||||
showButtonPanel: true,
|
||||
showOn: 'focus',
|
||||
buttonImageOnly: true,
|
||||
onSelect: function() {
|
||||
var option = $( this ).is( '.from' ) ? 'minDate' : 'maxDate',
|
||||
date = $( this ).datepicker( 'getDate' );
|
||||
|
||||
dates.not( this ).datepicker( 'option', option, date );
|
||||
}
|
||||
});
|
||||
|
||||
var a = document.createElement( 'a' );
|
||||
|
||||
if ( typeof a.download === 'undefined' ) {
|
||||
$( '.export_csv' ).hide();
|
||||
}
|
||||
|
||||
// Export
|
||||
$( '.export_csv' ).on( 'click', function() {
|
||||
var exclude_series = $( this ).data( 'exclude_series' ) || '';
|
||||
exclude_series = exclude_series.toString();
|
||||
exclude_series = exclude_series.split( ',' );
|
||||
var xaxes_label = $( this ).data( 'xaxes' );
|
||||
var groupby = $( this ) .data( 'groupby' );
|
||||
var index_type = $( this ).data( 'index_type' );
|
||||
var export_format = $( this ).data( 'export' );
|
||||
var csv_data = '';
|
||||
var s, series_data, d;
|
||||
|
||||
if ( 'table' === export_format ) {
|
||||
|
||||
$( this ).offsetParent().find( 'thead tr,tbody tr' ).each( function() {
|
||||
$( this ).find( 'th, td' ).each( function() {
|
||||
var value = $( this ).text();
|
||||
value = value.replace( '[?]', '' ).replace( '#', '' );
|
||||
csv_data += '"' + value + '"' + ',';
|
||||
});
|
||||
csv_data = csv_data.substring( 0, csv_data.length - 1 );
|
||||
csv_data += '\n';
|
||||
});
|
||||
|
||||
$( this ).offsetParent().find( 'tfoot tr' ).each( function() {
|
||||
$( this ).find( 'th, td' ).each( function() {
|
||||
var value = $( this ).text();
|
||||
value = value.replace( '[?]', '' ).replace( '#', '' );
|
||||
csv_data += '"' + value + '"' + ',';
|
||||
if ( $( this ).attr( 'colspan' ) > 0 ) {
|
||||
for ( i = 1; i < $(this).attr('colspan'); i++ ) {
|
||||
csv_data += '"",';
|
||||
}
|
||||
}
|
||||
});
|
||||
csv_data = csv_data.substring( 0, csv_data.length - 1 );
|
||||
csv_data += '\n';
|
||||
});
|
||||
|
||||
} else {
|
||||
|
||||
if ( ! window.main_chart ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
var the_series = window.main_chart.getData();
|
||||
var series = [];
|
||||
csv_data += '"' + xaxes_label + '",';
|
||||
|
||||
$.each( the_series, function( index, value ) {
|
||||
if ( ! exclude_series || $.inArray( index.toString(), exclude_series ) === -1 ) {
|
||||
series.push( value );
|
||||
}
|
||||
});
|
||||
|
||||
// CSV Headers
|
||||
for ( s = 0; s < series.length; ++s ) {
|
||||
csv_data += '"' + series[s].label + '",';
|
||||
}
|
||||
|
||||
csv_data = csv_data.substring( 0, csv_data.length - 1 );
|
||||
csv_data += '\n';
|
||||
|
||||
// Get x axis values
|
||||
var xaxis = {};
|
||||
|
||||
for ( s = 0; s < series.length; ++s ) {
|
||||
series_data = series[s].data;
|
||||
for ( d = 0; d < series_data.length; ++d ) {
|
||||
xaxis[series_data[d][0]] = [];
|
||||
// Zero values to start
|
||||
for ( var i = 0; i < series.length; ++i ) {
|
||||
xaxis[series_data[d][0]].push(0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Add chart data
|
||||
for ( s = 0; s < series.length; ++s ) {
|
||||
series_data = series[s].data;
|
||||
for ( d = 0; d < series_data.length; ++d ) {
|
||||
xaxis[series_data[d][0]][s] = series_data[d][1];
|
||||
}
|
||||
}
|
||||
|
||||
// Loop data and output to csv string
|
||||
$.each( xaxis, function( index, value ) {
|
||||
var date = new Date( parseInt( index, 10 ) );
|
||||
|
||||
if ( 'none' === index_type ) {
|
||||
csv_data += '"' + index + '",';
|
||||
} else {
|
||||
if ( groupby === 'day' ) {
|
||||
csv_data += '"' +
|
||||
date.getUTCFullYear() +
|
||||
'-' +
|
||||
parseInt( date.getUTCMonth() + 1, 10 ) +
|
||||
'-' +
|
||||
date.getUTCDate() +
|
||||
'",';
|
||||
} else {
|
||||
csv_data += '"' + date.getUTCFullYear() + '-' + parseInt( date.getUTCMonth() + 1, 10 ) + '",';
|
||||
}
|
||||
}
|
||||
|
||||
for ( var d = 0; d < value.length; ++d ) {
|
||||
var val = value[d];
|
||||
|
||||
if ( Math.round( val ) !== val ) {
|
||||
val = parseFloat( val );
|
||||
val = val.toFixed( 2 );
|
||||
}
|
||||
|
||||
csv_data += '"' + val + '",';
|
||||
}
|
||||
csv_data = csv_data.substring( 0, csv_data.length - 1 );
|
||||
csv_data += '\n';
|
||||
} );
|
||||
}
|
||||
|
||||
csv_data = 'data:text/csv;charset=utf-8,\uFEFF' + encodeURIComponent( csv_data );
|
||||
// Set data as href and return
|
||||
$( this ).attr( 'href', csv_data );
|
||||
return true;
|
||||
});
|
||||
});
|
1
assets/js/admin/reports.min.js
vendored
Normal file
1
assets/js/admin/reports.min.js
vendored
Normal file
@ -0,0 +1 @@
|
||||
jQuery(function(p){function r(t,e,a){p('<div class="chart-tooltip">'+a+"</div>").css({top:e-16,left:t+20}).appendTo("body").fadeIn(200)}var o=null,s=null;p(".chart-placeholder").on("plothover",function(t,e,a){var n,i;a?o===a.dataIndex&&s===a.seriesIndex||(o=a.dataIndex,s=a.seriesIndex,p(".chart-tooltip").remove(),(a.series.points.show||a.series.enable_tooltip)&&(n=a.series.data[a.dataIndex][1],i="",a.series.prepend_label&&(i=i+a.series.label+": "),a.series.prepend_tooltip&&(i+=a.series.prepend_tooltip),i+=n,a.series.append_tooltip&&(i+=a.series.append_tooltip),a.series.pie.show?r(e.pageX,e.pageY,i):r(a.pageX,a.pageY,i))):(p(".chart-tooltip").remove(),o=null)}),p(".wc_sparkline.bars").each(function(){var t=[{data:p(this).data("sparkline"),color:p(this).data("color"),bars:{fillColor:p(this).data("color"),fill:!0,show:!0,lineWidth:1,barWidth:p(this).data("barwidth"),align:"center"},shadowSize:0}];p.plot(p(this),t,{grid:{show:!1}})}),p(".wc_sparkline.lines").each(function(){var t=[{data:p(this).data("sparkline"),color:p(this).data("color"),lines:{fill:!1,show:!0,lineWidth:1,align:"center"},shadowSize:0}];p.plot(p(this),t,{grid:{show:!1}})});var a=p(".range_datepicker").datepicker({changeMonth:!0,changeYear:!0,defaultDate:"",dateFormat:"yy-mm-dd",numberOfMonths:1,minDate:"-20Y",maxDate:"+1D",showButtonPanel:!0,showOn:"focus",buttonImageOnly:!0,onSelect:function(){var t=p(this).is(".from")?"minDate":"maxDate",e=p(this).datepicker("getDate");a.not(this).datepicker("option",t,e)}});"undefined"==typeof document.createElement("a").download&&p(".export_csv").hide(),p(".export_csv").on("click",function(){var a=p(this).data("exclude_series")||"";a=(a=a.toString()).split(",");var t,e,n=p(this).data("xaxes"),r=p(this).data("groupby"),o=p(this).data("index_type"),i=p(this).data("export"),s="";if("table"===i)p(this).offsetParent().find("thead tr,tbody tr").each(function(){p(this).find("th, td").each(function(){var t=(t=p(this).text()).replace("[?]","").replace("#","");s+='"'+t+'",'}),s=s.substring(0,s.length-1),s+="\n"}),p(this).offsetParent().find("tfoot tr").each(function(){p(this).find("th, td").each(function(){var t=(t=p(this).text()).replace("[?]","").replace("#","");if(s+='"'+t+'",',0<p(this).attr("colspan"))for(c=1;c<p(this).attr("colspan");c++)s+='"",'}),s=s.substring(0,s.length-1),s+="\n"});else{if(!window.main_chart)return!1;var i=window.main_chart.getData(),l=[];for(s+='"'+n+'",',p.each(i,function(t,e){a&&-1!==p.inArray(t.toString(),a)||l.push(e)}),d=0;d<l.length;++d)s+='"'+l[d].label+'",';s=s.substring(0,s.length-1),s+="\n";for(var h={},d=0;d<l.length;++d)for(t=l[d].data,e=0;e<t.length;++e){h[t[e][0]]=[];for(var c=0;c<l.length;++c)h[t[e][0]].push(0)}for(d=0;d<l.length;++d)for(t=l[d].data,e=0;e<t.length;++e)h[t[e][0]][d]=t[e][1];p.each(h,function(t,e){var a=new Date(parseInt(t,10));s+="none"===o?'"'+t+'",':"day"===r?'"'+a.getUTCFullYear()+"-"+parseInt(a.getUTCMonth()+1,10)+"-"+a.getUTCDate()+'",':'"'+a.getUTCFullYear()+"-"+parseInt(a.getUTCMonth()+1,10)+'",';for(var n=0;n<e.length;++n){var i=e[n];Math.round(i)!==i&&(i=(i=parseFloat(i)).toFixed(2)),s+='"'+i+'",'}s=s.substring(0,s.length-1),s+="\n"})}return s="data:text/csv;charset=utf-8,\ufeff"+encodeURIComponent(s),p(this).attr("href",s),!0})});
|
383
assets/js/admin/settings-views-html-settings-tax.js
Normal file
383
assets/js/admin/settings-views-html-settings-tax.js
Normal file
@ -0,0 +1,383 @@
|
||||
/* global htmlSettingsTaxLocalizeScript, ajaxurl */
|
||||
|
||||
/**
|
||||
* Used by woocommerce/includes/admin/settings/views/html-settings-tax.php
|
||||
*/
|
||||
( function( $, data, wp, ajaxurl ) {
|
||||
$( function() {
|
||||
|
||||
if ( ! String.prototype.trim ) {
|
||||
String.prototype.trim = function () {
|
||||
return this.replace( /^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g, '' );
|
||||
};
|
||||
}
|
||||
|
||||
var rowTemplate = wp.template( 'wc-tax-table-row' ),
|
||||
rowTemplateEmpty = wp.template( 'wc-tax-table-row-empty' ),
|
||||
paginationTemplate = wp.template( 'wc-tax-table-pagination' ),
|
||||
$table = $( '.wc_tax_rates' ),
|
||||
$tbody = $( '#rates' ),
|
||||
$save_button = $( ':input[name="save"]' ),
|
||||
$pagination = $( '#rates-pagination' ),
|
||||
$search_field = $( '#rates-search .wc-tax-rates-search-field' ),
|
||||
$submit = $( '.submit .button-primary[type=submit]' ),
|
||||
WCTaxTableModelConstructor = Backbone.Model.extend({
|
||||
changes: {},
|
||||
setRateAttribute: function( rateID, attribute, value ) {
|
||||
var rates = _.indexBy( this.get( 'rates' ), 'tax_rate_id' ),
|
||||
changes = {};
|
||||
|
||||
if ( rates[ rateID ][ attribute ] !== value ) {
|
||||
changes[ rateID ] = {};
|
||||
changes[ rateID ][ attribute ] = value;
|
||||
rates[ rateID ][ attribute ] = value;
|
||||
}
|
||||
|
||||
this.logChanges( changes );
|
||||
},
|
||||
logChanges: function( changedRows ) {
|
||||
var changes = this.changes || {};
|
||||
|
||||
_.each( changedRows, function( row, id ) {
|
||||
changes[ id ] = _.extend( changes[ id ] || {
|
||||
tax_rate_id : id
|
||||
}, row );
|
||||
} );
|
||||
|
||||
this.changes = changes;
|
||||
this.trigger( 'change:rates' );
|
||||
},
|
||||
getFilteredRates: function() {
|
||||
var rates = this.get( 'rates' ),
|
||||
search = $search_field.val().toLowerCase();
|
||||
|
||||
if ( search.length ) {
|
||||
rates = _.filter( rates, function( rate ) {
|
||||
var search_text = _.toArray( rate ).join( ' ' ).toLowerCase();
|
||||
return ( -1 !== search_text.indexOf( search ) );
|
||||
} );
|
||||
}
|
||||
|
||||
rates = _.sortBy( rates, function( rate ) {
|
||||
return parseInt( rate.tax_rate_order, 10 );
|
||||
} );
|
||||
|
||||
return rates;
|
||||
},
|
||||
block: function() {
|
||||
$( '.wc_tax_rates' ).block({
|
||||
message: null,
|
||||
overlayCSS: {
|
||||
background: '#fff',
|
||||
opacity: 0.6
|
||||
}
|
||||
});
|
||||
},
|
||||
unblock: function() {
|
||||
$( '.wc_tax_rates' ).unblock();
|
||||
},
|
||||
save: function() {
|
||||
var self = this;
|
||||
|
||||
self.block();
|
||||
|
||||
Backbone.ajax({
|
||||
method: 'POST',
|
||||
dataType: 'json',
|
||||
url: ajaxurl + ( ajaxurl.indexOf( '?' ) > 0 ? '&' : '?' ) + 'action=woocommerce_tax_rates_save_changes',
|
||||
data: {
|
||||
current_class: data.current_class,
|
||||
wc_tax_nonce: data.wc_tax_nonce,
|
||||
changes: self.changes
|
||||
},
|
||||
success: function( response, textStatus ) {
|
||||
if ( 'success' === textStatus && response.success ) {
|
||||
WCTaxTableModelInstance.set( 'rates', response.data.rates );
|
||||
WCTaxTableModelInstance.trigger( 'change:rates' );
|
||||
|
||||
WCTaxTableModelInstance.changes = {};
|
||||
WCTaxTableModelInstance.trigger( 'saved:rates' );
|
||||
|
||||
// Reload view.
|
||||
WCTaxTableInstance.render();
|
||||
}
|
||||
|
||||
self.unblock();
|
||||
}
|
||||
});
|
||||
}
|
||||
} ),
|
||||
WCTaxTableViewConstructor = Backbone.View.extend({
|
||||
rowTemplate: rowTemplate,
|
||||
per_page: data.limit,
|
||||
page: data.page,
|
||||
initialize: function() {
|
||||
var qty_pages = Math.ceil( _.toArray( this.model.get( 'rates' ) ).length / this.per_page );
|
||||
|
||||
this.qty_pages = 0 === qty_pages ? 1 : qty_pages;
|
||||
this.page = this.sanitizePage( data.page );
|
||||
|
||||
this.listenTo( this.model, 'change:rates', this.setUnloadConfirmation );
|
||||
this.listenTo( this.model, 'saved:rates', this.clearUnloadConfirmation );
|
||||
$tbody.on( 'change autocompletechange', ':input', { view: this }, this.updateModelOnChange );
|
||||
$search_field.on( 'keyup search', { view: this }, this.onSearchField );
|
||||
$pagination.on( 'click', 'a', { view: this }, this.onPageChange );
|
||||
$pagination.on( 'change', 'input', { view: this }, this.onPageChange );
|
||||
$( window ).on( 'beforeunload', { view: this }, this.unloadConfirmation );
|
||||
$submit.on( 'click', { view: this }, this.onSubmit );
|
||||
$save_button.prop( 'disabled', true );
|
||||
|
||||
// Can bind these directly to the buttons, as they won't get overwritten.
|
||||
$table.find( '.insert' ).on( 'click', { view: this }, this.onAddNewRow );
|
||||
$table.find( '.remove_tax_rates' ).on( 'click', { view: this }, this.onDeleteRow );
|
||||
$table.find( '.export' ).on( 'click', { view: this }, this.onExport );
|
||||
},
|
||||
render: function() {
|
||||
var rates = this.model.getFilteredRates(),
|
||||
qty_rates = _.size( rates ),
|
||||
qty_pages = Math.ceil( qty_rates / this.per_page ),
|
||||
first_index = 0 === qty_rates ? 0 : this.per_page * ( this.page - 1 ),
|
||||
last_index = this.per_page * this.page,
|
||||
paged_rates = _.toArray( rates ).slice( first_index, last_index ),
|
||||
view = this;
|
||||
|
||||
// Blank out the contents.
|
||||
this.$el.empty();
|
||||
|
||||
if ( paged_rates.length ) {
|
||||
// Populate $tbody with the current page of results.
|
||||
$.each( paged_rates, function( id, rowData ) {
|
||||
view.$el.append( view.rowTemplate( rowData ) );
|
||||
} );
|
||||
} else {
|
||||
view.$el.append( rowTemplateEmpty() );
|
||||
}
|
||||
|
||||
// Initialize autocomplete for countries.
|
||||
this.$el.find( 'td.country input' ).autocomplete({
|
||||
source: data.countries,
|
||||
minLength: 2
|
||||
});
|
||||
|
||||
// Initialize autocomplete for states.
|
||||
this.$el.find( 'td.state input' ).autocomplete({
|
||||
source: data.states,
|
||||
minLength: 3
|
||||
});
|
||||
|
||||
// Postcode and city don't have `name` values by default.
|
||||
// They're only created if the contents changes, to save on database queries (I think)
|
||||
this.$el.find( 'td.postcode input, td.city input' ).on( 'change', function() {
|
||||
$( this ).attr( 'name', $( this ).data( 'name' ) );
|
||||
});
|
||||
|
||||
if ( qty_pages > 1 ) {
|
||||
// We've now displayed our initial page, time to render the pagination box.
|
||||
$pagination.html( paginationTemplate( {
|
||||
qty_rates: qty_rates,
|
||||
current_page: this.page,
|
||||
qty_pages: qty_pages
|
||||
} ) );
|
||||
} else {
|
||||
$pagination.empty();
|
||||
view.page = 1;
|
||||
}
|
||||
},
|
||||
updateUrl: function() {
|
||||
if ( ! window.history.replaceState ) {
|
||||
return;
|
||||
}
|
||||
|
||||
var url = data.base_url,
|
||||
search = $search_field.val();
|
||||
|
||||
if ( 1 < this.page ) {
|
||||
url += '&p=' + encodeURIComponent( this.page );
|
||||
}
|
||||
|
||||
if ( search.length ) {
|
||||
url += '&s=' + encodeURIComponent( search );
|
||||
}
|
||||
|
||||
window.history.replaceState( {}, '', url );
|
||||
},
|
||||
onSubmit: function( event ) {
|
||||
event.data.view.model.save();
|
||||
event.preventDefault();
|
||||
},
|
||||
onAddNewRow: function( event ) {
|
||||
var view = event.data.view,
|
||||
model = view.model,
|
||||
rates = _.indexBy( model.get( 'rates' ), 'tax_rate_id' ),
|
||||
changes = {},
|
||||
size = _.size( rates ),
|
||||
newRow = _.extend( {}, data.default_rate, {
|
||||
tax_rate_id: 'new-' + size + '-' + Date.now(),
|
||||
newRow: true
|
||||
} ),
|
||||
$current, current_id, current_order, rates_to_reorder, reordered_rates;
|
||||
|
||||
$current = $tbody.children( '.current' );
|
||||
|
||||
if ( $current.length ) {
|
||||
current_id = $current.last().data( 'id' );
|
||||
current_order = parseInt( rates[ current_id ].tax_rate_order, 10 );
|
||||
newRow.tax_rate_order = 1 + current_order;
|
||||
|
||||
rates_to_reorder = _.filter( rates, function( rate ) {
|
||||
if ( parseInt( rate.tax_rate_order, 10 ) > current_order ) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
} );
|
||||
|
||||
reordered_rates = _.map( rates_to_reorder, function( rate ) {
|
||||
rate.tax_rate_order++;
|
||||
changes[ rate.tax_rate_id ] = _.extend(
|
||||
changes[ rate.tax_rate_id ] || {}, { tax_rate_order : rate.tax_rate_order }
|
||||
);
|
||||
return rate;
|
||||
} );
|
||||
} else {
|
||||
newRow.tax_rate_order = 1 + _.max(
|
||||
_.pluck( rates, 'tax_rate_order' ),
|
||||
function ( val ) {
|
||||
// Cast them all to integers, because strings compare funky. Sighhh.
|
||||
return parseInt( val, 10 );
|
||||
}
|
||||
);
|
||||
// Move the last page
|
||||
view.page = view.qty_pages;
|
||||
}
|
||||
|
||||
rates[ newRow.tax_rate_id ] = newRow;
|
||||
changes[ newRow.tax_rate_id ] = newRow;
|
||||
|
||||
model.set( 'rates', rates );
|
||||
model.logChanges( changes );
|
||||
|
||||
view.render();
|
||||
},
|
||||
onDeleteRow: function( event ) {
|
||||
var view = event.data.view,
|
||||
model = view.model,
|
||||
rates = _.indexBy( model.get( 'rates' ), 'tax_rate_id' ),
|
||||
changes = {},
|
||||
$current, current_id;
|
||||
|
||||
event.preventDefault();
|
||||
|
||||
if ( $current = $tbody.children( '.current' ) ) {
|
||||
$current.each(function(){
|
||||
current_id = $( this ).data('id');
|
||||
|
||||
delete rates[ current_id ];
|
||||
|
||||
changes[ current_id ] = _.extend( changes[ current_id ] || {}, { deleted : 'deleted' } );
|
||||
});
|
||||
|
||||
model.set( 'rates', rates );
|
||||
model.logChanges( changes );
|
||||
|
||||
view.render();
|
||||
} else {
|
||||
window.alert( data.strings.no_rows_selected );
|
||||
}
|
||||
},
|
||||
onSearchField: function( event ){
|
||||
event.data.view.updateUrl();
|
||||
event.data.view.render();
|
||||
},
|
||||
onPageChange: function( event ) {
|
||||
var $target = $( event.currentTarget );
|
||||
|
||||
event.preventDefault();
|
||||
event.data.view.page = $target.data( 'goto' ) ? $target.data( 'goto' ) : $target.val();
|
||||
event.data.view.render();
|
||||
event.data.view.updateUrl();
|
||||
},
|
||||
onExport: function( event ) {
|
||||
var csv_data = 'data:application/csv;charset=utf-8,' + data.strings.csv_data_cols.join(',') + '\n';
|
||||
|
||||
$.each( event.data.view.model.getFilteredRates(), function( id, rowData ) {
|
||||
var row = '';
|
||||
|
||||
row += rowData.tax_rate_country + ',';
|
||||
row += rowData.tax_rate_state + ',';
|
||||
row += ( rowData.postcode ? rowData.postcode.join( '; ' ) : '' ) + ',';
|
||||
row += ( rowData.city ? rowData.city.join( '; ' ) : '' ) + ',';
|
||||
row += rowData.tax_rate + ',';
|
||||
row += rowData.tax_rate_name + ',';
|
||||
row += rowData.tax_rate_priority + ',';
|
||||
row += rowData.tax_rate_compound + ',';
|
||||
row += rowData.tax_rate_shipping + ',';
|
||||
row += data.current_class;
|
||||
|
||||
csv_data += row + '\n';
|
||||
});
|
||||
|
||||
$( this ).attr( 'href', encodeURI( csv_data ) );
|
||||
|
||||
return true;
|
||||
},
|
||||
setUnloadConfirmation: function() {
|
||||
this.needsUnloadConfirm = true;
|
||||
$save_button.prop( 'disabled', false );
|
||||
},
|
||||
clearUnloadConfirmation: function() {
|
||||
this.needsUnloadConfirm = false;
|
||||
$save_button.prop( 'disabled', true );
|
||||
},
|
||||
unloadConfirmation: function( event ) {
|
||||
if ( event.data.view.needsUnloadConfirm ) {
|
||||
event.returnValue = data.strings.unload_confirmation_msg;
|
||||
window.event.returnValue = data.strings.unload_confirmation_msg;
|
||||
return data.strings.unload_confirmation_msg;
|
||||
}
|
||||
},
|
||||
updateModelOnChange: function( event ) {
|
||||
var model = event.data.view.model,
|
||||
$target = $( event.target ),
|
||||
id = $target.closest( 'tr' ).data( 'id' ),
|
||||
attribute = $target.data( 'attribute' ),
|
||||
val = $target.val();
|
||||
|
||||
if ( 'city' === attribute || 'postcode' === attribute ) {
|
||||
val = val.split( ';' );
|
||||
val = $.map( val, function( thing ) {
|
||||
return thing.trim();
|
||||
});
|
||||
}
|
||||
|
||||
if ( 'tax_rate_compound' === attribute || 'tax_rate_shipping' === attribute ) {
|
||||
if ( $target.is( ':checked' ) ) {
|
||||
val = 1;
|
||||
} else {
|
||||
val = 0;
|
||||
}
|
||||
}
|
||||
|
||||
model.setRateAttribute( id, attribute, val );
|
||||
},
|
||||
sanitizePage: function( page_num ) {
|
||||
page_num = parseInt( page_num, 10 );
|
||||
if ( page_num < 1 ) {
|
||||
page_num = 1;
|
||||
} else if ( page_num > this.qty_pages ) {
|
||||
page_num = this.qty_pages;
|
||||
}
|
||||
return page_num;
|
||||
}
|
||||
} ),
|
||||
WCTaxTableModelInstance = new WCTaxTableModelConstructor({
|
||||
rates: data.rates
|
||||
} ),
|
||||
WCTaxTableInstance = new WCTaxTableViewConstructor({
|
||||
model: WCTaxTableModelInstance,
|
||||
el: '#rates'
|
||||
} );
|
||||
|
||||
WCTaxTableInstance.render();
|
||||
|
||||
});
|
||||
})( jQuery, htmlSettingsTaxLocalizeScript, wp, ajaxurl );
|
1
assets/js/admin/settings-views-html-settings-tax.min.js
vendored
Normal file
1
assets/js/admin/settings-views-html-settings-tax.min.js
vendored
Normal file
File diff suppressed because one or more lines are too long
183
assets/js/admin/settings.js
Normal file
183
assets/js/admin/settings.js
Normal file
@ -0,0 +1,183 @@
|
||||
/* global woocommerce_settings_params, wp */
|
||||
( function( $, params, wp ) {
|
||||
$( function() {
|
||||
// Sell Countries
|
||||
$( 'select#woocommerce_allowed_countries' ).on( 'change', function() {
|
||||
if ( 'specific' === $( this ).val() ) {
|
||||
$( this ).closest('tr').next( 'tr' ).hide();
|
||||
$( this ).closest('tr').next().next( 'tr' ).show();
|
||||
} else if ( 'all_except' === $( this ).val() ) {
|
||||
$( this ).closest('tr').next( 'tr' ).show();
|
||||
$( this ).closest('tr').next().next( 'tr' ).hide();
|
||||
} else {
|
||||
$( this ).closest('tr').next( 'tr' ).hide();
|
||||
$( this ).closest('tr').next().next( 'tr' ).hide();
|
||||
}
|
||||
}).trigger( 'change' );
|
||||
|
||||
// Ship Countries
|
||||
$( 'select#woocommerce_ship_to_countries' ).on( 'change', function() {
|
||||
if ( 'specific' === $( this ).val() ) {
|
||||
$( this ).closest('tr').next( 'tr' ).show();
|
||||
} else {
|
||||
$( this ).closest('tr').next( 'tr' ).hide();
|
||||
}
|
||||
}).trigger( 'change' );
|
||||
|
||||
// Stock management
|
||||
$( 'input#woocommerce_manage_stock' ).on( 'change', function() {
|
||||
if ( $( this ).is(':checked') ) {
|
||||
$( this ).closest('tbody').find( '.manage_stock_field' ).closest( 'tr' ).show();
|
||||
} else {
|
||||
$( this ).closest('tbody').find( '.manage_stock_field' ).closest( 'tr' ).hide();
|
||||
}
|
||||
}).trigger( 'change' );
|
||||
|
||||
// Color picker
|
||||
$( '.colorpick' )
|
||||
|
||||
.iris({
|
||||
change: function( event, ui ) {
|
||||
$( this ).parent().find( '.colorpickpreview' ).css({ backgroundColor: ui.color.toString() });
|
||||
},
|
||||
hide: true,
|
||||
border: true
|
||||
})
|
||||
|
||||
.on( 'click focus', function( event ) {
|
||||
event.stopPropagation();
|
||||
$( '.iris-picker' ).hide();
|
||||
$( this ).closest( 'td' ).find( '.iris-picker' ).show();
|
||||
$( this ).data( 'originalValue', $( this ).val() );
|
||||
})
|
||||
|
||||
.on( 'change', function() {
|
||||
if ( $( this ).is( '.iris-error' ) ) {
|
||||
var original_value = $( this ).data( 'originalValue' );
|
||||
|
||||
if ( original_value.match( /^\#([a-fA-F0-9]{6}|[a-fA-F0-9]{3})$/ ) ) {
|
||||
$( this ).val( $( this ).data( 'originalValue' ) ).trigger( 'change' );
|
||||
} else {
|
||||
$( this ).val( '' ).trigger( 'change' );
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
$( 'body' ).on( 'click', function() {
|
||||
$( '.iris-picker' ).hide();
|
||||
});
|
||||
|
||||
// Edit prompt
|
||||
$( function() {
|
||||
var changed = false;
|
||||
|
||||
$( 'input, textarea, select, checkbox' ).on( 'change', function() {
|
||||
if ( ! changed ) {
|
||||
window.onbeforeunload = function() {
|
||||
return params.i18n_nav_warning;
|
||||
};
|
||||
changed = true;
|
||||
}
|
||||
});
|
||||
|
||||
$( '.submit :input' ).on( 'click', function() {
|
||||
window.onbeforeunload = '';
|
||||
});
|
||||
});
|
||||
|
||||
// Sorting
|
||||
$( 'table.wc_gateways tbody, table.wc_shipping tbody' ).sortable({
|
||||
items: 'tr',
|
||||
cursor: 'move',
|
||||
axis: 'y',
|
||||
handle: 'td.sort',
|
||||
scrollSensitivity: 40,
|
||||
helper: function( event, ui ) {
|
||||
ui.children().each( function() {
|
||||
$( this ).width( $( this ).width() );
|
||||
});
|
||||
ui.css( 'left', '0' );
|
||||
return ui;
|
||||
},
|
||||
start: function( event, ui ) {
|
||||
ui.item.css( 'background-color', '#f6f6f6' );
|
||||
},
|
||||
stop: function( event, ui ) {
|
||||
ui.item.removeAttr( 'style' );
|
||||
ui.item.trigger( 'updateMoveButtons' );
|
||||
}
|
||||
});
|
||||
|
||||
// Select all/none
|
||||
$( '.woocommerce' ).on( 'click', '.select_all', function() {
|
||||
$( this ).closest( 'td' ).find( 'select option' ).prop( 'selected', true );
|
||||
$( this ).closest( 'td' ).find( 'select' ).trigger( 'change' );
|
||||
return false;
|
||||
});
|
||||
|
||||
$( '.woocommerce' ).on( 'click', '.select_none', function() {
|
||||
$( this ).closest( 'td' ).find( 'select option' ).prop( 'selected', false );
|
||||
$( this ).closest( 'td' ).find( 'select' ).trigger( 'change' );
|
||||
return false;
|
||||
});
|
||||
|
||||
// Re-order buttons.
|
||||
$( '.wc-item-reorder-nav').find( '.wc-move-up, .wc-move-down' ).on( 'click', function() {
|
||||
var moveBtn = $( this ),
|
||||
$row = moveBtn.closest( 'tr' );
|
||||
|
||||
moveBtn.trigger( 'focus' );
|
||||
|
||||
var isMoveUp = moveBtn.is( '.wc-move-up' ),
|
||||
isMoveDown = moveBtn.is( '.wc-move-down' );
|
||||
|
||||
if ( isMoveUp ) {
|
||||
var $previewRow = $row.prev( 'tr' );
|
||||
|
||||
if ( $previewRow && $previewRow.length ) {
|
||||
$previewRow.before( $row );
|
||||
wp.a11y.speak( params.i18n_moved_up );
|
||||
}
|
||||
} else if ( isMoveDown ) {
|
||||
var $nextRow = $row.next( 'tr' );
|
||||
|
||||
if ( $nextRow && $nextRow.length ) {
|
||||
$nextRow.after( $row );
|
||||
wp.a11y.speak( params.i18n_moved_down );
|
||||
}
|
||||
}
|
||||
|
||||
moveBtn.trigger( 'focus' ); // Re-focus after the container was moved.
|
||||
moveBtn.closest( 'table' ).trigger( 'updateMoveButtons' );
|
||||
} );
|
||||
|
||||
$( '.wc-item-reorder-nav').closest( 'table' ).on( 'updateMoveButtons', function() {
|
||||
var table = $( this ),
|
||||
lastRow = $( this ).find( 'tbody tr:last' ),
|
||||
firstRow = $( this ).find( 'tbody tr:first' );
|
||||
|
||||
table.find( '.wc-item-reorder-nav .wc-move-disabled' ).removeClass( 'wc-move-disabled' )
|
||||
.attr( { 'tabindex': '0', 'aria-hidden': 'false' } );
|
||||
firstRow.find( '.wc-item-reorder-nav .wc-move-up' ).addClass( 'wc-move-disabled' )
|
||||
.attr( { 'tabindex': '-1', 'aria-hidden': 'true' } );
|
||||
lastRow.find( '.wc-item-reorder-nav .wc-move-down' ).addClass( 'wc-move-disabled' )
|
||||
.attr( { 'tabindex': '-1', 'aria-hidden': 'true' } );
|
||||
} );
|
||||
|
||||
$( '.wc-item-reorder-nav').closest( 'table' ).trigger( 'updateMoveButtons' );
|
||||
|
||||
|
||||
$( '.submit button' ).on( 'click', function() {
|
||||
if (
|
||||
$( 'select#woocommerce_allowed_countries' ).val() === 'specific' &&
|
||||
! $( '[name="woocommerce_specific_allowed_countries[]"]' ).val()
|
||||
) {
|
||||
if ( window.confirm( woocommerce_settings_params.i18n_no_specific_countries_selected ) ) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
} );
|
||||
|
||||
});
|
||||
})( jQuery, woocommerce_settings_params, wp );
|
1
assets/js/admin/settings.min.js
vendored
Normal file
1
assets/js/admin/settings.min.js
vendored
Normal file
@ -0,0 +1 @@
|
||||
!function(n,c,s){n(function(){n("select#woocommerce_allowed_countries").on("change",function(){"specific"===n(this).val()?(n(this).closest("tr").next("tr").hide(),n(this).closest("tr").next().next("tr").show()):("all_except"===n(this).val()?n(this).closest("tr").next("tr").show():n(this).closest("tr").next("tr").hide(),n(this).closest("tr").next().next("tr").hide())}).trigger("change"),n("select#woocommerce_ship_to_countries").on("change",function(){"specific"===n(this).val()?n(this).closest("tr").next("tr").show():n(this).closest("tr").next("tr").hide()}).trigger("change"),n("input#woocommerce_manage_stock").on("change",function(){n(this).is(":checked")?n(this).closest("tbody").find(".manage_stock_field").closest("tr").show():n(this).closest("tbody").find(".manage_stock_field").closest("tr").hide()}).trigger("change"),n(".colorpick").iris({change:function(e,t){n(this).parent().find(".colorpickpreview").css({backgroundColor:t.color.toString()})},hide:!0,border:!0}).on("click focus",function(e){e.stopPropagation(),n(".iris-picker").hide(),n(this).closest("td").find(".iris-picker").show(),n(this).data("originalValue",n(this).val())}).on("change",function(){n(this).is(".iris-error")&&(n(this).data("originalValue").match(/^\#([a-fA-F0-9]{6}|[a-fA-F0-9]{3})$/)?n(this).val(n(this).data("originalValue")):n(this).val("")).trigger("change")}),n("body").on("click",function(){n(".iris-picker").hide()}),n(function(){var e=!1;n("input, textarea, select, checkbox").on("change",function(){e||(window.onbeforeunload=function(){return c.i18n_nav_warning},e=!0)}),n(".submit :input").on("click",function(){window.onbeforeunload=""})}),n("table.wc_gateways tbody, table.wc_shipping tbody").sortable({items:"tr",cursor:"move",axis:"y",handle:"td.sort",scrollSensitivity:40,helper:function(e,t){return t.children().each(function(){n(this).width(n(this).width())}),t.css("left","0"),t},start:function(e,t){t.item.css("background-color","#f6f6f6")},stop:function(e,t){t.item.removeAttr("style"),t.item.trigger("updateMoveButtons")}}),n(".woocommerce").on("click",".select_all",function(){return n(this).closest("td").find("select option").prop("selected",!0),n(this).closest("td").find("select").trigger("change"),!1}),n(".woocommerce").on("click",".select_none",function(){return n(this).closest("td").find("select option").prop("selected",!1),n(this).closest("td").find("select").trigger("change"),!1}),n(".wc-item-reorder-nav").find(".wc-move-up, .wc-move-down").on("click",function(){var e=n(this),t=e.closest("tr");e.trigger("focus");var i=e.is(".wc-move-up"),o=e.is(".wc-move-down");i?(i=t.prev("tr"))&&i.length&&(i.before(t),s.a11y.speak(c.i18n_moved_up)):!o||(o=t.next("tr"))&&o.length&&(o.after(t),s.a11y.speak(c.i18n_moved_down)),e.trigger("focus"),e.closest("table").trigger("updateMoveButtons")}),n(".wc-item-reorder-nav").closest("table").on("updateMoveButtons",function(){var e=n(this),t=n(this).find("tbody tr:last"),i=n(this).find("tbody tr:first");e.find(".wc-item-reorder-nav .wc-move-disabled").removeClass("wc-move-disabled").attr({tabindex:"0","aria-hidden":"false"}),i.find(".wc-item-reorder-nav .wc-move-up").addClass("wc-move-disabled").attr({tabindex:"-1","aria-hidden":"true"}),t.find(".wc-item-reorder-nav .wc-move-down").addClass("wc-move-disabled").attr({tabindex:"-1","aria-hidden":"true"})}),n(".wc-item-reorder-nav").closest("table").trigger("updateMoveButtons"),n(".submit button").on("click",function(){if("specific"===n("select#woocommerce_allowed_countries").val()&&!n('[name="woocommerce_specific_allowed_countries[]"]').val())return!!window.confirm(woocommerce_settings_params.i18n_no_specific_countries_selected)})})}(jQuery,woocommerce_settings_params,wp);
|
126
assets/js/admin/system-status.js
Normal file
126
assets/js/admin/system-status.js
Normal file
@ -0,0 +1,126 @@
|
||||
/* global jQuery, woocommerce_admin_system_status, wcSetClipboard, wcClearClipboard */
|
||||
jQuery( function ( $ ) {
|
||||
|
||||
/**
|
||||
* Users country and state fields
|
||||
*/
|
||||
var wcSystemStatus = {
|
||||
init: function() {
|
||||
$( document.body )
|
||||
.on( 'click', 'a.help_tip, a.woocommerce-help-tip', this.preventTipTipClick )
|
||||
.on( 'click', 'a.debug-report', this.generateReport )
|
||||
.on( 'click', '#copy-for-support', this.copyReport )
|
||||
.on( 'aftercopy', '#copy-for-support', this.copySuccess )
|
||||
.on( 'aftercopyfailure', '#copy-for-support', this.copyFail );
|
||||
},
|
||||
|
||||
/**
|
||||
* Prevent anchor behavior when click on TipTip.
|
||||
*
|
||||
* @return {Bool}
|
||||
*/
|
||||
preventTipTipClick: function() {
|
||||
return false;
|
||||
},
|
||||
|
||||
/**
|
||||
* Generate system status report.
|
||||
*
|
||||
* @return {Bool}
|
||||
*/
|
||||
generateReport: function() {
|
||||
var report = '';
|
||||
|
||||
$( '.wc_status_table thead, .wc_status_table tbody' ).each( function() {
|
||||
if ( $( this ).is( 'thead' ) ) {
|
||||
var label = $( this ).find( 'th:eq(0)' ).data( 'exportLabel' ) || $( this ).text();
|
||||
report = report + '\n### ' + label.trim() + ' ###\n\n';
|
||||
} else {
|
||||
$( 'tr', $( this ) ).each( function() {
|
||||
var label = $( this ).find( 'td:eq(0)' ).data( 'exportLabel' ) || $( this ).find( 'td:eq(0)' ).text();
|
||||
var the_name = label.trim().replace( /(<([^>]+)>)/ig, '' ); // Remove HTML.
|
||||
|
||||
// Find value
|
||||
var $value_html = $( this ).find( 'td:eq(2)' ).clone();
|
||||
$value_html.find( '.private' ).remove();
|
||||
$value_html.find( '.dashicons-yes' ).replaceWith( '✔' );
|
||||
$value_html.find( '.dashicons-no-alt, .dashicons-warning' ).replaceWith( '❌' );
|
||||
|
||||
// Format value
|
||||
var the_value = $value_html.text().trim();
|
||||
var value_array = the_value.split( ', ' );
|
||||
|
||||
if ( value_array.length > 1 ) {
|
||||
// If value have a list of plugins ','.
|
||||
// Split to add new line.
|
||||
var temp_line ='';
|
||||
$.each( value_array, function( key, line ) {
|
||||
temp_line = temp_line + line + '\n';
|
||||
});
|
||||
|
||||
the_value = temp_line;
|
||||
}
|
||||
|
||||
report = report + '' + the_name + ': ' + the_value + '\n';
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
try {
|
||||
$( '#debug-report' ).slideDown();
|
||||
$( '#debug-report' ).find( 'textarea' ).val( '`' + report + '`' ).trigger( 'focus' ).trigger( 'select' );
|
||||
$( this ).fadeOut();
|
||||
return false;
|
||||
} catch ( e ) {
|
||||
/* jshint devel: true */
|
||||
console.log( e );
|
||||
}
|
||||
|
||||
return false;
|
||||
},
|
||||
|
||||
/**
|
||||
* Copy for report.
|
||||
*
|
||||
* @param {Object} evt Copy event.
|
||||
*/
|
||||
copyReport: function( evt ) {
|
||||
wcClearClipboard();
|
||||
wcSetClipboard( $( '#debug-report' ).find( 'textarea' ).val(), $( this ) );
|
||||
evt.preventDefault();
|
||||
},
|
||||
|
||||
/**
|
||||
* Display a "Copied!" tip when success copying
|
||||
*/
|
||||
copySuccess: function() {
|
||||
$( '#copy-for-support' ).tipTip({
|
||||
'attribute': 'data-tip',
|
||||
'activation': 'focus',
|
||||
'fadeIn': 50,
|
||||
'fadeOut': 50,
|
||||
'delay': 0
|
||||
}).trigger( 'focus' );
|
||||
},
|
||||
|
||||
/**
|
||||
* Displays the copy error message when failure copying.
|
||||
*/
|
||||
copyFail: function() {
|
||||
$( '.copy-error' ).removeClass( 'hidden' );
|
||||
$( '#debug-report' ).find( 'textarea' ).trigger( 'focus' ).trigger( 'select' );
|
||||
}
|
||||
};
|
||||
|
||||
wcSystemStatus.init();
|
||||
|
||||
$( '.wc_status_table' ).on( 'click', '.run-tool .button', function( evt ) {
|
||||
evt.stopImmediatePropagation();
|
||||
return window.confirm( woocommerce_admin_system_status.run_tool_confirmation );
|
||||
});
|
||||
|
||||
$( '#log-viewer-select' ).on( 'click', 'h2 a.page-title-action', function( evt ) {
|
||||
evt.stopImmediatePropagation();
|
||||
return window.confirm( woocommerce_admin_system_status.delete_log_confirmation );
|
||||
});
|
||||
});
|
1
assets/js/admin/system-status.min.js
vendored
Normal file
1
assets/js/admin/system-status.min.js
vendored
Normal file
@ -0,0 +1 @@
|
||||
jQuery(function(n){({init:function(){n(document.body).on("click","a.help_tip, a.woocommerce-help-tip",this.preventTipTipClick).on("click","a.debug-report",this.generateReport).on("click","#copy-for-support",this.copyReport).on("aftercopy","#copy-for-support",this.copySuccess).on("aftercopyfailure","#copy-for-support",this.copyFail)},preventTipTipClick:function(){return!1},generateReport:function(){var r="";n(".wc_status_table thead, .wc_status_table tbody").each(function(){var t;n(this).is("thead")?(t=n(this).find("th:eq(0)").data("exportLabel")||n(this).text(),r=r+"\n### "+t.trim()+" ###\n\n"):n("tr",n(this)).each(function(){var t=(n(this).find("td:eq(0)").data("exportLabel")||n(this).find("td:eq(0)").text()).trim().replace(/(<([^>]+)>)/gi,""),e=n(this).find("td:eq(2)").clone();e.find(".private").remove(),e.find(".dashicons-yes").replaceWith("✔"),e.find(".dashicons-no-alt, .dashicons-warning").replaceWith("❌");var o,i=e.text().trim(),e=i.split(", ");1<e.length&&(o="",n.each(e,function(t,e){o=o+e+"\n"}),i=o),r=r+""+t+": "+i+"\n"})});try{return n("#debug-report").slideDown(),n("#debug-report").find("textarea").val("`"+r+"`").trigger("focus").trigger("select"),n(this).fadeOut(),!1}catch(t){console.log(t)}return!1},copyReport:function(t){wcClearClipboard(),wcSetClipboard(n("#debug-report").find("textarea").val(),n(this)),t.preventDefault()},copySuccess:function(){n("#copy-for-support").tipTip({attribute:"data-tip",activation:"focus",fadeIn:50,fadeOut:50,delay:0}).trigger("focus")},copyFail:function(){n(".copy-error").removeClass("hidden"),n("#debug-report").find("textarea").trigger("focus").trigger("select")}}).init(),n(".wc_status_table").on("click",".run-tool .button",function(t){return t.stopImmediatePropagation(),window.confirm(woocommerce_admin_system_status.run_tool_confirmation)}),n("#log-viewer-select").on("click","h2 a.page-title-action",function(t){return t.stopImmediatePropagation(),window.confirm(woocommerce_admin_system_status.delete_log_confirmation)})});
|
137
assets/js/admin/term-ordering.js
Normal file
137
assets/js/admin/term-ordering.js
Normal file
@ -0,0 +1,137 @@
|
||||
/*global ajaxurl, woocommerce_term_ordering_params */
|
||||
|
||||
/* Modifided script from the simple-page-ordering plugin */
|
||||
jQuery( function( $ ) {
|
||||
|
||||
var table_selector = 'table.wp-list-table',
|
||||
item_selector = 'tbody tr:not(.inline-edit-row)',
|
||||
term_id_selector = '.column-handle input[name="term_id"]',
|
||||
column_handle = '<td class="column-handle"></td>';
|
||||
|
||||
if ( 0 === $( table_selector ).find( '.column-handle' ).length ) {
|
||||
$( table_selector ).find( 'tr:not(.inline-edit-row)' ).append( column_handle );
|
||||
|
||||
term_id_selector = '.check-column input';
|
||||
}
|
||||
|
||||
$( table_selector ).find( '.column-handle' ).show();
|
||||
|
||||
$.wc_add_missing_sort_handles = function() {
|
||||
var all_table_rows = $( table_selector ).find('tbody > tr');
|
||||
var rows_with_handle = $( table_selector ).find('tbody > tr > td.column-handle').parent();
|
||||
if ( all_table_rows.length !== rows_with_handle.length ) {
|
||||
all_table_rows.each(function(index, elem){
|
||||
if ( ! rows_with_handle.is( elem ) ) {
|
||||
$( elem ).append( column_handle );
|
||||
}
|
||||
});
|
||||
}
|
||||
$( table_selector ).find( '.column-handle' ).show();
|
||||
};
|
||||
|
||||
$( document ).ajaxComplete( function( event, request, options ) {
|
||||
if (
|
||||
request &&
|
||||
4 === request.readyState &&
|
||||
200 === request.status &&
|
||||
options.data &&
|
||||
( 0 <= options.data.indexOf( '_inline_edit' ) || 0 <= options.data.indexOf( 'add-tag' ) )
|
||||
) {
|
||||
$.wc_add_missing_sort_handles();
|
||||
$( document.body ).trigger( 'init_tooltips' );
|
||||
}
|
||||
} );
|
||||
|
||||
$( table_selector ).sortable({
|
||||
items: item_selector,
|
||||
cursor: 'move',
|
||||
handle: '.column-handle',
|
||||
axis: 'y',
|
||||
forcePlaceholderSize: true,
|
||||
helper: 'clone',
|
||||
opacity: 0.65,
|
||||
placeholder: 'product-cat-placeholder',
|
||||
scrollSensitivity: 40,
|
||||
start: function( event, ui ) {
|
||||
if ( ! ui.item.hasClass( 'alternate' ) ) {
|
||||
ui.item.css( 'background-color', '#ffffff' );
|
||||
}
|
||||
ui.item.children( 'td, th' ).css( 'border-bottom-width', '0' );
|
||||
ui.item.css( 'outline', '1px solid #aaa' );
|
||||
},
|
||||
stop: function( event, ui ) {
|
||||
ui.item.removeAttr( 'style' );
|
||||
ui.item.children( 'td, th' ).css( 'border-bottom-width', '1px' );
|
||||
},
|
||||
update: function( event, ui ) {
|
||||
var termid = ui.item.find( term_id_selector ).val(); // this post id
|
||||
var termparent = ui.item.find( '.parent' ).html(); // post parent
|
||||
|
||||
var prevtermid = ui.item.prev().find( term_id_selector ).val();
|
||||
var nexttermid = ui.item.next().find( term_id_selector ).val();
|
||||
|
||||
// Can only sort in same tree
|
||||
var prevtermparent, nexttermparent;
|
||||
if ( prevtermid !== undefined ) {
|
||||
prevtermparent = ui.item.prev().find( '.parent' ).html();
|
||||
if ( prevtermparent !== termparent) {
|
||||
prevtermid = undefined;
|
||||
}
|
||||
}
|
||||
|
||||
if ( nexttermid !== undefined ) {
|
||||
nexttermparent = ui.item.next().find( '.parent' ).html();
|
||||
if ( nexttermparent !== termparent) {
|
||||
nexttermid = undefined;
|
||||
}
|
||||
}
|
||||
|
||||
// If previous and next not at same tree level, or next not at same tree level and
|
||||
// the previous is the parent of the next, or just moved item beneath its own children.
|
||||
if (
|
||||
( prevtermid === undefined && nexttermid === undefined ) ||
|
||||
( nexttermid === undefined && nexttermparent === prevtermid ) ||
|
||||
( nexttermid !== undefined && prevtermparent === termid )
|
||||
) {
|
||||
$( table_selector ).sortable( 'cancel' );
|
||||
return;
|
||||
}
|
||||
|
||||
// Show Spinner
|
||||
ui.item.find( '.check-column input' ).hide();
|
||||
ui.item
|
||||
.find( '.check-column' )
|
||||
.append( '<img alt="processing" src="images/wpspin_light.gif" class="waiting" style="margin-left: 6px;" />' );
|
||||
|
||||
// Go do the sorting stuff via ajax.
|
||||
$.post(
|
||||
ajaxurl,
|
||||
{
|
||||
action: 'woocommerce_term_ordering',
|
||||
id: termid,
|
||||
nextid: nexttermid,
|
||||
thetaxonomy: woocommerce_term_ordering_params.taxonomy
|
||||
},
|
||||
function(response) {
|
||||
if ( response === 'children' ) {
|
||||
window.location.reload();
|
||||
} else {
|
||||
ui.item.find( '.check-column input' ).show();
|
||||
ui.item.find( '.check-column' ).find( 'img' ).remove();
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
// Fix cell colors
|
||||
$( 'table.widefat tbody tr' ).each( function() {
|
||||
var i = jQuery( 'table.widefat tbody tr' ).index( this );
|
||||
if ( i%2 === 0 ) {
|
||||
jQuery( this ).addClass( 'alternate' );
|
||||
} else {
|
||||
jQuery( this ).removeClass( 'alternate' );
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
});
|
1
assets/js/admin/term-ordering.min.js
vendored
Normal file
1
assets/js/admin/term-ordering.min.js
vendored
Normal file
@ -0,0 +1 @@
|
||||
jQuery(function(r){var c="table.wp-list-table",m='.column-handle input[name="term_id"]',i='<td class="column-handle"></td>';0===r(c).find(".column-handle").length&&(r(c).find("tr:not(.inline-edit-row)").append(i),m=".check-column input"),r(c).find(".column-handle").show(),r.wc_add_missing_sort_handles=function(){var e=r(c).find("tbody > tr"),n=r(c).find("tbody > tr > td.column-handle").parent();e.length!==n.length&&e.each(function(e,t){n.is(t)||r(t).append(i)}),r(c).find(".column-handle").show()},r(document).ajaxComplete(function(e,t,n){t&&4===t.readyState&&200===t.status&&n.data&&(0<=n.data.indexOf("_inline_edit")||0<=n.data.indexOf("add-tag"))&&(r.wc_add_missing_sort_handles(),r(document.body).trigger("init_tooltips"))}),r(c).sortable({items:"tbody tr:not(.inline-edit-row)",cursor:"move",handle:".column-handle",axis:"y",forcePlaceholderSize:!0,helper:"clone",opacity:.65,placeholder:"product-cat-placeholder",scrollSensitivity:40,start:function(e,t){t.item.hasClass("alternate")||t.item.css("background-color","#ffffff"),t.item.children("td, th").css("border-bottom-width","0"),t.item.css("outline","1px solid #aaa")},stop:function(e,t){t.item.removeAttr("style"),t.item.children("td, th").css("border-bottom-width","1px")},update:function(e,t){var n,i,d=t.item.find(m).val(),a=t.item.find(".parent").html(),o=t.item.prev().find(m).val(),l=t.item.next().find(m).val();o!==undefined&&(n=t.item.prev().find(".parent").html())!==a&&(o=undefined),l!==undefined&&(i=t.item.next().find(".parent").html())!==a&&(l=undefined),o===undefined&&l===undefined||l===undefined&&i===o||l!==undefined&&n===d?r(c).sortable("cancel"):(t.item.find(".check-column input").hide(),t.item.find(".check-column").append('<img alt="processing" src="images/wpspin_light.gif" class="waiting" style="margin-left: 6px;" />'),r.post(ajaxurl,{action:"woocommerce_term_ordering",id:d,nextid:l,thetaxonomy:woocommerce_term_ordering_params.taxonomy},function(e){"children"===e?window.location.reload():(t.item.find(".check-column input").show(),t.item.find(".check-column").find("img").remove())}),r("table.widefat tbody tr").each(function(){jQuery("table.widefat tbody tr").index(this)%2==0?jQuery(this).addClass("alternate"):jQuery(this).removeClass("alternate")}))}})});
|
120
assets/js/admin/users.js
Normal file
120
assets/js/admin/users.js
Normal file
@ -0,0 +1,120 @@
|
||||
/*global wc_users_params */
|
||||
jQuery( function ( $ ) {
|
||||
|
||||
/**
|
||||
* Users country and state fields
|
||||
*/
|
||||
var wc_users_fields = {
|
||||
states: null,
|
||||
init: function() {
|
||||
if ( typeof wc_users_params.countries !== 'undefined' ) {
|
||||
/* State/Country select boxes */
|
||||
this.states = JSON.parse( wc_users_params.countries.replace( /"/g, '"' ) );
|
||||
}
|
||||
|
||||
$( '.js_field-country' ).selectWoo().on( 'change', this.change_country );
|
||||
$( '.js_field-country' ).trigger( 'change', [ true ] );
|
||||
$( document.body ).on( 'change', 'select.js_field-state', this.change_state );
|
||||
|
||||
$( document.body ).on( 'click', 'button.js_copy-billing', this.copy_billing );
|
||||
},
|
||||
|
||||
change_country: function( e, stickValue ) {
|
||||
// Check for stickValue before using it
|
||||
if ( typeof stickValue === 'undefined' ) {
|
||||
stickValue = false;
|
||||
}
|
||||
|
||||
// Prevent if we don't have the metabox data
|
||||
if ( wc_users_fields.states === null ) {
|
||||
return;
|
||||
}
|
||||
|
||||
var $this = $( this ),
|
||||
country = $this.val(),
|
||||
$state = $this.parents( '.form-table' ).find( ':input.js_field-state' ),
|
||||
$parent = $state.parent(),
|
||||
input_name = $state.attr( 'name' ),
|
||||
input_id = $state.attr( 'id' ),
|
||||
stickstatefield = 'woocommerce.stickState-' + country,
|
||||
value = $this.data( stickstatefield ) ? $this.data( stickstatefield ) : $state.val(),
|
||||
placeholder = $state.attr( 'placeholder' ),
|
||||
$newstate;
|
||||
|
||||
if ( stickValue ){
|
||||
$this.data( 'woocommerce.stickState-' + country, value );
|
||||
}
|
||||
|
||||
// Remove the previous DOM element
|
||||
$parent.show().find( '.select2-container' ).remove();
|
||||
|
||||
if ( ! $.isEmptyObject( wc_users_fields.states[ country ] ) ) {
|
||||
var state = wc_users_fields.states[ country ],
|
||||
$defaultOption = $( '<option value=""></option>' )
|
||||
.text( wc_users_fields.i18n_select_state_text );
|
||||
|
||||
$newstate = $( '<select style="width: 25em;"></select>' )
|
||||
.prop( 'id', input_id )
|
||||
.prop( 'name', input_name )
|
||||
.prop( 'placeholder', placeholder )
|
||||
.addClass( 'js_field-state' )
|
||||
.append( $defaultOption );
|
||||
|
||||
$.each( state, function( index ) {
|
||||
var $option = $( '<option></option>' )
|
||||
.prop( 'value', index )
|
||||
.text( state[ index ] );
|
||||
$newstate.append( $option );
|
||||
} );
|
||||
|
||||
$newstate.val( value );
|
||||
|
||||
$state.replaceWith( $newstate );
|
||||
|
||||
$newstate.show().selectWoo().hide().trigger( 'change' );
|
||||
} else {
|
||||
$newstate = $( '<input type="text" />' )
|
||||
.prop( 'id', input_id )
|
||||
.prop( 'name', input_name )
|
||||
.prop( 'placeholder', placeholder )
|
||||
.addClass( 'js_field-state regular-text' )
|
||||
.val( value );
|
||||
$state.replaceWith( $newstate );
|
||||
}
|
||||
|
||||
// This event has a typo - deprecated in 2.5.0
|
||||
$( document.body ).trigger( 'contry-change.woocommerce', [country, $( this ).closest( 'div' )] );
|
||||
$( document.body ).trigger( 'country-change.woocommerce', [country, $( this ).closest( 'div' )] );
|
||||
},
|
||||
|
||||
change_state: function() {
|
||||
// Here we will find if state value on a select has changed and stick it to the country data
|
||||
var $this = $( this ),
|
||||
state = $this.val(),
|
||||
$country = $this.parents( '.form-table' ).find( ':input.js_field-country' ),
|
||||
country = $country.val();
|
||||
|
||||
$country.data( 'woocommerce.stickState-' + country, state );
|
||||
},
|
||||
|
||||
copy_billing: function( event ) {
|
||||
event.preventDefault();
|
||||
|
||||
$( '#fieldset-billing' ).find( 'input, select' ).each( function( i, el ) {
|
||||
// The address keys match up, except for the prefix
|
||||
var shipName = el.name.replace( /^billing_/, 'shipping_' );
|
||||
// Swap prefix, then check if there are any elements
|
||||
var shipEl = $( '[name="' + shipName + '"]' );
|
||||
// No corresponding shipping field, skip this item
|
||||
if ( ! shipEl.length ) {
|
||||
return;
|
||||
}
|
||||
// Found a matching shipping element, update the value
|
||||
shipEl.val( el.value ).trigger( 'change' );
|
||||
} );
|
||||
}
|
||||
};
|
||||
|
||||
wc_users_fields.init();
|
||||
|
||||
});
|
1
assets/js/admin/users.min.js
vendored
Normal file
1
assets/js/admin/users.min.js
vendored
Normal file
@ -0,0 +1 @@
|
||||
jQuery(function(u){var h={states:null,init:function(){"undefined"!=typeof wc_users_params.countries&&(this.states=JSON.parse(wc_users_params.countries.replace(/"/g,'"'))),u(".js_field-country").selectWoo().on("change",this.change_country),u(".js_field-country").trigger("change",[!0]),u(document.body).on("change","select.js_field-state",this.change_state),u(document.body).on("click","button.js_copy-billing",this.copy_billing)},change_country:function(e,t){var a,n,o,i,c,s,l,r,p,d;void 0===t&&(t=!1),null!==h.states&&(n=(a=u(this)).val(),p=(o=a.parents(".form-table").find(":input.js_field-state")).parent(),i=o.attr("name"),c=o.attr("id"),l="woocommerce.stickState-"+n,s=a.data(l)?a.data(l):o.val(),l=o.attr("placeholder"),t&&a.data("woocommerce.stickState-"+n,s),p.show().find(".select2-container").remove(),u.isEmptyObject(h.states[n])?(d=u('<input type="text" />').prop("id",c).prop("name",i).prop("placeholder",l).addClass("js_field-state regular-text").val(s),o.replaceWith(d)):(r=h.states[n],p=u('<option value=""></option>').text(h.i18n_select_state_text),d=u('<select style="width: 25em;"></select>').prop("id",c).prop("name",i).prop("placeholder",l).addClass("js_field-state").append(p),u.each(r,function(e){e=u("<option></option>").prop("value",e).text(r[e]);d.append(e)}),d.val(s),o.replaceWith(d),d.show().selectWoo().hide().trigger("change")),u(document.body).trigger("contry-change.woocommerce",[n,u(this).closest("div")]),u(document.body).trigger("country-change.woocommerce",[n,u(this).closest("div")]))},change_state:function(){var e=u(this),t=e.val(),a=e.parents(".form-table").find(":input.js_field-country"),e=a.val();a.data("woocommerce.stickState-"+e,t)},copy_billing:function(e){e.preventDefault(),u("#fieldset-billing").find("input, select").each(function(e,t){var a=t.name.replace(/^billing_/,"shipping_"),a=u('[name="'+a+'"]');a.length&&a.val(t.value).trigger("change")})}};h.init()});
|
38
assets/js/admin/wc-clipboard.js
Normal file
38
assets/js/admin/wc-clipboard.js
Normal file
@ -0,0 +1,38 @@
|
||||
/* exported wcSetClipboard, wcClearClipboard */
|
||||
|
||||
/**
|
||||
* Simple text copy functions using native browser clipboard capabilities.
|
||||
* @since 3.2.0
|
||||
*/
|
||||
|
||||
/**
|
||||
* Set the user's clipboard contents.
|
||||
*
|
||||
* @param string data: Text to copy to clipboard.
|
||||
* @param object $el: jQuery element to trigger copy events on. (Default: document)
|
||||
*/
|
||||
function wcSetClipboard( data, $el ) {
|
||||
if ( 'undefined' === typeof $el ) {
|
||||
$el = jQuery( document );
|
||||
}
|
||||
var $temp_input = jQuery( '<textarea style="opacity:0">' );
|
||||
jQuery( 'body' ).append( $temp_input );
|
||||
$temp_input.val( data ).trigger( 'select' );
|
||||
|
||||
$el.trigger( 'beforecopy' );
|
||||
try {
|
||||
document.execCommand( 'copy' );
|
||||
$el.trigger( 'aftercopy' );
|
||||
} catch ( err ) {
|
||||
$el.trigger( 'aftercopyfailure' );
|
||||
}
|
||||
|
||||
$temp_input.remove();
|
||||
}
|
||||
|
||||
/**
|
||||
* Clear the user's clipboard.
|
||||
*/
|
||||
function wcClearClipboard() {
|
||||
wcSetClipboard( '' );
|
||||
}
|
1
assets/js/admin/wc-clipboard.min.js
vendored
Normal file
1
assets/js/admin/wc-clipboard.min.js
vendored
Normal file
@ -0,0 +1 @@
|
||||
function wcSetClipboard(e,r){void 0===r&&(r=jQuery(document));var t=jQuery('<textarea style="opacity:0">');jQuery("body").append(t),t.val(e).trigger("select"),r.trigger("beforecopy");try{document.execCommand("copy"),r.trigger("aftercopy")}catch(o){r.trigger("aftercopyfailure")}t.remove()}function wcClearClipboard(){wcSetClipboard("")}
|
325
assets/js/admin/wc-enhanced-select.js
Normal file
325
assets/js/admin/wc-enhanced-select.js
Normal file
@ -0,0 +1,325 @@
|
||||
/*global wc_enhanced_select_params */
|
||||
jQuery( function( $ ) {
|
||||
|
||||
function getEnhancedSelectFormatString() {
|
||||
return {
|
||||
'language': {
|
||||
errorLoading: function() {
|
||||
// Workaround for https://github.com/select2/select2/issues/4355 instead of i18n_ajax_error.
|
||||
return wc_enhanced_select_params.i18n_searching;
|
||||
},
|
||||
inputTooLong: function( args ) {
|
||||
var overChars = args.input.length - args.maximum;
|
||||
|
||||
if ( 1 === overChars ) {
|
||||
return wc_enhanced_select_params.i18n_input_too_long_1;
|
||||
}
|
||||
|
||||
return wc_enhanced_select_params.i18n_input_too_long_n.replace( '%qty%', overChars );
|
||||
},
|
||||
inputTooShort: function( args ) {
|
||||
var remainingChars = args.minimum - args.input.length;
|
||||
|
||||
if ( 1 === remainingChars ) {
|
||||
return wc_enhanced_select_params.i18n_input_too_short_1;
|
||||
}
|
||||
|
||||
return wc_enhanced_select_params.i18n_input_too_short_n.replace( '%qty%', remainingChars );
|
||||
},
|
||||
loadingMore: function() {
|
||||
return wc_enhanced_select_params.i18n_load_more;
|
||||
},
|
||||
maximumSelected: function( args ) {
|
||||
if ( args.maximum === 1 ) {
|
||||
return wc_enhanced_select_params.i18n_selection_too_long_1;
|
||||
}
|
||||
|
||||
return wc_enhanced_select_params.i18n_selection_too_long_n.replace( '%qty%', args.maximum );
|
||||
},
|
||||
noResults: function() {
|
||||
return wc_enhanced_select_params.i18n_no_matches;
|
||||
},
|
||||
searching: function() {
|
||||
return wc_enhanced_select_params.i18n_searching;
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
try {
|
||||
$( document.body )
|
||||
|
||||
.on( 'wc-enhanced-select-init', function() {
|
||||
|
||||
// Regular select boxes
|
||||
$( ':input.wc-enhanced-select, :input.chosen_select' ).filter( ':not(.enhanced)' ).each( function() {
|
||||
var select2_args = $.extend({
|
||||
minimumResultsForSearch: 10,
|
||||
allowClear: $( this ).data( 'allow_clear' ) ? true : false,
|
||||
placeholder: $( this ).data( 'placeholder' )
|
||||
}, getEnhancedSelectFormatString() );
|
||||
|
||||
$( this ).selectWoo( select2_args ).addClass( 'enhanced' );
|
||||
});
|
||||
|
||||
$( ':input.wc-enhanced-select-nostd, :input.chosen_select_nostd' ).filter( ':not(.enhanced)' ).each( function() {
|
||||
var select2_args = $.extend({
|
||||
minimumResultsForSearch: 10,
|
||||
allowClear: true,
|
||||
placeholder: $( this ).data( 'placeholder' )
|
||||
}, getEnhancedSelectFormatString() );
|
||||
|
||||
$( this ).selectWoo( select2_args ).addClass( 'enhanced' );
|
||||
});
|
||||
|
||||
function display_result( self, select2_args ) {
|
||||
select2_args = $.extend( select2_args, getEnhancedSelectFormatString() );
|
||||
|
||||
$( self ).selectWoo( select2_args ).addClass( 'enhanced' );
|
||||
|
||||
if ( $( self ).data( 'sortable' ) ) {
|
||||
var $select = $(self);
|
||||
var $list = $( self ).next( '.select2-container' ).find( 'ul.select2-selection__rendered' );
|
||||
|
||||
$list.sortable({
|
||||
placeholder : 'ui-state-highlight select2-selection__choice',
|
||||
forcePlaceholderSize: true,
|
||||
items : 'li:not(.select2-search__field)',
|
||||
tolerance : 'pointer',
|
||||
stop: function() {
|
||||
$( $list.find( '.select2-selection__choice' ).get().reverse() ).each( function() {
|
||||
var id = $( this ).data( 'data' ).id;
|
||||
var option = $select.find( 'option[value="' + id + '"]' )[0];
|
||||
$select.prepend( option );
|
||||
} );
|
||||
}
|
||||
});
|
||||
// Keep multiselects ordered alphabetically if they are not sortable.
|
||||
} else if ( $( self ).prop( 'multiple' ) ) {
|
||||
$( self ).on( 'change', function(){
|
||||
var $children = $( self ).children();
|
||||
$children.sort(function(a, b){
|
||||
var atext = a.text.toLowerCase();
|
||||
var btext = b.text.toLowerCase();
|
||||
|
||||
if ( atext > btext ) {
|
||||
return 1;
|
||||
}
|
||||
if ( atext < btext ) {
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
});
|
||||
$( self ).html( $children );
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
// Ajax product search box
|
||||
$( ':input.wc-product-search' ).filter( ':not(.enhanced)' ).each( function() {
|
||||
var select2_args = {
|
||||
allowClear: $( this ).data( 'allow_clear' ) ? true : false,
|
||||
placeholder: $( this ).data( 'placeholder' ),
|
||||
minimumInputLength: $( this ).data( 'minimum_input_length' ) ? $( this ).data( 'minimum_input_length' ) : '3',
|
||||
escapeMarkup: function( m ) {
|
||||
return m;
|
||||
},
|
||||
ajax: {
|
||||
url: wc_enhanced_select_params.ajax_url,
|
||||
dataType: 'json',
|
||||
delay: 250,
|
||||
data: function( params ) {
|
||||
return {
|
||||
term : params.term,
|
||||
action : $( this ).data( 'action' ) || 'woocommerce_json_search_products_and_variations',
|
||||
security : wc_enhanced_select_params.search_products_nonce,
|
||||
exclude : $( this ).data( 'exclude' ),
|
||||
exclude_type : $( this ).data( 'exclude_type' ),
|
||||
include : $( this ).data( 'include' ),
|
||||
limit : $( this ).data( 'limit' ),
|
||||
display_stock: $( this ).data( 'display_stock' )
|
||||
};
|
||||
},
|
||||
processResults: function( data ) {
|
||||
var terms = [];
|
||||
if ( data ) {
|
||||
$.each( data, function( id, text ) {
|
||||
terms.push( { id: id, text: text } );
|
||||
});
|
||||
}
|
||||
return {
|
||||
results: terms
|
||||
};
|
||||
},
|
||||
cache: true
|
||||
}
|
||||
};
|
||||
|
||||
display_result( this, select2_args );
|
||||
});
|
||||
|
||||
// Ajax Page Search.
|
||||
$( ':input.wc-page-search' ).filter( ':not(.enhanced)' ).each( function() {
|
||||
var select2_args = {
|
||||
allowClear: $( this ).data( 'allow_clear' ) ? true : false,
|
||||
placeholder: $( this ).data( 'placeholder' ),
|
||||
minimumInputLength: $( this ).data( 'minimum_input_length' ) ? $( this ).data( 'minimum_input_length' ) : '3',
|
||||
escapeMarkup: function( m ) {
|
||||
return m;
|
||||
},
|
||||
ajax: {
|
||||
url: wc_enhanced_select_params.ajax_url,
|
||||
dataType: 'json',
|
||||
delay: 250,
|
||||
data: function( params ) {
|
||||
return {
|
||||
term : params.term,
|
||||
action : $( this ).data( 'action' ) || 'woocommerce_json_search_pages',
|
||||
security : wc_enhanced_select_params.search_pages_nonce,
|
||||
exclude : $( this ).data( 'exclude' ),
|
||||
post_status : $( this ).data( 'post_status' ),
|
||||
limit : $( this ).data( 'limit' ),
|
||||
};
|
||||
},
|
||||
processResults: function( data ) {
|
||||
var terms = [];
|
||||
if ( data ) {
|
||||
$.each( data, function( id, text ) {
|
||||
terms.push( { id: id, text: text } );
|
||||
} );
|
||||
}
|
||||
return {
|
||||
results: terms
|
||||
};
|
||||
},
|
||||
cache: true
|
||||
}
|
||||
};
|
||||
|
||||
$( this ).selectWoo( select2_args ).addClass( 'enhanced' );
|
||||
});
|
||||
|
||||
// Ajax customer search boxes
|
||||
$( ':input.wc-customer-search' ).filter( ':not(.enhanced)' ).each( function() {
|
||||
var select2_args = {
|
||||
allowClear: $( this ).data( 'allow_clear' ) ? true : false,
|
||||
placeholder: $( this ).data( 'placeholder' ),
|
||||
minimumInputLength: $( this ).data( 'minimum_input_length' ) ? $( this ).data( 'minimum_input_length' ) : '1',
|
||||
escapeMarkup: function( m ) {
|
||||
return m;
|
||||
},
|
||||
ajax: {
|
||||
url: wc_enhanced_select_params.ajax_url,
|
||||
dataType: 'json',
|
||||
delay: 1000,
|
||||
data: function( params ) {
|
||||
return {
|
||||
term: params.term,
|
||||
action: 'woocommerce_json_search_customers',
|
||||
security: wc_enhanced_select_params.search_customers_nonce,
|
||||
exclude: $( this ).data( 'exclude' )
|
||||
};
|
||||
},
|
||||
processResults: function( data ) {
|
||||
var terms = [];
|
||||
if ( data ) {
|
||||
$.each( data, function( id, text ) {
|
||||
terms.push({
|
||||
id: id,
|
||||
text: text
|
||||
});
|
||||
});
|
||||
}
|
||||
return {
|
||||
results: terms
|
||||
};
|
||||
},
|
||||
cache: true
|
||||
}
|
||||
};
|
||||
|
||||
select2_args = $.extend( select2_args, getEnhancedSelectFormatString() );
|
||||
|
||||
$( this ).selectWoo( select2_args ).addClass( 'enhanced' );
|
||||
|
||||
if ( $( this ).data( 'sortable' ) ) {
|
||||
var $select = $(this);
|
||||
var $list = $( this ).next( '.select2-container' ).find( 'ul.select2-selection__rendered' );
|
||||
|
||||
$list.sortable({
|
||||
placeholder : 'ui-state-highlight select2-selection__choice',
|
||||
forcePlaceholderSize: true,
|
||||
items : 'li:not(.select2-search__field)',
|
||||
tolerance : 'pointer',
|
||||
stop: function() {
|
||||
$( $list.find( '.select2-selection__choice' ).get().reverse() ).each( function() {
|
||||
var id = $( this ).data( 'data' ).id;
|
||||
var option = $select.find( 'option[value="' + id + '"]' )[0];
|
||||
$select.prepend( option );
|
||||
} );
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
// Ajax category search boxes
|
||||
$( ':input.wc-category-search' ).filter( ':not(.enhanced)' ).each( function() {
|
||||
var select2_args = $.extend( {
|
||||
allowClear : $( this ).data( 'allow_clear' ) ? true : false,
|
||||
placeholder : $( this ).data( 'placeholder' ),
|
||||
minimumInputLength: $( this ).data( 'minimum_input_length' ) ? $( this ).data( 'minimum_input_length' ) : 3,
|
||||
escapeMarkup : function( m ) {
|
||||
return m;
|
||||
},
|
||||
ajax: {
|
||||
url: wc_enhanced_select_params.ajax_url,
|
||||
dataType: 'json',
|
||||
delay: 250,
|
||||
data: function( params ) {
|
||||
return {
|
||||
term: params.term,
|
||||
action: 'woocommerce_json_search_categories',
|
||||
security: wc_enhanced_select_params.search_categories_nonce
|
||||
};
|
||||
},
|
||||
processResults: function( data ) {
|
||||
var terms = [];
|
||||
if ( data ) {
|
||||
$.each( data, function( id, term ) {
|
||||
terms.push({
|
||||
id: term.slug,
|
||||
text: term.formatted_name
|
||||
});
|
||||
});
|
||||
}
|
||||
return {
|
||||
results: terms
|
||||
};
|
||||
},
|
||||
cache: true
|
||||
}
|
||||
}, getEnhancedSelectFormatString() );
|
||||
|
||||
$( this ).selectWoo( select2_args ).addClass( 'enhanced' );
|
||||
});
|
||||
})
|
||||
|
||||
// WooCommerce Backbone Modal
|
||||
.on( 'wc_backbone_modal_before_remove', function() {
|
||||
$( '.wc-enhanced-select, :input.wc-product-search, :input.wc-customer-search' ).filter( '.select2-hidden-accessible' )
|
||||
.selectWoo( 'close' );
|
||||
})
|
||||
|
||||
.trigger( 'wc-enhanced-select-init' );
|
||||
|
||||
$( 'html' ).on( 'click', function( event ) {
|
||||
if ( this === event.target ) {
|
||||
$( '.wc-enhanced-select, :input.wc-product-search, :input.wc-customer-search' ).filter( '.select2-hidden-accessible' )
|
||||
.selectWoo( 'close' );
|
||||
}
|
||||
} );
|
||||
} catch( err ) {
|
||||
// If select2 failed (conflict?) log the error but don't stop other scripts breaking.
|
||||
window.console.log( err );
|
||||
}
|
||||
});
|
1
assets/js/admin/wc-enhanced-select.min.js
vendored
Normal file
1
assets/js/admin/wc-enhanced-select.min.js
vendored
Normal file
File diff suppressed because one or more lines are too long
88
assets/js/admin/wc-orders.js
Normal file
88
assets/js/admin/wc-orders.js
Normal file
@ -0,0 +1,88 @@
|
||||
/* global wc_orders_params */
|
||||
jQuery( function( $ ) {
|
||||
|
||||
if ( typeof wc_orders_params === 'undefined' ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* WCOrdersTable class.
|
||||
*/
|
||||
var WCOrdersTable = function() {
|
||||
$( document )
|
||||
.on( 'click', '.post-type-shop_order .wp-list-table tbody td', this.onRowClick )
|
||||
.on( 'click', '.order-preview:not(.disabled)', this.onPreview );
|
||||
};
|
||||
|
||||
/**
|
||||
* Click a row.
|
||||
*/
|
||||
WCOrdersTable.prototype.onRowClick = function( e ) {
|
||||
if ( $( e.target ).filter( 'a, a *, .no-link, .no-link *, button, button *' ).length ) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if ( window.getSelection && window.getSelection().toString().length ) {
|
||||
return true;
|
||||
}
|
||||
|
||||
var $row = $( this ).closest( 'tr' ),
|
||||
href = $row.find( 'a.order-view' ).attr( 'href' );
|
||||
|
||||
if ( href && href.length ) {
|
||||
e.preventDefault();
|
||||
|
||||
if ( e.metaKey || e.ctrlKey ) {
|
||||
window.open( href, '_blank' );
|
||||
} else {
|
||||
window.location = href;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Preview an order.
|
||||
*/
|
||||
WCOrdersTable.prototype.onPreview = function() {
|
||||
var $previewButton = $( this ),
|
||||
$order_id = $previewButton.data( 'orderId' );
|
||||
|
||||
if ( $previewButton.data( 'order-data' ) ) {
|
||||
$( this ).WCBackboneModal({
|
||||
template: 'wc-modal-view-order',
|
||||
variable : $previewButton.data( 'orderData' )
|
||||
});
|
||||
} else {
|
||||
$previewButton.addClass( 'disabled' );
|
||||
|
||||
$.ajax({
|
||||
url: wc_orders_params.ajax_url,
|
||||
data: {
|
||||
order_id: $order_id,
|
||||
action : 'woocommerce_get_order_details',
|
||||
security: wc_orders_params.preview_nonce
|
||||
},
|
||||
type: 'GET',
|
||||
success: function( response ) {
|
||||
$( '.order-preview' ).removeClass( 'disabled' );
|
||||
|
||||
if ( response.success ) {
|
||||
$previewButton.data( 'orderData', response.data );
|
||||
|
||||
$( this ).WCBackboneModal({
|
||||
template: 'wc-modal-view-order',
|
||||
variable : response.data
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
return false;
|
||||
|
||||
};
|
||||
|
||||
/**
|
||||
* Init WCOrdersTable.
|
||||
*/
|
||||
new WCOrdersTable();
|
||||
} );
|
1
assets/js/admin/wc-orders.min.js
vendored
Normal file
1
assets/js/admin/wc-orders.min.js
vendored
Normal file
@ -0,0 +1 @@
|
||||
jQuery(function(r){if("undefined"==typeof wc_orders_params)return!1;var e=function(){r(document).on("click",".post-type-shop_order .wp-list-table tbody td",this.onRowClick).on("click",".order-preview:not(.disabled)",this.onPreview)};e.prototype.onRowClick=function(e){if(r(e.target).filter("a, a *, .no-link, .no-link *, button, button *").length)return!0;if(window.getSelection&&window.getSelection().toString().length)return!0;var t=r(this).closest("tr").find("a.order-view").attr("href");t&&t.length&&(e.preventDefault(),e.metaKey||e.ctrlKey?window.open(t,"_blank"):window.location=t)},e.prototype.onPreview=function(){var t=r(this),e=t.data("orderId");return t.data("order-data")?r(this).WCBackboneModal({template:"wc-modal-view-order",variable:t.data("orderData")}):(t.addClass("disabled"),r.ajax({url:wc_orders_params.ajax_url,data:{order_id:e,action:"woocommerce_get_order_details",security:wc_orders_params.preview_nonce},type:"GET",success:function(e){r(".order-preview").removeClass("disabled"),e.success&&(t.data("orderData",e.data),r(this).WCBackboneModal({template:"wc-modal-view-order",variable:e.data}))}})),!1},new e});
|
112
assets/js/admin/wc-product-export.js
Normal file
112
assets/js/admin/wc-product-export.js
Normal file
@ -0,0 +1,112 @@
|
||||
/*global ajaxurl, wc_product_export_params */
|
||||
;(function ( $, window ) {
|
||||
/**
|
||||
* productExportForm handles the export process.
|
||||
*/
|
||||
var productExportForm = function( $form ) {
|
||||
this.$form = $form;
|
||||
this.xhr = false;
|
||||
|
||||
// Initial state.
|
||||
this.$form.find('.woocommerce-exporter-progress').val( 0 );
|
||||
|
||||
// Methods.
|
||||
this.processStep = this.processStep.bind( this );
|
||||
|
||||
// Events.
|
||||
$form.on( 'submit', { productExportForm: this }, this.onSubmit );
|
||||
$form.find( '.woocommerce-exporter-types' ).on( 'change', { productExportForm: this }, this.exportTypeFields );
|
||||
};
|
||||
|
||||
/**
|
||||
* Handle export form submission.
|
||||
*/
|
||||
productExportForm.prototype.onSubmit = function( event ) {
|
||||
event.preventDefault();
|
||||
|
||||
var currentDate = new Date(),
|
||||
day = currentDate.getDate(),
|
||||
month = currentDate.getMonth() + 1,
|
||||
year = currentDate.getFullYear(),
|
||||
timestamp = currentDate.getTime(),
|
||||
filename = 'wc-product-export-' + day + '-' + month + '-' + year + '-' + timestamp + '.csv';
|
||||
|
||||
event.data.productExportForm.$form.addClass( 'woocommerce-exporter__exporting' );
|
||||
event.data.productExportForm.$form.find('.woocommerce-exporter-progress').val( 0 );
|
||||
event.data.productExportForm.$form.find('.woocommerce-exporter-button').prop( 'disabled', true );
|
||||
event.data.productExportForm.processStep( 1, $( this ).serialize(), '', filename );
|
||||
};
|
||||
|
||||
/**
|
||||
* Process the current export step.
|
||||
*/
|
||||
productExportForm.prototype.processStep = function( step, data, columns, filename ) {
|
||||
var $this = this,
|
||||
selected_columns = $( '.woocommerce-exporter-columns' ).val(),
|
||||
export_meta = $( '#woocommerce-exporter-meta:checked' ).length ? 1: 0,
|
||||
export_types = $( '.woocommerce-exporter-types' ).val(),
|
||||
export_category = $( '.woocommerce-exporter-category' ).val();
|
||||
|
||||
$.ajax( {
|
||||
type: 'POST',
|
||||
url: ajaxurl,
|
||||
data: {
|
||||
form : data,
|
||||
action : 'woocommerce_do_ajax_product_export',
|
||||
step : step,
|
||||
columns : columns,
|
||||
selected_columns : selected_columns,
|
||||
export_meta : export_meta,
|
||||
export_types : export_types,
|
||||
export_category : export_category,
|
||||
filename : filename,
|
||||
security : wc_product_export_params.export_nonce
|
||||
},
|
||||
dataType: 'json',
|
||||
success: function( response ) {
|
||||
if ( response.success ) {
|
||||
if ( 'done' === response.data.step ) {
|
||||
$this.$form.find('.woocommerce-exporter-progress').val( response.data.percentage );
|
||||
window.location = response.data.url;
|
||||
setTimeout( function() {
|
||||
$this.$form.removeClass( 'woocommerce-exporter__exporting' );
|
||||
$this.$form.find('.woocommerce-exporter-button').prop( 'disabled', false );
|
||||
}, 2000 );
|
||||
} else {
|
||||
$this.$form.find('.woocommerce-exporter-progress').val( response.data.percentage );
|
||||
$this.processStep( parseInt( response.data.step, 10 ), data, response.data.columns, filename );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
} ).fail( function( response ) {
|
||||
window.console.log( response );
|
||||
} );
|
||||
};
|
||||
|
||||
/**
|
||||
* Handle fields per export type.
|
||||
*/
|
||||
productExportForm.prototype.exportTypeFields = function() {
|
||||
var exportCategory = $( '.woocommerce-exporter-category' );
|
||||
|
||||
if ( -1 !== $.inArray( 'variation', $( this ).val() ) ) {
|
||||
exportCategory.closest( 'tr' ).hide();
|
||||
exportCategory.val( '' ).trigger( 'change' ); // Reset WooSelect selected value.
|
||||
} else {
|
||||
exportCategory.closest( 'tr' ).show();
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Function to call productExportForm on jquery selector.
|
||||
*/
|
||||
$.fn.wc_product_export_form = function() {
|
||||
new productExportForm( this );
|
||||
return this;
|
||||
};
|
||||
|
||||
$( '.woocommerce-exporter' ).wc_product_export_form();
|
||||
|
||||
})( jQuery, window );
|
1
assets/js/admin/wc-product-export.min.js
vendored
Normal file
1
assets/js/admin/wc-product-export.min.js
vendored
Normal file
@ -0,0 +1 @@
|
||||
!function(n,i){var o=function(o){this.$form=o,this.xhr=!1,this.$form.find(".woocommerce-exporter-progress").val(0),this.processStep=this.processStep.bind(this),o.on("submit",{productExportForm:this},this.onSubmit),o.find(".woocommerce-exporter-types").on("change",{productExportForm:this},this.exportTypeFields)};o.prototype.onSubmit=function(o){o.preventDefault();var e=new Date,e="wc-product-export-"+e.getDate()+"-"+(e.getMonth()+1)+"-"+e.getFullYear()+"-"+e.getTime()+".csv";o.data.productExportForm.$form.addClass("woocommerce-exporter__exporting"),o.data.productExportForm.$form.find(".woocommerce-exporter-progress").val(0),o.data.productExportForm.$form.find(".woocommerce-exporter-button").prop("disabled",!0),o.data.productExportForm.processStep(1,n(this).serialize(),"",e)},o.prototype.processStep=function(o,e,r,t){var c=this,p=n(".woocommerce-exporter-columns").val(),a=n("#woocommerce-exporter-meta:checked").length?1:0,s=n(".woocommerce-exporter-types").val(),m=n(".woocommerce-exporter-category").val();n.ajax({type:"POST",url:ajaxurl,data:{form:e,action:"woocommerce_do_ajax_product_export",step:o,columns:r,selected_columns:p,export_meta:a,export_types:s,export_category:m,filename:t,security:wc_product_export_params.export_nonce},dataType:"json",success:function(o){o.success&&("done"===o.data.step?(c.$form.find(".woocommerce-exporter-progress").val(o.data.percentage),i.location=o.data.url,setTimeout(function(){c.$form.removeClass("woocommerce-exporter__exporting"),c.$form.find(".woocommerce-exporter-button").prop("disabled",!1)},2e3)):(c.$form.find(".woocommerce-exporter-progress").val(o.data.percentage),c.processStep(parseInt(o.data.step,10),e,o.data.columns,t)))}}).fail(function(o){i.console.log(o)})},o.prototype.exportTypeFields=function(){var o=n(".woocommerce-exporter-category");-1!==n.inArray("variation",n(this).val())?(o.closest("tr").hide(),o.val("").trigger("change")):o.closest("tr").show()},n.fn.wc_product_export_form=function(){return new o(this),this},n(".woocommerce-exporter").wc_product_export_form()}(jQuery,window);
|
93
assets/js/admin/wc-product-import.js
Normal file
93
assets/js/admin/wc-product-import.js
Normal file
@ -0,0 +1,93 @@
|
||||
/*global ajaxurl, wc_product_import_params */
|
||||
;(function ( $, window ) {
|
||||
|
||||
/**
|
||||
* productImportForm handles the import process.
|
||||
*/
|
||||
var productImportForm = function( $form ) {
|
||||
this.$form = $form;
|
||||
this.xhr = false;
|
||||
this.mapping = wc_product_import_params.mapping;
|
||||
this.position = 0;
|
||||
this.file = wc_product_import_params.file;
|
||||
this.update_existing = wc_product_import_params.update_existing;
|
||||
this.delimiter = wc_product_import_params.delimiter;
|
||||
this.security = wc_product_import_params.import_nonce;
|
||||
|
||||
// Number of import successes/failures.
|
||||
this.imported = 0;
|
||||
this.failed = 0;
|
||||
this.updated = 0;
|
||||
this.skipped = 0;
|
||||
|
||||
// Initial state.
|
||||
this.$form.find('.woocommerce-importer-progress').val( 0 );
|
||||
|
||||
this.run_import = this.run_import.bind( this );
|
||||
|
||||
// Start importing.
|
||||
this.run_import();
|
||||
};
|
||||
|
||||
/**
|
||||
* Run the import in batches until finished.
|
||||
*/
|
||||
productImportForm.prototype.run_import = function() {
|
||||
var $this = this;
|
||||
|
||||
$.ajax( {
|
||||
type: 'POST',
|
||||
url: ajaxurl,
|
||||
data: {
|
||||
action : 'woocommerce_do_ajax_product_import',
|
||||
position : $this.position,
|
||||
mapping : $this.mapping,
|
||||
file : $this.file,
|
||||
update_existing : $this.update_existing,
|
||||
delimiter : $this.delimiter,
|
||||
security : $this.security
|
||||
},
|
||||
dataType: 'json',
|
||||
success: function( response ) {
|
||||
if ( response.success ) {
|
||||
$this.position = response.data.position;
|
||||
$this.imported += response.data.imported;
|
||||
$this.failed += response.data.failed;
|
||||
$this.updated += response.data.updated;
|
||||
$this.skipped += response.data.skipped;
|
||||
$this.$form.find('.woocommerce-importer-progress').val( response.data.percentage );
|
||||
|
||||
if ( 'done' === response.data.position ) {
|
||||
var file_name = wc_product_import_params.file.split( '/' ).pop();
|
||||
window.location = response.data.url +
|
||||
'&products-imported=' +
|
||||
parseInt( $this.imported, 10 ) +
|
||||
'&products-failed=' +
|
||||
parseInt( $this.failed, 10 ) +
|
||||
'&products-updated=' +
|
||||
parseInt( $this.updated, 10 ) +
|
||||
'&products-skipped=' +
|
||||
parseInt( $this.skipped, 10 ) +
|
||||
'&file-name=' +
|
||||
file_name;
|
||||
} else {
|
||||
$this.run_import();
|
||||
}
|
||||
}
|
||||
}
|
||||
} ).fail( function( response ) {
|
||||
window.console.log( response );
|
||||
} );
|
||||
};
|
||||
|
||||
/**
|
||||
* Function to call productImportForm on jQuery selector.
|
||||
*/
|
||||
$.fn.wc_product_importer = function() {
|
||||
new productImportForm( this );
|
||||
return this;
|
||||
};
|
||||
|
||||
$( '.woocommerce-importer' ).wc_product_importer();
|
||||
|
||||
})( jQuery, window );
|
1
assets/js/admin/wc-product-import.min.js
vendored
Normal file
1
assets/js/admin/wc-product-import.min.js
vendored
Normal file
@ -0,0 +1 @@
|
||||
!function(t,r){var i=function(t){this.$form=t,this.xhr=!1,this.mapping=wc_product_import_params.mapping,this.position=0,this.file=wc_product_import_params.file,this.update_existing=wc_product_import_params.update_existing,this.delimiter=wc_product_import_params.delimiter,this.security=wc_product_import_params.import_nonce,this.imported=0,this.failed=0,this.updated=0,this.skipped=0,this.$form.find(".woocommerce-importer-progress").val(0),this.run_import=this.run_import.bind(this),this.run_import()};i.prototype.run_import=function(){var p=this;t.ajax({type:"POST",url:ajaxurl,data:{action:"woocommerce_do_ajax_product_import",position:p.position,mapping:p.mapping,file:p.file,update_existing:p.update_existing,delimiter:p.delimiter,security:p.security},dataType:"json",success:function(t){var i;t.success&&(p.position=t.data.position,p.imported+=t.data.imported,p.failed+=t.data.failed,p.updated+=t.data.updated,p.skipped+=t.data.skipped,p.$form.find(".woocommerce-importer-progress").val(t.data.percentage),"done"===t.data.position?(i=wc_product_import_params.file.split("/").pop(),r.location=t.data.url+"&products-imported="+parseInt(p.imported,10)+"&products-failed="+parseInt(p.failed,10)+"&products-updated="+parseInt(p.updated,10)+"&products-skipped="+parseInt(p.skipped,10)+"&file-name="+i):p.run_import())}}).fail(function(t){r.console.log(t)})},t.fn.wc_product_importer=function(){return new i(this),this},t(".woocommerce-importer").wc_product_importer()}(jQuery,window);
|
322
assets/js/admin/wc-setup.js
Normal file
322
assets/js/admin/wc-setup.js
Normal file
@ -0,0 +1,322 @@
|
||||
/*global wc_setup_params */
|
||||
/*global wc_setup_currencies */
|
||||
/*global wc_base_state */
|
||||
/* @deprecated 4.6.0 */
|
||||
jQuery( function( $ ) {
|
||||
function blockWizardUI() {
|
||||
$('.wc-setup-content').block({
|
||||
message: null,
|
||||
overlayCSS: {
|
||||
background: '#fff',
|
||||
opacity: 0.6
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
$( '.button-next' ).on( 'click', function() {
|
||||
var form = $( this ).parents( 'form' ).get( 0 );
|
||||
|
||||
if ( ( 'function' !== typeof form.checkValidity ) || form.checkValidity() ) {
|
||||
blockWizardUI();
|
||||
}
|
||||
|
||||
return true;
|
||||
} );
|
||||
|
||||
$( 'form.address-step' ).on( 'submit', function( e ) {
|
||||
var form = $( this );
|
||||
if ( ( 'function' !== typeof form.checkValidity ) || form.checkValidity() ) {
|
||||
blockWizardUI();
|
||||
}
|
||||
|
||||
e.preventDefault();
|
||||
$('.wc-setup-content').unblock();
|
||||
|
||||
$( this ).WCBackboneModal( {
|
||||
template: 'wc-modal-tracking-setup'
|
||||
} );
|
||||
|
||||
$( document.body ).on( 'wc_backbone_modal_response', function() {
|
||||
form.off( 'submit' ).trigger( 'submit' );
|
||||
} );
|
||||
|
||||
$( '#wc_tracker_checkbox_dialog' ).on( 'change', function( e ) {
|
||||
var eventTarget = $( e.target );
|
||||
$( '#wc_tracker_checkbox' ).prop( 'checked', eventTarget.prop( 'checked' ) );
|
||||
} );
|
||||
|
||||
$( '#wc_tracker_submit' ).on( 'click', function () {
|
||||
form.off( 'submit' ).trigger( 'submit' );
|
||||
} );
|
||||
|
||||
return true;
|
||||
} );
|
||||
|
||||
$( '#store_country' ).on( 'change', function() {
|
||||
// Prevent if we don't have the metabox data
|
||||
if ( wc_setup_params.states === null ){
|
||||
return;
|
||||
}
|
||||
|
||||
var $this = $( this ),
|
||||
country = $this.val(),
|
||||
$state_select = $( '#store_state' );
|
||||
|
||||
if ( ! $.isEmptyObject( wc_setup_params.states[ country ] ) ) {
|
||||
var states = wc_setup_params.states[ country ];
|
||||
|
||||
$state_select.empty();
|
||||
|
||||
$.each( states, function( index ) {
|
||||
$state_select.append( $( '<option value="' + index + '">' + states[ index ] + '</option>' ) );
|
||||
} );
|
||||
|
||||
$( '.store-state-container' ).show();
|
||||
$state_select.selectWoo().val( wc_base_state ).trigger( 'change' ).prop( 'required', true );
|
||||
} else {
|
||||
$( '.store-state-container' ).hide();
|
||||
$state_select.empty().val( '' ).trigger( 'change' ).prop( 'required', false );
|
||||
}
|
||||
|
||||
$( '#currency_code' ).val( wc_setup_currencies[ country ] ).trigger( 'change' );
|
||||
} );
|
||||
|
||||
/* Setup postcode field and validations */
|
||||
$( '#store_country' ).on( 'change', function() {
|
||||
if ( ! wc_setup_params.postcodes ) {
|
||||
return;
|
||||
}
|
||||
|
||||
var $this = $( this ),
|
||||
country = $this.val(),
|
||||
$store_postcode_input = $( '#store_postcode' ),
|
||||
country_postcode_obj = wc_setup_params.postcodes[ country ];
|
||||
|
||||
// Default to required, if its unknown whether postcode is required or not.
|
||||
if ( $.isEmptyObject( country_postcode_obj ) || country_postcode_obj.required ) {
|
||||
$store_postcode_input.attr( 'required', 'true' );
|
||||
} else {
|
||||
$store_postcode_input.prop( 'required', false );
|
||||
}
|
||||
} );
|
||||
|
||||
$( '#store_country' ).trigger( 'change' );
|
||||
|
||||
$( '.wc-wizard-services' ).on( 'change', '.wc-wizard-service-enable input', function() {
|
||||
if ( $( this ).is( ':checked' ) ) {
|
||||
$( this ).closest( '.wc-wizard-service-toggle' ).removeClass( 'disabled' );
|
||||
$( this ).closest( '.wc-wizard-service-item' ).addClass( 'checked' );
|
||||
$( this ).closest( '.wc-wizard-service-item' )
|
||||
.find( '.wc-wizard-service-settings' ).removeClass( 'hide' );
|
||||
} else {
|
||||
$( this ).closest( '.wc-wizard-service-toggle' ).addClass( 'disabled' );
|
||||
$( this ).closest( '.wc-wizard-service-item' ).removeClass( 'checked' );
|
||||
$( this ).closest( '.wc-wizard-service-item' )
|
||||
.find( '.wc-wizard-service-settings' ).addClass( 'hide' );
|
||||
}
|
||||
} );
|
||||
|
||||
$( '.wc-wizard-services' ).on( 'keyup', function( e ) {
|
||||
var code = e.keyCode || e.which,
|
||||
$focused = $( document.activeElement );
|
||||
|
||||
if ( $focused.is( '.wc-wizard-service-toggle, .wc-wizard-service-enable' ) && ( 13 === code || 32 === code ) ) {
|
||||
$focused.find( ':input' ).trigger( 'click' );
|
||||
}
|
||||
} );
|
||||
|
||||
$( '.wc-wizard-services' ).on( 'click', '.wc-wizard-service-enable', function( e ) {
|
||||
var eventTarget = $( e.target );
|
||||
|
||||
if ( eventTarget.is( 'input' ) ) {
|
||||
e.stopPropagation();
|
||||
return;
|
||||
}
|
||||
|
||||
var $checkbox = $( this ).find( 'input[type="checkbox"]' );
|
||||
|
||||
$checkbox.prop( 'checked', ! $checkbox.prop( 'checked' ) ).trigger( 'change' );
|
||||
} );
|
||||
|
||||
$( '.wc-wizard-services-list-toggle' ).on( 'click', function() {
|
||||
var listToggle = $( this ).closest( '.wc-wizard-services-list-toggle' );
|
||||
|
||||
if ( listToggle.hasClass( 'closed' ) ) {
|
||||
listToggle.removeClass( 'closed' );
|
||||
} else {
|
||||
listToggle.addClass( 'closed' );
|
||||
}
|
||||
|
||||
$( this ).closest( '.wc-wizard-services' ).find( '.wc-wizard-service-item' )
|
||||
.slideToggle()
|
||||
.css( 'display', 'flex' );
|
||||
} );
|
||||
|
||||
$( '.wc-wizard-services' ).on( 'change', '.wc-wizard-shipping-method-select .method', function( e ) {
|
||||
var zone = $( this ).closest( '.wc-wizard-service-description' );
|
||||
var selectedMethod = e.target.value;
|
||||
|
||||
var description = zone.find( '.shipping-method-descriptions' );
|
||||
description.find( '.shipping-method-description' ).addClass( 'hide' );
|
||||
description.find( '.' + selectedMethod ).removeClass( 'hide' );
|
||||
|
||||
var $checkbox = zone.parent().find( 'input[type="checkbox"]' );
|
||||
var settings = zone.find( '.shipping-method-settings' );
|
||||
settings
|
||||
.find( '.shipping-method-setting' )
|
||||
.addClass( 'hide' )
|
||||
.find( '.shipping-method-required-field' )
|
||||
.prop( 'required', false );
|
||||
settings
|
||||
.find( '.' + selectedMethod )
|
||||
.removeClass( 'hide' )
|
||||
.find( '.shipping-method-required-field' )
|
||||
.prop( 'required', $checkbox.prop( 'checked' ) );
|
||||
} ).find( '.wc-wizard-shipping-method-select .method' ).trigger( 'change' );
|
||||
|
||||
$( '.wc-wizard-services' ).on( 'change', '.wc-wizard-shipping-method-enable', function() {
|
||||
var checked = $( this ).is( ':checked' );
|
||||
var selectedMethod = $( this )
|
||||
.closest( '.wc-wizard-service-item' )
|
||||
.find( '.wc-wizard-shipping-method-select .method' )
|
||||
.val();
|
||||
|
||||
$( this )
|
||||
.closest( '.wc-wizard-service-item' )
|
||||
.find( '.' + selectedMethod )
|
||||
.find( '.shipping-method-required-field' )
|
||||
.prop( 'required', checked );
|
||||
} );
|
||||
|
||||
function submitActivateForm() {
|
||||
$( 'form.activate-jetpack' ).trigger( 'submit' );
|
||||
}
|
||||
|
||||
function waitForJetpackInstall() {
|
||||
wp.ajax.post( 'setup_wizard_check_jetpack' )
|
||||
.then( function( result ) {
|
||||
// If we receive success, or an unexpected result
|
||||
// let the form submit.
|
||||
if (
|
||||
! result ||
|
||||
! result.is_active ||
|
||||
'yes' === result.is_active
|
||||
) {
|
||||
return submitActivateForm();
|
||||
}
|
||||
|
||||
// Wait until checking the status again
|
||||
setTimeout( waitForJetpackInstall, 3000 );
|
||||
} )
|
||||
.fail( function() {
|
||||
// Submit the form as normal if the request fails
|
||||
submitActivateForm();
|
||||
} );
|
||||
}
|
||||
|
||||
// Wait for a pending Jetpack install to finish before triggering a "save"
|
||||
// on the activate step, which launches the Jetpack connection flow.
|
||||
$( '.activate-jetpack' ).on( 'click', '.button-primary', function( e ) {
|
||||
blockWizardUI();
|
||||
|
||||
if ( 'no' === wc_setup_params.pending_jetpack_install ) {
|
||||
return true;
|
||||
}
|
||||
|
||||
e.preventDefault();
|
||||
waitForJetpackInstall();
|
||||
} );
|
||||
|
||||
$( '.activate-new-onboarding' ).on( 'click', '.button-primary', function() {
|
||||
// Show pending spinner while activate happens.
|
||||
blockWizardUI();
|
||||
} );
|
||||
|
||||
$( '.wc-wizard-services' ).on( 'change', 'input#stripe_create_account, input#ppec_paypal_reroute_requests', function() {
|
||||
if ( $( this ).is( ':checked' ) ) {
|
||||
$( this ).closest( '.wc-wizard-service-settings' )
|
||||
.find( 'input.payment-email-input' )
|
||||
.attr( 'type', 'email' )
|
||||
.prop( 'disabled', false )
|
||||
.prop( 'required', true );
|
||||
} else {
|
||||
$( this ).closest( '.wc-wizard-service-settings' )
|
||||
.find( 'input.payment-email-input' )
|
||||
.attr( 'type', null )
|
||||
.prop( 'disabled', true )
|
||||
.prop( 'required', false );
|
||||
}
|
||||
} ).find( 'input#stripe_create_account, input#ppec_paypal_reroute_requests' ).trigger( 'change' );
|
||||
|
||||
function addPlugins( bySlug, $el, hover ) {
|
||||
var plugins = $el.data( 'plugins' );
|
||||
for ( var i in Array.isArray( plugins ) ? plugins : [] ) {
|
||||
var slug = plugins[ i ].slug;
|
||||
bySlug[ slug ] = bySlug[ slug ] ||
|
||||
$( '<span class="plugin-install-info-list-item">' )
|
||||
.append( '<a href="https://wordpress.org/plugins/' + slug + '/" target="_blank">' + plugins[ i ].name + '</a>' );
|
||||
|
||||
bySlug[ slug ].find( 'a' )
|
||||
.on( 'mouseenter mouseleave', ( function( $hover, event ) {
|
||||
$hover.toggleClass( 'plugin-install-source', 'mouseenter' === event.type );
|
||||
} ).bind( null, hover ? $el.closest( hover ) : $el ) );
|
||||
}
|
||||
}
|
||||
|
||||
function updatePluginInfo() {
|
||||
var pluginLinkBySlug = {};
|
||||
var extraPlugins = [];
|
||||
|
||||
$( '.wc-wizard-service-enable input:checked' ).each( function() {
|
||||
addPlugins( pluginLinkBySlug, $( this ), '.wc-wizard-service-item' );
|
||||
|
||||
var $container = $( this ).closest( '.wc-wizard-service-item' );
|
||||
$container.find( 'input.payment-checkbox-input:checked' ).each( function() {
|
||||
extraPlugins.push( $( this ).attr( 'id' ) );
|
||||
addPlugins( pluginLinkBySlug, $( this ), '.wc-wizard-service-settings' );
|
||||
} );
|
||||
$container.find( '.wc-wizard-shipping-method-select .method' ).each( function() {
|
||||
var $this = $( this );
|
||||
if ( 'live_rates' === $this.val() ) {
|
||||
addPlugins( pluginLinkBySlug, $this, '.wc-wizard-service-item' );
|
||||
}
|
||||
} );
|
||||
} );
|
||||
|
||||
$( '.recommended-item input:checked' ).each( function() {
|
||||
addPlugins( pluginLinkBySlug, $( this ), '.recommended-item' );
|
||||
} );
|
||||
|
||||
var $list = $( 'span.plugin-install-info-list' ).empty();
|
||||
|
||||
for ( var slug in pluginLinkBySlug ) {
|
||||
$list.append( pluginLinkBySlug[ slug ] );
|
||||
}
|
||||
|
||||
if (
|
||||
extraPlugins &&
|
||||
wc_setup_params.current_step &&
|
||||
wc_setup_params.i18n.extra_plugins[ wc_setup_params.current_step ] &&
|
||||
wc_setup_params.i18n.extra_plugins[ wc_setup_params.current_step ][ extraPlugins.join( ',' ) ]
|
||||
) {
|
||||
$list.append(
|
||||
wc_setup_params.i18n.extra_plugins[ wc_setup_params.current_step ][ extraPlugins.join( ',' ) ]
|
||||
);
|
||||
}
|
||||
|
||||
$( 'span.plugin-install-info' ).toggle( $list.children().length > 0 );
|
||||
}
|
||||
|
||||
updatePluginInfo();
|
||||
$( '.wc-setup-content' ).on( 'change', '[data-plugins]', updatePluginInfo );
|
||||
|
||||
$( document.body ).on( 'init_tooltips', function() {
|
||||
$( '.help_tip' ).tipTip( {
|
||||
'attribute': 'data-tip',
|
||||
'fadeIn': 50,
|
||||
'fadeOut': 50,
|
||||
'delay': 200,
|
||||
'defaultPosition': 'top'
|
||||
} );
|
||||
} ).trigger( 'init_tooltips' );
|
||||
} );
|
1
assets/js/admin/wc-setup.min.js
vendored
Normal file
1
assets/js/admin/wc-setup.min.js
vendored
Normal file
File diff suppressed because one or more lines are too long
245
assets/js/admin/wc-shipping-classes.js
Normal file
245
assets/js/admin/wc-shipping-classes.js
Normal file
@ -0,0 +1,245 @@
|
||||
/* global shippingClassesLocalizeScript, ajaxurl */
|
||||
( function( $, data, wp, ajaxurl ) {
|
||||
$( function() {
|
||||
var $tbody = $( '.wc-shipping-class-rows' ),
|
||||
$save_button = $( '.wc-shipping-class-save' ),
|
||||
$row_template = wp.template( 'wc-shipping-class-row' ),
|
||||
$blank_template = wp.template( 'wc-shipping-class-row-blank' ),
|
||||
|
||||
// Backbone model
|
||||
ShippingClass = Backbone.Model.extend({
|
||||
changes: {},
|
||||
logChanges: function( changedRows ) {
|
||||
var changes = this.changes || {};
|
||||
|
||||
_.each( changedRows, function( row, id ) {
|
||||
changes[ id ] = _.extend( changes[ id ] || { term_id : id }, row );
|
||||
} );
|
||||
|
||||
this.changes = changes;
|
||||
this.trigger( 'change:classes' );
|
||||
},
|
||||
save: function() {
|
||||
if ( _.size( this.changes ) ) {
|
||||
$.post( ajaxurl + ( ajaxurl.indexOf( '?' ) > 0 ? '&' : '?' ) + 'action=woocommerce_shipping_classes_save_changes', {
|
||||
wc_shipping_classes_nonce : data.wc_shipping_classes_nonce,
|
||||
changes : this.changes
|
||||
}, this.onSaveResponse, 'json' );
|
||||
} else {
|
||||
shippingClass.trigger( 'saved:classes' );
|
||||
}
|
||||
},
|
||||
discardChanges: function( id ) {
|
||||
var changes = this.changes || {};
|
||||
|
||||
// Delete all changes
|
||||
delete changes[ id ];
|
||||
|
||||
// No changes? Disable save button.
|
||||
if ( 0 === _.size( this.changes ) ) {
|
||||
shippingClassView.clearUnloadConfirmation();
|
||||
}
|
||||
},
|
||||
onSaveResponse: function( response, textStatus ) {
|
||||
if ( 'success' === textStatus ) {
|
||||
if ( response.success ) {
|
||||
shippingClass.set( 'classes', response.data.shipping_classes );
|
||||
shippingClass.trigger( 'change:classes' );
|
||||
shippingClass.changes = {};
|
||||
shippingClass.trigger( 'saved:classes' );
|
||||
} else if ( response.data ) {
|
||||
window.alert( response.data );
|
||||
} else {
|
||||
window.alert( data.strings.save_failed );
|
||||
}
|
||||
}
|
||||
shippingClassView.unblock();
|
||||
}
|
||||
} ),
|
||||
|
||||
// Backbone view
|
||||
ShippingClassView = Backbone.View.extend({
|
||||
rowTemplate: $row_template,
|
||||
initialize: function() {
|
||||
this.listenTo( this.model, 'change:classes', this.setUnloadConfirmation );
|
||||
this.listenTo( this.model, 'saved:classes', this.clearUnloadConfirmation );
|
||||
this.listenTo( this.model, 'saved:classes', this.render );
|
||||
$tbody.on( 'change', { view: this }, this.updateModelOnChange );
|
||||
$( window ).on( 'beforeunload', { view: this }, this.unloadConfirmation );
|
||||
$save_button.on( 'click', { view: this }, this.onSubmit );
|
||||
$( document.body ).on( 'click', '.wc-shipping-class-add', { view: this }, this.onAddNewRow );
|
||||
$( document.body ).on( 'click', '.wc-shipping-class-save-changes', { view: this }, this.onSubmit );
|
||||
},
|
||||
block: function() {
|
||||
$( this.el ).block({
|
||||
message: null,
|
||||
overlayCSS: {
|
||||
background: '#fff',
|
||||
opacity: 0.6
|
||||
}
|
||||
});
|
||||
},
|
||||
unblock: function() {
|
||||
$( this.el ).unblock();
|
||||
},
|
||||
render: function() {
|
||||
var classes = _.indexBy( this.model.get( 'classes' ), 'term_id' ),
|
||||
view = this;
|
||||
|
||||
this.$el.empty();
|
||||
this.unblock();
|
||||
|
||||
if ( _.size( classes ) ) {
|
||||
// Sort classes
|
||||
classes = _.sortBy( classes, function( shipping_class ) {
|
||||
return shipping_class.name;
|
||||
} );
|
||||
|
||||
// Populate $tbody with the current classes
|
||||
$.each( classes, function( id, rowData ) {
|
||||
view.renderRow( rowData );
|
||||
} );
|
||||
} else {
|
||||
view.$el.append( $blank_template );
|
||||
}
|
||||
},
|
||||
renderRow: function( rowData ) {
|
||||
var view = this;
|
||||
view.$el.append( view.rowTemplate( rowData ) );
|
||||
view.initRow( rowData );
|
||||
},
|
||||
initRow: function( rowData ) {
|
||||
var view = this;
|
||||
var $tr = view.$el.find( 'tr[data-id="' + rowData.term_id + '"]');
|
||||
|
||||
// Support select boxes
|
||||
$tr.find( 'select' ).each( function() {
|
||||
var attribute = $( this ).data( 'attribute' );
|
||||
$( this ).find( 'option[value="' + rowData[ attribute ] + '"]' ).prop( 'selected', true );
|
||||
} );
|
||||
|
||||
// Make the rows function
|
||||
$tr.find( '.view' ).show();
|
||||
$tr.find( '.edit' ).hide();
|
||||
$tr.find( '.wc-shipping-class-edit' ).on( 'click', { view: this }, this.onEditRow );
|
||||
$tr.find( '.wc-shipping-class-delete' ).on( 'click', { view: this }, this.onDeleteRow );
|
||||
$tr.find( '.editing .wc-shipping-class-edit' ).trigger('click');
|
||||
$tr.find( '.wc-shipping-class-cancel-edit' ).on( 'click', { view: this }, this.onCancelEditRow );
|
||||
|
||||
// Editing?
|
||||
if ( true === rowData.editing ) {
|
||||
$tr.addClass( 'editing' );
|
||||
$tr.find( '.wc-shipping-class-edit' ).trigger( 'click' );
|
||||
}
|
||||
},
|
||||
onSubmit: function( event ) {
|
||||
event.data.view.block();
|
||||
event.data.view.model.save();
|
||||
event.preventDefault();
|
||||
},
|
||||
onAddNewRow: function( event ) {
|
||||
event.preventDefault();
|
||||
|
||||
var view = event.data.view,
|
||||
model = view.model,
|
||||
classes = _.indexBy( model.get( 'classes' ), 'term_id' ),
|
||||
changes = {},
|
||||
size = _.size( classes ),
|
||||
newRow = _.extend( {}, data.default_shipping_class, {
|
||||
term_id: 'new-' + size + '-' + Date.now(),
|
||||
editing: true,
|
||||
newRow : true
|
||||
} );
|
||||
|
||||
changes[ newRow.term_id ] = newRow;
|
||||
|
||||
model.logChanges( changes );
|
||||
view.renderRow( newRow );
|
||||
$( '.wc-shipping-classes-blank-state' ).remove();
|
||||
},
|
||||
onEditRow: function( event ) {
|
||||
event.preventDefault();
|
||||
$( this ).closest('tr').addClass('editing');
|
||||
$( this ).closest('tr').find('.view').hide();
|
||||
$( this ).closest('tr').find('.edit').show();
|
||||
event.data.view.model.trigger( 'change:classes' );
|
||||
},
|
||||
onDeleteRow: function( event ) {
|
||||
var view = event.data.view,
|
||||
model = view.model,
|
||||
classes = _.indexBy( model.get( 'classes' ), 'term_id' ),
|
||||
changes = {},
|
||||
term_id = $( this ).closest('tr').data('id');
|
||||
|
||||
event.preventDefault();
|
||||
|
||||
if ( classes[ term_id ] ) {
|
||||
delete classes[ term_id ];
|
||||
changes[ term_id ] = _.extend( changes[ term_id ] || {}, { deleted : 'deleted' } );
|
||||
model.set( 'classes', classes );
|
||||
model.logChanges( changes );
|
||||
}
|
||||
|
||||
view.render();
|
||||
},
|
||||
onCancelEditRow: function( event ) {
|
||||
var view = event.data.view,
|
||||
model = view.model,
|
||||
row = $( this ).closest('tr'),
|
||||
term_id = $( this ).closest('tr').data('id'),
|
||||
classes = _.indexBy( model.get( 'classes' ), 'term_id' );
|
||||
|
||||
event.preventDefault();
|
||||
model.discardChanges( term_id );
|
||||
|
||||
if ( classes[ term_id ] ) {
|
||||
classes[ term_id ].editing = false;
|
||||
row.after( view.rowTemplate( classes[ term_id ] ) );
|
||||
view.initRow( classes[ term_id ] );
|
||||
}
|
||||
|
||||
row.remove();
|
||||
},
|
||||
setUnloadConfirmation: function() {
|
||||
this.needsUnloadConfirm = true;
|
||||
$save_button.prop( 'disabled', false );
|
||||
},
|
||||
clearUnloadConfirmation: function() {
|
||||
this.needsUnloadConfirm = false;
|
||||
$save_button.attr( 'disabled', 'disabled' );
|
||||
},
|
||||
unloadConfirmation: function( event ) {
|
||||
if ( event.data.view.needsUnloadConfirm ) {
|
||||
event.returnValue = data.strings.unload_confirmation_msg;
|
||||
window.event.returnValue = data.strings.unload_confirmation_msg;
|
||||
return data.strings.unload_confirmation_msg;
|
||||
}
|
||||
},
|
||||
updateModelOnChange: function( event ) {
|
||||
var model = event.data.view.model,
|
||||
$target = $( event.target ),
|
||||
term_id = $target.closest( 'tr' ).data( 'id' ),
|
||||
attribute = $target.data( 'attribute' ),
|
||||
value = $target.val(),
|
||||
classes = _.indexBy( model.get( 'classes' ), 'term_id' ),
|
||||
changes = {};
|
||||
|
||||
if ( ! classes[ term_id ] || classes[ term_id ][ attribute ] !== value ) {
|
||||
changes[ term_id ] = {};
|
||||
changes[ term_id ][ attribute ] = value;
|
||||
}
|
||||
|
||||
model.logChanges( changes );
|
||||
}
|
||||
} ),
|
||||
shippingClass = new ShippingClass({
|
||||
classes: data.classes
|
||||
} ),
|
||||
shippingClassView = new ShippingClassView({
|
||||
model: shippingClass,
|
||||
el: $tbody
|
||||
} );
|
||||
|
||||
shippingClassView.render();
|
||||
});
|
||||
})( jQuery, shippingClassesLocalizeScript, wp, ajaxurl );
|
1
assets/js/admin/wc-shipping-classes.min.js
vendored
Normal file
1
assets/js/admin/wc-shipping-classes.min.js
vendored
Normal file
@ -0,0 +1 @@
|
||||
!function(d,c,l,r){d(function(){var e=d(".wc-shipping-class-rows"),i=d(".wc-shipping-class-save"),s=l.template("wc-shipping-class-row"),n=l.template("wc-shipping-class-row-blank"),t=Backbone.Model.extend({changes:{},logChanges:function(e){var s=this.changes||{};_.each(e,function(e,i){s[i]=_.extend(s[i]||{term_id:i},e)}),this.changes=s,this.trigger("change:classes")},save:function(){_.size(this.changes)?d.post(r+(0<r.indexOf("?")?"&":"?")+"action=woocommerce_shipping_classes_save_changes",{wc_shipping_classes_nonce:c.wc_shipping_classes_nonce,changes:this.changes},this.onSaveResponse,"json"):a.trigger("saved:classes")},discardChanges:function(e){delete(this.changes||{})[e],0===_.size(this.changes)&&o.clearUnloadConfirmation()},onSaveResponse:function(e,i){"success"===i&&(e.success?(a.set("classes",e.data.shipping_classes),a.trigger("change:classes"),a.changes={},a.trigger("saved:classes")):e.data?window.alert(e.data):window.alert(c.strings.save_failed)),o.unblock()}}),s=Backbone.View.extend({rowTemplate:s,initialize:function(){this.listenTo(this.model,"change:classes",this.setUnloadConfirmation),this.listenTo(this.model,"saved:classes",this.clearUnloadConfirmation),this.listenTo(this.model,"saved:classes",this.render),e.on("change",{view:this},this.updateModelOnChange),d(window).on("beforeunload",{view:this},this.unloadConfirmation),i.on("click",{view:this},this.onSubmit),d(document.body).on("click",".wc-shipping-class-add",{view:this},this.onAddNewRow),d(document.body).on("click",".wc-shipping-class-save-changes",{view:this},this.onSubmit)},block:function(){d(this.el).block({message:null,overlayCSS:{background:"#fff",opacity:.6}})},unblock:function(){d(this.el).unblock()},render:function(){var e=_.indexBy(this.model.get("classes"),"term_id"),s=this;this.$el.empty(),this.unblock(),_.size(e)?(e=_.sortBy(e,function(e){return e.name}),d.each(e,function(e,i){s.renderRow(i)})):s.$el.append(n)},renderRow:function(e){var i=this;i.$el.append(i.rowTemplate(e)),i.initRow(e)},initRow:function(i){var e=this.$el.find('tr[data-id="'+i.term_id+'"]');e.find("select").each(function(){var e=d(this).data("attribute");d(this).find('option[value="'+i[e]+'"]').prop("selected",!0)}),e.find(".view").show(),e.find(".edit").hide(),e.find(".wc-shipping-class-edit").on("click",{view:this},this.onEditRow),e.find(".wc-shipping-class-delete").on("click",{view:this},this.onDeleteRow),e.find(".editing .wc-shipping-class-edit").trigger("click"),e.find(".wc-shipping-class-cancel-edit").on("click",{view:this},this.onCancelEditRow),!0===i.editing&&(e.addClass("editing"),e.find(".wc-shipping-class-edit").trigger("click"))},onSubmit:function(e){e.data.view.block(),e.data.view.model.save(),e.preventDefault()},onAddNewRow:function(e){e.preventDefault();var i=e.data.view,s=i.model,n=_.indexBy(s.get("classes"),"term_id"),e={},n=_.size(n),n=_.extend({},c.default_shipping_class,{term_id:"new-"+n+"-"+Date.now(),editing:!0,newRow:!0});e[n.term_id]=n,s.logChanges(e),i.renderRow(n),d(".wc-shipping-classes-blank-state").remove()},onEditRow:function(e){e.preventDefault(),d(this).closest("tr").addClass("editing"),d(this).closest("tr").find(".view").hide(),d(this).closest("tr").find(".edit").show(),e.data.view.model.trigger("change:classes")},onDeleteRow:function(e){var i=e.data.view,s=i.model,n=_.indexBy(s.get("classes"),"term_id"),t={},a=d(this).closest("tr").data("id");e.preventDefault(),n[a]&&(delete n[a],t[a]=_.extend(t[a]||{},{deleted:"deleted"}),s.set("classes",n),s.logChanges(t)),i.render()},onCancelEditRow:function(e){var i=e.data.view,s=i.model,n=d(this).closest("tr"),t=d(this).closest("tr").data("id"),a=_.indexBy(s.get("classes"),"term_id");e.preventDefault(),s.discardChanges(t),a[t]&&(a[t].editing=!1,n.after(i.rowTemplate(a[t])),i.initRow(a[t])),n.remove()},setUnloadConfirmation:function(){this.needsUnloadConfirm=!0,i.prop("disabled",!1)},clearUnloadConfirmation:function(){this.needsUnloadConfirm=!1,i.attr("disabled","disabled")},unloadConfirmation:function(e){if(e.data.view.needsUnloadConfirm)return e.returnValue=c.strings.unload_confirmation_msg,window.event.returnValue=c.strings.unload_confirmation_msg,c.strings.unload_confirmation_msg},updateModelOnChange:function(e){var i=e.data.view.model,s=d(e.target),n=s.closest("tr").data("id"),t=s.data("attribute"),a=s.val(),e=_.indexBy(i.get("classes"),"term_id"),s={};e[n]&&e[n][t]===a||(s[n]={},s[n][t]=a),i.logChanges(s)}}),a=new t({classes:c.classes}),o=new s({model:a,el:e});o.render()})}(jQuery,shippingClassesLocalizeScript,wp,ajaxurl);
|
429
assets/js/admin/wc-shipping-zone-methods.js
Normal file
429
assets/js/admin/wc-shipping-zone-methods.js
Normal file
@ -0,0 +1,429 @@
|
||||
/* global shippingZoneMethodsLocalizeScript, ajaxurl */
|
||||
( function( $, data, wp, ajaxurl ) {
|
||||
$( function() {
|
||||
var $table = $( '.wc-shipping-zone-methods' ),
|
||||
$tbody = $( '.wc-shipping-zone-method-rows' ),
|
||||
$save_button = $( '.wc-shipping-zone-method-save' ),
|
||||
$row_template = wp.template( 'wc-shipping-zone-method-row' ),
|
||||
$blank_template = wp.template( 'wc-shipping-zone-method-row-blank' ),
|
||||
|
||||
// Backbone model
|
||||
ShippingMethod = Backbone.Model.extend({
|
||||
changes: {},
|
||||
logChanges: function( changedRows ) {
|
||||
var changes = this.changes || {};
|
||||
|
||||
_.each( changedRows.methods, function( row, id ) {
|
||||
changes.methods = changes.methods || { methods : {} };
|
||||
changes.methods[ id ] = _.extend( changes.methods[ id ] || { instance_id : id }, row );
|
||||
} );
|
||||
|
||||
if ( typeof changedRows.zone_name !== 'undefined' ) {
|
||||
changes.zone_name = changedRows.zone_name;
|
||||
}
|
||||
|
||||
if ( typeof changedRows.zone_locations !== 'undefined' ) {
|
||||
changes.zone_locations = changedRows.zone_locations;
|
||||
}
|
||||
|
||||
if ( typeof changedRows.zone_postcodes !== 'undefined' ) {
|
||||
changes.zone_postcodes = changedRows.zone_postcodes;
|
||||
}
|
||||
|
||||
this.changes = changes;
|
||||
this.trigger( 'change:methods' );
|
||||
},
|
||||
save: function() {
|
||||
$.post(
|
||||
ajaxurl + ( ajaxurl.indexOf( '?' ) > 0 ? '&' : '?' ) + 'action=woocommerce_shipping_zone_methods_save_changes',
|
||||
{
|
||||
wc_shipping_zones_nonce : data.wc_shipping_zones_nonce,
|
||||
changes : this.changes,
|
||||
zone_id : data.zone_id
|
||||
},
|
||||
this.onSaveResponse,
|
||||
'json'
|
||||
);
|
||||
},
|
||||
onSaveResponse: function( response, textStatus ) {
|
||||
if ( 'success' === textStatus ) {
|
||||
if ( response.success ) {
|
||||
if ( response.data.zone_id !== data.zone_id ) {
|
||||
data.zone_id = response.data.zone_id;
|
||||
if ( window.history.pushState ) {
|
||||
window.history.pushState(
|
||||
{},
|
||||
'',
|
||||
'admin.php?page=wc-settings&tab=shipping&zone_id=' + response.data.zone_id
|
||||
);
|
||||
}
|
||||
}
|
||||
shippingMethod.set( 'methods', response.data.methods );
|
||||
shippingMethod.trigger( 'change:methods' );
|
||||
shippingMethod.changes = {};
|
||||
shippingMethod.trigger( 'saved:methods' );
|
||||
|
||||
// Overrides the onbeforeunload callback added by settings.js.
|
||||
window.onbeforeunload = null;
|
||||
} else {
|
||||
window.alert( data.strings.save_failed );
|
||||
}
|
||||
}
|
||||
}
|
||||
} ),
|
||||
|
||||
// Backbone view
|
||||
ShippingMethodView = Backbone.View.extend({
|
||||
rowTemplate: $row_template,
|
||||
initialize: function() {
|
||||
this.listenTo( this.model, 'change:methods', this.setUnloadConfirmation );
|
||||
this.listenTo( this.model, 'saved:methods', this.clearUnloadConfirmation );
|
||||
this.listenTo( this.model, 'saved:methods', this.render );
|
||||
$tbody.on( 'change', { view: this }, this.updateModelOnChange );
|
||||
$tbody.on( 'sortupdate', { view: this }, this.updateModelOnSort );
|
||||
$( window ).on( 'beforeunload', { view: this }, this.unloadConfirmation );
|
||||
$save_button.on( 'click', { view: this }, this.onSubmit );
|
||||
|
||||
$( document.body ).on(
|
||||
'input change',
|
||||
'#zone_name, #zone_locations, #zone_postcodes',
|
||||
{ view: this },
|
||||
this.onUpdateZone
|
||||
);
|
||||
$( document.body ).on( 'click', '.wc-shipping-zone-method-settings', { view: this }, this.onConfigureShippingMethod );
|
||||
$( document.body ).on( 'click', '.wc-shipping-zone-add-method', { view: this }, this.onAddShippingMethod );
|
||||
$( document.body ).on( 'wc_backbone_modal_response', this.onConfigureShippingMethodSubmitted );
|
||||
$( document.body ).on( 'wc_backbone_modal_response', this.onAddShippingMethodSubmitted );
|
||||
$( document.body ).on( 'change', '.wc-shipping-zone-method-selector select', this.onChangeShippingMethodSelector );
|
||||
$( document.body ).on( 'click', '.wc-shipping-zone-postcodes-toggle', this.onTogglePostcodes );
|
||||
},
|
||||
onUpdateZone: function( event ) {
|
||||
var view = event.data.view,
|
||||
model = view.model,
|
||||
value = $( this ).val(),
|
||||
$target = $( event.target ),
|
||||
attribute = $target.data( 'attribute' ),
|
||||
changes = {};
|
||||
|
||||
event.preventDefault();
|
||||
|
||||
changes[ attribute ] = value;
|
||||
model.set( attribute, value );
|
||||
model.logChanges( changes );
|
||||
view.render();
|
||||
},
|
||||
block: function() {
|
||||
$( this.el ).block({
|
||||
message: null,
|
||||
overlayCSS: {
|
||||
background: '#fff',
|
||||
opacity: 0.6
|
||||
}
|
||||
});
|
||||
},
|
||||
unblock: function() {
|
||||
$( this.el ).unblock();
|
||||
},
|
||||
render: function() {
|
||||
var methods = _.indexBy( this.model.get( 'methods' ), 'instance_id' ),
|
||||
zone_name = this.model.get( 'zone_name' ),
|
||||
view = this;
|
||||
|
||||
// Set name.
|
||||
$('.wc-shipping-zone-name').text( zone_name ? zone_name : data.strings.default_zone_name );
|
||||
|
||||
// Blank out the contents.
|
||||
this.$el.empty();
|
||||
this.unblock();
|
||||
|
||||
if ( _.size( methods ) ) {
|
||||
// Sort methods
|
||||
methods = _.sortBy( methods, function( method ) {
|
||||
return parseInt( method.method_order, 10 );
|
||||
} );
|
||||
|
||||
// Populate $tbody with the current methods
|
||||
$.each( methods, function( id, rowData ) {
|
||||
if ( 'yes' === rowData.enabled ) {
|
||||
rowData.enabled_icon = '<span class="woocommerce-input-toggle woocommerce-input-toggle--enabled">' +
|
||||
data.strings.yes +
|
||||
'</span>';
|
||||
} else {
|
||||
rowData.enabled_icon = '<span class="woocommerce-input-toggle woocommerce-input-toggle--disabled">' +
|
||||
data.strings.no +
|
||||
'</span>';
|
||||
}
|
||||
|
||||
view.$el.append( view.rowTemplate( rowData ) );
|
||||
|
||||
var $tr = view.$el.find( 'tr[data-id="' + rowData.instance_id + '"]');
|
||||
|
||||
if ( ! rowData.has_settings ) {
|
||||
$tr
|
||||
.find( '.wc-shipping-zone-method-title > a' )
|
||||
.replaceWith('<span>' + $tr.find( '.wc-shipping-zone-method-title > a' ).text() + '</span>' );
|
||||
var $del = $tr.find( '.wc-shipping-zone-method-delete' );
|
||||
$tr.find( '.wc-shipping-zone-method-title .row-actions' ).empty().html($del);
|
||||
}
|
||||
} );
|
||||
|
||||
// Make the rows function
|
||||
this.$el.find( '.wc-shipping-zone-method-delete' ).on( 'click', { view: this }, this.onDeleteRow );
|
||||
this.$el.find( '.wc-shipping-zone-method-enabled a').on( 'click', { view: this }, this.onToggleEnabled );
|
||||
} else {
|
||||
view.$el.append( $blank_template );
|
||||
}
|
||||
|
||||
this.initTooltips();
|
||||
},
|
||||
initTooltips: function() {
|
||||
$( '#tiptip_holder' ).removeAttr( 'style' );
|
||||
$( '#tiptip_arrow' ).removeAttr( 'style' );
|
||||
$( '.tips' ).tipTip({ 'attribute': 'data-tip', 'fadeIn': 50, 'fadeOut': 50, 'delay': 50 });
|
||||
},
|
||||
onSubmit: function( event ) {
|
||||
event.data.view.block();
|
||||
event.data.view.model.save();
|
||||
event.preventDefault();
|
||||
},
|
||||
onDeleteRow: function( event ) {
|
||||
var view = event.data.view,
|
||||
model = view.model,
|
||||
methods = _.indexBy( model.get( 'methods' ), 'instance_id' ),
|
||||
changes = {},
|
||||
instance_id = $( this ).closest('tr').data('id');
|
||||
|
||||
event.preventDefault();
|
||||
|
||||
delete methods[ instance_id ];
|
||||
changes.methods = changes.methods || { methods : {} };
|
||||
changes.methods[ instance_id ] = _.extend( changes.methods[ instance_id ] || {}, { deleted : 'deleted' } );
|
||||
model.set( 'methods', methods );
|
||||
model.logChanges( changes );
|
||||
view.render();
|
||||
},
|
||||
onToggleEnabled: function( event ) {
|
||||
var view = event.data.view,
|
||||
$target = $( event.target ),
|
||||
model = view.model,
|
||||
methods = _.indexBy( model.get( 'methods' ), 'instance_id' ),
|
||||
instance_id = $target.closest( 'tr' ).data( 'id' ),
|
||||
enabled = $target.closest( 'tr' ).data( 'enabled' ) === 'yes' ? 'no' : 'yes',
|
||||
changes = {};
|
||||
|
||||
event.preventDefault();
|
||||
methods[ instance_id ].enabled = enabled;
|
||||
changes.methods = changes.methods || { methods : {} };
|
||||
changes.methods[ instance_id ] = _.extend( changes.methods[ instance_id ] || {}, { enabled : enabled } );
|
||||
model.set( 'methods', methods );
|
||||
model.logChanges( changes );
|
||||
view.render();
|
||||
},
|
||||
setUnloadConfirmation: function() {
|
||||
this.needsUnloadConfirm = true;
|
||||
$save_button.prop( 'disabled', false );
|
||||
},
|
||||
clearUnloadConfirmation: function() {
|
||||
this.needsUnloadConfirm = false;
|
||||
$save_button.attr( 'disabled', 'disabled' );
|
||||
},
|
||||
unloadConfirmation: function( event ) {
|
||||
if ( event.data.view.needsUnloadConfirm ) {
|
||||
event.returnValue = data.strings.unload_confirmation_msg;
|
||||
window.event.returnValue = data.strings.unload_confirmation_msg;
|
||||
return data.strings.unload_confirmation_msg;
|
||||
}
|
||||
},
|
||||
updateModelOnChange: function( event ) {
|
||||
var model = event.data.view.model,
|
||||
$target = $( event.target ),
|
||||
instance_id = $target.closest( 'tr' ).data( 'id' ),
|
||||
attribute = $target.data( 'attribute' ),
|
||||
value = $target.val(),
|
||||
methods = _.indexBy( model.get( 'methods' ), 'instance_id' ),
|
||||
changes = {};
|
||||
|
||||
if ( methods[ instance_id ][ attribute ] !== value ) {
|
||||
changes.methods[ instance_id ] = {};
|
||||
changes.methods[ instance_id ][ attribute ] = value;
|
||||
methods[ instance_id ][ attribute ] = value;
|
||||
}
|
||||
|
||||
model.logChanges( changes );
|
||||
},
|
||||
updateModelOnSort: function( event ) {
|
||||
var view = event.data.view,
|
||||
model = view.model,
|
||||
methods = _.indexBy( model.get( 'methods' ), 'instance_id' ),
|
||||
changes = {};
|
||||
|
||||
_.each( methods, function( method ) {
|
||||
var old_position = parseInt( method.method_order, 10 );
|
||||
var new_position = parseInt( $table.find( 'tr[data-id="' + method.instance_id + '"]').index() + 1, 10 );
|
||||
|
||||
if ( old_position !== new_position ) {
|
||||
methods[ method.instance_id ].method_order = new_position;
|
||||
changes.methods = changes.methods || { methods : {} };
|
||||
changes.methods[ method.instance_id ] = _.extend(
|
||||
changes.methods[ method.instance_id ] || {}, { method_order : new_position }
|
||||
);
|
||||
}
|
||||
} );
|
||||
|
||||
if ( _.size( changes ) ) {
|
||||
model.logChanges( changes );
|
||||
}
|
||||
},
|
||||
onConfigureShippingMethod: function( event ) {
|
||||
var instance_id = $( this ).closest( 'tr' ).data( 'id' ),
|
||||
model = event.data.view.model,
|
||||
methods = _.indexBy( model.get( 'methods' ), 'instance_id' ),
|
||||
method = methods[ instance_id ];
|
||||
|
||||
// Only load modal if supported
|
||||
if ( ! method.settings_html ) {
|
||||
return true;
|
||||
}
|
||||
|
||||
event.preventDefault();
|
||||
|
||||
$( this ).WCBackboneModal({
|
||||
template : 'wc-modal-shipping-method-settings',
|
||||
variable : {
|
||||
instance_id : instance_id,
|
||||
method : method
|
||||
},
|
||||
data : {
|
||||
instance_id : instance_id,
|
||||
method : method
|
||||
}
|
||||
});
|
||||
|
||||
$( document.body ).trigger( 'init_tooltips' );
|
||||
},
|
||||
onConfigureShippingMethodSubmitted: function( event, target, posted_data ) {
|
||||
if ( 'wc-modal-shipping-method-settings' === target ) {
|
||||
shippingMethodView.block();
|
||||
|
||||
// Save method settings via ajax call
|
||||
$.post(
|
||||
ajaxurl + ( ajaxurl.indexOf( '?' ) > 0 ? '&' : '?' ) + 'action=woocommerce_shipping_zone_methods_save_settings',
|
||||
{
|
||||
wc_shipping_zones_nonce : data.wc_shipping_zones_nonce,
|
||||
instance_id : posted_data.instance_id,
|
||||
data : posted_data
|
||||
},
|
||||
function( response, textStatus ) {
|
||||
if ( 'success' === textStatus && response.success ) {
|
||||
$( 'table.wc-shipping-zone-methods' ).parent().find( '#woocommerce_errors' ).remove();
|
||||
|
||||
// If there were errors, prepend the form.
|
||||
if ( response.data.errors.length > 0 ) {
|
||||
shippingMethodView.showErrors( response.data.errors );
|
||||
}
|
||||
|
||||
// Method was saved. Re-render.
|
||||
if ( _.size( shippingMethodView.model.changes ) ) {
|
||||
shippingMethodView.model.save();
|
||||
} else {
|
||||
shippingMethodView.model.onSaveResponse( response, textStatus );
|
||||
}
|
||||
} else {
|
||||
window.alert( data.strings.save_failed );
|
||||
shippingMethodView.unblock();
|
||||
}
|
||||
},
|
||||
'json'
|
||||
);
|
||||
}
|
||||
},
|
||||
showErrors: function( errors ) {
|
||||
var error_html = '<div id="woocommerce_errors" class="error notice is-dismissible">';
|
||||
|
||||
$( errors ).each( function( index, value ) {
|
||||
error_html = error_html + '<p>' + value + '</p>';
|
||||
} );
|
||||
error_html = error_html + '</div>';
|
||||
|
||||
$( 'table.wc-shipping-zone-methods' ).before( error_html );
|
||||
},
|
||||
onAddShippingMethod: function( event ) {
|
||||
event.preventDefault();
|
||||
|
||||
$( this ).WCBackboneModal({
|
||||
template : 'wc-modal-add-shipping-method',
|
||||
variable : {
|
||||
zone_id : data.zone_id
|
||||
}
|
||||
});
|
||||
|
||||
$( '.wc-shipping-zone-method-selector select' ).trigger( 'change' );
|
||||
},
|
||||
onAddShippingMethodSubmitted: function( event, target, posted_data ) {
|
||||
if ( 'wc-modal-add-shipping-method' === target ) {
|
||||
shippingMethodView.block();
|
||||
|
||||
// Add method to zone via ajax call
|
||||
$.post( ajaxurl + ( ajaxurl.indexOf( '?' ) > 0 ? '&' : '?' ) + 'action=woocommerce_shipping_zone_add_method', {
|
||||
wc_shipping_zones_nonce : data.wc_shipping_zones_nonce,
|
||||
method_id : posted_data.add_method_id,
|
||||
zone_id : data.zone_id
|
||||
}, function( response, textStatus ) {
|
||||
if ( 'success' === textStatus && response.success ) {
|
||||
if ( response.data.zone_id !== data.zone_id ) {
|
||||
data.zone_id = response.data.zone_id;
|
||||
if ( window.history.pushState ) {
|
||||
window.history.pushState(
|
||||
{},
|
||||
'',
|
||||
'admin.php?page=wc-settings&tab=shipping&zone_id=' + response.data.zone_id
|
||||
);
|
||||
}
|
||||
}
|
||||
// Trigger save if there are changes, or just re-render
|
||||
if ( _.size( shippingMethodView.model.changes ) ) {
|
||||
shippingMethodView.model.save();
|
||||
} else {
|
||||
shippingMethodView.model.set( 'methods', response.data.methods );
|
||||
shippingMethodView.model.trigger( 'change:methods' );
|
||||
shippingMethodView.model.changes = {};
|
||||
shippingMethodView.model.trigger( 'saved:methods' );
|
||||
}
|
||||
}
|
||||
shippingMethodView.unblock();
|
||||
}, 'json' );
|
||||
}
|
||||
},
|
||||
onChangeShippingMethodSelector: function() {
|
||||
var description = $( this ).find( 'option:selected' ).data( 'description' );
|
||||
$( this ).parent().find( '.wc-shipping-zone-method-description' ).remove();
|
||||
$( this ).after( '<div class="wc-shipping-zone-method-description">' + description + '</div>' );
|
||||
$( this ).closest( 'article' ).height( $( this ).parent().height() );
|
||||
},
|
||||
onTogglePostcodes: function( event ) {
|
||||
event.preventDefault();
|
||||
var $tr = $( this ).closest( 'tr');
|
||||
$tr.find( '.wc-shipping-zone-postcodes' ).show();
|
||||
$tr.find( '.wc-shipping-zone-postcodes-toggle' ).hide();
|
||||
}
|
||||
} ),
|
||||
shippingMethod = new ShippingMethod({
|
||||
methods: data.methods,
|
||||
zone_name: data.zone_name
|
||||
} ),
|
||||
shippingMethodView = new ShippingMethodView({
|
||||
model: shippingMethod,
|
||||
el: $tbody
|
||||
} );
|
||||
|
||||
shippingMethodView.render();
|
||||
|
||||
$tbody.sortable({
|
||||
items: 'tr',
|
||||
cursor: 'move',
|
||||
axis: 'y',
|
||||
handle: 'td.wc-shipping-zone-method-sort',
|
||||
scrollSensitivity: 40
|
||||
});
|
||||
});
|
||||
})( jQuery, shippingZoneMethodsLocalizeScript, wp, ajaxurl );
|
1
assets/js/admin/wc-shipping-zone-methods.min.js
vendored
Normal file
1
assets/js/admin/wc-shipping-zone-methods.min.js
vendored
Normal file
File diff suppressed because one or more lines are too long
275
assets/js/admin/wc-shipping-zones.js
Normal file
275
assets/js/admin/wc-shipping-zones.js
Normal file
@ -0,0 +1,275 @@
|
||||
/* global shippingZonesLocalizeScript, ajaxurl */
|
||||
( function( $, data, wp, ajaxurl ) {
|
||||
$( function() {
|
||||
var $table = $( '.wc-shipping-zones' ),
|
||||
$tbody = $( '.wc-shipping-zone-rows' ),
|
||||
$save_button = $( '.wc-shipping-zone-save' ),
|
||||
$row_template = wp.template( 'wc-shipping-zone-row' ),
|
||||
$blank_template = wp.template( 'wc-shipping-zone-row-blank' ),
|
||||
|
||||
// Backbone model
|
||||
ShippingZone = Backbone.Model.extend({
|
||||
changes: {},
|
||||
logChanges: function( changedRows ) {
|
||||
var changes = this.changes || {};
|
||||
|
||||
_.each( changedRows, function( row, id ) {
|
||||
changes[ id ] = _.extend( changes[ id ] || { zone_id : id }, row );
|
||||
} );
|
||||
|
||||
this.changes = changes;
|
||||
this.trigger( 'change:zones' );
|
||||
},
|
||||
discardChanges: function( id ) {
|
||||
var changes = this.changes || {},
|
||||
set_position = null,
|
||||
zones = _.indexBy( this.get( 'zones' ), 'zone_id' );
|
||||
|
||||
// Find current set position if it has moved since last save
|
||||
if ( changes[ id ] && changes[ id ].zone_order !== undefined ) {
|
||||
set_position = changes[ id ].zone_order;
|
||||
}
|
||||
|
||||
// Delete all changes
|
||||
delete changes[ id ];
|
||||
|
||||
// If the position was set, and this zone does exist in DB, set the position again so the changes are not lost.
|
||||
if ( set_position !== null && zones[ id ] && zones[ id ].zone_order !== set_position ) {
|
||||
changes[ id ] = _.extend( changes[ id ] || {}, { zone_id : id, zone_order : set_position } );
|
||||
}
|
||||
|
||||
this.changes = changes;
|
||||
|
||||
// No changes? Disable save button.
|
||||
if ( 0 === _.size( this.changes ) ) {
|
||||
shippingZoneView.clearUnloadConfirmation();
|
||||
}
|
||||
},
|
||||
save: function() {
|
||||
if ( _.size( this.changes ) ) {
|
||||
$.post( ajaxurl + ( ajaxurl.indexOf( '?' ) > 0 ? '&' : '?' ) + 'action=woocommerce_shipping_zones_save_changes', {
|
||||
wc_shipping_zones_nonce : data.wc_shipping_zones_nonce,
|
||||
changes : this.changes
|
||||
}, this.onSaveResponse, 'json' );
|
||||
} else {
|
||||
shippingZone.trigger( 'saved:zones' );
|
||||
}
|
||||
},
|
||||
onSaveResponse: function( response, textStatus ) {
|
||||
if ( 'success' === textStatus ) {
|
||||
if ( response.success ) {
|
||||
shippingZone.set( 'zones', response.data.zones );
|
||||
shippingZone.trigger( 'change:zones' );
|
||||
shippingZone.changes = {};
|
||||
shippingZone.trigger( 'saved:zones' );
|
||||
} else {
|
||||
window.alert( data.strings.save_failed );
|
||||
}
|
||||
}
|
||||
}
|
||||
} ),
|
||||
|
||||
// Backbone view
|
||||
ShippingZoneView = Backbone.View.extend({
|
||||
rowTemplate: $row_template,
|
||||
initialize: function() {
|
||||
this.listenTo( this.model, 'change:zones', this.setUnloadConfirmation );
|
||||
this.listenTo( this.model, 'saved:zones', this.clearUnloadConfirmation );
|
||||
this.listenTo( this.model, 'saved:zones', this.render );
|
||||
$tbody.on( 'change', { view: this }, this.updateModelOnChange );
|
||||
$tbody.on( 'sortupdate', { view: this }, this.updateModelOnSort );
|
||||
$( window ).on( 'beforeunload', { view: this }, this.unloadConfirmation );
|
||||
$( document.body ).on( 'click', '.wc-shipping-zone-add', { view: this }, this.onAddNewRow );
|
||||
},
|
||||
onAddNewRow: function() {
|
||||
var $link = $( this );
|
||||
window.location.href = $link.attr( 'href' );
|
||||
},
|
||||
block: function() {
|
||||
$( this.el ).block({
|
||||
message: null,
|
||||
overlayCSS: {
|
||||
background: '#fff',
|
||||
opacity: 0.6
|
||||
}
|
||||
});
|
||||
},
|
||||
unblock: function() {
|
||||
$( this.el ).unblock();
|
||||
},
|
||||
render: function() {
|
||||
var zones = _.indexBy( this.model.get( 'zones' ), 'zone_id' ),
|
||||
view = this;
|
||||
|
||||
view.$el.empty();
|
||||
view.unblock();
|
||||
|
||||
if ( _.size( zones ) ) {
|
||||
// Sort zones
|
||||
zones = _( zones )
|
||||
.chain()
|
||||
.sortBy( function ( zone ) { return parseInt( zone.zone_id, 10 ); } )
|
||||
.sortBy( function ( zone ) { return parseInt( zone.zone_order, 10 ); } )
|
||||
.value();
|
||||
|
||||
// Populate $tbody with the current zones
|
||||
$.each( zones, function( id, rowData ) {
|
||||
view.renderRow( rowData );
|
||||
} );
|
||||
} else {
|
||||
view.$el.append( $blank_template );
|
||||
}
|
||||
|
||||
view.initRows();
|
||||
},
|
||||
renderRow: function( rowData ) {
|
||||
var view = this;
|
||||
view.$el.append( view.rowTemplate( rowData ) );
|
||||
view.initRow( rowData );
|
||||
},
|
||||
initRow: function( rowData ) {
|
||||
var view = this;
|
||||
var $tr = view.$el.find( 'tr[data-id="' + rowData.zone_id + '"]');
|
||||
|
||||
// List shipping methods
|
||||
view.renderShippingMethods( rowData.zone_id, rowData.shipping_methods );
|
||||
$tr.find( '.wc-shipping-zone-delete' ).on( 'click', { view: this }, this.onDeleteRow );
|
||||
},
|
||||
initRows: function() {
|
||||
// Stripe
|
||||
if ( 0 === ( $( 'tbody.wc-shipping-zone-rows tr' ).length % 2 ) ) {
|
||||
$table.find( 'tbody.wc-shipping-zone-rows' ).next( 'tbody' ).find( 'tr' ).addClass( 'odd' );
|
||||
} else {
|
||||
$table.find( 'tbody.wc-shipping-zone-rows' ).next( 'tbody' ).find( 'tr' ).removeClass( 'odd' );
|
||||
}
|
||||
// Tooltips
|
||||
$( '#tiptip_holder' ).removeAttr( 'style' );
|
||||
$( '#tiptip_arrow' ).removeAttr( 'style' );
|
||||
$( '.tips' ).tipTip({ 'attribute': 'data-tip', 'fadeIn': 50, 'fadeOut': 50, 'delay': 50 });
|
||||
},
|
||||
renderShippingMethods: function( zone_id, shipping_methods ) {
|
||||
var $tr = $( '.wc-shipping-zones tr[data-id="' + zone_id + '"]');
|
||||
var $method_list = $tr.find('.wc-shipping-zone-methods ul');
|
||||
|
||||
$method_list.find( '.wc-shipping-zone-method' ).remove();
|
||||
|
||||
if ( _.size( shipping_methods ) ) {
|
||||
shipping_methods = _.sortBy( shipping_methods, function( method ) {
|
||||
return parseInt( method.method_order, 10 );
|
||||
} );
|
||||
|
||||
_.each( shipping_methods, function( shipping_method ) {
|
||||
var class_name = 'method_disabled';
|
||||
|
||||
if ( 'yes' === shipping_method.enabled ) {
|
||||
class_name = 'method_enabled';
|
||||
}
|
||||
|
||||
$method_list.append(
|
||||
'<li class="wc-shipping-zone-method ' + class_name + '">' + shipping_method.title + '</li>'
|
||||
);
|
||||
} );
|
||||
} else {
|
||||
$method_list.append( '<li class="wc-shipping-zone-method">' + data.strings.no_shipping_methods_offered + '</li>' );
|
||||
}
|
||||
},
|
||||
onDeleteRow: function( event ) {
|
||||
var view = event.data.view,
|
||||
model = view.model,
|
||||
zones = _.indexBy( model.get( 'zones' ), 'zone_id' ),
|
||||
changes = {},
|
||||
row = $( this ).closest('tr'),
|
||||
zone_id = row.data('id');
|
||||
|
||||
event.preventDefault();
|
||||
|
||||
if ( window.confirm( data.strings.delete_confirmation_msg ) ) {
|
||||
if ( zones[ zone_id ] ) {
|
||||
delete zones[ zone_id ];
|
||||
changes[ zone_id ] = _.extend( changes[ zone_id ] || {}, { deleted : 'deleted' } );
|
||||
model.set( 'zones', zones );
|
||||
model.logChanges( changes );
|
||||
event.data.view.block();
|
||||
event.data.view.model.save();
|
||||
}
|
||||
}
|
||||
},
|
||||
setUnloadConfirmation: function() {
|
||||
this.needsUnloadConfirm = true;
|
||||
$save_button.prop( 'disabled', false );
|
||||
},
|
||||
clearUnloadConfirmation: function() {
|
||||
this.needsUnloadConfirm = false;
|
||||
$save_button.prop( 'disabled', true );
|
||||
},
|
||||
unloadConfirmation: function( event ) {
|
||||
if ( event.data.view.needsUnloadConfirm ) {
|
||||
event.returnValue = data.strings.unload_confirmation_msg;
|
||||
window.event.returnValue = data.strings.unload_confirmation_msg;
|
||||
return data.strings.unload_confirmation_msg;
|
||||
}
|
||||
},
|
||||
updateModelOnChange: function( event ) {
|
||||
var model = event.data.view.model,
|
||||
$target = $( event.target ),
|
||||
zone_id = $target.closest( 'tr' ).data( 'id' ),
|
||||
attribute = $target.data( 'attribute' ),
|
||||
value = $target.val(),
|
||||
zones = _.indexBy( model.get( 'zones' ), 'zone_id' ),
|
||||
changes = {};
|
||||
|
||||
if ( ! zones[ zone_id ] || zones[ zone_id ][ attribute ] !== value ) {
|
||||
changes[ zone_id ] = {};
|
||||
changes[ zone_id ][ attribute ] = value;
|
||||
}
|
||||
|
||||
model.logChanges( changes );
|
||||
},
|
||||
updateModelOnSort: function( event ) {
|
||||
var view = event.data.view,
|
||||
model = view.model,
|
||||
zones = _.indexBy( model.get( 'zones' ), 'zone_id' ),
|
||||
rows = $( 'tbody.wc-shipping-zone-rows tr' ),
|
||||
changes = {};
|
||||
|
||||
// Update sorted row position
|
||||
_.each( rows, function( row ) {
|
||||
var zone_id = $( row ).data( 'id' ),
|
||||
old_position = null,
|
||||
new_position = parseInt( $( row ).index(), 10 );
|
||||
|
||||
if ( zones[ zone_id ] ) {
|
||||
old_position = parseInt( zones[ zone_id ].zone_order, 10 );
|
||||
}
|
||||
|
||||
if ( old_position !== new_position ) {
|
||||
changes[ zone_id ] = _.extend( changes[ zone_id ] || {}, { zone_order : new_position } );
|
||||
}
|
||||
} );
|
||||
|
||||
if ( _.size( changes ) ) {
|
||||
model.logChanges( changes );
|
||||
event.data.view.block();
|
||||
event.data.view.model.save();
|
||||
}
|
||||
}
|
||||
} ),
|
||||
shippingZone = new ShippingZone({
|
||||
zones: data.zones
|
||||
} ),
|
||||
shippingZoneView = new ShippingZoneView({
|
||||
model: shippingZone,
|
||||
el: $tbody
|
||||
} );
|
||||
|
||||
shippingZoneView.render();
|
||||
|
||||
$tbody.sortable({
|
||||
items: 'tr',
|
||||
cursor: 'move',
|
||||
axis: 'y',
|
||||
handle: 'td.wc-shipping-zone-sort',
|
||||
scrollSensitivity: 40
|
||||
});
|
||||
});
|
||||
})( jQuery, shippingZonesLocalizeScript, wp, ajaxurl );
|
1
assets/js/admin/wc-shipping-zones.min.js
vendored
Normal file
1
assets/js/admin/wc-shipping-zones.min.js
vendored
Normal file
@ -0,0 +1 @@
|
||||
!function(r,l,c,h){r(function(){var e=r(".wc-shipping-zones"),n=r(".wc-shipping-zone-rows"),i=r(".wc-shipping-zone-save"),o=c.template("wc-shipping-zone-row"),t=c.template("wc-shipping-zone-row-blank"),s=Backbone.Model.extend({changes:{},logChanges:function(e){var i=this.changes||{};_.each(e,function(e,n){i[n]=_.extend(i[n]||{zone_id:n},e)}),this.changes=i,this.trigger("change:zones")},discardChanges:function(e){var n=this.changes||{},i=null,o=_.indexBy(this.get("zones"),"zone_id");n[e]&&n[e].zone_order!==undefined&&(i=n[e].zone_order),delete n[e],null!==i&&o[e]&&o[e].zone_order!==i&&(n[e]=_.extend(n[e]||{},{zone_id:e,zone_order:i})),this.changes=n,0===_.size(this.changes)&&a.clearUnloadConfirmation()},save:function(){_.size(this.changes)?r.post(h+(0<h.indexOf("?")?"&":"?")+"action=woocommerce_shipping_zones_save_changes",{wc_shipping_zones_nonce:l.wc_shipping_zones_nonce,changes:this.changes},this.onSaveResponse,"json"):d.trigger("saved:zones")},onSaveResponse:function(e,n){"success"===n&&(e.success?(d.set("zones",e.data.zones),d.trigger("change:zones"),d.changes={},d.trigger("saved:zones")):window.alert(l.strings.save_failed))}}),o=Backbone.View.extend({rowTemplate:o,initialize:function(){this.listenTo(this.model,"change:zones",this.setUnloadConfirmation),this.listenTo(this.model,"saved:zones",this.clearUnloadConfirmation),this.listenTo(this.model,"saved:zones",this.render),n.on("change",{view:this},this.updateModelOnChange),n.on("sortupdate",{view:this},this.updateModelOnSort),r(window).on("beforeunload",{view:this},this.unloadConfirmation),r(document.body).on("click",".wc-shipping-zone-add",{view:this},this.onAddNewRow)},onAddNewRow:function(){var e=r(this);window.location.href=e.attr("href")},block:function(){r(this.el).block({message:null,overlayCSS:{background:"#fff",opacity:.6}})},unblock:function(){r(this.el).unblock()},render:function(){var e=_.indexBy(this.model.get("zones"),"zone_id"),i=this;i.$el.empty(),i.unblock(),_.size(e)?(e=_(e).chain().sortBy(function(e){return parseInt(e.zone_id,10)}).sortBy(function(e){return parseInt(e.zone_order,10)}).value(),r.each(e,function(e,n){i.renderRow(n)})):i.$el.append(t),i.initRows()},renderRow:function(e){var n=this;n.$el.append(n.rowTemplate(e)),n.initRow(e)},initRow:function(e){var n=this.$el.find('tr[data-id="'+e.zone_id+'"]');this.renderShippingMethods(e.zone_id,e.shipping_methods),n.find(".wc-shipping-zone-delete").on("click",{view:this},this.onDeleteRow)},initRows:function(){0==r("tbody.wc-shipping-zone-rows tr").length%2?e.find("tbody.wc-shipping-zone-rows").next("tbody").find("tr").addClass("odd"):e.find("tbody.wc-shipping-zone-rows").next("tbody").find("tr").removeClass("odd"),r("#tiptip_holder").removeAttr("style"),r("#tiptip_arrow").removeAttr("style"),r(".tips").tipTip({attribute:"data-tip",fadeIn:50,fadeOut:50,delay:50})},renderShippingMethods:function(e,n){var i=r('.wc-shipping-zones tr[data-id="'+e+'"]').find(".wc-shipping-zone-methods ul");i.find(".wc-shipping-zone-method").remove(),_.size(n)?(n=_.sortBy(n,function(e){return parseInt(e.method_order,10)}),_.each(n,function(e){var n="method_disabled";"yes"===e.enabled&&(n="method_enabled"),i.append('<li class="wc-shipping-zone-method '+n+'">'+e.title+"</li>")})):i.append('<li class="wc-shipping-zone-method">'+l.strings.no_shipping_methods_offered+"</li>")},onDeleteRow:function(e){var n=e.data.view.model,i=_.indexBy(n.get("zones"),"zone_id"),o={},t=r(this).closest("tr").data("id");e.preventDefault(),window.confirm(l.strings.delete_confirmation_msg)&&i[t]&&(delete i[t],o[t]=_.extend(o[t]||{},{deleted:"deleted"}),n.set("zones",i),n.logChanges(o),e.data.view.block(),e.data.view.model.save())},setUnloadConfirmation:function(){this.needsUnloadConfirm=!0,i.prop("disabled",!1)},clearUnloadConfirmation:function(){this.needsUnloadConfirm=!1,i.prop("disabled",!0)},unloadConfirmation:function(e){if(e.data.view.needsUnloadConfirm)return e.returnValue=l.strings.unload_confirmation_msg,window.event.returnValue=l.strings.unload_confirmation_msg,l.strings.unload_confirmation_msg},updateModelOnChange:function(e){var n=e.data.view.model,i=r(e.target),o=i.closest("tr").data("id"),t=i.data("attribute"),s=i.val(),e=_.indexBy(n.get("zones"),"zone_id"),i={};e[o]&&e[o][t]===s||(i[o]={},i[o][t]=s),n.logChanges(i)},updateModelOnSort:function(e){var n=e.data.view.model,o=_.indexBy(n.get("zones"),"zone_id"),i=r("tbody.wc-shipping-zone-rows tr"),t={};_.each(i,function(e){var n=r(e).data("id"),i=null,e=parseInt(r(e).index(),10);o[n]&&(i=parseInt(o[n].zone_order,10)),i!==e&&(t[n]=_.extend(t[n]||{},{zone_order:e}))}),_.size(t)&&(n.logChanges(t),e.data.view.block(),e.data.view.model.save())}}),d=new s({zones:l.zones}),a=new o({model:d,el:n});a.render(),n.sortable({items:"tr",cursor:"move",axis:"y",handle:"td.wc-shipping-zone-sort",scrollSensitivity:40})})}(jQuery,shippingZonesLocalizeScript,wp,ajaxurl);
|
32
assets/js/admin/wc-status-widget.js
Normal file
32
assets/js/admin/wc-status-widget.js
Normal file
@ -0,0 +1,32 @@
|
||||
/*global jQuery */
|
||||
(function( $ ) {
|
||||
var recordEvent = function( link ) {
|
||||
window.wcTracks.recordEvent( 'status_widget_click', {
|
||||
link: link
|
||||
} );
|
||||
};
|
||||
|
||||
$( '.sales-this-month a' ).on( 'click', function() {
|
||||
recordEvent( 'net-sales' );
|
||||
});
|
||||
|
||||
$( '.best-seller-this-month a' ).on( 'click', function() {
|
||||
recordEvent( 'best-seller-this-month' );
|
||||
});
|
||||
|
||||
$( '.processing-orders a' ).on( 'click', function() {
|
||||
recordEvent( 'orders-processing' );
|
||||
});
|
||||
|
||||
$( '.on-hold-orders a' ).on( 'click', function() {
|
||||
recordEvent( 'orders-on-hold' );
|
||||
});
|
||||
|
||||
$( '.low-in-stock a' ).on( 'click', function() {
|
||||
recordEvent( 'low-stock' );
|
||||
});
|
||||
|
||||
$( '.out-of-stock a' ).on( 'click', function() {
|
||||
recordEvent( 'out-of-stock' );
|
||||
});
|
||||
})( jQuery );
|
1
assets/js/admin/wc-status-widget.min.js
vendored
Normal file
1
assets/js/admin/wc-status-widget.min.js
vendored
Normal file
@ -0,0 +1 @@
|
||||
!function(o){var n=function(o){window.wcTracks.recordEvent("status_widget_click",{link:o})};o(".sales-this-month a").on("click",function(){n("net-sales")}),o(".best-seller-this-month a").on("click",function(){n("best-seller-this-month")}),o(".processing-orders a").on("click",function(){n("orders-processing")}),o(".on-hold-orders a").on("click",function(){n("orders-on-hold")}),o(".low-in-stock a").on("click",function(){n("low-stock")}),o(".out-of-stock a").on("click",function(){n("out-of-stock")})}(jQuery);
|
452
assets/js/admin/woocommerce_admin.js
Normal file
452
assets/js/admin/woocommerce_admin.js
Normal file
@ -0,0 +1,452 @@
|
||||
/* global woocommerce_admin */
|
||||
( function( $, woocommerce_admin ) {
|
||||
$( function() {
|
||||
if ( 'undefined' === typeof woocommerce_admin ) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Add buttons to product screen.
|
||||
var $product_screen = $( '.edit-php.post-type-product' ),
|
||||
$title_action = $product_screen.find( '.page-title-action:first' ),
|
||||
$blankslate = $product_screen.find( '.woocommerce-BlankState' );
|
||||
|
||||
if ( 0 === $blankslate.length ) {
|
||||
if ( woocommerce_admin.urls.export_products ) {
|
||||
$title_action.after(
|
||||
'<a href="' +
|
||||
woocommerce_admin.urls.export_products +
|
||||
'" class="page-title-action">' +
|
||||
woocommerce_admin.strings.export_products +
|
||||
'</a>'
|
||||
);
|
||||
}
|
||||
if ( woocommerce_admin.urls.import_products ) {
|
||||
$title_action.after(
|
||||
'<a href="' +
|
||||
woocommerce_admin.urls.import_products +
|
||||
'" class="page-title-action">' +
|
||||
woocommerce_admin.strings.import_products +
|
||||
'</a>'
|
||||
);
|
||||
}
|
||||
} else {
|
||||
$title_action.hide();
|
||||
}
|
||||
|
||||
// Progress indicators when showing steps.
|
||||
$( '.woocommerce-progress-form-wrapper .button-next' ).on( 'click', function() {
|
||||
$('.wc-progress-form-content').block({
|
||||
message: null,
|
||||
overlayCSS: {
|
||||
background: '#fff',
|
||||
opacity: 0.6
|
||||
}
|
||||
});
|
||||
return true;
|
||||
} );
|
||||
|
||||
// Field validation error tips
|
||||
$( document.body )
|
||||
|
||||
.on( 'wc_add_error_tip', function( e, element, error_type ) {
|
||||
var offset = element.position();
|
||||
|
||||
if ( element.parent().find( '.wc_error_tip' ).length === 0 ) {
|
||||
element.after( '<div class="wc_error_tip ' + error_type + '">' + woocommerce_admin[error_type] + '</div>' );
|
||||
element.parent().find( '.wc_error_tip' )
|
||||
.css( 'left', offset.left + element.width() - ( element.width() / 2 ) - ( $( '.wc_error_tip' ).width() / 2 ) )
|
||||
.css( 'top', offset.top + element.height() )
|
||||
.fadeIn( '100' );
|
||||
}
|
||||
})
|
||||
|
||||
.on( 'wc_remove_error_tip', function( e, element, error_type ) {
|
||||
element.parent().find( '.wc_error_tip.' + error_type ).fadeOut( '100', function() { $( this ).remove(); } );
|
||||
})
|
||||
|
||||
.on( 'click', function() {
|
||||
$( '.wc_error_tip' ).fadeOut( '100', function() { $( this ).remove(); } );
|
||||
})
|
||||
|
||||
.on( 'blur', '.wc_input_decimal[type=text], .wc_input_price[type=text], .wc_input_country_iso[type=text]', function() {
|
||||
$( '.wc_error_tip' ).fadeOut( '100', function() { $( this ).remove(); } );
|
||||
})
|
||||
|
||||
.on(
|
||||
'change',
|
||||
'.wc_input_price[type=text], .wc_input_decimal[type=text], .wc-order-totals #refund_amount[type=text]',
|
||||
function() {
|
||||
var regex, decimalRegex,
|
||||
decimailPoint = woocommerce_admin.decimal_point;
|
||||
|
||||
if ( $( this ).is( '.wc_input_price' ) || $( this ).is( '#refund_amount' ) ) {
|
||||
decimailPoint = woocommerce_admin.mon_decimal_point;
|
||||
}
|
||||
|
||||
regex = new RegExp( '[^\-0-9\%\\' + decimailPoint + ']+', 'gi' );
|
||||
decimalRegex = new RegExp( '\\' + decimailPoint + '+', 'gi' );
|
||||
|
||||
var value = $( this ).val();
|
||||
var newvalue = value.replace( regex, '' ).replace( decimalRegex, decimailPoint );
|
||||
|
||||
if ( value !== newvalue ) {
|
||||
$( this ).val( newvalue );
|
||||
}
|
||||
}
|
||||
)
|
||||
|
||||
.on(
|
||||
'keyup',
|
||||
// eslint-disable-next-line max-len
|
||||
'.wc_input_price[type=text], .wc_input_decimal[type=text], .wc_input_country_iso[type=text], .wc-order-totals #refund_amount[type=text]',
|
||||
function() {
|
||||
var regex, error, decimalRegex;
|
||||
var checkDecimalNumbers = false;
|
||||
|
||||
if ( $( this ).is( '.wc_input_price' ) || $( this ).is( '#refund_amount' ) ) {
|
||||
checkDecimalNumbers = true;
|
||||
regex = new RegExp( '[^\-0-9\%\\' + woocommerce_admin.mon_decimal_point + ']+', 'gi' );
|
||||
decimalRegex = new RegExp( '[^\\' + woocommerce_admin.mon_decimal_point + ']', 'gi' );
|
||||
error = 'i18n_mon_decimal_error';
|
||||
} else if ( $( this ).is( '.wc_input_country_iso' ) ) {
|
||||
regex = new RegExp( '([^A-Z])+|(.){3,}', 'im' );
|
||||
error = 'i18n_country_iso_error';
|
||||
} else {
|
||||
checkDecimalNumbers = true;
|
||||
regex = new RegExp( '[^\-0-9\%\\' + woocommerce_admin.decimal_point + ']+', 'gi' );
|
||||
decimalRegex = new RegExp( '[^\\' + woocommerce_admin.decimal_point + ']', 'gi' );
|
||||
error = 'i18n_decimal_error';
|
||||
}
|
||||
|
||||
var value = $( this ).val();
|
||||
var newvalue = value.replace( regex, '' );
|
||||
|
||||
// Check if newvalue have more than one decimal point.
|
||||
if ( checkDecimalNumbers && 1 < newvalue.replace( decimalRegex, '' ).length ) {
|
||||
newvalue = newvalue.replace( decimalRegex, '' );
|
||||
}
|
||||
|
||||
if ( value !== newvalue ) {
|
||||
$( document.body ).triggerHandler( 'wc_add_error_tip', [ $( this ), error ] );
|
||||
} else {
|
||||
$( document.body ).triggerHandler( 'wc_remove_error_tip', [ $( this ), error ] );
|
||||
}
|
||||
}
|
||||
)
|
||||
|
||||
.on( 'change', '#_sale_price.wc_input_price[type=text], .wc_input_price[name^=variable_sale_price]', function() {
|
||||
var sale_price_field = $( this ), regular_price_field;
|
||||
|
||||
if ( sale_price_field.attr( 'name' ).indexOf( 'variable' ) !== -1 ) {
|
||||
regular_price_field = sale_price_field
|
||||
.parents( '.variable_pricing' )
|
||||
.find( '.wc_input_price[name^=variable_regular_price]' );
|
||||
} else {
|
||||
regular_price_field = $( '#_regular_price' );
|
||||
}
|
||||
|
||||
var sale_price = parseFloat(
|
||||
window.accounting.unformat( sale_price_field.val(), woocommerce_admin.mon_decimal_point )
|
||||
);
|
||||
var regular_price = parseFloat(
|
||||
window.accounting.unformat( regular_price_field.val(), woocommerce_admin.mon_decimal_point )
|
||||
);
|
||||
|
||||
if ( sale_price >= regular_price ) {
|
||||
$( this ).val( '' );
|
||||
}
|
||||
})
|
||||
|
||||
.on( 'keyup', '#_sale_price.wc_input_price[type=text], .wc_input_price[name^=variable_sale_price]', function() {
|
||||
var sale_price_field = $( this ), regular_price_field;
|
||||
|
||||
if ( sale_price_field.attr( 'name' ).indexOf( 'variable' ) !== -1 ) {
|
||||
regular_price_field = sale_price_field
|
||||
.parents( '.variable_pricing' )
|
||||
.find( '.wc_input_price[name^=variable_regular_price]' );
|
||||
} else {
|
||||
regular_price_field = $( '#_regular_price' );
|
||||
}
|
||||
|
||||
var sale_price = parseFloat(
|
||||
window.accounting.unformat( sale_price_field.val(), woocommerce_admin.mon_decimal_point )
|
||||
);
|
||||
var regular_price = parseFloat(
|
||||
window.accounting.unformat( regular_price_field.val(), woocommerce_admin.mon_decimal_point )
|
||||
);
|
||||
|
||||
if ( sale_price >= regular_price ) {
|
||||
$( document.body ).triggerHandler( 'wc_add_error_tip', [ $(this), 'i18n_sale_less_than_regular_error' ] );
|
||||
} else {
|
||||
$( document.body ).triggerHandler( 'wc_remove_error_tip', [ $(this), 'i18n_sale_less_than_regular_error' ] );
|
||||
}
|
||||
})
|
||||
|
||||
.on( 'init_tooltips', function() {
|
||||
|
||||
$( '.tips, .help_tip, .woocommerce-help-tip' ).tipTip( {
|
||||
'attribute': 'data-tip',
|
||||
'fadeIn': 50,
|
||||
'fadeOut': 50,
|
||||
'delay': 200,
|
||||
'keepAlive': true
|
||||
} );
|
||||
|
||||
$( '.column-wc_actions .wc-action-button' ).tipTip( {
|
||||
'fadeIn': 50,
|
||||
'fadeOut': 50,
|
||||
'delay': 200
|
||||
} );
|
||||
|
||||
// Add tiptip to parent element for widefat tables
|
||||
$( '.parent-tips' ).each( function() {
|
||||
$( this ).closest( 'a, th' ).attr( 'data-tip', $( this ).data( 'tip' ) ).tipTip( {
|
||||
'attribute': 'data-tip',
|
||||
'fadeIn': 50,
|
||||
'fadeOut': 50,
|
||||
'delay': 200,
|
||||
'keepAlive': true
|
||||
} ).css( 'cursor', 'help' );
|
||||
});
|
||||
});
|
||||
|
||||
// Tooltips
|
||||
$( document.body ).trigger( 'init_tooltips' );
|
||||
|
||||
// wc_input_table tables
|
||||
$( '.wc_input_table.sortable tbody' ).sortable({
|
||||
items: 'tr',
|
||||
cursor: 'move',
|
||||
axis: 'y',
|
||||
scrollSensitivity: 40,
|
||||
forcePlaceholderSize: true,
|
||||
helper: 'clone',
|
||||
opacity: 0.65,
|
||||
placeholder: 'wc-metabox-sortable-placeholder',
|
||||
start: function( event, ui ) {
|
||||
ui.item.css( 'background-color', '#f6f6f6' );
|
||||
},
|
||||
stop: function( event, ui ) {
|
||||
ui.item.removeAttr( 'style' );
|
||||
}
|
||||
});
|
||||
// Focus on inputs within the table if clicked instead of trying to sort.
|
||||
$( '.wc_input_table.sortable tbody input' ).on( 'click', function() {
|
||||
$( this ).trigger( 'focus' );
|
||||
} );
|
||||
|
||||
$( '.wc_input_table .remove_rows' ).on( 'click', function() {
|
||||
var $tbody = $( this ).closest( '.wc_input_table' ).find( 'tbody' );
|
||||
if ( $tbody.find( 'tr.current' ).length > 0 ) {
|
||||
var $current = $tbody.find( 'tr.current' );
|
||||
$current.each( function() {
|
||||
$( this ).remove();
|
||||
});
|
||||
}
|
||||
return false;
|
||||
});
|
||||
|
||||
var controlled = false;
|
||||
var shifted = false;
|
||||
var hasFocus = false;
|
||||
|
||||
$( document.body ).on( 'keyup keydown', function( e ) {
|
||||
shifted = e.shiftKey;
|
||||
controlled = e.ctrlKey || e.metaKey;
|
||||
});
|
||||
|
||||
$( '.wc_input_table' ).on( 'focus click', 'input', function( e ) {
|
||||
var $this_table = $( this ).closest( 'table, tbody' );
|
||||
var $this_row = $( this ).closest( 'tr' );
|
||||
|
||||
if ( ( e.type === 'focus' && hasFocus !== $this_row.index() ) || ( e.type === 'click' && $( this ).is( ':focus' ) ) ) {
|
||||
hasFocus = $this_row.index();
|
||||
|
||||
if ( ! shifted && ! controlled ) {
|
||||
$( 'tr', $this_table ).removeClass( 'current' ).removeClass( 'last_selected' );
|
||||
$this_row.addClass( 'current' ).addClass( 'last_selected' );
|
||||
} else if ( shifted ) {
|
||||
$( 'tr', $this_table ).removeClass( 'current' );
|
||||
$this_row.addClass( 'selected_now' ).addClass( 'current' );
|
||||
|
||||
if ( $( 'tr.last_selected', $this_table ).length > 0 ) {
|
||||
if ( $this_row.index() > $( 'tr.last_selected', $this_table ).index() ) {
|
||||
$( 'tr', $this_table )
|
||||
.slice( $( 'tr.last_selected', $this_table ).index(), $this_row.index() )
|
||||
.addClass( 'current' );
|
||||
} else {
|
||||
$( 'tr', $this_table )
|
||||
.slice( $this_row.index(), $( 'tr.last_selected', $this_table ).index() + 1 )
|
||||
.addClass( 'current' );
|
||||
}
|
||||
}
|
||||
|
||||
$( 'tr', $this_table ).removeClass( 'last_selected' );
|
||||
$this_row.addClass( 'last_selected' );
|
||||
} else {
|
||||
$( 'tr', $this_table ).removeClass( 'last_selected' );
|
||||
if ( controlled && $( this ).closest( 'tr' ).is( '.current' ) ) {
|
||||
$this_row.removeClass( 'current' );
|
||||
} else {
|
||||
$this_row.addClass( 'current' ).addClass( 'last_selected' );
|
||||
}
|
||||
}
|
||||
|
||||
$( 'tr', $this_table ).removeClass( 'selected_now' );
|
||||
}
|
||||
}).on( 'blur', 'input', function() {
|
||||
hasFocus = false;
|
||||
});
|
||||
|
||||
// Additional cost and Attribute term tables
|
||||
$( '.woocommerce_page_wc-settings .shippingrows tbody tr:even, table.attributes-table tbody tr:nth-child(odd)' )
|
||||
.addClass( 'alternate' );
|
||||
|
||||
// Show order items on orders page
|
||||
$( document.body ).on( 'click', '.show_order_items', function() {
|
||||
$( this ).closest( 'td' ).find( 'table' ).toggle();
|
||||
return false;
|
||||
});
|
||||
|
||||
// Select availability
|
||||
$( 'select.availability' ).on( 'change', function() {
|
||||
if ( $( this ).val() === 'all' ) {
|
||||
$( this ).closest( 'tr' ).next( 'tr' ).hide();
|
||||
} else {
|
||||
$( this ).closest( 'tr' ).next( 'tr' ).show();
|
||||
}
|
||||
}).trigger( 'change' );
|
||||
|
||||
// Hidden options
|
||||
$( '.hide_options_if_checked' ).each( function() {
|
||||
$( this ).find( 'input:eq(0)' ).on( 'change', function() {
|
||||
if ( $( this ).is( ':checked' ) ) {
|
||||
$( this )
|
||||
.closest( 'fieldset, tr' )
|
||||
.nextUntil( '.hide_options_if_checked, .show_options_if_checked', '.hidden_option' )
|
||||
.hide();
|
||||
} else {
|
||||
$( this )
|
||||
.closest( 'fieldset, tr' )
|
||||
.nextUntil( '.hide_options_if_checked, .show_options_if_checked', '.hidden_option' )
|
||||
.show();
|
||||
}
|
||||
}).trigger( 'change' );
|
||||
});
|
||||
|
||||
$( '.show_options_if_checked' ).each( function() {
|
||||
$( this ).find( 'input:eq(0)' ).on( 'change', function() {
|
||||
if ( $( this ).is( ':checked' ) ) {
|
||||
$( this )
|
||||
.closest( 'fieldset, tr' )
|
||||
.nextUntil( '.hide_options_if_checked, .show_options_if_checked', '.hidden_option' )
|
||||
.show();
|
||||
} else {
|
||||
$( this )
|
||||
.closest( 'fieldset, tr' )
|
||||
.nextUntil( '.hide_options_if_checked, .show_options_if_checked', '.hidden_option' )
|
||||
.hide();
|
||||
}
|
||||
}).trigger( 'change' );
|
||||
});
|
||||
|
||||
// Reviews.
|
||||
$( 'input#woocommerce_enable_reviews' ).on( 'change', function() {
|
||||
if ( $( this ).is( ':checked' ) ) {
|
||||
$( '#woocommerce_enable_review_rating' ).closest( 'tr' ).show();
|
||||
} else {
|
||||
$( '#woocommerce_enable_review_rating' ).closest( 'tr' ).hide();
|
||||
}
|
||||
}).trigger( 'change' );
|
||||
|
||||
// Attribute term table
|
||||
$( 'table.attributes-table tbody tr:nth-child(odd)' ).addClass( 'alternate' );
|
||||
|
||||
// Toggle gateway on/off.
|
||||
$( '.wc_gateways' ).on( 'click', '.wc-payment-gateway-method-toggle-enabled', function() {
|
||||
var $link = $( this ),
|
||||
$row = $link.closest( 'tr' ),
|
||||
$toggle = $link.find( '.woocommerce-input-toggle' );
|
||||
|
||||
var data = {
|
||||
action: 'woocommerce_toggle_gateway_enabled',
|
||||
security: woocommerce_admin.nonces.gateway_toggle,
|
||||
gateway_id: $row.data( 'gateway_id' )
|
||||
};
|
||||
|
||||
$toggle.addClass( 'woocommerce-input-toggle--loading' );
|
||||
|
||||
$.ajax( {
|
||||
url: woocommerce_admin.ajax_url,
|
||||
data: data,
|
||||
dataType : 'json',
|
||||
type : 'POST',
|
||||
success: function( response ) {
|
||||
if ( true === response.data ) {
|
||||
$toggle.removeClass( 'woocommerce-input-toggle--enabled, woocommerce-input-toggle--disabled' );
|
||||
$toggle.addClass( 'woocommerce-input-toggle--enabled' );
|
||||
$toggle.removeClass( 'woocommerce-input-toggle--loading' );
|
||||
} else if ( false === response.data ) {
|
||||
$toggle.removeClass( 'woocommerce-input-toggle--enabled, woocommerce-input-toggle--disabled' );
|
||||
$toggle.addClass( 'woocommerce-input-toggle--disabled' );
|
||||
$toggle.removeClass( 'woocommerce-input-toggle--loading' );
|
||||
} else if ( 'needs_setup' === response.data ) {
|
||||
window.location.href = $link.attr( 'href' );
|
||||
}
|
||||
}
|
||||
} );
|
||||
|
||||
return false;
|
||||
});
|
||||
|
||||
$( '#wpbody' ).on( 'click', '#doaction, #doaction2', function() {
|
||||
var action = $( this ).is( '#doaction' ) ? $( '#bulk-action-selector-top' ).val() : $( '#bulk-action-selector-bottom' ).val();
|
||||
|
||||
if ( 'remove_personal_data' === action ) {
|
||||
return window.confirm( woocommerce_admin.i18n_remove_personal_data_notice );
|
||||
}
|
||||
});
|
||||
|
||||
var marketplaceSectionDropdown = $( '#marketplace-current-section-dropdown' );
|
||||
var marketplaceSectionName = $( '#marketplace-current-section-name' );
|
||||
var marketplaceMenuIsOpen = false;
|
||||
|
||||
// Add event listener to toggle Marketplace menu on touch devices
|
||||
if ( marketplaceSectionDropdown.length ) {
|
||||
if ( isTouchDevice() ) {
|
||||
marketplaceSectionName.on( 'click', function() {
|
||||
marketplaceMenuIsOpen = ! marketplaceMenuIsOpen;
|
||||
if ( marketplaceMenuIsOpen ) {
|
||||
marketplaceSectionDropdown.addClass( 'is-open' );
|
||||
$( document ).on( 'click', maybeToggleMarketplaceMenu );
|
||||
} else {
|
||||
marketplaceSectionDropdown.removeClass( 'is-open' );
|
||||
$( document ).off( 'click', maybeToggleMarketplaceMenu );
|
||||
}
|
||||
} );
|
||||
} else {
|
||||
document.body.classList.add( 'no-touch' );
|
||||
}
|
||||
}
|
||||
|
||||
// Close menu if the user clicks outside it
|
||||
function maybeToggleMarketplaceMenu( e ) {
|
||||
if (
|
||||
! marketplaceSectionDropdown.is( e.target )
|
||||
&& marketplaceSectionDropdown.has( e.target ).length === 0
|
||||
) {
|
||||
marketplaceSectionDropdown.removeClass( 'is-open' );
|
||||
marketplaceMenuIsOpen = false;
|
||||
$( document ).off( 'click', maybeToggleMarketplaceMenu );
|
||||
}
|
||||
}
|
||||
|
||||
function isTouchDevice() {
|
||||
return ( ( 'ontouchstart' in window ) ||
|
||||
( navigator.maxTouchPoints > 0 ) ||
|
||||
( navigator.msMaxTouchPoints > 0 ) );
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
})( jQuery, woocommerce_admin );
|
1
assets/js/admin/woocommerce_admin.min.js
vendored
Normal file
1
assets/js/admin/woocommerce_admin.min.js
vendored
Normal file
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user