From c7b0817dabd1ea596086b03569d4480355e5f721 Mon Sep 17 00:00:00 2001 From: cash Date: Sat, 1 Oct 2011 12:42:00 -0400 Subject: using the menu system for the embed tabs and adding a reusable select list view --- mod/embed/start.php | 132 +++++++++++++++++++++++++++++----------------------- 1 file changed, 74 insertions(+), 58 deletions(-) (limited to 'mod/embed/start.php') diff --git a/mod/embed/start.php b/mod/embed/start.php index 6c26163e9..a87776c7e 100644 --- a/mod/embed/start.php +++ b/mod/embed/start.php @@ -15,6 +15,7 @@ function embed_init() { elgg_extend_view('css/elgg', 'embed/css'); elgg_register_plugin_hook_handler('register', 'menu:longtext', 'embed_longtext_menu'); + elgg_register_plugin_hook_handler('register', 'menu:embed', 'embed_select_tab', 1000); // Page handler for the modal media embed elgg_register_page_handler('embed', 'embed_page_handler'); @@ -40,7 +41,7 @@ function embed_longtext_menu($hook, $type, $items, $vars) { $items[] = ElggMenuItem::factory(array( 'name' => 'embed', 'href' => "embed", - 'text' => elgg_echo('media:insert'), + 'text' => elgg_echo('embed:media'), 'rel' => 'lightbox', 'link_class' => "elgg-longtext-control elgg-lightbox embed-control embed-control-{$vars['id']}", 'priority' => 10, @@ -54,68 +55,83 @@ function embed_longtext_menu($hook, $type, $items, $vars) { } /** - * Serves pages for upload and embed. + * Select the correct embed tab for display * - * @param $page + * @param string $hook + * @param string $type + * @param array $items + * @param array $vars */ -function embed_page_handler($page) { - if (!isset($page[0])) { - $page[0] = 'embed'; +function embed_select_tab($hook, $type, $items, $vars) { + + $tab_name = array_pop(explode('/', full_url())); + foreach ($items as $item) { + if ($item->getName() == $tab_name) { + $item->setSelected(); + elgg_set_config('embed_tab', $item); + } } - switch ($page[0]) { - case 'upload': - echo elgg_view('embed/upload'); - break; - case 'embed': - default: - // trigger hook to get section tabs - // use views for embed/section/ - // listing - // item - // default to embed/listing | item if not found. - - // @todo the menu system is good for registering and sorting, but not great for - // displaying tabs. - // Pulling in the menu manually and passing it through the embed/tabs view. - // We should work on making it easier to use tabs through the menu system, then fix - // this mess. - $menus = get_config('menus'); - $menu = $menus['embed:sections']; - - $sections = array(); - $upload_sections = array(); - - foreach ($menu as $item) { - switch ($item->section) { - case 'upload': - $upload_sections[$item->getName()] = array( - 'name' => $item->getText(), - ); - break; - - default: - $sections[$item->getName()] = array( - 'name' => $item->getText(), - ); - break; - } - } - - $active_section = get_input('active_section', ''); - $active_section = preg_replace('[\W]', '', $active_section); - $internal_id = get_input('internal_id', ''); - $internal_id = preg_replace('[\W]', '', $internal_id); - - echo elgg_view('embed/embed', array( - 'sections' => $sections, - 'active_section' => $active_section, - 'upload_sections' => $upload_sections, - 'internal_id' => $internal_id - )); - break; + if (!elgg_get_config('embed_tab') && count($items) > 0) { + $items[0]->setSelected(); + elgg_set_config('embed_tab', $items[0]); } +} + +/** + * Serves the content for the embed lightbox + * + * @param array $page URL segments + */ +function embed_page_handler($page) { + + echo elgg_view('embed/layout'); // exit because this is in a modal display. exit; -} \ No newline at end of file +} + +/** + * A special listing function for selectable content + * + * This calls a custom list view for entities. + * + * @param array $entities Array of ElggEntity objects + * @param array $vars Display parameters + * @return string + */ +function embed_list_items($entities, $vars = array()) { + + $defaults = array( + 'items' => $entities, + 'list_class' => 'elgg-list-entity', + ); + + $vars = array_merge($defaults, $vars); + + return elgg_view('embed/list', $vars); +} + +/** + * Set the options for the list of embedable content + * + * @param array $options + * @return array + */ +function embed_get_list_options($options = array()) { + + if (elgg_get_page_owner_guid()) { + $container_guid = elgg_get_page_owner_guid(); + } else { + $container_guid = elgg_get_logged_in_user_guid(); + } + + $defaults = array( + 'limit' => 6, + 'container_guid' => $container_guid, + ); + + $options = array_merge($defaults, $options); + + return $options; +} -- cgit v1.2.3 From 418078a8d4c157c1c88d196d3b24ff0f0893b764 Mon Sep 17 00:00:00 2001 From: cash Date: Sat, 1 Oct 2011 16:30:04 -0400 Subject: cleaned up the embed item view and removed the inline js --- mod/embed/start.php | 1 + mod/embed/views/default/embed/css.php | 6 +++- mod/embed/views/default/embed/item.php | 44 ++++++++++++++++++------------ mod/embed/views/default/js/embed/embed.php | 27 +++++++++++++----- 4 files changed, 52 insertions(+), 26 deletions(-) (limited to 'mod/embed/start.php') diff --git a/mod/embed/start.php b/mod/embed/start.php index a87776c7e..015c0c0e4 100644 --- a/mod/embed/start.php +++ b/mod/embed/start.php @@ -129,6 +129,7 @@ function embed_get_list_options($options = array()) { $defaults = array( 'limit' => 6, 'container_guid' => $container_guid, + 'item_class' => 'embed-item', ); $options = array_merge($defaults, $options); diff --git a/mod/embed/views/default/embed/css.php b/mod/embed/views/default/embed/css.php index f654a208a..324ed1038 100644 --- a/mod/embed/views/default/embed/css.php +++ b/mod/embed/views/default/embed/css.php @@ -28,6 +28,10 @@ .embed-wrapper p { color: #333; } -.embed-wrapper .elgg-image-block:hover { +.embed-item { + padding-left: 5px; + padding-right: 5px; +} +.embed-item:hover { background-color: #eee; } diff --git a/mod/embed/views/default/embed/item.php b/mod/embed/views/default/embed/item.php index c6faa450b..4087b7408 100644 --- a/mod/embed/views/default/embed/item.php +++ b/mod/embed/views/default/embed/item.php @@ -7,25 +7,33 @@ $entity = $vars['entity']; -$image = elgg_view_entity_icon($entity, 'small'); - -$body = "

" . $entity->title . "

"; - -$icon = "getIconURL('small')}\" />"; - -$embed_code = elgg_view('output/url', array( - 'href' => $entity->getURL(), +$title = $entity->title; +if (!$title) { + $title = $entity->name; +} + +// different entity types have different title attribute names. +$title = isset($entity->name) ? $entity->name : $entity->title; +// don't let it be too long +$title = elgg_get_excerpt($title); + +$owner = $entity->getOwnerEntity(); +if ($owner) { + $author_text = elgg_echo('byline', array($owner->name)); + $date = elgg_view_friendly_time($entity->time_created); + $subtitle = "$author_text $date"; +} else { + $subtitle = ''; +} + +$params = array( 'title' => $title, - 'text' => $icon, - 'encode_text' => FALSE -)); + 'entity' => $entity, + 'subtitle' => $subtitle, + 'tags' => FALSE, +); +$body = elgg_view('object/elements/summary', $params); +$image = elgg_view_entity_icon($entity, 'small'); -echo "
getGUID()}\">"; echo elgg_view_image_block($image, $body); -echo '
'; - -// @todo JS 1.8: is this approach better than inline js? -echo ""; diff --git a/mod/embed/views/default/js/embed/embed.php b/mod/embed/views/default/js/embed/embed.php index e60c6b367..37246ee8a 100644 --- a/mod/embed/views/default/js/embed/embed.php +++ b/mod/embed/views/default/js/embed/embed.php @@ -3,7 +3,7 @@ elgg.provide('elgg.embed'); elgg.embed.init = function() { // inserts the embed content into the textarea - $(".embed_data").live('click', elgg.embed.insert); + $(".embed-item").live('click', elgg.embed.insert); // caches the current textarea id $(".embed-control").live('click', function() { @@ -24,7 +24,7 @@ elgg.embed.init = function() { /** * Inserts data attached to an embed list item in textarea * - * @todo generalize lightbox closing and wysiwyg refreshing + * @todo generalize lightbox closing * * @param {Object} event * @return void @@ -32,10 +32,23 @@ elgg.embed.init = function() { elgg.embed.insert = function(event) { var textAreaId = elgg.embed.textAreaId; - var content = $(this).data('embed_code'); - $('#' + textAreaId).val($('#' + textAreaId).val() + ' ' + content + ' '); - - + // generalize this based on a css class attached to what should be inserted + var content = ' ' + $(this).find(".elgg-image").html() + ' '; + + + $('#' + textAreaId).val($('#' + textAreaId).val() + content); + $('#' + textAreaId).focus(); + $.fancybox.close(); @@ -68,7 +81,7 @@ elgg.embed.submit = function(event) { if (response.status >= 0) { // @todo - really this should forward to what the registered defined // For example, forward to images tab if an image was uploaded - var url = elgg.config.wwwroot + 'embed/embed?active_section=file'; + var url = elgg.config.wwwroot + 'embed/embed'; $('.embed-wrapper').parent().load(url); } } -- cgit v1.2.3