forked from hbz/edoweb-drupal-theme
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfacets.js
132 lines (118 loc) · 5.58 KB
/
facets.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
(function($) {
Drupal.behaviors.edoweb_drupal_theme_facets = {
attach: function (context, settings) {
// append the div for toggle functionality to each facet
$('.item-list h3', context).each(function() {
var facetHeader = $(this);
var facetName = facetHeader.html();
facetHeader.parent().attr('id', facetName);
//alert(facetName + ': ' + $.cookie(facetName));
if ($.cookie(facetName)) {
facetHeader.append('<div class="toggleButton"><span class="' + $.cookie(facetName) + '"></span> </div>');
//$(this).find('div span.octicon-triangle-up').parent().parent().parent().find("ul").css('display', 'block');
facetHeader.find('div span.octicon-triangle-down').parent().parent().parent().find("ul").css('display', 'none');
} else {
facetHeader.append('<div class="toggleButton"><span class="octicon octicon-triangle-up"></span> </div>');
}
});
// restore order of facets from cookie
if ($.cookie('sortFacets')) {
var sortFacets = $('.item-list h3', context).parent();
var facetsParent = $('.item-list h3', context).parent().parent();
var cookieSplit = $.cookie('sortFacets').split(' ');
var i;
for (i=0; i < cookieSplit.length; i++) {
var part = sortFacets.filter('#' + cookieSplit[i].trim());
facetsParent.append(part);
};
}
// add sortable behaviour to facet list
$('.edoweb-facets .fieldset-wrapper', context).sortable({
update: function(event, ui) {
var sorts = $('.edoweb-facets .fieldset-wrapper', context).sortable('toArray');
var i = 0;
var cookieValue = '';
//alert(sorts.length);
while (i < sorts.length) {
cookieValue = cookieValue +' ' + sorts[i];
i++;
}
$.cookie('sortFacets', cookieValue.trim());
},
});
// toggle functionality
$('.item-list h3 div span', context).click(function() {
var facet = $(this).parent().parent().parent().find("ul");
facet.toggle("clip", function() {
var facetHeader = $(this).parent().find('h3 div span');
facetHeader.toggleClass('octicon-triangle-down').toggleClass('octicon-triangle-up');
var status = facetHeader.attr('class');
var facetName = facetHeader.parent().parent().parent().attr('id');
$.cookie(facetName, status);
});
});
}
};
Drupal.behaviors.edoweb_drupal_theme_icons = {
attach: function (context, settings) {
var icons = {
'monograph': 'octicon-repo',
'journal': 'octicon-versions',
'volume': 'octicon-list-ordered',
'issue': 'octicon-book',
'article': 'octicon-file-text',
'file': 'octicon-file-binary',
'webpage': 'octicon-browser',
'version': 'octicon-git-branch'
}
for (var bundle in icons) {
var icon = icons[bundle];
$('#content .form-type-item a[data-bundle="' + bundle + '"]', context).prepend($('<span> </span>').addClass('octicon ' + icon));
$('#edoweb-tree-menu a[data-bundle="' + bundle + '"]', context).prepend($('<span> </span>').addClass('octicon ' + icon));
$('.edoweb-tree a[data-bundle="' + bundle + '"]', context).before($('<span> </span>').addClass('octicon ' + icon));
$('.entity-label-' + bundle, context).before($('<span> </span>').addClass('octicon ' + icon));
$('body.entity-type-' + bundle + ' h1.title', context).addClass('mega-octicon ' + icon);
}
replaceWithIcon($('label a[href="#"]'), 'batch-icons batch-icon-plus', context);
replaceWithIcon($('label[for="edit-field-edoweb-parent-und"] a[href="#"]', context), 'batch-icons batch-icon-concat');
replaceWithIcon($('label[for="edit-field-edoweb-identifier-ht-und-0-value"] a[href="#"]', context), 'batch-icons batch-icon-concat');
replaceWithIcon($('label[for="edit-field-edoweb-parallel-und"] a[href="#"]', context), 'batch-icons batch-icon-concat');
function replaceWithIcon(target, iconCss) {
target
.attr('title', target.html())
.html('<span class="' + iconCss + '"></span>');
}
}
};
Drupal.behaviors.edoweb_drupal_theme_zoom = {
attach: function (context, settings) {
// add zoom control to search result listing
$('.edoweb-entity-list ul.pager:first', context).append('<div class="toggleButton"><span class="batch-icons batch-icon-zoom-plus"></span><span class="batch-icons batch-icon-zoom-minus"></div>');
if ($.cookie('table-font-size')) {
$('table', context).css('font-size', $.cookie('table-font-size') + 'px');
}
$('.edoweb-entity-list ul.pager span.batch-icon-zoom-plus', context).click(function() {
var size = $('table').css('font-size');
var newSize = parseFloat(size) + 1;
$('table').css('font-size', newSize);
$.cookie("table-font-size", newSize);
});
$('.edoweb-entity-list ul.pager span.batch-icon-zoom-minus', context).click(function() {
var size = $('table').css('font-size');
var newSize = parseFloat(size) - 1;
$('table').css('font-size', newSize);
$.cookie("table-font-size", newSize);
});
}
};
//Drupal.behaviors.edoweb_drupal_theme_datepicker = {
// attach: function (context, settings) {
// // datepicker
// $('#edit-field-edoweb-issued-und-0-value', context).datepicker({
// changeMonth:true,
// changeYear:true,
// dateFormat:"dd.mm.yy"
// });
// }
//};
})(jQuery);