improve modale registration and login forms
This commit is contained in:
@@ -30,89 +30,93 @@ MaterioUser = function(){
|
||||
destination = href.match('/\?destination=([^,]+)');
|
||||
|
||||
destination = "/" + destination[1].replace('%23', '#');
|
||||
trace('destination', destination);
|
||||
destination = destination.replace('//', '/');
|
||||
// trace('destination', destination);
|
||||
|
||||
loadRegistrationBlock(destination);
|
||||
if($this.parents('.gratos').size()){
|
||||
loadRegisterBlock(destination);
|
||||
}else{
|
||||
loadLoginAndRegisterBlock(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));
|
||||
|
||||
$('.modal-wrapper').bind('click', function(event) {
|
||||
$(this).remove();
|
||||
});
|
||||
|
||||
$('.modal-content').bind('click', function(event) {
|
||||
event.stopPropagation();
|
||||
});
|
||||
|
||||
// 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($('#user-register-form'), 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($('#user-login'), 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 loadRegisterBlock (destination) {
|
||||
trace("loadRegisterBlock :: dest = "+destination);
|
||||
$.getJSON(Drupal.settings.basePath+Drupal.settings.pathPrefix+'materio_user/registerblock', formLoaded);
|
||||
}
|
||||
|
||||
function loadLoginAndRegisterBlock(destination){
|
||||
//trace('loadRegistrationBlock :: dest = '+destination);
|
||||
$.getJSON(Drupal.settings.basePath+Drupal.settings.pathPrefix+'materio_user/loginandregisterblock', function(json){formLoaded(json, destination);});
|
||||
};
|
||||
|
||||
function formLoaded(json, destination){
|
||||
//trace('formLoaded | json', json);
|
||||
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);
|
||||
});
|
||||
|
||||
// $('.homepage-textfield', $modal).hide();
|
||||
|
||||
$('body').append($('<div>').addClass('modal-wrapper').append($modal));
|
||||
|
||||
$('.modal-wrapper').bind('click', function(event) {
|
||||
$(this).remove();
|
||||
});
|
||||
|
||||
$('.modal-content').bind('click', function(event) {
|
||||
event.stopPropagation();
|
||||
});
|
||||
|
||||
// doesn't work
|
||||
// Drupal.attachBehaviors('bodi>.modal-wrapper');
|
||||
|
||||
$.event.trigger('ajax-register-block-loaded');
|
||||
|
||||
$("#user-register-form #edit-submit, #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($('#user-register-form'), 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($('#user-login'), 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($form, data, destination){
|
||||
|
Reference in New Issue
Block a user