]> gitweb.fluxo.info Git - lorea/elgg.git/commitdiff
rewrote the insert javascript as an intermediate step. I'm sure I completely broke...
authorcash <cash.costello@gmail.com>
Sun, 19 Jun 2011 01:30:01 +0000 (21:30 -0400)
committercash <cash.costello@gmail.com>
Sun, 19 Jun 2011 01:30:01 +0000 (21:30 -0400)
mod/embed/start.php
mod/embed/views/default/embed/css.php
mod/embed/views/default/embed/embed.php
mod/embed/views/default/js/embed/embed.php [new file with mode: 0644]
mod/embed/views/default/js/embed/inline.php [new file with mode: 0644]

index ce6c6ec11f677b8fdb99a7b1e128777cb98424eb..3b6e58ce12b2cfedaf8067d7b99c70ae76c9fc60 100644 (file)
@@ -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;
 }
index c20116bf2a6de45b3762c714b415d3c50055a9fc..1ce994cfec814701e5d930e21507d25d3aee2f0d 100644 (file)
@@ -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
        color: #666;
 }
 
+.embed-wrapper p {
+       color: #333;
+}
+.embed-wrapper .elgg-image-block:hover {
+       background-color: #eee;
+}
+<?php
+return true;
+?>
 /***************
  Form
 ******************/
 .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;
 }
index f09d76a4bc0aa97e82e7cb6779b4dbf543fa7833..9f0ac730fd083db6d7cef06467a28b9d106244d0 100644 (file)
@@ -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 (file)
index 0000000..78ad125
--- /dev/null
@@ -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 (file)
index 0000000..0672a68
--- /dev/null
@@ -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