1/*! 2SerializeJSON jQuery plugin. 3https://github.com/marioizquierdo/jquery.serializeJSON 4version 2.8.1 (Dec, 2016) 5 6Copyright (c) 2012, 2017 Mario Izquierdo 7Dual licensed under the MIT (http://www.opensource.org/licenses/mit-license.php) 8and GPL (http://www.opensource.org/licenses/gpl-license.php) licenses. 9*/ 10!function (a) { 11 if ("function" == typeof define && define.amd) define(["jquery"], a); else if ("object" == typeof exports) { 12 var b = require("jquery"); 13 module.exports = a(b) 14 } else a(window.jQuery || window.Zepto || window.$) 15}(function (a) { 16 "use strict"; 17 a.fn.serializeJSON = function (b) { 18 var c, d, e, f, g, h, i, j, k, l, m, n, o; 19 return c = a.serializeJSON, d = this, e = c.setupOpts(b), f = d.serializeArray(), c.readCheckboxUncheckedValues(f, e, d), g = {}, a.each(f, function (a, b) { 20 h = b.name, i = b.value, k = c.extractTypeAndNameWithNoType(h), l = k.nameWithNoType, m = k.type, m || (m = c.attrFromInputWithName(d, h, "data-value-type")), c.validateType(h, m, e), "skip" !== m && (n = c.splitInputNameIntoKeysArray(l), j = c.parseValue(i, h, m, e), o = !j && c.shouldSkipFalsy(d, h, l, m, e), o || c.deepSet(g, n, j, e)) 21 }), g 22 }, a.serializeJSON = { 23 defaultOptions: { 24 checkboxUncheckedValue: void 0, 25 parseNumbers: !1, 26 parseBooleans: !1, 27 parseNulls: !1, 28 parseAll: !1, 29 parseWithFunction: null, 30 skipFalsyValuesForTypes: [], 31 skipFalsyValuesForFields: [], 32 customTypes: {}, 33 defaultTypes: { 34 string: function (a) { 35 return String(a) 36 }, number: function (a) { 37 return Number(a) 38 }, boolean: function (a) { 39 var b = ["false", "null", "undefined", "", "0"]; 40 return b.indexOf(a) === -1 41 }, null: function (a) { 42 var b = ["false", "null", "undefined", "", "0"]; 43 return b.indexOf(a) === -1 ? a : null 44 }, array: function (a) { 45 return JSON.parse(a) 46 }, object: function (a) { 47 return JSON.parse(a) 48 }, auto: function (b) { 49 return a.serializeJSON.parseValue(b, null, null, { 50 parseNumbers: !0, 51 parseBooleans: !0, 52 parseNulls: !0 53 }) 54 }, skip: null 55 }, 56 useIntKeysAsArrayIndex: !1 57 }, setupOpts: function (b) { 58 var c, d, e, f, g, h; 59 h = a.serializeJSON, null == b && (b = {}), e = h.defaultOptions || {}, d = ["checkboxUncheckedValue", "parseNumbers", "parseBooleans", "parseNulls", "parseAll", "parseWithFunction", "skipFalsyValuesForTypes", "skipFalsyValuesForFields", "customTypes", "defaultTypes", "useIntKeysAsArrayIndex"]; 60 for (c in b) if (d.indexOf(c) === -1) throw new Error("serializeJSON ERROR: invalid option '" + c + "'. Please use one of " + d.join(", ")); 61 return f = function (a) { 62 return b[a] !== !1 && "" !== b[a] && (b[a] || e[a]) 63 }, g = f("parseAll"), { 64 checkboxUncheckedValue: f("checkboxUncheckedValue"), 65 parseNumbers: g || f("parseNumbers"), 66 parseBooleans: g || f("parseBooleans"), 67 parseNulls: g || f("parseNulls"), 68 parseWithFunction: f("parseWithFunction"), 69 skipFalsyValuesForTypes: f("skipFalsyValuesForTypes"), 70 skipFalsyValuesForFields: f("skipFalsyValuesForFields"), 71 typeFunctions: a.extend({}, f("defaultTypes"), f("customTypes")), 72 useIntKeysAsArrayIndex: f("useIntKeysAsArrayIndex") 73 } 74 }, parseValue: function (b, c, d, e) { 75 var f, g; 76 return f = a.serializeJSON, g = b, e.typeFunctions && d && e.typeFunctions[d] ? g = e.typeFunctions[d](b) : e.parseNumbers && f.isNumeric(b) ? g = Number(b) : !e.parseBooleans || "true" !== b && "false" !== b ? e.parseNulls && "null" == b && (g = null) : g = "true" === b, e.parseWithFunction && !d && (g = e.parseWithFunction(g, c)), g 77 }, isObject: function (a) { 78 return a === Object(a) 79 }, isUndefined: function (a) { 80 return void 0 === a 81 }, isValidArrayIndex: function (a) { 82 return /^[0-9]+$/.test(String(a)) 83 }, isNumeric: function (a) { 84 return a - parseFloat(a) >= 0 85 }, optionKeys: function (a) { 86 if (Object.keys) return Object.keys(a); 87 var b, c = []; 88 for (b in a) c.push(b); 89 return c 90 }, readCheckboxUncheckedValues: function (b, c, d) { 91 var e, f, g, h, i; 92 null == c && (c = {}), i = a.serializeJSON, e = "input[type=checkbox][name]:not(:checked):not([disabled])", f = d.find(e).add(d.filter(e)), f.each(function (d, e) { 93 if (g = a(e), h = g.attr("data-unchecked-value"), null == h && (h = c.checkboxUncheckedValue), null != h) { 94 if (e.name && e.name.indexOf("[][") !== -1) throw new Error("seri
94alizeJSON ERROR: checkbox unchecked values are not supported on nested arrays of objects like '" + e.name + "'. See https://github.com/marioizquierdo/jquery.serializeJSON/issues/67"); 95 b.push({name: e.name, value: h}) 96 } 97 }) 98 }, extractTypeAndNameWithNoType: function (a) { 99 var b; 100 return (b = a.match(/(.*):([^:]+)$/)) ? {nameWithNoType: b[1], type: b[2]} : {nameWithNoType: a, type: null} 101 }, shouldSkipFalsy: function (b, c, d, e, f) { 102 var g = a.serializeJSON, h = g.attrFromInputWithName(b, c, "data-skip-falsy"); 103 if (null != h) return "false" !== h; 104 var i = f.skipFalsyValuesForFields; 105 if (i && (i.indexOf(d) !== -1 || i.indexOf(c) !== -1)) return !0; 106 var j = f.skipFalsyValuesForTypes; 107 return null == e && (e = "string"), !(!j || j.indexOf(e) === -1) 108 }, attrFromInputWithName: function (a, b, c) { 109 var d, e, f; 110 return d = b.replace(/(:|\.|\[|\]|\s)/g, "\\$1"), e = '[name="' + d + '"]', f = a.find(e).add(a.filter(e)), f.attr(c) 111 }, validateType: function (b, c, d) { 112 var e, f; 113 if (f = a.serializeJSON, e = f.optionKeys(d ? d.typeFunctions : f.defaultOptions.defaultTypes), c && e.indexOf(c) === -1) throw new Error("serializeJSON ERROR: Invalid type " + c + " found in input name '" + b + "', please use one of " + e.join(", ")); 114 return !0 115 }, splitInputNameIntoKeysArray: function (b) { 116 var c, d; 117 return d = a.serializeJSON, c = b.split("["), c = a.map(c, function (a) { 118 return a.replace(/\]/g, "") 119 }), "" === c[0] && c.shift(), c 120 }, deepSet: function (b, c, d, e) { 121 var f, g, h, i, j, k; 122 if (null == e && (e = {}), k = a.serializeJSON, k.isUndefined(b)) throw new Error("ArgumentError: param 'o' expected to be an object or array, found undefined"); 123 if (!c || 0 === c.length) throw new Error("ArgumentError: param 'keys' expected to be an array with least one element"); 124 f = c[0], 1 === c.length ? "" === f ? b.push(d) : b[f] = d : (g = c[1], "" === f && (i = b.length - 1, j = b[i], f = k.isObject(j) && (k.isUndefined(j[g]) || c.length > 2) ? i : i + 1), "" === g ? !k.isUndefined(b[f]) && a.isArray(b[f]) || (b[f] = []) : e.useIntKeysAsArrayIndex && k.isValidArrayIndex(g) ? !k.isUndefined(b[f]) && a.isArray(b[f]) || (b[f] = []) : !k.isUndefined(b[f]) && k.isObject(b[f]) || (b[f] = {}), h = c.slice(1), k.deepSet(b[f], h, d, e)) 125 } 126 } 127}); 128 129(function ($) { 130 /** 131 * Watch for all the content forms and listen for a submit action 132 */ 133 $(document).on('submit', 'form.content-form', function (e) { 134 e.preventDefault(); 135 136 var $form = $(this), 137 serialized = $form.serializeJSON(), 138 postData = { 139 form_type: serialized['form-type'], 140 form_id: serialized['form-id'], 141 post_id: serialized['post-id'], 142 form_builder: serialized['form-builder'], 143 data: serialized.data, 144 nonce: serialized['_wpnonce_' + serialized['form-type']], 145 }; 146 147 $form.addClass('content-form-loading'); 148 149 window.jQuery.ajax({ 150 url: contentFormsSettings.restUrl + `submit`, 151 dataType: 'json', 152 method: 'POST', 153 data: postData, 154 beforeSend: function (xhr) { 155 xhr.setRequestHeader('X-WP-Nonce', window.contentFormsSettings.nonce); 156 }, 157 success: function (data) { 158 $form.removeClass('content-form-loading'); 159 160 var status = 'error'; 161 162 if (typeof data.success !== "undefined" && data.success) { 163 status = 'success'; 164 } 165 166 addContentFormNotice(data, status, $form); 167 }, 168 error: function (e) { 169 $form.removeClass('content-form-loading'); 170 171 addContentFormNotice(e, 'error', $form); 172 173 console.error(e) 174 } 175 }); 176 }); 177 178 /** 179 * Handle Form notices 180 * @param notice 181 * @param type 182 * @param $form 183 */ 184 var addContentFormNotice = function (notice, type, $form) { 185 var noticeStatus = 'content-form-success'; 186 var $currentNotice = $form.find('.content-form-notice-wrapper'); 187 if (notice.success === false || (notice.status >= 400 && notice.status < 500) ) { 188 noticeStatus = 'content-form-error'; 189 } 190 var noticeData = typeof notice.responseText !== 'undefined' ? jQuery.parseJSON(notice.responseText) : notice; 191 var noticeText = noticeData.message; 192 var style = typeof formStyle !== 'undefined' && formStyle.formStyle !== '' ? formStyle.formStyle : ''; 193 194 var noticeEl = '<div class="content-form-notice-wrapper"><h3 ' + style +' class="content-form-notice ' + noticeStatus + '" >' + noticeText + '</h3></div>'; 195 196 var $noticeEl; 197 if ($currentNotice.length > 0) { 198 $noticeEl = $(noticeEl); 199 $currentNotice.replaceWith($noticeEl); 200 } else { 201 $noticeEl = $(noticeEl); 202 $form.prepend($noticeEl); 203 } 204 205 // Scroll the notice into view 206 if ($noticeEl && $noticeEl.length > 0) { 207 $noticeEl[0].scrollIntoView({ behavior: 'smooth', block: 'center' }); 208 } 209 } 210})(jQuery);
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.