diff options
Diffstat (limited to 'views/default/js')
| -rw-r--r-- | views/default/js/admin.php | 101 | ||||
| -rw-r--r-- | views/default/js/elgg.php | 20 | ||||
| -rw-r--r-- | views/default/js/initialize_elgg.php | 15 | ||||
| -rw-r--r-- | views/default/js/languages.php | 28 | ||||
| -rw-r--r-- | views/default/js/lightbox.php | 36 | ||||
| -rw-r--r-- | views/default/js/walled_garden.php | 67 |
6 files changed, 193 insertions, 74 deletions
diff --git a/views/default/js/admin.php b/views/default/js/admin.php index 603d0f066..e8aa0d2ed 100644 --- a/views/default/js/admin.php +++ b/views/default/js/admin.php @@ -4,23 +4,24 @@ * * @since 1.8 */ + +if (0) { ?><script><?php } ?> elgg.provide('elgg.admin'); elgg.admin.init = function () { - // display manifest info - <?php //@todo Use elgg-toggler pattern ?> - $('a.manifest_details.link').click(function() { - elgg_slide_toggle($(this), '.elgg-plugin', '.manifest_file'); - }); - // plugin screenshot modal - $('.elgg-plugin-screenshot a').click(elgg.admin.displayPluginScreenshot); + // 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').sortable({ - items: 'div.elgg-state-draggable', - handle: 'h3.elgg-head', + $('#elgg-plugin-list > ul').sortable({ + items: 'li:has(> .elgg-state-draggable)', + handle: '.elgg-head', forcePlaceholderSize: true, placeholder: 'elgg-widget-placeholder', opacity: 0.8, @@ -29,6 +30,7 @@ elgg.admin.init = function () { }); // in-line editing for custom profile fields. + // @note this requires jquery.jeditable plugin $(".elgg-state-editable").editable(elgg.admin.editProfileField, { type: 'text', onblur: 'submit', @@ -38,12 +40,15 @@ elgg.admin.init = function () { }); // draggable profile field reordering. - $('#sortable_profile_fields').sortable({ + $('#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); +}; /** * Save the plugin order after a move event. @@ -53,9 +58,9 @@ elgg.admin.init = function () { * @return void */ elgg.admin.movePlugin = function(e, ui) { - // get guid from id like elgg-plugin-<guid> - var pluginGuid = ui.item.closest('.elgg-plugin').attr('id'); - pluginGuid = pluginGuid.replace('elgg-plugin-', ''); + // 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: { @@ -67,48 +72,6 @@ elgg.admin.movePlugin = function(e, ui) { }; /** - * Display a plugin screenshot. - * - * @param {Object} e The event object. - * @return void - */ -elgg.admin.displayPluginScreenshot = function(e) { - e.preventDefault(); - var lb = $('.elgg-plugin-screenshot-lightbox'); - - if (lb.length < 1) { - $('body').append('<div class="elgg-plugin-screenshot-lightbox"></div>'); - lb = $('.elgg-plugin-screenshot-lightbox'); - - lb.click(function() { - lb.hide(); - }); - - $(document).click(function(e) { - var target = $(e.target); - if (target.is('a') && target.hasClass('elgg-plugin-screenshot-lightbox')) { - lb.hide(); - e.preventDefault(); - } - }); - } - - var html = '<img class="pas" src="' + $(this).attr('href') + '">'; - var desc = $(this).find('img').attr('alt'); - - if (desc) { - html = '<h2 class="pam">' + desc + '</h2>' + html; - } - - lb.html(html); - - top_pos = $(window).scrollTop() + 10 + 'px'; - left_pos = $(window).scrollLeft() + 5 + 'px'; - - lb.css('top', top_pos).css('left', left_pos).show(); -}; - -/** * In-line editing for custom profile fields * * @param string value The new value @@ -126,7 +89,7 @@ elgg.admin.editProfileField = function(value, settings) { elgg.action('profile/fields/edit', data); return value; -} +}; /** * Save the plugin profile order after a move event. @@ -136,12 +99,28 @@ elgg.admin.editProfileField = function(value, settings) { * @return void */ elgg.admin.moveProfileField = function(e, ui) { - var orderArr = $('#sortable_profile_fields').sortable('toArray'); + 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'); + } + }); +}; -elgg.register_event_handler('init', 'system', elgg.admin.init);
\ No newline at end of file +elgg.register_hook_handler('init', 'system', elgg.admin.init, 1000);
\ No newline at end of file diff --git a/views/default/js/elgg.php b/views/default/js/elgg.php index 16c8ff20c..c3b56e398 100644 --- a/views/default/js/elgg.php +++ b/views/default/js/elgg.php @@ -28,12 +28,13 @@ foreach ($model_files as $file) { $libs = array( //libraries 'prototypes', - 'events', + 'hooks', 'security', 'languages', 'ajax', 'session', 'pageowner', + 'configuration', //ui 'ui', @@ -42,26 +43,29 @@ $libs = array( foreach ($libs as $file) { include("{$CONFIG->path}js/lib/$file.js"); + // putting a new line between the files to address https://github.com/elgg/elgg/issues/3081 + echo "\n"; } /** * Set some values that are cacheable */ +if (0) { ?><script><?php } ?> elgg.version = '<?php echo get_version(); ?>'; elgg.release = '<?php echo get_version(true); ?>'; elgg.config.wwwroot = '<?php echo elgg_get_site_url(); ?>'; -elgg.security.interval = 5 * 60 * 1000; <?php //@todo make this configurable ?> - -//Mimic PHP engine boot process - -//Before the DOM is ready -- note that plugins aren't loaded yet -elgg.trigger_event('boot', 'system'); +<?php //@todo make this configurable ?> +elgg.security.interval = 5 * 60 * 1000; +elgg.config.domReady = false; +elgg.config.language = '<?php echo isset($CONFIG->language) ? $CONFIG->language : 'en'; ?>'; +elgg.config.languageReady = false; //After the DOM is ready $(function() { - elgg.trigger_event('init', 'system'); + elgg.config.domReady = true; + elgg.initWhenReady(); }); <?php diff --git a/views/default/js/initialize_elgg.php b/views/default/js/initialize_elgg.php index 9032d8a63..b45c33463 100644 --- a/views/default/js/initialize_elgg.php +++ b/views/default/js/initialize_elgg.php @@ -1,18 +1,23 @@ <?php /** - * + * Initialize Elgg's js lib with the uncacheable data */ +if (0) { ?><script><?php } ?> /** * Don't want to cache these -- they could change for every request */ elgg.config.lastcache = <?php echo (int)elgg_get_config('lastcache'); ?>; +elgg.config.viewtype = '<?php echo elgg_get_viewtype(); ?>'; +elgg.config.simplecache_enabled = <?php echo (int)elgg_is_simplecache_enabled(); ?>; elgg.security.token.__elgg_ts = <?php echo $ts = time(); ?>; elgg.security.token.__elgg_token = '<?php echo generate_action_token($ts); ?>'; <?php +// @todo json export should be smoother than this... +// @todo Might also be nice to make url exportable. $entity->url? yes please! $page_owner = elgg_get_page_owner_entity(); if ($page_owner instanceof ElggEntity) { @@ -24,7 +29,7 @@ if ($page_owner instanceof ElggEntity) { $page_owner_json['subtype'] = $page_owner->getSubtype(); $page_owner_json['url'] = $page_owner->getURL(); - echo 'elgg.page_owner = '.json_encode($page_owner_json).';'; + echo 'elgg.page_owner = ' . json_encode($page_owner_json) . ';'; } $user = elgg_get_logged_in_user_entity(); @@ -37,7 +42,11 @@ if ($user instanceof ElggUser) { $user_json['subtype'] = $user->getSubtype(); $user_json['url'] = $user->getURL(); + $user_json['admin'] = $user->isAdmin(); - echo 'elgg.session.user = new elgg.ElggUser('.json_encode($user_json).');'; + echo 'elgg.session.user = new elgg.ElggUser(' . json_encode($user_json) . ');'; } ?> + +//Before the DOM is ready, but elgg's js framework is fully initalized +elgg.trigger_hook('boot', 'system');
\ No newline at end of file diff --git a/views/default/js/languages.php b/views/default/js/languages.php index 009e8159c..fcf903d4b 100644 --- a/views/default/js/languages.php +++ b/views/default/js/languages.php @@ -1,9 +1,33 @@ <?php /** * @uses $vars['language'] + * @uses $vars['lc'] if present, client will be sent long expires headers */ -global $CONFIG; $language = $vars['language']; +$lastcache = elgg_extract('lc', $vars, 0); -echo json_encode($CONFIG->translations[$language]);
\ No newline at end of file +// @todo add server-side caching +if ($lastcache) { + // we're relying on lastcache changes to predict language changes + $etag = '"' . md5("$language|$lastcache") . '"'; + + header('Expires: ' . gmdate('D, d M Y H:i:s \G\M\T', strtotime("+6 months")), true); + header("Pragma: public", true); + header("Cache-Control: public", true); + header("ETag: $etag"); + + if (isset($_SERVER['HTTP_IF_NONE_MATCH']) && trim($_SERVER['HTTP_IF_NONE_MATCH']) === $etag) { + header("HTTP/1.1 304 Not Modified"); + exit; + } +} + +$all_translations = elgg_get_config('translations'); +$translations = $all_translations['en']; + +if ($language != 'en') { + $translations = array_merge($translations, $all_translations[$language]); +} + +echo json_encode($translations);
\ No newline at end of file diff --git a/views/default/js/lightbox.php b/views/default/js/lightbox.php new file mode 100644 index 000000000..a1f018eea --- /dev/null +++ b/views/default/js/lightbox.php @@ -0,0 +1,36 @@ +<?php +/** + * Elgg lightbox + * + * Usage + * Call elgg_load_js('lightbox') and elgg_load_css('lightbox') then + * apply the class elgg-lightbox to links. + * + * Advanced Usage + * Elgg is distributed with the Fancybox jQuery library. Please go to + * http://fancybox.net for more information on the options of this lightbox. + * + * Overriding + * In a plugin, override this view and override the registration for the + * lightbox JavaScript and CSS (@see elgg_views_boot()). + * + * @todo add support for passing options: $('#myplugin-lightbox').elgg.ui.lightbox(options); + */ + +if (0) { ?><script><?php } +?> + +/** + * Lightbox initialization + */ +elgg.ui.lightbox_init = function() { + $(".elgg-lightbox").fancybox(); +} + +elgg.register_hook_handler('init', 'system', elgg.ui.lightbox_init); + +<?php + +$js_path = elgg_get_config('path'); +$js_path = "{$js_path}vendors/jquery/fancybox/jquery.fancybox-1.3.4.pack.js"; +include $js_path; diff --git a/views/default/js/walled_garden.php b/views/default/js/walled_garden.php new file mode 100644 index 000000000..e228df507 --- /dev/null +++ b/views/default/js/walled_garden.php @@ -0,0 +1,67 @@ +<?php +/** + * Walled garden JavaScript + * + * @since 1.8 + */ + +$cancel_button = elgg_view('input/button', array( + 'value' => elgg_echo('cancel'), + 'class' => 'elgg-button-cancel mlm', +)); +$cancel_button = json_encode($cancel_button); + +if (0) { ?><script><?php } +?> + +elgg.provide('elgg.walled_garden'); + +elgg.walled_garden.init = function () { + + $('.forgot_link').click(elgg.walled_garden.load('lost_password')); + $('.registration_link').click(elgg.walled_garden.load('register')); + + $('input.elgg-button-cancel').live('click', function(event) { + var $wgs = $('.elgg-walledgarden-single'); + if ($wgs.is(':visible')) { + $('.elgg-walledgarden-double').fadeToggle(); + $wgs.fadeToggle(); + $wgs.remove(); + } + event.preventDefault(); + }); +}; + +/** + * Creates a closure for loading walled garden content through ajax + * + * @param {String} view Name of the walled garden view + * @return {Object} + */ +elgg.walled_garden.load = function(view) { + return function(event) { + var id = '#elgg-walledgarden-' + view; + id = id.replace('_', '-'); + //@todo display some visual element that indicates that loading of content is running + elgg.get('walled_garden/' + view, { + 'success' : function(data) { + var $wg = $('.elgg-body-walledgarden'); + $wg.append(data); + $(id).find('input.elgg-button-submit').after(<?php echo $cancel_button; ?>); + + if (view == 'register' && $wg.hasClass('hidden')) { + // this was a failed register, display the register form ASAP + $('#elgg-walledgarden-login').toggle(false); + $(id).toggle(); + $wg.removeClass('hidden'); + } else { + $('#elgg-walledgarden-login').fadeToggle(); + $(id).fadeToggle(); + } + } + }); + event.preventDefault(); + }; +}; + +elgg.register_hook_handler('init', 'system', elgg.walled_garden.init);
\ No newline at end of file |
