1(function (window) { 2 3 if (!!window.JCCatalogProductSubscribe) 4 return; 5 6 var subscribeButton = function (params) { 7 subscribeButton.superclass.constructor.apply(this, arguments); 8 this.nameNode = BX.create('span', { 9 props: { id: this.id }, 10 style: typeof (params.style) === 'object' ? params.style : {}, 11 text: params.text 12 }); 13 this.buttonNode = BX.create('a', { 14 attrs: { className: params.className }, 15 children: [this.nameNode], 16 events: this.contextEvents 17 }); 18 if (BX.browser.IsIE()) { 19 this.buttonNode.setAttribute("hideFocus", "hidefocus"); 20 } 21 }; 22 BX.extend(subscribeButton, BX.PopupWindowButton); 23 24 window.JCCatalogProductSubscribe = function (params) { 25 this.buttonId = params.buttonId; 26 this.buttonClass = params.buttonClass; 27 this.jsObject = params.jsObject; 28 this.ajaxUrl = '/bitrix/components/bitrix/catalog.product.subscribe/ajax.php'; 29 this.alreadySubscribed = params.alreadySubscribed; 30 this.listIdAlreadySubscribed = params.listIdAlreadySubscribed; 31 this.urlListSubscriptions = params.urlListSubscriptions; 32 this.listOldItemId = {}; 33 this.landingId = params.landingId; 34 35 this.elemButtonSubscribe = null; 36 this.elemPopupWin = null; 37 this.defaultButtonClass = 'bx-catalog-subscribe-button'; 38 39 this.buttonMainColorClass = params.buttonMainColorClass; 40 41 this._elemButtonSubscribeClickHandler = BX.delegate(this.subscribe, this); 42 this._elemHiddenClickHandler = BX.delegate(this.checkSubscribe, this); 43 44 BX.ready(BX.delegate(this.init, this)); 45 }; 46 47 window.JCCatalogProductSubscribe.prototype.init = function () { 48 if (!!this.buttonId) { 49 this.elemButtonSubscribe = BX(this.buttonId); 50 this.elemHiddenSubscribe = BX(this.buttonId + '_hidden'); 51 } 52 53 if (!!this.elemButtonSubscribe) { 54 BX.bind(this.elemButtonSubscribe, 'click', this._elemButtonSubscribeClickHandler); 55 } 56 57 if (!!this.elemHiddenSubscribe) { 58 BX.bind(this.elemHiddenSubscribe, 'click', this._elemHiddenClickHandler); 59 } 60 61 this.setButton(this.alreadySubscribed); 62 this.setIdAlreadySubscribed(this.listIdAlreadySubscribed); 63 }; 64 65 window.JCCatalogProductSubscribe.prototype.checkSubscribe = function () { 66 if (!this.elemHiddenSubscribe || !this.elemButtonSubscribe) return; 67 68 if (this.listOldItemId.hasOwnProperty(this.elemButtonSubscribe.dataset.item)) { 69 this.setButton(true); 70 } 71 else { 72 BX.ajax({ 73 method: 'POST', 74 dataType: 'json', 75 url: this.ajaxUrl, 76 data: { 77 sessid: BX.bitrix_sessid(), 78 checkSubscribe: 'Y', 79 itemId: this.elemButtonSubscribe.dataset.item 80 }, 81 onsuccess: BX.delegate(function (result) { 82 if (result.subscribe) { 83 this.setButton(true); 84 this.listOldItemId[this.elemButtonSubscribe.dataset.item] = true; 85 } 86 else { 87 this.setButton(false); 88 } 89 }, this) 90 }); 91 } 92 }; 93 94 window.JCCatalogProductSubscribe.prototype.subscribe = function () { 95 this.elemButtonSubscribe = BX.proxy_context; 96 if (!this.elemButtonSubscribe) return false; 97 98 BX.ajax({ 99 method: 'POST', 100 dataType: 'json', 101 url: this.ajaxUrl, 102 data: { 103 sessid: BX.bitrix_sessid(), 104 subscribe: 'Y', 105 itemId: this.elemButtonSubscribe.dataset.item, 106 siteId: BX.message('SITE_ID'), 107 landingId: this.landingId 108 }, 109 onsuccess: BX.delegate(function (result) { 110 if (result.success) { 111 this.createSuccessPopup(result); 112 this.setButton(true); 113 this.listOldItemId[this.elemButtonSubscribe.dataset.item] = true; 114 } 115 else if (result.contactFormSubmit) { 116 this.initPopupWindow(); 117 this.elemPopupWin.setTitleBar(BX.message('CPST_SUBSCRIBE_POPUP_TITLE')); 118 var form = this.createContentForPopup(result); 119 this.elemPopupWin.setContent(form); 120 this.elemPopupWin.setButtons([ 121 new subscribeButton({ 122 text: BX.message('CPST_SUBSCRIBE_BUTTON_NAME'), 123 className: 'main-color button-def ' + this.buttonMainColorClass, 124 events: { 125 click: BX.delegate(function () { 126 if (!this.validateContactField(result.contactTypeData)) { 127 return false; 128 } 129 BX.ajax.submitAjax(form, { 130 method: 'POST', 131 url: this.ajaxUrl, 132 processData: true, 133 onsuccess: BX.delegate(function (resultForm) { 134 resultForm = BX.parseJSON(resultForm, {}); 135 if (resultForm.success) { 136 this.createSuccessPopup(resultForm); 137 this.setButton(true); 138 this.listOldItemId[this.elemButtonSubscribe.dataset.item] = true; 139 } 140 else if (resultForm.error) { 141 if (resultForm.hasOwnProperty('setButton')) { 142 this.listOldItemId[this.elemButtonSubscribe.dataset.item] = true; 143 this.setButton(true); 144 } 145 var errorMessage = resultForm.message; 146 if (resultForm.hasOwnProperty('typeName')) { 147 errorMessage = resultForm.message.replace('USER_CONTACT', 148 resultForm.typeName); 149 } 150 BX('bx-catalog-subscribe-form-notify').style.color = 'red'; 151 BX('bx-catalog-subscribe-form-notify').innerHTML = errorMessage; 152 } 153 }, this) 154 }); 155 }, this) 156 } 157 }) 158 /*new subscribeButton({ 159 text : BX.message('CPST_SUBSCRIBE_BUTTON_CLOSE'),
160 className : 'btn-transpatent', 161 events : { 162 click : BX.delegate(function() { 163 this.elemPopupWin.destroy(); 164 }, this) 165 } 166 })*/ 167 ]); 168 this.elemPopupWin.show(); 169 } 170 else if (result.error) { 171 if (result.hasOwnProperty('setButton')) { 172 this.listOldItemId[this.elemButtonSubscribe.dataset.item] = true; 173 this.setButton(true); 174 } 175 this.showWindowWithAnswer({ status: 'error', message: result.message }); 176 } 177 }, this) 178 }); 179 }; 180 181 window.JCCatalogProductSubscribe.prototype.validateContactField = function (contactTypeData) { 182 var inputFields = BX.findChildren(BX('bx-catalog-subscribe-form'), 183 { 'tag': 'input', 'attribute': { id: 'userContact' } }, true); 184 if (!inputFields.length || typeof contactTypeData !== 'object') { 185 BX('bx-catalog-subscribe-form-notify').style.color = 'red'; 186 BX('bx-catalog-subscribe-form-notify').innerHTML = BX.message('CPST_SUBSCRIBE_VALIDATE_UNKNOW_ERROR'); 187 return false; 188 } 189 190 var contactTypeId, contactValue, useContact, errors = [], useContactErrors = []; 191 for (var k = 0; k < inputFields.length; k++) { 192 contactTypeId = inputFields[k].getAttribute('data-id'); 193 contactValue = inputFields[k].value; 194 useContact = BX('bx-contact-use-' + contactTypeId); 195 if (useContact && useContact.value == 'N') { 196 useContactErrors.push(true); 197 continue; 198 } 199 if (!contactValue.length) { 200 errors.push(BX.message('CPST_SUBSCRIBE_VALIDATE_ERROR_EMPTY_FIELD').replace( 201 '#FIELD#', contactTypeData[contactTypeId].contactLable)); 202 } 203 } 204 205 if (inputFields.length == useContactErrors.length) { 206 BX('bx-catalog-subscribe-form-notify').style.color = 'red'; 207 BX('bx-catalog-subscribe-form-notify').innerHTML = BX.message('CPST_SUBSCRIBE_VALIDATE_ERROR'); 208 return false; 209 } 210 211 if (errors.length) { 212 BX('bx-catalog-subscribe-form-notify').style.color = 'red'; 213 for (var i = 0; i < errors.length; i++) { 214 BX('bx-catalog-subscribe-form-notify').innerHTML = errors[i]; 215 } 216 return false; 217 } 218 219 return true; 220 }; 221 222 window.JCCatalogProductSubscribe.prototype.reloadCaptcha = function () { 223 BX.ajax.get(this.ajaxUrl + '?reloadCaptcha=Y', '', function (captchaCode) { 224 BX('captcha_sid').value = captchaCode; 225 BX('captcha_img').src = '/bitrix/tools/captcha.php?captcha_sid=' + captchaCode + ''; 226 }); 227 }; 228 229 window.JCCatalogProductSubscribe.prototype.createContentForPopup = function (responseData) { 230 if (!responseData.hasOwnProperty('contactTypeData')) { 231 return null; 232 } 233 234 var contactTypeData = responseData.contactTypeData, contactCount = Object.keys(contactTypeData).length, 235 styleInputForm = '', manyContact = 'N', content = document.createDocumentFragment(); 236 237 if (contactCount > 1) { 238 manyContact = 'Y'; 239 styleInputForm = 'display:none;'; 240 content.appendChild(BX.create('p', { 241 text: BX.message('CPST_SUBSCRIBE_MANY_CONTACT_NOTIFY') 242 })); 243 } 244 245 content.appendChild(BX.create('p', { 246 props: { id: 'bx-catalog-subscribe-form-notify' } 247 })); 248 249 for (var k in contactTypeData) { 250 if (contactCount > 1) { 251 content.appendChild(BX.create('div', { 252 props: { 253 className: 'bx-catalog-subscribe-form-container' 254 }, 255 children: [ 256 BX.create('div', { 257 props: { 258 className: 'checkbox' 259 }, 260 children: [ 261 BX.create('lable', { 262 props: { 263 className: 'bx-filter-param-label' 264 }, 265 attrs: { 266 onclick: this.jsObject + '.selectContactType(' + k + ', event);' 267 }, 268 children: [ 269 BX.create('input', { 270 props: { 271 type: 'hidden', 272 id: 'bx-contact-use-' + k, 273 name: 'contact[' + k + '][use]', 274 value: 'N' 275 } 276 }), 277 BX.create('input', { 278 props: { 279 id: 'bx-contact-checkbox-' + k, 280 type: 'checkbox' 281 } 282 }), 283 BX.create('span', { 284 props: { 285 className: 'bx-filter-param-text' 286 }, 287 text: contactTypeData[k].contactLable 288 }) 289 ] 290 }) 291 ] 292 }) 293 ] 294 })); 295 } 296 content.appendChild(BX.create('div', { 297 props: { 298 id: 'bx-catalog-subscribe-form-container-' + k, 299 className: 'bx-catalog-subscribe-form-container', 300 style: styleInputForm 301 }, 302 children: [ 303 BX.create('div', { 304 props: { 305 className: 'bx-catalog-subscribe-form-container-input input-simple inp-small' 306 }, 307 children: [ 308 BX.create('DIV', { 309 props: 310 { 311 className: "bg" 312 }, 313 }), 314 BX.create('SPAN', { 315 props: 316 { 317 className: "desc" 318 }, 319 html: BX.message('CPST_SUBSCRIBE_LABLE_CONTACT_INPUT').replace(
320 '#CONTACT#', contactTypeData[k].contactLable) 321 }), 322 BX.create('input', { 323 props: { 324 id: 'userContact', 325 className: 'focus-anim bord-1 b-ra inp-require', 326 type: 'text', 327 name: 'contact[' + k + '][user]' 328 }, 329 attrs: { 'data-id': k } 330 }) 331 ] 332 }) 333 ] 334 })); 335 } 336 if (responseData.hasOwnProperty('captchaCode')) { 337 content.appendChild(BX.create('div', { 338 props: { 339 className: 'bx-catalog-subscribe-form-container' 340 }, 341 children: [ 342 BX.create('span', { props: { className: 'bx-catalog-subscribe-form-star-required' }, text: '*' }), 343 BX.message('CPST_ENTER_WORD_PICTURE'), 344 BX.create('div', { 345 props: { className: 'bx-captcha' }, 346 children: [ 347 BX.create('input', { 348 props: { 349 type: 'hidden', 350 id: 'captcha_sid', 351 name: 'captcha_sid', 352 value: responseData.captchaCode 353 } 354 }), 355 BX.create('img', { 356 props: { 357 id: 'captcha_img', 358 src: '/bitrix/tools/captcha.php?captcha_sid=' + responseData.captchaCode + '' 359 }, 360 attrs: { 361 width: '180', 362 height: '40', 363 alt: 'captcha', 364 onclick: this.jsObject + '.reloadCaptcha();' 365 } 366 }) 367 ] 368 }), 369 BX.create('div', { 370 props: { className: 'bx-catalog-subscribe-form-container-input' }, 371 children: [ 372 BX.create('input', { 373 props: { 374 id: 'captcha_word', 375 className: '', 376 type: 'text', 377 name: 'captcha_word' 378 }, 379 attrs: { maxlength: '50' } 380 }) 381 ] 382 }) 383 ] 384 })); 385 } 386 var form = BX.create('form', { 387 props: { 388 id: 'bx-catalog-subscribe-form' 389 }, 390 children: [ 391 BX.create('input', { 392 props: { 393 type: 'hidden', 394 name: 'manyContact', 395 value: manyContact 396 } 397 }), 398 BX.create('input', { 399 props: { 400 type: 'hidden', 401 name: 'sessid', 402 value: BX.bitrix_sessid() 403 } 404 }), 405 BX.create('input', { 406 props: { 407 type: 'hidden', 408 name: 'itemId', 409 value: this.elemButtonSubscribe.dataset.item 410 } 411 }), 412 BX.create('input', { 413 props: { 414 type: 'hidden', 415 name: 'landingId', 416 value: this.landingId 417 } 418 }), 419 BX.create('input', { 420 props: { 421 type: 'hidden', 422 name: 'siteId', 423 value: BX.message('SITE_ID') 424 } 425 }), 426 BX.create('input', { 427 props: { 428 type: 'hidden', 429 name: 'contactFormSubmit', 430 value: 'Y' 431 } 432 }) 433 ] 434 }); 435 436 form.appendChild(content); 437 438 return form; 439 }; 440 441 window.JCCatalogProductSubscribe.prototype.selectContactType = function (contactTypeId, event) { 442 var contactInput = BX('bx-catalog-subscribe-form-container-' + contactTypeId), visibility = '', 443 checkboxInput = BX('bx-contact-checkbox-' + contactTypeId); 444 if (!contactInput) { 445 return false; 446 } 447 448 if (checkboxInput != event.target) { 449 if (checkboxInput.checked) { 450 checkboxInput.checked = false; 451 } 452 else { 453 checkboxInput.checked = true; 454 } 455 } 456 457 if (contactInput.currentStyle) { 458 visibility = contactInput.currentStyle.display; 459 } 460 else if (window.getComputedStyle) { 461 var computedStyle = window.getComputedStyle(contactInput, null); 462 visibility = computedStyle.getPropertyValue('display'); 463 } 464 465 if (visibility === 'none') { 466 BX('bx-contact-use-' + contactTypeId).value = 'Y'; 467 BX.style(contactInput, 'display', ''); 468 } 469 else { 470 BX('bx-contact-use-' + contactTypeId).value = 'N'; 471 BX.style(contactInput, 'display', 'none'); 472 } 473 }; 474 475 window.JCCatalogProductSubscribe.prototype.createSuccessPopup = function (result) { 476 this.initPopupWindow(); 477 this.elemPopupWin.setTitleBar(BX.message('CPST_SUBSCRIBE_POPUP_TITLE')); 478 var content = BX.create('div', { 479 props: { 480 className: 'bx-catalog-popup-content text-content center' 481 }, 482 children: [ 483 BX.create('p', { 484 props: { 485 className: 'bx-catalog-popup-message' 486 }, 487 text: result.message 488 }) 489 ] 490 }); 491 this.elemPopupWin.setContent(content); 492 /*this.elemPopupWin.setButtons([ 493 new subscribeButton({ 494 text : BX.message('CPST_SUBSCRIBE_BUTTON_CLOSE'),
495 className : 'btn-transpatent', 496 events : { 497 click : BX.delegate(function() { 498 this.elemPopupWin.destroy(); 499 }, this) 500 } 501 }) 502 ]);*/ 503 this.elemPopupWin.show(); 504 }; 505 506 window.JCCatalogProductSubscribe.prototype.initPopupWindow = function () { 507 this.elemPopupWin = BX.PopupWindowManager.create('CatalogSubscribe_' + this.buttonId, null, { 508 autoHide: false, 509 offsetLeft: 0, 510 offsetTop: 0, 511 overlay: true, 512 closeByEsc: true, 513 titleBar: true, 514 closeIcon: true, 515 contentColor: 'white' 516 }); 517 }; 518 519 window.JCCatalogProductSubscribe.prototype.setButton = function (statusSubscription) { 520 this.alreadySubscribed = Boolean(statusSubscription); 521 522 523 if (this.alreadySubscribed) { 524 this.elemButtonSubscribe.className = this.buttonClass + ' ' + this.defaultButtonClass + ' disabled'; 525 this.elemButtonSubscribe.innerHTML = '<span>' + BX.message('CPST_TITLE_ALREADY_SUBSCRIBED') + '</span>'; 526 BX.unbind(this.elemButtonSubscribe, 'click', this._elemButtonSubscribeClickHandler); 527 } 528 else { 529 this.elemButtonSubscribe.className = this.buttonClass + ' ' + this.defaultButtonClass; 530 this.elemButtonSubscribe.innerHTML = '<span>' + BX.message('CPST_SUBSCRIBE_BUTTON_NAME') + '</span>'; 531 BX.bind(this.elemButtonSubscribe, 'click', this._elemButtonSubscribeClickHandler); 532 } 533 }; 534 535 window.JCCatalogProductSubscribe.prototype.setIdAlreadySubscribed = function (listIdAlreadySubscribed) { 536 if (BX.type.isPlainObject(listIdAlreadySubscribed)) { 537 this.listOldItemId = listIdAlreadySubscribed; 538 } 539 }; 540 541 window.JCCatalogProductSubscribe.prototype.showWindowWithAnswer = function (answer) { 542 answer = answer || {}; 543 if (!answer.message) { 544 if (answer.status == 'success') { 545 answer.message = BX.message('CPST_STATUS_SUCCESS'); 546 } else { 547 answer.message = BX.message('CPST_STATUS_ERROR'); 548 } 549 } 550 var messageBox = BX.create('div', { 551 props: { 552 className: 'bx-catalog-subscribe-alert' 553 }, 554 children: [ 555 BX.create('span', { 556 props: { 557 className: 'bx-catalog-subscribe-aligner' 558 } 559 }), 560 BX.create('span', { 561 props: { 562 className: 'bx-catalog-subscribe-alert-text' 563 }, 564 text: answer.message 565 }), 566 BX.create('div', { 567 props: { 568 className: 'bx-catalog-subscribe-alert-footer' 569 } 570 }) 571 ] 572 }); 573 var currentPopup = BX.PopupWindowManager.getCurrentPopup(); 574 if (currentPopup) { 575 currentPopup.destroy(); 576 } 577 var idTimeout = setTimeout(function () { 578 var w = BX.PopupWindowManager.getCurrentPopup(); 579 if (!w || w.uniquePopupId != 'bx-catalog-subscribe-status-action') { 580 return; 581 } 582 w.close(); 583 w.destroy(); 584 }, 3500); 585 var popupConfirm = BX.PopupWindowManager.create('bx-catalog-subscribe-status-action', null, {
586 content: messageBox, 587 onPopupClose: function () { 588 this.destroy(); 589 clearTimeout(idTimeout); 590 }, 591 autoHide: true, 592 zIndex: 2000, 593 className: 'bx-catalog-subscribe-alert-popup' 594 }); 595 popupConfirm.show(); 596 BX('bx-catalog-subscribe-status-action').onmouseover = function (e) { 597 clearTimeout(idTimeout); 598 }; 599 BX('bx-catalog-subscribe-status-action').onmouseout = function (e) { 600 idTimeout = setTimeout(function () { 601 var w = BX.PopupWindowManager.getCurrentPopup(); 602 if (!w || w.uniquePopupId != 'bx-catalog-subscribe-status-action') { 603 return; 604 } 605 w.close(); 606 w.destroy(); 607 }, 3500); 608 }; 609 }; 610 611})(window);
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.