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
|
elgg.provide('elgg.ui.widgets');
elgg.ui.widgets.init = function() {
$(".widget_column").sortable({
items: 'div.widget',
connectWith: '.widget_column',
handle: 'div.drag_handle',
forcePlaceholderSize: true,
placeholder: 'widget_placeholder'
});
$('#widget_add_button a').bind('click', function(event) {
$('.widgets_add').slideToggle('medium');
event.preventDefault();
});
$('.widgets_add a').bind('click', function(event) {
elgg.action('widgets/add', {
data: {
handler: $(this).attr('id'),
user: elgg.get_loggedin_userid(),
context: $("input[name='widget_context']").val()
},
success: function(json) {
elgg.ui.widgets.insert(json.output);
}
});
event.preventDefault();
});
elgg.ui.widgets.equalHeight(".widget_column");
};
// insert a widget into the layout
elgg.ui.widgets.insert = function(html) {
$('.widget_col_1').prepend(html);
}
elgg.ui.widgets.equalHeight = function(selector) {
var maxHeight = 0;
$(selector).each(function() {
if ($(this).height() > maxHeight) {
maxHeight = $(this).height();
}
})
$(selector).css('min-height', maxHeight);
}
//List active widgets for each page column
elgg.ui.widgets.outputList = function(forElement) {
return $("input[name='handler'], input[name='guid']", forElement).makeDelimitedList("value");
};
//Read each widgets collapsed/expanded state from cookie and apply
elgg.ui.widgets.state = function(forWidget) {
var thisWidgetState = elgg.session.cookie(forWidget);
if (thisWidgetState === 'collapsed') {
forWidget = "#" + forWidget;
$(forWidget).find("div.collapsable_box_content").hide();
$(forWidget).find("a.toggle_box_contents").html('+');
$(forWidget).find("a.toggle_box_edit_panel").fadeOut('medium');
}
};
//More info tooltip in widget gallery edit panel
elgg.ui.widgets.moreinfo = function() {
$("img.more_info").hover(function(e) {
var widgetdescription = $("input[name='description']", this.parentNode.parentNode.parentNode).val();
$("body").append("<p id='widget_moreinfo'><b>" + widgetdescription + " </b></p>");
if (e.pageX < 900) {
$("#widget_moreinfo")
.css("top", (e.pageY + 10) + "px")
.css("left", (e.pageX + 10) + "px")
.fadeIn("medium");
} else {
$("#widget_moreinfo")
.css("top", (e.pageY + 10) + "px")
.css("left", (e.pageX - 210) + "px")
.fadeIn("medium");
}
}, function() {
$("#widget_moreinfo").remove();
});
};
//Toggle widgets contents and save to a cookie
elgg.ui.widgets.toggleContent = function(e) {
var thisWidgetName,
targetContent = $('div.collapsable_box_content', this.parentNode.parentNode);
if (targetContent.css('display') === 'none') {
targetContent.slideDown(400);
$(this).html('-');
$(this.parentNode).children(".toggle_box_edit_panel").fadeIn('medium');
// set cookie for widget panel open-state
thisWidgetName = $(this.parentNode.parentNode.parentNode).attr('id');
elgg.session.cookie(thisWidgetName, 'expanded', {expires: 365});
} else {
targetContent.slideUp(400);
$(this).html('+');
$(this.parentNode).children(".toggle_box_edit_panel").fadeOut('medium');
// make sure edit pane is closed
$(this.parentNode.parentNode).children(".collapsable_box_editpanel").hide();
// set cookie for widget panel closed-state
thisWidgetName = $(this.parentNode.parentNode.parentNode).attr('id');
elgg.session.cookie(thisWidgetName, 'collapsed', {expires: 365});
}
return false;
};
/**
* @deprecated Use elgg.ui.widgets.*
*/
var toggleContent = elgg.ui.widgets.toggleContent,
widget_moreinfo = elgg.ui.widgets.moreinfo,
widget_state = elgg.ui.widgets.state,
outputWidgetList = elgg.ui.widgets.outputList;
elgg.register_event_handler('init', 'system', elgg.ui.widgets.init);
|