-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathjquery.grab-gets.min.js
10 lines (10 loc) · 2.04 KB
/
jquery.grab-gets.min.js
1
2
3
4
5
6
7
8
9
10
/*!
* jQuery grabget plugin
* Description: Grab GET parameters from url and put, select and check elements of selected form
* version: 1.3-2016.03.22
* Requires jQuery v1.6 or later
* Autor: saxa:p (http://dontforget.pro)
* Dual licensed under the MIT and GPL licenses.
* https://github.com/malsup/form#copyright-and-license
*/
!function(t){jQuery.fn.grabgets=function(e){e=t.extend({hidden:!0},e),t.extend({getUrlVars:function(){for(var e,i,n,a=[],r=window.location.href.slice(window.location.href.indexOf("?")+1).split("&"),p=0;p<r.length;p++)e=r[p].split("="),i=decodeURIComponent(e[0]).replace(/\+/g," "),n=e[1]?decodeURIComponent(e[1].replace(/\+/g," ")):e[1],a[i]?(t.isArray(a[i])||(a[i]=[a[i]]),a[i].push(n)):a[i]=n;return a}});var i=t(this),n=function(){var n=t.getUrlVars();0!=i.length&&(i.find('input[type="text"], input[type="number"], input[type="date"], input[type="color"], input[type="range"], input[type="month"], input[type="week"], input[type="time"], input[type="datetime"], input[type="datetime-local"], input[type="email"], input[type="search"], input[type="tel"], input[type="url"]').each(function(){var e=t(this).attr("name"),a=n[e];t.isArray(a)&&(a=a[i.find('input[name="'+e+'"]').index(t(this))]),a&&t(this).val(a)}),e.hidden&&i.find('input[type="hidden"]').each(function(){var e=t(this).attr("name"),a=n[e];t.isArray(a)&&(a=a[i.find('input[type="hidden"][name="'+e+'"]').index(t(this))]),a&&t(this).val(a)}),i.find("textarea").each(function(){var e=t(this).attr("name"),a=n[e];t.isArray(a)&&(a=a[i.find('textarea[name="'+e+'"]').index(t(this))]),a&&t(this).html(a)}),i.find("select").each(function(){var e=t(this).attr("name"),a=n[e];t.isArray(a)&&!t(this).attr("multiple")&&(a=a[i.find('select[name="'+e+'"]').index(t(this))]),t(this).find("option").each(function(){var e=t(this).val();(a==e||-1!=t.inArray(e,a))&&t(this).prop("selected",!0)})}),i.find('input[type="checkbox"], input[type="radio"]').each(function(){var e=t(this).attr("name"),i=t(this).val();(n[e]==i||-1!=t.inArray(i,n[e]))&&t(this).attr("checked","checked")}))};return i.each(n)}}(jQuery);