Dashboard sipadu mbip
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

querystring-parse-simple-debug.js 2.7KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. /*
  2. Copyright (c) 2010, Yahoo! Inc. All rights reserved.
  3. Code licensed under the BSD License:
  4. http://developer.yahoo.com/yui/license.html
  5. version: 3.4.0
  6. build: nightly
  7. */
  8. YUI.add('querystring-parse-simple', function(Y) {
  9. // @TODO this looks like we are requiring the user to extract the querystring
  10. // portion of the url, which isn't good. The majority use case will be to
  11. // extract querystring from the document configured for this YUI instance.
  12. // This should be the default if qs is not supplied.
  13. /*global Y */
  14. /**
  15. * <p>Provides Y.QueryString.stringify method for converting objects to Query Strings.
  16. * This is a simpler implementation than the full querystring-stringify.</p>
  17. * <p>Because some things may require basic query string escaping functionality,
  18. * this module provides the bare minimum functionality (decoding a hash of simple values),
  19. * without the additional support for arrays, objects, and so on.</p>
  20. * <p>This provides a friendly way to deserialize basic query strings, without necessitating
  21. * a lot of code for simple use-cases.</p>
  22. *
  23. * @module querystring
  24. * @submodule querystring-parse-simple
  25. * @for QueryString
  26. * @static
  27. */
  28. var QueryString = Y.namespace("QueryString");
  29. /**
  30. * Provides Y.QueryString.parse method to accept Query Strings and return native
  31. * JavaScript objects.
  32. *
  33. * @module querystring
  34. * @submodule querystring-parse
  35. * @for QueryString
  36. * @method parse
  37. * @param qs {String} Querystring to be parsed into an object.
  38. * @param sep {String} (optional) Character that should join param k=v pairs together. Default: "&"
  39. * @param eq {String} (optional) Character that should join keys to their values. Default: "="
  40. * @public
  41. * @static
  42. */
  43. QueryString.parse = function (qs, sep, eq) {
  44. sep = sep || "&";
  45. eq = eq || "=";
  46. for (
  47. var obj = {},
  48. i = 0,
  49. pieces = qs.split(sep),
  50. l = pieces.length,
  51. tuple;
  52. i < l;
  53. i ++
  54. ) {
  55. tuple = pieces[i].split(eq);
  56. if (tuple.length > 0) {
  57. obj[QueryString.unescape(tuple.shift())] = QueryString.unescape(tuple.join(eq));
  58. }
  59. }
  60. return obj;
  61. };
  62. /**
  63. * Provides Y.QueryString.unescape method to be able to override default decoding
  64. * method. This is important in cases where non-standard delimiters are used, if
  65. * the delimiters would not normally be handled properly by the builtin
  66. * (en|de)codeURIComponent functions.
  67. * Default: replace "+" with " ", and then decodeURIComponent behavior.
  68. * @module querystring
  69. * @submodule querystring-parse
  70. * @for QueryString
  71. * @method unescape
  72. * @param s {String} String to be decoded.
  73. * @public
  74. * @static
  75. **/
  76. QueryString.unescape = function (s) {
  77. return decodeURIComponent(s.replace(/\+/g, ' '));
  78. };
  79. }, '3.4.0' ,{requires:['yui-base']});