Merge lp:~jcsackett/juju-gui/charm-slider into lp:juju-gui/experimental

Proposed by j.c.sackett
Status: Merged
Merged at revision: 420
Proposed branch: lp:~jcsackett/juju-gui/charm-slider
Merge into: lp:juju-gui/experimental
Diff against target: 512 lines (+447/-2)
8 files modified
app/modules-debug.js (+4/-0)
app/templates/charm-small-widget.handlebars (+1/-1)
app/widgets/charm-slider.js (+329/-0)
app/widgets/charm-small.js (+1/-1)
lib/views/browser/charm-slider.less (+29/-0)
lib/views/stylesheet.less (+1/-0)
test/index.html (+1/-0)
test/test_charm_slider.js (+81/-0)
To merge this branch: bzr merge lp:~jcsackett/juju-gui/charm-slider
Reviewer Review Type Date Requested Status
Juju GUI Hackers Pending
Review via email: mp+152418@code.launchpad.net

Description of the change

Adds the charm slider widget

This adds a slider widget derived from Jeff Pihach's flickr carousel. It
doesn't wire it into anything yet.

https://codereview.appspot.com/7641043/

To post a comment you must log in.
Revision history for this message
j.c.sackett (jcsackett) wrote :

Reviewers: mp+152418_code.launchpad.net,

Message:
Please take a look.

Description:
Adds the charm slider widget

This adds a slider widget derived from Jeff Pihach's flickr carousel. It
doesn't wire it into anything yet.

https://code.launchpad.net/~jcsackett/juju-gui/charm-slider/+merge/152418

(do not edit description out of merge proposal)

Please review this at https://codereview.appspot.com/7641043/

Affected files:
   A [revision details]
   M app/modules-debug.js
   M app/templates/charm-small-widget.handlebars
   A app/widgets/charm-slider.js
   M app/widgets/charm-small.js
   A lib/views/browser/charm-slider.less
   M lib/views/stylesheet.less
   M test/index.html
   A test/test_charm_slider.js

Revision history for this message
Richard Harding (rharding) wrote :
Download full text (4.7 KiB)

Some light weight changes. Many have a lot of occurances so didn't mark
each one for the first pass, but {Object} vs { Object } and String vs
string.

Some other suggestions and additional tests requested.

https://codereview.appspot.com/7641043/diff/1/app/widgets/charm-slider.js
File app/widgets/charm-slider.js (right):

https://codereview.appspot.com/7641043/diff/1/app/widgets/charm-slider.js#newcode7
app/widgets/charm-slider.js:7: * @namespace juju.widgets.browser
namespace juju; modules widgets; submodule browser.notifier I think is
how it works.

https://codereview.appspot.com/7641043/diff/1/app/widgets/charm-slider.js#newcode12
app/widgets/charm-slider.js:12: var sub = Y.Lang.sub;
comma here and combine with next var

https://codereview.appspot.com/7641043/diff/1/app/widgets/charm-slider.js#newcode21
app/widgets/charm-slider.js:21: *
In the doc string can you put a sample of min. html needed to use the
widget? Want to include enough to reuse without too much hunting.

https://codereview.appspot.com/7641043/diff/1/app/widgets/charm-slider.js#newcode29
app/widgets/charm-slider.js:29: * @type { string }
Caps String for a class name. No spaces inside the {}.

https://codereview.appspot.com/7641043/diff/1/app/widgets/charm-slider.js#newcode66
app/widgets/charm-slider.js:66:
extra space here

https://codereview.appspot.com/7641043/diff/1/app/widgets/charm-slider.js#newcode82
app/widgets/charm-slider.js:82:
extra space here (my snippets fault I know...)

https://codereview.appspot.com/7641043/diff/1/app/widgets/charm-slider.js#newcode83
app/widgets/charm-slider.js:83: _generateDOM: function() {
please move private methods to the top of the class functions.

https://codereview.appspot.com/7641043/diff/1/app/widgets/charm-slider.js#newcode90
app/widgets/charm-slider.js:90: sub(that.itemTemplate, {width:
that.get('width'), index: index}));
you get width twice. Please just get the var and cache it to avoid
lookups that aren't required.

