1/* A5 Share For Invitation - Frontend JS */ 2/* ç¬ç« JS æä»¶ï¼é¿å 被ç¼åæä»¶æä¸»é¢ä¼åç ´å */ 3(function($) { 4 'use strict'; 5 6 // çå¾ DOM å è½½ 7 $(function() { 8 9 // ========== å·¥å ·å½æ°ï¼è·åç¿»è¯ææ¬ï¼å åºï¼ ========== 10 function t(key) { 11 if (window.a5_sf_data && window.a5_sf_data.i18n && window.a5_sf_data.i18n[key]) { 12 return window.a5_sf_data.i18n[key]; 13 } 14 // å åºä¸æå¼ 15 var fallback = { 16 'gen_btn_default': 'ð çæé¾æ¥', 17 'gen_btn_loading': 'çæä¸...', 18 'copied': 'â å·²å¤å¶', 19 'submit_default': 'ð æäº¤å®¡æ ¸', 20 'submit_loading': 'æäº¤ä¸...', 21 'err_network': 'ç½ç»é误ï¼è¯·éè¯', 22 'err_no_identifier': '请å å¡«åæ è¯', 23 'err_no_ref': '请å çæä¸å±é¾æ¥', 24 'hint_email': 'é请ç å°åéå°æ¤é®ç®±', 25 'hint_wechat': '请填åçå®å¾®ä¿¡å·ï¼ç¨äºå®¢ææ ¸éª', 26 'hint_qq': '请填åçå®QQå·ï¼ç¨äºå®¢ææ ¸éª', 27 'ph_email': '[email protected]', 28 'ph_wechat': 'å¦ wxid_xxx æ 微信å·', 29 'ph_qq': 'å¦ 123456789' 30 }; 31 return fallback[key] || key; 32 } 33 34 function getAjaxUrl() { 35 if (window.a5_sf_data && window.a5_sf_data.ajaxurl) return window.a5_sf_data.ajaxurl; 36 if (window.ajaxurl) return window.ajaxurl; 37 return '/wp-admin/admin-ajax.php'; 38 } 39 40 function getNonce() { 41 if (window.a5_sf_data && window.a5_sf_data.nonce) return window.a5_sf_data.nonce; 42 return ''; 43 } 44 45 // ========== 忢æ è¯ç±»åæ¶æ´æ°æç¤º ========== 46 $(document).on('change', 'input[name="identifier_type"]', function() { 47 var type = $(this).val(); 48 $('#a5_identifier_hint').text(t('hint_' + type)); 49 $('#a5_identifier').attr('placeholder', t('ph_' + type)); 50 }); 51 52 // ========== çæé¾æ¥ ========== 53 $(document).on('click', '#a5_gen_btn', function(e) { 54 e.preventDefault(); 55 var $btn = $(this); 56 var identifier = $('#a5_identifier').val().trim(); 57 var type = $('input[name="identifier_type"]:checked').val(); 58 59 if (!identifier) { 60 alert(t('err_no_identifier')); 61 $('#a5_identifier').focus(); 62 return; 63 } 64 65 $btn.text(t('gen_btn_loading')).prop('disabled', true); 66 67 $.ajax({ 68 url: getAjaxUrl(), 69 type: 'POST', 70 dataType: 'json', 71 data: { 72 action: 'a5_gen_share_link', 73 nonce: getNonce(), 74 identifier: identifier, 75 type: type 76 }, 77 timeout: 15000 78 }).done(function(resp) { 79 $btn.text(t('gen_btn_default')).prop('disabled', false); 80 if (resp && resp.success) { 81 $('#a5_share_url').val(resp.data.share_url).prop('readonly', false); 82 $('#a5_ref_code').text(resp.data.ref_code); 83 $('#a5_link_box').slideDown(300); 84 // 忥å°è¡¨å hidden åæ®µ 85 $('#a5_form_identifier').val(identifier); 86 $('#a5_form_type').val(type); 87 $('#a5_form_ref_code').val(resp.data.ref_code); 88 // æ»å¨å°é¾æ¥åº 89 $('html, body').animate({ 90 scrollTop: $('#a5_link_box').offset().top - 100 91 }, 500); 92 } else { 93 var msg = (resp && resp.data && resp.data.message) ? resp.data.message : 'çæå¤±è´¥'; 94 alert(msg); 95 } 96 }).fail(function(xhr, status) { 97 $btn.text(t('gen_btn_default')).prop('disabled', false); 98 console.error('A5 SF Generate Error:', status, xhr.responseText); 99 alert(t('err_network') + '\n\n' + (xhr.responseText ? xhr.responseText.substring(0, 200) : '')); 100 }); 101 }); 102 103 // ========== å¤å¶é¾æ¥ ========== 104 $(document).on('click', '#a5_copy_btn', function(e) { 105 e.preventDefault(); 106 var input = document.getElementById('a5_share_url'); 107 if (!input) return; 108 input.select(); 109 input.setSelectionRange(0, 99999); 110 111 var $btn = $(this); 112 var orig = $btn.text(); 113 114 // ä¼å ä½¿ç¨ Clipboard API 115 if (navigator.clipboard && navigator.clipboard.writeText) { 116 navigator.clipboard.writeText(input.value).then(function() { 117 $btn.text(t('copied')); 118 setTimeout(function() { $btn.text(orig); }, 2000); 119 }).catch(function() { 120 fallbackCopy(input, $btn, orig); 121 }); 122 } else { 123 fallbackCopy(input, $btn, orig); 124 } 125 }); 126 127 function fallbackCopy(input, $btn, orig) { 128 try { 129 document.execCommand('copy'); 130 $btn.text(t('copied')); 131 setTimeout(function() { $btn.text(orig); }, 2000); 132 } catch (err) { 133 alert('请æå¨å¤å¶ï¼' + input.value); 134 } 135 } 136 137 // ========== æäº¤è¡¨å ========== 138 $(document).on('submit', '#a5_submit_form', function(e) { 139 e.preventDefault(); 140 if (!$('#a5_form_ref_code').val()) { 141 alert(t('err_no_ref')); 142 $('html, body').animate({ 143 scrollTop: $('#a5_identifier').offset().top - 100 144 }, 500); 145 return; 146 } 147 148 var $btn = $('.a5-sf-btn-submit'); 149 $btn.text(t('submit_loading')).prop('disabled', true); 150 151 var formData = $(this).serialize(); 152 // ç¡®ä¿å å« action å nonce 153 if (formData.indexOf('action=') === -1) { 154 formData += '&action=a5_submit_share'; 155 } 156 if (formData.indexOf('nonce=') === -1) { 157 formData += '&nonce=' + getNonce(); 158 } 159 160 $.ajax({
161 url: getAjaxUrl(), 162 type: 'POST', 163 dataType: 'json', 164 data: formData, 165 timeout: 20000 166 }).done(function(resp) { 167 $btn.text(t('submit_default')).prop('disabled', false); 168 var $msg = $('#a5_submit_msg'); 169 $msg.show().removeClass('a5-sf-msg-success a5-sf-msg-error'); 170 171 if (resp && resp.success) { 172 $msg.addClass('a5-sf-msg-success').html( 173 'â ' + resp.data.message + '<br><br>' + 174 'ð 请ç«å³æ«ç å 客æå¾®ä¿¡ï¼åéï¼<br>' + 175 '1. ä½ çæ è¯ï¼é®ç®±/微信/QQï¼<br>' + 176 '2. åäº«é¡µé¢æªå¾<br><br>' + 177 '客æå°å¨ 30 åéå å®¡æ ¸å¹¶åé请ç å°ä½ çé®ç®±ã' 178 ); 179 $('#a5_submit_form')[0].reset(); 180 $('#a5_form_identifier, #a5_form_type, #a5_form_ref_code').val(''); 181 $('#a5_link_box').slideUp(300); 182 } else { 183 $msg.addClass('a5-sf-msg-error').text( 184 'â ' + ((resp && resp.data && resp.data.message) ? resp.data.message : 'æäº¤å¤±è´¥') 185 ); 186 } 187 $('html, body').animate({ 188 scrollTop: $msg.offset().top - 100 189 }, 500); 190 }).fail(function(xhr, status) { 191 $btn.text(t('submit_default')).prop('disabled', false); 192 console.error('A5 SF Submit Error:', status, xhr.responseText); 193 var $msg = $('#a5_submit_msg'); 194 $msg.show().removeClass('a5-sf-msg-success').addClass('a5-sf-msg-error').text( 195 'â ' + t('err_network') + '\n\n' + (xhr.responseText ? xhr.responseText.substring(0, 200) : '') 196 ); 197 }); 198 }); 199 200 }); 201})(jQuery);
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.