PageSourceSearch

https://gongwer.com/about/jquery.redirect.js

js gongwer.com collected 2026-10-04 00:25:33 UTC 6,867 bytes, 177 lines download raw bytes

vendor: 6,867 bytes, lines 1-177
1/*
2jQuery Redirect v1.1.3
3Copyright (c) 2013-2018 Miguel Galante
4Copyright (c) 2011-2013 Nemanja Avramovic, www.avramovic.info
5Licensed under CC BY-SA 4.0 License: http://creativecommons.org/licenses/by-sa/4.0/
6This means everyone is allowed to:
7Share - copy and redistribute the material in any medium or format
8Adapt - remix, transform, and build upon the material for any purpose, even commercially.
9Under following conditions:
10Attribution - You must give appropriate credit, provide a link to the license, and indicate if changes were made. You may do so in any reasonable manner, but not in any way that suggests the licensor endorses you or your use.
11ShareAlike - If you remix, transform, or build upon the material, you must distribute your contributions under the same license as the original.
12*/
13;(function ($) {
14    'use strict';
15  
16    //Defaults configuration
17    var defaults = {
18      url: null,
19      values: null,
20      method: "POST",
21      target: null,
22      traditional: false,
23      redirectTop: false
24    };
25  
26    /**
27    * jQuery Redirect
28    * @param {string} url - Url of the redirection
29    * @param {Object} values - (optional) An object with the data to send. If not present will look for values as QueryString in the target url.
30    * @param {string} method - (optional) The HTTP verb can be GET or POST (defaults to POST)
31    * @param {string} target - (optional) The target of the form. "_blank" will open the url in a new window.
32    * @param {boolean} traditional - (optional) This provides the same function as jquery's ajax function. The brackets are omitted on the field name if its an array.  This allows arrays to work with MVC.net among others.
33    * @param {boolean} redirectTop - (optional) If its called from a iframe, force to navigate the top window. 
34    *//**
35    * jQuery Redirect
36    * @param {string} opts - Options object
37    * @param {string} opts.url - Url of the redirection
38    * @param {Object} opts.values - (optional) An object with the data to send. If not present will look for values as QueryString in the target url.
39    * @param {string} opts.method - (optional) The HTTP verb can be GET or POST (defaults to POST)
40    * @param {string} opts.target - (optional) The target of the form. "_blank" will open the url in a new window.
41    * @param {boolean} opts.traditional - (optional) This provides the same function as jquery's ajax function. The brackets are omitted on the field name if its an array.  This allows arrays to work with MVC.net among others.
42    * @param {boolean} opts.redirectTop - (optional) If its called from a iframe, force to navigate the top window. 
43    */
44    $.redirect = function (url, values, method, target, traditional, redirectTop) {
45      var opts = url;
46      if (typeof url !== "object") {
47        var opts = {
48          url: url,
49          values: values,
50          method: method,
51          target: target,
52          traditional: traditional,
53          redirectTop: redirectTop
54        };
55      }
56  
57      var config = $.extend({}, defaults, opts);
58      var generatedForm = $.redirect.getForm(config.url, config.values, config.method, config.target, config.traditional);
59      $('body', config.redirectTop ? window.top.document : undefined).append(generatedForm.form);
60      generatedForm.submit();
61      generatedForm.form.remove();
62    };
63  
64    $.redirect.getForm = function (url, values, method, target, traditional) {
65      method = (method && ["GET", "POST", "PUT", "DELETE"].indexOf(method.toUpperCase()) !== -1) ? method.toUpperCase() : 'POST';
66  
67      url = url.split("#");
68      var hash = url[1] ? ("#" + url[1]) : "";
69      url = url[0];
70  
71      if (!values) {
72        var obj = $.parseUrl(url);
73        url = obj.url;
74        values = obj.params;
75      }
76  
77      values = removeNulls(values);
78  
79      var form = $('<form>')
80        .attr("method", method)
81        .attr("action", url + hash);
82  
83  
84      if (target) {
85        form.attr("target", target);
86      }
87  
88      var submit = form[0].submit;
89      iterateValues(values, [], form, null, traditional);
90  
91      return { form: form, submit: function () { submit.call(form[0]); } };
92    }
93  
94    //Utility Functions
95      /**
96       * Url and QueryString Parser.
97       * @param {string} url - a Url to parse.
98       * @returns {object} an object with the parsed url with the following structure {url: URL, params:{ KEY: VALUE }}
99       */
100    $.parseUrl = function (url) {
101  
102      if (url.indexOf('?') === -1) {
103        return {
104          url: url,
105          params: {}
106        };
107      }
108      var parts = url.split('?'),
109        query_string = parts[1],
110        elems = query_string.split('&');
111      url = parts[0];
112  
113      var i, pair, obj = {};
114      for (i = 0; i < elems.length; i += 1) {
115        pair = elems[i].split('=');
116        obj[pair[0]] = pair[1];
117      }
118  
119      return {
120        url: url,
121        params: obj
122      };
123    };
124  
125    //Private Functions
126    var getInput = function (name, value, parent, array, traditional) {
127      var parentString;
128      if (parent.length > 0) {
129        parentString = parent[0];
130        var i;
131        for (i = 1; i < parent.length; i += 1) {
132          parentString += "[" + parent[i] + "]";
133        }
134  
135        if (array) {
136          if (traditional)
137            name = parentString;
138          else
139            name = parentString + "[" + name + "]";
140        } else {
141          name = parentString + "[" + name + "]";
142        }
143      }
144  
145      return $("<input>").attr("type", "hidden")
146        .attr("name", name)
147        .attr("value", value);
148    };
149  
150    var iterateValues = function (values, parent, form, isArray, traditional) {
151      var i, iterateParent = [];
152      Object.keys(values).forEach(function (i) {
153        if (typeof values[i] === "object") {
154          iterateParent = parent.slice();
155          iterateParent.push(i);
156          iterateValues(values[i], iterateParent, form, Array.isArray(values[i]), traditional);
157        } else {
158          form.append(getInput(i, values[i], parent, isArray, traditional));
159        }
160      });
161    };
162  
163    var removeNulls = function (values) {
164      var propNames = Object.getOwnPropertyNames(values);
165      for (var i = 0; i < propNames.length; i++) {
166        var propName = propNames[i];
167        if (values[propName] === null || values[propName] === undefined) {
168          delete values[propName];
169        } else if (typeof values[propName] === 'object') {
170          values[propName] = removeNulls(values[propName]);
171        } else if (values[propName].length < 1) {
172          delete values[propName];
173        }
174      }
175      return values;
176    };
177  }(window.jQuery || window.Zepto || window.jqlite));

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.