balmet.com

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs

dashboard-js.js (4304B)


      1 /* global jQuery, woocommerce_admin_system_status, wcSetClipboard, wcClearClipboard */
      2 jQuery( function ( $ ) {
      3 
      4 	/**
      5 	 * Users country and state fields
      6 	 */
      7 	var wcSystemStatus = {
      8 		init: function() {
      9 			$( document.body )
     10 				.on( 'click', 'a.help_tip, a.woocommerce-help-tip', this.preventTipTipClick )
     11 				.on( 'click', 'a.debug-report', this.generateReport )
     12 				.on( 'click', '#copy-for-support', this.copyReport )
     13 				.on( 'change', '#envato_activate_checkbox', this.buttonTigger )
     14 				$(document).bind('aftercopy',  this.copySuccess );
     15 				$(document).bind('aftercopyfailure',  this.copyFail );
     16 		},
     17 
     18 		/**
     19 		 * Prevent anchor behavior when click on TipTip.
     20 		 *
     21 		 * @return {Bool}
     22 		 */
     23 		preventTipTipClick: function() {
     24 			return false;
     25 		},
     26 
     27 		/**
     28 		 * Generate system status report.
     29 		 *
     30 		 * @return {Bool}
     31 		 */
     32 		generateReport: function() {
     33 			var report = '';
     34 
     35 			$( '.'+envato_theme_systemerrorshow.table_class+' thead, .'+envato_theme_systemerrorshow.table_class+' tbody' ).each( function() {
     36 				if ( $( this ).is( 'thead' ) ) {
     37 					var label = $( this ).find( 'th:eq(0)' ).data( 'export-label' ) || $( this ).text();
     38 					report = report + '\n---- ' + $.trim( label ) + ' ----\n\n';
     39 				} else {
     40 					$( 'tr', $( this ) ).each( function() {
     41 						var label       = $( this ).find( 'td:eq(0)' ).data( 'export-label' ) || $( this ).find( 'td:eq(0)' ).text();
     42 						var the_name    = $.trim( label ).replace( /(<([^>]+)>)/ig, '' ); // Remove HTML.
     43 
     44 						// Find value
     45 						var $value_html = $( this ).find( 'td:eq(2)' ).clone();
     46 						$value_html.find( '.private' ).remove();
     47 						$value_html.find( '.dashicons-yes' ).replaceWith( '&#10004;' );
     48 						$value_html.find( '.dashicons-no-alt, .dashicons-warning' ).replaceWith( '&#10060;' );
     49 
     50 						// Format value
     51 						var the_value   = $.trim( $value_html.text() );
     52 						var value_array = the_value.split( ', ' );
     53 
     54 						if ( value_array.length > 1 ) {
     55 							// If value have a list of plugins ','.
     56 							// Split to add new line.
     57 							var temp_line ='';
     58 							$.each( value_array, function( key, line ) {
     59 								temp_line = temp_line + line + '\n';
     60 							});
     61 
     62 							the_value = temp_line;
     63 						}
     64 
     65 						report = report + '' + the_name + ': ' + the_value + '\n';
     66 					});
     67 				}
     68 			});
     69 
     70 			try {
     71 				$( '#debug-report' ).slideDown();
     72 				$( '#debug-report' ).find( 'textarea' ).val( '`' + report + '`' ).focus().select();
     73 				$( this ).fadeOut();
     74 				return false;
     75 			} catch ( e ) {
     76 				/* jshint devel: true */
     77 				console.log( e );
     78 			}
     79 
     80 			return false;
     81 		},
     82 
     83 		/**
     84 		 * Copy for report.
     85 		 *
     86 		 * @param {Object} evt Copy event.
     87 		 */
     88 		copyReport: function( evt ) {
     89 			$( '#debug-report' ).find( 'textarea' ).select();
     90 			var copytext=document.execCommand('copy');
     91 			if(copytext){
     92 				
     93 				$( document.body ).trigger( "aftercopy" );
     94 			}else{
     95 				$( document.body ).trigger( "aftercopyfailure" );
     96 			}
     97 			evt.preventDefault();
     98 		},
     99 
    100 		/**
    101 		 * Display a "Copied!" tip when success copying
    102 		 */
    103 		copySuccess: function() {
    104 			$("#copy-for-support").attr('title',ajax_dashboard_js.copytext) 
    105 			$("#copy-for-support").tooltip({ 
    106 				hide: {effect: "explode",delay: 250}
    107 			});
    108 			$("#copy-for-support").trigger('mouseenter');
    109 			setTimeout(function(){ 
    110 				
    111 				$("#copy-for-support").tooltip('destroy')
    112 				$("#copy-for-support").attr('title','');
    113 			}, 5000);
    114 		},
    115 
    116 		/**
    117 		 * Displays the copy error message when failure copying.
    118 		 */
    119 		copyFail: function() {
    120 			$( '.copy-error' ).removeClass( 'hidden' );
    121 			$( '#debug-report' ).find( 'textarea' ).focus().select();
    122 		},
    123 		buttonTigger: function(e){
    124 			if($(e.target).is(":checked")) {
    125 				$('.envato-liccence-button-tr').show();
    126 			}else{
    127 				$('.envato-liccence-button-tr').hide();
    128 			}
    129 		}
    130 	};
    131 
    132 	wcSystemStatus.init();
    133 
    134 	$( '#log-viewer-select' ).on( 'click', 'h2 a.page-title-action', function( evt ) {
    135 		evt.stopImmediatePropagation();
    136 		return window.confirm( woocommerce_admin_system_status.delete_log_confirmation );
    137 	});
    138 	if(typeof(envato_theme_systemerrorshow)!='undefined'){
    139         if(envato_theme_systemerrorshow.count>0){
    140             $('.nav-tab-wrapper .nav-tab-active').append('<span class="systemerrorshow_notification"><div class="systemerrorshow_notification_count">'+envato_theme_systemerrorshow.count+'</div></span>')
    141         }
    142     }
    143 });