util.js 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. AmCharts.RB.Util = {
  2. Class: {
  3. create: function(block) {
  4. function klass() {
  5. this.initialize.apply(this, arguments);
  6. }
  7. klass.prototype = block || {};
  8. if (!klass.prototype.initialize) klass.prototype.initialize = function() {}
  9. klass.prototype.constructor = klass;
  10. return klass;
  11. }
  12. },
  13. try_these: function()
  14. {
  15. var returnValue;
  16. for (var i = 0, length = arguments.length; i < length; i++)
  17. {
  18. var lambda = arguments[i];
  19. try
  20. {
  21. returnValue = lambda();
  22. break;
  23. }
  24. catch (e) { }
  25. }
  26. return returnValue;
  27. },
  28. to_query_string: function(obj, prefix)
  29. {
  30. var str = [];
  31. if (AmCharts.ifArray(obj))
  32. {
  33. for (var i = 0; i < obj.length; i++)
  34. {
  35. var k = prefix ? prefix + "[]" : "[]", v = obj[i];
  36. str.push(encodeURIComponent(k) + '=' + encodeURIComponent(v));
  37. }
  38. }
  39. else {
  40. for (var p in obj) {
  41. if (!obj.hasOwnProperty(p)) continue;
  42. var k = prefix ? prefix + "[" + p + "]" : p, v = obj[p];
  43. str.push(typeof v == "object" ?
  44. AmCharts.RB.Util.to_query_string(v, k) :
  45. encodeURIComponent(k) + "=" + encodeURIComponent(v));
  46. }
  47. }
  48. return str.join("&");
  49. },
  50. is_function: function(object)
  51. {
  52. return Object.prototype.toString.call(object) === "[object Function]";
  53. },
  54. is_empty: function(object)
  55. {
  56. if (object === null || object === undefined) return true;
  57. if (object.length !== undefined) return object.length == 0;
  58. return undefined;
  59. }
  60. }