PluginProbe
MaxButtons – Create buttons / 6.23
MaxButtons – Create buttons v6.23
6.23 6.24 6.25 6.26 6.26.1 6.27 6.28 6.3 6.4 6.5 6.6 6.7 6.8 6.9 7.0 7.1 7.1.1 7.1.2 7.1.3 7.10 7.11 7.13 7.13.1 7.13.2 7.13.3 All 100 releases
maxbuttons / js / min / maxajax.js

maxajax.js in MaxButtons – Create buttons 6.23, at js/min/maxajax.js

137 lines 3.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1
2 /** New AJAX Call methods
3 /* Get the standard AJAX vars for this plugin */
4
5 var maxAjax = function(jquery) {
6 $ = jquery;
7
8 }
9
10 maxAjax.prototype.init = function()
11 {
12
13 // default actions that trigger ajax action.
14 $(document).on('click', '.mb-ajax-form .mb-ajax-submit', $.proxy(this.ajaxForm, this ));
15 $(document).on('click', '.mb-ajax-action', $.proxy(this.ajaxCall, this ));
16 $(document).on('change', '.mb-ajax-action-change', $.proxy(this.ajaxCall, this));
17 $(document).trigger('maxajax_init'); // for hanging in other actions.
18 }
19
20 maxAjax.prototype.ajaxInit = function()
21 {
22 data = {
23 action: maxajax.ajax_action,
24 nonce: maxajax.nonce,
25 }
26
27 return data;
28 }
29
30 maxAjax.prototype.ajaxForm = function (e)
31 {
32 var target = $(e.target);
33 var form = $(target).parents('form');
34 var action = $(target).data('action');
35
36 var data = this.ajaxInit();
37 data['form'] = form.serialize();
38 data['plugin_action'] = action;
39 // data['action'] = 'mb_button_action';
40
41 this.showSpinner(target);
42
43 this.ajaxPost(data);
44
45
46 }
47
48 /* Ajax call functionality */
49 maxAjax.prototype.ajaxCall = function (e)
50 {
51
52 e.preventDefault();
53 var target = e.target;
54
55 var param = false;
56 var plugin_action = $(target).data('action');
57 var check_param = $(target).data('param');
58 var param_input = $(target).data('param-input');
59
60 if (typeof check_param !== 'undefined')
61 param = check_param;
62 if (typeof param_input !== 'undefined')
63 param = $(param_input).val();
64
65 data = this.ajaxInit();
66
67 data['plugin_action'] = plugin_action;
68 data['param'] = param;
69 data['post'] = $('form').serialize(); // send it all
70
71 this.showSpinner(target);
72
73 this.ajaxPost(data);
74 }
75
76 maxAjax.prototype.showSpinner = function(target)
77 {
78 var spinner = '<div class="ajax-load-spinner"></div>';
79 $('.ajax-load-spinner').remove();
80 $(target).after(spinner);
81 //return spinner;
82 }
83
84 maxAjax.prototype.ajaxPost = function(data, successHandler, errorHandler)
85 {
86 var self = this;
87
88 if (typeof successHandler == 'undefined')
89 {
90 var action = data['plugin_action'];
91 var successHandler = function (r,s,o,) { self.defaultSuccessHandler(r,s,o,action) } ;
92
93 }
94
95 if (typeof errorHandler == 'undefined')
96 {
97 var action = data['plugin_action'];
98 var errorHandler = function (r,s,o,) { self.defaultErrorHandler(r,s,o,action) } ;
99 }
100
101
102 $.ajax({
103 type: "POST",
104 url: maxajax.ajax_url,
105 data: data,
106 success: successHandler,
107 error: errorHandler,
108 });
109 }
110
111 maxAjax.prototype.defaultSuccessHandler = function (result, status, object, action)
112 {
113 $(document).trigger('maxajax_success_' + action, [result, status, object]);
114
115 }
116
117 maxAjax.prototype.defaultErrorHandler = function(jq,status,error, action)
118 {
119 $(document).trigger('maxajax_error_' + action, jq, status, error);
120 console.log(jq);
121 console.log(status);
122 console.log(error);
123 }
124
125
126 jQuery(document).ready(function($) {
127
128 if (typeof window.maxFoundry === 'undefined')
129 window.maxFoundry = {} ;
130
131 window.maxFoundry.maxAjax = new maxAjax($);
132
133 window.maxFoundry.maxAjax.init();
134
135 }); /* END OF JQUERY */
136
137