https://codereview.appspot.com/7641043/diff/1/app/widgets/charm-slider.js#newcode115
app/widgets/charm-slider.js:115: * Advances the slider to the next item,
or a designated index
end comment with .

https://codereview.appspot.com/7641043/diff/1/app/widgets/charm-slider.js#newcode128
app/widgets/charm-slider.js:128: index = parseInt(index, 10);
why does index need to be parsed? How is it coming in as a string?

https://codereview.appspot.com/7641043/diff/1/app/widgets/charm-slider.js#newcode184
app/widgets/charm-slider.js:184: this.set('pauseOnHover', true);
can we rename this to pause(d)OnHover. It matches up better since it's a
completed state. Maybe even just move to paused. Who cares if we're
paused for hover or some manual control.

https://codereview.appspot.com/7641043/diff/1/app/widgets/charm-slider.js#newcode200
app/widgets/charm-slider.js:200:
Y.juju.widgets.browser.CharmSlider.superclass.bindUI.apply(this);
to prevent the nested lookup use ns. please.

https://codereview.appspot.com/7641043/diff/1/app/widgets/charm-slider.js#newcode244
app/widgets/charm-slider.js:244: * @default 500
since this is a little slider let's default to something closer to what
we would use like 150 or 200px.

https://coderevie...

Read more...

lp:~jcsackett/juju-gui/charm-slider updated
431. By j.c.sackett

Addressed comments from review.

Revision history for this message
j.c.sackett (jcsackett) wrote :

Agree with most comments, address the remainder. Code is coming up
shortly.

https://codereview.appspot.com/7641043/diff/1/app/widgets/charm-slider.js
File app/widgets/charm-slider.js (right):

https://codereview.appspot.com/7641043/diff/1/app/widgets/charm-slider.js#newcode21
app/widgets/charm-slider.js:21: *
On 2013/03/08 15:12:02, rharding wrote:
> In the doc string can you put a sample of min. html needed to use the
widget?
> Want to include enough to reuse without too much hunting.

Per discussion, this doesn't actual require any setup; just pass in
parentNode to render, as with default Y.Widget.

https://codereview.appspot.com/7641043/diff/1/app/widgets/charm-slider.js#newcode128
app/widgets/charm-slider.js:128: index = parseInt(index, 10);
On 2013/03/08 15:12:02, rharding wrote:
> why does index need to be parsed? How is it coming in as a string?

We get index out of a data-* attribute on the element, but I have moved
the parseInt to where we fetch it, so it's an int when it hits this
method.

https://codereview.appspot.com/7641043/

Revision history for this message
j.c.sackett (jcsackett) wrote :
Revision history for this message
Jeff Pihach (hatch) wrote :

Thanks for the code! See my comments (as we discussed) below.

https://codereview.appspot.com/7641043/diff/8001/app/widgets/charm-slider.js
File app/widgets/charm-slider.js (right):

https://codereview.appspot.com/7641043/diff/8001/app/widgets/charm-slider.js#newcode72
app/widgets/charm-slider.js:72: if (Y.Lang.isValue(index)) {
We decided to no longer use isValue() as all it's really doing is a
glorified falsy check

https://codereview.appspot.com/7641043/diff/8001/app/widgets/charm-slider.js#newcode102
app/widgets/charm-slider.js:102: sub(that.itemTemplate, {width: width,
index: index}));
There is no need to do the that=this trick here because (like most
methods of this type in yui) it has a final param which is the context.

http://yuilibrary.com/yui/docs/api/classes/Array.html#method_map

https://codereview.appspot.com/7641043/diff/8001/app/widgets/charm-slider.js#newcode103
app/widgets/charm-slider.js:103: tmpNode.setContent(item);
setContent() is depricated use setHTML()

