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