SvgButton.js
上传用户:kimgenplus
上传日期:2016-06-05
资源大小:20877k
文件大小:3k
源码类别:

OA系统

开发平台:

Java

  1. /*
  2. Copyright (c) 2004-2006, The Dojo Foundation
  3. All Rights Reserved.
  4. Licensed under the Academic Free License version 2.1 or above OR the
  5. modified BSD license. For more information on Dojo licensing, see:
  6. http://dojotoolkit.org/community/licensing.shtml
  7. */
  8. dojo.provide("dojo.widget.SvgButton");
  9. dojo.require("dojo.experimental");
  10. dojo.experimental("dojo.widget.SvgButton");
  11. dojo.widget.SvgButton = function () {
  12. dojo.widget.DomButton.call(this);
  13. dojo.widget.SvgWidget.call(this);
  14. this.onFoo = function () {
  15. alert("bar");
  16. };
  17. this.label = "huzzah!";
  18. this.setLabel = function (x, y, textSize, label, shape) {
  19. var coords = dojo.widget.SvgButton.prototype.coordinates(x, y, textSize, label, shape);
  20. var textString = "";
  21. switch (shape) {
  22.   case "ellipse":
  23. textString = "<text x='" + coords[6] + "' y='" + coords[7] + "'>" + label + "</text>";
  24. break;
  25.   case "rectangle":
  26. textString = "";
  27. break;
  28.   case "circle":
  29. textString = "";
  30. break;
  31. }
  32. return textString;
  33. };
  34. this.fillInTemplate = function (x, y, textSize, label, shape) {
  35. this.textSize = textSize || 12;
  36. this.label = label;
  37. var textWidth = this.label.length * this.textSize;
  38. };
  39. };
  40. dojo.inherits(dojo.widget.SvgButton, dojo.widget.DomButton);
  41. dojo.widget.SvgButton.prototype.shapeString = function (x, y, textSize, label, shape) {
  42. switch (shape) {
  43.   case "ellipse":
  44. var coords = dojo.widget.SvgButton.prototype.coordinates(x, y, textSize, label, shape);
  45. return "<ellipse cx='" + coords[4] + "' cy='" + coords[5] + "' rx='" + coords[2] + "' ry='" + coords[3] + "'/>";
  46. break;
  47.   case "rect":
  48. return "";
  49. break;
  50.   case "circle":
  51. return "";
  52. break;
  53. }
  54. };
  55. dojo.widget.SvgButton.prototype.coordinates = function (x, y, textSize, label, shape) {
  56. switch (shape) {
  57.   case "ellipse":
  58. var buttonWidth = label.length * textSize;
  59. var buttonHeight = textSize * 2.5;
  60. var rx = buttonWidth / 2;
  61. var ry = buttonHeight / 2;
  62. var cx = rx + x;
  63. var cy = ry + y;
  64. var textX = cx - rx * textSize / 25;
  65. var textY = cy * 1.1;
  66. return [buttonWidth, buttonHeight, rx, ry, cx, cy, textX, textY];
  67. break;
  68.   case "rectangle":
  69. return "";
  70. break;
  71.   case "circle":
  72. return "";
  73. break;
  74. }
  75. };
  76. dojo.widget.SvgButton.prototype.labelString = function (x, y, textSize, label, shape) {
  77. var textString = "";
  78. var coords = dojo.widget.SvgButton.prototype.coordinates(x, y, textSize, label, shape);
  79. switch (shape) {
  80.   case "ellipse":
  81. textString = "<text x='" + coords[6] + "' y='" + coords[7] + "'>" + label + "</text>";
  82. break;
  83.   case "rectangle":
  84. textString = "";
  85. break;
  86.   case "circle":
  87. textString = "";
  88. break;
  89. }
  90. return textString;
  91. };
  92. dojo.widget.SvgButton.prototype.templateString = function (x, y, textSize, label, shape) {
  93. return "<g class='dojoButton' dojoAttachEvent='onClick; onMouseMove: onFoo;' dojoAttachPoint='labelNode'>" + dojo.widgets.SVGButton.prototype.shapeString(x, y, textSize, label, shape) + dojo.widget.SVGButton.prototype.labelString(x, y, textSize, label, shape) + "</g>";
  94. };