aboutsummaryrefslogtreecommitdiff
path: root/mod/embed/views/default/js
diff options
context:
space:
mode:
authorcash <cash.costello@gmail.com>2011-06-18 21:30:01 -0400
committercash <cash.costello@gmail.com>2011-06-18 21:30:01 -0400
commitd462b57edfeab81bd90a5d0321ea3d1fcbbddff3 (patch)
tree8caaf24aec75f04c9007ebc34889a5146b0dbebb /mod/embed/views/default/js
parent755187045527c5c15ea3b9e70fe7a451d7796585 (diff)
downloadelgg-d462b57edfeab81bd90a5d0321ea3d1fcbbddff3.tar.gz
elgg-d462b57edfeab81bd90a5d0321ea3d1fcbbddff3.tar.bz2
rewrote the insert javascript as an intermediate step. I'm sure I completely broke ECML integration and uploading files.
Diffstat (limited to 'mod/embed/views/default/js')
-rw-r--r--mod/embed/views/default/js/embed/embed.php39
-rw-r--r--mod/embed/views/default/js/embed/inline.php26
2 files changed, 65 insertions, 0 deletions
diff --git a/mod/embed/views/default/js/embed/embed.php b/mod/embed/views/default/js/embed/embed.php
new file mode 100644
index 000000000..78ad125ef
--- /dev/null
+++ b/mod/embed/views/default/js/embed/embed.php
@@ -0,0 +1,39 @@
+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;
+ });
+}
+
+/**
+ * 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();
+}
+
+elgg.register_hook_handler('init', 'system', elgg.embed.init);
diff --git a/mod/embed/views/default/js/embed/inline.php b/mod/embed/views/default/js/embed/inline.php
new file mode 100644
index 000000000..0672a68f8
--- /dev/null
+++ b/mod/embed/views/default/js/embed/inline.php
@@ -0,0 +1,26 @@
+<?php
+/**
+ * Inline embed JavaScript for attaching the insert data to list items
+ *
+ * @uses $vars['items']
+ */
+
+foreach ($vars['items'] as $item) {
+
+ // different entity types have different title attribute names.
+ $title = isset($item->name) ? $item->name : $item->title;
+ // don't let it be too long
+ $title = elgg_get_excerpt($title);
+
+ $icon = "<img src=\"{$item->getIcon($icon_size)}\" />" . htmlspecialchars($title, ENT_QUOTES, 'UTF-8', false);
+
+ $embed_code = elgg_view('output/url', array(
+ 'href' => $item->getURL(),
+ 'title' => $title,
+ 'text' => $icon,
+ 'encode_text' => false,
+ ));
+ $embed_code = json_encode($embed_code);
+
+ echo "$('#elgg-object-{$item->getGUID()}').data('embed_code', $embed_code);";
+} \ No newline at end of file