1 2(function ($) { 3 4 var SF2 = window.SF2 = { 5 shadeElement: $('<div class="sf2Shade"><div class="cssload-container"><div class="cssload-speeding-wheel"></div></div></div>'), 6 7 showLoading: function (_blockJQObj) { 8 $(':focus').blur(); 9 var self = this; 10 var lid = 'sf2Shade_' + this.getRandomInt(1, 99999); 11 var _f; 12 var shade; 13 14 if (_blockJQObj && _blockJQObj.length) { 15 var ids = []; 16 _blockJQObj.each(function (index) { 17 var tmp = self.shadeElement.clone().appendTo('body').click(); 18 tmp.attr('id', lid + '_' + index); 19 tmp.addClass(lid); 20 ids.push(lid + '_' + index); 21 }); 22 shade = $('#' + ids.join(',#')); 23 shade.css('position', 'absolute'); 24 _f = function () { 25 _blockJQObj.each(function (index) { 26 var $this = $(this); 27 var offset = $this.offset(); 28 $('#' + lid + '_' + index).css({ 29 left: offset.left, 30 top: offset.top, 31 width: $this.width(), 32 height: $this.height() 33 }); 34 }); 35 }; 36 _f(); 37 window[lid] = setInterval(_f, 200); 38 } else { 39 shade = this.shadeElement.clone().appendTo('body').click(); 40 shade.attr('id', lid); 41 shade.addClass(lid); 42 shade.css({ 43 left: 0, 44 top: 0, 45 width: '100%', 46 height: '100%', 47 position: 'fixed' 48 }); 49 } 50 shade.stop().css('opacity', 0).animate({ 51 opacity: 1, 52 }, 200); 53 return lid; 54 }, 55 56 hideLoading: function (lid) { 57 var shade = $('.' + lid); 58 shade.stop().css('opacity', 1).animate({ 59 opacity: 0, 60 }, 200, function () { 61 if (window[lid]) { 62 clearInterval(window[lid]); 63 delete window[lid]; 64 } 65 shade.remove(); 66 }); 67 }, 68 69 showSuccess: function (msg) { 70 this.showPopupMessage(msg, 'success'); 71 }, 72 73 showError: function (msg) { 74 this.showPopupMessage(msg, 'error'); 75 }, 76 77 showPopupMessage: function (msg, type) { 78 $(':focus').blur(); 79 var html = '<div class="sf2Shade sf2Message"><div class="sf2Win ' + type + '">'; 80 html += '<div class="sf2Win-body">' + msg + '</div>'; 81 html += '<div class="sf2Win-close">+</div>'; 82 html += '</div></div>'; 83 var win = $(html).appendTo('body'); 84 var modal = win.find('.sf2Win'); 85 win.on('sf2Close', function () { 86 win.animate({ 87 opacity: 0 88 }, 200, 'swing', function () { 89 win.remove(); 90 }); 91 modal.animate({ 92 'margin-top': -100 93 }, 200, 'swing'); 94 }); 95 win.on('click', function (e) { 96 var target = $(e.target); 97 if (target.is('.sf2Shade, .sf2Win-close') || target.parent().is('.sf2Win-close')) { 98 win.trigger('sf2Close'); 99 } 100 }); 101 win.css({ 102 opacity: 0 103 }); 104 modal.css({ 105 'margin-top': -100 106 }); 107 win.animate({ 108 opacity: 1 109 }, 300, 'swing'); 110 modal.animate({ 111 'margin-top': 0 112 }, 300, 'swing'); 113 }, 114 115 closePopup: function () { 116 $('.sf2Win').closest('.sf2Shade').trigger('sf2Close'); 117 }, 118 119 getRandomInt: function (min, max) { 120 return Math.floor(Math.random() * (max - min + 1)) + min; 121 }, 122 123 Config: function (id) { 124 var cfg = window.SF2Config || {}; 125 this.cfg = {}; 126 if (cfg[id]) { 127 this.cfg = cfg[id]; 128 } 129 return this; 130 }, 131 132 Text: function (key) { 133 return window.SF2Lang[key]; 134 }, 135 136 init: function () { 137 $('.sf2-callBtn').off('click').on('click', function () { 138 var callerButton = $(this); 139 var form = $('#' + callerButton.attr('data-formid')); 140 var win = new SF2Window(form.parent()); 141 return false; 142 }); 143 144 $('[data-sf2-caller]').off('click').on('click', function () { 145 var callerButton = $(this); 146 var form = $('#' + callerButton.data('sf2-caller')); 147 var win = new SF2Window(form.parent()); 148 return false; 149 }); 150 151 $('form.simpleForm2').each(function () { 152 var form = $(this); 153 if (form.data('sf2processed') && form.data('sf2processed') === true) { 154 return; 155 } 156 form.data('sf2processed', true); 157 158 var cfg = new SF2.Config(form.attr('id')); 159 form.on('submit', function () { 160 if (!cfg.get('onBeforeSend')(form)) { 161 return false; 162 } 163 var isPopup = form.closest('.sf2Win').length; 164 var lid = SF2.showLoading((isPopup ? null : form)); 165 form.ajaxSubmit({ 166 'url': cfg.get('ajaxURI'), 167 'form': form, 168 'method': 'POST', 169 'resetForm': false, 170 'dataType': 'json', 171 'success': function (responce, textStatus, jqXHR, $form) {
172 SF2.hideLoading(lid); 173 // <!-- Captcha reset 174 $form.find('.sf2Captcha').click(); 175 if (typeof grecaptcha !== 'undefined' && grecaptcha) { 176 grecaptcha.reset(); 177 } 178 // --> 179 if (responce == null) { 180 SF2.showError('AJAX server error.'); 181 return; 182 } 183 if (!cfg.get('onAfterReceive')($form, responce)) { 184 return; 185 } 186 187 $form.find('.sf2-element-state-error').removeClass('sf2-element-state-error'); 188 189 if (responce.status == 'success') { 190 $form.html(responce.html); 191 if (isPopup) { 192 $('.sf2Win .sf2SendBtn').remove(); 193 } 194 195 } else if (responce.status == 'error') { 196 SF2.showError(responce.message); 197 if (responce.elements) { 198 var k; 199 while (k in responce.elements) { 200 $form.find('#' + k).addClass('sf2-element-state-error'); 201 } 202 } 203 } else { 204 SF2.showError('AJAX server error.'); 205 } 206 }, 207 'error': function (jqXHR, textStatus, errorThrown) { 208 if (typeof grecaptcha !== 'undefined' && grecaptcha) { 209 grecaptcha.reset(); 210 } 211 SF2.hideLoading(lid); 212 SF2.showError(errorThrown); 213 } 214 }); 215 return false; 216 }); 217 }); 218 } 219 } 220 221 SF2.Config.prototype = { 222 get: function (paramName) { 223 if (this.cfg[paramName]) { 224 return this.cfg[paramName]; 225 } 226 return null; 227 }, 228 }; 229 230 var SF2Window = window.SF2Window = function (_container, _id, _isModal) { 231 var html, 232 win, 233 modal, 234 body, 235 sendBtn, 236 closeBtn; 237 var winExists = false; 238 var self = this; 239 var form = _container.find('form'); 240 if (!_id) { 241 _id = 'sf2Win_' + SF2.getRandomInt(9999, 99999); 242 } 243 if ($('#' + _id).length > 0) { 244 winExists = true; 245 win = this.win = $('#' + _id).closest('.sf2Shade'); 246 } else { 247 var classes = ['sf2Win']; 248 $.each(form.attr('class').split(/\s+/), function (index, _cls) { 249 if (_cls.match(/^sf2Style\-/)) { 250 classes.push(_cls); 251 } 252 }); 253 html = '<div class="sf2Shade"><div class="' + classes.join(' ') + '" id="' + _id + '">'; 254 html += '<div class="sf2Win-body"></div>'; 255 html += '<div class="sf2Win-footer">'; 256 if (form.find('input,select,textarea').length > 0) { 257 var hasButton = form.find('input[type="submit"],button[type="submit"]'); 258 if (hasButton.length) { 259 hasButton = hasButton.hide().clone().show(); 260 hasButton.attr('type', 'button'); 261 hasButton.addClass('sf2SendBtn'); 262 html += hasButton.prop('outerHTML'); 263 } else { 264 html += '<button type="button" class="sf2-element sf2SendBtn">' + SF2.Text('send') + '</button>'; 265 } 266 } 267 html += '<button type="button" class="sf2-element sf2CloseBtn">' + SF2.Text('close') + '</button>'; 268 html += '</div>'; 269 html += '</div></div>'; 270 win = this.win = $(html).appendTo('body').click(); 271 } 272 modal = this.modal = win.find('.sf2Win'); 273 body = this.body = win.find('.sf2Win-body'); 274 sendBtn = this.sendBtn = win.find('.sf2SendBtn'); 275 closeBtn = this.closeBtn = win.find('.sf2CloseBtn'); 276 277 body.append(form.detach()); 278 win.on('sf2Close', function () { 279 self.onClose(); 280 win.animate({ 281 opacity: 0 282 }, 200, 'swing', function () { 283 _container.append(form.detach()); 284 win.remove(); 285 }); 286 modal.animate({ 287 'margin-top': -100 288 }, 200, 'swing'); 289 }); 290 win.on('click', function (e) { 291 var target = $(e.target); 292 if (target.is('.sf2CloseBtn') || (!_isModal && target.is('.sf2Shade'))) { 293 win.trigger('sf2Close'); 294 } else if (target.is('.sf2SendBtn')) { 295 form.submit(); 296 } 297 }); 298 win.css({ 299 opacity: 0 300 }); 301 modal.css({ 302 'margin-top': -100 303 }); 304 win.animate({ 305 opacity: 1 306 }, 300, 'swing'); 307 modal.animate({ 308 'margin-top': 0 309 }, 300, 'swing'); 310 }; 311 312 SF2Window.prototype = { 313 close: function () { 314 this.win.trigger('sf2Close'); 315 }, 316 onClose: function () {}, 317 getWin: function () { 318 return this.win; 319 }, 320 getModal: function () { 321 return this.modal; 322 }, 323 setContent: function (_html) { 324 this.body.html(_html); 325 }, 326 getContentBlock: function () { 327 return this.body; 328 }, 329 }; 330 331 $(document).ready(function () { 332 SF2.init(); 333 });
334 335})(jQuery);
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.