Ejemplo n.º 1
0
		bind: function (selector) {
			elggCKEditor.registerHandlers();
			CKEDITOR = elgg.trigger_hook('prepare', 'ckeditor', null, CKEDITOR);
			selector = selector || '.elgg-input-longtext';
			if ($(selector).length === 0) {
				return;
			}
			$(selector).not('[data-cke-init]')
					.attr('data-cke-init', true)
					.each(function () {
						var opts = $(this).data('editorOpts') || {};

						if (opts.disabled) {
							// Editor has been disabled
							return;
						}
						delete opts.disabled;

						var visual = opts.state !== 'html';
						delete opts.state;

						var config = $.extend({}, elggCKEditor.config, opts);
						$(this).data('elggCKEeditorConfig', config);

						if (!visual) {
							elggCKEditor.init(this, visual);
						} else {
							$(this).ckeditor(elggCKEditor.init, config);
						}
					});
		},
Ejemplo n.º 2
0
		getOptions: function (opts) {
			if (!$.isPlainObject(opts)) {
				opts = {};
			}

			// Note: keep these in sync with /views/default/lightbox.js.php
			var 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'),
				opacity: 0.5,
				maxWidth: '100%',
				// don't move colorbox on small viewports https://github.com/Elgg/Elgg/issues/5312
				reposition: $(window).height() > 600
			};
			
			elgg.provide('elgg.ui.lightbox');
			
			if ($.isPlainObject(elgg.ui.lightbox.deprecated_settings)) {
				$.extend(settings, elgg.ui.lightbox.deprecated_settings, opts);
			} else {
				$.extend(settings, opts);
			}

			return elgg.trigger_hook('getOptions', 'ui.lightbox', null, settings);
		},
Ejemplo n.º 3
0
Archivo: prepare.js Proyecto: Elgg/Elgg
define('elgg/init', function (require) {
	var elgg = require('elgg');
	var plugin = require('boot/example');

	plugin._init();

	elgg.trigger_hook('init', 'system');
});
Ejemplo n.º 4
0
		bind: function (selector) {
			elggCKEditor.registerHandlers();
			CKEDITOR = elgg.trigger_hook('prepare', 'ckeditor', null, CKEDITOR);
			selector = selector || '.elgg-input-longtext';
			if ($(selector).length === 0) {
				return;
			}
			$(selector)
					.not('[data-cke-init]')
					.attr('data-cke-init', true)
					.ckeditor(elggCKEditor.init, elggCKEditor.config);
		},
Ejemplo n.º 5
0
Archivo: Ajax.js Proyecto: Facyla/Elgg
			function unwrap_data(data) {
				var params;

				if (!msgs_were_set) {
					data.msgs.error && elgg.register_error(data.msgs.error);
					data.msgs.success && elgg.system_message(data.msgs.success);
					msgs_were_set = 1;
				}

				params = {
					options: orig_options
				};
				if (hook_type) {
					return elgg.trigger_hook(Ajax.RESPONSE_DATA_HOOK, hook_type, params, data.data);
				}
				return data.data;
			}
Ejemplo n.º 6
0
Archivo: embed.js Proyecto: Elgg/Elgg
		insert: function (event) {
			var textAreaId = 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() + ' ';
			var value = textArea.val();
			var result = textArea.val();
			// this is a temporary work-around for #3971
			if (content.indexOf('/serve-icon/') != -1) {
				content = content.replace(/\/serve-icon\/[0-9]*\/small/g, function replacer(match) {
					return match.replace('small', 'large');
				});
			}

			textArea.focus();
			if (!elgg.isNullOrUndefined(textArea.prop('selectionStart'))) {
				var cursorPos = textArea.prop('selectionStart');
				var textBefore = value.substring(0, cursorPos);
				var textAfter = value.substring(cursorPos, value.length);
				result = textBefore + content + textAfter;
			} else if (document.selection) {
				// IE compatibility
				var sel = document.selection.createRange();
				sel.text = content;
				result = textArea.val();
			}

			// See the ckeditor plugin for an example of this hook
			result = elgg.trigger_hook('embed', 'editor', {
				textAreaId: textAreaId,
				content: content,
				value: value,
				event: event
			}, result);
			if (result || result === '') {
				textArea.val(result);
			}

			lightbox.close();
			event.preventDefault();
		},
Ejemplo n.º 7
0
				expect(function() { elgg.trigger_hook('pinky', 'winky'); }).toThrow();
Ejemplo n.º 8
0
				expect(function() { elgg.trigger_hook('foo', 'baz'); }).toThrow();
Ejemplo n.º 9
0
			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);
			});
Ejemplo n.º 10
0
Archivo: Ajax.js Proyecto: Facyla/Elgg
		/**
		 * Fetch a value from an Ajax endpoint.
		 *
		 * Note that this function does not support the array form of "success".
		 *
		 * To request the response be cached, set options.method to "GET" and options.data.response_ttl
		 * to a number of seconds.
		 *
		 * @param {Object} options   See {@link jQuery#ajax}. The default method is "GET" (or "POST" for actions).
		 *
		 *     url   : {String} Path of the Ajax API endpoint (required)
		 *     error : {Function} Error handler. Default is elgg.ajax.handleAjaxError. To cancel this altogether,
		 *                        pass in function(){}.
		 *
		 * @param {String} hook_type Type of the plugin hooks. If missing, the hooks will not trigger.
		 *
		 * @returns {jqXHR}
		 */
		function fetch(options, hook_type) {
			var orig_options,
				msgs_were_set = 0,
				params;

			function unwrap_data(data) {
				var params;

				if (!msgs_were_set) {
					data.msgs.error && elgg.register_error(data.msgs.error);
					data.msgs.success && elgg.system_message(data.msgs.success);
					msgs_were_set = 1;
				}

				params = {
					options: orig_options
				};
				if (hook_type) {
					return elgg.trigger_hook(Ajax.RESPONSE_DATA_HOOK, hook_type, params, data.data);
				}
				return data.data;
			}

			hook_type = hook_type || '';

			if (!$.isPlainObject(options) || !options.url) {
				throw new Error('options must be a plain with key "url"');
			}

			// ease hook filtering by making these keys always available
			options.data = options.data || {};
			options.dataType = 'json';
			if (!options.method) {
				options.method = 'GET';
			}

			// copy of original options
			orig_options = $.extend({}, options);

			params = {
				options: options
			};
			if (hook_type) {
				options.data = elgg.trigger_hook(Ajax.REQUEST_DATA_HOOK, hook_type, params, options.data);
			}

			if ($.isArray(options.success)) {
				throw new Error('The array form of options.success is not supported');
			}

			if (elgg.isFunction(options.success)) {
				options.success = function (data) {
					data = unwrap_data(data);
					orig_options.success(data);
				};
			}

			if (use_spinner) {
				options.beforeSend = function () {
					orig_options.beforeSend && orig_options.beforeSend();
					spinner.start();
				};
				options.complete = function () {
					spinner.stop();
					orig_options.complete && orig_options.complete();
				};
			}

			if (!options.error) {
				options.error = elgg.ajax.handleAjaxError;
			}

			options.url = elgg.normalize_url(options.url);
			options.headers = {
				'X-Elgg-Ajax-API': '2'
			};

			return $.ajax(options).then(unwrap_data);
		}