Move clipboards off zeroclipboard
This commit is contained in:
parent
abc43c473e
commit
279ac6814c
|
@ -1,4 +1,4 @@
|
|||
/*global jQuery, Backbone, _, woocommerce_admin_api_keys */
|
||||
/*global jQuery, Backbone, _, woocommerce_admin_api_keys, wcSetClipboard, wcClearClipboard */
|
||||
(function( $ ) {
|
||||
|
||||
var APIView = Backbone.View.extend({
|
||||
|
@ -50,32 +50,30 @@
|
|||
*/
|
||||
initTipTip: function( css_class ) {
|
||||
$( document.body )
|
||||
.on( 'aftercopy', css_class, function( e ) {
|
||||
if ( true === e.success['text/plain'] ) {
|
||||
$( '#copy-error' ).text( '' );
|
||||
$( css_class ).tipTip( {
|
||||
'attribute': 'data-tip',
|
||||
'activation': 'focus',
|
||||
'fadeIn': 50,
|
||||
'fadeOut': 50,
|
||||
'delay': 0
|
||||
} ).focus();
|
||||
} else {
|
||||
$( css_class ).parent().find( 'input' ).focus().select();
|
||||
$( '#copy-error' ).text( woocommerce_admin_api_keys.clipboard_failed );
|
||||
}
|
||||
} )
|
||||
.on( 'click', css_class, function() {
|
||||
.on( 'click', css_class, function( evt ) {
|
||||
evt.preventDefault();
|
||||
if ( ! document.queryCommandSupported( 'copy' ) ) {
|
||||
$( css_class ).parent().find( 'input' ).focus().select();
|
||||
$( '#copy-error' ).text( woocommerce_admin_api_keys.clipboard_failed );
|
||||
} else {
|
||||
$( '#copy-error' ).text( '' );
|
||||
wcClearClipboard();
|
||||
wcSetClipboard( $.trim( $( this ).prev( 'input' ).val() ), $( css_class ) );
|
||||
}
|
||||
} )
|
||||
.on( 'copy', css_class, function( e ) {
|
||||
.on( 'aftercopy', css_class, function() {
|
||||
$( '#copy-error' ).text( '' );
|
||||
e.clipboardData.clearData();
|
||||
e.clipboardData.setData( 'text/plain', $.trim( $( this ).prev( 'input' ).val() ) );
|
||||
e.preventDefault();
|
||||
$( css_class ).tipTip( {
|
||||
'attribute': 'data-tip',
|
||||
'activation': 'focus',
|
||||
'fadeIn': 50,
|
||||
'fadeOut': 50,
|
||||
'delay': 0
|
||||
} ).focus();
|
||||
} )
|
||||
.on( 'aftercopyerror', css_class, function() {
|
||||
$( css_class ).parent().find( 'input' ).focus().select();
|
||||
$( '#copy-error' ).text( woocommerce_admin_api_keys.clipboard_failed );
|
||||
} );
|
||||
},
|
||||
|
||||
|
|
|
@ -1 +1 @@
|
|||
!function(e){new(Backbone.View.extend({el:e("#key-fields"),events:{"click input#update_api_key":"saveKey"},initialize:function(){_.bindAll(this,"saveKey")},block:function(){e(this.el).block({message:null,overlayCSS:{background:"#fff",opacity:.6}})},unblock:function(){e(this.el).unblock()},initTipTip:function(i){e(document.body).on("aftercopy",i,function(t){!0===t.success["text/plain"]?(e("#copy-error").text(""),e(i).tipTip({attribute:"data-tip",activation:"focus",fadeIn:50,fadeOut:50,delay:0}).focus()):(e(i).parent().find("input").focus().select(),e("#copy-error").text(woocommerce_admin_api_keys.clipboard_failed))}).on("click",i,function(){document.queryCommandSupported("copy")||(e(i).parent().find("input").focus().select(),e("#copy-error").text(woocommerce_admin_api_keys.clipboard_failed))}).on("copy",i,function(i){e("#copy-error").text(""),i.clipboardData.clearData(),i.clipboardData.setData("text/plain",e.trim(e(this).prev("input").val())),i.preventDefault()})},createQRCode:function(i,t){e("#keys-qrcode").qrcode({text:i+"|"+t,width:120,height:120})},saveKey:function(i){i.preventDefault();var t=this;t.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:e("#key_id",t.el).val(),description:e("#key_description",t.el).val(),user:e("#key_user",t.el).val(),permissions:e("#key_permissions",t.el).val()},success:function(i){if(e(".wc-api-message",t.el).remove(),i.success){var a=i.data;if(e("h3",t.el).first().append('<div class="wc-api-message updated"><p>'+a.message+"</p></div>"),0<a.consumer_key.length&&0<a.consumer_secret.length){e("#api-keys-options",t.el).remove(),e("p.submit",t.el).empty().append(a.revoke_url);var o=wp.template("api-keys-template");e("p.submit",t.el).before(o({consumer_key:a.consumer_key,consumer_secret:a.consumer_secret})),t.createQRCode(a.consumer_key,a.consumer_secret),t.initTipTip(".copy-key"),t.initTipTip(".copy-secret")}else e("#key_description",t.el).val(a.description),e("#key_user",t.el).val(a.user_id),e("#key_permissions",t.el).val(a.permissions)}else e("h3",t.el).first().append('<div class="wc-api-message error"><p>'+i.data.message+"</p></div>");t.unblock()}})}}))}(jQuery);
|
||||
!function(e){new(Backbone.View.extend({el:e("#key-fields"),events:{"click input#update_api_key":"saveKey"},initialize:function(){_.bindAll(this,"saveKey")},block:function(){e(this.el).block({message:null,overlayCSS:{background:"#fff",opacity:.6}})},unblock:function(){e(this.el).unblock()},initTipTip:function(i){e(document.body).on("click",i,function(o){o.preventDefault(),document.queryCommandSupported("copy")?(e("#copy-error").text(""),wcClearClipboard(),wcSetClipboard(e.trim(e(this).prev("input").val()),e(i))):(e(i).parent().find("input").focus().select(),e("#copy-error").text(woocommerce_admin_api_keys.clipboard_failed))}).on("aftercopy",i,function(){e("#copy-error").text(""),e(i).tipTip({attribute:"data-tip",activation:"focus",fadeIn:50,fadeOut:50,delay:0}).focus()}).on("aftercopyerror",i,function(){e(i).parent().find("input").focus().select(),e("#copy-error").text(woocommerce_admin_api_keys.clipboard_failed)})},createQRCode:function(i,o){e("#keys-qrcode").qrcode({text:i+"|"+o,width:120,height:120})},saveKey:function(i){i.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:e("#key_id",o.el).val(),description:e("#key_description",o.el).val(),user:e("#key_user",o.el).val(),permissions:e("#key_permissions",o.el).val()},success:function(i){if(e(".wc-api-message",o.el).remove(),i.success){var t=i.data;if(e("h3",o.el).first().append('<div class="wc-api-message updated"><p>'+t.message+"</p></div>"),0<t.consumer_key.length&&0<t.consumer_secret.length){e("#api-keys-options",o.el).remove(),e("p.submit",o.el).empty().append(t.revoke_url);var a=wp.template("api-keys-template");e("p.submit",o.el).before(a({consumer_key:t.consumer_key,consumer_secret:t.consumer_secret})),o.createQRCode(t.consumer_key,t.consumer_secret),o.initTipTip(".copy-key"),o.initTipTip(".copy-secret")}else e("#key_description",o.el).val(t.description),e("#key_user",o.el).val(t.user_id),e("#key_permissions",o.el).val(t.permissions)}else e("h3",o.el).first().append('<div class="wc-api-message error"><p>'+i.data.message+"</p></div>");o.unblock()}})}}))}(jQuery);
|
|
@ -1,4 +1,4 @@
|
|||
/* global jQuery, woocommerce_admin_system_status */
|
||||
/* global jQuery, woocommerce_admin_system_status, wcSetClipboard, wcClearClipboard */
|
||||
jQuery( function ( $ ) {
|
||||
|
||||
/**
|
||||
|
@ -9,8 +9,9 @@ jQuery( function ( $ ) {
|
|||
$( document.body )
|
||||
.on( 'click', 'a.help_tip, a.woocommerce-help-tip', this.preventTipTipClick )
|
||||
.on( 'click', 'a.debug-report', this.generateReport )
|
||||
.on( 'copy', '#copy-for-support', this.copyReport )
|
||||
.on( 'aftercopy', '#copy-for-support', this.afterCopyReport );
|
||||
.on( 'click', '#copy-for-support', this.copyReport )
|
||||
.on( 'aftercopy', '#copy-for-support', this.copySuccess )
|
||||
.on( 'aftercopyfailure', '#copy-for-support', this.copyFail );
|
||||
},
|
||||
|
||||
/**
|
||||
|
@ -84,31 +85,30 @@ jQuery( function ( $ ) {
|
|||
* @param {Object} evt Copy event.
|
||||
*/
|
||||
copyReport: function( evt ) {
|
||||
evt.clipboardData.clearData();
|
||||
evt.clipboardData.setData( 'text/plain', $( '#debug-report' ).find( 'textarea' ).val() );
|
||||
wcClearClipboard();
|
||||
wcSetClipboard( $( '#debug-report' ).find( 'textarea' ).val(), $( this ) );
|
||||
evt.preventDefault();
|
||||
},
|
||||
|
||||
/**
|
||||
* Actions after copying the report.
|
||||
* Display a "Copied!" tip when success copied
|
||||
* or display an error message.
|
||||
*
|
||||
* @param {Object} evt Copy event.
|
||||
* Display a "Copied!" tip when success copying
|
||||
*/
|
||||
afterCopyReport: function( evt ) {
|
||||
if ( true === evt.success['text/plain'] ) {
|
||||
$( '#copy-for-support' ).tipTip({
|
||||
'attribute': 'data-tip',
|
||||
'activation': 'focus',
|
||||
'fadeIn': 50,
|
||||
'fadeOut': 50,
|
||||
'delay': 0
|
||||
}).focus();
|
||||
} else {
|
||||
$( '.copy-error' ).removeClass( 'hidden' );
|
||||
$( '#debug-report' ).find( 'textarea' ).focus().select();
|
||||
}
|
||||
copySuccess: function() {
|
||||
$( '#copy-for-support' ).tipTip({
|
||||
'attribute': 'data-tip',
|
||||
'activation': 'focus',
|
||||
'fadeIn': 50,
|
||||
'fadeOut': 50,
|
||||
'delay': 0
|
||||
}).focus();
|
||||
},
|
||||
|
||||
/**
|
||||
* Displays the copy error message when failure copying.
|
||||
*/
|
||||
copyFail: function() {
|
||||
$( '.copy-error' ).removeClass( 'hidden' );
|
||||
$( '#debug-report' ).find( 'textarea' ).focus().select();
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
@ -1 +1 @@
|
|||
jQuery(function(t){({init:function(){t(document.body).on("click","a.help_tip, a.woocommerce-help-tip",this.preventTipTipClick).on("click","a.debug-report",this.generateReport).on("copy","#copy-for-support",this.copyReport).on("aftercopy","#copy-for-support",this.afterCopyReport)},preventTipTipClick:function(){return!1},generateReport:function(){var e="";t(".wc_status_table thead, .wc_status_table tbody").each(function(){if(t(this).is("thead")){var i=t(this).find("th:eq(0)").data("export-label")||t(this).text();e=e+"\n### "+t.trim(i)+" ###\n\n"}else t("tr",t(this)).each(function(){var i=t(this).find("td:eq(0)").data("export-label")||t(this).find("td:eq(0)").text(),o=t.trim(i).replace(/(<([^>]+)>)/gi,""),a=t(this).find("td:eq(2)").clone();a.find(".private").remove(),a.find(".dashicons-yes").replaceWith("✔"),a.find(".dashicons-no-alt, .dashicons-warning").replaceWith("❌");var n=t.trim(a.text()),r=n.split(", ");if(r.length>1){var c="";t.each(r,function(t,e){c=c+e+"\n"}),n=c}e=e+""+o+": "+n+"\n"})});try{return t("#debug-report").slideDown(),t("#debug-report").find("textarea").val("`"+e+"`").focus().select(),t(this).fadeOut(),!1}catch(i){console.log(i)}return!1},copyReport:function(e){e.clipboardData.clearData(),e.clipboardData.setData("text/plain",t("#debug-report").find("textarea").val()),e.preventDefault()},afterCopyReport:function(e){!0===e.success["text/plain"]?t("#copy-for-support").tipTip({attribute:"data-tip",activation:"focus",fadeIn:50,fadeOut:50,delay:0}).focus():(t(".copy-error").removeClass("hidden"),t("#debug-report").find("textarea").focus().select())}}).init(),t("#log-viewer-select").on("click","h2 a.page-title-action",function(t){return t.stopImmediatePropagation(),window.confirm(woocommerce_admin_system_status.delete_log_confirmation)})});
|
||||
jQuery(function(t){({init:function(){t(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 e="";t(".wc_status_table thead, .wc_status_table tbody").each(function(){if(t(this).is("thead")){var i=t(this).find("th:eq(0)").data("export-label")||t(this).text();e=e+"\n### "+t.trim(i)+" ###\n\n"}else t("tr",t(this)).each(function(){var i=t(this).find("td:eq(0)").data("export-label")||t(this).find("td:eq(0)").text(),o=t.trim(i).replace(/(<([^>]+)>)/gi,""),n=t(this).find("td:eq(2)").clone();n.find(".private").remove(),n.find(".dashicons-yes").replaceWith("✔"),n.find(".dashicons-no-alt, .dashicons-warning").replaceWith("❌");var r=t.trim(n.text()),a=r.split(", ");if(a.length>1){var c="";t.each(a,function(t,e){c=c+e+"\n"}),r=c}e=e+""+o+": "+r+"\n"})});try{return t("#debug-report").slideDown(),t("#debug-report").find("textarea").val("`"+e+"`").focus().select(),t(this).fadeOut(),!1}catch(i){console.log(i)}return!1},copyReport:function(e){wcClearClipboard(),wcSetClipboard(t("#debug-report").find("textarea").val(),t(this)),e.preventDefault()},copySuccess:function(){t("#copy-for-support").tipTip({attribute:"data-tip",activation:"focus",fadeIn:50,fadeOut:50,delay:0}).focus()},copyFail:function(){t(".copy-error").removeClass("hidden"),t("#debug-report").find("textarea").focus().select()}}).init(),t("#log-viewer-select").on("click","h2 a.page-title-action",function(t){return t.stopImmediatePropagation(),window.confirm(woocommerce_admin_system_status.delete_log_confirmation)})});
|
|
@ -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="visibility:none">' );
|
||||
jQuery( 'body' ).append( $temp_input );
|
||||
$temp_input.val( data ).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( '' );
|
||||
}
|
|
@ -0,0 +1 @@
|
|||
function wcSetClipboard(e,r){void 0===r&&(r=jQuery(document));var t=jQuery('<textarea style="visibility:none">');jQuery("body").append(t),t.val(e).select(),r.trigger("beforecopy");try{document.execCommand("copy"),r.trigger("aftercopy")}catch(o){r.trigger("aftercopyfailure")}t.remove()}function wcClearClipboard(){wcSetClipboard("")}
|
|
@ -110,6 +110,7 @@ class WC_Admin_Assets {
|
|||
wp_register_script( 'wc-shipping-zones', WC()->plugin_url() . '/assets/js/admin/wc-shipping-zones' . $suffix . '.js', array( 'jquery', 'wp-util', 'underscore', 'backbone', 'jquery-ui-sortable', 'wc-enhanced-select', 'wc-backbone-modal' ), WC_VERSION );
|
||||
wp_register_script( 'wc-shipping-zone-methods', WC()->plugin_url() . '/assets/js/admin/wc-shipping-zone-methods' . $suffix . '.js', array( 'jquery', 'wp-util', 'underscore', 'backbone', 'jquery-ui-sortable', 'wc-backbone-modal' ), WC_VERSION );
|
||||
wp_register_script( 'wc-shipping-classes', WC()->plugin_url() . '/assets/js/admin/wc-shipping-classes' . $suffix . '.js', array( 'jquery', 'wp-util', 'underscore', 'backbone' ), WC_VERSION );
|
||||
wp_register_script( 'wc-clipboard', WC()->plugin_url() . '/assets/js/admin/wc-clipboard' . $suffix . '.js', array( 'jquery' ), WC_VERSION );
|
||||
wp_register_script( 'select2', WC()->plugin_url() . '/assets/js/select2/select2.full' . $suffix . '.js', array( 'jquery' ), '4.0.3' );
|
||||
wp_register_script( 'selectWoo', WC()->plugin_url() . '/assets/js/selectWoo/selectWoo.full' . $suffix . '.js', array( 'jquery' ), '1.0.0' );
|
||||
wp_register_script( 'wc-enhanced-select', WC()->plugin_url() . '/assets/js/admin/wc-enhanced-select' . $suffix . '.js', array( 'jquery', 'selectWoo' ), WC_VERSION );
|
||||
|
@ -346,7 +347,7 @@ class WC_Admin_Assets {
|
|||
|
||||
// API settings
|
||||
if ( $wc_screen_id . '_page_wc-settings' === $screen_id && isset( $_GET['section'] ) && 'keys' == $_GET['section'] ) {
|
||||
wp_register_script( 'wc-api-keys', WC()->plugin_url() . '/assets/js/admin/api-keys' . $suffix . '.js', array( 'jquery', 'woocommerce_admin', 'underscore', 'backbone', 'wp-util', 'qrcode', 'zeroclipboard' ), WC_VERSION, true );
|
||||
wp_register_script( 'wc-api-keys', WC()->plugin_url() . '/assets/js/admin/api-keys' . $suffix . '.js', array( 'jquery', 'woocommerce_admin', 'underscore', 'backbone', 'wp-util', 'qrcode', 'wc-clipboard' ), WC_VERSION, true );
|
||||
wp_enqueue_script( 'wc-api-keys' );
|
||||
wp_localize_script(
|
||||
'wc-api-keys',
|
||||
|
@ -361,7 +362,7 @@ class WC_Admin_Assets {
|
|||
|
||||
// System status.
|
||||
if ( $wc_screen_id . '_page_wc-status' === $screen_id ) {
|
||||
wp_register_script( 'wc-admin-system-status', WC()->plugin_url() . '/assets/js/admin/system-status' . $suffix . '.js', array( 'zeroclipboard' ), WC_VERSION );
|
||||
wp_register_script( 'wc-admin-system-status', WC()->plugin_url() . '/assets/js/admin/system-status' . $suffix . '.js', array( 'wc-clipboard' ), WC_VERSION );
|
||||
wp_enqueue_script( 'wc-admin-system-status' );
|
||||
wp_localize_script(
|
||||
'wc-admin-system-status',
|
||||
|
|
Loading…
Reference in New Issue