-
Notifications
You must be signed in to change notification settings - Fork 5
/
jquery.swapgallerywithdots.coffee
130 lines (94 loc) · 3.1 KB
/
jquery.swapgallerywithdots.coffee
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
# encapsulate plugin
do ($=jQuery) ->
ns = {}
# ============================================================
# Main
class ns.Main extends window.EveEve
@defaults =
selector_gallery_container: null
selector_gallery_inner: null
selector_gallery_inner2: null
selector_gallery_item: null
selector_dot_container: null
selector_dot_item: null
class_dot_activeItem: null
class_dot_inactiveItem: null
src_dotItem: null
stepwidth: null
widthbetween: 0
forever: false
forever_duplicate_count: 1
maxindex: 'auto'
normalize_height: true
normalize_height_on_resize: true
constructor: (@$el, options) ->
@options = $.extend {}, ns.Main.defaults, options
@$gallery = @$el.find @options.selector_gallery_container
@_countItems()
@_putDotsHtml()
@_prepareTouchdragh()
@_prepareDots()
@_eventify()
_countItems: ->
selector = @options.selector_gallery_item
@_itemsCount = (@$gallery.find selector).length
return this
_prepareTouchdragh: ->
o = @options
$items = @$gallery.find o.selector_gallery_item
galleryOptions =
inner: o.selector_gallery_inner
inner2: o.selector_gallery_inner2
item: o.selector_gallery_item
stepwidth: o.stepwidth or $items.eq(0).outerWidth()
widthbetween: o.widthbetween or 0
maxindex: o.maxindex
forever: o.forever
forever_duplicate_count: o.forever_duplicate_count
inner2left: o.inner2left or 0
normalize_height: o.normalize_height
normalize_height_on_resize: o.normalize_height_on_resize
@$gallery.touchdraghsteppy galleryOptions
@touchdragh = @$gallery.data 'touchdraghsteppy'
return this
_putDotsHtml: ->
@$dots = @$el.find @options.selector_dot_container
src = @options.src_dotItem
srcs = ''
for [0...@_itemsCount]
srcs += src
@$dots.append srcs
return this
_prepareDots: ->
o = @options
dotOptions =
selector_item: o.selector_dot_item
class_activeItem: o.class_dot_activeItem
if o.class_dot_inactiveItem
dotOptions.class_inactiveItem = o.class_dot_inactiveItem
@$dots.currentDots dotOptions
@dot = @$dots.data 'currentDots'
return this
_eventify: ->
@dot.on 'itemclick', (data) =>
@touchdragh.to data.index, true
@touchdragh.on 'indexchange', (data) =>
if @options.forever
i = data.normalizedIndex
else
i = data.index
@dot.to i
@trigger 'indexchange', index: i
return this
# ============================================================
# bridge to plugin
$.fn.swapgallerywithdots = (options) ->
return @each (i, el) ->
$el = $(el)
instance = new ns.Main $el, options
$el.data 'swapgallerywithdots', instance
return
# ============================================================
# globalify
$.SwapgallerywithdotsNs = ns
$.Swapgallerywithdots = ns.Main