source: Dev/branches/rest-dojo-ui/client/dojox/widget/FisheyeLite.js @ 256

Last change on this file since 256 was 256, checked in by hendrikvanantwerpen, 13 years ago

Reworked project structure based on REST interaction and Dojo library. As
soon as this is stable, the old jQueryUI branch can be removed (it's
kept for reference).

File size: 4.3 KB
Line 
1define(["dojo", "dojox", "dijit/_Widget", "dojo/fx/easing"], function(dojo, dojox, widget, easing){
2       
3        dojo.getObject("widget", true, dojox);
4        dojo.experimental("dojox.widget.FisheyeLite");
5
6        return dojo.declare("dojox.widget.FisheyeLite",
7                dijit._Widget,
8                {
9                // summary:  A Light-weight Fisheye Component, or an exhanced version
10                //              of dojo.fx.Toggler ...
11                //
12                // description:
13                //              A Simple FisheyeList-like widget which (in the interest of
14                //              performance) relies on well-styled content for positioning,
15                //              and natural page layout for rendering.
16                //
17                //              use position:absolute/relative nodes to prevent layout
18                //              changes, and use caution when seleting properties to
19                //              scale. Negative scaling works, but some properties
20                //              react poorly to being set to negative values, IE being
21                //              particularly annoying in that regard.
22                //
23                //              quirk: uses the domNode as the target of the animation
24                //              unless it finds a node class="fisheyeTarget" in the container
25                //              being turned into a FisheyeLite instance
26                //
27                // example:
28                //      |       // make all the LI's in a node Fisheye's:
29                //      |   dojo.query("#node li").forEach(function(n){
30                //      |               new dojox.widget.FisheyeLite({},n);
31                //      |       });
32                //
33                //
34                // example:
35                //      |       new dojox.widget.FisheyeLite({
36                //      |               properties:{
37                //      |                       // height is literal, width is multiplied
38                //      |                       height:{ end: 200 }, width:2.3
39                //      |               }
40                //      |       }, "someNode");
41                //
42                // duationIn: Integer
43                //              The time (in ms) the run the show animation
44                durationIn: 350,
45
46                // easeIn: Function
47                //              An easing function to use for the show animation
48                easeIn: easing.backOut,
49
50                // durationOut: Integer
51                //              The Time (in ms) to run the hide animation
52                durationOut: 1420,
53
54                // easeOut: Function
55                //              An easing function to use for the hide animation
56                easeOut: easing.elasticOut,
57
58                //      properties: Object
59                //                      An object of "property":scale pairs, or "property":{} pairs.
60                //                      defaults to font-size with a scale of 2.75
61                //                      If a named property is an integer or float, the "scale multiplier"
62                //                      is used. If the named property is an object, that object is mixed
63                //                      into the animation directly. eg: height:{ end:20, units:"em" }
64                properties: null,
65
66                // units: String
67                //              Sometimes, you need to specify a unit. Should be part of
68                //              properties attrib, but was trying to shorthand the logic there
69                units:"px",
70
71                constructor: function(props, node){
72                        this.properties = props.properties || {
73                                fontSize: 2.75
74                        }
75                },
76
77                postCreate: function(){
78
79                        this.inherited(arguments);
80                        this._target = dojo.query(".fisheyeTarget", this.domNode)[0] || this.domNode;
81                        this._makeAnims();
82
83                        this.connect(this.domNode, "onmouseover", "show");
84                        this.connect(this.domNode, "onmouseout", "hide");
85                        this.connect(this._target, "onclick", "onClick");
86
87                },
88
89                show: function(){
90                        // summary:
91                        //              Show this Fisheye item.
92                        this._runningOut.stop();
93                        this._runningIn.play();
94                },
95
96                hide: function(){
97                        // summary:
98                        //              Hide this fisheye item on mouse leave
99                        this._runningIn.stop();
100                        this._runningOut.play();
101                },
102
103                _makeAnims: function(){
104                        // summary:
105                        //              Pre-generate the animations
106
107                        // create two properties: objects, one for each "state"
108                        var _in = {}, _out = {}, cs = dojo.getComputedStyle(this._target);
109                        for(var p in this.properties){
110                                var prop = this.properties[p],
111                                        deep = dojo.isObject(prop),
112                                        v = parseInt(cs[p])
113                                ;
114                                // note: do not set negative scale for [a list of properties] for IE support
115                                // note: filter:'s are your own issue, too ;)
116                                // FIXME: this.unit here is bad, likely. d._toPixelValue ?
117                                _out[p] = { end: v, units:this.units };
118                                _in[p] = deep ? prop : { end: prop * v, units:this.units };
119                        }
120
121                        this._runningIn = dojo.animateProperty({
122                                node: this._target,
123                                easing: this.easeIn,
124                                duration: this.durationIn,
125                                properties: _in
126                        });
127
128                        this._runningOut = dojo.animateProperty({
129                                node: this._target,
130                                duration: this.durationOut,
131                                easing: this.easeOut,
132                                properties: _out
133                        });
134
135                        this.connect(this._runningIn, "onEnd", dojo.hitch(this, "onSelected", this));
136                },
137
138                onClick: function(/* Event */e){
139                        // summary: stub function fired when target is clicked
140                        //              connect or override to use.
141                },
142
143                onSelected: function(/* Object */e){
144                        // summary: stub function fired when Fisheye Item is fully visible and
145                        //              hovered. connect or override use.
146                }
147
148        });
149       
150});
Note: See TracBrowser for help on using the repository browser.