PageSourceSearch

https://larachecity.com/public/naples/plugins/extend.js

js larachecity.com collected 2026-10-03 02:35:46 UTC 20,820 bytes, 513 lines download raw bytes

1(function ($, window) {
2    /** 默认配置 */
3    var defaults = {
4        //比例
5        ratio: 'auto',
6        //播放效果
7        style: 'fade',
8        //播放速度
9        speend: 5,
10        //是否自动播放
11        autoplay: 1,
12        //是否显示上下翻页按钮
13        showcotrols: 1,
14        //文字位置(0:底部,1:顶部)
15        captionpos: 0,
16        //菜单类型(0:无,1:文字,2:小图)
17        navstyle: 0,
18        //菜单位置(0:底部,1:顶部,2:左边,3:右边)
19        navlocation: 0,
20        //禁用事件
21        disabled: false
22    };
23    function slide(element, options) {
24        this.element = element;
25        this.$element = $(element);
26        this.$items = null;
27        this.curIndex = 0;
28        this.options = $.extend({}, defaults, options);
29        this.playtime = null;
30        this.allimg = null;
31        this.imginfo = [];
32        this.curheight = 0;
33        this.curSubIndex = 0;
34        this._init();
35    }
36    slide.prototype = {
37        //初始化
38        _init: function () {
39            this.$items = this.$element.find('div.slide-item');
40            this._setShowCotrols();
41            this._setCaptionPos();
42            this._setNavigation();
43            this._initSize();
44            if (!this.options.disabled)
45                this._initEvent();
46            this._autoPlay();
47        },
48        //初始比例
49        _initSize: function () {
50            var self = this;
51            this.allimg = this.$element.find('div.slide-item img');
52            var count = 1;
53            //加载图片
54            for (var i = 0; i < this.allimg.length; i++) {
55                var temImg = $(this.allimg[i]);
56                var newImg = new Image;
57                newImg.index = i;
58                newImg.onload = function () {
59                    var index = parseInt(this.index);
60                    self.imginfo[self.imginfo.length] = {'index': index, 'width': this.width, 'height': this.height};
61                    if (count == self.allimg.length)
62                        self._setSize();
63                    if (index > 0)
64                        $(self.$items[index]).hide();
65                    count++;
66                };
67                newImg.src = temImg.attr('src');
68            }
69        },
70        //事件
71        _initEvent: function () {
72            var self = this;
73            var prev = this.$element.find('div.cycle-prev:first');
74            var next = this.$element.find('div.cycle-next:first');
75            prev.click(function () {
76                if ($(this).data('play') == '1') {
77                    return '';
78                } else {
79                    $(this).data('play', '1');
80                }
81                self._stopPlay();
82                var index = self.curIndex - 1;
83                if (index < 0)
84                    index = self.$items.length - 1;
85                self._play(index);
86                self._add_active(index);
87                self._autoPlay();
88                return false;
89            });
90            next.click(function () {
91                if ($(this).data('play') == '1') {
92                    return '';
93                } else {
94                    $(this).data('play', '1');
95                }
96                self._stopPlay();
97                var index = self.curIndex + 1;
98                if (index > self.$items.length - 1)
99                    index = 0;
100                self._play(index);
101                self._add_active(index);
102                self._autoPlay();
103                return false;
104            });
105        },
106        //设置比例
107        _setSize: function () {
108            var maxWith = this.$element.width();
109            var maxHeight = 0;
110            if (this.options.ratio != 'auto') {
111                var ratioItems = this.options.ratio.split(':');
112                var ratioWidth = parseInt(ratioItems[0]);
113                var ratioHeight = parseInt(ratioItems[1]);
114                maxHeight = parseInt((maxWith / ratioWidth) * ratioHeight);
115            }
116
117            for (var i = 0; i < this.allimg.length; i++) {
118                var temImg = $(this.allimg[i]);
119                var temImgInfo = null;
120                for (var j = 0; j < this.imginfo.length; j++) {
121                    if (i == this.imginfo[j].index) {
122                        temImgInfo = this.imginfo[j];
123                    }
124                }
125                var imgWidth = temImgInfo.width;
126                var imgHeight = temImgInfo.height;
127                if (imgWidth > maxWith) {
128                    imgHeight = imgHeight * (maxWith / imgWidth);
129                    imgWidth = maxWith;
130                }
131                if (this.options.ratio == 'auto') {
132                    maxHeight = imgHeight > maxHeight ? imgHeight : maxHeight;
133                    maxHeight = parseInt(maxHeight);
134                } else {
135                    if (imgHeight > maxHeight) {
136                        imgWidth = imgWidth * (maxHeight / imgHeight);
137                        imgHeight = maxHeight;
138                        imgWidth = parseInt(imgWidth);
139                    }
140                }
141                temImg.css({'width': imgWidth});
142                temImg.parent().css({'width': imgWidth, 'left': (0 - parseInt(imgWidth / 2)), 'top': (0 - parseInt(imgHeight / 2))});
143            }
144            this.$element.find('.w-slide-content').css('height', maxHeight);
145            this._setNavigation();
146        },
147        //自动播放
148        _autoPlay: function () {
149            if (this.options.autoplay == 1) {
150                var self = this;
151                //setTimeout/setInterval
152                this.playtime = window.setInterval(function () {
153                    self._play();
154                    var autoIndex;
155                    if (self.curIndex + 1 >= self.$items.length) {
156                        autoIndex = 0;
157                    } else {
158                        autoIndex = self.curIndex + 1;
159                    }
160                    self._add_active(autoIndex);
161                }, self.options.speend * 1000);
162
163            }
164        },
165        //停止播放
166        _stopPlay: function () {
167            if (this.options.autoplay == 1) {
168                if (this.playtime != null)
169                    window.clearInterval(this.playtime);
170
171            }
172        },
173        //关闭自动播放
174        _closeAutoPlay: function () {
175            if (this.playtime != null) {
176                clearInterval(this.playtime);
177                this.playtime = null;
178            }
179        },
180        _getNextIndex: function (index) {
181            var nextIndex = 0;
182            if (typeof index == 'number') {
183                nextIndex = index;
184                return index;
185            } else {
186                if (this.curIndex >= this.$items.length - 1) {
187                    nextIndex = 0;
188                } else {
189                    nextIndex = this.curIndex + 1;
190                }
191            }
192            return nextIndex;
193        },
194        //播放
195        _play: function (index) {
196            var self = this;
197            var nextIndex = this._getNextIndex(index);
198            //渐显效果fade
199            if (this.options.style == 'fade') {
200                $(this.$items[this.curIndex]).fadeOut(function () {
201                    self.curIndex = nextIndex;
202                    $(self.$items[self.curIndex]).fadeIn('fast');
203                    // 改变点击状态
204                    self._elementPaly(self);
205                });
206            }
207            //左右滑动效果
208            if (this.options.style == 'slide') {
209                var maxWith = this.$element.width();
210                $(this.$items[nextIndex]).css('left', maxWith).show();
211                $(this.$items[this.curIndex]).animate({'left': (0 - maxWith)}, 500, function () {
212                    $(this).hide().css('left', 0);
213                    // 改变点击状态
214                    self._elementPaly(self);
215                });
216                $(this.$items[nextIndex]).animate({'left': 0});
217                this.curIndex = nextIndex;
218            }
219            //卡片式和百叶窗效果
220            if (this.options.style == 'fold' || this.options.style == 'slice') {
221                var temCurItem = $(this.$items[this.curIndex]);
222                temCurItem.css('z-index', 1);
223                this.curIndex = nextIndex;
224                // $(this.$items[this.curIndex]).hide();
225                var curItem = $(this.$items[nextIndex])
226                curItem.css('z-index', 2);
227                var curImg = curItem.find('.slide-img');
228                curImg.css('opacity', 0);
229                curItem.show();
230                var curImgDiv = $(curItem.find('.slide-item-div-inner'));
231                var curWidth = curImgDiv.width();
232                var curHeight = curImgDiv.height();
233                var subWidth = curWidth / 12;
234                var html = '<div class="slide-img-block">';
235                var imgurl = curItem.find('img').attr('src');
236                for (var i = 0; i < 12; i++) {
237                    html += '<div style="';
238                    if (this.options.style == 'fold') {
239                        html += 'width:0px;left:' + (subWidth * i) + 'px;'
240                    } else if (this.options.style == 'slice') {
241                        html += 'width:' + subWidth + 'px;left:' + (subWidth * i) + 'px;';
242                    }
243                    html += 'opacity:0;position:absolute;top:0;height:' + curHeight + 'px;overflow:hidden;">';
244                    html += '<img src="' + imgurl + '" style="width:' + curWidth + 'px;top:0;left:-' + (subWidth * i) + 'px;position:absolute;dispaly:block;max-width:none;" /></div>';
245                }
246                html += "</div>";
247                curImgDiv.append(html);
248                var count = 0;
249                var itemList = curItem.find('.slide-img-block').children();
250                if (this.options.style == 'fold') {
251                    itemList.each(function () {
252                        $(this).animate({'width': subWidth, 'opacity': 1}, count * 100, function () {
253                            var index = itemList.index($(this));
254                            if (index == itemList.length - 1 && temCurItem.css('z-index') != 2) {
255                                curImg.css('opacity', 1);
256                                temCurItem.fadeOut();
257                                curItem.find('.slide-img-block').remove();
258                            }
259                        });
260                        count++;
261                    });
262                } else if (this.options.style == 'slice') {
263                    this.curSubIndex = 0;
264                    //  this._sliceAction(itemList, subWidth, curImg, curItem, temCurItem);
265                    itemList.each(function () {
266                        var index = itemList.index($(this));
267                        $(this).animate({'opacity': 1}, count * 150, function () {
268                            if (itemList.index($(this)) == itemList.length - 1 && temCurItem.css('z-index') != 2) {
269                                curImg.css('opacity', 1);
270                                temCurItem.fadeOut();
271                                curItem.find('.slide-img-block').remove();
272                            }
273                        });
274                        count++;
275                    });
276                }
277                setTimeout(function () {
278                    self._elementPaly(self);
279                }, count * 150);
280
281            }
282        },
283        _elementPaly: function (self) {
284            // 改变点击状态
285            self.$element.find(".cycle-prev").data("play", '0');
286            self.$element.find(".cycle-next").data("play", '0');
287            self.$element.find(".slide-page>a").each(function () {
288                if ($(this).data("play") === '1') {
289                    $(this).data("play", "0");
290                }
291            });
292        },
293        _sliceAction: function (items, width, curImg, curItem, temCurItem) {
294            var self = this;
295            if (this.curSubIndex >= items.length - 1) {
296                curImg.css('opacity', 1);
297                temCurItem.hide();
298                curItem.find('.slide-img-block').remove();
299                return false;
300            }
301            var item = $(items[this.curSubIndex]);
302            item.animate({'opacity': 1}, 50, function () {
303                self.curSubIndex++;
304                self._sliceAction(items, width, curImg, curItem, temCurItem);
305            });
306        },
307        //设置文字位置
308        _setCaptionPos: function () {
309            var subElement = this.$element.children().get(0);
310            if (this.options.captionpos == 1) {
311                $(subElement).addClass('slide-caption-top');
312            } else {
313                $(subElement).removeClass('slide-caption-top');
314            }
315        },
316        //设置分页按钮是否显示
317        _setShowCotrols: function () {
318            var prev = this.$element.find('div.cycle-prev:first');
319            var next = this.$element.find('div.cycle-next:first');
320            if (this.options.showcotrols == 1) {
321                prev.show();
322                next.show();
323            } else {
324                prev.hide();
325                next.hide();
326            }
327        },
328        //设置当前导航
329        _add_active: function (index) {
330            var pagest = this.$element.find('.slide-page').children('a');
331            pagest.eq(index).siblings('a').removeClass('active');
332            pagest.eq(index).addClass('active');
333
334        },
335        //设置导航
336        _setNavigation: function () {
337            var nav = this.$element.find('.slide-page');
338            if (nav.length > 0)
339                nav.remove();
340            if (this.options.navstyle > 0) {
341                var self = this;
342                var subElement = $(this.$element.children().get(0));
343                var posElement = $(subElement.children().get(0))
344                if (this.options.captionpos == 1) {
345                    var _w_slide_img = "w-slide-page-img slide-caption-top";
346                    var _w_slide_num = "w-slide-page-num slide-caption-top";
347                } else {
348                    var _w_slide_img = "w-slide-page-img";
349                    var _w_slide_num = "w-slide-page-num";
350                }
351                var className = (this.options.navstyle == 1 ? _w_slide_num : _w_slide_img);
352                subElement.attr('class', className);
353                className = '';
354                var navBox = $(this._getNavHtml());
355                if (!this.options.disabled) {
356                    navBox.find('a').each(function () {
357                        $(this).on('click', function () {
358                            if ($(this).data('play') == '1') {
359                                return '';
360                            } else {
361                                $(this).data('play', '1');
362                            }
363                            self._stopPlay();
364                            self._play(parseInt($(this).attr('data-index')));
365                            self._add_active(parseInt($(this).attr('data-index')));
366                            self._autoPlay();
367                            return false;
368                        })
369                    });
370                }
371                posElement.append(navBox);
372                var slideContent = $(this.$element.find('.w-slide-content:first'));
373                switch (this.options.navlocation) {
374                    case 0:
375                        className = 'w-page-bottom';
376                        break;
377                    case 1:
378                        className = 'w-page-top';
379                        break;
380                    case 2:
381                        className = 'w-page-left';
382                        break;
383                    case 3:
384                        className = 'w-page-right';
385                        break;
386                }
387                switch (this.options.navlocation) {
388                    case 0:
389                    case 1:
390                        var widthSlide = slideContent.outerWidth(true);
391                        var allImg = navBox.find('img');
392                        if (allImg.length * 80 > widthSlide) {
393                            var itemWidth = widthSlide / allImg.length;
394                            allImg.css('width', itemWidth - 10);
395                        }
396                        break;
397                    case 2:
398                    case 3:
399                        var heightSlide = slideContent.outerHeight(true);
400                        var allImg = navBox.find('img');
401                        if (allImg.length * 80 > heightSlide) {
402                            var itemHeight = heightSlide / allImg.length;
403                            allImg.css('height', itemHeight - 10);
404                        }
405                        break;
406                }
407                posElement.attr('class', className);
408            }
409        },
410        _getNavHtml: function () {
411            var html = '<div class="slide-page">';
412            var imgCount = this.$items.length;
413            for (var i = 0; i < imgCount; i++) {
414                if (this.options.navstyle == 1) {
415                    if (i === this.curIndex) {
416                        html += '<a href="javascript:void(0);" data-index="' + i + '" class="active"> ' + (i + 1) + ' </a>';
417                    } else {
418                        html += '<a href="javascript:void(0);" data-index="' + i + '"> ' + (i + 1) + ' </a>';
419                    }
420                } else if (this.options.navstyle == 2) {
421                    var item = $(this.$items[i]);
422                    item = item.find('img.slide-img');
423                    if (i === this.curIndex) {
424                        html += '<a href="javascript:void(0)" data-index="' + i + '" class="active"><img src="' + item.attr('src') + '"></a>';
425                    } else {
426                        html += '<a href="javascript:void(0)" data-index="' + i + '"><img src="' + item.attr('src') + '"></a>';
427                    }
428                }
429            }
430            html += '</div>';
431            return html;
432        },
433        //配置
434        option: function (key, value) {
435            if (typeof (this.options[key]) == 'number')
436                value = parseInt(value);
437            this.options[key] = value;
438            if (key == 'ratio')
439                this._setSize();
440            if (key == 'autoplay' || key == 'speend') {
441                this._closeAutoPlay();
442                this._autoPlay();
443            }
444            if (key == 'showcotrols')
445                this._setShowCotrols();
446            if (key == 'navstyle' || key == 'navlocation')
447                this._setNavigation();
448            this._setCaptionPos();
449            return this.options[key];
450        }
451    };
452    /** 封装 */
453    $.fn.slide = function (options) {
454        var args = arguments;
455        if (options === undefined || typeof options === 'object') {
456            return this.each(function () {
457                if (!$.data(this, 'slide')) {
458                    $.data(this, 'slide', new slide(this, options));
459                }
460            });
461        } else if (typeof options === 'string' && options[0] !== '_') {
462            return this.each(function () {
463                var instance = $.data(this, 'slide');
464                if (instance instanceof slide && typeof instance[options] === 'function') {
465                    instance[options].apply(instance, Array.prototype.slice.call(args, 1));
466                }
467                //清除缓存
468                if (options === 'destroy') {
469                    $.data(this, 'slide', null);
470                }
471            });
472        }
473    };
474}(jQuery, window));
475
476// 判断图片加载的函数
477function isImgLoad(callback) {
478    var isLoad = true;
479    $('.g-cover').each(function () {
480        if ($(this).height() === 0) {
481            isLoad = false;
482        }
483    });
484    if (isLoad) {
485        callback();
486        // 为false,因为找到了没有加载完成的图,将调用定时器递归
487    } else {
488        var t_img;
489        t_img = setInterval(function () {
490            clearInterval(t_img);
491            isImgLoad(callback);
492        }, 100);
493    }
494}
495
496// 判断图片加载的函数
497var allIsImgLoad = function (_obj, callBack) {
498    var imgLoad = new Array;
499    _obj.each(function (key) {
500        $(this).on('load',function () {
501            imgLoad[key] = true;
502            if (imgLoad.length == _obj.length) {
503                callBack();
504            }
505        });
506        if (window.navigator.userAgent.indexOf("Chrome/42.0") > 0) {
507            var src = $(this).attr("src") + "?" + Date.parse(new Date());
508        } else {
509            var src = $(this).attr("src");
510        }
511        $(this).attr("src", src);
512    });
513}

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.