Web UI for ARGUS server
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

146 lines
6.5 KiB

6 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. <html>
  2. <head>
  3. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  4. <title>The source code</title>
  5. <link href="../resources/prettify/prettify.css" type="text/css" rel="stylesheet" />
  6. <script type="text/javascript" src="../resources/prettify/prettify.js"></script>
  7. </head>
  8. <body onload="prettyPrint();">
  9. <pre class="prettyprint lang-js">/*!
  10. * Ext JS Library 3.3.1
  11. * Copyright(c) 2006-2010 Sencha Inc.
  12. * licensing@sencha.com
  13. * http://www.sencha.com/license
  14. */
  15. <div id="cls-Ext.util.TextMetrics"></div>/**
  16. * @class Ext.util.TextMetrics
  17. * Provides precise pixel measurements for blocks of text so that you can determine exactly how high and
  18. * wide, in pixels, a given block of text will be. Note that when measuring text, it should be plain text and
  19. * should not contain any HTML, otherwise it may not be measured correctly.
  20. * @singleton
  21. */
  22. Ext.util.TextMetrics = function(){
  23. var shared;
  24. return {
  25. <div id="method-Ext.util.TextMetrics-measure"></div>/**
  26. * Measures the size of the specified text
  27. * @param {String/HTMLElement} el The element, dom node or id from which to copy existing CSS styles
  28. * that can affect the size of the rendered text
  29. * @param {String} text The text to measure
  30. * @param {Number} fixedWidth (optional) If the text will be multiline, you have to set a fixed width
  31. * in order to accurately measure the text height
  32. * @return {Object} An object containing the text's size {width: (width), height: (height)}
  33. */
  34. measure : function(el, text, fixedWidth){
  35. if(!shared){
  36. shared = Ext.util.TextMetrics.Instance(el, fixedWidth);
  37. }
  38. shared.bind(el);
  39. shared.setFixedWidth(fixedWidth || 'auto');
  40. return shared.getSize(text);
  41. },
  42. <div id="method-Ext.util.TextMetrics-createInstance"></div>/**
  43. * Return a unique TextMetrics instance that can be bound directly to an element and reused. This reduces
  44. * the overhead of multiple calls to initialize the style properties on each measurement.
  45. * @param {String/HTMLElement} el The element, dom node or id that the instance will be bound to
  46. * @param {Number} fixedWidth (optional) If the text will be multiline, you have to set a fixed width
  47. * in order to accurately measure the text height
  48. * @return {Ext.util.TextMetrics.Instance} instance The new instance
  49. */
  50. createInstance : function(el, fixedWidth){
  51. return Ext.util.TextMetrics.Instance(el, fixedWidth);
  52. }
  53. };
  54. }();
  55. Ext.util.TextMetrics.Instance = function(bindTo, fixedWidth){
  56. var ml = new Ext.Element(document.createElement('div'));
  57. document.body.appendChild(ml.dom);
  58. ml.position('absolute');
  59. ml.setLeftTop(-1000, -1000);
  60. ml.hide();
  61. if(fixedWidth){
  62. ml.setWidth(fixedWidth);
  63. }
  64. var instance = {
  65. <div id="method-Ext.util.TextMetrics-getSize"></div>/**
  66. * <p><b>Only available on the instance returned from {@link #createInstance}, <u>not</u> on the singleton.</b></p>
  67. * Returns the size of the specified text based on the internal element's style and width properties
  68. * @param {String} text The text to measure
  69. * @return {Object} An object containing the text's size {width: (width), height: (height)}
  70. */
  71. getSize : function(text){
  72. ml.update(text);
  73. var s = ml.getSize();
  74. ml.update('');
  75. return s;
  76. },
  77. <div id="method-Ext.util.TextMetrics-bind"></div>/**
  78. * <p><b>Only available on the instance returned from {@link #createInstance}, <u>not</u> on the singleton.</b></p>
  79. * Binds this TextMetrics instance to an element from which to copy existing CSS styles
  80. * that can affect the size of the rendered text
  81. * @param {String/HTMLElement} el The element, dom node or id
  82. */
  83. bind : function(el){
  84. ml.setStyle(
  85. Ext.fly(el).getStyles('font-size','font-style', 'font-weight', 'font-family','line-height', 'text-transform', 'letter-spacing')
  86. );
  87. },
  88. <div id="method-Ext.util.TextMetrics-setFixedWidth"></div>/**
  89. * <p><b>Only available on the instance returned from {@link #createInstance}, <u>not</u> on the singleton.</b></p>
  90. * Sets a fixed width on the internal measurement element. If the text will be multiline, you have
  91. * to set a fixed width in order to accurately measure the text height.
  92. * @param {Number} width The width to set on the element
  93. */
  94. setFixedWidth : function(width){
  95. ml.setWidth(width);
  96. },
  97. <div id="method-Ext.util.TextMetrics-getWidth"></div>/**
  98. * <p><b>Only available on the instance returned from {@link #createInstance}, <u>not</u> on the singleton.</b></p>
  99. * Returns the measured width of the specified text
  100. * @param {String} text The text to measure
  101. * @return {Number} width The width in pixels
  102. */
  103. getWidth : function(text){
  104. ml.dom.style.width = 'auto';
  105. return this.getSize(text).width;
  106. },
  107. <div id="method-Ext.util.TextMetrics-getHeight"></div>/**
  108. * <p><b>Only available on the instance returned from {@link #createInstance}, <u>not</u> on the singleton.</b></p>
  109. * Returns the measured height of the specified text. For multiline text, be sure to call
  110. * {@link #setFixedWidth} if necessary.
  111. * @param {String} text The text to measure
  112. * @return {Number} height The height in pixels
  113. */
  114. getHeight : function(text){
  115. return this.getSize(text).height;
  116. }
  117. };
  118. instance.bind(bindTo);
  119. return instance;
  120. };
  121. Ext.Element.addMethods({
  122. <div id="method-Ext.Element-getTextWidth"></div>/**
  123. * Returns the width in pixels of the passed text, or the width of the text in this Element.
  124. * @param {String} text The text to measure. Defaults to the innerHTML of the element.
  125. * @param {Number} min (Optional) The minumum value to return.
  126. * @param {Number} max (Optional) The maximum value to return.
  127. * @return {Number} The text width in pixels.
  128. * @member Ext.Element getTextWidth
  129. */
  130. getTextWidth : function(text, min, max){
  131. return (Ext.util.TextMetrics.measure(this.dom, Ext.value(text, this.dom.innerHTML, true)).width).constrain(min || 0, max || 1000000);
  132. }
  133. });
  134. </pre>
  135. </body>
  136. </html>