1jQuery(document).ready(function($){ 2 3 var formsTrigger = { 4 'xoo-el-login-tgr': 'login', 5 'xoo-el-reg-tgr': 'register', 6 'xoo-el-lostpw-tgr': 'lostpw', 7 'xoo-el-resetpw-tgr': 'resetpw' 8 } 9 10 class Container{ 11 12 constructor( $container ){ 13 this.$container = $container; 14 this.$tabs = $container.find('ul.xoo-el-tabs').length ? $container.find( 'ul.xoo-el-tabs' ) : null; 15 this.display = $container.hasClass('xoo-el-form-inline') ? 'inline' : 'popup'; 16 17 if( this.$container.attr('data-active') ){ 18 this.toggleForm( this.$container.attr('data-active') ); 19 } 20 21 this.eventHandlers(); 22 } 23 24 eventHandlers(){ 25 this.formTriggerEvent(); 26 this.$container.on( 'submit', '.xoo-el-action-form', this.submitForm.bind(this) ) ; 27 } 28 29 30 formTriggerEvent(){ 31 var container = this; 32 $.each( formsTrigger, function( triggerClass, formType ){ 33 $( container.$container ).on( 'click', '.' + triggerClass, function(e){ 34 e.preventDefault(); 35 e.stopImmediatePropagation(); 36 container.toggleForm(formType); 37 } ) 38 } ); 39 } 40 41 42 toggleForm( formType ){ 43 44 this.$container.attr( 'data-active', formType ); 45 46 var $section = this.$container.find('.xoo-el-section[data-section="'+formType+'"]'), 47 activeClass = 'xoo-el-active'; 48 49 //Setting section 50 if( $section.length ){ 51 this.$container.find('.xoo-el-section').removeClass( activeClass ); 52 $section.addClass( activeClass ); 53 $section.find('.xoo-el-notice').html('').hide(); 54 $section.find('.xoo-el-action-form').show(); 55 } 56 57 //Setting Tab 58 if( this.$tabs ){ 59 this.$tabs.find('li').removeClass( activeClass ); 60 if( this.$tabs.find('li[data-tab="'+formType+'"]').length ){ 61 this.$tabs.find('li[data-tab="'+formType+'"]').addClass( activeClass ); 62 } 63 } 64 65 $(document.body).trigger( 'xoo_el_form_toggled', [ formType, this ] ); 66 67 } 68 69 70 submitForm(e){ 71 72 e.preventDefault(); 73 74 var $form = $(e.currentTarget), 75 $button = $form.find('button[type="submit"]'), 76 $section = $form.parents('.xoo-el-section'), 77 buttonTxt = $button.text(), 78 $notice = $section.find('.xoo-el-notice'), 79 formType = $section.attr('data-section'), 80 container = this; 81 82 $button.html( xoo_el_localize.html.spinner ).addClass('xoo-el-processing'); 83 84 var form_data = $form.serialize() + '&action=xoo_el_form_action' + '&display=' + container.display; 85 86 $.ajax({ 87 url: xoo_el_localize.adminurl, 88 type: 'POST', 89 data: form_data, 90 success: function(response){ 91 92 $button.removeClass('xoo-el-processing').html(buttonTxt); 93 94 //Unexpected response 95 if( response.error === undefined ){ 96 console.log(response); 97 location.reload(); 98 return; 99 } 100 101 if( response.notice ){ 102 103 $notice.html(response.notice).show(); 104 105 //scrollbar position 106 if( container.display === 'inline' ){ 107 $('html, body').animate({ scrollTop: $notice.offset().top - 100}, 500); 108 } 109 110 } 111 112 if ( response.error === 0 ){ 113 114 if( response.redirect ){ 115 //Redirect 116 setTimeout(function(){ 117 window.location = response.redirect; 118 }, xoo_el_localize.redirectDelay ); 119 } 120 else{ 121 $form.hide(); 122 } 123 124 $form.trigger('reset'); 125 126 if( formType === 'resetpw' ){ 127 $form.add( '.xoo-el-resetpw-hnotice' ).remove(); 128 } 129 130 } 131 132 $( document.body ).trigger( 'xoo_el_form_submitted', [ response, $form, container ] ); 133 134 } 135 }) 136 } 137 138 } 139 140 141 class Popup{ 142 143 constructor( $popup ){ 144 this.$popup = $popup; 145 this.eventHandlers(); 146 this.initScrollbar(); 147 } 148 149 eventHandlers(){ 150 this.$popup.on( 'click', '.xoo-el-close, .xoo-el-modal', this.closeOnClick.bind(this) ); 151 $( document.body ).on( 'xoo_el_form_submitted', this.onFormSubmitSuccess.bind(this) ); 152 this.$popup.on( 'click', '.xoo-el-action-btn', this.setScrollBarOnSubmit.bind(this) ); 153 $(window).on('hashchange load', this.openViaHash.bind(this) ); 154 this.triggerPopupOnClick(); //Open popup using link 155 } 156 157 triggerPopupOnClick(){ 158 159 $.each( formsTrigger, function( triggerClass, formType ){ 160 161 $( document.body ).on( 'click', '.' + triggerClass, function(e){
162 163 if( $(this).parents( '.xoo-el-form-container' ).length ) return true; //Let container class handle 164 165 e.preventDefault(); 166 e.stopImmediatePropagation(); 167 168 popup.toggle('show'); 169 170 if( $(this).attr( 'data-redirect' ) ){ 171 popup.$popup.find('input[name="xoo_el_redirect"]').val( $(this).attr('data-redirect') ); 172 } 173 174 popup.$popup.find( '.'+triggerClass ).trigger('click'); 175 176 return false; 177 178 }) 179 180 }) 181 182 } 183 184 initScrollbar(){ 185 this.$scrollbar = Scrollbar.init( this.$popup.find('.xoo-el-srcont').get(0) ); 186 } 187 188 toggle( type ){ 189 var $els = this.$popup.add( 'body' ), 190 activeClass = 'xoo-el-popup-active'; 191 192 if( type === 'show' ){ 193 $els.addClass(activeClass); 194 } 195 else if( type === 'hide' ){ 196 $els.removeClass(activeClass); 197 } 198 else{ 199 $els.toggleClass(activeClass); 200 } 201 202 $(document.body).trigger( 'xoo_el_popup_toggled', [ type ] ); 203 } 204 205 closeOnClick(e){ 206 var elClassList = e.target.classList; 207 if( elClassList.contains( 'xoo-el-close' ) || elClassList.contains('xoo-el-modal') ){ 208 this.toggle('hide'); 209 } 210 } 211 212 setScrollbarPosition( position ){ 213 this.$scrollbar.scrollTop = position || 0; 214 } 215 216 onFormSubmitSuccess( e, response, $form, container ){ 217 this.setScrollbarPosition(); 218 } 219 220 setScrollBarOnSubmit(e){ 221 var invalid_els = $(e.currentTarget).closest('form').find('input:invalid'); 222 if( invalid_els.length === 0 ) return; 223 this.setScrollbarPosition( invalid_els.filter(":first").closest('.xoo-aff-group').position().top ); 224 } 225 226 openViaHash(){ 227 228 var hash = $(location).attr('hash'); 229 230 if( hash === '#login' || hash === '#register' ){ 231 232 this.toggle('show'); 233 234 //Clear hash 235 var uri = window.location.toString(), 236 clean_uri = uri.substring( 0, uri.indexOf("#") ); 237 238 window.history.replaceState( 239 {}, 240 document.title, clean_uri 241 ); 242 } 243 244 if( hash === '#login' ){ 245 this.$popup.find('.xoo-el-login-tgr').trigger('click'); 246 } 247 else if( hash === '#register' ){ 248 this.$popup.find('.xoo-el-reg-tgr').trigger('click'); 249 } 250 251 } 252 253 254 } 255 256 class Form{ 257 258 constructor( $form ){ 259 this.$form = $form; 260 } 261 262 eventHandlers(){ 263 264 } 265 266 } 267 268 var popup = null; 269 270 //Popup 271 if( $('.xoo-el-container').length ){ 272 popup = new Popup( $('.xoo-el-container') ); 273 } 274 275 276 //Auto open popup 277 if( xoo_el_localize.autoOpenPopup === 'yes' && localStorage.getItem( "xoo_el_popup_opened" ) !== "yes" ){ 278 279 if( xoo_el_localize.autoOpenPopupOnce === "yes" ){ 280 localStorage.setItem( "xoo_el_popup_opened", "yes" ); 281 } 282 283 setTimeout(function(){ 284 popup.toggle('show'); 285 }, xoo_el_localize.aoDelay); 286 } 287 288 289 $('.xoo-el-form-container').each(function( key, el ){ 290 new Container( $(el) ); 291 }) 292 293 //Trigger popup if reset field is active 294 if( $('form.xoo-el-form-resetpw').length ){ 295 if( $('.xoo-el-form-inline').length ){ 296 $([document.documentElement, document.body]).animate({ 297 scrollTop: $(".xoo-el-form-inline").offset().top 298 }, 500); 299 } 300 else{ 301 if( popup ){ 302 popup.toggle('show'); 303 } 304 } 305 } 306 307 308 if( $( 'body.woocommerce-checkout' ).length && $('.xoo-el-form-inline').length && $( 'a.showlogin' ).length ){ 309 var $inlineForm = $('.xoo-el-form-inline'); 310 $inlineForm.hide(); 311 $( document.body ).on( 'click', 'a.showlogin', function(){ 312 $inlineForm.slideToggle(); 313 $inlineForm.find('.xoo-el-login-tgr').trigger('click'); 314 } ); 315 } 316 317 318})
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.