From d462b57edfeab81bd90a5d0321ea3d1fcbbddff3 Mon Sep 17 00:00:00 2001 From: cash Date: Sat, 18 Jun 2011 21:30:01 -0400 Subject: rewrote the insert javascript as an intermediate step. I'm sure I completely broke ECML integration and uploading files. --- mod/embed/start.php | 18 ++++-- mod/embed/views/default/embed/css.php | 24 ++++---- mod/embed/views/default/embed/embed.php | 93 +++++++---------------------- mod/embed/views/default/js/embed/embed.php | 39 ++++++++++++ mod/embed/views/default/js/embed/inline.php | 26 ++++++++ 5 files changed, 112 insertions(+), 88 deletions(-) create mode 100644 mod/embed/views/default/js/embed/embed.php create mode 100644 mod/embed/views/default/js/embed/inline.php (limited to 'mod') 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; +} + /*************** 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 = ''; - - $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 '
' . $content . '
'; -?> - - - +if (isset($js)) { + echo ''; +} 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 + ' '); + + + + $.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 @@ +name) ? $item->name : $item->title; + // don't let it be too long + $title = elgg_get_excerpt($title); + + $icon = "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 -- cgit v1.2.3