Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /****************
- * jnews login & register popup
- ****************/
- window.jnews.loginregister = {
- xhr: null,
- captcha: [],
- validateCaptcha: false,
- show_popup: function (popuplink) {
- var obj = this
- if (popuplink.length > 0) {
- popuplink.magnificPopup({
- type: 'inline',
- removalDelay: 500, //delay removal by X to allow out-animation
- midClick: true,
- // mainClass: 'mfp-zoom-out', // this class is for CSS animation below
- callbacks: {
- beforeOpen: function () {
- this.st.mainClass = 'mfp-zoom-out'
- jnews.body_inject.removeClass('jeg_show_menu')
- },
- change: function () {
- var element = this.content.find('.g-recaptcha')
- var type = this.content.find('form').data('type')
- var key = element.data('sitekey')
- this.content.find('.form-message p').remove()
- obj.validateCaptcha = false
- if ( jnewsoption.recaptcha == 1 && element.length ) {
- if (!element.hasClass('loaded')) {
- obj.captcha[type] = grecaptcha.render(element.get(0), {
- sitekey: key,
- callback: obj.validateResponse.bind(obj),
- })
- $(element).addClass('loaded')
- } else {
- grecaptcha.reset(obj.captcha[type])
- }
- }
- },
- },
- })
- }
- },
- validateResponse: function (response) {
- if (response !== '') {
- this.validateCaptcha = true
- }
- },
- init: function () {
- var popuplink = jnews.body_inject ? jnews.body_inject.find('.jeg_popuplink') : $('.jeg_popuplink')
- this.show_popup(popuplink)
- var popupparent = jnews.body_inject ? jnews.body_inject.find('.jeg_popuplink_parent a') : $('.jeg_popuplink_parent a')
- this.show_popup(popupparent)
- },
- validateForm: function (form) {
- var msg = $(form).find('.form-message')
- var type = $(form).data('type')
- if ('register' === type) {
- var email = $(form).find('[name="email"]').val()
- if ('' === email) {
- msg.html("<p class='alert alert-error'>" + jnewsoption.lang.empty_email + '</p>')
- return false
- }
- }
- if ('login' === type || 'register' === type) {
- var username = $(form).find('[name="username"]').val()
- if ('' === username) {
- msg.html("<p class='alert alert-error'>" + jnewsoption.lang.empty_username + '</p>')
- return false
- }
- }
- if ('login' === type) {
- var password = $(form).find('[name="password"]').val()
- if ('' === password) {
- msg.html("<p class='alert alert-error'>" + jnewsoption.lang.empty_password + '</p>')
- return false
- }
- }
- if ('forgot' === type) {
- var user_login = $(form).find('[name="user_login"]').val()
- if ('' === user_login) {
- msg.html("<p class='alert alert-error'>" + jnewsoption.lang.empty_username + '</p>')
- return false
- }
- }
- // Validate Form
- if (jnewsoption.recaptcha == 1 && !this.validateCaptcha) {
- msg.html("<p class='alert alert-error'>" + jnewsoption.lang.invalid_recaptcha + '</p>')
- return false
- }
- return true
- },
- hook_form: function () {
- var obj = this
- $('.jeg_popupform.jeg_popup_account > form').each(function () {
- var form = this,
- $form = $(form),
- $form_button = $form.find('.button'),
- msg = $form.find('.form-message')
- $form.on('submit', function (e) {
- e.preventDefault()
- if (obj.validateForm(form)) {
- msg.html('')
- $form_button.val($form_button.data('process'))
- if (obj.xhr !== null) obj.xhr.abort()
- obj.xhr = $.post(jnews_ajax_url, {action: 'jnews_refresh_nonce', refresh_action_nonce: 'jnews_nonce'}).always(function (data) {
- if ( data.jnews_nonce ) {
- $form.find('input[name="jnews_nonce"]').val(data.jnews_nonce)
- obj.xhr = $.ajax({
- url: jnews_ajax_url,
- type: 'post',
- dataType: 'json',
- data: $form.serialize(),
- success: function (data) {
- if (data.response === 1) {
- msg.html('<p class=\'alert alert-success\'>' + data.string + '</p>')
- if (data.refresh === 1) {
- window.location = jnewsoption.login_reload
- }
- }
- if (data.response == 0) {
- var type = $form.data('type')
- $form_button.val($form_button.data('string'))
- msg.html('<p class=\'alert alert-error\'>' + data.string + '</p>')
- obj.show_popup(msg.find('.jeg_popuplink'));
- if( typeof grecaptcha !== 'undefined' ) {
- grecaptcha.reset(obj.captcha[type])
- }
- }
- $form_button.val($form_button.data('string'))
- $form.trigger('reset')
- },
- })
- }
- })
- }
- })
- })
- },
- }
Advertisement
Add Comment
Please, Sign In to add comment