Skip to content

Instantly share code, notes, and snippets.

@fakedarren
Created August 12, 2011 12:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fakedarren/1141970 to your computer and use it in GitHub Desktop.
Save fakedarren/1141970 to your computer and use it in GitHub Desktop.
Abacus.InitPopup = function(context){
if (Abacus.BeforeInitPopup){
Abacus.BeforeInitPopup(context);
}
context.getElements('form').addEvent('submit', function(evt){
if (!this.hasClass('no-ajax')) evt.stop();
});
context.getElements('button').addEvent('click', function(evt){
var parentform = $(this).getParent('form');
if (parentform){
var validator = parentform.retrieve('validator');
if (validator && !validator.validate()){
evt.stop();
} else {
if (this.get('type') == 'submit' && !parentform.hasClass('no-ajax')){
var form = parentform.toObject();
var trigger = {
name: $(this).get('name'),
value: $(this).get('value').replace(/<[^>]+>/gi, '') || 'true'
};
if (name) form[trigger.name] = trigger.value;
new Request.HTML({
url: $(this).getParent('form').get('action'),
method: $(this).getParent('form').get('method') || 'post',
headers: {
'X-Requested-With': 'Popup'
},
data: form,
onSuccess: function(tree, els, html, js){
popup.content.set('html', html);
Abacus.InitUI(popup.element);
Abacus.InitPopup(popup.element);
popup.show();
Browser.exec(js);
}
}).send();
} else if (!parentform.hasClass('no-ajax')){
evt.stop();
}
}
}
});
context.getElements('[type=text], [type=password]').addEvent('keypress', function(evt){
if (evt.key == 13){
this.getParent('form').getElement('[type=submit]').fireEvent('click');
}
});
if (Abacus.AfterInitPopup){
Abacus.AfterInitPopup(context);
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment