Current Path : /var/www/www-root/data/www/info.monolith-realty.ru/bitrix/js/landing/ui/form/ |
Current File : /var/www/www-root/data/www/info.monolith-realty.ru/bitrix/js/landing/ui/form/cards_form.min.js |
(function(){"use strict";BX.namespace("BX.Landing.UI.Form");var e=BX.Landing.Utils.throttle;var t=BX.Landing.Utils.append;var n=BX.Landing.Utils.create;var i=BX.Landing.Utils.bind;var r=BX.Landing.Utils.unbind;var o=BX.Landing.Utils.proxy;var a=BX.Landing.Utils.addClass;var s=BX.Landing.Utils.removeClass;var l=BX.Landing.Utils.hasClass;var d=BX.Landing.Utils.style;var p=BX.Landing.Utils.slice;var c=BX.Landing.Utils.findParent;var u=BX.Landing.Utils.offsetTop;var h=BX.Landing.Utils.offsetLeft;var m=BX.Landing.Utils.rect;var f=BX.Landing.Utils.remove;var g=BX.Landing.Utils.onTransitionEnd;var v=BX.Landing.Utils.random;var L=BX.Landing.Utils.clone;var B=BX.Landing.Utils.isString;var y=BX.Landing.Utils.isArray;var E=BX.Landing.Utils.isEmpty;var C=BX.Landing.Utils.isPlainObject;var F=BX.Landing.Utils.join;var I=BX.Landing.Utils.onCustomEvent;var x=BX.Landing.UI.Collection.FormCollection;var X=BX.Landing.UI.Button.BaseButton;BX.Landing.UI.Form.CardsForm=function(n){BX.Landing.UI.Form.BaseForm.apply(this,arguments);this.layout.classList.add("landing-ui-form-cards");this.type="cards";this.code=n.code;this.presets=n.presets;this.childForms=new x;this.presetForm=new x;this.sync=n.sync;this.forms=n.forms;this.id=this.code.replace(".","")+"-"+BX.Landing.Utils.random();this.onItemClick=e(this.onItemClick,200,this);this.onRemoveItemClick=o(this.onRemoveItemClick,this);this.onRemoveItemMouseenter=o(this.onRemoveItemMouseenter,this);this.onRemoveItemMouseleave=o(this.onRemoveItemMouseleave,this);this.onAddCardClick=o(this.onAddCardClick,this);this.onMouseWheel=o(this.onMouseWheel,this);this.addButton=this.createAddButton();this.wheelEventName=this.getWheelEventName();setTimeout(function(){this.value=this.serialize()}.bind(this));this.adjustLastFormState();t(this.addButton.layout,this.footer)};function b(e,t){return n("div",{props:{className:"landing-ui-form-cards-item"},children:[n("div",{children:[n("div",{props:{className:"landing-ui-form-card-item-header"},events:{click:t.onItemClick},children:[n("div",{props:{className:"landing-ui-form-card-item-header-left"},children:[n("div",{props:{className:"landing-ui-form-card-item-header-left-inner"},children:[n("span",{props:{className:"landing-ui-form-card-item-header-drag landing-ui-drag"}}),n("span",{props:{className:"landing-ui-form-card-item-header-title"},children:[e.label]})]}),n("span",{props:{className:"landing-ui-form-card-item-header-edit"},children:[n("span",{props:{className:"fa fa-pencil"}})]})]}),n("div",{children:[n("span",{props:{className:"landing-ui-form-card-item-header-remove"},children:[n("span",{props:{className:"fa fa-remove"}})],events:{click:t.onRemoveItemClick,mouseenter:t.onRemoveItemMouseenter,mouseleave:t.onRemoveItemMouseleave}})]})]}),e.layout]})]})}function w(e,t){var n=e.querySelector(".landing-ui-form-card-item-header-drag");n.onbxdragstart=I.bind(this);n.onbxdrag=x.bind(this);n.onbxdragstop=X.bind(this);jsDD.registerObject(n);i(n,"mousedown",w);i(n,"mouseup",M);i(n,"click",b);var r=c(e,{className:"landing-ui-panel-content-body-content"});jsDD.setScrollWindow(r);var o;var l;var h;var f;var g;var v;var L;var E;var C;function I(){r=c(e,{className:"landing-ui-panel-content-body-content"});o=m(e);l=Math.max(Math.abs(jsDD.start_y-o.top),0);h=r.scrollTop;f=[].indexOf.call(p(e.parentElement.children),e);L=c(jsDD.current_node,{className:"landing-ui-form-cards-item"});var t=getComputedStyle(e);var n=parseInt(t.getPropertyValue("margin-top"));n=n===n?n:0;var i=parseInt(t.getPropertyValue("margin-bottom"));i=i===i?i:0;g=o.height+(n+i)/2;E=-u(L,L.parentElement);var a=m(L.parentElement);C=a.height-u(L,L.parentElement)-o.height}function x(t,n){var i=h-r.scrollTop;var a=n-o.top-l-i;a=Math.min(Math.max(a,E),C);void d(e,{zIndex:999,transform:"translateY("+a+"px)"});p(e.parentElement.children).forEach(function(t,i){if(t!==e){var r=t.getBoundingClientRect();var o=r.top+BX.scrollTop(window)+r.height/2;if(i>f&&n>o&&t.style.transform!=="translate3d(0px, "+-g+"px, 0px)"&&t.style.transform!==""){v=t;void d(t,{transform:"translate3d(0px, "+-g+"px, 0px)",transition:"300ms"})}if(i<f&&n<o&&t.style.transform!=="translate3d(0px, "+g+"px, 0px)"&&t.style.transform!==""){v=t;void d(t,{transform:"translate3d(0px, "+g+"px, 0px)",transition:"300ms"})}if((i<f&&n>o||i>f&&n<o)&&t.style.transform!=="translate3d(0px, 0px, 0px)"){if(o>n){v=t.previousElementSibling}else{v=t.nextElementSibling}void d(t,{transform:"translate3d(0px, 0px, 0px)",transition:"300ms"})}}})}function X(){p(e.parentElement.children).forEach(function(e){void d(e,{zIndex:null,transform:null,transition:null});setTimeout(function(){s(e,"landing-ui-form-card-item-draggable")},50)});if(L&&v&&L!==v&&L.parentNode===v.parentNode){var n=[].indexOf.call(v.parentElement.children,L);var i=[].indexOf.call(v.parentElement.children,v);if(v.parentElement.children.length===i){v.parentElement.appendChild(target)}if(n>i){v.parentElement.insertBefore(L,v)}if(n<i&&v.parentElement.children.length!==i){v.parentElement.insertBefore(L,v.nextElementSibling)}if(t.sync){var r=t.sync;if(B(t.sync)){r=[t.sync]}if(y(r)){r.forEach(function(e){var r=t.forms.find(function(t){return t.code===e});if(r){var o=r.body.children[n];var a=r.body.children[i];if(a.parentElement.children.length===i){a.parentElement.appendChild(target)}if(n>i){a.parentElement.insertBefore(o,a)}if(n<i&&a.parentElement.children.length!==i){a.parentElement.insertBefore(o,a.nextElementSibling)}}r.childForms.forEach(function(e){var t=[].indexOf.call(e.layout.parentElement.parentElement.parentElement.children,e.layout.parentElement.parentElement);e.oldIndex=N(e.selector);e.selector=F(e.selector.split("@")[0],"@",t)});r.childForms.sort(function(e,t){return parseInt(e.selector.split("@")[1])<parseInt(t.selector.split("@")[1])?-1:1})})}}}t.childForms.forEach(function(e){var t=[].indexOf.call(e.layout.parentElement.parentElement.parentElement.children,e.layout.parentElement.parentElement);e.oldIndex=N(e.selector);e.selector=F(e.selector.split("@")[0],"@",t)});t.childForms.sort(function(e,t){return parseInt(e.selector.split("@")[1])<parseInt(t.selector.split("@")[1])?-1:1})}function b(e){e.preventDefault();e.stopPropagation()}function w(){a(e,"landing-ui-form-card-item-draggable")}function M(){s(e,"landing-ui-form-card-item-draggable")}}function M(e){var t=[];if(B(e.labelBindings)){t.push(e.labelBindings)}else if(y(e.labelBindings)){t=t.concat(e.labelBindings)}e.fields.forEach(function(e){e.layout.hidden=true;e.reset();e.layout.hidden=false});var i=-1;t.forEach(function(t){var r=e.fields.find(function(e){return e.selector.split("@")[0]===t});if(r){var o=c(e.layout,{className:"landing-ui-form-cards-item"});var a;if(r instanceof BX.Landing.UI.Field.Link){a=o.querySelector(".landing-card-title-link");a.innerHTML=BX.Landing.Loc.getMessage("LANDING_CARDS_FORM_ITEM_PLACEHOLDER_TEXT");I(r,"change",function(e){a.innerHTML=e.text});return}if(r instanceof BX.Landing.UI.Field.Icon){a=o.querySelector(".landing-card-title-icon").firstElementChild;a.className="landing-card-title-icon";I(r,"change",function(e){a.className="landing-card-title-icon "+e.classList.join(" ")});return}if(r instanceof BX.Landing.UI.Field.Image){a=o.querySelector(".landing-card-title-img");a.style.backgroundColor="#fafafa";a.innerHTML="";I(r,"change",function(e){a.innerHTML="";a.appendChild(n("img",{props:{src:e.src}}))});return}if(r instanceof BX.Landing.UI.Field.Text){i+=1;var s=o.querySelectorAll(".landing-card-title-text");a=s[i];I(r,"change",function(e){a.innerHTML=n("div",{html:e}).innerText});if(a===s[0]){a.innerHTML=BX.Landing.Loc.getMessage("LANDING_CARDS_FORM_ITEM_PLACEHOLDER_TEXT");r.setValue(BX.Landing.Loc.getMessage("LANDING_CARDS_FORM_ITEM_PLACEHOLDER_TEXT"))}else{a.innerHTML=""}}}})}function U(e){return B(e)?e.split("@")[0]:""}function N(e){return B(e)?e.split("@")[1]:""}function T(e,t){return F(e.split("@")[0],"@",t)}BX.Landing.UI.Form.CardsForm.prototype={constructor:BX.Landing.UI.Form.CardsForm,__proto__:BX.Landing.UI.Form.BaseForm.prototype,getWheelEventName:function(){return!!window.onwheel?"wheel":"mousewheel"},createAddButton:function(){return new X("add-card-"+v(),{className:"landing-ui-card-add-button",text:BX.Landing.Loc.getMessage("LANDING_CARDS_FORM_ADD_BUTTON"),onClick:this.onAddCardClick})},onItemClick:function(e){e.preventDefault();var t=c(e.currentTarget,{className:"landing-ui-form-cards-item"});if(!!t&&!l(t,"landing-ui-form-card-item-draggable")){if(!l(t,"landing-ui-form-cards-item-expand")){a(t,"landing-ui-form-cards-item-expand");g(t).then(function(){void d(t,{overflow:"visible"})});void d(t,{height:"auto"})}else{s(t,"landing-ui-form-cards-item-expand");void d(t,null)}}},onRemoveItemClick:function(e,t){e.stopPropagation();var n=this.getVisibleForms();if(n.length>1){var i=c(e.currentTarget,{className:"landing-ui-form-cards-item"});f(i);var r=i.querySelector(".landing-ui-form-card");var o=this.childForms.find(function(e){return e.layout===r});this.childForms.remove(o);if(t!==true){if(this.sync){var a=this.sync;if(B(this.sync)){a=[this.sync]}if(y(a)){a.forEach(function(e){var t=this.forms.find(function(t){return t.code===e});if(t){var n=t.childForms.find(function(e){return e.selector.split("@")[1]===o.selector.split("@")[1]});t.onRemoveItemClick({currentTarget:n.layout,stopPropagation:function(){}},true)}},this)}}}}this.adjustLastFormState()},onRemoveItemMouseenter:function(e){e.stopPropagation();e.preventDefault();var t=c(e.currentTarget,{className:"landing-ui-form-card-item-header"});a(t,"landing-ui-form-card-item-header-onremove")},onRemoveItemMouseleave:function(e){var t=c(e.currentTarget,{className:"landing-ui-form-card-item-header"});s(t,"landing-ui-form-card-item-header-onremove")},addChildForm:function(e){this.childForms.add(e);var n=b(e,this);t(n,this.body);w(n,this);this.adjustLastFormState()},addPresetForm:function(e){this.presetForm.add(e);var n=b(e,this);n.hidden=true;t(n,this.body);w(n,this);this.adjustLastFormState()},onAddCardClick:function(e){if(C(this.presets)&&!E(this.presets)){this.showPresetsPopup()}else{this.addEmptyCard();if(e!==true){if(this.sync){var t=this.sync;if(B(this.sync)){t=[this.sync]}if(y(t)){t.forEach(function(e){var t=this.forms.find(function(t){return t.code===e});if(t){t.onAddCardClick(true)}},this)}}}}},onPresetItemClick:function(e){var t=this.presets[e];var n=this.presetForm.find(function(t){return t.preset.id===e}).clone();n.selector=F(n.selector.split("@")[0],"@",this.childForms.length);n.oldIndex=this.childForms.length;n.preset=L(t);n.preset.id=e;this.addChildForm(n);M(n);this.adjustLastFormState();this.popup.close();if(C(t.values)){n.fields.forEach(function(e){var n=e.selector.split("@")[0];if(n in t.values){e.setValue(t.values[n]);if(e instanceof BX.Landing.UI.Field.Text){BX.fireEvent(e.input,"input")}}if(y(t.disallow)){var i=!!t.disallow.find(function(e){return n===e});if(i){e.layout.hidden=true}}})}},showPresetsPopup:function(){if(!this.popup){this.popup=new BX.Landing.UI.Tool.Menu({id:"catalog_blocks_list",bindElement:this.addButton.layout,items:Object.keys(this.presets).map(function(e){return{text:this.presets[e].name,className:"landing-ui-form-cards-preset-popup-item menu-popup-no-icon",onclick:this.onPresetItemClick.bind(this,e)}},this),autoHide:true,maxHeight:176,minHeight:87});i(this.popup.popupWindow.popupContainer,"mouseover",this.onMouseOver.bind(this));i(this.popup.popupWindow.popupContainer,"mouseleave",this.onMouseLeave.bind(this));var e=BX.Landing.PageObject.getRootWindow();i(e.document,"click",this.onDocumentClick.bind(this));t(this.popup.popupWindow.popupContainer,c(this.addButton.layout,{className:"landing-ui-panel-content-body-content"}))}if(this.popup.popupWindow.isShown()){this.popup.popupWindow.close()}else{this.popup.popupWindow.show()}this.adjustPopupPosition()},onMouseOver:function(){this.popup.popupWindow.popupContainer.addEventListener(this.wheelEventName,this.onMouseWheel,true);this.popup.popupWindow.popupContainer.addEventListener("touchmove",this.onMouseWheel,true)},onMouseLeave:function(){this.popup.popupWindow.popupContainer.removeEventListener(this.wheelEventName,this.onMouseWheel,true);this.popup.popupWindow.popupContainer.removeEventListener("touchmove",this.onMouseWheel,true)},onMouseWheel:function(e){e.stopPropagation();e.preventDefault();var t=BX.Landing.UI.Panel.Content.getDeltaFromEvent(e);var n=this.popup.popupWindow.contentContainer.scrollTop;requestAnimationFrame(function(){this.popup.popupWindow.contentContainer.scrollTop=n-t.y}.bind(this))},onDocumentClick:function(){if(this.popup.popupWindow){this.popup.popupWindow.close()}},adjustPopupPosition:function(){if(this.popup.popupWindow){requestAnimationFrame(function(){var e=c(this.addButton.layout,{className:"landing-ui-panel-content-body-content"});var t=u(this.addButton.layout,e);var n=h(this.addButton.layout,e);var i=this.addButton.layout.getBoundingClientRect();var r=this.popup.popupWindow.popupContainer.getBoundingClientRect();var o=14;this.popup.popupWindow.popupContainer.style.top=t+i.height+o+"px";this.popup.popupWindow.popupContainer.style.left=n-r.width/2+i.width/2+"px";this.popup.popupWindow.setAngle({offset:83,position:"top"})}.bind(this))}},addEmptyCard:function(){var e=L(this.childForms[0].data);var t=F(e.selector.split("@")[0],"@",this.childForms.length);e.selector=t;var n=this.childForms[0].clone(e);n.oldIndex=this.childForms.length;n.selector=t;this.addChildForm(n);M(n);this.adjustLastFormState()},getVisibleForms:function(){return[].slice.call(this.body.children).filter(function(e){return!e.hidden})},adjustLastFormState:function(){var e=this.getVisibleForms();if(e.length===1){a(e[0],"landing-ui-disallow-remove");return}p(e).forEach(function(e){s(e,"landing-ui-disallow-remove")})},serialize:function(){return this.childForms.map(function(e){return e.serialize()})},getIndexesMap:function(){return this.childForms.reduce(function(e,t,n){return e[n]=t.oldIndex,e},{})},getUsedPresets:function(){return this.childForms.reduce(function(e,t){if(C(t.preset)){e[N(t.selector)]=t.preset.id}return e},{})},isChanged:function(){return JSON.stringify(this.value)!==JSON.stringify(this.serialize())}}})(); //# sourceMappingURL=cards_form.map.js