/admin/public/js/lib/tinymce/classes/ui/BoxUtils.js

https://gitlab.com/0072016/0072016-PHP-APP · JavaScript · 98 lines · 59 code · 15 blank · 24 comment · 13 complexity · e0e5334af63588fa8e55cb2a9e2f4712 MD5 · raw file

  1. /**
  2. * BoxUtils.js
  3. *
  4. * Released under LGPL License.
  5. * Copyright (c) 1999-2015 Ephox Corp. All rights reserved
  6. *
  7. * License: http://www.tinymce.com/license
  8. * Contributing: http://www.tinymce.com/contributing
  9. */
  10. /**
  11. * Utility class for box parsing and measuing.
  12. *
  13. * @private
  14. * @class tinymce.ui.BoxUtils
  15. */
  16. define("tinymce/ui/BoxUtils", [
  17. ], function() {
  18. "use strict";
  19. return {
  20. /**
  21. * Parses the specified box value. A box value contains 1-4 properties in clockwise order.
  22. *
  23. * @method parseBox
  24. * @param {String/Number} value Box value "0 1 2 3" or "0" etc.
  25. * @return {Object} Object with top/right/bottom/left properties.
  26. * @private
  27. */
  28. parseBox: function(value) {
  29. var len, radix = 10;
  30. if (!value) {
  31. return;
  32. }
  33. if (typeof value === "number") {
  34. value = value || 0;
  35. return {
  36. top: value,
  37. left: value,
  38. bottom: value,
  39. right: value
  40. };
  41. }
  42. value = value.split(' ');
  43. len = value.length;
  44. if (len === 1) {
  45. value[1] = value[2] = value[3] = value[0];
  46. } else if (len === 2) {
  47. value[2] = value[0];
  48. value[3] = value[1];
  49. } else if (len === 3) {
  50. value[3] = value[1];
  51. }
  52. return {
  53. top: parseInt(value[0], radix) || 0,
  54. right: parseInt(value[1], radix) || 0,
  55. bottom: parseInt(value[2], radix) || 0,
  56. left: parseInt(value[3], radix) || 0
  57. };
  58. },
  59. measureBox: function(elm, prefix) {
  60. function getStyle(name) {
  61. var defaultView = document.defaultView;
  62. if (defaultView) {
  63. // Remove camelcase
  64. name = name.replace(/[A-Z]/g, function(a) {
  65. return '-' + a;
  66. });
  67. return defaultView.getComputedStyle(elm, null).getPropertyValue(name);
  68. }
  69. return elm.currentStyle[name];
  70. }
  71. function getSide(name) {
  72. var val = parseFloat(getStyle(name), 10);
  73. return isNaN(val) ? 0 : val;
  74. }
  75. return {
  76. top: getSide(prefix + "TopWidth"),
  77. right: getSide(prefix + "RightWidth"),
  78. bottom: getSide(prefix + "BottomWidth"),
  79. left: getSide(prefix + "LeftWidth")
  80. };
  81. }
  82. };
  83. });