1 elgg.provide(
'elgg.ui.widgets');
9 elgg.ui.widgets.init =
function() {
12 if ($(
".elgg-widgets").length === 0) {
16 $(
".elgg-widgets").sortable({
17 items:
'div.elgg-module-widget.elgg-state-draggable',
18 connectWith:
'.elgg-widgets',
19 handle:
'.elgg-widget-handle',
20 forcePlaceholderSize:
true,
24 stop:
elgg.ui.widgets.move
27 $(
'.elgg-widgets-add-panel li.elgg-state-available').
click(
elgg.ui.widgets.add);
29 $(
'a.elgg-widget-delete-button').live(
'click',
elgg.ui.widgets.remove);
30 $(
'.elgg-widget-edit > form ').live(
'submit',
elgg.ui.widgets.saveSettings);
31 $(
'a.elgg-widget-collapse-button').live(
'click',
elgg.ui.widgets.collapseToggle);
33 elgg.ui.widgets.setMinHeight(
".elgg-widgets");
44 elgg.ui.widgets.add =
function(event) {
45 var
type = $(
this).data(
'elgg-widget-type');
48 var multiple = $(
this).attr(
'class').indexOf(
'elgg-widget-multiple') != -1;
49 if (multiple ===
false) {
50 $(
this).addClass(
'elgg-state-unavailable');
51 $(
this).removeClass(
'elgg-state-available');
52 $(
this).unbind(
'click',
elgg.ui.widgets.add);
55 elgg.action(
'widgets/add', {
58 page_owner_guid:
elgg.get_page_owner_guid(),
59 context: $(
"input[name='widget_context']").val(),
60 show_access: $(
"input[name='show_access']").val(),
61 default_widgets: $(
"input[name='default_widgets']").val() || 0
64 $(
'#elgg-widget-col-1').prepend(json.output);
67 event.preventDefault();
78 elgg.ui.widgets.move =
function(event, ui) {
81 var guidString = ui.item.attr(
'id');
82 guidString = guidString.substr(guidString.indexOf(
'elgg-widget-') +
"elgg-widget-".length);
85 var
col = ui.item.parent().attr(
'id');
86 col = col.substr(col.indexOf(
'elgg-widget-col-') +
"elgg-widget-col-".length);
88 elgg.action(
'widgets/move', {
90 widget_guid: guidString,
97 ui.item.css(
'top', 0);
98 ui.item.css(
'left', 0);
109 elgg.ui.widgets.remove =
function(event) {
110 if (confirm(
elgg.echo(
'deleteconfirm')) ===
false) {
111 event.preventDefault();
115 var
$widget = $(
this).closest(
'.elgg-module-widget');
118 var
type = $(
this).data(
'elgg-widget-type');
119 $container = $(
this).parents(
'.elgg-layout-widgets').first();
120 $button = $(
'[data-elgg-widget-type="' + type +
'"]',
$container);
121 var multiple = $button.attr(
'class').indexOf(
'elgg-widget-multiple') != -1;
122 if (multiple ===
false) {
123 $button.addClass(
'elgg-state-available');
124 $button.removeClass(
'elgg-state-unavailable');
125 $button.unbind(
'click',
elgg.ui.widgets.add);
126 $button.click(
elgg.ui.widgets.add);
132 elgg.action($(
this).attr(
'href'));
134 event.preventDefault();
143 elgg.ui.widgets.collapseToggle =
function(event) {
144 $(
this).toggleClass(
'elgg-widget-collapsed');
145 $(
this).parent().parent().find(
'.elgg-body').slideToggle(
'medium');
146 event.preventDefault();
157 elgg.ui.widgets.saveSettings =
function(event) {
158 $(
this).parent().slideToggle(
'medium');
159 var $widgetContent = $(
this).parent().parent().children(
'.elgg-widget-content');
162 var
$loader = $(
'#elgg-widget-loader').clone();
163 $loader.attr(
'id',
'#elgg-widget-active-loader');
164 $loader.removeClass(
'hidden');
165 $widgetContent.html($loader);
167 var default_widgets = $(
"input[name='default_widgets']").val() || 0;
168 if (default_widgets) {
169 $(
this).append(
'<input type="hidden" name="default_widgets" value="1">');
172 elgg.action(
'widgets/save', {
173 data: $(
this).serialize(),
175 $widgetContent.html(json.output);
176 if (typeof(json.title) !=
"undefined") {
177 var $widgetTitle = $widgetContent.parent().parent().find(
'.elgg-widget-title');
178 $widgetTitle.html(json.title);
182 event.preventDefault();
194 elgg.ui.widgets.setMinHeight =
function(selector) {
196 $(selector).each(
function() {
198 if (bottom > maxBottom) {
202 $(selector).each(
function() {
204 if (bottom < maxBottom) {
205 var newMinHeight = parseInt($(
this).
height() + (maxBottom - bottom));
206 $(
this).css(
'min-height', newMinHeight +
'px');
211 elgg.register_hook_handler(
'init',
'system',
elgg.ui.widgets.init);
elgg message elgg state success
clearfix elgg elgg elgg elgg page elgg page elgg elgg elgg col
elgg module widget elgg state draggable elgg widget handle
function elgg combo checkbox click(function(){if($(this).is(':checked')){$(this).prev().attr('disabled', true);$(this).prev().val('');}else{$(this).prev().attr('disabled', false);}})