PageSourceSearch

https://amano-web.co.jp/common/js/lib/keyvisual.js

js amano-web.co.jp collected 2026-10-06 05:03:47 UTC 11,639 bytes, 315 lines download raw bytes

1/*!
2 * @author: INFORMARC
3 * @created: 2013/08/08
4 * @modified: 2013/08/19
5 */
6(function( $, window, document, undefined ) {
7    var namespace = 'slider';
8    
9    $[ namespace ] = function( elem, options ) {
10        this.settings = $.extend({
11            imgCount: 3,
12            panelCount: 9,
13            duration: 300,
14            easing: 'swing',
15            autoPlay: true,
16            autoPlayTimer: 4000,
17            callback: function() {}
18        }, options );
19        
20        // —v‘fƒLƒƒƒbƒVƒ… 
21        this.$slideWrapper = $( elem );
22        this.$keyvisual    = this.$slideWrapper.parent();
23        this.$ul           = this.$slideWrapper.find( '#slideList' );
24        this.$li           = this.$ul.find( 'li' );
25        this.$nav          = this.$keyvisual.find( '#slideNav' ).find( 'img' );
26        this.$checkElem    = this.$keyvisual.find( '#check' );
27        
28        // ó‘Ô•Û‘¶ 
29        this.slideQueue     = [];
30        this.isAnimate      = false;
31        this.autoPlayPause  = true;
32        this.currentIndex   = 1;
33        this.basePos        = 0;
34        this.panelWidth     = 0;
35        this.panelHeight    = 0;
36        this.panelWidthHalf = 0;
37        this.slideWidth     = 0;
38    };
39    
40    $[ namespace ].prototype = {
41        init: function() {
42            this.setSize();
43            this.eventBind();
44            
45            // Ž©“®Ä¶‚ª—LŒø‚È‚ç 
46            if ( this.settings.autoPlay ) {
47                this.setTimer();
48                this.autoPlayPause = false;
49            }
50            
51            this.settings.callback();
52        },
53        getPos: function() {
54            return parseInt( this.$ul.css( 'marginLeft' ) );
55        },
56        getFirst: function() {
57            return $( '> li:first-child', this.$ul );
58        },
59        getLast: function() {
60            return $( '> li:last-child', this.$ul );
61        },
62        // ƒŒƒXƒ|ƒ“ƒVƒu‘ΉžFƒTƒCƒYÝ’è 
63        setSize: function() {
64            // ‰¡•&‚‚³Žæ“¾ 
65            this.panelHeight     = this.$checkElem.height();
66            this.panelWidth      = this.$checkElem.width();
67            this.panelWidthHalf  = this.panelWidth / 2;
68            this.slideWidth      = this.panelWidth * this.settings.panelCount;
69            
70            // ‰¡•&‚‚³Ý’è 
71            this.$keyvisual.css( 'height', this.panelHeight + 27 );
72            this.$slideWrapper.css({
73                'width': this.slideWidth,
74                'height': this.panelHeight
75            });
76            this.$ul.css({
77                'marginLeft': '-' + ( this.panelWidth * this.settings.imgCount + this.panelWidthHalf ) + 'px',
78                'width': this.slideWidth,
79                'height': this.panelHeight
80            });
81            this.$li.css( 'width', this.panelWidth );
82            
83            // Šî€ˆÊ’u‚ðŽæ“¾ 
84            this.basePos = this.getPos();
85        },
86        // ƒiƒrƒQ[ƒVƒ‡ƒ“ƒCƒxƒ“ƒgƒZƒbƒg 
87        eventBind: function() {
88            var self = this,
89                resizeQueue;
90            
91            // ‰º•”‚̃iƒrƒQ[ƒVƒ‡ƒ“ 
92            this.$nav.on( 'click.slide', function() {
93                var next = Number( this.getAttribute('data-show') );
94                
95                if ( self.currentIndex !== next && !self.isAnimate ) {
96                    self.slide( next );
97                    
98                    // ƒiƒrƒQ[ƒVƒ‡ƒ“ƒNƒŠƒbƒN‚ÅŽ©“®Ä¶I—¹ 
99                    self.settings.autoPlay = false;
100                }
101            });
102            
103            // ƒŒƒXƒ|ƒ“ƒVƒu‘ΉžFƒTƒCƒYÝ’è 
104            $( window ).on( 'resize.slide', function() {
105                clearTimeout( resizeQueue );
106                resizeQueue = setTimeout(function() {
107                    self.setSize();
108                }, 100 );
109            });
110            
111            // ƒ^ƒbƒ`ƒfƒoƒCƒX‚̉摜ƒtƒŠƒbƒNØ‚è‘Ö‚¦ 
112            if ( 'ontouchstart' in window ) {
113                var touchStartX = 0,
114                    pageX = 0,
115                    flickReady = false,
116                    flickPause = false,
117                    nextIndex = 0;
118                
119                this.$keyvisual.on({
120                    'touchstart.slide': function( e ) {
121                        flickReady = false;
122                        flickPause = false;
123                        touchStartX = e.originalEvent.changedTouches[0].pageX;
124                    },
125                    'touchmove.slide': function( e ) {
126                        pageX = e.originalEvent.changedTouches[0].pageX;
127                        
128                        e.preventDefault();
129                        e.stopPropagation();
130                        
131                        if ( flickReady && !flickPause ) {
132                            // ŽŸ‚̉摜‚ªÅ‘å’l‚ð’´‚¦‚Ä‚¢‚½‚ç1–‡–Ú‚ð•\ަ 
133                            if ( nextIndex > self.settings.imgCount ) {
134                                nextIndex = 1;
135                            
136                            // ŽŸ‚̉摜‚ªÅ’á’lˆÈ‰º‚È‚ç3–‡–Ú‚ð•\ަ 
137                            } else if ( nextIndex < 1 ) {
138                                nextIndex = self.settings.imgCount;
139                            }
140                            
141                            self.slide( nextIndex );
142                            flickPause = true;
143                            
144                            // ƒtƒŠƒbƒNŒã‚ÍŽ©“®Ä¶I—¹ 
145                            self.settings.autoPlay = false;
146                        
147                        // ƒ^ƒbƒ`ŠJŽnˆÊ’u‚©‚ç10ˆÈãˆÚ“®‚È‚ç 
148                        } else if ( Math.abs( pageX - touchStartX ) > 10 ) {
149                            flickReady = true;
150                            
151                            // ¶•ûŒü‚̃tƒŠƒbƒN 
152                            if ( touchStartX - pageX < 0 ) {
153                                nextIndex = self.currentIndex - 1;
154                            
155                            // ‰E•ûŒü‚̃tƒŠƒbƒN 
156                            } else {
157                                nextIndex = self.currentIndex + 1;
158                            }
159                        }
160                    }
161                });
162            }
163        },
164        // ’†‰›‚̉摜‚ð”»’è 
165        updateIndex: function() {
166            var self = this;
167            
168            this.$li.removeClass( 'center' );
169            this.$ul.find( 'li' ).eq(3).addClass( 'center' );
170        },
171        // ¶‰EƒXƒ‰ƒCƒh 
172        slide: function( nextIndex ) {
173            var self = this,
174                op = {};
175            
176            // ƒXƒ‰ƒCƒhŠ®—¹‚܂Ńtƒ‰ƒOƒIƒ“ 
177            self.isAnimate = true;
178            
179            // ƒXƒ‰ƒCƒhŒü‚«”»•Ê 
180            // ŽŸ‚̉摜‚Ö 
181            if ( this.currentIndex < nextIndex ) {
182                // 1–‡–ڂ̉摜‚ð•\ަ’† 
183                if ( this.currentIndex === 1 ) {
184                    op.moveCount = 1;
185                    
186                    // ŽŸ‚ª3–‡–ڂȂ獶‰ñ‚è 
187                    if ( nextIndex === 3 ) {
188                        op.margin = this.basePos + this.panelWidth;
189                        op.prop   = 'prependTo';
190                    
191                    // ŽŸ‚ª2–‡–Ú‚È‚ç‰E‰ñ‚è 
192                    } else if ( nextIndex === 2 ) {
193                        op.margin = this.basePos - this.panelWidth;
194                        op.prop   = 'appendTo';
195                    }
196                
197                // 2–‡–ڂ̉摜‚ð•\ަ’† 
198                } else {
199                    op.moveCount = nextIndex - this.currentIndex;
200                    op.margin = self.basePos - ( self.panelWidth * op.moveCount );
201                    op.prop   = 'appendTo';
202                }
203                
204            } else {
205                op.moveCount = 1;
206                
207                // 3–‡–ڂ̉摜‚ð•\ަ’† 
208                if ( this.currentIndex === 3 ) {
209                    // ŽŸ‚ª1–‡–Ú‚È‚ç‰E‰ñ‚è 
210                    if ( nextIndex === 1 ) {
211                        op.margin = this.basePos - this.panelWidth;
212                        op.prop   = 'appendTo';
213                    
214                    // ŽŸ‚ª2–‡–ڂȂ獶‰ñ‚è 
215                    } else if ( nextIndex === 2 ) {
216                        op.margin = this.basePos + this.panelWidth;
217                        op.prop   = 'prependTo';
218                    }
219                
220                // 2–‡–ڂ̉摜‚ð•\ަ’† 
221                } else if ( this.currentIndex === 2 ) {
222                    // ŽŸ‚ª1–‡–ڂȂ獶‰ñ‚è 
223                    if ( nextIndex === 1 ) {
224                        op.margin = this.basePos + this.panelWidth;
225                        op.prop   = 'prependTo';
226                    
227                    // ŽŸ‚ª3–‡–Ú‚È‚ç‰E‰ñ‚è 
228                    } else if ( nextIndex === 3 ) {
229                        op.margin = this.basePos - this.panelWidth;
230                        op.prop   = 'appendTo';
231                    }
232                }
233            }
234            
235            // ƒAƒjƒ[ƒVƒ‡ƒ“ 
236            self.$ul.animate({
237                marginLeft: op.margin
238            }, self.settings.duration, self.settings.easing, function() {
239                for ( var i = -1;  ++i < op.moveCount; ) {
240                    var elem;;
241                    
242                    if ( op.prop === 'appendTo' ) {
243                        elem = self.getFirst();
244                    } else {
245                        elem = self.getLast();
246                    }
247                    
248                    elem[ op.prop ]( self.$ul );
249                }
250                
251                self.$ul.css({
252                    'marginLeft': '-' + ( self.panelWidth * self.settings.imgCount + self.panelWidthHalf ) + 'px',
253                    'width': self.slideWidth
254                });
255                
256                // ƒvƒƒpƒeƒBXV 
257                self.currentIndex = nextIndex;
258                self.isAnimate = false;
259                
260                // ƒJƒŒƒ“ƒg•\ަXV 
261                self.$nav.each(function( i ) {
262                    if ( i + 1 === nextIndex ) {
263                        this.src = this.src.replace( '_off.png', '_on.png' );
264                    } else {
265                        this.src = this.src.replace( '_on.png', '_off.png' );
266                    }
267                });
268                
269                // ƒZƒ“ƒ^[XV 
270                self.updateIndex();
271            });
272        },
273        // Ž©“®Ä¶ 
274        setTimer: function() {
275            var self = this,
276                nextIndex = 1;
277            
278            // ƒ}ƒEƒXƒI[ƒo[Žž‚ÍŽ©“®Ä¶’âŽ~
279            this.$slideWrapper.on({
280                'mouseover.autoPlayFlag': function() {
281                    self.autoPlayPause = true;
282                },
283                'mouseout.autoPlayFlag': function() {
284                    self.autoPlayPause = false;
285                }
286            });
287            
288            (function autoPlay() {
289                // Ž©“®Ä¶I—¹ 
290                if ( !self.settings.autoPlay || nextIndex > self.settings.imgCount ) {
291                    return;
292                }
293                
294                // ƒtƒ‰ƒO‚ªƒIƒt‚ÌŽž‚¾‚¯Ž©“®Ä¶ 
295                if ( !self.autoPlayPause ) {
296                    nextIndex++;
297                    
298                    if ( nextIndex <= self.settings.imgCount ) {
299                        self.slide( nextIndex );
300                    }
301                }
302                
303                // –³–¼ŠÖ”Ä‹A 
304                setTimeout( autoPlay, self.settings.autoPlayTimer );
305            })();
306        }
307    };
308    
309    $.fn[ namespace ] = function( options ) {
310        return this.each(function() {
311            var o = new $[ namespace ]( this, options );
312            o.init();
313        });
314    };
315})( jQuery, this, this.document );

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.