PageSourceSearch

https://www.samaterials.es/js/inquirySubmit.js?v=1789002534

js samaterials.es collected 2026-10-02 20:45:41 UTC 9,926 bytes, 340 lines download raw bytes

1var invisibleCaptcha = false
2window.IS_RECAPTCHA = false
3var isLoadCaptcha = true,
4  isOneCaptcha = false
5
6var SAM_INQUIRY_FIELD_MAP = {
7  username: 'username',
8  email: 'email',
9  product: 'product',
10  phone: 'phone',
11  message: 'message',
12  robot: 'robot',
13}
14
15function clearSamInquiryFieldErrors() {
16  var $root = $('#samv1-inquiry-component')
17  if (!$root.length) return
18  $root.find('.form-item.is-error').removeClass('is-error')
19  $root.find('.field-error').text('')
20  $('#errorMessage').text('')
21}
22
23function showSamInquiryFieldError(valid) {
24  var $root = $('#samv1-inquiry-component')
25  if (!$root.length) {
26    $('#errorMessage').text(valid.message || '')
27    return
28  }
29
30  clearSamInquiryFieldErrors()
31  if (valid.isValid || !valid.message) return
32
33  var fieldKey = SAM_INQUIRY_FIELD_MAP[valid.errorKey] || valid.errorKey
34  var $item = fieldKey ? $root.find('.form-item[data-field="' + fieldKey + '"]') : $()
35
36  if ($item.length) {
37    $item.addClass('is-error')
38    $item.find('.field-error').first().text(valid.message)
39  } else {
40    $('#errorMessage').text(valid.message)
41  }
42}
43
44$(document).ready(function () {
45  var product_name = $('.oc-main-sam-page-banner-title').html()
46  $('#product').val(product_name)
47  // if (isMobile) {
48  //   // 6LcW59wpAAAAANk8TrXxzMZWQojRR7ZAHccgmn4z
49  //   // 隐形式人机
50  //   invisibleCaptcha = true
51  //   $('#recaptcha-label').hide()
52  //   $('#recaptcha-box').html(`<div id="recaptcha" class="g-recaptcha"
53  //           data-sitekey="6LcW59wpAAAAANk8TrXxzMZWQojRR7ZAHccgmn4z"
54  //           data-callback="submitted"
55  //           data-size="invisible"></div>`)
56  // } else {
57
58  // }
59  //复选框式人机
60  invisibleCaptcha = false
61  $.getScript('https://www.google.com/recaptcha/api.js?hl=es')
62  $('#recaptcha-box').html(
63    `<div class="g-recaptcha" data-sitekey="6Ld2EwcqAAAAAItHmoBmZ9idRngpibBggzvs-vqq"></div>`,
64  )
65
66
67  $('#samv1-inquiry-component').on('input change', 'input, textarea', function () {
68    var $item = $(this).closest('.form-item')
69    $item.removeClass('is-error')
70    $item.find('.field-error').text('')
71    $('#errorMessage').text('')
72  })
73
74
75
76  // 验证字段必传
77  $('#submitForm').on('click', function () {
78    //防止多次点击
79    if ($(this).hasClass('disable')) {
80      return false
81    }
82    let valid = validateForm([
83      {
84        key: 'username',
85        value: $('#name').val(),
86        message: TextPrompt.name,
87      },
88      {
89        key: 'email',
90        value: $('#email').val(),
91        message: TextPrompt.yourEmail,
92      },
93      {
94        key: 'product',
95        value: $('#product').val(),
96        message: TextPrompt.productName,
97      },
98      {
99        key: 'phone',
100        value: $('#phone').val(),
101        message: TextPrompt.phone,
102      },
103      {
104        key: 'message',
105        value: $('#comments').val(),
106        required: false,
107        message: TextPrompt.comment,
108      },
109    ])
110    showSamInquiryFieldError(valid)
111    if (!valid.isValid) {
112      return false
113    }
114    if (invisibleCaptcha) {
115      $('#submitForm').addClass('loding-icon')
116      $('#submitForm').addClass('disable')
117      loadRecaptcha().then(() => {
118        setTimeout(
119          () => {
120            $('#submitForm').removeClass('disable')
121            $('#submitForm').removeClass('loding-icon')
122          },
123          isLoadCaptcha ? 3000 : 600,
124        )
125      })
126    } else {
127      submitted()
128    }
129    return true
130  })
131})
132function submitted(token) {
133  var country = $('#country p').data('value')
134  // 邮箱
135  var trader = $('#trader').val()
136  let valid = validateForm([
137    {
138      key: 'username',
139      value: $('#name').val(),
140      message: TextPrompt.name,
141    },
142    {
143      key: 'email',
144      value: $('#email').val(),
145      message: TextPrompt.yourEmail,
146    },
147    {
148      key: 'product',
149      value: $('#product').val(),
150      message: TextPrompt.productName,
151    },
152    {
153      key: 'phone',
154      value: $('#phone').val(),
155      message: TextPrompt.phone,
156    },
157    {
158      key: 'message',
159      value: $('#comments').val(),
160      required: false,
161      message: TextPrompt.comment,
162    },
163    {
164      required: ENV.googleVerification, // 是否需要验证码
165      key: 'robot',
166      value: getGoogleSafeResponse(),
167      message: TextPrompt.checkCode,
168    },
169  ])
170  showSamInquiryFieldError(valid)
171  isLoadCaptcha = true
172  if (valid.isValid) {
173    $('#submitForm').addClass('loding-icon')
174    $('#submitForm').addClass('disable')
175    // 拼接请求参数
176    var postFormData = new FormData()
177    window.attachments.files.forEach((f, i) => {
178      postFormData.append('myFile[' + i + ']', f)
179    })
180    postFormData.append('website', 'sam_es')
181    postFormData.append('robotType', invisibleCaptcha ? 2 : 1)
182    postFormData.append('product', valid.values.product)
183    postFormData.append('email', valid.values.email)
184    postFormData.append('country', country)
185    postFormData.append('username', valid.values.username)
186    postFormData.append('message', valid.values.message)
187    postFormData.append('phone', valid.values.phone)
188    postFormData.append('traderemail', trader ? trader : '[email protected]')
189    postFormData.append('wouldlike', $('#checkbox').is(':checked'))
190    postFormData.append('robot', valid.values.robot)
191    postFormData.append('tracking', window.location.href)
192    postFormData.append('referrer', document.referrer)
193    // 发送请求
194    $.ajax({
195      url: Apis.Inquiry,
196      type: 'post',
197      processData: false,
198      contentType: false,
199      data: postFormData,
200      success: function (res) {
201        $('#submitForm').removeClass('disable')
202        $('#submitForm').removeClass('loding-icon')
203        if (res.code == '200') {
204          window.location.href = res.msg
205        } else {
206          $('#errorMessage').text(res.msg ? res.msg : TextPrompt.fail)
207        }
208      },
209      error() {
210        $('#submitForm').removeClass('loding-icon')
211        $('#submitForm').removeClass('disable')
212        $('#errorMessage').text(TextPrompt.fail)
213      },
214    })
215  }
216}
217//加载人机验证
218function loadRecaptcha() {
219  return new Promise((req, rej) => {
220    function exect() {
221      grecaptcha.ready(function () {
222        if (isLoadCaptcha && isOneCaptcha) {
223          isLoadCaptcha = false
224          grecaptcha.reset()
225        }
226        isOneCaptcha = true
227        grecaptcha
228          .execute()
229          .then((token) => {
230            console.log('reCAPTCHA 准备好了', token)
231            req(token)
232          })
233          .catch((err) => console.log(err, 'yc'))
234      })
235    }
236    if (window.IS_RECAPTCHA) {
237      exect()
238    } else {
239      $.getScript('https://www.google.com/recaptcha/api.js?hl=es')
240        .done(function () {
241          window.IS_RECAPTCHA = true
242          exect()
243        })
244        .fail(function () {
245          rej()
246          $('#errorMessage').text(TextPrompt.recaptchaErr)
247        })
248    }
249  })
250}
251function changeCheck(e) {
252  // if (e.checked === false) {
253  //     $('#submitForm').addClass("disable");
254  // } else {
255  //     $('#submitForm').removeClass("disable");
256  // }
257}
258
259// 全局附件存储对象
260window.attachments = {
261  files: [],
262  maxSize: 2 * 1024 * 1024, // 2MB
263  errors: [],
264}
265
266function handleFileChange(event) {
267  const input = event.target
268  window.attachments.errors = [] // 清空错误信息
269  // 验证并存储文件
270  const validFiles = Array.from(input.files).filter((file) => {
271    if (file.size > window.attachments.maxSize) {
272      window.attachments.errors.push({
273        name: file.name,
274        size: file.size,
275      })
276      return false
277    }
278    return true
279  })
280  // 合并并更新全局文件列表
281  window.attachments.files = [...window.attachments.files, ...validFiles]
282
283  // 生成文件列表HTML
284  renderFileList()
285
286  // 显示错误信息
287  if (window.attachments.errors.length > 0) {
288    showSizeError()
289  }
290
291  // 重置input值以允许重新选择已拒绝的文件
292  input.value = ''
293}
294
295function renderFileList() {
296  var resourceUrl = (typeof TextPrompt !== 'undefined' && TextPrompt.resourceUrl) || ''
297  var docIcon = resourceUrl + 'css/img/sam-inquiry-doc.svg'
298  var successIcon = resourceUrl + 'css/img/sam-inquiry-success.svg'
299  let _html = ''
300  window.attachments.files.forEach((file, index) => {
301    _html += `
302        <div class="upload-file-child" data-index="${index}">
303          <div class="upload-file-meta">
304            <img class="upload-file-type-icon" src="${docIcon}" width="14" height="14" alt="">
305            <div class="upload-name text-ellipsis-1">${file.name}</div>
306          </div>
307          <div class="upload-file-actions">
308            <img class="upload-status-icon is-success" src="${successIcon}" width="14" height="14" alt="">
309            <div class="close-btn" onclick="handleRemoveFile(${index})">
310              <div class="close-icon"></div>
311            </div>
312          </div>
313        </div>`
314  })
315  $('.upload-files').html(_html)
316}
317
318function handleRemoveFile(index) {
319  // 从全局列表中移除
320  window.attachments.files = [
321    ...window.attachments.files.slice(0, index),
322    ...window.attachments.files.slice(index + 1),
323  ]
324  renderFileList()
325}
326
327function showSizeError() {
328  const errorList = window.attachments.errors
329    .map((f) => `${f.name} (${formatFileSize(f.size)})`)
330    .join(', ')
331
332  alert(`The following files exceed the 2 MB limit\n${errorList}`)
333}
334
335function formatFileSize(bytes) {
336  if (bytes === 0) return '0 Bytes'
337  const units = ['Bytes', 'KB', 'MB', 'GB']
338  const exp = Math.floor(Math.log(bytes) / Math.log(1024))
339  return (bytes / Math.pow(1024, exp)).toFixed(2) + ' ' + units[exp]
340}

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.