Advertisement
Dawid-Klimczak

Untitled

Dec 17th, 2018
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <script src="https://code.jquery.com/jquery-latest.min.js" type="text/javascript"></script>
  2. <script>
  3. /*!
  4.  * jQuery Cookie Plugin v1.4.1
  5.  * https://github.com/carhartl/jquery-cookie
  6.  *
  7.  * Copyright 2006, 2014 Klaus Hartl
  8.  * Released under the MIT license
  9.  */
  10. (function (factory) {
  11.     if (typeof define === 'function' && define.amd) {
  12.         // AMD (Register as an anonymous module)
  13.         define(['jquery'], factory);
  14.     } else if (typeof exports === 'object') {
  15.         // Node/CommonJS
  16.         module.exports = factory(require('jquery'));
  17.     } else {
  18.         // Browser globals
  19.         factory(jQuery);
  20.     }
  21. }(function ($) {
  22.  
  23.     var pluses = /\+/g;
  24.  
  25.     function encode(s) {
  26.         return config.raw ? s : encodeURIComponent(s);
  27.     }
  28.  
  29.     function decode(s) {
  30.         return config.raw ? s : decodeURIComponent(s);
  31.     }
  32.  
  33.     function stringifyCookieValue(value) {
  34.         return encode(config.json ? JSON.stringify(value) : String(value));
  35.     }
  36.  
  37.     function parseCookieValue(s) {
  38.         if (s.indexOf('"') === 0) {
  39.             // This is a quoted cookie as according to RFC2068, unescape...
  40.             s = s.slice(1, -1).replace(/\\"/g, '"').replace(/\\\\/g, '\\');
  41.         }
  42.  
  43.         try {
  44.             // Replace server-side written pluses with spaces.
  45.             // If we can't decode the cookie, ignore it, it's unusable.
  46.             // If we can't parse the cookie, ignore it, it's unusable.
  47.             s = decodeURIComponent(s.replace(pluses, ' '));
  48.             return config.json ? JSON.parse(s) : s;
  49.         } catch(e) {}
  50.     }
  51.  
  52.     function read(s, converter) {
  53.         var value = config.raw ? s : parseCookieValue(s);
  54.         return $.isFunction(converter) ? converter(value) : value;
  55.     }
  56.  
  57.     var config = $.cookie = function (key, value, options) {
  58.  
  59.         // Write
  60.  
  61.         if (arguments.length > 1 && !$.isFunction(value)) {
  62.             options = $.extend({}, config.defaults, options);
  63.  
  64.             if (typeof options.expires === 'number') {
  65.                 var days = options.expires, t = options.expires = new Date();
  66.                 t.setMilliseconds(t.getMilliseconds() + days * 864e+5);
  67.             }
  68.  
  69.             return (document.cookie = [
  70.                 encode(key), '=', stringifyCookieValue(value),
  71.                 options.expires ? '; expires=' + options.expires.toUTCString() : '', // use expires attribute, max-age is not supported by IE
  72.                 options.path    ? '; path=' + options.path : '',
  73.                 options.domain  ? '; domain=' + options.domain : '',
  74.                 options.secure  ? '; secure' : ''
  75.             ].join(''));
  76.         }
  77.  
  78.         // Read
  79.  
  80.         var result = key ? undefined : {},
  81.             // To prevent the for loop in the first place assign an empty array
  82.             // in case there are no cookies at all. Also prevents odd result when
  83.             // calling $.cookie().
  84.             cookies = document.cookie ? document.cookie.split('; ') : [],
  85.             i = 0,
  86.             l = cookies.length;
  87.  
  88.         for (; i < l; i++) {
  89.             var parts = cookies[i].split('='),
  90.                 name = decode(parts.shift()),
  91.                 cookie = parts.join('=');
  92.  
  93.             if (key === name) {
  94.                 // If second argument (value) is a function it's a converter...
  95.                 result = read(cookie, value);
  96.                 break;
  97.             }
  98.  
  99.             // Prevent storing a cookie that we couldn't decode.
  100.             if (!key && (cookie = read(cookie)) !== undefined) {
  101.                 result[name] = cookie;
  102.             }
  103.         }
  104.  
  105.         return result;
  106.     };
  107.  
  108.     config.defaults = {};
  109.  
  110.     $.removeCookie = function (key, options) {
  111.         // Must not alter options, thus extending a fresh object...
  112.         $.cookie(key, '', $.extend({}, options, { expires: 1 }));
  113.         return !$.cookie(key);
  114.     };
  115.  
  116. }));
  117. </script>
  118.  
  119. <script>
  120. function getParameterByName(name) {
  121.     name = name.replace(/[\[]/, "\\[").replace(/[\]]/, "\\]");
  122.     var regex = new RegExp("[\\?&]" + name + "=([^&#]*)"),
  123.         results = regex.exec(location.search);
  124.     return results === null ? "" : decodeURIComponent(results[1].replace(/\+/g, " "));
  125. }
  126.  
  127. var source = getParameterByName('a');
  128.  
  129.  
  130. if($.cookie('a') == null || $.cookie('a') == "") {
  131. $.cookie('a', source);
  132. }
  133.  
  134. $(document).ready(function(){
  135.     $('input[name=a').val(a);
  136. });
  137. </script>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement