Elgg  Version 2.3
widgets.js
Go to the documentation of this file.
1 
10 define('elgg/widgets', ['elgg', 'jquery'], function (elgg, $) {
11 
12  var widgets = {};
13 
20  widgets.init = function () {
21 
22  // widget layout?
23  if ($(".elgg-widgets").length === 0) {
24  return;
25  }
26 
27  $(".elgg-widgets").sortable({
28  items: 'div.elgg-module-widget.elgg-state-draggable',
29  connectWith: '.elgg-widgets',
30  handle: '.elgg-widget-handle',
31  forcePlaceholderSize: true,
32  placeholder: 'elgg-widget-placeholder',
33  opacity: 0.8,
34  revert: 500,
35  stop: widgets.move
36  });
37 
38  $('.elgg-widgets-add-panel li.elgg-state-available').click(widgets.add);
39 
40  $(document).on('click', 'a.elgg-widget-delete-button', widgets.remove);
41  $(document).on('submit', '.elgg-widget-edit > form ', widgets.saveSettings);
42  $(document).on('click', 'a.elgg-widget-collapse-button', widgets.collapseToggle);
43 
44  widgets.setMinHeight(".elgg-widgets");
45  };
46 
55  widgets.add = function (event) {
56  var type = $(this).data('elgg-widget-type');
57 
58  // if multiple instances not allow, disable this widget type add button
59  var multiple = $(this).attr('class').indexOf('elgg-widget-multiple') != -1;
60  if (multiple === false) {
61  $(this).addClass('elgg-state-unavailable');
62  $(this).removeClass('elgg-state-available');
63  $(this).unbind('click', widgets.add);
64  }
65 
66  var $layout = $(this).closest('.elgg-layout-widgets');
67  var page_owner_guid = $layout.data('pageOwnerGuid') || elgg.get_page_owner_guid();
68 
69  elgg.action('widgets/add', {
70  data: {
71  handler: type,
72  page_owner_guid: page_owner_guid,
73  context: $("input[name='widget_context']").val(),
74  show_access: $("input[name='show_access']").val(),
75  default_widgets: $("input[name='default_widgets']").val() || 0
76  },
77  success: function (json) {
78  $('#elgg-widget-col-1').prepend(json.output);
79  }
80  });
81  event.preventDefault();
82  };
83 
92  widgets.move = function (event, ui) {
93 
94  // elgg-widget-<guid>
95  var guidString = ui.item.attr('id');
96  guidString = guidString.substr(guidString.indexOf('elgg-widget-') + "elgg-widget-".length);
97 
98  // elgg-widget-col-<column>
99  var col = ui.item.parent().attr('id');
100  col = col.substr(col.indexOf('elgg-widget-col-') + "elgg-widget-col-".length);
101 
102  elgg.action('widgets/move', {
103  data: {
104  widget_guid: guidString,
105  column: col,
106  position: ui.item.index()
107  }
108  });
109 
110  // @hack fixes jquery-ui/opera bug where draggable elements jump
111  ui.item.css('top', 0);
112  ui.item.css('left', 0);
113  };
114 
123  widgets.remove = function (event) {
124  if (confirm(elgg.echo('deleteconfirm')) === false) {
125  event.preventDefault();
126  return;
127  }
128 
129  var $widget = $(this).closest('.elgg-module-widget');
130 
131  // if widget type is single instance type, enable the add buton
132  var type = $(this).data('elgg-widget-type');
133  $container = $(this).parents('.elgg-layout-widgets').first();
134  $button = $('[data-elgg-widget-type="' + type + '"]', $container);
135  var multiple = $button.attr('class').indexOf('elgg-widget-multiple') != -1;
136  if (multiple === false) {
137  $button.addClass('elgg-state-available');
138  $button.removeClass('elgg-state-unavailable');
139  $button.unbind('click', widgets.add); // make sure we don't bind twice
140  $button.click(widgets.add);
141  }
142 
143  $widget.remove();
144 
145  // delete the widget through ajax
146  elgg.action($(this).attr('href'));
147 
148  event.preventDefault();
149  };
150 
157  widgets.collapseToggle = function (event) {
158  $(this).toggleClass('elgg-widget-collapsed');
159  $(this).parent().parent().find('.elgg-body').slideToggle('medium');
160  event.preventDefault();
161  };
162 
171  widgets.saveSettings = function (event) {
172  $(this).parent().slideToggle('medium');
173  var $widgetContent = $(this).parent().parent().children('.elgg-widget-content');
174 
175  // stick the ajax loader in there
176  var $loader = $('#elgg-widget-loader').clone();
177  $loader.attr('id', '#elgg-widget-active-loader');
178  $loader.removeClass('hidden');
179  $widgetContent.html($loader);
180 
181  var default_widgets = $("input[name='default_widgets']").val() || 0;
182  if (default_widgets) {
183  $(this).append('<input type="hidden" name="default_widgets" value="1">');
184  }
185 
186  elgg.action('widgets/save', {
187  data: $(this).serialize(),
188  success: function (json) {
189  $widgetContent.html(json.output);
190  if (typeof (json.title) != "undefined") {
191  var $widgetTitle = $widgetContent.parent().parent().find('.elgg-widget-title');
192  $widgetTitle.html(json.title);
193  }
194  }
195  });
196  event.preventDefault();
197  };
198 
208  widgets.setMinHeight = function (selector) {
209  var maxBottom = 0;
210  $(selector).each(function () {
211  var bottom = parseInt($(this).offset().top + $(this).height());
212  if (bottom > maxBottom) {
213  maxBottom = bottom;
214  }
215  });
216  $(selector).each(function () {
217  var bottom = parseInt($(this).offset().top + $(this).height());
218  if (bottom < maxBottom) {
219  var newMinHeight = parseInt($(this).height() + (maxBottom - bottom));
220  $(this).css('min-height', newMinHeight + 'px');
221  }
222  });
223  };
224 
225  return widgets;
226 });
elgg
Definition: install.js:23
clearfix elgg elgg elgg elgg page elgg page elgg elgg elgg col
Definition: admin.css.php:127
elgg module widget elgg state draggable elgg widget handle
Definition: admin.css.php:1269
line height
Definition: admin.css.php:82
elgg layout widgets elgg widgets
Definition: admin.css.php:1211
$widget
Definition: delete.php:9
list style type
Definition: admin.css.php:808
define('elgg/widgets', ['elgg', 'jquery'], function(elgg,$){var widgets={};widgets.init=function(){if($(".elgg-widgets").length===0){return;}$(".elgg-widgets").sortable({items: 'div.elgg-module-widget.elgg-state-draggable', connectWith: '.elgg-widgets', handle: '.elgg-widget-handle', forcePlaceholderSize:true, placeholder: 'elgg-widget-placeholder', opacity:0.8, revert:500, stop:widgets.move});$('.elgg-widgets-add-panel li.elgg-state-available').click(widgets.add);$(document).on('click', 'a.elgg-widget-delete-button', widgets.remove);$(document).on('submit', '.elgg-widget-edit > form ', widgets.saveSettings);$(document).on('click', 'a.elgg-widget-collapse-button', widgets.collapseToggle);widgets.setMinHeight(".elgg-widgets");};widgets.add=function(event){var type=$(this).data('elgg-widget-type');var multiple=$(this).attr('class').indexOf('elgg-widget-multiple')!=-1;if(multiple===false){$(this).addClass('elgg-state-unavailable');$(this).removeClass('elgg-state-available');$(this).unbind('click', widgets.add);}var $layout=$(this).closest('.elgg-layout-widgets');var page_owner_guid=$layout.data('pageOwnerGuid')||elgg.get_page_owner_guid();elgg.action('widgets/add',{data:{handler:type, page_owner_guid:page_owner_guid, context:$("input[name='widget_context']").val(), show_access:$("input[name='show_access']").val(), default_widgets:$("input[name='default_widgets']").val()||0}, success:function(json){$('#elgg-widget-col-1').prepend(json.output);}});event.preventDefault();};widgets.move=function(event, ui){var guidString=ui.item.attr('id');guidString=guidString.substr(guidString.indexOf('elgg-widget-')+"elgg-widget-".length);var col=ui.item.parent().attr('id');col=col.substr(col.indexOf('elgg-widget-col-')+"elgg-widget-col-".length);elgg.action('widgets/move',{data:{widget_guid:guidString, column:col, position:ui.item.index()}});ui.item.css('top', 0);ui.item.css('left', 0);};widgets.remove=function(event){if(confirm(elgg.echo('deleteconfirm'))===false){event.preventDefault();return;}var $widget=$(this).closest('.elgg-module-widget');var type=$(this).data('elgg-widget-type');$container=$(this).parents('.elgg-layout-widgets').first();$button=$('[data-elgg-widget-type="' + type + '"]', $container);var multiple=$button.attr('class').indexOf('elgg-widget-multiple')!=-1;if(multiple===false){$button.addClass('elgg-state-available');$button.removeClass('elgg-state-unavailable');$button.unbind('click', widgets.add);$button.click(widgets.add);}$widget.remove();elgg.action($(this).attr('href'));event.preventDefault();};widgets.collapseToggle=function(event){$(this).toggleClass('elgg-widget-collapsed');$(this).parent().parent().find('.elgg-body').slideToggle('medium');event.preventDefault();};widgets.saveSettings=function(event){$(this).parent().slideToggle('medium');var $widgetContent=$(this).parent().parent().children('.elgg-widget-content');var $loader=$('#elgg-widget-loader').clone();$loader.attr('id', '#elgg-widget-active-loader');$loader.removeClass('hidden');$widgetContent.html($loader);var default_widgets=$("input[name='default_widgets']").val()||0;if(default_widgets){$(this).append('< input type="hidden"name="default_widgets"value="1">');}elgg.action('widgets/save',{data:$(this).serialize(), success:function(json){$widgetContent.html(json.output);if(typeof(json.title)!="undefined"){var $widgetTitle=$widgetContent.parent().parent().find('.elgg-widget-title');$widgetTitle.html(json.title);}}});event.preventDefault();};widgets.setMinHeight=function(selector){var maxBottom=0;$(selector).each(function(){var bottom=parseInt($(this).offset().top+$(this).height());if(bottom > maxBottom){maxBottom=bottom;}});$(selector).each(function(){var bottom=parseInt($(this).offset().top+$(this).height());if(bottom< maxBottom){var newMinHeight=parseInt($(this).height()+(maxBottom-bottom));$(this).css('min-height', newMinHeight+ 'px');}});};return widgets;})
To implement a BC solution and deprecated elgg.ui.widgets, we use a named AMD module that is inlined ...
and that you know you can do these things To protect your we need to make restrictions that forbid anyone to deny you these rights or to ask you to surrender the rights These restrictions translate to certain responsibilities for you if you distribute copies of the or if you modify it For if you distribute copies of such a whether gratis or for a you must give the recipients all the rights that you have You must make sure that receive or can get the source code And you must show them these terms so they know their rights We protect your rights with two distribute and or modify the software for each author s protection and we want to make certain that everyone understands that there is no warranty for this free software If the software is modified by someone else and passed on
Definition: GPL-LICENSE.txt:43
$container
Definition: delete.php:29
margin bottom
Definition: admin.css.php:38
if(isset($httpCodes[$type])) $layout
Definition: error.php:33
function elgg combo checkbox click(function(){if($(this).is(':checked')){$(this).prev().attr('disabled', true);$(this).prev().val('');}else{$(this).prev().attr('disabled', false);}})
GNU GENERAL PUBLIC LICENSE June Free Software Inc Franklin Fifth MA USA Everyone is permitted to copy and distribute verbatim copies of this license document
Definition: GPL-LICENSE.txt:4
elgg message elgg state success
Definition: admin.css.php:252
list style position
$loader
Definition: ajax_loader.php:32
border top
Definition: admin.css.php:390
elgg widget placeholder
Definition: admin.css.php:1308