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