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.