materio_user.min.js 2.9 KB

123456
  1. (function($){MaterioUser=function(){var _isAdhesion=$('body').is('.page-node-11187')||$('body').is('.page-node-11186');function init(){if(_isAdhesion)
  2. initAdhesion();};function initAdhesion(){$('.get-link a').bind('click',function(event){if($('body').is('.logged-in'))
  3. return true;event.preventDefault();var $this=$(this),href=$this.attr("href"),destination=href.match('/\?destination=([^,]+)');destination="/"+destination[1];destination=destination.replace('//','/');loadLoginAndRegisterBlock(destination);return false;});};function loadLoginAndRegisterBlock(destination){$.getJSON(Drupal.settings.basePath+Drupal.settings.pathPrefix+'materio_user/loginandregisterblock',function(json){formLoaded(json,destination);});};function formLoaded(json,destination){var $modal=$('<div>').addClass('modal-content').append(json.block);var id,label,description;$('input.form-text',$modal).each(function(i){id=$(this).attr('id');label=$('label[for='+id+']').hide().text();description=$(this).parent().find('.description').hide().text();$(this).attr('placeholder',label).attr('title',description);});$('body').append($('<div>').addClass('modal-wrapper').append($modal));$('.modal-wrapper').bind('click',function(event){$(this).remove();});$('.modal-content').bind('click',function(event){event.stopPropagation();});$.event.trigger('ajax-register-block-loaded');$("#user-register-form #edit-submit, #user-register-form #edit-submit--2",$modal).click(function(event){event.preventDefault();$(this).attr('disabled','true');$.ajax({type:'POST',dataType:'json',url:Drupal.settings.basePath+Drupal.settings.pathPrefix+"materio_user/register/submit",data:$('#user-register-form',$modal).serialize(),success:function(data){onUserLoginRegisterSubmit($('#user-register-form'),data,destination);},error:function(jqXHR,textStatus,errorThrown){trace('error : '+textStatus+' | '+errorThrown);}});return false;});$("#user-login #edit-submit",$modal).click(function(event){event.preventDefault();$.ajax({type:'POST',dataType:'json',url:Drupal.settings.basePath+Drupal.settings.pathPrefix+"materio_user/login/submit",data:$('#user-login',$modal).serialize(),success:function(data){onUserLoginRegisterSubmit($('#user-login'),data,destination);},error:function(jqXHR,textStatus,errorThrown){trace('error : '+textStatus+' | '+errorThrown);}});return false;});};function onUserLoginRegisterSubmit($form,data,destination){cleanModalErrors();if(data.errors!=null){for(field in data.errors){$('input[name='+field+']',$form).addClass('error');$form.prepend($('<div>').addClass('message-error').html(data.errors[field]));}
  4. (function($form){setTimeout(function(){console.log('enabled');$('input[type=submit]',$form).removeAttr('disabled');},0.5*1000);})($form);}else{window.location=destination.replace('%23','#');}};function cleanModalErrors(){$('.message-error','.modal-content').remove();$('input','.modal-content').removeClass('error');}
  5. init();};$(document).ready(function(){var materiouser=new MaterioUser();});})(jQuery);