为了更好的为您提供服务, 云效 邀请您使用持续交付相关功能。云效结合ECS、EDAS等服务为您提供完备的发布、部署、测试全研发流程,大大提升您的研发效率. 了解更多>

提交 1f3bc3ff15f8f48574ca296f1b9a1ee166399763

作者 i.feelinglucky@gmail.com
1 个父辈 70c48c91

--no commit message

正在显示 1 个修改的文件 包含 171 行增加43 行删除
1   -// vim: set et sw=4 ts=4 sts=4 fdm=marker ff=unix fenc=gbk nobomb:
2   -/**
3   - * KISSKY - Slider module
4   - *
5   - * @author mingcheng<i.feelinglucky#gmail.com>
6   - * @since 2009-12-16
7   - * @link http://www.gracecode.com/
8   - */
9   -
10   -KISSY.add("carousel", function(S) {
11   - var Y = YAHOO.util, Dom = Y.Dom, Event = Y.Event, Lang = YAHOO.lang;
12   -
13   - var defConfig = {
14   - slidesClass: 'slider',
15   - triggersClass: 'slider-triggers',
16   - //triggers: null,
17   - currentClass: 'current',
18   - eventType: 'click',
19   - effect: 'none', // opacity, scroll
20   - autoPlayDelay: 3000,
21   - autoPlay: true,
22   - direction: 'vertical' // 'horizontal(h)' or 'vertical(v)'
23   - };
24   -
25   - var Slider = function(container, config) {
26   -
27   - };
28   -
29   - Lang.augmentObject(Slider.prototype, {
30   - _init: function() {
31   -
32   -
33   - },
34   -
35   - switchTo: function() {
36   -
37   -
38   - }
39   -
40   - });
41   -
42   - S.Slider = Slider;
43   -});
  1 +// vim: set et sw=4 ts=4 sts=4 fdm=marker ff=unix fenc=gbk nobomb:
  2 +/**
  3 + * KISSKY - Slider module
  4 + *
  5 + * @creator mingcheng<i.feelinglucky#gmail.com>
  6 + * @since 2009-12-16
  7 + * @link http://www.gracecode.com/
  8 + */
  9 +
  10 +KISSY.add("carousel", function(S) {
  11 + var Y = YAHOO.util, Dom = Y.Dom, Event = Y.Event, Lang = YAHOO.lang;
  12 +
  13 + var defaultConfig = {
  14 + triggersClass: 'slider-triggers',
  15 + //triggers: null,
  16 + currentClass: 'current',
  17 + eventType: 'click',
  18 + effect: 'none', // opacity, scroll
  19 + delay: 2000,
  20 + speed: 500,
  21 + autoPlay: true,
  22 + switchSize: false,
  23 + //onSwitch: function() {},
  24 + direction: 'vertical' // 'horizontal(h)' or 'vertical(v)'
  25 + };
  26 +
  27 + //
  28 + var effect = {
  29 + 'none': function() {
  30 +
  31 + },
  32 +
  33 + 'opacity': function() {
  34 +
  35 + },
  36 +
  37 + 'scroll': function() {
  38 +
  39 + }
  40 + };
  41 +
  42 + var Slider = function(container, config) {
  43 + this.config = Lang.merge(defaultConfig, config || {});
  44 + this.container = Dom.get(container);
  45 +
  46 + this._init();
  47 + };
  48 +
  49 + Lang.augmentObject(Slider.prototype, {
  50 + _init: function() {
  51 + //
  52 + var config = this.config, effect;
  53 +
  54 + // direction
  55 + this.direction = {
  56 + x: (config.direction == 'horizontal') || (config.direction == 'h'),
  57 + y: (config.direction == 'vertical') || (config.direction == 'v')
  58 + };
  59 +
  60 + // panels
  61 + this.panels = this.config.panels || container.getElementsByTagName('li');
  62 +
  63 + // total
  64 + this.total = this.panels.length;
  65 +
  66 + // switch
  67 + this.switchSize = this.config.switchSize;
  68 + if (!this.switchSize) {
  69 + if (this.direction.x) {
  70 + this.switchSize = this.panels[0]['clientWidth'];
  71 + } else {
  72 + this.switchSize = this.panels[0]['clientHeight'];
  73 + }
  74 + }
  75 +
  76 + // triggers
  77 + this.triggers = config.triggers;
  78 + if (!this.triggers) {
  79 + var triggers = document.createElement('ul');
  80 + Dom.addClass(triggers, config.triggersClass);
  81 + for(var i = 0; i < total;) {
  82 + var t = createElement('li');
  83 + t.innerHTML = ++i;
  84 + triggers.appendChild(li);
  85 + }
  86 + this.container.appendChild(triggers);
  87 + this.triggers = triggers.getElementsByTagName('li');
  88 + }
  89 +
  90 +
  91 + //
  92 + this.current = config.startAt || 0;
  93 +
  94 + // switch effect
  95 + if (Lang.isFunction(config.effect)) {
  96 + effect = config.effect;
  97 + } else if (Lang.isString(config.effect) && Lang.isFunction(effect[config.effect]) {
  98 + effect = effect[config.effect];
  99 + } else {
  100 + effect = effect['none'];
  101 + }
  102 +
  103 + this.effect = new Y.CustomEvent('effect', this, false, Y.CustomEvent.FLAT);
  104 + this.effect.subscribe(effect);
  105 +
  106 + // callback
  107 + if (Lang.isFunction(config.onSwitch)) {
  108 + this.onSwitchEvent = new Y.CustomEvent('onSwitchEvent', this, false, Y.CustomEvent.FLAT);
  109 + }
  110 +
  111 + // event
  112 + Event.on(this.panels, 'mouseover', function() {
  113 +
  114 + });
  115 +
  116 + Event.on(this.panels, 'mouseout', function() {
  117 +
  118 + });
  119 +
  120 + Event.on(this.triggers, 'mouseover', function() {
  121 +
  122 + });
  123 +
  124 + Event.on(this.triggers, 'mouseout', function() {
  125 +
  126 + });
  127 +
  128 + // autoStart?
  129 + if (config.autoStart) {
  130 + Lang.later(config.delay, this, this.switchTo(this.current));
  131 + }
  132 + },
  133 +
  134 + switchTo: function(index) {
  135 + var config = this.config;
  136 +
  137 + this.next = index || ++this.current;
  138 + if (index > this.total) {
  139 + this.next = 0;
  140 + }
  141 +
  142 + this.onSwitchEvent.fire();
  143 +
  144 + this.effect.fire();
  145 +
  146 + this.current = this.next;
  147 +
  148 + if (!this.pause || config.autoStart) {
  149 + this.timer = Lang.later(config.delay, this, arguments.callee);
  150 + }
  151 + },
  152 +
  153 + pause: function() {
  154 + this.pause = true;
  155 + if (this.timer) {
  156 + this.timer.cancel();
  157 + }
  158 + },
  159 +
  160 + wakeup: function() {
  161 + this.pause = false;
  162 +
  163 + if (this.timer) {
  164 + this.timer.cancel();
  165 + }
  166 + this.switchTo(++this.current);
  167 + }
  168 + });
  169 +
  170 + S.Slider = Slider;
  171 +});
... ...