aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--mod/embed/start.php18
-rw-r--r--mod/embed/views/default/embed/css.php24
-rw-r--r--mod/embed/views/default/embed/embed.php93
-rw-r--r--mod/embed/views/default/js/embed/embed.php39
-rw-r--r--mod/embed/views/default/js/embed/inline.php26
5 files changed, 112 insertions, 88 deletions
diff --git a/mod/embed/start.php b/mod/embed/start.php
index ce6c6ec11..3b6e58ce1 100644
--- a/mod/embed/start.php
+++ b/mod/embed/start.php
@@ -13,17 +13,24 @@ elgg_register_event_handler('init', 'system', 'embed_init');
*/
function embed_init() {
elgg_extend_view('css/elgg', 'embed/css');
- elgg_extend_view('js/elgg', 'embed/js');
- elgg_extend_view('js/elgg', 'embed/lightbox_init');
elgg_register_plugin_hook_handler('register', 'menu:longtext', 'embed_longtext_menu');
// Page handler for the modal media embed
elgg_register_page_handler('embed', 'embed_page_handler');
- elgg_register_js('elgg.embed', 'mod/embed/js/embed.js', 'footer');
+ elgg_register_js('elgg.embed', 'js/embed/embed.js', 'footer');
}
+/**
+ * Add the embed menu item to the long text menu
+ *
+ * @param string $hook
+ * @param string $type
+ * @param array $items
+ * @param array $vars
+ * @return array
+ */
function embed_longtext_menu($hook, $type, $items, $vars) {
// yeah this is naughty. embed and ecml might want to merge.
if (elgg_is_active_plugin('ecml')) {
@@ -37,12 +44,13 @@ function embed_longtext_menu($hook, $type, $items, $vars) {
'href' => "embed?{$active_section}internal_id={$vars['id']}",
'text' => elgg_echo('media:insert'),
'rel' => 'lightbox',
- 'link_class' => 'elgg-longtext-control elgg-lightbox',
- 'priority' => 1,
+ 'link_class' => "elgg-longtext-control elgg-lightbox embed-control embed-control-{$vars['id']}",
+ 'priority' => 10,
));
elgg_load_js('lightbox');
elgg_load_css('lightbox');
+ elgg_load_js('elgg.embed');
return $items;
}
diff --git a/mod/embed/views/default/embed/css.php b/mod/embed/views/default/embed/css.php
index c20116bf2..1ce994cfe 100644
--- a/mod/embed/views/default/embed/css.php
+++ b/mod/embed/views/default/embed/css.php
@@ -8,12 +8,15 @@
.embed-wrapper {
width: 730px;
min-height: 400px;
- padding: 5px;
+ margin: 5px;
}
.embed-wrapper h2 {
color: #333333;
margin-bottom: 10px;
}
+.embed-wrapper .elgg-list-item {
+ cursor: pointer;
+}
/* ***************************************
EMBED TABBED PAGE NAVIGATION
@@ -22,6 +25,15 @@
color: #666;
}
+.embed-wrapper p {
+ color: #333;
+}
+.embed-wrapper .elgg-image-block:hover {
+ background-color: #eee;
+}
+<?php
+return true;
+?>
/***************
Form
******************/
@@ -51,15 +63,7 @@
.embed-wrapper .elgg-input-file {
background-color: white;
}
-.embed-wrapper p {
- color:#333;
-}
-.embed-wrapper p.entity-title {
- color:#666;
-}
-.embed-wrapper .elgg-image-block:hover {
- background-color: #eee;
-}
+
.embed-wrapper label {
color:#333;
}
diff --git a/mod/embed/views/default/embed/embed.php b/mod/embed/views/default/embed/embed.php
index f09d76a4b..9f0ac730f 100644
--- a/mod/embed/views/default/embed/embed.php
+++ b/mod/embed/views/default/embed/embed.php
@@ -29,8 +29,6 @@ if (!$sections) {
$layout = isset($section_info['layout']) ? $section_info['layout'] : 'list';
$params = array(
- //'type' => $type,
- //'subtype' => $subtype,
'offset' => $offset,
'limit' => $limit,
'section' => $active_section,
@@ -43,10 +41,13 @@ if (!$sections) {
if ($section_content = elgg_view("embed/$active_section/content", $params)) {
// handles its own pagination
$content .= $section_content;
- } elseif ($embed_info = elgg_trigger_plugin_hook('embed_get_items', $active_section, $params, array('items' => array(), 'count' => 0))) {
- // check if we have an override for this section type.
- $view = "embed/$active_section/item/$layout";
+ } else {
+ // see if anyone has any items to display for the active section
+ $result = array('items' => array(), 'count' => 0);
+ $embed_info = elgg_trigger_plugin_hook('embed_get_items', $active_section, $params, $result);
+ // do we use default view or has someone defined "embed/$active_section/item/$layout"
+ $view = "embed/$active_section/item/$layout";
if (!elgg_view_exists($view)) {
$view = "embed/item/$layout";
}
@@ -54,37 +55,16 @@ if (!$sections) {
if (!isset($embed_info['items']) || !is_array($embed_info['items']) || !count($embed_info['items'])) {
$content .= elgg_echo('embed:no_section_content');
} else {
- // pull out some common tests
- // embed requires ECML, but until we have plugin deps working
- // we need to explicitly check and use a fallback.
- if ($ecml_enabled = elgg_is_active_plugin('ecml')){
- $ecml_valid_keyword = ecml_is_valid_keyword($active_section);
- } else {
- $ecml_valid_keyword = FALSE;
- }
-
- $items_content = '<ul class="elgg-list">';
- foreach ($embed_info['items'] as $item) {
- $item_params = array(
- 'section' => $active_section,
- 'item' => $item,
- 'ecml_enabled' => $ecml_enabled,
- 'ecml_keyword' => ($ecml_valid_keyword) ? $active_section : 'entity',
- 'icon_size' => elgg_extract('icon_size', $section_info, 'tiny'),
- );
-
- $items_content .= '<li class="elgg-list-item">' . elgg_view($view, $item_params) . '</li>';
- }
- $items_content .= '</ul>';
-
- $params['content'] = $items_content;
- $params['count'] = $embed_info['count'];
-
- $content .= elgg_view('navigation/pagination', $params);
- $content .= elgg_view("embed/layouts/$layout", $params);
+ elgg_push_context('widgets');
+ $content .= elgg_view_entity_list($embed_info['items'], array(
+ 'full_view' => false,
+ ));
+ elgg_pop_context();
+
+ $js = elgg_view('js/embed/inline', array(
+ 'items' => $embed_info['items'],
+ ));
}
- } else {
- $content .= elgg_echo('embed:no_section_content');
}
} else {
$content .= elgg_echo('embed:invalid_section');
@@ -92,42 +72,9 @@ if (!$sections) {
}
echo '<div class="embed-wrapper">' . $content . '</div>';
-?>
-
-<?php //@todo: JS 1.8: ugly ?>
-<script type="text/javascript">
-$(function() {
- var internal_id = '<?php echo addslashes($internal_id); ?>';
-
- // Remove any existing "live" handlers
- $('.embed_data').die('click');
- $('.embed_section').die('click');
- $('#facebox .elgg-pagination a').die('click');
-
- // insert embed codes
- $('.embed_data').live('click', function() {
- var embed_code = $(this).data('embed_code');
- elggEmbedInsertContent(embed_code, internal_id);
-
- return false;
- });
- // tabs
- $('.embed_section').live('click', function() {
- var section = $(this).attr('id');
- var url = elgg.config.wwwroot + 'embed/embed?active_section=' + section + '&internal_id=' + internal_id;
- $('#facebox .body .content').load(url);
-
- return false;
- });
-
- // pagination
- function elggPaginationClick() {
- $('#facebox .body .content').load($(this).attr('href'));
- return false;
- }
-
- $('#facebox .elgg-pagination a').live('click', elggPaginationClick);
-});
-
-</script>
+if (isset($js)) {
+ echo '<script type="text/javascript">';
+ echo $js;
+ echo '</script>';
+}
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