1;(function(){ 2 window["UC"] = (window["UC"] || {}); 3 if (!!window["FCForm"]) 4 return; 5 6 window.FCForm = function(arParams) 7 { 8 this.url = ''; 9 this.lhe = ''; 10 this.entitiesId = {}; 11 this.form = BX(arParams['formId']); 12 this.handler = window.LHEPostForm.getHandler(arParams['editorId']); 13 this.editorName = arParams['editorName']; 14 this.editorId = arParams['editorId']; 15 this.windowEvents = { 16 OnUCUnlinkForm : BX.delegate(function(entityId) { 17 if (!!entityId && !!this.entitiesId[entityId]) { 18 var res = {}, empty = true; 19 for (var ii in this.entitiesId) 20 { 21 if (this.entitiesId.hasOwnProperty(ii) && ii != entityId) 22 { 23 empty = false; 24 res[ii] = this.entitiesId[ii]; 25 } 26 } 27 this.entitiesId = res; 28 if (empty && !!this.windowEvents) 29 { 30 for (ii in this.windowEvents) 31 { 32 if (this.windowEvents.hasOwnProperty(ii) && ii) 33 BX.removeCustomEvent(window, ii, this.windowEvents[ii]); 34 } 35 this.windowEventsSet = false; 36 } 37 } 38 }, this), 39 OnUCQuote : BX.delegate(function(entityId, author, quotedText) { 40 if ( 41 !this.entitiesId[entityId] 42 || !this._checkTextSafety([entityId, 0]) 43 ) 44 { 45 return; 46 } 47 48 this.show([entityId, 0]); 49 var attempts = 0; 50 var quoteHandler = function() { 51 attempts++; 52 if (attempts > 10) 53 { 54 return; 55 } 56 if (!this.handler.oEditor || !this.handler.oEditor.action) 57 { 58 return setTimeout(quoteHandler, 10); 59 } 60 if (!this.handler.oEditor.toolbar.controls.Quote) 61 { 62 return; 63 } 64 if (!author && !quotedText) 65 { 66 return this.handler.oEditor.action.Exec('quote'); 67 } 68 69 var haveWrittenText = ''; 70 if (author) 71 { 72 haveWrittenText = author.gender ? BX.message("MPL_HAVE_WRITTEN_"+author.gender) : BX.message("MPL_HAVE_WRITTEN"); 73 if (this.handler.oEditor.GetViewMode() === 'wysiwyg') // BB Codes 74 { 75 if (author.id > 0) 76 { 77 author = '<span id="' + this.handler.oEditor.SetBxTag(false, {tag: "postuser", userId: author.id, userName: author.name}) + 78 '" class="bxhtmled-metion">' + author.name.replace(/</gi, '<').replace(/>/gi, '>') + '</span>'; 79 } 80 else 81 { 82 author = '<span>' + author.name.replace(/</gi, '<').replace(/>/gi, '>') + '</span>'; 83 } 84 haveWrittenText = (author + haveWrittenText + '<br/>'); 85 } 86 else if (this.handler.oEditor.bbCode) 87 { 88 if (author.id > 0) 89 { 90 author = "[USER=" + author.id + "]" + author.name + "[/USER]"; 91 } 92 else 93 { 94 author = author.name; 95 } 96 haveWrittenText = (author !== '' ? (author + haveWrittenText + '\n') : ''); 97 } 98 } 99 100 if (this.handler.oEditor.action.actions.quote.setExternalSelectionFromRange) 101 { 102 // Here we take selected text via editor tools 103 // we don't use "res" 104 this.handler.oEditor.action.actions.quote.setExternalSelectionFromRange(); 105 var extSel = this.handler.oEditor.action.actions.quote.getExternalSelection(); 106 107 if (extSel === '' && quotedText !== '') 108 { 109 extSel = quotedText; 110 } 111 extSel = haveWrittenText + extSel; 112 if (BX.type.isNotEmptyString(extSel)) 113 { 114 this.handler.oEditor.action.actions.quote.setExternalSelection(extSel); 115 } 116 } 117 else 118 { 119 // For compatibility with old fileman (< 16.0.1) 120 this.handler.oEditor.action.actions.quote.setExternalSelection(quotedText); 121 } 122 this.handler.oEditor.action.Exec('quote'); 123 }.bind(this); 124 this.handler.exec(quoteHandler); 125 }, this), 126 OnUCReply : function(entityId, authorId, authorName, safeEdit, eventResult) { 127 if (!this.entitiesId[entityId] 128 || !this._checkTextSafety([entityId, 0]) 129 || eventResult.caught === true 130 ) 131 { 132 return false; 133 } 134 eventResult.caught = true; 135 136 this.show([entityId, 0]); 137 if (authorId > 0) 138 { 139 this.handler.exec(window.BxInsertMention, [{ 140 item: {entityId: authorId, name: authorName}, 141 type: 'user', 142 formID: this.form.id, 143 editorId: this.editorId, 144 bNeedComa: true, 145 insertHtml: true 146 }]); 147 } 148 }.bind(this), 149 OnUCAfterRecordEdit : BX.delegate(function(entityId, id, data, act) {
150 if (!!this.entitiesId[entityId]) { 151 if (act === "EDIT") 152 { 153 this.show([entityId, id], data['messageBBCode'], data['messageFields']); 154 this.editing = true; 155 } 156 else 157 { 158 this.hide(true); 159 if (!!data['errorMessage']) 160 { 161 this.id = [entityId, id]; 162 this.showError(data['errorMessage']); 163 } 164 else if (!!data['okMessage']) 165 { 166 this.id = [entityId, id]; 167 this.showNote(data['okMessage']); 168 this.id = null; 169 } 170 } 171 } }, this) 172 }; 173 174 this.linkEntity(arParams['entitiesId']); 175 176 BX.remove(BX("micro" + arParams['editorName'])); 177 BX.remove(BX("micro" + arParams['editorId'])); 178 179 this.eventNode = this.handler.eventNode; 180 181 if (this.eventNode) 182 { 183 BX.addCustomEvent(this.eventNode, 'OnBeforeHideLHE', BX.delegate(function(/*show, obj*/) { 184 BX.removeClass(document.documentElement, 'bx-ios-fix-frame-focus'); 185 if (top && top["document"]) 186 BX.removeClass(top["document"]["documentElement"], 'bx-ios-fix-frame-focus'); 187 if (!!this.id && !!BX('uc-writing-' + this.form.id + '-' + this.id[0] + '-area')) 188 { 189 BX.hide(BX('uc-writing-' + this.form.id + '-' + this.id[0] + '-area')); 190 } 191 }, this)); 192 193 BX.addCustomEvent(this.eventNode, 'OnAfterHideLHE', BX.delegate(function(/*show, obj*/) { 194 var node = this._getPlacehoder(); 195 if (node) 196 { 197 BX.hide(node); 198 } 199 200 node = this._getSwitcher(); 201 if (node) 202 { 203 BX.show(node); 204 BX.focus(node.firstChild); 205 } 206 207 this.__content_length = 0; 208 if (!!this.id) { 209 BX.onCustomEvent(this.eventNode, 'OnUCFormAfterHide', [this]); 210 } 211 clearTimeout(this._checkWriteTimeout); 212 this._checkWriteTimeout = 0; 213 this.clear(); 214 BX.onCustomEvent(window, "OnUCFeedChanged", [this.id]); 215 }, this)); 216 217 BX.addCustomEvent(this.eventNode, 'OnBeforeShowLHE', BX.delegate(function(/*show, obj*/) { 218 if (BX.browser.IsIOS() && BX.browser.IsMobile()) 219 { 220 BX.addClass(window["document"]["documentElement"], 'bx-ios-fix-frame-focus'); 221 if (top && top["document"]) 222 BX.addClass(top["document"]["documentElement"], 'bx-ios-fix-frame-focus'); 223 } 224 var node = this._getPlacehoder(); 225 226 if (node) 227 { 228 BX.removeClass(node, 'feed-com-add-box-no-form'); 229 BX.removeClass(node, 'feed-com-add-box-header'); 230 BX.show(node); 231 } 232 node = this._getSwitcher(); 233 if (node) 234 { 235 BX.hide(node); 236 } 237 238 if (!!this.id && !!BX('uc-writing-' + this.form.id + '-' + this.id[0] + '-area')) 239 { 240 BX.hide(BX('uc-writing-' + this.form.id + '-' + this.id[0] + '-area')); 241 } 242 }, this)); 243 BX.addCustomEvent(this.eventNode, 'OnAfterShowLHE', function(show, obj){ 244 this._checkWrite(show, obj); 245 BX.onCustomEvent(window, "OnUCFeedChanged", [this.id]); 246 }.bind(this)); 247 BX.addCustomEvent(this.eventNode, 'OnClickSubmit', BX.delegate(this.submit, this)); 248 BX.addCustomEvent(this.eventNode, 'OnClickCancel', BX.delegate(this.cancel, this)); 249 250 BX.onCustomEvent(this.eventNode, 'OnUCFormInit', [this]); 251 } 252 this.id = null; 253 this.jsCommentId = null; 254 255 // Lock the submit button when inserting an image. 256 BX.addCustomEvent(window, 'OnImageDataUriHandle', BX.delegate(this.showWait, this)); 257 BX.addCustomEvent(window, 'OnImageDataUriCaughtUploaded', BX.delegate(this.closeWait, this)); 258 BX.addCustomEvent(window, 'OnImageDataUriCaughtFailed', BX.delegate(this.closeWait, this)); 259 }; 260 window.FCForm.prototype = { 261 linkEntity : function(Ent) { 262 if (!!Ent) 263 { 264 for(var ii in Ent) 265 { 266 if (Ent.hasOwnProperty(ii)) 267 { 268 BX.onCustomEvent(window, 'OnUCUnlinkForm', [ii]); 269 this.entitiesId[ii] = Ent[ii]; 270 } 271 } 272 } 273 if (!this.windowEventsSet && !!this.entitiesId) 274 { 275 BX.addCustomEvent(window, 'OnUCUnlinkForm', this.windowEvents.OnUCUnlinkForm); 276 BX.addCustomEvent(window, 'OnUCReply', BX.debounce(this.windowEvents.OnUCReply, 10)); 277 BX.addCustomEvent(window, 'OnUCQuote', BX.debounce(this.windowEvents.OnUCQuote, 10)); 278 BX.addCustomEvent(window, 'OnUCAfterRecordEdit', this.windowEvents.OnUCAfterRecordEdit); 279 this.windowEventsSet = true; 280 } 281 }, 282 _checkTextSafety : function(id) { 283 if ( 284 this.id 285 && this.id.join('-') !== id.join('-') 286 && this.handler.editorIsLoaded 287 && this.handler.oEditor.IsContentChanged() 288 ) 289 { 290 return window.confirm(BX.message('MPL_SAFE_EDIT')); 291 } 292 return true; 293 }, 294 _checkWrite : function() { 295 if (this.handler.editorIsLoaded && this._checkWriteTimeout !== false) 296 { 297 this.__content_length = (this.__content_length > 0 ? this.__content_length : 0); 298 var content = this.handler.oEditor.GetContent(), 299 time = 2000; 300 if(content.length >= 4 && this.__content_length != content.length && !!this.id) 301 { 302 BX.onCustomEvent(window, 'OnUCUserIsWriting', [this.id[0], {sent : false}]); 303 time = 30000; 304 } 305 this._checkWriteTimeout = setTimeout(this._checkWrite.bind(this), time); 306 this.__content_length = content.length; 307 } 308 }, 309 _getPlacehoder : function(res) {res = (!!res ? res : this.id); return (!!res ? BX('record-' + res.join('-') + '-placeholder') : null); }, 310 _getSwitcher : function(res) {res = (!!res ? res : this.id); return (!!res ? BX('record-' + res[0] + '-switcher') : null); }, 311 hide : function(quick) {if (this.eventNode.style.display != 'none') { BX.onCustomEvent(this.eventNode, 'OnShowLHE', [(quick === true ? false : 'hide')]); } if (quick) { document.body.appendChild(this.form); }}, 312 clear : function() { 313 //var form = this.form, filesForm = null; 314 this.editing = false;
315 var res = this._getPlacehoder(); 316 if (!!res) 317 BX.hide(res); 318 319 this.clearNotification(res, 'feed-add-error'); 320 321 BX.onCustomEvent(this.eventNode, 'OnUCFormClear', [this]); 322 323 var filesForm = BX.findChild(this.form, {'className': 'wduf-placeholder-tbody' }, true, false); 324 if(filesForm !== null && typeof filesForm != 'undefined') 325 BX.cleanNode(filesForm, false); 326 filesForm = BX.findChild(this.form, {'className': 'wduf-selectdialog' }, true, false); 327 if(filesForm !== null && typeof filesForm != 'undefined') 328 BX.hide(filesForm); 329 330 filesForm = BX.findChild(this.form, {'className': 'file-placeholder-tbody' }, true, false); 331 if(filesForm !== null && typeof filesForm != 'undefined') 332 BX.cleanNode(filesForm, false); 333 334 this.id = null; 335 this.jsCommentId = null; 336 }, 337 show : function(id, text, data) 338 { 339 if (this.id && !!id && this.id.join('-') == id.join('-')) 340 { 341 var placeholderNode = this._getPlacehoder(id); 342 this.handler.oEditor.Focus(); 343 setTimeout(function() { 344 var pos = BX.pos(placeholderNode); 345 var windowPos = BX.GetWindowSize(document); 346 if (windowPos.scrollTop > pos.top) 347 { 348 placeholderNode.scrollIntoView(); 349 } 350 else if ((windowPos.scrollTop + windowPos.innerHeight) < pos.top) 351 { 352 placeholderNode.scrollIntoView(false); 353 } 354 }, 100); 355 return true; 356 } 357 else 358 { 359 this.hide(true); 360 } 361 362 this.id = id; 363 this.jsCommentId = BX.util.getRandomString(20); 364 365 var node = this._getPlacehoder(); 366 BX.removeClass(node, 'feed-com-add-box-no-form'); 367 BX.removeClass(node, 'feed-com-add-box-header'); 368 node.appendChild(this.form); 369 BX.onCustomEvent(this.eventNode, 'OnUCFormBeforeShow', [this, text, data]); 370 BX.onCustomEvent(this.eventNode, 'OnShowLHE', ['show', null, this.id]); 371 BX.onCustomEvent(this.eventNode, 'OnUCFormAfterShow', [this, text, data]); 372 return true; 373 }, 374 submit : function() { 375 if (this.busy === true) 376 return 'busy'; 377 378 var text = (this.handler.editorIsLoaded ? this.handler.oEditor.GetContent() : ''); 379 380 if (!text) 381 { 382 this.showError(BX.message('JERROR_NO_MESSAGE')); 383 return false; 384 } 385 this.showWait(); 386 this.busy = true; 387 388 var post_data = {}; 389 window.convertFormToArray(this.form, post_data); 390 post_data['REVIEW_TEXT'] = text; 391 post_data['NOREDIRECT'] = "Y"; 392 post_data['MODE'] = "RECORD"; 393 post_data['AJAX_POST'] = "Y"; 394 post_data['id'] = this.id; 395 if (this.jsCommentId !== null) 396 post_data['COMMENT_EXEMPLAR_ID'] = this.jsCommentId; 397 post_data['SITE_ID'] = BX.message("SITE_ID"); 398 post_data['LANGUAGE_ID'] = BX.message("LANGUAGE_ID"); 399 post_data["ACTION"] = "ADD"; 400 401 if (this.editing === true) 402 { 403 post_data['REVIEW_ACTION'] = "EDIT"; // @deprecated 404 post_data["FILTER"] = {"ID" : this.id[1]}; 405 post_data["ACTION"] = "EDIT"; 406 post_data["ID"] = this.id[1]; // comment to edit 407 } 408 BX.onCustomEvent(this.eventNode, 'OnUCFormSubmit', [this, post_data]); 409 BX.onCustomEvent(window, 'OnUCFormSubmit', [this.id[0], this.id[1], this, post_data]); 410 411 var actionUrl = this.form.action; 412 actionUrl = BX.util.remove_url_param(actionUrl, [ 'b24statAction' ]); 413 actionUrl = BX.util.add_url_param(actionUrl, { 414 b24statAction: (this.id[1] > 0 ? 'editComment' : 'addComment') 415 }); 416 this.form.action = actionUrl; 417 418 BX.ajax({ 419 method: 'POST', 420 url: this.form.action, 421 data: post_data, 422 dataType: 'json', 423 onsuccess: BX.proxy(function(data) { 424 this.closeWait(); 425 var true_data = data, ENTITY_XML_ID = this.id[0]; 426 BX.onCustomEvent(this.eventNode, 'OnUCFormResponse', [this, data]); 427 if (!!this.OnUCFormResponseData) 428 data = this.OnUCFormResponseData; 429 if (!!data) 430 { 431 if (data['errorMessage']) 432 { 433 this.showError(data['errorMessage']); 434 } 435 else if (data["status"] == "error") 436 { 437 this.showError((BX.type.isNotEmptyString(data["message"]) ? data["message"] : "")); 438 } 439 else 440 { 441 BX.onCustomEvent(window, 'OnUCAfterRecordAdd', [this.id[0], data, true_data]); 442 this.hide(true); 443 } 444 } 445 this.busy = false;
446 BX.onCustomEvent(window, 'OnUCFormResponse', [ENTITY_XML_ID, data["messageId"], this, data]); 447 }, this), 448 onfailure: BX.delegate(function(){this.closeWait(); 449 this.busy = false; 450 BX.onCustomEvent(window, 'OnUCFormResponse', [this.id[0], this.id[1], this, []]);}, this) 451 }); 452 }, 453 cancel : function() {}, 454 clearNotification : function(node, className) { 455 var nodes = BX.findChildren(node, {tagName : "DIV", className : className}, true); 456 if (!!nodes) 457 { 458 var res = nodes.pop(); 459 do { 460 BX.remove(res); 461 BX.remove(res); 462 } while ((res = nodes.pop()) && !!res); 463 } 464 }, 465 showError : function(text) { 466 if (!text) 467 return; 468 469 var node = this._getPlacehoder(); 470 this.clearNotification(node, 'feed-add-error'); 471 BX.addClass(node, (!node.firstChild ? 'feed-com-add-box-no-form' : 'feed-com-add-box-header')); 472 473 node.insertBefore(BX.create( 474 'div', { 475 attrs : { 476 class: "feed-add-error" 477 }, 478 html: '<span class="feed-add-info-text"><span class="feed-add-info-icon"></span>' + '<b>' + BX.message('FC_ERROR') + '</b><br />' + text + '</span>' 479 }), 480 node.firstChild); 481 482 BX.show(node); 483 }, 484 showNote : function(text) { 485 if (!text) 486 return; 487 488 var node = this._getPlacehoder(); 489 this.clearNotification(node, 'feed-add-error'); 490 this.clearNotification(node, 'feed-add-successfully'); 491 BX.addClass(node, (!node.firstChild ? 'feed-com-add-box-no-form' : 'feed-com-add-box-header')); 492 493 node.insertBefore(BX.create('div', {attrs : {"class": "feed-add-successfully"}, 494 html: '<span class="feed-add-info-text"><span class="feed-add-info-icon"></span>' + text + '</span>'}), 495 node.firstChild); 496 BX.addClass(node, 'comment-deleted'); 497 BX.show(node); 498 }, 499 showWait : function() { 500 var el = BX('lhe_button_submit_' + this.form.id); 501 this.busy = true; 502 if (!!el) 503 { 504 BX.addClass(el, "ui-btn-clock"); 505 BX.defer(function(){el.disabled = true})(); 506 } 507 }, 508 closeWait : function() { 509 var el = BX('lhe_button_submit_' + this.form.id); 510 this.busy = false; 511 if (!!el ) 512 { 513 el.disabled = false ; 514 BX.removeClass(el, "ui-btn-clock"); 515 } 516 }, 517 }; 518 519 window.convertFormToArray = function(form, data) 520 { 521 data = (!!data ? data : []); 522 if(!!form){ 523 var 524 i, 525 _data = [], 526 n = form.elements.length; 527 528 for(i=0; i<n; i++) 529 { 530 var el = form.elements[i]; 531 if (el.disabled) 532 continue; 533 switch(el.type.toLowerCase()) 534 { 535 case 'text': 536 case 'textarea': 537 case 'password': 538 case 'hidden': 539 case 'select-one': 540 _data.push({name: el.name, value: el.value}); 541 break; 542 case 'radio': 543 case 'checkbox': 544 if(el.checked) 545 _data.push({name: el.name, value: el.value}); 546 break; 547 case 'select-multiple': 548 for (var j = 0; j < el.options.length; j++) { 549 if (el.options[j].selected) 550 _data.push({name : el.name, value : el.options[j].value}); 551 } 552 break; 553 default: 554 break; 555 } 556 } 557 558 var current = data; 559 i = 0; 560 561 while(i < _data.length) 562 { 563 var p = _data[i].name.indexOf('['); 564 if (p == -1) { 565 current[_data[i].name] = _data[i].value; 566 current = data; 567 i++; 568 } 569 else 570 { 571 var name = _data[i].name.substring(0, p); 572 var rest = _data[i].name.substring(p+1); 573 if(!current[name]) 574 current[name] = []; 575 576 var pp = rest.indexOf(']'); 577 if(pp == -1) 578 { 579 current = data; 580 i++; 581 } 582 else if(pp === 0) 583 { 584 //No index specified - so take the next integer 585 current = current[name]; 586 _data[i].name = '' + current.length; 587 } 588 else 589 { 590 //Now index name becomes and name and we go deeper into the array 591 current = current[name]; 592 _data[i].name = rest.substring(0, pp) + rest.substring(pp+1); 593 } 594 } 595 } 596 } 597 return data; 598 }; 599 600 window["fRefreshCaptcha"] = function(form) 601 { 602 var captchaIMAGE = null, 603 captchaHIDDEN = BX.findChild(form, {attr : {'name': 'captcha_code'}}, true), 604 captchaINPUT = BX.findChild(form, {attr: {'name':'captcha_word'}}, true),
605 captchaDIV = BX.findChild(form, {'className':'comments-reply-field-captcha-image'}, true); 606 if (captchaDIV) 607 captchaIMAGE = BX.findChild(captchaDIV, {'tag':'img'}); 608 if (captchaHIDDEN && captchaINPUT && captchaIMAGE) 609 { 610 captchaINPUT.value = ''; 611 BX.ajax.getCaptcha(function(result) { 612 captchaHIDDEN.value = result["captcha_sid"]; 613 captchaIMAGE.src = '/bitrix/tools/captcha.php?captcha_code='+result["captcha_sid"]; 614 }); 615 } 616 }; 617})();
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.