new membership and account creation process : modal and form is in a separated page
This commit is contained in:
134
js/materio_user.js
Executable file
134
js/materio_user.js
Executable file
@@ -0,0 +1,134 @@
|
||||
// @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);
|
1
js/materio_user.min.js
vendored
Executable file
1
js/materio_user.min.js
vendored
Executable file
@@ -0,0 +1 @@
|
||||
!function(t){MaterioUser=function(){function e(){a&&r()}function r(){t(".get-link a").bind("click",function(e){e.preventDefault();var r=t(this),a=r.attr("href").match("/?destination=([^,]+)/");return i(a),!1})}function i(){t.getJSON(Drupal.settings.basePath+Drupal.settings.pathPrefix+"materio_user/register",function(e){var r,i,a,n=t("<div>").addClass("modal-content").append(e.block);t("input.form-text",n).each(function(){r=t(this).attr("id"),i=t("label[for="+r+"]").hide().text(),a=t(this).parent().find(".description").hide().text(),t(this).attr("placeholder",i).attr("title",a)}),t("body").append(t("<div>").addClass("modal-wrapper").append(n)),t.event.trigger("ajax-register-block-loaded"),t("#user-register-form #edit-submit--2").click(function(e){return e.preventDefault(),t.ajax({type:"POST",dataType:"json",url:Drupal.settings.basePath+Drupal.settings.pathPrefix+"materio_user/register/submit",data:t("#user-register-form",n).serialize(),success:function(){},error:function(){}}),!1})})}var a=t("body").is(".page-node-11187")||t("body").is(".page-node-11186");e()},t(document).ready(function(){new MaterioUser})}(jQuery);
|
Reference in New Issue
Block a user