Upgrade to ExtJS 4.0.2 - Released 06/09/2011
[extjs.git] / docs / source / Tip.html
index cac905d..89d606c 100644 (file)
+<!DOCTYPE html>
 <html>
 <head>
-  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />    
+  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
   <title>The source code</title>
-    <link href="../resources/prettify/prettify.css" type="text/css" rel="stylesheet" />
-    <script type="text/javascript" src="../resources/prettify/prettify.js"></script>
+  <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();">
-    <pre class="prettyprint lang-js">/*!
- * Ext JS Library 3.2.1
- * Copyright(c) 2006-2010 Ext JS, Inc.
- * licensing@extjs.com
- * http://www.extjs.com/license
- */
-<div id="cls-Ext.Tip"></div>/**
- * @class Ext.Tip
- * @extends Ext.Panel
- * @xtype tip
- * This is the base class for {@link Ext.QuickTip} and {@link Ext.Tooltip} that provides the basic layout and
- * positioning that all tip-based classes require. This class can be used directly for simple, statically-positioned
- * tips that are displayed programmatically, or it can be extended to provide custom tip implementations.
- * @constructor
- * Create a new Tip
- * @param {Object} config The configuration options
+<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.Tip = Ext.extend(Ext.Panel, {
-    <div id="cfg-Ext.Tip-closable"></div>/**
-     * @cfg {Boolean} closable True to render a close tool button into the tooltip header (defaults to false).
-     */
-    <div id="cfg-Ext.Tip-width"></div>/**
-     * @cfg {Number} width
-     * Width in pixels of the tip (defaults to auto).  Width will be ignored if it exceeds the bounds of
-     * {@link #minWidth} or {@link #maxWidth}.  The maximum supported value is 500.
-     */
-    <div id="cfg-Ext.Tip-minWidth"></div>/**
-     * @cfg {Number} minWidth The minimum width of the tip in pixels (defaults to 40).
-     */
-    minWidth : 40,
-    <div id="cfg-Ext.Tip-maxWidth"></div>/**
-     * @cfg {Number} maxWidth The maximum width of the tip in pixels (defaults to 300).  The maximum supported value is 500.
-     */
-    maxWidth : 300,
-    <div id="cfg-Ext.Tip-shadow"></div>/**
-     * @cfg {Boolean/String} shadow True or "sides" for the default effect, "frame" for 4-way shadow, and "drop"
-     * for bottom-right shadow (defaults to "sides").
-     */
-    shadow : "sides",
-    <div id="cfg-Ext.Tip-defaultAlign"></div>/**
-     * @cfg {String} defaultAlign <b>Experimental</b>. The default {@link Ext.Element#alignTo} anchor position value
-     * for this tip relative to its element of origin (defaults to "tl-bl?").
-     */
-    defaultAlign : "tl-bl?",
-    autoRender: true,
-    quickShowInterval : 250,
-
-    // private panel overrides
-    frame:true,
-    hidden:true,
-    baseCls: 'x-tip',
-    floating:{shadow:true,shim:true,useDisplay:true,constrain:false},
-    autoHeight:true,
-
-    closeAction: 'hide',
+Ext.define('Ext.slider.Tip', {
+    extend: 'Ext.tip.Tip',
+    minWidth: 10,
+    alias: 'widget.slidertip',
+    offsets : [0, -10],
+    
+    isSliderTip: true,
 
-    // private
-    initComponent : function(){
-        Ext.Tip.superclass.initComponent.call(this);
-        if(this.closable && !this.title){
-            this.elements += ',header';
-        }
-    },
-
-    // private
-    afterRender : function(){
-        Ext.Tip.superclass.afterRender.call(this);
-        if(this.closable){
-            this.addTool({
-                id: 'close',
-                handler: this[this.closeAction],
-                scope: this
-            });
-        }
-    },
-
-    <div id="method-Ext.Tip-showAt"></div>/**
-     * Shows this tip at the specified XY position.  Example usage:
-     * <pre><code>
-// Show the tip at x:50 and y:100
-tip.showAt([50,100]);
-</code></pre>
-     * @param {Array} xy An array containing the x and y coordinates
-     */
-    showAt : function(xy){
-        Ext.Tip.superclass.show.call(this);
-        if(this.measureWidth !== false && (!this.initialConfig || typeof this.initialConfig.width != 'number')){
-            this.doAutoWidth();
-        }
-        if(this.constrainPosition){
-            xy = this.el.adjustForConstraints(xy);
-        }
-        this.setPagePosition(xy[0], xy[1]);
-    },
-
-    // protected
-    doAutoWidth : function(adjust){
-        adjust = adjust || 0;
-        var bw = this.body.getTextWidth();
-        if(this.title){
-            bw = Math.max(bw, this.header.child('span').getTextWidth(this.title));
-        }
-        bw += this.getFrameWidth() + (this.closable ? 20 : 0) + this.body.getPadding("lr") + adjust;
-        this.setWidth(bw.constrain(this.minWidth, this.maxWidth));
+    init: function(slider) {
+        var me = this;
         
-        // IE7 repaint bug on initial show
-        if(Ext.isIE7 && !this.repainted){
-            this.el.repaint();
-            this.repainted = true;
-        }
+        slider.on({
+            scope    : me,
+            dragstart: me.onSlide,
+            drag     : me.onSlide,
+            dragend  : me.hide,
+            destroy  : me.destroy
+        });
     },
-
-    <div id="method-Ext.Tip-showBy"></div>/**
-     * <b>Experimental</b>. Shows this tip at a position relative to another element using a standard {@link Ext.Element#alignTo}
-     * anchor position value.  Example usage:
-     * <pre><code>
-// Show the tip at the default position ('tl-br?')
-tip.showBy('my-el');
-
-// Show the tip's top-left corner anchored to the element's top-right corner
-tip.showBy('my-el', 'tl-tr');
-</code></pre>
-     * @param {Mixed} el An HTMLElement, Ext.Element or string id of the target element to align to
-     * @param {String} position (optional) A valid {@link Ext.Element#alignTo} anchor position (defaults to 'tl-br?' or
-     * {@link #defaultAlign} if specified).
+<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
      */
-    showBy : function(el, pos){
-        if(!this.rendered){
-            this.render(Ext.getBody());
-        }
-        this.showAt(this.el.getAlignToXY(el, pos || this.defaultAlign));
+    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);
     },
 
-    initDraggable : function(){
-        this.dd = new Ext.Tip.DD(this, typeof this.draggable == 'boolean' ? null : this.draggable);
-        this.header.addClass('x-tip-draggable');
-    }
-});
-
-Ext.reg('tip', Ext.Tip);
-
-// private - custom Tip DD implementation
-Ext.Tip.DD = function(tip, config){
-    Ext.apply(this, config);
-    this.tip = tip;
-    Ext.Tip.DD.superclass.constructor.call(this, tip.el.id, 'WindowDD-'+tip.id);
-    this.setHandleElId(tip.header.id);
-    this.scroll = false;
-};
-
-Ext.extend(Ext.Tip.DD, Ext.dd.DD, {
-    moveOnly:true,
-    scroll:false,
-    headerOffsets:[100, 25],
-    startDrag : function(){
-        this.tip.el.disableShadow();
-    },
-    endDrag : function(e){
-        this.tip.el.enableShadow(true);
+<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>    
+});</pre>
 </body>
-</html>
\ No newline at end of file
+</html>