-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathportlet.js
More file actions
172 lines (148 loc) · 5.45 KB
/
Copy pathportlet.js
File metadata and controls
172 lines (148 loc) · 5.45 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
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
Drupal.behaviors.portlet = function (context) {
// Hide panel with form to customize panels
$('div#portlet-categories-menu').hide();
// Replace checkboxes by image representation
//$('.portlet-checkbox-checked').parent().css('background', 'red');
//$('.portlet-checkbox-unchecked').parent().css('background', 'blue');
// Hide checkboxes when dey replaced by "image - checkboxes"
//$('.portlet-checkbox').hide();
$('a#portlet-customize').click(function() {
if ($('div#portlet-categories-menu').is(':visible')) {
$('div#portlet-categories-menu').hide('slow');
} else {
$('div#portlet-categories-menu').show('slow');
}
return false;
});
/*
* kick ass checkboxes
function checkCheckbox(name) {
$(name).attr('checked', true).removeClass('portlet-checkbox-unchecked').addClass('portlet-checkbox-checked');
}
function uncheckCheckbox(name) {
$(name).attr('checked', false).removeClass('portlet-checkbox-checked').addClass('portlet-checkbox-unchecked');
}
*/
function savePanelsPosition() {
// @todo Actualize only ui.item(id)
var left = String($('div#portlet-left-column').sortable('toArray'));
var center = String($('div#portlet-center-column').sortable('toArray'));
var right = String($('div#portlet-right-column').sortable('toArray'));
$.post('portlet/save/ajax', { left: left, center: center, right: right });
}
function minimizePanel(panel) {
var url = $(panel).children('.portlet-panel-icons').children('.portlet-resize').attr('href');
$.getJSON(url + '/ajax', function(data) {
// @todo there is no two different icons for minimize and maximize
$(panel).children('.portlet-panel-title').children('.portlet-resize').attr('href', data.url);//.html('M');
$(panel).next('.portlet-panel-content').slideUp('slow');
});
}
function maximizePanel(panel) {
var url = $(panel).children('.portlet-panel-icons').children('.portlet-resize').attr('href');
$.getJSON(url + '/ajax', function(data) {
// @todo there is no two different icons for minimize and maximize
$(panel).children('.portlet-panel-title').children('.portlet-resize').attr('href', data.url);//.html('m');
$(panel).next('.portlet-panel-content').slideDown('slow');
});
}
function closePanel(panel) {
var url = $(panel).children('.portlet-panel-header').children('.portlet-panel-icons').children('.portlet-close').attr('href');
var checkbox = '#' + $(panel).attr('id') + '-checkbox';
$.getJSON(url + '/ajax', function(data) {
$(panel).slideUp('slow', function() {
// kick ass checkboxes still not implemented
//uncheckCheckbox(checkbox);
$(checkbox).attr('checked',false);
$(panel).remove();
});
});
}
/**
* Function is called after
* panel was moved to new column.
*/
function stopMovingPanel(event, ui) {
savePanelsPosition();
}
/**
* Fuction is called before
* panel was start moving
*/
function startMovingPanel(event, ui) {
var width = $(this).css('width');
$(ui.item).css('width', width);
}
$('.portlet-handler-js').css('cursor', 'move');
$('a.portlet-close').click(function() {
var panel = $(this).parent().parent().parent();
closePanel(panel);
return false;
});
/**
* Handling for checkboxes
* Parents should react on clicking
* Handle for nice looking checkboxes
*/
/*
$('.portlet-checkbox').parent().click(function () {
if ($(this).hasClass('portlet-checkbox-checked')) {
uncheckCheckbox(checkbox);
} else {
checkCheckbox(checkbox);
}
});*/
// Service +/- links by ajax
$('a.portlet-countup').click(function () {
var url = $(this).attr('href');
var bar = $(this).parent().parent();
var content = $(bar).next();
$.getJSON(url + '/ajax', function(data) {
$(bar).children('.portlet-panel-icons').children('.portlet-countdown').attr('href', data.countdown);
$(bar).children('.portlet-panel-icons').children('.portlet-countup').attr('href', data.countup);
var cid = $(content).attr('id');
$(content).children().children().html(data.content);
});
return false;
});
$('a.portlet-countdown').click(function () {
var url = $(this).attr('href');
var bar = $(this).parent().parent();
var content = $(bar).next();
$.getJSON(url + '/ajax', function(data) {
$(bar).children('.portlet-panel-icons').children('.portlet-countdown').attr('href', data.countdown);
$(bar).children('.portlet-panel-icons').children('.portlet-countup').attr('href', data.countup);
$(content).children().children().html(data.content);
});
return false;
});
$('a.portlet-resize').click(function () {
panel = $(this).parent().parent();
if ($(panel).next('.portlet-panel-content').is(':visible')) {
minimizePanel(panel);
} else {
maximizePanel(panel);
}
return false;
});
// Select all elements witch should be movable
var columns = ['.portlet-column-js'];
var $columns = $(columns.toString());
// Make column's elements movable
$columns.sortable({
items: '> .portlet-panel-js',
handle: '.portlet-handler-js',
cursor: 'move',
opacity: 0.5,
scroll: true,
scrollSensitivity: '100',
revert: true,
tolerance: 'pointer',
connectWith: columns,
// @todo somehow add resize animation after drop
// change CSS removing 100% weight for childrens
// think about it
start: startMovingPanel,
stop: stopMovingPanel,
});
};