Resizable.js 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. /**
  2. * Resizable.js
  3. *
  4. * Copyright, Moxiecode Systems AB
  5. * Released under LGPL License.
  6. *
  7. * License: http://www.tinymce.com/license
  8. * Contributing: http://www.tinymce.com/contributing
  9. */
  10. /**
  11. * Resizable mixin. Enables controls to be resized.
  12. *
  13. * @mixin tinymce.ui.Resizable
  14. */
  15. define("tinymce/ui/Resizable", [
  16. "tinymce/ui/DomUtils"
  17. ], function(DomUtils) {
  18. "use strict";
  19. return {
  20. /**
  21. * Resizes the control to contents.
  22. *
  23. * @method resizeToContent
  24. */
  25. resizeToContent: function() {
  26. this._layoutRect.autoResize = true;
  27. this._lastRect = null;
  28. this.reflow();
  29. },
  30. /**
  31. * Resizes the control to a specific width/height.
  32. *
  33. * @method resizeTo
  34. * @param {Number} w Control width.
  35. * @param {Number} h Control height.
  36. * @return {tinymce.ui.Control} Current control instance.
  37. */
  38. resizeTo: function(w, h) {
  39. // TODO: Fix hack
  40. if (w <= 1 || h <= 1) {
  41. var rect = DomUtils.getWindowSize();
  42. w = w <= 1 ? w * rect.w : w;
  43. h = h <= 1 ? h * rect.h : h;
  44. }
  45. this._layoutRect.autoResize = false;
  46. return this.layoutRect({minW: w, minH: h, w: w, h: h}).reflow();
  47. },
  48. /**
  49. * Resizes the control to a specific relative width/height.
  50. *
  51. * @method resizeBy
  52. * @param {Number} dw Relative control width.
  53. * @param {Number} dh Relative control height.
  54. * @return {tinymce.ui.Control} Current control instance.
  55. */
  56. resizeBy: function(dw, dh) {
  57. var self = this, rect = self.layoutRect();
  58. return self.resizeTo(rect.w + dw, rect.h + dh);
  59. }
  60. };
  61. });