This repository has been archived by the owner on Nov 10, 2017. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
jquery.replace_location.js
53 lines (51 loc) · 1.87 KB
/
jquery.replace_location.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
(function($) {
"use strict";
$.fn.replace_location = function(options) {
$.fn.replace_location.defaults = {
replaceLocation: 'replaceLocation',
ajaxType: 'POST',
replaceLocationURLAttr: 'href',
replaceLocationURLFormAttr: 'action'
};
var opts = $.extend({}, $.fn.replace_location.defaults, options);
$(this).live({
'change': function(event){
var formElement = $(this);
if(formElement.attr(opts.replaceLocationURLAttr) !== null && formElement.attr(opts.replaceLocationURLAttr) !== undefined){
$.ajax({
url: formElement.attr(opts.replaceLocationURLAttr),
data: formElement.serialize(),
success: function(data){ $(formElement.data(opts.replaceLocation)).html(data + " Fired from Change event handler."); },
type: opts.ajaxType
});
event.preventDefault();
}
},
'submit': function(event){
var formElement = $(this);
if(formElement.attr(opts.replaceLocationURLFormAttr) !== null && formElement.attr(opts.replaceLocationURLFormAttr) !== undefined){
$.ajax({
url: formElement.attr(opts.replaceLocationURLFormAttr),
data: formElement.serialize(),
success: function(data){ $(formElement.data(opts.replaceLocation)).html(data + " Fired from Submit event handler."); },
type: opts.ajaxType
});
event.preventDefault();
}
},
'click': function(event){
if(event.target.nodeName !== "SELECT" || event.target.nodeName !== "OPTION"){
var formElement = $(this);
if(formElement.attr(opts.replaceLocationURLAttr) !== null && formElement.attr(opts.replaceLocationURLAttr) !== undefined){
$.ajax({
url: formElement.attr(opts.replaceLocationURLAttr),
data: formElement.serialize(),
success: function(data){ $(formElement.data(opts.replaceLocation)).html(data + " Fired from Click event handler."); },
type: opts.ajaxType
});
event.preventDefault();
}
}
}
});
};})(jQuery);