forked from drupalprojects/panopoly_widgets
-
Notifications
You must be signed in to change notification settings - Fork 0
/
panopoly-widgets.js
87 lines (76 loc) · 2.93 KB
/
panopoly-widgets.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
Drupal.settings.spotlight_settings = Drupal.settings.spotlight_settings || {};
(function ($) {
/**
* Get the total displacement of given region.
*
* @param region
* Region name. Either "top" or "bottom".
*
* @return
* The total displacement of given region in pixels.
*/
if (Drupal.overlay) {
Drupal.overlay.getDisplacement = function (region) {
var displacement = 0;
var lastDisplaced = $('.overlay-displace-' + region + ':last');
if (lastDisplaced.length) {
displacement = lastDisplaced.offset().top + lastDisplaced.outerHeight();
// In modern browsers (including IE9), when box-shadow is defined, use the
// normal height.
var cssBoxShadowValue = lastDisplaced.css('box-shadow');
var boxShadow = (typeof cssBoxShadowValue !== 'undefined' && cssBoxShadowValue !== 'none');
// In IE8 and below, we use the shadow filter to apply box-shadow styles to
// the toolbar. It adds some extra height that we need to remove.
if (!boxShadow && /DXImageTransform\.Microsoft\.Shadow/.test(lastDisplaced.css('filter'))) {
displacement -= lastDisplaced[0].filters.item('DXImageTransform.Microsoft.Shadow').strength;
displacement = Math.max(0, displacement);
}
}
return displacement;
};
};
/**
* Form behavior for Spotlight
*/
Drupal.behaviors.panopolySpotlight = {
attach: function (context, settings) {
if ($('.field-name-field-basic-spotlight-items').length) {
var rotation_time = Drupal.settings.spotlight_settings.rotation_time;
$('.field-name-field-basic-spotlight-items').tabs().tabs("rotate", rotation_time, true);
// $('.field-name-field-basic-spotlight-items').css('height', $('.field-name-field-basic-spotlight-items').height());
// $('.field-name-field-basic-spotlight-items').css('overflow', 'hidden');
}
}
}
/**
* Create responsive magic for Table Widget
*/
Drupal.behaviors.panopolyWidgetTables = {
attach: function (context, settings) {
$('table.tablefield', context).each(function() {
var table = $(this); // cache table object.
var head = table.find('thead th');
var rows = table.find('tbody tr').clone(); // appending afterwards does not break original table.
// create new table
var newtable = $(
'<table class="mobile-table">' +
' <tbody>' +
' </tbody>' +
'</table>'
);
// cache tbody where we'll be adding data.
var newtable_tbody = newtable.find('tbody');
rows.each(function(i) {
var cols = $(this).find('td');
var classname = i % 2 ? 'even' : 'odd';
cols.each(function(k) {
var new_tr = $('<tr class="' + classname + '"></tr>').appendTo(newtable_tbody);
new_tr.append(head.clone().get(k));
new_tr.append($(this));
});
});
$(this).after(newtable);
});
}
}
})(jQuery);