Tip2.html 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  5. <title>The source code</title>
  6. <link href="../resources/prettify/prettify.css" type="text/css" rel="stylesheet" />
  7. <script type="text/javascript" src="../resources/prettify/prettify.js"></script>
  8. <style type="text/css">
  9. .highlight { display: block; background-color: #ddd; }
  10. </style>
  11. <script type="text/javascript">
  12. function highlight() {
  13. document.getElementById(location.hash.replace(/#/, "")).className = "highlight";
  14. }
  15. </script>
  16. </head>
  17. <body onload="prettyPrint(); highlight();">
  18. <pre class="prettyprint lang-js"><span id='Ext-slider-Tip'>/**
  19. </span> * Simple plugin for using an Ext.tip.Tip with a slider to show the slider value. In general this class is not created
  20. * directly, instead pass the {@link Ext.slider.Multi#useTips} and {@link Ext.slider.Multi#tipText} configuration
  21. * options to the slider directly.
  22. *
  23. * @example
  24. * Ext.create('Ext.slider.Single', {
  25. * width: 214,
  26. * minValue: 0,
  27. * maxValue: 100,
  28. * useTips: true,
  29. * renderTo: Ext.getBody()
  30. * });
  31. *
  32. * Optionally provide your own tip text by passing tipText:
  33. *
  34. * @example
  35. * Ext.create('Ext.slider.Single', {
  36. * width: 214,
  37. * minValue: 0,
  38. * maxValue: 100,
  39. * useTips: true,
  40. * tipText: function(thumb){
  41. * return Ext.String.format('**{0}% complete**', thumb.value);
  42. * },
  43. * renderTo: Ext.getBody()
  44. * });
  45. */
  46. Ext.define('Ext.slider.Tip', {
  47. extend: 'Ext.tip.Tip',
  48. minWidth: 10,
  49. alias: 'widget.slidertip',
  50. <span id='Ext-slider-Tip-cfg-offsets'> /**
  51. </span> * @cfg {Array} [offsets=null]
  52. * Offsets for aligning the tip to the slider. See {@link Ext.dom.Element#alignTo}. Default values
  53. * for offsets are provided by specifying the {@link #position} config.
  54. */
  55. offsets : null,
  56. <span id='Ext-slider-Tip-cfg-align'> /**
  57. </span> * @cfg {String} [align=null]
  58. * Alignment configuration for the tip to the slider. See {@link Ext.dom.Element#alignTo}. Default
  59. * values for alignment are provided by specifying the {@link #position} config.
  60. */
  61. align: null,
  62. <span id='Ext-slider-Tip-cfg-position'> /**
  63. </span> * @cfg {String} [position=For horizontal sliders, &quot;top&quot;, for vertical sliders, &quot;left&quot;]
  64. * Sets the position for where the tip will be displayed related to the thumb. This sets
  65. * defaults for {@link #align} and {@link #offsets} configurations. If {@link #align} or
  66. * {@link #offsets} configurations are specified, they will override the defaults defined
  67. * by position.
  68. */
  69. position: '',
  70. defaultVerticalPosition: 'left',
  71. defaultHorizontalPosition: 'top',
  72. isSliderTip: true,
  73. init: function(slider) {
  74. var me = this,
  75. align,
  76. offsets;
  77. if (!me.position) {
  78. me.position = slider.vertical ? me.defaultVerticalPosition : me.defaultHorizontalPosition;
  79. }
  80. switch (me.position) {
  81. case 'top':
  82. offsets = [0, -10];
  83. align = 'b-t?';
  84. break;
  85. case 'bottom':
  86. offsets = [0, 10];
  87. align = 't-b?';
  88. break;
  89. case 'left':
  90. offsets = [-10, 0];
  91. align = 'r-l?';
  92. break;
  93. case 'right':
  94. offsets = [10, 0];
  95. align = 'l-r?';
  96. }
  97. if (!me.align) {
  98. me.align = align;
  99. }
  100. if (!me.offsets) {
  101. me.offsets = offsets;
  102. }
  103. slider.on({
  104. scope : me,
  105. dragstart: me.onSlide,
  106. drag : me.onSlide,
  107. dragend : me.hide,
  108. destroy : me.destroy
  109. });
  110. },
  111. <span id='Ext-slider-Tip-method-onSlide'> /**
  112. </span> * @private
  113. * Called whenever a dragstart or drag event is received on the associated Thumb.
  114. * Aligns the Tip with the Thumb's new position.
  115. * @param {Ext.slider.MultiSlider} slider The slider
  116. * @param {Ext.EventObject} e The Event object
  117. * @param {Ext.slider.Thumb} thumb The thumb that the Tip is attached to
  118. */
  119. onSlide : function(slider, e, thumb) {
  120. var me = this;
  121. me.show();
  122. me.update(me.getText(thumb));
  123. me.el.alignTo(thumb.el, me.align, me.offsets);
  124. },
  125. <span id='Ext-slider-Tip-method-getText'> /**
  126. </span> * Used to create the text that appears in the Tip's body. By default this just returns the value of the Slider
  127. * Thumb that the Tip is attached to. Override to customize.
  128. * @param {Ext.slider.Thumb} thumb The Thumb that the Tip is attached to
  129. * @return {String} The text to display in the tip
  130. * @protected
  131. * @template
  132. */
  133. getText : function(thumb) {
  134. return String(thumb.value);
  135. }
  136. });</pre>
  137. </body>
  138. </html>