-
Notifications
You must be signed in to change notification settings - Fork 0
/
isotope-full-text-open.js
162 lines (137 loc) · 5.66 KB
/
isotope-full-text-open.js
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
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
jQuery(document).ready(function ($) {
var $container = $('#wpr-display-articles');
$container.imagesLoaded(function () {
$container.isotope({
getSortData: {
sorting: function (elem) {
var sortnum = $(elem).find('.wpr-sorting').text();
var parse = parseInt(sortnum, 10);
return parse;
}
},
transitionDuration: '0.4s',
sortBy: 'sorting',
transformsEnabled: false,
animationEngine: 'best-available',
itemPositionDataEnabled: true,
layoutMode: 'fitRows',
itemSelector: '.wpr-post-article',
percentPosition: true
});
});
var $optionSets = $('#filters'), $optionLinks = $optionSets.find('a');
$optionLinks.click(function () {
var $this = $(this);
// don't proceed if already selected
if ($this.hasClass('selected')) {
return false;
}
$optionSets.find('.selected').removeClass('selected');
$this.addClass('selected');
wpr_remove_modal(false);
if ($('#wpr-toggle').length && $('#wpr-toggle').hasClass('on')) {
$('#wpr-toggle').removeClass('on');
}
var selector = $(this).attr('data-filter');
$container.isotope({
filter: selector
});
return false;
});
$container.on('touch click', '.show-full', function () {
open_modal($(this).attr('id'));
});
$('body').on('touch click', '.wpr-close-modal', function () {
wpr_remove_modal(false);
return false;
});
function open_modal(id) {
var elem_bollino = $('#wpr-baloon');
var isOpen = false;
if (elem_bollino.length) {
isOpen = true;
var activeItem = elem_bollino.data('item-id');
wpr_remove_modal(isOpen);
if (activeItem == id) {
return;
}
}
var elem = $('#' + id);
var main_width = $('#wpr-display-articles').width();
var num = (main_width < 641) ? 2 : 7;
var item_width = Math.floor(main_width / num);
calculate_dimensions(item_width, num);
var htmlcontents = elem.find('.wpr-full-content').html();
var modalHtml = '<div class="wpr-modal-content">' + htmlcontents + '</div>';
modalHtml += '<div class="clearfix"></div> <a href class="wpr-close-modal"></a>';
if (htmlcontents != '') {
var sorting = 9999;
var isoElems = $container.isotope('getItemElements');
var hunt = false;
for (var i = 0; i < isoElems.length; i++) {
if (id == isoElems[i].id) {
hunt = true;
continue;
}
if (hunt == true && isoElems[i].offsetLeft <= 15) {
sorting = $('#' + isoElems[i].id).find('.wpr-sorting').text() - 0.5;
break;
}
}
var elementCSS = elem.attr('class');
elementCSS = elementCSS.replace("show-full", "");
elementCSS = elementCSS.replace("format", "");
var newItem = $('<div id="wpr-baloon" data-item-id="' + id + '" class="' + elementCSS + ' ballon">' + modalHtml + '<p class="wpr-sorting">' + sorting + '</p></div>');
$container.imagesLoaded(function () {
$container.append(newItem).isotope('appended', newItem);
$container.isotope({sortBy: 'sorting'});
if ($('#wpr-baloon').length) {
if (isOpen == true) {
setTimeout(function () {
var childof = $('#wpr-baloon').attr('data-item-id');
var destination = $('#' + childof).offset().top + $('#' + childof).outerHeight() - 50;
$('body,html').scrollTo(destination, 400);
}, 500);
} else {
var childof = $('#wpr-baloon').attr('data-item-id');
var destination = $('#' + childof).offset().top + $('#' + childof).outerHeight() - 50;
$('body,html').scrollTo(destination, 400);
}
}
$("#wpr-baloon .boxscroll-active").niceScroll({
cursorcolor: "#000000",
cursoropacitymin: 1,
cursoropacitymax: 1,
cursorwidth: 8,
cursorborder: '0'
});
$("#wpr-baloon .boxscroll-active").getNiceScroll().resize();
});
}
}
function wpr_remove_modal(isOpen) {
var elem_bollino = $('#wpr-baloon');
if (elem_bollino.length) {
if (isOpen == true) {
$('#wpr-display-articles').isotope('remove', elem_bollino).isotope();
} else {
$('#wpr-display-articles').isotope('remove', elem_bollino).isotope();
var scrollto = $('#wpr-baloon').attr('data-item-id');
var dest = $('#' + scrollto).offset().top - 50;
$('body,html').scrollTo(dest, 400);
}
}
}
function calculate_dimensions(item_width, num) {
var item_height = (item_width);
setTimeout(function () {
$('.ballon').width(num * item_width);
$('.ballon').css('min-height', 2 * item_height);
$('.ballon').css('height', 'auto');
}, 100);
}
$('.wpr-display-articles-filter').on('click', '#wpr-toggle', function (e) {
e.preventDefault();
$(this).toggleClass('on');
});
});