trinUtil.js 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. function extend(Child, Parent) {
  2. var F = function() {
  3. };
  4. F.prototype = Parent.prototype;
  5. Child.prototype = new F();
  6. Child.prototype.constructor = Child;
  7. Child.superclass = Parent.prototype;
  8. }
  9. function TrinUtil() {
  10. }
  11. TrinUtil.prototype.drawEllipse = function(ctx, x, y, w, h) {
  12. var kappa = 0.5522848,
  13. ox = (w / 2) * kappa, // control point offset horizontal
  14. oy = (h / 2) * kappa, // control point offset vertical
  15. xe = x + w, // x-end
  16. ye = y + h, // y-end
  17. xm = x + w / 2, // x-middle
  18. ym = y + h / 2; // y-middle
  19. ctx.beginPath();
  20. ctx.moveTo(x, ym);
  21. ctx.bezierCurveTo(x, ym - oy, xm - ox, y, xm, y);
  22. ctx.bezierCurveTo(xm + ox, y, xe, ym - oy, xe, ym);
  23. ctx.bezierCurveTo(xe, ym + oy, xm + ox, ye, xm, ye);
  24. ctx.bezierCurveTo(xm - ox, ye, x, ym + oy, x, ym);
  25. ctx.closePath();
  26. ctx.stroke();
  27. };
  28. TrinUtil.prototype.detectmob = function() {
  29. if (navigator.userAgent.match(/Android/i)
  30. || navigator.userAgent.match(/webOS/i)
  31. || navigator.userAgent.match(/iPhone/i)
  32. || navigator.userAgent.match(/iPad/i)
  33. || navigator.userAgent.match(/iPod/i)
  34. || navigator.userAgent.match(/BlackBerry/i)
  35. || navigator.userAgent.match(/Windows Phone/i))
  36. {
  37. return true;
  38. } else {
  39. return false;
  40. }
  41. };
  42. TrinUtil.prototype.isAndroid = function(){
  43. return navigator.userAgent.match(/Android/i);
  44. };
  45. TrinUtil.prototype.isIDevice = function(){
  46. return (navigator.userAgent.match(/iPhone/i)) || (navigator.userAgent.match(/iPod/i));
  47. };
  48. TrinUtil.prototype.digits = "0123456789ABCDEF";
  49. TrinUtil.prototype.numberToDec = function(number, base) {
  50. var dec = 0;
  51. var p = 1;
  52. number = number.toUpperCase();
  53. for (var i = number.length - 1; i >= 0; i--) {
  54. var c = number[i];
  55. dec += this.digits.indexOf(c) * p;
  56. p *= base;
  57. }
  58. return dec;
  59. };
  60. TrinUtil.prototype.decToNumber = function(dec, base, len) {
  61. if (len === undefined) {
  62. len = 2;
  63. }
  64. var number = "";
  65. while (dec > 0) {
  66. number = this.digits[dec % base] + number;
  67. dec = Math.floor(dec / base);
  68. }
  69. while (number.length < len) {
  70. number = "0" + number;
  71. }
  72. return number;
  73. };