Elgg  Version 1.9
ui.widgets.js
Go to the documentation of this file.
1 elgg.provide('elgg.ui.widgets');
2 
9 elgg.ui.widgets.init = function() {
10 
11  // widget layout?
12  if ($(".elgg-widgets").length === 0) {
13  return;
14  }
15 
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,
21  placeholder: 'elgg-widget-placeholder',
22  opacity: 0.8,
23  revert: 500,
24  stop: elgg.ui.widgets.move
25  });
26 
27  $('.elgg-widgets-add-panel li.elgg-state-available').click(elgg.ui.widgets.add);
28 
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);
32 
33  elgg.ui.widgets.setMinHeight(".elgg-widgets");
34 };
35 
44 elgg.ui.widgets.add = function(event) {
45  var type = $(this).data('elgg-widget-type');
46 
47  // if multiple instances not allow, disable this widget type add button
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);
53  }
54 
55  elgg.action('widgets/add', {
56  data: {
57  handler: type,
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
62  },
63  success: function(json) {
64  $('#elgg-widget-col-1').prepend(json.output);
65  }
66  });
67  event.preventDefault();
68 };
69 
78 elgg.ui.widgets.move = function(event, ui) {
79 
80  // elgg-widget-<guid>
81  var guidString = ui.item.attr('id');
82  guidString = guidString.substr(guidString.indexOf('elgg-widget-') + "elgg-widget-".length);
83 
84  // elgg-widget-col-<column>
85  var col = ui.item.parent().attr('id');
86  col = col.substr(col.indexOf('elgg-widget-col-') + "elgg-widget-col-".length);
87 
88  elgg.action('widgets/move', {
89  data: {
90  widget_guid: guidString,
91  column: col,
92  position: ui.item.index()
93  }
94  });
95 
96  // @hack fixes jquery-ui/opera bug where draggable elements jump
97  ui.item.css('top', 0);
98  ui.item.css('left', 0);
99 };
100 
109 elgg.ui.widgets.remove = function(event) {
110  if (confirm(elgg.echo('deleteconfirm')) === false) {
111  event.preventDefault();
112  return;
113  }
114 
115  var $widget = $(this).closest('.elgg-module-widget');
116 
117  // if widget type is single instance type, enable the add buton
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); // make sure we don't bind twice
126  $button.click(elgg.ui.widgets.add);
127  }
128 
129  $widget.remove();
130 
131  // delete the widget through ajax
132  elgg.action($(this).attr('href'));
133 
134  event.preventDefault();
135 };
136 
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();
147 };
148 
157 elgg.ui.widgets.saveSettings = function(event) {
158  $(this).parent().slideToggle('medium');
159  var $widgetContent = $(this).parent().parent().children('.elgg-widget-content');
160 
161  // stick the ajax loader in there
162  var $loader = $('#elgg-widget-loader').clone();
163  $loader.attr('id', '#elgg-widget-active-loader');
164  $loader.removeClass('hidden');
165  $widgetContent.html($loader);
166 
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">');
170  }
171 
172  elgg.action('widgets/save', {
173  data: $(this).serialize(),
174  success: function(json) {
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);
179  }
180  }
181  });
182  event.preventDefault();
183 };
184 
194 elgg.ui.widgets.setMinHeight = function(selector) {
195  var maxBottom = 0;
196  $(selector).each(function() {
197  var bottom = parseInt($(this).offset().top + $(this).height());
198  if (bottom > maxBottom) {
199  maxBottom = bottom;
200  }
201  });
202  $(selector).each(function() {
203  var bottom = parseInt($(this).offset().top + $(this).height());
204  if (bottom < maxBottom) {
205  var newMinHeight = parseInt($(this).height() + (maxBottom - bottom));
206  $(this).css('min-height', newMinHeight + 'px');
207  }
208  });
209 };
210 
211 elgg.register_hook_handler('init', 'system', elgg.ui.widgets.init);
elgg message elgg state success
Definition: admin.php:243
elgg
Definition: install.js:23
clearfix elgg elgg elgg elgg page elgg page elgg elgg elgg col
Definition: admin.php:127
list style position
Definition: typography.php:154
elgg module widget elgg state draggable elgg widget handle
Definition: admin.php:1183
$widget
Definition: delete.php:9
margin top
Definition: admin.php:192
margin bottom
Definition: admin.php:38
$pages items
Definition: pagination.php:62
elgg widget placeholder
Definition: admin.php:1222
function elgg combo checkbox click(function(){if($(this).is(':checked')){$(this).prev().attr('disabled', true);$(this).prev().val('');}else{$(this).prev().attr('disabled', false);}})
list style type
Definition: admin.php:724
$container
Definition: access.php:30
$loader
Definition: ajax_loader.php:32
line height
Definition: admin.php:82