PageSourceSearch

https://phototo.co.kr/data/skin/front/on_commonMotif_p_phototo/js/jquery/jquery.serialize.object.js

js phototo.co.kr collected 2026-09-24 15:05:25 UTC 4,060 bytes, 146 lines download raw bytes

1/**
2 * jQuery serializeObject
3 * @copyright 2014, macek <[email protected]>
4 * @link https://github.com/macek/jquery-serialize-object
5 * @license BSD
6 * @version 2.5.0
7 */
8(function(root, factory) {
9
10    // AMD
11    if (typeof define === "function" && define.amd) {
12        define(["exports", "jquery"], function(exports, $) {
13            return factory(exports, $);
14        });
15    }
16
17    // CommonJS
18    else if (typeof exports !== "undefined") {
19        var $ = require("jquery");
20        factory(exports, $);
21    }
22
23    // Browser
24    else {
25        factory(root, (root.jQuery || root.Zepto || root.ender || root.$));
26    }
27
28}(this, function(exports, $) {
29
30    var patterns = {
31        validate: /^[a-z_][a-z0-9_]*(?:\[(?:\d*|[a-z0-9_]+)\])*$/i,
32        key:      /[a-z0-9_]+|(?=\[\])/gi,
33        push:     /^$/,
34        fixed:    /^\d+$/,
35        named:    /^[a-z0-9_]+$/i
36    };
37
38    function FormSerializer(helper, $form) {
39
40        // private variables
41        var data     = {},
42            pushes   = {};
43
44        // private API
45        function build(base, key, value) {
46            base[key] = value;
47            return base;
48        }
49
50        function makeObject(root, value) {
51
52            var keys = root.match(patterns.key), k;
53
54            // nest, nest, ..., nest
55            while ((k = keys.pop()) !== undefined) {
56                // foo[]
57                if (patterns.push.test(k)) {
58                    var idx = incrementPush(root.replace(/\[\]$/, ''));
59                    value = build([], idx, value);
60                }
61
62                // foo[n]
63                else if (patterns.fixed.test(k)) {
64                    value = build([], k, value);
65                }
66
67                // foo; foo[bar]
68                else if (patterns.named.test(k)) {
69                    value = build({}, k, value);
70                }
71            }
72
73            return value;
74        }
75
76        function incrementPush(key) {
77            if (pushes[key] === undefined) {
78                pushes[key] = 0;
79            }
80            return pushes[key]++;
81        }
82
83        function encode(pair) {
84            switch ($('[name="' + pair.name + '"]', $form).attr("type")) {
85                case "checkbox":
86                    return pair.value === "on" ? true : pair.value;
87                default:
88                    return pair.value;
89            }
90        }
91
92        function addPair(pair) {
93            if (!patterns.validate.test(pair.name)) return this;
94            var obj = makeObject(pair.name, encode(pair));
95            data = helper.extend(true, data, obj);
96            return this;
97        }
98
99        function addPairs(pairs) {
100            if (!helper.isArray(pairs)) {
101                throw new Error("formSerializer.addPairs expects an Array");
102            }
103            for (var i=0, len=pairs.length; i<len; i++) {
104                this.addPair(pairs[i]);
105            }
106            return this;
107        }
108
109        function serialize() {
110            return data;
111        }
112
113        function serializeJSON() {
114            return JSON.stringify(serialize());
115        }
116
117        // public API
118        this.addPair = addPair;
119        this.addPairs = addPairs;
120        this.serialize = serialize;
121        this.serializeJSON = serializeJSON;
122    }
123
124    FormSerializer.patterns = patterns;
125
126    FormSerializer.serializeObject = function serializeObject() {
127        return new FormSerializer($, this).
128        addPairs(this.serializeArray()).
129        serialize();
130    };
131
132    FormSerializer.serializeJSON = function serializeJSON() {
133        return new FormSerializer($, this).
134        addPairs(this.serializeArray()).
135        serializeJSON();
136    };
137
138    if (typeof $.fn !== "undefined") {
139        $.fn.serializeObject = FormSerializer.serializeObject;
140        $.fn.serializeJSON   = FormSerializer.serializeJSON;
141    }
142
143    exports.FormSerializer = FormSerializer;
144
145    return FormSerializer;
146}));

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.