https://codereview.appspot.com/7641043/diff/8001/app/widgets/charm-slider.js#newcode116
app/widgets/charm-slider.js:116: Y.log('_generateSliderControls',
'info', this.name);
I think we have standardized on using console.log()

https://codereview.appspot.com/7641043/diff/8001/app/widgets/charm-slider.js#newcode119
app/widgets/charm-slider.js:119: Y.Array.each(this.get('items'),
function(item, index) {
Like I mentioned above, YUI's iterators have a context param as the
final param so the that=this can be removed in favour of that.

https://codereview.appspot.com/7641043/diff/8001/app/widgets/charm-slider.js#newcode195
app/widgets/charm-slider.js:195: var index =
this.getAttribute('data-index');
event callbacks are passed an event object which hold reference to the
target.

so this can be changed to e.currentTarget.getAttribute('data-index');

https://codereview.appspot.com/7641043/diff/8001/app/widgets/charm-slider.js#newcode198
app/widgets/charm-slider.js:198: }, 'li'));
delegate() also has a context property

https://codereview.appspot.com/7641043/diff/8001/lib/views/browser/charm-slider.less
File lib/views/browser/charm-slider.less (right):

https://codereview.appspot.com/7641043/diff/8001/lib/views/browser/charm-slider.less#newcode1
lib/views/browser/charm-slider.less:1:
.yui3-browser-charm-slider-content {
Because we are using less you can actually nest most of the rules in
this commit - let me know if you need help doing this.

https://codereview.appspot.com/7641043/

lp:~jcsackett/juju-gui/charm-slider updated
432. By j.c.sackett

Changes from hatch's review

Revision history for this message
j.c.sackett (jcsackett) wrote :

On 2013/03/08 19:23:49, jeff.pihach wrote:
> Thanks for the code! See my comments (as we discussed) below.

https://codereview.appspot.com/7641043/diff/8001/app/widgets/charm-slider.js
> File app/widgets/charm-slider.js (right):

https://codereview.appspot.com/7641043/diff/8001/app/widgets/charm-slider.js#newcode72
> app/widgets/charm-slider.js:72: if (Y.Lang.isValue(index)) {
> We decided to no longer use isValue() as all it's really doing is a
glorified
> falsy check

https://codereview.appspot.com/7641043/diff/8001/app/widgets/charm-slider.js#newcode102
> app/widgets/charm-slider.js:102: sub(that.itemTemplate, {width: width,
index:
> index}));
> There is no need to do the that=this trick here because (like most
methods of
> this type in yui) it has a final param which is the context.

> http://yuilibrary.com/yui/docs/api/classes/Array.html#method_map

https://codereview.appspot.com/7641043/diff/8001/app/widgets/charm-slider.js#newcode103
> app/widgets/charm-slider.js:103: tmpNode.setContent(item);
> setContent() is depricated use setHTML()

https://codereview.appspot.com/7641043/diff/8001/app/widgets/charm-slider.js#newcode116
> app/widgets/charm-slider.js:116: Y.log('_generateSliderControls',
'info',
> this.name);
> I think we have standardized on using console.log()

https://codereview.appspot.com/7641043/diff/8001/app/widgets/charm-slider.js#newcode119
> app/widgets/charm-slider.js:119: Y.Array.each(this.get('items'),
function(item,
> index) {
> Like I mentioned above, YUI's iterators have a context param as the
final param
> so the that=this can be removed in favour of that.

https://codereview.appspot.com/7641043/diff/8001/app/widgets/charm-slider.js#newcode195
> app/widgets/charm-slider.js:195: var index =
this.getAttribute('data-index');
> event callbacks are passed an event object which hold reference to the
target.

> so this can be changed to e.currentTarget.getAttribute('data-index');

https://codereview.appspot.com/7641043/diff/8001/app/widgets/charm-slider.js#newcode198
> app/widgets/charm-slider.js:198: }, 'li'));
> delegate() also has a context property

https://codereview.appspot.com/7641043/diff/8001/lib/views/browser/charm-slider.less
> File lib/views/browser/charm-slider.less (right):

