Elgg  Version 3.0
plugins.js
Go to the documentation of this file.
1 define(function(require) {
2  var $ = require('jquery');
3  var elgg = require('elgg');
4  var spinner = require('elgg/spinner');
5  var Ajax = require('elgg/Ajax');
6 
7  var ajax = new Ajax();
8 
9  function init () {
10 
11  initPluginReordering();
12 
13  // plugin category filtering
14  $(document).on('click', '.elgg-admin-plugins-categories a', filterPluginCategory);
15 
16  $(document).on('click', '.elgg-plugins-toggle', toggleAllPlugins);
17 
18  $(document).on('click', '.elgg-plugin-state-change', toggleSinglePlugin);
19 
20  // plugin screenshots
21  $(document).on('mouseenter', '.elgg-plugin-details-screenshots .elgg-plugin-screenshot', showPluginScreenshot);
22  };
23 
24  function freezePlugins() {
25  $('#elgg-plugin-list-cover').css('display', 'block');
26  };
27  function unfreezePlugins() {
28  $('#elgg-plugin-list-cover').css('display', 'none');
29  };
30 
31  function initPluginReordering() {
32  $('#elgg-plugin-list > ul').sortable({
33  items: 'li:has(> .elgg-state-draggable)',
34  handle: '.elgg-body',
35  forcePlaceholderSize: true,
36  placeholder: 'elgg-plugin-placeholder',
37  opacity: 0.8,
38  revert: 500,
39  stop: movePlugin
40  });
41  };
42 
43  function toggleSinglePlugin(e) {
44  freezePlugins();
45 
46  e.preventDefault();
47 
48  ajax.action(this.href)
49  .done(function (output, statusText, jqXHR) {
50  if (jqXHR.AjaxData.status == -1) {
51  // don't know status :/
52  location.reload();
53  return;
54  }
55 
56  // second request because views list must be rebuilt and this can't be done
57  // within the first.
58  ajax.path('admin_plugins_refresh')
59  .done(function (output) {
60 
61  $('#elgg-plugin-list').html(output.list);
62  $('.elgg-sidebar').html(output.sidebar);
63 
64  // reapply category filtering
65  $(".elgg-admin-plugins-categories > li.elgg-state-selected > a").trigger('click');
66  initPluginReordering();
67  unfreezePlugins();
68  });
69  });
70  };
71 
78  function toggleAllPlugins(e) {
79  e.preventDefault();
80 
81  if (!confirm(elgg.echo('question:areyousure'))) {
82  return;
83  }
84 
85  freezePlugins();
86 
87  var guids = [],
88  state = $(this).data('desiredState'),
89  find_state = state == 'active' ? 'inactive' : 'active';
90 
91  $('.elgg-plugin.elgg-state-' + find_state + ':visible').each(function () {
92  var guid = $(this).data('guid');
93  if (guid) {
94  guids.push(guid);
95  }
96  });
97 
98  if (!guids.length) {
99  elgg.register_error(elgg.echo('admin:plugins:already:' + state));
100  unfreezePlugins();
101  return;
102  }
103 
104  spinner.start();
105 
106  // We create a regular form and submit it. This is the simplest way to send the
107  // data, have the page refreshed, and make sure error messages are still shown on
108  // the new page. Using ajax leads to complexity because Elgg wants to send the error
109  // messages back to the client.
110  var $form = $('<form method="post" />');
111  $form.prop('action', elgg.security.addToken(this.href));
112  $form.append('<input type="hidden" name="guids" value="' + guids.join(',') + '" />');
113  $form.appendTo("body").submit();
114  };
115 
123  function movePlugin (e, ui) {
124  freezePlugins();
125 
126  // get guid from id like elgg-object-<guid>
127  var pluginGuid = ui.item.attr('id');
128  pluginGuid = pluginGuid.replace('elgg-object-', '');
129 
130  elgg.action('admin/plugins/set_priority', {
131  data: {
132  plugin_guid: pluginGuid,
133  // we start at priority 1
134  priority: ui.item.index() + 1
135  },
136  success: function() {
137  // update plugins with priority dependences
138  var priorityDep = new RegExp(elgg.echo('ElggPlugin:Dependencies:Priority'));
139  ui.item.siblings().andSelf().each(function() {
140  if (priorityDep.test($(this).find('.elgg-dependency-requires').text())) {
141  updatePluginView($(this));
142  }
143  });
144  unfreezePlugins();
145  }
146  });
147  };
148 
155  function updatePluginView (pluginView) {
156  // get guid from id like elgg-object-<guid>
157  var pluginGuid = pluginView.attr('id');
158  pluginGuid = pluginGuid.replace('elgg-object-', '');
159 
160  elgg.get({
161  url: elgg.config.wwwroot + "ajax/view/object/plugin/full",
162  dataType: "html",
163  cache: false,
164  data: {
165  guid: pluginGuid,
166  display_reordering: true
167  },
168  success: function(htmlData) {
169  if (htmlData.length > 0) {
170  pluginView.html(htmlData);
171  }
172  }
173  });
174  };
175 
181  function filterPluginCategory (e) {
182  e.preventDefault();
183 
184  // remove selected state from all buttons
185  $(".elgg-admin-plugins-categories > li").removeClass("elgg-state-selected");
186 
187  // show plugins with the selected category
188  $(".elgg-plugin").hide();
189  $(".elgg-plugin-category-" + $(this).attr("rel")).show();
190  $(this).closest('li').addClass("elgg-state-selected");
191  };
192 
198  function showPluginScreenshot () {
199  $(this).parent().find(".elgg-plugin-screenshot").removeClass("elgg-state-selected");
200  $(this).addClass("elgg-state-selected");
201 
202  // must use .hide/show() to work with elgg-tabs
203  $(".elgg-plugin-details-screenshots > div > img").hide();
204  $(".elgg-plugin-details-screenshots > div > img[rel='" + $(this).attr("rel") + "']").show();
205  };
206 
207  init();
208 });
elgg ajax
Wrapper function for jQuery.ajax which ensures that the url being called is relative to the elgg site...
Definition: ajax.js:19
elgg require
Throw an error if the required package isn&#39;t present.
Definition: elgglib.js:164
$CONFIG url
The full URL where Elgg is installed.
Definition: config.php:38
define(function(require){var $=require('jquery');var elgg=require('elgg');var spinner=require('elgg/spinner');var Ajax=require('elgg/Ajax');var ajax=new Ajax();function init(){initPluginReordering();$(document).on('click', '.elgg-admin-plugins-categories a', filterPluginCategory);$(document).on('click', '.elgg-plugins-toggle', toggleAllPlugins);$(document).on('click', '.elgg-plugin-state-change', toggleSinglePlugin);$(document).on('mouseenter', '.elgg-plugin-details-screenshots.elgg-plugin-screenshot', showPluginScreenshot);};function freezePlugins(){$('#elgg-plugin-list-cover').css('display', 'block');};function unfreezePlugins(){$('#elgg-plugin-list-cover').css('display', 'none');};function initPluginReordering(){$('#elgg-plugin-list > ul').sortable({items: 'li:has(>.elgg-state-draggable)', handle: '.elgg-body', forcePlaceholderSize:true, placeholder: 'elgg-plugin-placeholder', opacity:0.8, revert:500, stop:movePlugin});};function toggleSinglePlugin(e){freezePlugins();e.preventDefault();ajax.action(this.href).done(function(output, statusText, jqXHR){if(jqXHR.AjaxData.status==-1){location.reload();return;}ajax.path('admin_plugins_refresh').done(function(output){$('#elgg-plugin-list').html(output.list);$('.elgg-sidebar').html(output.sidebar);$(".elgg-admin-plugins-categories > li.elgg-state-selected > a").trigger('click');initPluginReordering();unfreezePlugins();});});};function toggleAllPlugins(e){e.preventDefault();if(!confirm(elgg.echo('question:areyousure'))){return;}freezePlugins();var guids=[], state=$(this).data('desiredState'), find_state=state== 'active'? 'inactive': 'active';$('.elgg-plugin.elgg-state-'+find_state+ ':visible').each(function(){var guid=$(this).data('guid');if(guid){guids.push(guid);}});if(!guids.length){elgg.register_error(elgg.echo('admin:plugins:already:'+state));unfreezePlugins();return;}spinner.start();var $form=$('< form method="post"/>');$form.prop('action', elgg.security.addToken(this.href));$form.append('< input type="hidden"name="guids"value="' + guids.join(',') + '"/>');$form.appendTo("body").submit();};function movePlugin(e, ui){freezePlugins();var pluginGuid=ui.item.attr('id');pluginGuid=pluginGuid.replace('elgg-object-', '');elgg.action('admin/plugins/set_priority',{data:{plugin_guid:pluginGuid, priority:ui.item.index()+1}, success:function(){var priorityDep=new RegExp(elgg.echo('ElggPlugin:Dependencies:Priority'));ui.item.siblings().andSelf().each(function(){if(priorityDep.test($(this).find('.elgg-dependency-requires').text())){updatePluginView($(this));}});unfreezePlugins();}});};function updatePluginView(pluginView){var pluginGuid=pluginView.attr('id');pluginGuid=pluginGuid.replace('elgg-object-', '');elgg.get({url:elgg.config.wwwroot+"ajax/view/object/plugin/full", dataType:"html", cache:false, data:{guid:pluginGuid, display_reordering:true}, success:function(htmlData){if(htmlData.length > 0){pluginView.html(htmlData);}}});};function filterPluginCategory(e){e.preventDefault();$(".elgg-admin-plugins-categories > li").removeClass("elgg-state-selected");$(".elgg-plugin").hide();$(".elgg-plugin-category-"+$(this).attr("rel")).show();$(this).closest('li').addClass("elgg-state-selected");};function showPluginScreenshot(){$(this).parent().find(".elgg-plugin-screenshot").removeClass("elgg-state-selected");$(this).addClass("elgg-state-selected");$(".elgg-plugin-details-screenshots > div > img").hide();$(".elgg-plugin-details-screenshots > div > img[rel='"+$(this).attr("rel")+"']").show();};init();})
$form
List all unvalidated users in the admin area.
Definition: unvalidated.php:9
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