diff options
Diffstat (limited to 'views/default/js')
-rw-r--r-- | views/default/js/admin.php | 126 | ||||
-rw-r--r-- | views/default/js/elgg.php | 77 | ||||
-rw-r--r-- | views/default/js/embed/embed.php | 171 | ||||
-rw-r--r-- | views/default/js/initialise_elgg.php | 4 | ||||
-rw-r--r-- | views/default/js/initialize_elgg.php | 52 | ||||
-rw-r--r-- | views/default/js/languages.php | 15 | ||||
-rw-r--r-- | views/default/js/languages/en.php | 2 | ||||
-rw-r--r-- | views/default/js/lightbox.php | 67 | ||||
-rw-r--r-- | views/default/js/walled_garden.php | 57 |
9 files changed, 344 insertions, 227 deletions
diff --git a/views/default/js/admin.php b/views/default/js/admin.php new file mode 100644 index 000000000..e8aa0d2ed --- /dev/null +++ b/views/default/js/admin.php @@ -0,0 +1,126 @@ +<?php +/** + * Admin-area specific javascript functions. + * + * @since 1.8 + */ + +if (0) { ?><script><?php } +?> +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); +}; + +/** + * 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 + } + }); +}; + +/** + * 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'); + } + }); +}; + +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 new file mode 100644 index 000000000..6fe03484d --- /dev/null +++ b/views/default/js/elgg.php @@ -0,0 +1,77 @@ +<?php +/** + * Core Elgg javascript loader + */ +global $CONFIG; + +$prereq_files = array( + "vendors/sprintf.js", + "js/lib/elgglib.js", +); + +foreach ($prereq_files as $file) { + include("{$CONFIG->path}$file"); +} + +//No such thing as autoloading classes in javascript +$model_files = array( + 'ElggEntity', + 'ElggUser', + 'ElggPriorityList', +); + +foreach ($model_files as $file) { + include("{$CONFIG->path}js/classes/$file.js"); +} + +//Include library files +$libs = array( + //libraries + 'prototypes', + 'hooks', + 'security', + 'languages', + 'ajax', + 'session', + 'pageowner', + 'configuration', + + //ui + 'ui', + 'ui.widgets', +); + +foreach ($libs as $file) { + include("{$CONFIG->path}js/lib/$file.js"); + // putting a new line between the files to address http://trac.elgg.org/ticket/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(); ?>'; +<?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.config.domReady = true; + elgg.initWhenReady(); +}); + +<?php + +$previous_content = elgg_view('js/initialise_elgg'); +if ($previous_content) { + elgg_deprecated_notice("The view 'js/initialise_elgg' has been deprecated for js/elgg", 1.8); + echo $previous_content; +} diff --git a/views/default/js/embed/embed.php b/views/default/js/embed/embed.php deleted file mode 100644 index ada6653a8..000000000 --- a/views/default/js/embed/embed.php +++ /dev/null @@ -1,171 +0,0 @@ -<?php -/** - * Colorbox -- Javascript - * - * Used as a view because we need to pass a full URL to AlphaImageLoader. - * - * @package Lorea - * @subpackage Colorbox - * @override mod/embed/views/default/js/embed/embed.php - * - * Copyright 2011-2012 Lorea Faeries <federation@lorea.org> - * - * This program is free software: you can redistribute it and/or - * modify it under the terms of the GNU Affero General Public License - * as published by the Free Software Foundation, either version 3 of - * the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public - * License along with this program. If not, see - * <http://www.gnu.org/licenses/>. - */ -?> - -elgg.provide('elgg.embed'); - -elgg.embed.init = function() { - - // inserts the embed content into the textarea - $(".embed-item").live('click', elgg.embed.insert); - - // caches the current textarea id - $(".embed-control").live('click', function() { - elgg.embed.textAreaId = /embed-control-(\S)+/.exec($(this).attr('class'))[1]; - }); - - // special pagination helper for lightbox - $('.embed-wrapper .elgg-pagination a').live('click', elgg.embed.forward); - - $('.embed-section').live('click', elgg.embed.forward); - - $('.elgg-form-embed').live('submit', elgg.embed.submit); -}; - -/** - * Inserts data attached to an embed list item in textarea - * - * @todo generalize lightbox closing - * - * @param {Object} event - * @return void - */ -elgg.embed.insert = function(event) { - var textAreaId = elgg.embed.textAreaId; - var textArea = $('#' + textAreaId); - - // generalize this based on a css class attached to what should be inserted - var content = ' ' + $(this).find(".embed-insert").parent().html() + ' '; - - // this is a temporary work-around for #3971 - if (content.indexOf('thumbnail.php') != -1) { - content = content.replace('size=small', 'size=medium'); - } - - textArea.val(textArea.val() + content); - textArea.focus(); - -<?php -// See the TinyMCE plugin for an example of this view -echo elgg_view('embed/custom_insert_js'); -?> - - elgg.ui.lightbox.close(); - - event.preventDefault(); -}; - -/** - * Submit an upload form through Ajax - * - * Requires the jQuery Form Plugin. Because files cannot be uploaded with - * XMLHttpRequest, the plugin uses an invisible iframe. This results in the - * the X-Requested-With header not being set. To work around this, we are - * sending the header as a POST variable and Elgg's code checks for it in - * elgg_is_xhr(). - * - * @param {Object} event - * @return bool - */ -elgg.embed.submit = function(event) { - $('.embed-wrapper .elgg-form-file-upload').hide(); - $('.embed-throbber').show(); - - $(this).ajaxSubmit({ - dataType : 'json', - data : { 'X-Requested-With' : 'XMLHttpRequest'}, - success : function(response) { - if (response) { - if (response.system_messages) { - elgg.register_error(response.system_messages.error); - elgg.system_message(response.system_messages.success); - } - if (response.status >= 0) { - var forward = $('input[name=embed_forward]').val(); - var url = elgg.normalize_url('embed/tab/' + forward); - url = elgg.embed.addContainerGUID(url); - $('.embed-wrapper').parent().load(url); - } else { - // incorrect response, presumably an error has been displayed - $('.embed-throbber').hide(); - $('.embed-wrapper .elgg-form-file-upload').show(); - } - } - - // ie 7 and 8 have a null response because of the use of an iFrame - // so just show the list after upload. - // http://jquery.malsup.com/form/#file-upload claims you can wrap JSON - // in a textarea, but a quick test didn't work, and that is fairly - // intrusive to the rest of the ajax system. - else if (response === undefined && $.browser.msie) { - var forward = $('input[name=embed_forward]').val(); - var url = elgg.normalize_url('embed/tab/' + forward); - url = elgg.embed.addContainerGUID(url); - $('.embed-wrapper').parent().load(url); - } - }, - error : function(xhr, status) { - // @todo nothing for now - } - }); - - // this was bubbling up the DOM causing a submission - event.preventDefault(); - event.stopPropagation(); -}; - -/** - * Loads content within the lightbox - * - * @param {Object} event - * @return void - */ -elgg.embed.forward = function(event) { - // make sure container guid is passed - var url = $(this).attr('href'); - url = elgg.embed.addContainerGUID(url); - - $('.embed-wrapper').parent().load(url); - event.preventDefault(); -}; - -/** - * Adds the container guid to a URL - * - * @param {string} url - * @return string - */ -elgg.embed.addContainerGUID = function(url) { - if (url.indexOf('container_guid=') == -1) { - var guid = $('input[name=embed_container_guid]').val(); - return url + '?container_guid=' + guid; - } else { - return url; - } -}; - -elgg.register_hook_handler('init', 'system', elgg.embed.init); diff --git a/views/default/js/initialise_elgg.php b/views/default/js/initialise_elgg.php new file mode 100644 index 000000000..3d617953a --- /dev/null +++ b/views/default/js/initialise_elgg.php @@ -0,0 +1,4 @@ +<?php +/** + * This has been deprecated in 1.8 - see elgg.php in this directory. + */
\ No newline at end of file diff --git a/views/default/js/initialize_elgg.php b/views/default/js/initialize_elgg.php new file mode 100644 index 000000000..b45c33463 --- /dev/null +++ b/views/default/js/initialize_elgg.php @@ -0,0 +1,52 @@ +<?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) { + $page_owner_json = array(); + foreach ($page_owner->getExportableValues() as $v) { + $page_owner_json[$v] = $page_owner->$v; + } + + $page_owner_json['subtype'] = $page_owner->getSubtype(); + $page_owner_json['url'] = $page_owner->getURL(); + + echo 'elgg.page_owner = ' . json_encode($page_owner_json) . ';'; +} + +$user = elgg_get_logged_in_user_entity(); + +if ($user instanceof ElggUser) { + $user_json = array(); + foreach ($user->getExportableValues() as $v) { + $user_json[$v] = $user->$v; + } + + $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) . ');'; +} +?> + +//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 new file mode 100644 index 000000000..c51d7bcb2 --- /dev/null +++ b/views/default/js/languages.php @@ -0,0 +1,15 @@ +<?php +/** + * @uses $vars['language'] + */ +global $CONFIG; + +$language = $vars['language']; + +$translations = $CONFIG->translations['en']; + +if ($language != 'en') { + $translations = array_merge($translations, $CONFIG->translations[$language]); +} + +echo json_encode($translations);
\ No newline at end of file diff --git a/views/default/js/languages/en.php b/views/default/js/languages/en.php new file mode 100644 index 000000000..8a604cc12 --- /dev/null +++ b/views/default/js/languages/en.php @@ -0,0 +1,2 @@ +<?php +echo elgg_view('js/languages', array('language' => 'en'));
\ No newline at end of file diff --git a/views/default/js/lightbox.php b/views/default/js/lightbox.php index 732092e2b..a1f018eea 100644 --- a/views/default/js/lightbox.php +++ b/views/default/js/lightbox.php @@ -1,34 +1,14 @@ <?php /** - * Colorbox -- Stylesheet - * - * Used as a view because we need to pass a full URL to AlphaImageLoader. - * - * @package Lorea - * @subpackage Colorbox - * - * Copyright 2011-2012 Lorea Faeries <federation@lorea.org> - * - * This program is free software: you can redistribute it and/or - * modify it under the terms of the GNU Affero General Public License - * as published by the Free Software Foundation, either version 3 of - * the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public - * License along with this program. If not, see - * <http://www.gnu.org/licenses/>. + * Elgg lightbox * * Usage - * Apply the class elgg-lightbox to links. + * 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 Colorbox jQuery library. Please go to - * http://www.jacklmoore.com/colorbox for more information on the options of this lightbox. + * 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 @@ -37,45 +17,20 @@ * @todo add support for passing options: $('#myplugin-lightbox').elgg.ui.lightbox(options); */ +if (0) { ?><script><?php } ?> /** * Lightbox initialization */ - -elgg.provide('elgg.ui.lightbox'); - -elgg.ui.lightbox.init = function() { - - $.extend($.colorbox.settings, { - current: elgg.echo('js:lightbox:current', ['{current}', '{total}']), - previous: elgg.echo('previous'), - next: elgg.echo('next'), - close: elgg.echo('close'), - xhrError: elgg.echo('error:default'), - imgError: elgg.echo('error:default'), - }); - - $(".elgg-lightbox").colorbox(); - $(".elgg-lightbox-photo").colorbox({photo: true}); - var n = 0; - $(".elgg-lightbox-gallery").each(function() { - $(this).find(".elgg-lightbox, .elgg-lightbox-photo") - .addClass("elgg-lightbox-" + n) - .colorbox({ - rel: "elgg-lightbox-" + n++, - }); - }); -} - -elgg.ui.lightbox.close = function() { - $.colorbox.close(); +elgg.ui.lightbox_init = function() { + $(".elgg-lightbox").fancybox(); } -elgg.register_hook_handler('init', 'system', elgg.ui.lightbox.init); +elgg.register_hook_handler('init', 'system', elgg.ui.lightbox_init); <?php -$js_path = elgg_get_plugins_path(); -$js_path = "{$js_path}colorbox/vendors/jquery/colorbox/colorbox/jquery.colorbox-min.js"; +$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..7a482fe23 --- /dev/null +++ b/views/default/js/walled_garden.php @@ -0,0 +1,57 @@ +<?php +/** + * Walled garden JavaScript + * + * @since 1.8 + */ + +// note that this assumes the button view is not using single quotes +$cancel_button = elgg_view('input/button', array( + 'value' => elgg_echo('cancel'), + 'class' => 'elgg-button-cancel mlm', +)); +$cancel_button = trim($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) { + if ($('.elgg-walledgarden-single').is(':visible')) { + $('.elgg-walledgarden-double').fadeToggle(); + $('.elgg-walledgarden-single').fadeToggle(); + $('.elgg-walledgarden-single').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('_', '-'); + elgg.get('walled_garden/' + view, { + 'success' : function(data) { + $('.elgg-body-walledgarden').append(data); + $(id).find('input.elgg-button-submit').after('<?php echo $cancel_button; ?>'); + $('#elgg-walledgarden-login').fadeToggle(); + $(id).fadeToggle(); + } + }); + event.preventDefault(); + }; +}; + +elgg.register_hook_handler('init', 'system', elgg.walled_garden.init);
\ No newline at end of file |