/projects/htmlunit-2.8/src/test/resources/libraries/dojo/1.0.2/dojo/cookie.js

https://gitlab.com/essere.lab.public/qualitas.class-corpus · JavaScript · 77 lines · 29 code · 4 blank · 44 comment · 10 complexity · 386b83077e6f9328e274b2992fe2756f MD5 · raw file

  1. if(!dojo._hasResource["dojo.cookie"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
  2. dojo._hasResource["dojo.cookie"] = true;
  3. dojo.provide("dojo.cookie");
  4. /*=====
  5. dojo.__cookieProps = function(kwArgs){
  6. // expires: Date|Number?
  7. // If a number, seen as the number of days from today. If a date, the
  8. // date past which the cookie is invalid. If expires is in the past,
  9. // the cookie will be deleted If expires is left out or is 0, the
  10. // cookie will expire when the browser closes.
  11. // path: String?
  12. // The path to use for the cookie.
  13. // domain: String?
  14. // The domain to use for the cookie.
  15. // secure: Boolean?
  16. // Whether to only send the cookie on secure connections
  17. }
  18. =====*/
  19. dojo.cookie = function(/*String*/name, /*String?*/value, /*dojo.__cookieProps?*/props){
  20. // summary:
  21. // Get or set a cookie.
  22. // description:
  23. // If you pass in one argument, the the value of the cookie is returned
  24. //
  25. // If you pass in two arguments, the cookie value is set to the second
  26. // argument.
  27. //
  28. // If you pass in three arguments, the cookie value is set to the
  29. // second argument, and the options on the third argument are used for
  30. // extended properties on the cookie
  31. // name:
  32. // The name of the cookie
  33. // value:
  34. // Optional. The value for the cookie.
  35. // props:
  36. // Optional additional properties for the cookie
  37. // example:
  38. // set a cookie with the JSON-serialized contents of an object which
  39. // will expire 5 days from now:
  40. // | dojo.cookie("configObj", dojo.toJson(config), { expires: 5 });
  41. //
  42. // example:
  43. // de-serialize a cookie back into a JavaScript object:
  44. // | var config = dojo.fromJson(dojo.cookie("configObj"));
  45. //
  46. // example:
  47. // delete a cookie:
  48. // | dojo.cookie("configObj", null);
  49. var c = document.cookie;
  50. if(arguments.length == 1){
  51. var idx = c.lastIndexOf(name+'=');
  52. if(idx == -1){ return null; }
  53. var start = idx+name.length+1;
  54. var end = c.indexOf(';', idx+name.length+1);
  55. if(end == -1){ end = c.length; }
  56. return decodeURIComponent(c.substring(start, end));
  57. }else{
  58. props = props || {};
  59. value = encodeURIComponent(value);
  60. if(typeof(props.expires) == "number"){
  61. var d = new Date();
  62. d.setTime(d.getTime()+(props.expires*24*60*60*1000));
  63. props.expires = d;
  64. }
  65. document.cookie = name + "=" + value
  66. + (props.expires ? "; expires=" + props.expires.toUTCString() : "")
  67. + (props.path ? "; path=" + props.path : "")
  68. + (props.domain ? "; domain=" + props.domain : "")
  69. + (props.secure ? "; secure" : "");
  70. return null;
  71. }
  72. };
  73. }