1/** 2 * Created by Admin on 7/2/2018. 3 */ 4jQuery(document).ready(function ($) { 5 var form_trigger = '.ef4-payments-trigger[data-target]', form_selector = '.ef4-payment-form'; 6 $(document).on('click', form_trigger, function (e) { 7 var $this = $(this); 8 if ($this.is('a')) 9 e.preventDefault(); 10 show_form($this.attr('data-target'), $this.attr('data-options')); 11 }).on('submit', form_selector + ' form', function (e) { 12 e.preventDefault(); 13 submit_form($(this)); 14 }).on('click',form_selector + ' .form-close',function (e) { 15 e.preventDefault(); 16 close_form(this); 17 }); 18 var ajax_save_running; 19 function close_form(el) { 20 var $el = $(el); 21 var modal = $el.closest(form_selector); 22 if(!modal.is('.modal')) 23 modal = modal.closest('.modal'); 24 modal.modal('hide'); 25 } 26 function submit_form(form) { 27 var data = { 28 data: get_input_data(form, '[name]'), 29 action: ef4_payments['settings']['action'], 30 nonce: ef4_payments['settings']['nonce'] 31 }; 32 ajax_save_running = true; 33 var form_container = form.closest(form_selector); 34 form_container.find('.view-single[data-name="payment-loading"]').trigger('show'); 35 $.ajax({ 36 type: "POST", 37 url: ef4_payments['settings']['ajaxurl'], 38 data: data, 39 success: function (response) { 40 render_response_payment_form(response,form); 41 }, 42 dataType: 'JSON' 43 }).fail(function () { 44 form_container.find('.view-single[data-name="payment-fail"]').trigger('show'); 45 }).always(function () { 46 ajax_save_running = false; 47 }); 48 } 49 function render_response_payment_form(response,form) { 50 var container = (form.is(form_selector)) ? form : form.closest(form_selector); 51 switch (response['status']) 52 { 53 case 'success': 54 var result_container = container.find('.view-single[data-name="payment-result"]'); 55 result_container.html(response['message']); 56 if(response['action'] && typeof response['action'] == 'object') 57 { 58 do_extend_action(response['action']); 59 } 60 extends_modify_view(result_container); 61 result_container.trigger('show'); 62 break; 63 case 'fail': 64 var fail_container = container.find('.view-single[data-name="payment-fail"]'); 65 fail_container.html = response['message']; 66 if(typeof response['action'] == 'object') 67 { 68 do_extend_action(response['action']); 69 } 70 fail_container.trigger('show'); 71 break; 72 } 73 74 } 75 function extends_modify_view(view) { 76 view.find('.show-if-match').each(function () { 77 var $this= $(this),match = $this.attr('data-match'),check = $this.attr('data-check'); 78 if(match == check) 79 $this.show(); 80 else 81 $this.hide(); 82 }); 83 view.find('.hidden-if-empty[data-check=""]').hide(); 84 } 85 function do_extend_action(action) { 86 if(typeof action != 'object') 87 return; 88 switch (action['type']) 89 { 90 case 'redirect': 91 var delay = (action['data']['delay']) ? parseInt(action['data']['delay'])*1000 : 100 ; 92 setTimeout(function () { 93 window.location = action['data']['url']; 94 },delay); 95 break; 96 } 97 } 98 function show_form(target, item) { 99 var form = $(form_selector + '[data-target="' + target + '"]'); 100 var data = ef4_payments['items'][target][item]; 101 if (!data) 102 return; 103 var items_id = []; 104 form.find('.dynamic-element').remove(); 105 form.find('.dynamic-data').each(function () { 106 var $this = $(this), element = $this.attr('data-target'), 107 template = $this.attr('data-template'), mode = $this.attr('data-insert-mode'), 108 cr_el, k, cr_template ,special_key = 'special', special_prefix = special_key+':'; 109 if(element.indexOf(special_prefix) != -1) 110 { 111 //handle for special field; 112 var sp_key = element.substr(special_prefix.length); 113 var current_val = data[special_key][sp_key]; 114 if(!current_val) 115 return; 116 for(var key in current_val) 117 { 118 if(current_val.hasOwnProperty(key)) 119 { 120 cr_template = template; 121 cr_template = replace_data(cr_template, {key:key,value:current_val[key]}); 122 cr_template = $(cr_template).addClass('dynamic-element'); 123 switch (mode) { 124 case 'after': 125 cr_template.insertAfter($this); 126 break; 127 default: 128 $this.append(cr_template); 129 } 130 } 131 } 132 return; 133 }; 134 if (!data[element]) 135 return; 136 for (k in data[element]) { 137 if (!data[element].hasOwnProperty(k)) 138 continue; 139 if (element == 'items' && items_id.indexOf(k) === -1) 140 items_id.push(k); 141 cr_el = data[element][k]; 142 cr_template = template; 143 cr_template = replace_data(cr_template, cr_el); 144 cr_template = $(cr_template).addClass('dynamic-element'); 145 switch (mode) { 146 case 'after': 147 cr_template.insertAfter($this); 148 break; 149 default: 150 $this.append(cr_template); 151 } 152 } 153 }); 154 form.find('.dynamic-attr').each(function () { 155 var $this = $(this), options = json_tryparse($this.attr('data-options')) 156 , attr, items, value, k, el, seg, join, wrap; 157 for (attr in options) { 158 if (!options.hasOwnProperty(attr)) 159 continue; 160 el = options[attr]['elements']; 161 seg = options[attr]['segment']; 162 join = options[attr]['join']; 163 wrap = options[attr]['wrap']; 164 if (!el || !data[el] || !seg) 165 continue; 166 items = data[el]; 167 value = []; 168 for (k in items) { 169 if (!items.hasOwnProperty(k)) 170 continue; 171 value.push(replace_data(seg, items[k])); 172 if (!join) 173 break; 174 } 175 if (wrap) 176 value = wrap.split('{-value-}').join(value.join(join)); 177 else 178 value = value.join(join); 179 $this.attr(attr, value); 180 } 181 }); 182 183 $(document).trigger('ef4.math.cal'); 184 185 var payment_required_fields = { 186 'form-type': data['settings']['form_type'], 187 'form-item-source': data['settings']['form_item_source'], 188 'form-items': items_id.join(','), 189 'form-request-url':window.location.toString() 190 }; 191 for (var name in payment_required_fields) 192 if (payment_required_fields.hasOwnProperty(name)) { 193 if (form.find('form [name="' + name + '"]').length < 1) 194 form.find('form').append('<input type="hidden" name="' + name + '">') 195 form.find('form [name="' + name + '"]').val(payment_required_fields[name]); 196 } 197 form.trigger('ef4.view.initial'); 198 form.modal(); 199 } 200 201 function get_input_data(container, mask) { 202 if (!mask) mask = 'input-field'; 203 var data = {}; 204 container.find(mask).each(function () { 205 var $this = jQuery(this); 206 if (!$this.attr('name')) return; 207 if ($this.is(':checkbox')) { 208 data[$this.attr('name')] = ($this.is(':checked')) ? 'yes' : 'no'; 209 } else if ($this.is(':radio')) { 210 if ($this.is(':checked')) 211 data[$this.attr('name')] = $this.val(); 212 } 213 else { 214 data[$this.attr('name')] = $this.val(); 215 } 216 }); 217 return data; 218 } 219 220 function replace_data(str, data) { 221 for (var k in data) { 222 if (!data.hasOwnProperty(k)) 223 continue; 224 str = str.split('{{_' + k + '_}}').join(data[k]); 225 } 226 return str; 227 } 228 229 function json_tryparse(str) { 230 var result = {}; 231 try { 232 result = JSON.parse(str) 233 } 234 catch (e) { 235 result = {} 236 } 237 return result; 238 } 239});
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.