1/** 2 * Owl2row 3 * @since 2.0.2 4 */ 5;(function ($, window, document, undefined) { 6 Owl2row = function (scope) { 7 this.owl = scope; 8 this.owl.options = $.extend({}, Owl2row.Defaults, this.owl.options); 9 //link callback events with owl carousel here 10 11 this.handlers = { 12 'initialize.owl.carousel': $.proxy(function (e) { 13 if (this.owl.settings.owl2row) { 14 this.build2row(this); 15 } 16 }, this) 17 }; 18 19 this.owl.$element.on(this.handlers); 20 }; 21 22 Owl2row.Defaults = { 23 owl2row: false, 24 owl2rowTarget: 'item', 25 owl2rowContainer: 'owl2row-item', 26 owl2rowDirection: 'utd' // ltr 27 }; 28 29 //mehtods: 30 Owl2row.prototype.build2row = function(thisScope){ 31 32 var carousel = $(thisScope.owl.$element); 33 var carouselItems = carousel.find('.' + thisScope.owl.options.owl2rowTarget); 34 35 var aEvenElements = []; 36 var aOddElements = []; 37 38 $.each(carouselItems, function (index, item) { 39 if ( index % 2 === 0 ) { 40 aEvenElements.push(item); 41 } else { 42 aOddElements.push(item); 43 } 44 }); 45 46 carousel.empty(); 47 48 switch (thisScope.owl.options.owl2rowDirection) { 49 case 'ltr': 50 thisScope.leftToright(thisScope, carousel, carouselItems); 51 break; 52 53 default : 54 thisScope.upTodown(thisScope, aEvenElements, aOddElements, carousel); 55 } 56 57 }; 58 59 Owl2row.prototype.leftToright = function(thisScope, carousel, carouselItems){ 60 61 var o2wContainerClass = thisScope.owl.options.owl2rowContainer; 62 var owlMargin = thisScope.owl.options.margin; 63 64 var carouselItemsLength = carouselItems.length; 65 66 var firsArr = []; 67 var secondArr = []; 68 69 //console.log(carouselItemsLength); 70 71 if (carouselItemsLength %2 === 1) { 72 carouselItemsLength = ((carouselItemsLength - 1)/2) + 1; 73 } else { 74 carouselItemsLength = carouselItemsLength/2; 75 } 76 77 //console.log(carouselItemsLength); 78 79 $.each(carouselItems, function (index, item) { 80 81 82 if (index < carouselItemsLength) { 83 firsArr.push(item); 84 } else { 85 secondArr.push(item); 86 } 87 }); 88 89 $.each(firsArr, function (index, item) {
90 var rowContainer = $('<div class="' + o2wContainerClass + '"/>'); 91 92 var firstRowElement = firsArr[index]; 93 firstRowElement.style.marginBottom = owlMargin + 'px'; 94 95 rowContainer 96 .append(firstRowElement) 97 .append(secondArr[index]); 98 99 carousel.append(rowContainer); 100 }); 101 102 }; 103 104 Owl2row.prototype.upTodown = function(thisScope, aEvenElements, aOddElements, carousel){ 105 106 var o2wContainerClass = thisScope.owl.options.owl2rowContainer; 107 var owlMargin = thisScope.owl.options.margin; 108 109 $.each(aEvenElements, function (index, item) { 110 111 var rowContainer = $('<div class="' + o2wContainerClass + '"/>'); 112 var evenElement = aEvenElements[index]; 113 114 evenElement.style.marginBottom = owlMargin + 'px'; 115 116 rowContainer 117 .append(evenElement) 118 .append(aOddElements[index]); 119 120 carousel.append(rowContainer); 121 }); 122 }; 123 124 /** 125 * Destroys the plugin. 126 */ 127 Owl2row.prototype.destroy = function() { 128 var handler, property; 129 130 for (handler in this.handlers) { 131 this.owl.dom.$el.off(handler, this.handlers[handler]); 132 } 133 for (property in Object.getOwnPropertyNames(this)) { 134 typeof this[property] !== 'function' && (this[property] = null); 135 } 136 }; 137 138 $.fn.owlCarousel.Constructor.Plugins['owl2row'] = Owl2row; 139})( window.Zepto || window.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.