Permalink
Browse files

feature(javascript): admin panel javascript is now loaded asynchronously

BREAKING CHANGE:
The view js/admin and the namespace elgg.admin are not available anymore.
  • Loading branch information...
juho-jaakkola committed Jun 8, 2015
1 parent ab3c879 commit 7141da5fe2038baa6eb5e38faad479da935f44eb
Showing with 187 additions and 188 deletions.
  1. +1 −1 engine/lib/admin.php
  2. +0 −187 views/default/js/admin.php
  3. +186 −0 views/default/js/elgg/admin.js
View
@@ -509,7 +509,7 @@ function _elgg_admin_page_handler($page) {
elgg_set_context('admin');
elgg_unregister_css('elgg');
- elgg_load_js('elgg.admin');
+ elgg_require_js('elgg/admin');
elgg_load_js('jquery.jeditable');
// default to dashboard
View
@@ -1,187 +0,0 @@
-<?php
-/**
- * Admin-area specific javascript functions.
- *
- * @since 1.8
- */
-
-?>
-//<script>
-elgg.provide('elgg.admin');
-
-elgg.admin.init = function () {
-
- // system messages do not fade in admin area, instead slide up when clicked
- $('.elgg-system-messages li').stop(true);
- $('.elgg-system-messages li').die('click');
- $('.elgg-system-messages li').live('click', function() {
- $(this).stop().slideUp('medium');
- });
-
- // draggable plugin reordering
- $('#elgg-plugin-list > ul').sortable({
- items: 'li:has(> .elgg-state-draggable)',
- handle: '.elgg-head',
- forcePlaceholderSize: true,
- placeholder: 'elgg-widget-placeholder',
- opacity: 0.8,
- revert: 500,
- stop: elgg.admin.movePlugin
- });
-
- // in-line editing for custom profile fields.
- // @note this requires jquery.jeditable plugin
- $(".elgg-state-editable").editable(elgg.admin.editProfileField, {
- type: 'text',
- onblur: 'submit',
- width: '300px',
- height: 'none',
- style: 'display:inline;'
- });
-
- // draggable profile field reordering.
- $('#elgg-profile-fields').sortable({
- items: 'li',
- handle: 'span.elgg-state-draggable',
- stop: elgg.admin.moveProfileField
- });
-
- // admin notices delete ajax
- $('a.elgg-admin-notice').click(elgg.admin.deleteNotice);
-
- // disable checkboxes (readonly does not work for them)
- $('input:checkbox.elgg-state-disabled, label.elgg-state-disabled > input:checkbox')
- .live('click', function() {return false;});
-
- // disable simple cache compress settings if simple cache is off
- $('[name=simplecache_enabled]').click(elgg.admin.simplecacheToggle);
-};
-
-/**
- * Save the plugin order after a move event.
- *
- * @param {Object} e Event object.
- * @param {Object} ui jQueryUI object
- * @return void
- */
-elgg.admin.movePlugin = function(e, ui) {
- // get guid from id like elgg-object-<guid>
- var pluginGuid = ui.item.attr('id');
- pluginGuid = pluginGuid.replace('elgg-object-', '');
-
- elgg.action('admin/plugins/set_priority', {
- data: {
- plugin_guid: pluginGuid,
- // we start at priority 1
- priority: ui.item.index() + 1
- },
- success: function() {
- // update plugins with priority dependences
- var priorityDep = new RegExp(elgg.echo('ElggPlugin:Dependencies:Priority'));
- ui.item.siblings().andSelf().each(function() {
- if (priorityDep.test($(this).find('.elgg-dependency-requires').text())) {
- elgg.admin.updatePluginView($(this));
- }
- });
- }
- });
-};
-
-/**
- * Update the plugin view.
- *
- * @param {Object} pluginView Plugin view element to update
- * @return void
- */
-elgg.admin.updatePluginView = function(pluginView) {
- // get guid from id like elgg-object-<guid>
- 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);
- }
- }
- });
-}
-
-/**
- * In-line editing for custom profile fields
- *
- * @param string value The new value
- * @param {Object} settings The settings used for editable
- * @return void
- */
-elgg.admin.editProfileField = function(value, settings) {
- var id = $(this).attr('id');
- id = id.replace('elgg-profile-field-', '');
-
- var data = {
- id: id,
- label: value
- };
-
- elgg.action('profile/fields/edit', data);
- return value;
-};
-
-/**
- * Save the plugin profile order after a move event.
- *
- * @param {Object} e Event object.
- * @param {Object} ui jQueryUI object
- * @return void
- */
-elgg.admin.moveProfileField = function(e, ui) {
- var orderArr = $('#elgg-profile-fields').sortable('toArray');
- var orderStr = orderArr.join(',');
-
- elgg.action('profile/fields/reorder', {
- fieldorder: orderStr
- });
-};
-
-/**
- * Fires the ajax action to delete the admin notice then hides the notice.
- *
- * @return void
- */
-elgg.admin.deleteNotice = function(e) {
- e.preventDefault();
- var $container = $(this).closest('p');
-
- elgg.action($(this).attr('href'), {
- success: function(json) {
- $container.slideUp('medium');
- }
- });
-};
-
-/**
- * Toggles the display of the compression settings for simplecache
- *
- * @return void
- */
-elgg.admin.simplecacheToggle = function() {
- // when the checkbox is disabled, do not toggle the compression checkboxes
- if (!$(this).hasClass('elgg-state-disabled')) {
- var names = ['simplecache_minify_js', 'simplecache_minify_css'];
- for (var i = 0; i < names.length; i++) {
- var $input = $('input[type!=hidden][name="' + names[i] + '"]');
- if ($input.length) {
- $input.parent().toggleClass('elgg-state-disabled');
- }
- }
- }
-};
-
-elgg.register_hook_handler('init', 'system', elgg.admin.init, 1000);
@@ -0,0 +1,186 @@
+/**
+ * Admin-area specific javascript functions.
+ *
+ * @since 1.8
+ */
+define(function(require) {
+ var $ = require('jquery');
+ var ui = require('jquery-ui');
+ var elgg = require('elgg');
+
+ function init () {
+ // system messages do not fade in admin area, instead slide up when clicked
+ $('.elgg-system-messages li').stop(true);
+ $('.elgg-system-messages li').die('click');
+ $('.elgg-system-messages li').live('click', function() {
+ $(this).stop().slideUp('medium');
+ });
+
+ // draggable plugin reordering
+ $('#elgg-plugin-list > ul').sortable({
+ items: 'li:has(> .elgg-state-draggable)',
+ handle: '.elgg-head',
+ forcePlaceholderSize: true,
+ placeholder: 'elgg-widget-placeholder',
+ opacity: 0.8,
+ revert: 500,
+ stop: movePlugin
+ });
+
+ // in-line editing for custom profile fields.
+ // @note this requires jquery.jeditable plugin
+ $(".elgg-state-editable").editable(editProfileField, {
+ type: 'text',
+ onblur: 'submit',
+ width: '300px',
+ height: 'none',
+ style: 'display:inline;'
+ });
+
+ // draggable profile field reordering.
+ $('#elgg-profile-fields').sortable({
+ items: 'li',
+ handle: 'span.elgg-state-draggable',
+ stop: moveProfileField
+ });
+
+ // admin notices delete ajax
+ $('a.elgg-admin-notice').click(deleteNotice);
+
+ // disable checkboxes (readonly does not work for them)
+ $('input:checkbox.elgg-state-disabled, label.elgg-state-disabled > input:checkbox')
+ .live('click', function() {return false;});
+
+ // disable simple cache compress settings if simple cache is off
+ $('[name=simplecache_enabled]').click(simplecacheToggle);
+ };
+
+ /**
+ * Save the plugin order after a move event.
+ *
+ * @param {Object} e Event object.
+ * @param {Object} ui jQueryUI object
+ * @return void
+ */
+ function movePlugin (e, ui) {
+ // get guid from id like elgg-object-<guid>
+ var pluginGuid = ui.item.attr('id');
+ pluginGuid = pluginGuid.replace('elgg-object-', '');
+
+ elgg.action('admin/plugins/set_priority', {
+ data: {
+ plugin_guid: pluginGuid,
+ // we start at priority 1
+ priority: ui.item.index() + 1
+ },
+ success: function() {
+ // update plugins with priority dependences
+ 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));
+ }
+ });
+ }
+ });
+ };
+
+ /**
+ * Update the plugin view.
+ *
+ * @param {Object} pluginView Plugin view element to update
+ * @return void
+ */
+ function updatePluginView (pluginView) {
+ // get guid from id like elgg-object-<guid>
+ 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);
+ }
+ }
+ });
+ };
+
+ /**
+ * In-line editing for custom profile fields
+ *
+ * @param string value The new value
+ * @param {Object} settings The settings used for editable
+ * @return void
+ */
+ function editProfileField (value, settings) {
+ var id = $(this).attr('id');
+ id = id.replace('elgg-profile-field-', '');
+
+ var data = {
+ id: id,
+ label: value
+ };
+
+ elgg.action('profile/fields/edit', data);
+ return value;
+ };
+
+ /**
+ * Save the plugin profile order after a move event.
+ *
+ * @param {Object} e Event object.
+ * @param {Object} ui jQueryUI object
+ * @return void
+ */
+ function moveProfileField (e, ui) {
+ var orderArr = $('#elgg-profile-fields').sortable('toArray');
+ var orderStr = orderArr.join(',');
+
+ elgg.action('profile/fields/reorder', {
+ fieldorder: orderStr
+ });
+ };
+
+ /**
+ * Fires the ajax action to delete the admin notice then hides the notice.
+ *
+ * @return void
+ */
+ function deleteNotice (e) {
+ e.preventDefault();
+ var $container = $(this).closest('p');
+
+ elgg.action($(this).attr('href'), {
+ success: function(json) {
+ $container.slideUp('medium');
+ }
+ });
+ };
+
+ /**
+ * Toggles the display of the compression settings for simplecache
+ *
+ * @return void
+ */
+ function simplecacheToggle () {
+ // when the checkbox is disabled, do not toggle the compression checkboxes
+ if (!$(this).hasClass('elgg-state-disabled')) {
+ var names = ['simplecache_minify_js', 'simplecache_minify_css'];
+ for (var i = 0; i < names.length; i++) {
+ var $input = $('input[type!=hidden][name="' + names[i] + '"]');
+ if ($input.length) {
+ $input.parent().toggleClass('elgg-state-disabled');
+ }
+ }
+ }
+ };
+
+ init();
+});

0 comments on commit 7141da5

Please sign in to comment.