]> dev.renevier.net Git - syj.git/blob - public/js/deck.js
version 0.1
[syj.git] / public / js / deck.js
1 /*  This file is part of Syj, Copyright (c) 2010 Arnaud Renevier,
2     and is published under the AGPL license. */
3 var Deck = Class.create();
4 Deck.prototype = {
5     initialize: function(elt, options) {
6         this.element = $(elt);
7         this.index = null;
8         this.setIndex(parseInt(this.element.readAttribute("selectedindex") || 0, 10));
9     },
10     setIndex: function(idx) {
11         if (idx === this.index) {
12             return;
13         }
14
15         var childs = this.element.childElements();
16         if (childs.length === 0) {
17             this.index = -1;
18             return;
19         }
20         idx = Math.max(0, idx);
21         idx = Math.min(childs.length - 1, idx);
22
23         childs.each(function(item, i) {
24             if (idx === i) {
25                 item.show();
26             } else {
27                 item.hide();
28             }
29         });
30         this.index = idx;
31     },
32     getIndex: function() {
33         return this.index;
34     }
35 };