123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134 |
- // @codekit-prepend "gui.js"
- // @koala-prepend "gui.js"
- (function($) {
- MaterioUser = function(){
-
- var _isAdhesion = $('body').is('.page-node-11187') || $('body').is('.page-node-11186');
- function init() {
- //trace('MaterioUser init compile test 3');
- if(_isAdhesion)
- initAdhesion();
- };
- function initAdhesion(){
- //trace('initAdhesion');
- $('.get-link a').bind('click', function(event) {
- // do not show the registration form if already logged-in
- if($('body').is('.logged-in'))
- return true;
- // else show the ajaxified registration form
- event.preventDefault();
- var $this = $(this),
- href = $this.attr("href"),
- destination = href.match('/\?destination=([^,]+)');
- destination = "/" + destination[1].replace('%23', '#');
- trace('destination', destination);
- loadRegistrationBlock(destination);
- return false;
- });
- };
- function loadRegistrationBlock(destination){
- //trace('loadRegistrationBlock :: dest = '+dest);
- $.getJSON(Drupal.settings.basePath+Drupal.settings.pathPrefix+'materio_user/register',
- // {'types':types,'current_path':document.location.href, 'keys':keys, 'searchmode':searchmode},
- function(json){
- //trace('json', json);
-
- var $modal = $('<div>').addClass('modal-content').append(json.block);
-
- // $.event.trigger({
- // type:"form-loaded",
- // context:"modal-content"
- // });
- 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);
- });
- // $('.homepage-textfield', $modal).hide();
- $('body').append($('<div>').addClass('modal-wrapper').append($modal));
- // doesn't work
- // Drupal.attachBehaviors('bodi>.modal-wrapper');
- $.event.trigger('ajax-register-block-loaded');
- $("#user-register-form #edit-submit--2", $modal).click(function(event){
- event.preventDefault();
- $.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(data, destination);},
- error: function() {trace('error');}
- });
- 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(data, destination); },
- error: function() { trace('error'); }
- });
- return false;
- });
- // google analytics
- // $.event.trigger({
- // type : "record-stat",
- // categorie : 'Search',
- // action : keys,
- // label : 'filters : '+ stringTypes.join(' ,'),
- // value : json.count
- // });
- });
- };
- function onUserLoginRegisterSubmit(data, destination){
- cleanModalErrors();
- if(data.errors != null){
- for(field in data.errors){
- $('#user-login input[name='+field+']', '.modal-content').addClass('error');
- $('.modal-content').prepend($('<div>').addClass('message-error').html(data.errors[field]));
- }
- }else{
- window.location.pathname = destination;
- }
- };
- function cleanModalErrors() {
- $('.message-error', '.modal-content').remove();
- $('input', '.modal-content').removeClass('error');
- }
- init();
- };
- $(document).ready(function() {
- var materiouser = new MaterioUser();
- });
-
- })(jQuery);
|