1/* 2 *dbpasCarousel - another jquery carousel plugin! 3 *version 0.1 4 *copyright(c) 2013, dbpas llc, http://www.dbpas.com/ 5 *dual licensed under mit and gpl 6 * 7 *inspired by http://web.enavu.com/tutorials/making-an-infinite-jquery-carousel/ 8 * 9*/ 10 11//polyfill, object.create 12if (!Object.create) { 13 Object.create = (function(){ 14 function F(){} 15 return function(o){ 16 if (arguments.length != 1) { 17 throw new Error('Object.create implementation only accepts one parameter.'); 18 } 19 F.prototype = o; 20 return new F() 21 } 22 })(); 23} 24 25;(function($, win, doc, undefined) { 26 'use strict'; 27 28 function destroy(elem) { 29 var $data = $.data($(elem)[0], 'dbpasCarousel'); //get jquery data to remove timer 30 31 if ($data) { 32 clearInterval($data.timerHandle); //remove timer 33 34 $(elem).parent().parent().find('*').off('.dbpasCarousel'); //remove all events on descendants 35 36 $(elem).unwrap().unwrap().siblings('[data-carousel-control]').remove(); //remove control structure around ul 37 $(elem).find('.caption').remove(); //remove any image captions 38 $(elem).removeAttr('style').children().removeAttr('style'); //remove inline styles 39 40 $(elem).removeData('dbpasCarousel'); //remove jquery data 41 }else{ 42 console.log('dbpasCarousel: unable to destroy selected element!'); 43 } 44 } 45 46 var Carousel = { 47 init: function(options, elem) { 48 var self = this; 49 50 self.elem = elem; 51 self.$elem = $(elem); 52 53 self.options = $.extend({}, $.fn.dbpasCarousel.options, options); 54 55 self.timerHandle = null; 56 self.$queue = $({}); 57 58 self.build(); //build control structure around ul 59 60 self.$wrapper = self.$elem.parent(); 61 self.$controlLeft = self.$wrapper.siblings('[data-carousel-control="left"]'); 62 self.$controlRight = self.$wrapper.siblings('[data-carousel-control="right"]'); 63 self.$li = self.$elem.find('li'), 64 65 self.maxOuterWidth = 0; 66 self.maxWidth = 0; 67 68 self.get_deta_row = self.$elem.closest("#dbpas-slider").attr("data-row"); 69 //self.get_deta_count = $("#dbpas-slider").attr("data-count"); 70 //self.get_deta_count = $("#dbpas-slider").attr("data-row"); 71 self.get_deta_count = 1; 72 self.get_deta_max = self.$elem.closest("#dbpas-slider").attr("data-max"); 73 74 self.get_data_width = self.$elem.closest("#dbpas-slider").attr("data-width"); 75 //self.maxLeftCount = self.get_deta_max - self.get_deta_row; 76 self.maxLeftCount = self.get_deta_max - self.get_deta_row; 77 78 if (self.maxLeftCount < 0) { 79 self.maxLeftCount = 0; 80 } 81 82 self.maxRightCount = self.get_deta_count; 83 84 85 self.$li.each(function() { 86 if ($(this).outerWidth() >= self.maxOuterWidth) { //get max width to apply to all items for smooth movement 87 self.maxOuterWidth = $(this).outerWidth(); 88 self.maxWidth = $(this).width(); 89 } 90 if (self.options.imgCaption && $(this).find('img:first').attr('alt')) { //image caption enabled, assume first image alt is caption 91 $(this).append($('<p/>').addClass('caption').html($(this).find('img:first').attr('alt'))); 92 } 93 }); 94 95 self.$li.css({'width': (self.maxWidth) + 'px'}); //give all items uniform width for smooth movement 96 97 //self.$wrapper.css({'max-width': (self.maxOuterWidth * self.options.itemsVisible) + 'px'}); //adjust wrapper width to show X items 98 self.$wrapper.css({'max-width': self.get_data_width + 'px'}); //adjust wrapper width to show X items 99 100 //self.$elem.css({'left': '-' + self.maxOuterWidth + 'px'}); //move list to the left of view by 1 item width 101 //self.$elem.css({'left': self.maxOuterWidth + 'px'}); //move list to the left of view by 1 item width 102 self.$elem.css({'left': '0px'}); //move list to the left of view by 1 item width 103 104 105 //self.$elem.find('li:first').before($(self.$elem.find('li:last'))); //makes sure first item is showing 106 107 self.events(); 108 109 self.complete(); 110 }, 111 112 build: function() { 113 var self = this; 114console.log(self); 115 self.$elem.wrap($('<div />').addClass("ad-not-link").attr('data-carousel-name', self.$elem.attr('id') || '')).wrap($('<div />').attr('data-carousel-control', 'wrapper')); 116 //WEBã¢ã¯ã»ã·ããªãã£è¨å®æã¯æè¨ã表示ãã 117 if(self.$elem.data("prev-text")){ 118 //#3093 tabindex追å
119 self.$elem.parent().parent().prepend($('<i />').attr('tabIndex','0').attr('data-carousel-control','left').attr("data-not-panel","true").addClass("fa fa-angle-left ad-not-link mbcolor-op10 fcolor-op20").html('<div class="" style="font-size:15px;font-weight:bold;">'+self.$elem.data("prev-text")+'</div>')) 120 .append($('<i />').html('<div class="" style="font-size:15px;font-weight:bold;">'+self.$elem.data("next-text")+'</div>').attr('data-carousel-control', 'right').attr("data-not-panel","true").addClass("fa fa-angle-right ad-not-link mbcolor-op30 fcolor")); 121 122 }else{ 123 //#3093 tabindex追å 124 self.$elem.parent().parent().prepend($('<i />').attr('tabIndex','0').attr('data-carousel-control','left').attr("data-not-panel","true").addClass("fa fa-angle-left ad-not-link mbcolor-op10 fcolor-op20").html('')) 125 .append($('<i />').html('').attr('data-carousel-control', 'right').attr("data-not-panel","true").addClass("fa fa-angle-right ad-not-link mbcolor-op30 fcolor")); 126 } 127 //wrap ul by 2 divs for formating and add navigation controls 128 }, 129 130 navigation: function(direction) { 131 var self = this; 132 133 self.leftIndent = 0; 134 135 if (direction == 'right') { 136 self.leftIndent = parseInt(self.$elem.css('left')) + self.maxOuterWidth; //move list to the right of view by 1 item width 137 /* 138 self.$queue.queue('dbpasCarouselMove', function(next) { //queue the moving of item to front of list to be dequeued in animation 139 self.$elem.find('li:first').before($(self.$elem.find('li:last'))); 140 next(); 141 }); 142 */ 143 }else{ 144 self.leftIndent = parseInt(self.$elem.css('left')) - self.maxOuterWidth; //move list to the left of view by 1 item width 145 146 /* 147 self.$queue.queue('dbpasCarouselMove', function(next) { //queue the moving of item to back of list to be dequeued in animation 148 self.$elem.find('li:last').after($(self.$elem.find('li:first'))); 149 next(); 150 }); 151 */ 152 } 153 154 self.$elem.not(':animated').animate( 155 {'left': self.leftIndent}, 156 self.options.slideDelay, 157 function() { 158 /* 159 self.$queue.dequeue('dbpasCarouselMove'); //move item to front/back of list 160 self.$elem.css({'left': '-' + self.maxOuterWidth + 'px'}); //move list to the left/right of view by 1 item width 161 */ 162 } 163 ); 164 }, 165 166 timer: function(action) { 167 var self = this; 168 169 if (action == 'start') { 170 self.timerHandle = setInterval(function() { 171 self.navigation('left'); //auto slide always goes left 172 }, self.options.autoDelay); 173 }else{ 174 clearInterval(self.timerHandle); 175 } 176 }, 177 178 events: function() { 179 var self = this, eventNS = '.dbpasCarousel', 180 pauseActionStart, pauseActionStop, controlAction; 181 182 if ('ontouchstart' in doc.documentElement) { //check for touch events 183 controlAction = 'touchstart' + eventNS; 184 pauseActionStart = 'touchstart' + eventNS; 185 pauseActionStop = 'touchend' + eventNS; 186 }else{ 187 controlAction = 'click' + eventNS; 188 pauseActionStart = 'mouseenter' + eventNS; 189 pauseActionStop = 'mouseleave' + eventNS; 190 $('body').addClass('no-touch'); //add class to disable :hover 191 } 192 193 if (self.options.autoSlide) { 194 self.timer('start'); 195 196 if (self.options.hoverPause) { 197 self.$wrapper.parent().on(pauseActionStart, function() { 198 self.timer('stop'); 199 }); 200 201 self.$wrapper.parent().on(pauseActionStop, function() { 202 self.timer('start'); 203 }); 204 } 205 } 206 207 self.$controlLeft.on(controlAction, function() { 208 if(self.$elem.is(':animated')){ 209 return; 210 }else{ 211 //if (self.get_deta_count <= self.maxLeftCount) { 212 // self.get_deta_count++; 213 if (self.get_deta_count > 1) { 214 //if (self.get_deta_count > self.get_deta_row) { 215 216 self.get_deta_count--; 217 //self.navigation('left'); 218 self.navigation('right'); 219 self.$controlRight.css("color","#ABABAB"); 220 self.$controlRight.css("border","2px solid #ABABAB"); 221 self.$controlRight.removeClass('fcolor-op20'); 222 self.$controlRight.addClass('fcolor'); 223 self.$controlRight.addClass('mbcolor-op30'); 224 self.$controlRight.removeClass('mbcolor-op10'); 225 } 226 227 //if (self.get_deta_count > self.maxLeftCount) { 228 if (self.get_deta_count == 1) { 229 //if (self.get_deta_count == self.get_deta_row) { 230 self.$controlLeft.css("color","#E6E6E6"); 231 self.$controlLeft.css("border","2px solid #E6E6E6"); 232 self.$controlLeft.addClass('fcolor-op20'); 233 self.$controlLeft.removeClass('fcolor'); 234 self.$controlLeft.addClass('mbcolor-op10'); 235 self.$controlLeft.removeClass('mbcolor-op30'); 236 } 237 } 238 }); 239
240 self.$controlRight.on(controlAction, function() { 241 if(self.$elem.is(':animated')){ 242 return; 243 }else{ 244 // if (self.get_deta_count > 1) { 245 // self.get_deta_count--; 246 if (self.get_deta_count <= self.maxLeftCount) { 247 self.get_deta_count++; 248 //self.navigation('right'); 249 self.navigation('left'); 250 self.$controlLeft.css("color","#ABABAB"); 251 self.$controlLeft.css("border","2px solid #ABABAB"); 252 self.$controlLeft.removeClass('fcolor-op20'); 253 self.$controlLeft.addClass('fcolor'); 254 self.$controlLeft.addClass('mbcolor-op30'); 255 self.$controlLeft.removeClass('mbcolor-op10'); 256 } 257 258 //if (self.get_deta_count == 1) { 259 if (self.get_deta_count > self.maxLeftCount) { 260 self.$controlRight.css("color","#E6E6E6"); 261 self.$controlRight.css("border","2px solid #E6E6E6"); 262 self.$controlRight.addClass('fcolor-op20'); 263 self.$controlRight.removeClass('fcolor'); 264 self.$controlRight.addClass('mbcolor-op10'); 265 self.$controlRight.removeClass('mbcolor-op30'); 266 } 267 } 268 }); 269 }, 270 271 complete: function() { 272 var self = this; 273 274 if (typeof self.options.onComplete === 'function') { 275 self.options.onComplete.apply(self.$elem); 276 } 277 } 278 }; 279 280 $.fn.dbpasCarousel = function(options) { 281 return this.each(function() { 282 if (this.tagName.toLowerCase() == 'ul') { //must be ul to work 283 if (typeof options === 'string') { 284 switch(options.toLowerCase()) { 285 case 'destroy': 286 destroy(this); 287 break; 288 default: 289 console.log('dbpasCarousel: "' + options + '" is an invalid method!'); 290 } 291 }else{ 292 var carousel = Object.create(Carousel); 293 294 carousel.init(options, this); 295 296 $.data(this, 'dbpasCarousel', carousel); //make data available for later use 297 } 298 }else{ 299 console.log('dbpasCarousel: selected element is not a "UL"!'); 300 } 301 }); 302 }; 303 304 $.fn.dbpasCarousel.options = { 305 itemsVisible: 2, //for smooth movement, leave at a minimum 2 items out of view 306 slideDelay: 500, //milliseconds 307 autoSlide: 0, //0-off 1-on 308 autoDelay: 5000, //milliseconds 309 hoverPause: 1, //0-off 1-on 310 imgCaption: 1, //0-off 1-on 311 onComplete: null //callback function 312 }; 313 314})(jQuery, window, 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.