it("triggers handlers registered with 'all'", function() { elgg.register_hook_handler('all', 'bar', elgg.abstractMethod); expect(function() { elgg.trigger_hook('foo', 'bar'); }).toThrow(); elgg.register_hook_handler('foo', 'all', elgg.abstractMethod); expect(function() { elgg.trigger_hook('foo', 'baz'); }).toThrow(); elgg.register_hook_handler('all', 'all', elgg.abstractMethod); expect(function() { elgg.trigger_hook('pinky', 'winky'); }).toThrow(); });
it("allows filtering response wrapper by hook, called only once", function(done) { response_object = { value: 1, foo: 2 }; var hook_calls = 0; elgg.register_hook_handler(Ajax.RESPONSE_DATA_HOOK, 'path:foo', function (h, t, p, v) { hook_calls++; expect(v).toEqual({value: 1, foo: 2}); expect(p.options.url).toBe('foo'); v.value = 3; return v; }); var def1 = $.Deferred(), def2 = $.Deferred(); ajax.path('foo', { success: function (val) { expect(val).toBe(3); def1.resolve(); } }).done(function (val) { expect(val).toBe(3); def2.resolve(); }); $.when(def1, def2).then(function () { expect(hook_calls).toBe(1); done(); }); });
beforeEach(function() { ajax_tmp = $.ajax; response_object = {value: null}; captured_hook = null; $.ajax = function(options) { captured_options = options; var def = $.Deferred(); setTimeout(function () { if ($.isFunction(options.success)) { options.success(response_object); } def.resolve(response_object); }, 1); return def; }; elgg.config.hooks = {}; Ajax._init_hooks(); // note, "all" type > always higher priority than specific types elgg.register_hook_handler(Ajax.REQUEST_DATA_HOOK, 'all', function (h, t, p, v) { captured_hook = { t: t, p: p, v: v }; }); });
define('boot/example', function(require) { var elgg = require('elgg'); var Plugin = require('elgg/Plugin'); elgg._test_signals.push('boot/example define'); elgg.register_hook_handler('init', 'system', function() { elgg._test_signals.push('boot/example init,system'); }); elgg.register_hook_handler('ready', 'system', function() { elgg._test_signals.push('boot/example ready,system'); }); return new Plugin({ init: function () { elgg._test_signals.push('boot/example init'); } }); });
UserPicker.setup = function(selector) { elgg.register_hook_handler('init', 'system', function () { $(selector).each(function () { // we only want to wrap each picker once if (!$(this).data('initialized')) { new UserPicker(this); $(this).data('initialized', 1); } }); }); };
registerHandlers: function () { elgg.register_hook_handler('prepare', 'ckeditor', function (hook, type, params, CKEDITOR) { CKEDITOR.plugins.addExternal('blockimagepaste', elgg.get_simplecache_url('elgg/ckeditor/blockimagepaste.js'), ''); CKEDITOR.on('instanceReady', elggCKEditor.fixImageAttributes); return CKEDITOR; }); elgg.register_hook_handler('embed', 'editor', function (hook, type, params, value) { var textArea = $('#' + params.textAreaId); var content = params.content; if ($.fn.ckeditorGet) { try { var editor = textArea.ckeditorGet(); editor.insertHtml(content); return false; } catch (e) { // do nothing. } } }); elggCKEditor.registerHandlers = elgg.nullFunction; },
define(function (require) { var $ = require('jquery'); var elgg = require('elgg'); var Ajax = require('elgg/Ajax'); var ajax = new Ajax(); /** * @see \Elgg\Likes\JsConfigHandler */ var STATES = elgg.data.likes_states; function update_like_menu_item(guid, menu_item) { $('.elgg-menu-item-likes > a[data-likes-guid=' + guid + ']').replaceWith(menu_item); } function set_counts(guid, num_likes, new_value) { var li_modifier = num_likes > 0 ? 'removeClass' : 'addClass'; $('.elgg-menu-item-likes-count > a[data-likes-guid=' + guid + ']').each(function () { $(this) .replaceWith(new_value) .parent()[li_modifier]('hidden'); }); } $(document).on('click', '.elgg-menu-item-likes a', function () { // warning: data is "live" and reflects changes from set_liked_state() var data = $(this).data(), guid = data.likesGuid, current_state = data.likesState; ajax.action(STATES[current_state].action, { data: {guid: guid} }); return false; }); // Any Ajax operation can return likes data elgg.register_hook_handler(Ajax.RESPONSE_DATA_HOOK, 'all', function (hook, type, params, value) { if (value.likes_status) { var status = value.likes_status; update_like_menu_item(status.guid, status.like_menu_item); set_counts(status.guid, status.count, status.count_menu_item); } }); });
it("allows altering value via hook", function() { elgg.register_hook_handler(Ajax.REQUEST_DATA_HOOK, 'path:foo/bar', function (h, t, p, v) { v.arg3 = 3; return v; }, 900); ajax.path('/foo/bar/?arg1=1#target', { data: {arg2: 2} }); expect(captured_options.data).toEqual({ arg2: 2, arg3: 3 }); expect(captured_hook.v).toEqual({arg2: 2, arg3: 3}); expect(captured_hook.p.options.data).toEqual({arg2: 2, arg3: 3}); });
init: function () { // we only need to bind these events once embed.init = elgg.nullFunction; // inserts the embed content into the textarea $(document).on('click', ".embed-item", embed.insert); if (typeof elgg.embed._deprecated_custom_insert_js === 'function') { elgg.register_hook_handler('embed', 'editor', elgg.embed._deprecated_custom_insert_js); } // caches the current textarea id $(document).on('click', ".embed-control", function () { var textAreaId = /embed-control-(\S)+/.exec($(this).attr('class'))[0]; embed.textAreaId = textAreaId.substr("embed-control-".length); }); // special pagination helper for lightbox $(document).on('click', '.embed-wrapper .elgg-pagination a', embed.forward); $(document).on('click', '.embed-section', embed.forward); $(document).on('submit', '.elgg-form-embed', embed.submit); },
define(function(require) { var $ = require('jquery'); var elgg = require('elgg'); require('chosen/chosen.jquery'); var init = function() { $('form#plugin_search_form select.multiselect').chosen(); // "Clear search" button loads search page without parameters $(document).on('click', 'form#plugin_search_form .elgg-button-cancel', function() { window.location.href = elgg.get_site_url() + "plugins/search"; }); }; elgg.register_hook_handler('init', 'system', init); return { init: init }; });
define(function (require) { var elgg = require("elgg"); var $ = require("jquery"); require('jquery.form'); /** * Repositions the feedback wrapper popup */ function popupHandler(hook, type, params, options) { if (!params.source.is('.feedback-toggler-fixed')) { // only do this for fixed element return; } options.my = 'left top'; options.at = 'left top'; options.collision = 'fit fit'; return options; } elgg.register_hook_handler('getOptions', 'ui.popup', popupHandler); });
MultiSelect.init = function(selector) { elgg.register_hook_handler("init", "system", function () { $(selector).each(function () { // we only want to wrap once if (!$(this).data("multiSelectInitialized")) { $(this) .multiselect({ header: false, appendTo: "body", selectedList: 1, noneSelectedText: elgg.echo('profile_manager:input:multi_select:empty_text'), selectedText: elgg.echo('profile_manager:input:multi_select:selected_text') }) .multiselect('getButton') .find('.ui-icon') .addClass('elgg-icon elgg-icon-caret-down fa fa-caret-down'); $(this).data("multiSelectInitialized", 1); } }); }); };
define('elgg/uservalidationbyemail', function (require) { var $ = require('jquery'); var elgg = require('elgg'); function init() { $('#uservalidationbyemail-checkall').click(function() { $('#uservalidationbyemail-form .elgg-body').find('input[type=checkbox]').prop('checked', this.checked); }); $('.uservalidationbyemail-submit').click(function(event) { var form = $('#uservalidationbyemail-form')[0]; event.preventDefault(); // check if there are selected users if ($('.elgg-body', form).find('input[type=checkbox]:checked').length < 1) { return false; } // confirmation if (!confirm(this.title)) { return false; } form.action = this.href; form.submit(); }); } elgg.register_hook_handler('init', 'system', init); /** * elgg.uservalidationbyemail object is deprecated. Do not call it directly. * @deprecated 2.3 */ elgg.uservalidationbyemail = { init: init }; });
define(function(require) { var $ = require('jquery'); var elgg = require('elgg'); /** * Repositions the notifier popup * * @param {String} hook 'getOptions' * @param {String} type 'ui.popup' * @param {Object} params An array of info about the target and source. * @param {Object} options Options to pass to * * @return {Object} */ function popupHandler(hook, type, params, options) { if (!params.target.hasClass('elgg-notifier-popup')) { return; } // Due to elgg.ui.popup's design, there's no way to verify in a click handler whether the // click will actually be closing the popup after this hook. This is the only chance to verify // whether the popup is visible or not. if (params.target.is(':visible')) { // user clicked the icon to close, we're just letting it close return; } populatePopup(); options.my = 'left top'; options.at = 'left bottom'; options.collision = 'fit none'; return options; } /** * Dismiss all unread notifications and then hide related UI elements. * * @return void */ function dismissAll() { // start delete on server but don't block elgg.action(this.href); // Hide notification count from topbar icon $('#notifier-new').addClass('hidden').html(''); // Remove highlighting from the unread notifications one by one function dismiss() { var $unread = $('.elgg-notifier-unread:first'); if ($unread.length) { $unread.removeClass('elgg-notifier-unread'); } else { clearInterval(dismissing); // close popup $('body').trigger('click'); } } var dismissing = setInterval(dismiss, 100); dismiss(); // Hide the "Dismiss all" button $('#notifier-dismiss-all').addClass('hidden'); return false; } /** * Fetch notifications and display them in the popup module. * * @return void */ function populatePopup() { $('#notifier-popup > .elgg-body > ul').html('<li><div class="elgg-ajax-loader mtm mbm"></div></li>'); elgg.get('notifier/popup', { success: function(output) { if (output) { // Add the received <li> elements into the list $('#notifier-popup > .elgg-body > ul').html(output); // Hide the "No notifications" texts $('.notifier-none').addClass('hidden'); // Display the "View all" link $('#notifier-view-all').removeClass('hidden'); // Check if there are unread notifications if ($('.elgg-notifier-unread').length) { // Display the "Dismiss all" icon $('#notifier-dismiss-all').removeClass('hidden'); } // Check if there are links that trigger a lightbox $('#notifier-popup .elgg-lightbox').each(function() { // Bind lightbox to the new links elgg.ui.lightbox.bind(".elgg-lightbox"); return false; }); } else { // remove the spinner $('#notifier-popup > .elgg-body > ul').html(''); // Hide the "Dismiss all" icon & the "View all" link $('#notifier-dismiss-all, #notifier-view-all').addClass('hidden'); // Display the "No notifications" text $('.notifier-none').removeClass('hidden'); } } }); } /** * Dismiss single notification on click * @returns {void} */ function dismissOne() { var id = $(this).closest('.elgg-item-object-notification').attr('id'); var guid = id.substr(id.indexOf('elgg-object-') + "elgg-object-".length); elgg.action('action/notifier/dismiss_one', { data: { guid: guid, } }); }; $('#notifier-dismiss-all').on('click', dismissAll); $(document).on('click', '.elgg-item-object-notification:has(.elgg-notifier-unread) a', dismissOne); elgg.register_hook_handler('getOptions', 'ui.popup', popupHandler); });
require(['elgg/ready'], function () { elgg.register_hook_handler('init', 'system', walled_garden.init); });
define('elgg/likes', function (require) { var $ = require('jquery'); var elgg = require('elgg'); elgg.provide('elgg.ui'); /** * Repositions the likes popup * * @param {String} hook 'getOptions' * @param {String} type 'ui.popup' * @param {Object} params An array of info about the target and source. * @param {Object} options Options to pass to * * @return {Object} * @deprecated 2.3 Do not call this directly */ elgg.ui.likesPopupHandler = function(hook, type, params, options) { if (params.target.hasClass('elgg-likes')) { options.my = 'right bottom'; options.at = 'left top'; return options; } return null; }; elgg.register_hook_handler('getOptions', 'ui.popup', elgg.ui.likesPopupHandler); function setupHandlers(nameA, nameB) { $(document).on('click', '.elgg-menu-item-' + nameA + ' a', function() { var $menu = $(this).closest('.elgg-menu'); // Be optimistic about success elgg.ui.toggleMenuItems($menu, nameB, nameA); $menu.find('.elgg-menu-item-' + nameB + ' a').blur(); // Send the ajax request elgg.action($(this).attr('href'), { success: function(data) { if (data.system_messages.error.length) { // Something went wrong, so undo the optimistic changes elgg.ui.toggleMenuItems($menu, nameA, nameB); } var func_name = data.output.num_likes > 0 ? 'removeClass' : 'addClass'; $(data.output.selector).text(data.output.text)[func_name]('hidden'); }, error: function() { // Something went wrong, so undo the optimistic changes elgg.ui.toggleMenuItems($menu, nameA, nameB); } }); // Don't want to actually click the link return false; }); } setupHandlers('likes', 'unlike'); setupHandlers('unlike', 'likes'); });
define(function (require) { var $ = require('jquery'); var elgg = require('elgg'); var TW = { init: function() { var callback = function() { var maxLength = $(this).data('max-length'); if (maxLength) { TW.textCounter(this, $(this).closest('form').find("#thewire-characters-remaining span"), maxLength); } }; $(document).on('input propertychange', "#thewire-textarea", callback); $(document).on('click', ".thewire-previous", TW.viewPrevious); }, /** * Update the number of characters left with every keystroke * * @param {Object} textarea * @param {Object} status * @param {integer} limit * @return void */ textCounter: function(textarea, status, limit) { var remaining_chars = limit - $(textarea).val().length; status.html(remaining_chars); var $submit = $(textarea).closest('form').find('#thewire-submit-button'); if (remaining_chars < 0) { status.parent().addClass("thewire-characters-remaining-warning"); $submit.prop('disabled', true); $submit.addClass('elgg-state-disabled'); } else { status.parent().removeClass("thewire-characters-remaining-warning"); $submit.prop('disabled', false); $submit.removeClass('elgg-state-disabled'); } }, /** * Display the previous wire post * * Makes Ajax call to load the html and handles changing the previous link * * @param {Object} event * @return void */ viewPrevious: function(event) { var $link = $(this); var postGuid = $link.attr("href").split("/").pop(); var $previousDiv = $("#thewire-previous-" + postGuid); if ($link.html() == elgg.echo('hide')) { $link.html(elgg.echo('previous')); $link.attr("title", elgg.echo('thewire:previous:help')); $previousDiv.slideUp(400); } else { $link.html(elgg.echo('hide')); $link.attr("title", elgg.echo('thewire:hide:help')); elgg.get({ url: elgg.config.wwwroot + "ajax/view/thewire/previous", dataType: "html", cache: false, data: {guid: postGuid}, success: function(htmlData) { if (htmlData.length > 0) { $previousDiv.html(htmlData); $previousDiv.slideDown(600); } } }); } event.preventDefault(); } }; elgg.register_hook_handler('init', 'system', TW.init); /** * elgg.thewire object is deprecated. Do not call it directly. * @deprecated 2.3 */ elgg.thewire = TW; });
define(function(require) { var $ = require('jquery'); var elgg = require('elgg'); /** * Remove a column */ removeColumn = function () { var target = $(this).index() + 1; // There must be at least one option if (target > 2){ $("#elgg-table-scheduling").find("tr :nth-child(" + target + ")").remove(); } }; /** * Add a new column to each of the existing rows * * @return void */ addColumn = function () { var $table = $(this).closest('table'); $table.find('tr').each(function () { var $last = $(this).find('.scheduling-input-time:last'); var $clone = $last.clone(true); $clone.find('select').val(''); $last.after($clone); if ($clone.is('th')) { var deleteIcon = $last.find('span').clone(); var slot_number = $clone.siblings('.scheduling-input-time').andSelf().length; $clone.text(elgg.echo('scheduling:slot:title', [slot_number])); $clone.append(deleteIcon); } }); }; /** * Copy row * * @return void */ copyRow = function () { destroyDatepicker(); var $row = $(this).closest('tr'); var $clone = $row.clone(true); var index = $row.data('index'); var max_index = index; $row.siblings().each(function () { if ($(this).data('index') > max_index) { max_index = $(this).data('index'); } }); $row.after($clone); $clone.data('index', max_index + 1).attr('data-index', max_index + 1); $clone.find("[name*='[" + index + "]']").each(function () { var $elem = $(this); $elem.attr('name', $elem.attr('name').replace('[' + index + ']', '[' + $clone.data('index') + ']')); }); initDatepicker(); }; /** * */ deleteRow = function(e) { var confirmText = $(this).data('confirm') || elgg.echo('question:areyousure'); if (!confirm(confirmText)) { return false; } $(this).closest('tr').fadeOut().remove(); }; /** * Initializes the javascript */ init = function () { $(document).delegate('.scheduling-column-add', 'click', addColumn); $(document).delegate('.scheduling-row-copy', 'click', copyRow); $(document).delegate('.scheduling-row-delete', 'click', deleteRow); $(document).delegate('th.scheduling-input-time', 'click', removeColumn); }; initDatepicker = function () { $('.scheduling-datepicker').datepicker({ dateFormat: 'yy-mm-dd' }); }; destroyDatepicker = function () { $('.scheduling-datepicker').datepicker('destroy'); $('.scheduling-datepicker').removeClass("hasDatepicker").removeAttr('id'); }; elgg.register_hook_handler('init', 'system', init); elgg.register_hook_handler('init', 'system', initDatepicker); });
define(function(require) { var Ajax = require('elgg/Ajax'); var elgg = require('elgg'); var ajax = new Ajax(); var log = console.log.bind(console); // log data passed through all hooks //elgg.register_hook_handler(Ajax.REQUEST_DATA_HOOK, 'all', function (name, type, params, value) { // log(arguments); //}); //elgg.register_hook_handler(Ajax.RESPONSE_DATA_HOOK, 'all', function (name, type, params, value) { // log(arguments); //}); // alter request data for the action elgg.register_hook_handler( Ajax.REQUEST_DATA_HOOK, 'action:developers/ajax_demo', function (name, type, params, value) { // alter the data object sent to server value.client_request_altered = 1; return value; } ); var got_metadata_from_server = false; log("Expecting 6 passes..."); // alter request data response for the action elgg.register_hook_handler( Ajax.RESPONSE_DATA_HOOK, 'action:developers/ajax_demo', function (name, type, params, data) { // check the data wrapper for our expected metadata if (data.server_response_altered) { got_metadata_from_server = true; } // alter the return value data.value.altered_value = true; return data; } ); // we make 4 successive ajax calls, here chained together by Promises ajax.path('developers_ajax_demo') .then(function (html_page) { if (html_page.indexOf('path demo') != -1) { log("PASS path()"); return ajax.view('developers/ajax_demo.html', { data: {guid: 1} }); } }) .then(function (div) { if (div.indexOf('view demo') != -1) { log("PASS view()"); return ajax.form('developers/ajax_demo', { data: {guid: 1} }); } }) .then(function (form) { if (form.indexOf('form demo') != -1) { log("PASS form()"); return ajax.action('developers/ajax_demo', { data: {arg1: 2, arg2: 3}, success: function (obj) { // we should not get two sets of system messages } }); } }) .then(function (obj) { if (obj.sum === 5) { log("PASS action()"); } if (got_metadata_from_server) { log("PASS got metadata from server response hook"); } if (obj.altered_value) { log("PASS client response hook altered value"); } alert('Success!'); }); });
expect(function() { elgg.register_hook_handler('str', 'str', 'oops'); }).toThrow();
define(function (require) { var $ = require('jquery'); var elgg = require('elgg'); /** * elgg.discussion object is deprecated. Do not call it directly. * @deprecated 2.3 */ elgg.discussion = {}; /** * @param {Number} guid * @constructor */ function Reply(guid) { this.guid = guid; this.$item = $('#elgg-object-' + guid); } Reply.prototype = { /** * Get a jQuery-wrapped reference to the form * * @returns {jQuery} note: may be empty */ getForm: function () { return this.$item.find('.elgg-form-discussion-reply-save'); }, /** * @param {Function} complete Optional function to run when animation completes */ hideForm: function (complete) { complete = complete || function () {}; this.getForm().slideUp('fast', complete).data('hidden', 1); }, showForm: function () { this.getForm().slideDown('medium').data('hidden', 0); }, loadForm: function () { var that = this; // Get the form using ajax ajax/view/core/ajax/edit_comment elgg.ajax('ajax/view/ajax/discussion/reply/edit?guid=' + this.guid, { success: function(html) { // Add the form to DOM that.$item.find('.elgg-body').first().append(html); that.showForm(); var $form = that.getForm(); $form.find('.elgg-button-cancel').on('click', function () { that.hideForm(); return false; }); // save $form.on('submit', function () { that.submitForm(); return false; }); } }); }, submitForm: function () { var that = this, $form = this.getForm(), value = $form.find('textarea[name=description]').val(); elgg.action('discussion/reply/save', { data: $form.serialize(), success: function(json) { if (json.status === 0) { // Update list item content that.$item.find('[data-role="discussion-reply-text"]').html(value); } that.hideForm(function () { that.getForm().remove(); }); } }); return false; }, toggleEdit: function () { var $form = this.getForm(); if ($form.length) { if ($form.data('hidden')) { this.showForm(); } else { this.hideForm(); } } else { this.loadForm(); } return false; } }; /** * Initialize discussion reply inline editing * * @return void */ elgg.discussion.init = function() { $(document).on('click', '.elgg-item-object-discussion_reply .elgg-menu-item-edit > a', function () { // store object as data in the edit link var dc = $(this).data('Reply'), guid; if (!dc) { guid = this.href.split('/').pop(); dc = new Reply(guid); $(this).data('Reply', dc); } dc.toggleEdit(); return false; }); }; elgg.register_hook_handler('init', 'system', elgg.discussion.init); /** * elgg.discussion.Reply object is deprecated. Do not call it directly. * @deprecated 2.3 */ elgg.discussion.Reply = Reply; });
it("returns true by default", function() { expect(elgg.trigger_hook("fee", "fum")).toBe(true); elgg.register_hook_handler('fee', 'fum', elgg.nullFunction); expect(elgg.trigger_hook("fee", "fum")).toBe(true); });
define(function(require) { var $ = require('jquery'); var elgg = require('elgg'); require('smoothproducts'); var init = function() { // initialize the image zoomer $(window).load(function() { $('.sp-wrap').smoothproducts(); $('.sp-wrap').find('.sp-thumbs > .sp-current').removeClass('sp-current'); }); // open the image zoomer $(document).on('click', '.sp-thumbs a', function() { $('.sp-large').show(); }); // close the image zoomer $(document).on('click', '*', function(e) { var container = $(".sp-wrap"); if (!container.is(e.target) // if the target of the click isn't the container... && container.has(e.target).length === 0) // ... nor a descendant of the container { container.find('.sp-large').slideUp(); container.find('.sp-thumbs > .sp-current').removeClass('sp-current'); } }); // ajax fetch release info $(document).on('click', '.plugins-show-all', function(e) { e.preventDefault(); var wrapper = $(this).parents('.plugins-download-table-wrapper').eq(0); var html = wrapper.html(); var guid = wrapper.attr('data-guid'); var stable = $(this).attr('data-stable'); wrapper.find('table > tbody').html('<div class="elgg-ajax-loader"></div>'); elgg.get('ajax/view/object/plugin_project/release_table', { data: { guid: guid, stable: stable }, success: function(result) { wrapper.html(result); }, error: function(result) { wrapper.html(html); }, complete: function() { // scroll to the top of the results $('html,body').animate({scrollTop: wrapper.offset().top},'slow'); } }); }); }; elgg.register_hook_handler('init', 'system', init); return { init: init }; });
define(function(require) { var $ = require('jquery'); var elgg = require('elgg'); var init = function() { if (elgg.is_logged_in()) { $('#chat-preview-link').bind('click', getMessages); } }; /** * Get messages via AJAX. * * Get both the number of unread messages and a preview list * of the latest messages. Then populate the topbar menu item * and popup module with the data. */ var getMessages = function() { var url = elgg.normalize_url("chat/notifier"); var messages = elgg.getJSON( url, { success: function(data) { // Add notifier to topbar menu item var counter = $('#chat-messages-new'); counter.text(data.count); if (data.count > 0) { counter.removeClass('hidden'); } else { counter.addClass('hidden'); } // Add content to popup module $('#chat-messages-preview > .elgg-body > ul').replaceWith(data.preview); if ($('#chat-messages-preview > .elgg-body > ul').text()) { $('#chat-messages-none').hide(); $('#chat-view-all').show(); } else { $('#chat-messages-none').show(); $('#chat-view-all').hide(); } } } ); }; /** * Repositions the chat members popup * * @param {String} hook 'getOptions' * @param {String} type 'ui.popup' * @param {Object} params An array of info about the target and source. * @param {Object} options Options to pass to * * @return {Object} */ elgg.ui.chatMemberPopupHandler = function(hook, type, params, options) { if (params.target.hasClass('elgg-chat-members')) { options.my = 'left bottom'; options.at = 'right top'; return options; } return null; }; /** * Repositions the chat messages popup * * @param {String} hook 'getOptions' * @param {String} type 'ui.popup' * @param {Object} params An array of info about the target and source. * @param {Object} options Options to pass to * * @return {Object} */ elgg.ui.chatMessagesPopupHandler = function(hook, type, params, options) { if (params.target.hasClass('elgg-chat-messages-preview')) { options.my = 'left top'; options.at = 'left bottom'; return options; } return null; }; elgg.register_hook_handler('init', 'system', init); elgg.register_hook_handler('getOptions', 'ui.popup', elgg.ui.chatMemberPopupHandler); elgg.register_hook_handler('getOptions', 'ui.popup', elgg.ui.chatMessagesPopupHandler); return { getMessages: getMessages }; });
define(function(require) { var $ = require('jquery'); var elgg = require('elgg'); $.extend({ getUrlVars: function(){ var vars = [], hash; var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&'); for(var i = 0; i < hashes.length; i++) { hash = hashes[i].split('='); vars.push(hash[0]); vars[hash[0]] = hash[1]; } return vars; }, getUrlVar: function(name){ return $.getUrlVars()[name]; } }); getUrlParameter = function getUrlParameter(sParam) { var sPageURL = decodeURIComponent(window.location.search.substring(1)), sURLVariables = sPageURL.split('&'), sParameterName, i; for (i = 0; i < sURLVariables.length; i++) { sParameterName = sURLVariables[i].split('='); if (sParameterName[0] === sParam) { return sParameterName[1] === undefined ? true : sParameterName[1]; } } }; // grab currently selected filter options from UI, build the URL for the options and then forward the browser to the new URL changeFilter = function(status) { var timing_to_val; var timing_from_val; var url = window.location.href; if (window.location.search.length) { url = url.substring(0, url.indexOf('?')); } var filter_param = getUrlParameter('filter'); var sort_val = $("#sort").val(); // use default date values (all) if the date fields match their original defaults if ($('#timing-from').data('default_from') == $("input[name='timing-from']").val()) timing_from_val = 'all'; else timing_from_val = $("input[name='timing-from']").val(); if ($('#timing-to').data('default_to') == $("input[name='timing-to']").val()) timing_to_val = 'all'; else timing_to_val = $("input[name='timing-to']").val(); // if the reset button was clicked then use default date values if (status == 'reset') { timing_from_val = 'all'; timing_to_val = 'all'; } var contain_val = $("#contain").val(); var status_val = $("#status").val(); var objtype_val = $("#elgg-river-selector").val(); if (($('#icon').length > 0) &&(document.getElementById('icon').checked)) var icon_val = 'true'; else var icon_val = 'false'; if ($('#status').length == 0) status_val = 'all'; var limit_val = $("#limit").val(); var list_type = $.getUrlVar("list_type"); if ((list_type != 'gallery')&&(list_type != 'list')) list_type = 'list'; url += '?sort=' + sort_val + '&' + 'timing_from=' + timing_from_val + '&' + 'timing_to=' + timing_to_val + '&' + 'contain=' + contain_val + '&' + 'status=' + status_val + '&' + 'limit=' + limit_val + '&' + 'list_type=' + list_type; if (icon_val) url += '&' + 'show_icon=' + icon_val; if (filter_param) url += '&' + 'filter=' + filter_param; if (objtype_val) url += '&' + objtype_val; elgg.forward(url); }; init = function() { $('#filter_options_go_btn').click(function() { // if the to-date is before the from-date then throw an error if (parseInt($("input[name='timing-to']").val()) < parseInt($("input[name='timing-from']").val())) elgg.register_error(elgg.echo('filter_and_sort:datepicker_mismatch')); // otherwise, process the filter state and reload the page else changeFilter(); }); // if url params exist or cookie present if (((window.location.href.indexOf('?') != -1))||($('#elgg-sort-options').data('cookie') == 1)) { var params = $.getUrlVars(); var firstparam = 0; if (params[0] == '') firstparam = 1; if ($('#icon').length > 0) var icon_check = document.getElementById('icon').checked; // if any filters are active if (($(".elgg-active-sort-filter").length > 0)||(icon_check)) { // reveal filter control area $("#elgg-filter-options").slideDown( "slow" ); $('#elgg-filter-options-link').html(elgg.echo('filter_and_sort:hide')); } } $( "#elgg-filter-options-link").click(function () { if ( $("#elgg-filter-options").is( ":hidden" ) ) { $("#elgg-filter-options").slideDown( "slow" ); $('#elgg-filter-options-link').html(elgg.echo('filter_and_sort:hide')); } else { $('#elgg-filter-options-link').html(elgg.echo('filter_and_sort:show')); $("#elgg-filter-options").slideUp( "fast" ); } }); $("#elgg-reset-sort-filters").click(function () { // reset dropdowns to default options $("#elgg-filter-options select").prop('selectedIndex', 0); // set date fields to default changeFilter('reset'); }); $( ".elgg-active-sort-filter").click(function () { var filter = $(this).attr('data'); if (filter == 'objtype') filter = 'elgg-river-selector'; if (filter == 'timing-to') var reset = 'reset'; $("#" + filter).prop('selectedIndex', 0); changeFilter('reset'); }); $( ".elgg-active-sort-filter").mouseover(function () { $(this).children().css( "background-position", "0 -127px" ); }) .mouseout(function () { $(this).children().css( "background-position", "0 -136px" ); }); }; elgg.register_hook_handler('init', 'system', init); });