Upgrade to ExtJS 4.0.2 - Released 06/09/2011
[extjs.git] / docs / source / Tip.html
index df04629..89d606c 100644 (file)
-<html>\r
-<head>\r
-  <title>The source code</title>\r
-    <link href="../resources/prettify/prettify.css" type="text/css" rel="stylesheet" />\r
-    <script type="text/javascript" src="../resources/prettify/prettify.js"></script>\r
-</head>\r
-<body  onload="prettyPrint();">\r
-    <pre class="prettyprint lang-js"><div id="cls-Ext.Tip"></div>/**\r
- * @class Ext.Tip\r
- * @extends Ext.Panel\r
- * This is the base class for {@link Ext.QuickTip} and {@link Ext.Tooltip} that provides the basic layout and\r
- * positioning that all tip-based classes require. This class can be used directly for simple, statically-positioned\r
- * tips that are displayed programmatically, or it can be extended to provide custom tip implementations.\r
- * @constructor\r
- * Create a new Tip\r
- * @param {Object} config The configuration options\r
- */\r
-Ext.Tip = Ext.extend(Ext.Panel, {\r
-    <div id="cfg-Ext.Tip-closable"></div>/**\r
-     * @cfg {Boolean} closable True to render a close tool button into the tooltip header (defaults to false).\r
-     */\r
-    <div id="cfg-Ext.Tip-width"></div>/**\r
-     * @cfg {Number} width\r
-     * Width in pixels of the tip (defaults to auto).  Width will be ignored if it exceeds the bounds of\r
-     * {@link #minWidth} or {@link #maxWidth}.  The maximum supported value is 500.\r
-     */\r
-    <div id="cfg-Ext.Tip-minWidth"></div>/**\r
-     * @cfg {Number} minWidth The minimum width of the tip in pixels (defaults to 40).\r
-     */\r
-    minWidth : 40,\r
-    <div id="cfg-Ext.Tip-maxWidth"></div>/**\r
-     * @cfg {Number} maxWidth The maximum width of the tip in pixels (defaults to 300).  The maximum supported value is 500.\r
-     */\r
-    maxWidth : 300,\r
-    <div id="cfg-Ext.Tip-shadow"></div>/**\r
-     * @cfg {Boolean/String} shadow True or "sides" for the default effect, "frame" for 4-way shadow, and "drop"\r
-     * for bottom-right shadow (defaults to "sides").\r
-     */\r
-    shadow : "sides",\r
-    <div id="cfg-Ext.Tip-defaultAlign"></div>/**\r
-     * @cfg {String} defaultAlign <b>Experimental</b>. The default {@link Ext.Element#alignTo} anchor position value\r
-     * for this tip relative to its element of origin (defaults to "tl-bl?").\r
-     */\r
-    defaultAlign : "tl-bl?",\r
-    autoRender: true,\r
-    quickShowInterval : 250,\r
-\r
-    // private panel overrides\r
-    frame:true,\r
-    hidden:true,\r
-    baseCls: 'x-tip',\r
-    floating:{shadow:true,shim:true,useDisplay:true,constrain:false},\r
-    autoHeight:true,\r
-\r
-    closeAction: 'hide',\r
-\r
-    // private\r
-    initComponent : function(){\r
-        Ext.Tip.superclass.initComponent.call(this);\r
-        if(this.closable && !this.title){\r
-            this.elements += ',header';\r
-        }\r
-    },\r
-\r
-    // private\r
-    afterRender : function(){\r
-        Ext.Tip.superclass.afterRender.call(this);\r
-        if(this.closable){\r
-            this.addTool({\r
-                id: 'close',\r
-                handler: this[this.closeAction],\r
-                scope: this\r
-            });\r
-        }\r
-    },\r
-\r
-    <div id="method-Ext.Tip-showAt"></div>/**\r
-     * Shows this tip at the specified XY position.  Example usage:\r
-     * <pre><code>\r
-// Show the tip at x:50 and y:100\r
-tip.showAt([50,100]);\r
-</code></pre>\r
-     * @param {Array} xy An array containing the x and y coordinates\r
-     */\r
-    showAt : function(xy){\r
-        Ext.Tip.superclass.show.call(this);\r
-        if(this.measureWidth !== false && (!this.initialConfig || typeof this.initialConfig.width != 'number')){\r
-            this.doAutoWidth();\r
-        }\r
-        if(this.constrainPosition){\r
-            xy = this.el.adjustForConstraints(xy);\r
-        }\r
-        this.setPagePosition(xy[0], xy[1]);\r
-    },\r
-\r
-    // protected\r
-    doAutoWidth : function(){\r
-        var bw = this.body.getTextWidth();\r
-        if(this.title){\r
-            bw = Math.max(bw, this.header.child('span').getTextWidth(this.title));\r
-        }\r
-        bw += this.getFrameWidth() + (this.closable ? 20 : 0) + this.body.getPadding("lr");\r
-        this.setWidth(bw.constrain(this.minWidth, this.maxWidth));\r
-        \r
-        // IE7 repaint bug on initial show\r
-        if(Ext.isIE7 && !this.repainted){\r
-            this.el.repaint();\r
-            this.repainted = true;\r
-        }\r
-    },\r
-\r
-    <div id="method-Ext.Tip-showBy"></div>/**\r
-     * <b>Experimental</b>. Shows this tip at a position relative to another element using a standard {@link Ext.Element#alignTo}\r
-     * anchor position value.  Example usage:\r
-     * <pre><code>\r
-// Show the tip at the default position ('tl-br?')\r
-tip.showBy('my-el');\r
-\r
-// Show the tip's top-left corner anchored to the element's top-right corner\r
-tip.showBy('my-el', 'tl-tr');\r
-</code></pre>\r
-     * @param {Mixed} el An HTMLElement, Ext.Element or string id of the target element to align to\r
-     * @param {String} position (optional) A valid {@link Ext.Element#alignTo} anchor position (defaults to 'tl-br?' or\r
-     * {@link #defaultAlign} if specified).\r
-     */\r
-    showBy : function(el, pos){\r
-        if(!this.rendered){\r
-            this.render(Ext.getBody());\r
-        }\r
-        this.showAt(this.el.getAlignToXY(el, pos || this.defaultAlign));\r
-    },\r
-\r
-    initDraggable : function(){\r
-        this.dd = new Ext.Tip.DD(this, typeof this.draggable == 'boolean' ? null : this.draggable);\r
-        this.header.addClass('x-tip-draggable');\r
-    }\r
-});\r
-\r
-// private - custom Tip DD implementation\r
-Ext.Tip.DD = function(tip, config){\r
-    Ext.apply(this, config);\r
-    this.tip = tip;\r
-    Ext.Tip.DD.superclass.constructor.call(this, tip.el.id, 'WindowDD-'+tip.id);\r
-    this.setHandleElId(tip.header.id);\r
-    this.scroll = false;\r
-};\r
-\r
-Ext.extend(Ext.Tip.DD, Ext.dd.DD, {\r
-    moveOnly:true,\r
-    scroll:false,\r
-    headerOffsets:[100, 25],\r
-    startDrag : function(){\r
-        this.tip.el.disableShadow();\r
-    },\r
-    endDrag : function(e){\r
-        this.tip.el.enableShadow(true);\r
-    }\r
-});</pre>    \r
-</body>\r
-</html>
\ No newline at end of file
+<!DOCTYPE html>
+<html>
+<head>
+  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
+  <title>The source code</title>
+  <link href="../prettify/prettify.css" type="text/css" rel="stylesheet" />
+  <script type="text/javascript" src="../prettify/prettify.js"></script>
+  <style type="text/css">
+    .highlight { display: block; background-color: #ddd; }
+  </style>
+  <script type="text/javascript">
+    function highlight() {
+      document.getElementById(location.hash.replace(/#/, "")).className = "highlight";
+    }
+  </script>
+</head>
+<body onload="prettyPrint(); highlight();">
+  <pre class="prettyprint lang-js"><span id='Ext-slider-Tip'>/**
+</span> * @class Ext.slider.Tip
+ * @extends Ext.tip.Tip
+ * Simple plugin for using an Ext.tip.Tip with a slider to show the slider value. In general this
+ * class is not created directly, instead pass the {@link Ext.slider.Multi#useTips} and 
+ * {@link Ext.slider.Multi#tipText} configuration options to the slider directly.
+ * {@img Ext.slider.Tip/Ext.slider.Tip1.png Ext.slider.Tip component}
+ * Example usage:
+&lt;pre&gt;
+    Ext.create('Ext.slider.Single', {
+        width: 214,
+        minValue: 0,
+        maxValue: 100,
+        useTips: true,
+        renderTo: Ext.getBody()
+    });   
+&lt;/pre&gt;
+ * Optionally provide your own tip text by passing tipText:
+ &lt;pre&gt;
+ new Ext.slider.Single({
+     width: 214,
+     minValue: 0,
+     maxValue: 100,
+     useTips: true,
+     tipText: function(thumb){
+         return Ext.String.format('&lt;b&gt;{0}% complete&lt;/b&gt;', thumb.value);
+     }
+ });
+ &lt;/pre&gt;
+ */
+Ext.define('Ext.slider.Tip', {
+    extend: 'Ext.tip.Tip',
+    minWidth: 10,
+    alias: 'widget.slidertip',
+    offsets : [0, -10],
+    
+    isSliderTip: true,
+
+    init: function(slider) {
+        var me = this;
+        
+        slider.on({
+            scope    : me,
+            dragstart: me.onSlide,
+            drag     : me.onSlide,
+            dragend  : me.hide,
+            destroy  : me.destroy
+        });
+    },
+<span id='Ext-slider-Tip-method-onSlide'>    /**
+</span>     * @private
+     * Called whenever a dragstart or drag event is received on the associated Thumb. 
+     * Aligns the Tip with the Thumb's new position.
+     * @param {Ext.slider.MultiSlider} slider The slider
+     * @param {Ext.EventObject} e The Event object
+     * @param {Ext.slider.Thumb} thumb The thumb that the Tip is attached to
+     */
+    onSlide : function(slider, e, thumb) {
+        var me = this;
+        me.show();
+        me.update(me.getText(thumb));
+        me.doComponentLayout();
+        me.el.alignTo(thumb.el, 'b-t?', me.offsets);
+    },
+
+<span id='Ext-slider-Tip-method-getText'>    /**
+</span>     * Used to create the text that appears in the Tip's body. By default this just returns
+     * the value of the Slider Thumb that the Tip is attached to. Override to customize.
+     * @param {Ext.slider.Thumb} thumb The Thumb that the Tip is attached to
+     * @return {String} The text to display in the tip
+     */
+    getText : function(thumb) {
+        return String(thumb.value);
+    }
+});</pre>
+</body>
+</html>