aboutsummaryrefslogtreecommitdiff
path: root/mod/embed/views/default/js/embed/embed.php
blob: 3b398af3ae3d4e7085214de6ba32e7714f00e1f2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
elgg.provide('elgg.embed');

elgg.embed.init = function() {

	// inserts the embed content into the textarea
	$(".embed-wrapper .elgg-list-item").live('click', elgg.embed.insert);

	// caches the current textarea id
	$(".embed-control").live('click', function() {
		var classes = $(this).attr('class');
		var class = classes.split(/[, ]+/).pop();
		var textAreaId = class.substr(class.indexOf('embed-control-') + "embed-control-".length);
		elgg.embed.textAreaId = textAreaId;
	});

	// special pagination helper for lightbox
	$('.embed-wrapper .elgg-pagination a').live('click', elgg.embed.pagination);

	$('.embed-section').live('click', elgg.embed.loadTab);
}

/**
 * Inserts data attached to an embed list item in textarea
 *
 * @todo generalize lightbox closing and wysiwyg refreshing
 *
 * @param {Object} event
 * @return void
 */
elgg.embed.insert = function(event) {

	var textAreaId = elgg.embed.textAreaId;

	var content = $(this).data('embed_code');
	$('#' + textAreaId).val($('#' + textAreaId).val() + ' ' + content + ' ');

	<?php echo elgg_view('embed/custom_insert_js'); ?>

	$.fancybox.close();

	event.preventDefault();
}

/**
 * Loads the next chunk of content within the lightbox
 *
 * @param {Object} event
 * @return void
 */
elgg.embed.pagination = function(event) {
	$('.embed-wrapper').parent().load($(this).attr('href'));
	event.preventDefault();
}

/**
 * Loads an embed tab
 *
 * @param {Object} event
 * @return void
 */
elgg.embed.loadTab = function(event) {
	var section = $(this).attr('id');
	var url = elgg.config.wwwroot + 'embed/embed?active_section=' + section;
	$('.embed-wrapper').parent().load(url);
	event.preventDefault();
}

elgg.register_hook_handler('init', 'system', elgg.embed.init);