Elgg  Version 3.0
widgets.js
Go to the documentation of this file.
1 
4 define(['elgg', 'jquery', 'elgg/ready'], function (elgg, $) {
5 
6  var widgets = {};
7 
14  widgets.init = function () {
15 
16  // widget layout?
17  if ($(".elgg-widgets").length === 0) {
18  return;
19  }
20 
21  $(".elgg-widgets").sortable({
22  items: 'div.elgg-module-widget.elgg-state-draggable',
23  connectWith: '.elgg-widgets',
24  handle: '.elgg-widget-handle',
25  forcePlaceholderSize: true,
26  placeholder: 'elgg-widget-placeholder',
27  opacity: 0.8,
28  revert: 500,
29  stop: widgets.move
30  });
31 
32  $(document).on('click', 'a.elgg-widget-delete-button', widgets.remove);
33  $(document).on('submit', '.elgg-widget-edit > form ', widgets.saveSettings);
34  $(document).on('click', 'a.elgg-widget-collapse-button', widgets.collapseToggle);
35  };
36 
45  widgets.move = function (event, ui) {
46 
47  // elgg-widget-<guid>
48  var guidString = ui.item.attr('id');
49  guidString = guidString.substr(guidString.indexOf('elgg-widget-') + "elgg-widget-".length);
50 
51  // elgg-widget-col-<column>
52  var col = ui.item.parent().attr('id');
53  col = col.substr(col.indexOf('elgg-widget-col-') + "elgg-widget-col-".length);
54 
55  elgg.action('widgets/move', {
56  data: {
57  widget_guid: guidString,
58  column: col,
59  position: ui.item.index()
60  }
61  });
62 
63  // @hack fixes jquery-ui/opera bug where draggable elements jump
64  ui.item.css('top', 0);
65  ui.item.css('left', 0);
66  };
67 
76  widgets.remove = function (event) {
77  if (confirm(elgg.echo('deleteconfirm')) === false) {
78  event.preventDefault();
79  return;
80  }
81 
82  $(this).closest('.elgg-module-widget').remove();
83 
84  // delete the widget through ajax
85  elgg.action($(this).attr('href'));
86 
87  event.preventDefault();
88  };
89 
96  widgets.collapseToggle = function (event) {
97  $(this).toggleClass('elgg-widget-collapsed');
98  $(this).parent().parent().find('.elgg-body').slideToggle('medium');
99  event.preventDefault();
100  };
101 
110  widgets.saveSettings = function (event) {
111  $(this).parent().slideToggle('medium');
112  var $widgetContent = $(this).parent().parent().children('.elgg-widget-content');
113 
114  // stick the ajax loader in there
115  var $loader = $('#elgg-widget-loader').clone();
116  $loader.attr('id', '#elgg-widget-active-loader');
117  $loader.removeClass('hidden');
118  $widgetContent.html($loader);
119 
120  elgg.action('widgets/save', {
121  data: $(this).serialize(),
122  success: function (json) {
123  $widgetContent.html(json.output.content);
124  if (typeof (json.output.title) != "undefined") {
125  var $widgetTitle = $widgetContent.parent().parent().find('.elgg-widget-title');
126  $widgetTitle.html(json.title);
127  }
128  }
129  });
130  event.preventDefault();
131  };
132 
133  return widgets;
134 });
135 
define(['elgg', 'jquery', 'elgg/ready'], 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});$(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.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;}$(this).closest('.elgg-module-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);elgg.action('widgets/save',{data:$(this).serialize(), success:function(json){$widgetContent.html(json.output.content);if(typeof(json.output.title)!="undefined"){var $widgetTitle=$widgetContent.parent().parent().find('.elgg-widget-title');$widgetTitle.html(json.title);}}});event.preventDefault();};return widgets;})
elgg/widgets
Bundled plugins(the contents of the"/mod"directory) are available only under the GPLv2 license.The remainder of the project is available under either MIT or GPLv2.Both licenses can be found below.More info 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: LICENSE.txt:96
var elgg
Definition: elgglib.js:4
$loader
Definition: ajax_loader.php:27