boundry.js 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. define(function(require, exports, module) {
  2. "use strict";
  3. var Util = require('./util');
  4. function Boundry(cfg) {
  5. this.cfg = Util.mix({
  6. width: 0,
  7. height: 0
  8. }, cfg)
  9. this.init();
  10. }
  11. Util.mix(Boundry.prototype, {
  12. init: function() {
  13. var self = this;
  14. self._xtop = 0;
  15. self._xright = 0;
  16. self._xleft = 0;
  17. self._xbottom = 0;
  18. self.refresh({
  19. width: self.cfg.width,
  20. height: self.cfg.height
  21. });
  22. },
  23. reset: function() {
  24. this.resetTop();
  25. this.resetLeft();
  26. this.resetBottom();
  27. this.resetRight();
  28. return this;
  29. },
  30. resetTop: function() {
  31. this._xtop = 0;
  32. this.refresh();
  33. return this;
  34. },
  35. resetLeft: function() {
  36. this._xleft = 0;
  37. this.refresh();
  38. return this;
  39. },
  40. resetBottom: function() {
  41. this._xbottom = 0;
  42. this.refresh();
  43. return this;
  44. },
  45. resetRight: function() {
  46. this._xright = 0;
  47. this.refresh();
  48. return this;
  49. },
  50. expandTop: function(top) {
  51. this._xtop = top;
  52. this.refresh();
  53. return this;
  54. },
  55. expandLeft: function(left) {
  56. this._xleft = left;
  57. this.refresh();
  58. return this;
  59. },
  60. expandRight: function(right) {
  61. this._xright = right;
  62. this.refresh();
  63. return this;
  64. },
  65. expandBottom: function(bottom) {
  66. this._xbottom = bottom;
  67. this.refresh();
  68. return this;
  69. },
  70. refresh: function(cfg) {
  71. Util.mix(this.cfg, cfg);
  72. this.top = this._xtop;
  73. this.left = this._xleft;
  74. this.bottom = (cfg && cfg.height || this.cfg.height || 0) - this._xbottom;
  75. this.right = (cfg && cfg.width || this.cfg.width || 0) - this._xright;
  76. this.width = this.right - this.left > 0 ? this.right - this.left : 0;
  77. this.height = this.bottom - this.top > 0 ? this.bottom - this.top : 0;
  78. return this;
  79. }
  80. });
  81. if (typeof module == 'object' && module.exports) {
  82. module.exports = Boundry;
  83. }
  84. /** ignored by jsdoc **/
  85. else{
  86. return Boundry;
  87. }
  88. });