https://codereview.appspot.com/7641043/diff/8001/lib/views/browser/charm-slider.less#newcode1
> lib/views/browser/charm-slider.less:1:
.yui3-browser-charm-slider-content {
> Because we are using less you can actually nest most of the rules in
this commit
> - let me know if you need help doing this.

I've address your points, code coming shortly.

https://codereview.appspot.com/7641043/

Revision history for this message
j.c.sackett (jcsackett) wrote :
Revision history for this message
Jeff Pihach (hatch) wrote :
Revision history for this message
Richard Harding (rharding) wrote :

On 2013/03/08 20:17:48, jeff.pihach wrote:
> LGTM

lgtm as well

https://codereview.appspot.com/7641043/

Revision history for this message
j.c.sackett (jcsackett) wrote :

*** Submitted:

Adds the charm slider widget

This adds a slider widget derived from Jeff Pihach's flickr carousel. It
doesn't wire it into anything yet.

R=rharding, jeff.pihach
CC=
https://codereview.appspot.com/7641043

https://codereview.appspot.com/7641043/

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'app/modules-debug.js'
--- app/modules-debug.js 2013-03-06 16:17:11 +0000
+++ app/modules-debug.js 2013-03-08 19:44:21 +0000
@@ -52,6 +52,10 @@
52 fullpath: '/juju-ui/widgets/charm-small.js'52 fullpath: '/juju-ui/widgets/charm-small.js'
53 },53 },
5454
55 'browser-charm-slider': {
56 fullpath: '/juju-ui/widgets/charm-slider.js'
57 },
58
55 'reconnecting-websocket': {59 'reconnecting-websocket': {
56 fullpath: '/juju-ui/assets/javascripts/reconnecting-websocket.js'60 fullpath: '/juju-ui/assets/javascripts/reconnecting-websocket.js'
57 },61 },
5862
=== modified file 'app/templates/charm-small-widget.handlebars'
--- app/templates/charm-small-widget.handlebars 2013-03-01 20:58:58 +0000
+++ app/templates/charm-small-widget.handlebars 2013-03-08 19:44:21 +0000
@@ -1,4 +1,4 @@
1<div >1<div>
2 <img url="{{ iconfile }}" />2 <img url="{{ iconfile }}" />
3 <h3 class="title">{{ title }}</h3>3 <h3 class="title">{{ title }}</h3>
4 <p class="description">{{ description }}</p>4 <p class="description">{{ description }}</p>
55
=== added file 'app/widgets/charm-slider.js'
--- app/widgets/charm-slider.js 1970-01-01 00:00:00 +0000
+++ app/widgets/charm-slider.js 2013-03-08 19:44:21 +0000
@@ -0,0 +1,329 @@
1'use strict';
2
3
4/**
5 * Provides the Charm Slider widget.
6 *
7 * @namespace juju
8 * @module widgets
9 * @submodule browser.CharmSlider
10 *
11 */
12YUI.add('browser-charm-slider', function(Y) {
13 var sub = Y.Lang.sub,
14 ns = Y.namespace('juju.widgets.browser');
15
16 /**
17 * The CharmSlider provides a rotating display of one member of a generic set
18 * of items, with controls to go directly to a given item.
19 *
20 * @class CharmSlider
21 * @extends {Y.ScrollView}
22 *
23 */
24 ns.CharmSlider = new Y.Base.create('browser-charm-slider', Y.ScrollView, [], {
25
26 /**
27 * Template for the CharmSlider
28 *
29 * @property charmSliderTemplate
30 * @type {String}
31 *
32 */
33 charmSliderTemplate: '<ul width="{width}px" />',
34
35 /**
36 * Template for a given item in the slider
37 *
38 * @property itemTemplate
39 * @type {String}
40 *
41 */
42 itemTemplate: '<li width="{width}px" data-index="{index}" />',
43
44 /**
45 * Template used for the navigation controls.
46 *
47 * @property prevNavTemplate
48 * @type {String}
49 */
50 navTemplate: '<ul class="navigation"></div>',
51
52 /**
53 * Template used for items in the navigation.
54 *
55 * @property navItemTemplate
56 * @type {String}
57 */
58 navItemTemplate: '<li data-index="{index}">O</li>',
59
60 /**
61 * Advances the slider to the next item, or a designated index.
62 *
63 * @method _advanceSlide
64 * @param {string} Index to move to; if not supplied, advances to next
65 * slide.
66 * @private
67 */
68 _advanceSlide: function(index) {
69 var pages = this.pages;
70 if (index) {
71 this._stopTimer();
72 pages.scrollToIndex(index);
73 this._startTimer();
74 } else {
75 index = pages.get('index');
76 if (index < pages.get('total') - 1) {
77 pages.next();
78 } else {
79 pages.scrollToIndex(0);
80 }
81 }
82 },
83
84 /**
85 * Creates the structure and DOM nodes for the slider.
86 *
87 * @method _generateDOM
88 * @private
89 * @return {Node} The slider's DOM nodes.
90 *
91 */
92 _generateDOM: function() {
93 var width = this.get('width'),
94 slider = Y.Node.create(
95 sub(this.charmSliderTemplate, {width: width}));
96
97 Y.Array.map(this.get('items'), function(item, index) {
98 var tmpNode = Y.Node.create(
99 sub(this.itemTemplate, {width: width, index: index}));
100 tmpNode.setHTML(item);
101 slider.append(tmpNode);
102 }, this);
103 return slider;
104 },
105
106 /**
107 * Generates and appends the navigation controls for the slider
108 *
109 * @method _generateSliderControls
110 * @private
111 */
112 _generateSliderControls: function() {
113 var nav = Y.Node.create(this.navTemplate);
114 Y.Array.each(this.get('items'), function(item, index) {
115 nav.append(Y.Node.create(sub(
116 this.navItemTemplate, {index: index})));
117 }, this);
118 this.get('boundingBox').append(nav);
119 },
120
121 /**
122 * Mouseenter/mouseleave event handler
123 *
124 * @method _pauseAutoAdvance
125 * @private
126 * @param {object} mouseout or mouseover event object.
127 */
128 _pauseAutoAdvance: function(e) {
129 if (e.type === 'mouseenter') {
130 this.set('paused', true);
131 } else {
132 this.set('paused', false);
133 }
134 },
135
136 /**
137 * Checks to see if autoadvance is set then sets up the timeouts
138 *
139 * @method _startTimer
140 * @private
141 */
142 _startTimer: function() {
143
144 if (this.get('autoAdvance') === true) {
145 var timer = Y.later(this.get('advanceDelay'), this, function() {
146 if (this.get('paused') !== true) {
147 this._advanceSlide();
148 }
149 }, null, true);
150 this.set('timer', timer);
151 }
152 },
153
154 /**
155 * Stops the timer for autoadvance
156 *
157 * @method _stopTimer
158 * @private
159 */
160 _stopTimer: function() {
161 var timer = this.get('timer');
162 if (timer) {
163 timer.cancel();
164 }
165 },
166
167 /**
168 * Binds the navigate event listeners
169 *
170 * @method bindUI
171 * @private
172 */
173 bindUI: function() {
174
175 //Call the parent bindUI method
176 ns.CharmSlider.superclass.bindUI.apply(this);
177
178 var events = this.get('_events'),
179 boundingBox = this.get('boundingBox'),
180 nav = boundingBox.one('.navigation');
181 events.push(this.after('render', this._startTimer, this));
182 events.push(boundingBox.on('mouseenter', this._pauseAutoAdvance, this));
183 events.push(boundingBox.on('mouseleave', this._pauseAutoAdvance, this));
184 events.push(nav.delegate('click', function(e) {
185 var index = e.currentTarget.getAttribute('data-index');
186 index = parseInt(index, 10);
187 this._advanceSlide(index);
188 }, 'li', this));
189 },
190
191 /**
192 * Detaches events attached during instantiation
193 *
194 * @method destructor
195 * @private
196 */
197 destructor: function() {
198 this.get('_events').each(function(event) {
199 event.detach();
200 });
201 },
202
203 /**
204 * Initializer
205 *
206 * @method initializer
207 * @param {Object} The config object.
208 *
209 */
210 initializer: function(cfg) {
211 this.plug(Y.Plugin.ScrollViewPaginator, {
212 selector: 'li'
213 });
214
215 },
216
217 /**
218 * Render the nodes and HTML for the slider.
219 *
220 * @method renderUI
221 * @private
222 */
223 renderUI: function() {
224 this.get('contentBox').setHTML(this._generateDOM());
225 this._generateSliderControls();
226 }
227 }, {
228 ATTRS: {
229
230 /**
231 * @attribute width
232 * @default 200
233 * @type {Int}
234 *
235 */
236 width: {
237 value: 500
238 },
239
240 /**
241 * @attribute autoAdvance
242 * @default true
243 * @type {Boolean}
244 *
245 */
246 autoAdvance: {
247 value: true
248 },
249
250 /**
251 * @attribute advanceDelay
252 * @default 3000
253 * @type {Int}
254 *
255 */
256 advanceDelay: {
257 value: 3000
258 },
259
260 /**
261 * @attribute paused
262 * @default false
263 * @type {Boolean}
264 *
265 */
266 paused: {
267 value: false
268 },
269
270 /**
271 * @attribute items
272 * @default []
273 * @type {Array}
274 *
275 */
276 items: {
277 value: [],
278 /**
279 * Verify items aren't larger than max value.
280 *
281 * @method validator
282 * @param {Array} The items being validated.
283 */
284 validator: function(val) {
285 return (val.length <= this.get('max'));
286 }
287 },
288
289 /**
290 * @attribute _events
291 * @default []
292 * @type {Array}
293 *
294 */
295 _events: {
296 value: []
297 },
298
299 /**
300 * @attribute max
301 * @default 5
302 * @type {Int}
303 *
304 */
305 max: {
306 value: 5
307 },
308
309 /**
310 * @attribute timer
311 * @default null
312 * @type {Object}
313 *
314 */
315 timer: {
316 value: null
317 }
318 }
319 });
320
321}, '0.1.0', {
322 requires: [
323 'array-extras',
324 'base',
325 'event-mouseenter',
326 'scrollview',
327 'scrollview-paginator'
328 ]
329});
0330
=== modified file 'app/widgets/charm-small.js'
--- app/widgets/charm-small.js 2013-03-04 21:26:27 +0000
+++ app/widgets/charm-small.js 2013-03-08 19:44:21 +0000
@@ -57,7 +57,7 @@
57 },57 },
5858
59 /**59 /**
60 * Desctructor60 * Destructor
61 *61 *
62 * @method destructor62 * @method destructor
63 * @return {undefined} Mutates only.63 * @return {undefined} Mutates only.
6464
=== added file 'lib/views/browser/charm-slider.less'
--- lib/views/browser/charm-slider.less 1970-01-01 00:00:00 +0000
+++ lib/views/browser/charm-slider.less 2013-03-08 19:44:21 +0000
@@ -0,0 +1,29 @@
1.yui3-browser-charm-slider {
2
3 .yui3-browser-charm-slider-content {
4 white-space: nowrap;
5
6 ul {
7 margin: 0;
8 -moz-padding-start: 0;
9 padding-start: 0;
10 -webkit-padding-start: 0;
11 }
12
13 li {
14 display: inline-block;
15 text-align: center;
16 vertical-align: middle;
17 }
18 }
19
20 .navigate {
21 cursor: pointer;
22 list-style-type: none;
23
24 li {
25 display: block-inline;
26 width: auto;
27 }
28 }
29}
030
=== modified file 'lib/views/stylesheet.less'
--- lib/views/stylesheet.less 2013-03-06 15:07:47 +0000
+++ lib/views/stylesheet.less 2013-03-08 19:44:21 +0000
@@ -1635,3 +1635,4 @@
1635}1635}
16361636
1637@import "browser/charm-small.less";1637@import "browser/charm-small.less";
1638@import "browser/charm-slider.less";
16381639
=== modified file 'test/index.html'
--- test/index.html 2013-03-06 15:59:28 +0000
+++ test/index.html 2013-03-08 19:44:21 +0000
@@ -39,6 +39,7 @@
39 <script src="test_charm_configuration.js"></script>39 <script src="test_charm_configuration.js"></script>
40 <script src="test_charm_panel.js"></script>40 <script src="test_charm_panel.js"></script>
41 <script src="test_charm_small_widget.js"></script>41 <script src="test_charm_small_widget.js"></script>
42 <script src="test_charm_slider.js"></script>
42 <script src="test_charm_store.js"></script>43 <script src="test_charm_store.js"></script>
43 <script src="test_charm_view.js"></script>44 <script src="test_charm_view.js"></script>
44 <script src="test_console.js"></script>45 <script src="test_console.js"></script>
4546
=== added file 'test/test_charm_slider.js'
--- test/test_charm_slider.js 1970-01-01 00:00:00 +0000
+++ test/test_charm_slider.js 2013-03-08 19:44:21 +0000
@@ -0,0 +1,81 @@
1'use strict';
2
3describe('charm slider', function() {
4 var container, Y;
5
6 before(function(done) {
7 Y = YUI(GlobalConfig).use(
8 ['browser-charm-slider', 'browser-charm-small', 'event-simulate',
9 'node-event-simulate', 'node'], function(Y) {
10 done();
11 });
12 });
13
14 beforeEach(function() {
15 container = Y.Node.create('<div id="container"></div>');
16 Y.one('body').prepend(container);
17 });
18
19 afterEach(function() {
20 container.remove(true);
21 });
22
23 it('initializes', function() {
24 var cs = new Y.juju.widgets.browser.CharmSlider();
25 assert.isObject(cs);
26 });
27
28 it('creates the right DOM', function() {
29 var cs = new Y.juju.widgets.browser.CharmSlider(),
30 items = ['foo', 'bar', 'baz'];
31 cs.set('items', items);
32 var sliderDOM = cs._generateDOM();
33 assert.equal(3, sliderDOM.all('li').size());
34 var html = sliderDOM.get('outerHTML');
35 Y.Array.each(items, function(item) {
36 assert.notEqual(-1, html.indexOf(item));
37 });
38 });
39
40 it('renders', function() {
41 var cs = new Y.juju.widgets.browser.CharmSlider({
42 items: ['<div id="foo"/>']
43 });
44 cs.render(container);
45 assert.isObject(Y.one('#foo'));
46 });
47
48 it('it generates buttons for each', function() {
49 var cs = new Y.juju.widgets.browser.CharmSlider(),
50 items = ['<div />', '<div />'];
51 cs.set('items', items);
52 cs.render(container);
53 var nav = Y.one('.navigation');
54 assert.equal(items.length, nav.all('li').size());
55 });
56
57 it('pauses on hover', function() {
58 var cs = new Y.juju.widgets.browser.CharmSlider({items: ['<div/>']});
59 cs.render(container);
60 Y.one('.yui3-browser-charm-slider').simulate('mouseover');
61 assert.isTrue(cs.get('paused'), 'Slider is not paused.');
62 Y.one('.yui3-browser-charm-slider').simulate('mouseout');
63 assert.isFalse(cs.get('paused'), 'Slider is not paused.');
64 });
65
66 it('goes to the right slide on nav click', function() {
67 var cs = new Y.juju.widgets.browser.CharmSlider({
68 items: ['<div/>', '<div/>'],
69 autoAdvance: false
70 });
71 cs.render(container);
72 assert.equal(
73 0, cs.pages.get('index'),
74 'Slider did not start on first slide.');
75 var li = Y.one('.navigation').all('li').pop();
76 li.simulate('click');
77 assert.equal(
78 1, cs.pages.get('index'),
79 'Slider did not advance to second slide.');
80 });
81});

Subscribers

People subscribed via source and target branches