1;(function() { 2 'use strict'; 3 4 let Popup = function(parameters) { 5 if (!BX.type.isElementNode(parameters.node)) 6 { 7 return {}; 8 } 9 10 this.parameters = { 11 initialClickKey: 'popupInitialClick', 12 initialClickValue: 'hpau', 13 onOpenCallback: BX.type.isFunction(parameters.onOpenCallback) ? parameters.onOpenCallback : null, 14 onCloseCallback: BX.type.isFunction(parameters.onCloseCallback) ? parameters.onCloseCallback : null, 15 }; 16 17 this.nodes = { 18 popup: parameters.node, 19 }; 20 21 this.attributes = { 22 active: 'data-active', 23 close: 'data-close', 24 }; 25 26 let closes = this.nodes.popup.querySelectorAll('[' + this.attributes.close + ']'); 27 closes = Array.prototype.slice.call(closes); 28 closes.forEach((close) => { 29 BX.bind(close, 'click', this.close.bind(this)); 30 }); 31 }; 32 33 Popup.prototype = { 34 checkInitialClick: function(event) { 35 event = event || window.event; 36 37 return typeof event !== 'undefined' 38 && event.type === 'click' 39 && event.hasOwnProperty(this.parameters.initialClickKey) 40 && event[this.parameters.initialClickKey] === this.parameters.initialClickValue; 41 }, 42 setInitialClick: function(event) { 43 event = event || window.event; 44 45 if (typeof event !== 'undefined' && event.type === 'click' && 46 !this.nodes.popup.hasAttribute(this.attributes.active)) 47 { 48 event[this.parameters.initialClickKey] = this.parameters.initialClickValue; 49 } 50 }, 51 closeHandler: function(event) { 52 event = event || window.event; 53 54 if (!this.checkInitialClick(event) && !this.nodes.popup.contains(event.target)) 55 { 56 this.close(); 57 } 58 }, 59 close: function() { 60 BX.unbind(window, 'click', BX.proxy(this.closeHandler, this)); 61 this.nodes.popup.removeAttribute(this.attributes.active); 62 this.parameters.onCloseCallback.call(); 63 }, 64 open: function() { 65 this.nodes.popup.setAttribute(this.attributes.active, 'true'); 66 BX.bind(window, 'click', BX.proxy(this.closeHandler, this)); 67 this.parameters.onOpenCallback.call(); 68 }, 69 toggle: function() { 70 this.isActive() ? this.close() : this.open(); 71 }, 72 isActive: function() { 73 return this.nodes.popup.hasAttribute(this.attributes.active); 74 } 75 }; 76 77 let Initialization = function() { 78 this.nodes = { 79 section: null, 80 icon: null, 81 }; 82 83 this.classes = { 84 popup: 'js-bitrix24-auth-popup', 85 authorization: 'js-bitrix24-net-auth', 86 }; 87 88 this.attributes = { 89 initialized: 'data-pab-initialized', 90 parameters: 'data-pab-parameters', 91 section: 'data-pab-section', 92 button: 'data-pab-button', 93 popup: 'data-pab-popup', 94 icon: 'data-pab-icon', 95 active: 'data-active', 96 uri: 'data-icon-uri', 97 authorization: 'data-authorization-data', 98 }; 99 100 this.events = { 101 open: 'BX.SB.Portal.Authorization.Popup:open', 102 authorize: 'BX.SB.Portal.Authorization:authorize', 103 }; 104 105 this.popup = {}; 106 107 this.nodes.section = document.querySelector( 108 '[' + this.attributes.section + ']:not(' + this.attributes.initialized + ')'); 109 110 if (!this.nodes.section) 111 { 112 return; 113 } 114 115 this.nodes.section.setAttribute(this.attributes.initialized, 'true'); 116 117 let button = this.nodes.section.querySelector('[' + this.attributes.button + ']'); 118 119 if (!button) 120 { 121 return; 122 } 123 124 this.nodes.icon = this.nodes.section.querySelector('[' + this.attributes.icon + ']'); 125 126 this.popup = new Popup({ 127 node: this.nodes.section.querySelector('[' + this.attributes.popup + ']'), 128 onOpenCallback: function() { 129 this.nodes.section.setAttribute(this.attributes.active, 'true'); 130 }.bind(this), 131 onCloseCallback: function() { 132 this.nodes.section.removeAttribute(this.attributes.active); 133 }.bind(this), 134 }); 135 136 if (BX.type.isNotEmptyObject(this.popup)) 137 { 138 BX.bind(button, 'click', function(event) { 139 this.popup.setInitialClick(event); 140 this.popup.toggle(); 141 }.bind(this)); 142 } 143 144 BX.addCustomEvent(this.events.open, function(event) { 145 this.popup.setInitialClick(event); 146 this.popup.open(); 147 }.bind(this)); 148 149 let Composite = function() { 150 let inner = this.popup.nodes.popup.querySelector('[' + this.attributes.parameters + ']'); 151 152 if (BX.type.isElementNode(inner)) 153 { 154 let parameters = {}; 155
156 try 157 { 158 parameters = JSON.parse(inner.getAttribute(this.attributes.parameters) || '') || {}; 159 } 160 catch (e) 161 { 162 163 } 164 165 if (this.nodes.icon && BX.type.isNotEmptyObject(parameters) && parameters.hasOwnProperty('picture')) 166 { 167 this.nodes.icon.setAttribute(this.attributes.uri, parameters.picture); 168 169 if (BX.type.isNotEmptyString(parameters.picture)) 170 { 171 this.nodes.icon.style.backgroundImage = 'url(' + parameters.picture + ')'; 172 } 173 } 174 175 let buttons = inner.querySelectorAll('[' + this.attributes.authorization + ']'); 176 (Array.prototype.slice.call(buttons || [])).forEach((button) => { 177 let settings = {}; 178 179 try 180 { 181 settings = JSON.parse(button.getAttribute(this.attributes.authorization) || '') || {}; 182 } 183 catch (e) 184 { 185 186 } 187 188 settings = BX.type.isNotEmptyObject(settings) ? settings : {}; 189 190 BX.bind(button, 'click', function() { 191 BX.onCustomEvent(this.events.authorize, [settings]); 192 }.bind(this)); 193 }); 194 } 195 }.bind(this); 196 197 BX.addCustomEvent('onFrameDataReceived', function() { 198 Composite(); 199 }); 200 201 Composite(); 202 203 let externalButtons = document.querySelectorAll('.' + this.classes.popup); 204 (Array.prototype.slice.call(externalButtons || [])).forEach((button) => { 205 BX.bind(button, 'click', function(event) { 206 this.popup.setInitialClick(event); 207 this.popup.open(); 208 }.bind(this)); 209 }); 210 211 }; 212 213 Initialization.prototype = {}; 214 215 BX.ready(function() { 216 new Initialization(); 217 }); 218})();
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.