Make WordPress Core

Changeset 16393


Ignore:
Timestamp:
11/15/2010 11:48:24 PM (14 years ago)
Author:
nacin
Message:

Next pass on internal linking. Functional, but needs styling. props koopersmith, see #11420.

Location:
trunk/wp-includes/js/tinymce
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-includes/js/tinymce/plugins/wplink/editor_plugin.dev.js

    r15940 r16393  
    1414                ed.windowManager.open({
    1515                    file : tinymce.baseURL + '/wp-mce-link.php',
    16                     width : 320,
    17                     height : 340,
     16                    width : 480,
     17                    height : 400,
    1818                    inline : 1
    1919                }, {
  • trunk/wp-includes/js/tinymce/plugins/wplink/editor_plugin.js

    r15940 r16393  
    1 (function(){tinymce.create("tinymce.plugins.wpLink",{init:function(a,b){a.addCommand("WP_Link",function(){a.windowManager.open({file:tinymce.baseURL+"/wp-mce-link.php",width:320,height:340,inline:1},{plugin_url:b})});a.addButton("link",{title:a.getLang("advanced.link_desc"),cmd:"WP_Link"});a.addShortcut("alt+shift+a",a.getLang("advanced.link_desc"),"WP_Link");a.onNodeChange.add(function(d,c,e){c.setActive("wplink",e.nodeName=="A")})},getInfo:function(){return{longname:"WordPress Link Dialog",author:"WordPress",authorurl:"http://wordpress.org",infourl:"",version:"1.0"}}});tinymce.PluginManager.add("wplink",tinymce.plugins.wpLink)})();
     1(function(){tinymce.create("tinymce.plugins.wpLink",{init:function(a,b){a.addCommand("WP_Link",function(){a.windowManager.open({file:tinymce.baseURL+"/wp-mce-link.php",width:480,height:400,inline:1},{plugin_url:b})});a.addButton("link",{title:a.getLang("advanced.link_desc"),cmd:"WP_Link"});a.addShortcut("alt+shift+a",a.getLang("advanced.link_desc"),"WP_Link");a.onNodeChange.add(function(d,c,e){c.setActive("wplink",e.nodeName=="A")})},getInfo:function(){return{longname:"WordPress Link Dialog",author:"WordPress",authorurl:"http://wordpress.org",infourl:"",version:"1.0"}}});tinymce.PluginManager.add("wplink",tinymce.plugins.wpLink)})();
  • trunk/wp-includes/js/tinymce/plugins/wplink/js/wplink.dev.js

    r16391 r16393  
    1 (function($){
    2     $.widget('wp.wpTabs', {
    3         options: {},
    4         _create: function() {
    5             var self = this,
    6                 ul = this.element,
    7                 lis = ul.children();
    8            
    9             this.active = lis.filter('.wp-tab-active');
    10             // Calculate panel IDs
    11             lis.each(function() {
    12                 var panel = self._getPanel( $(this) );
    13                 if ( self.active[0] == this )
    14                     panel.show();
    15                 else
    16                     panel.hide();
    17             });
    18            
    19             ul.delegate('li', 'click.wpTabs', function(e) {
    20                 var li = $(this);
    21                
    22                 // Prevent any child link from redirecting the page.
    23                 e.preventDefault();
    24                 // Deactivate previous tab.
    25                 self._getPanel( self.active ).hide();
    26                 self.active.removeClass('wp-tab-active');
    27                 self._trigger("hide", e, self.widget() );
    28                
    29                 // Activate current tab.
    30                 self.active = li.addClass('wp-tab-active');
    31                 self._getPanel( self.active ).show();
    32                 self._trigger("show", e, self.widget() );
    33             });
    34         },
    35         widget: function() {
    36             return {
    37                 ul: this.element,
    38                 tab: this.active,
    39                 panel: this._getPanel( this.active )
    40             };
    41         },
    42         _setPanel: function( $el ) {
    43             var panel = $( '#' + $el.children('.wp-tab-for-id').val() );
    44             $el.data( 'wp-tab-panel', panel );
    45             return panel;
    46         },
    47         _getPanel: function( $el ) {
    48             var panel = $el.data('wp-tab-panel');
    49             return ( !panel || !panel.length ) ? this._setPanel( $el ) : panel;
    50         }
    51     });
    52     // Create tab bars by default.
    53     $(function(){
    54         $('.wp-tab-bar').wpTabs();
    55     });
    56 })(jQuery);
    57 
    581(function($){   
    59     var inputs = {}, panels, active, ed,
     2    var inputs = {}, results = {}, ed,
    603    wpLink = {
    614        init : function() {
     
    636            // Init shared vars
    647            ed = tinyMCEPopup.editor;
     8           
     9           
     10            // URL
     11            inputs.url = $('#url-field');
    6512            // Secondary options
    6613            inputs.title = $('#link-title-field');
    6714            // Advanced Options
    6815            inputs.openInNewTab = $('#link-target-checkbox');
    69            
    70             panels = $('.link-panel');
    71             active = $('.link-panel-active');
    72             $('#link-panel-tab-bar').wpTabs({
    73                 show: function(e, widget) {
    74                     active = widget.panel;
    75                     active.addClass('link-panel-active');
    76                     wpLink.maybeLoadPanel();
    77                 },
    78                 hide: function(e, widget) {
    79                     active.removeClass('link-panel-active');
    80                 }
    81             })
    82            
    83             panels.each( function(){
    84                 var linkType = this.id.replace(/^link-panel-id-/,''),
    85                     parts = linkType.split('-');
    86                 $(this).data( 'link-type', {
    87                     full : linkType,
    88                     type : parts[0],
    89                     name : parts[1] || ''
    90                 });
    91             });
     16            inputs.search = $('#search-field');
     17            // Result lists
     18            results.search = $('#search-results');
     19            results.recent = $('#most-recent-results');
    9220           
    9321            // Bind event handlers
    9422            $('#wp-update').click( wpLink.update );
    9523            $('#wp-cancel').click( function() { tinyMCEPopup.close(); } );
    96             $('.link-panel .wp-tab-bar').wpTabs('option', 'show', wpLink.maybeLoadPanel );
    97             $('.link-panel .wp-tab-panel').delegate('li', 'click', wpLink.selectInternalLink );
    98             $('.wp-tab-panel-pagelinks').delegate('a', 'click', wpLink.selectPageLink );
    99             $('.link-panel .link-search-field').keyup( wpLink.searchInternalLinks );
    100 
    101             active.find('input.url-field').focus();
     24            $('.query-results').delegate('li', 'click', wpLink.selectInternalLink );
     25            $('.wp-results-pagelinks').delegate('a', 'click', wpLink.selectPageLink );
     26            inputs.search.keyup( wpLink.searchInternalLinks );
    10227
    10328            // If link exists, select proper values.
    104             e = ed.dom.getParent(ed.selection.getNode(), 'A');
    105             if ( ! e )
    106                 return;
    107            
    108             active.find('input.url-field').val( e.href );
    109             inputs.title.val( ed.dom.getAttrib(e, 'title') );
    110             // Advanced Options
    111            
    112             if ( "_blank" == ed.dom.getAttrib(e, 'target') )
    113                 inputs.openInNewTab.attr('checked','checked');
     29            if ( e = ed.dom.getParent(ed.selection.getNode(), 'A') ) {
     30                // Set URL and description.
     31                inputs.url.val( e.href );
     32                inputs.title.val( ed.dom.getAttrib(e, 'title') );
     33                // Set open in new tab.
     34                if ( "_blank" == ed.dom.getAttrib(e, 'target') )
     35                    inputs.openInNewTab.attr('checked','checked');
     36            }
    11437        },
    11538       
     
    11841                ed = tinyMCEPopup.editor,
    11942                attrs = {
     43                    href : inputs.url.val(),
    12044                    title : inputs.title.val(),
    12145                    target : inputs.openInNewTab.attr('checked') ? '_blank' : ''
    122                 }, defaultContent, e, b;
    123            
    124             if ( active.hasClass('link-panel-custom') ) {
    125                 attrs.href = active.find('input.url-field').val();
    126                 defaultContent = attrs.href;
    127             } else {
    128                 el = active.find('li.selected:visible');
    129                 if ( !el.length )
    130                     return;
    131                
    132                 attrs.href = el.children('input').val();
    133                 defaultContent = el.text();
    134             }
     46                }, e, b,
     47                defaultContent = attrs.title ? attrs.title : attrs.href;
    13548           
    13649            tinyMCEPopup.restoreSelection();
     
    191104        },
    192105       
    193         maybeLoadPanel : function() {
    194             var panel = active.find('.wp-tab-panel:visible');
    195             if ( panel.length && panel.find('.wp-tab-panel-loading').length )
    196                 wpLink.linkPanelAJAX( panel );
    197         },
    198        
    199         linkPanelAJAX : function( $panel, params, callback ) {
    200             if ( ! $panel.hasClass('wp-tab-panel') )
    201                 $panel = $panel.parents('.wp-tab-panel');
    202            
    203             if ( ! $panel.length )
    204                 return;
    205                
    206             var query = $panel.children('.wp-tab-panel-query').val();
    207            
    208             wpLink.linkAJAX( $panel, $.extend({
    209                 preset : query,
    210                 page : 'all' == query ? 1 : 0
    211             }, params), function(r, lt) {
    212                 var pagelinks = $panel.children('.wp-tab-panel-pagelinks');
    213                
    214                 // Set results
    215                 $panel.children('ul').html( wpLink.generateListMarkup( r['results'], lt ) );
    216                
    217                 // Handle page links
    218                 if ( r['page_links'] )
    219                     pagelinks.html( r['page_links'] ).show();
    220                 else
    221                     pagelinks.hide();
    222                 // Run callback
    223                 if ( callback )
    224                     callback(r, lt);
    225             })
    226         },
    227        
    228106        selectInternalLink : function() {
    229107            var t = $(this);
     
    232110            t.siblings('.selected').removeClass('selected');
    233111            t.addClass('selected');
     112            inputs.url.val( t.children('.item-permalink').val() );
     113            inputs.title.val( t.children('.item-title').text() );
    234114        },
    235115       
     
    240120            e.preventDefault(); // Prevent the link from redirecting.
    241121           
    242             wpLink.linkPanelAJAX( $(this), { page : page });
     122            wpLink.linkAJAX( $(this), { page : page });
    243123        },
    244124       
    245125        searchInternalLinks : function() {
    246             var t = $(this),
     126            var t = $(this), waiting,
     127                title = t.val();
     128           
     129            if ( title ) {
     130                results.recent.hide();
     131                results.search.show();
    247132                waiting = t.siblings('img.waiting').show();
    248                
    249             wpLink.linkPanelAJAX( t, { title : t.val() }, function(){ waiting.hide(); });
     133                wpLink.linkAJAX( results.search, { title : title }, function(){ waiting.hide(); });
     134            } else {
     135                results.search.hide();
     136                results.recent.show();
     137            }
    250138        },
    251139       
    252         linkAJAX : function( el, params, callback ) {
    253             var linkType = el.parents('.link-panel').data('link-type');
     140        linkAJAX : function( $panel, params, callback ) {
     141            if ( ! $panel.hasClass('query-results') )
     142                $panel = $panel.parents('.query-results');
     143           
     144            if ( ! $panel.length )
     145                return;
     146           
    254147            $.post( ajaxurl, $.extend({
    255                 action : 'wp-link-ajax',
    256                 type : linkType.type,
    257                 name : linkType.name
     148                action : 'wp-link-ajax'
    258149            }, params ), function(r) {
    259                 return callback(r, linkType);
     150                var pagelinks = $panel.children('.wp-results-pagelinks');
     151               
     152                // Set results
     153                $panel.children('ul').html( wpLink.generateListMarkup( r['results'] ) );
     154               
     155                // Handle page links
     156                if ( r['page_links'] )
     157                    pagelinks.html( r['page_links'] ).show();
     158                else
     159                    pagelinks.hide();
     160               
     161                // Run callback
     162                if ( callback )
     163                    callback( r['results'] );
    260164            }, "json" );
    261165        },
    262166       
    263         generateListMarkup : function( results, linkType ) {
     167        generateListMarkup : function( results ) {
    264168            var s = '';
    265169           
    266170            if ( ! results )
    267                 return '<li class="no-matches-found unselectable"><em>' + wpLinkL10n.noMatchesFound + '</em></li>';
     171                return '<li class="no-matches-found unselectable"><span class="item-title"><em>' + wpLinkL10n.noMatchesFound + '</em></span></li>';
    268172           
    269173            $.each( results, function() {
    270                 s+= '<li id="link-to-' + linkType.full + '-' + this['ID'] + '">';
    271                 s+= '<input type="hidden" value="' + this['permalink'] + '" />';
     174                s+= '<li><input type="hidden" class="item-permalink" value="' + this['permalink'] + '" />';
     175                s+= '<span class="item-title">'
    272176                s+= this['title'] ? this['title'] : '<em>'+ wpLinkL10n.untitled + '</em>';
     177                s+= '</span><span class="item-info">' + this['info'] + '</span>';
    273178                s+= '</li>';
    274179            });
  • trunk/wp-includes/js/tinymce/wp-mce-link-includes.php

    r16159 r16393  
    11<?php
     2// args expects optionally 'pagenum' and 's'
     3function wp_link_query( $args = array() ) {
     4    $pts = get_post_types( array( 'publicly_queryable' => true ), 'objects' );
     5    $pt_names = array_keys( $pts );
    26   
    3 class WP_Tab_Bar {
    4     var $tabs = array();
    5    
    6     var $id = '';
    7     var $classes = array();
    8    
    9     var $selected = '';
    10    
    11     function add( $id, $label, $url='' ) {
    12         array_push( $this->tabs, array(
    13             'label' => $label,
    14             'for' => $id,
    15             'url' => $url
    16         ));
    17     }
    18    
    19     function select( $id ) {
    20         $this->selected = $id;
    21     }
    22    
    23     function render( $echo=true ) {
    24         if ( empty( $this->selected ) )
    25             $this->selected = $this->tabs[0]['for'];
    26 
    27         array_unshift( $this->classes, 'wp-tab-bar' );
    28        
    29         $out = "<ul id='$this->id' class='" . esc_attr( implode( ' ', $this->classes ) ) . "'>";
    30         foreach( $this->tabs as $tab ) {
    31             if ( !isset($tab['url']) )
    32                 $tab['url'] = '';
    33 
    34             $out.= "<li class='";
    35             $out.= $this->selected == $tab['for'] ? 'wp-tab-active' : '';
    36             $out.= "'><input type='hidden' class='wp-tab-for-id' value='{$tab['for']}' />";
    37             $out.= "<a href='{$tab['url']}#{$tab['for']}'>";
    38             $out.= "{$tab['label']}</a></li>";
    39         }
    40         $out.= "</ul>";
    41 
    42         if ( $echo )
    43             echo $out;
    44 
    45         return $out;
    46     }
    47 }
    48 
    49 function wp_link_panel_custom() { ?>
    50     <div id="link-panel-id-custom" class="link-panel link-panel-custom link-panel-active">
    51         <input type="hidden" class="link-panel-type" value="custom" />
    52         <label>
    53             <span><?php _e('URL:'); ?></span><input class="url-field" type="text" />
    54         </label>
    55     </div>
    56 <?php }
    57 
    58 function wp_link_panel_structure( $panel_type, $name, $queries ) {
    59     $id = $panel_type . '-' . $name;
    60    
    61     ?>
    62     <div id="link-panel-id-<?php echo $id; ?>" class="link-panel link-panel-<?php echo $panel_type; ?>">
    63         <!-- <input type="hidden" class="link-panel-type" value="<?php echo $panel_type; ?>" /> -->
    64         <!-- <input type="hidden" class="link-panel-id" value="" /> -->
    65         <?php
    66        
    67         $tb = new WP_Tab_Bar();
    68         foreach( $queries as $i => $query ) {
    69             $queries[$i]['id'] = "$id-{$query['preset']}";
    70             $tb->add( $queries[$i]['id'], $query['label'] );
    71         }
    72         $tb->render();
    73 
    74         foreach( $queries as $query ): ?>
    75             <div id="<?php echo $query['id']; ?>" class="wp-tab-panel">
    76                 <input type="hidden" class="wp-tab-panel-query" value="<?php echo $query['preset']; ?>" />
    77                
    78             <?php if ( 'search' == $query['preset'] ): ?>
    79                 <label for="<?php echo $id; ?>-search-field" class="link-search-wrapper">
    80                     <span><?php _e('Search:'); ?></span>
    81                     <input type="text" id="<?php echo $id; ?>-search-field" class="link-search-field" />
    82                     <img class="waiting" src="<?php echo esc_url( admin_url( 'images/wpspin_light.gif' ) ); ?>" alt="" />
    83                 </label>
    84                 <ul id="<?php echo $id; ?>-search-results" class="link-search-results"></ul>
    85                
    86             <?php else: ?>
    87                 <div class="wp-tab-panel-pagelinks wp-tab-panel-pagelinks-top"></div>
    88                 <ul>
    89                     <li class="wp-tab-panel-loading unselectable"><em><?php _e('Loading...'); ?></em></li>
    90                 </ul>
    91                 <div class="wp-tab-panel-pagelinks wp-tab-panel-pagelinks-bottom"></div>
    92             <?php endif; ?>
    93             </div>
    94         <?php endforeach; ?>
    95     </div>
    96 <?php }
    97 
    98 function wp_link_query_post_type( $pt_obj, $preset='all', $opts=array() ) {
    99     $args_base = array(
    100         'post_type' => $pt_obj->name,
     7    $query = array(
     8        'post_type' => $pt_names,
    1019        'suppress_filters' => true,
    10210        'update_post_term_cache' => false,
    10311        'update_post_meta_cache' => false,
    10412        'post_status' => 'publish',
     13        'order' => 'DESC',
     14        'orderby' => 'post_date',
     15        'posts_per_page' => 20,
    10516    );
    106    
    107     switch( $preset ) {
    108     case 'all':
    109         $args = array_merge( $args_base, array(
    110             'order' => 'ASC',
    111             'orderby' => 'title',
    112             'posts_per_page' => 20,
    113         ));
    114         break;
    115     case 'recent':
    116         $args = array_merge( $args_base, array(
    117             'order' => 'DESC',
    118             'orderby' => 'post_date',
    119             'posts_per_page' => 15,
    120         ));
    121         break;
    122     case 'search':
    123         $args = array_merge( $args_base, array(
    124             's' => isset($opts['search']) ? $opts['search'] : '',
    125             'posts_per_page' => 10
    126         ));
    127         break;
    128     }
    129    
    130     // Handle pages if a page number is specified.
    131     if ( isset( $opts['pagenum'] ) && isset( $args['posts_per_page'] ) ) {
    132         $pages = array(
    133             'current' => $opts['pagenum'],
    134             'per_page' => $args['posts_per_page']
    135         );
    136        
    137         if ( ! isset( $args['offset'] ) )
    138             $args['offset'] = 0 < $opts['pagenum'] ? $args['posts_per_page'] * ( $opts['pagenum'] - 1 ) : 0;
    139         $pages['offset'] = $args['offset'];
    140     }
    141    
    142     // Allow args to be extended.
    143     if ( isset( $opts['args'] ) )
    144         $args = array_merge( $args, $opts['args'] );
    145    
     17
     18    $args['pagenum'] = isset( $args['pagenum'] ) ? absint( $args['pagenum'] ) : 1;
     19
     20    if ( isset( $args['s'] ) )
     21        $query['s'] = $args['s'];
     22
     23    $pagination = array(
     24        'current'  => $args['pagenum'],
     25        'per_page' => $query['posts_per_page'],
     26    );
     27
     28    $query['offset'] = $pagination['offset'] = $args['pagenum'] > 1 ? $query['posts_per_page'] * ( $args['pagenum'] - 1 ) : 0;
     29
    14630    // Do main query.
    14731    $get_posts = new WP_Query;
    148     $posts = $get_posts->query( $args );
     32    $posts = $get_posts->query( $query );
    14933    // Check if any posts were found.
    15034    if ( ! $get_posts->post_count )
     
    15438    $results = array();
    15539    foreach ( $posts as $post ) {
     40        if ( 'post' == $post->post_type )
     41            $info = mysql2date( __( 'Y/m/d' ), $post->post_date );
     42        else
     43            $info = $pts[ $post->post_type ]->labels->singular_name;
     44       
    15645        $results[] = array(
    15746            'ID' => $post->ID,
    158             'title' => $post->post_title,
    159             'permalink' => get_permalink( $post->ID )
    160         );
     47            'title' => esc_html( strip_tags($post->post_title) ),
     48            'permalink' => get_permalink( $post->ID ),
     49            'info' => $info,
     50        );;
    16151    }
     52
     53    // Remaining pagination values.
     54    $pagination['max'] = $get_posts->max_num_pages;
     55    $pagination['page_links'] = paginate_links( array(
     56        'prev_text' => __('&laquo;'),
     57        'next_text' => __('&raquo;'),
     58        'total' => $pagination['max'],
     59        'current' => $pagination['current']
     60    ) );
     61
    16262    // Build response.
    16363    $resp = array(
    16464        'query' => $get_posts,
    16565        'objects' => $posts,
    166         'results' => $results
     66        'results' => $results,
     67        'pages' => $pagination,
    16768    );
    168    
    169     // Set remaining pages values.
    170     if ( isset( $pages ) ) {
    171         $pages['max'] = $resp['query']->max_num_pages;
    172         $pages['page_links'] = paginate_links( array(
    173             'prev_text' => __('&laquo;'),
    174             'next_text' => __('&raquo;'),
    175             'total' => $pages['max'],
    176             'current' => $pages['current']
    177         ));
    178         $resp['pages'] = $pages;
    179     }
    180    
     69
    18170    return $resp;
    18271}
    18372
    18473function wp_link_ajax( $request ) {
    185     if ( !isset($request['type']) || !isset($request['name']) || !isset($request['preset']) )
    186         die('-1');
     74    // Searches have a title term.
     75    if ( isset( $request['title'] ) )
     76        $args['s'] = stripslashes( $request['title'] );
     77    $args['pagenum'] = ! empty( $request['page'] ) ? absint( $request['page'] ) : 1;
    18778
    188     // Run only presets we recognize.
    189     if ( 'pt' != $request['type'] || ! in_array( $request['preset'], array('all','search','recent') ) )
    190         die('-1');
    191     // Searches must have a search term.
    192     else if ( 'search' == $request['preset'] && !isset($request['title']) )
    193         die('-1');
    194 
    195     $opts = array();
    196     if ( 'search' == $request['preset'] ) {
    197         $opts['search'] = $request['title'];
    198     } else if ( ! empty( $request['page'] ) ) {
    199         $opts['pagenum'] = $request['page'];
    200     }
    201        
    202     if ( 'pt' == $request['type'] && $obj = get_post_type_object($request['name']) )
    203         $resp = wp_link_query_post_type( $obj, $request['preset'], $opts );
     79    $resp = wp_link_query( $args );
    20480
    20581    if ( ! isset( $resp ) )
    206         die('0');
     82        die( '0' );
    20783
    20884    $json = array( 'results' => $resp['results'] );
     
    21389    echo "\n";
    21490}
     91
    21592?>
  • trunk/wp-includes/js/tinymce/wp-mce-link.php

    r16159 r16393  
    2424wp_print_scripts( array('jquery', 'jquery-ui-widget') );
    2525?>
    26 <script type="text/javascript" src="plugins/wplink/js/wplink.js?ver=20101023"></script>
     26<?php
     27    $suffix = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ? '.dev' : '';
     28    $src = "plugins/wplink/js/wplink$suffix.js?ver=20101023";
     29?>
     30<script type="text/javascript" src="<?php echo $src; ?>"></script>
    2731<?php
    2832wp_admin_css( 'global', true );
     
    4448}
    4549
    46 #link-header,
    4750#link-options,
    4851#link-advanced-options {
     
    5053    border-bottom: 1px solid #dfdfdf;
    5154}
    52     #link-header {
    53         padding-bottom: 0;
    54         background: #fff;
    55     }
    56     #link-panel-tab-bar li {
    57         font-weight: bold;
    58         border: #dfdfdf solid;
    59         margin-right: 5px;
    60         border-width: 1px 1px 0;
    61     }
    62     #link-panel-tab-bar .wp-tab-active {
    63         border-color:#ccc;
    64         background-color: #f1f1f1;
    65     }
    6655
    6756#link-type {
     
    7867
    7968label input[type="text"] {
    80     width: 220px;
    81 }
    82     .wp-tab-panel label input[type="text"] {
    83         float: left;
    84         width: 200px;
    85     }
     69    width: 360px;
     70    margin-top: 5px;
     71}
    8672
    8773label span {
     
    9177    padding-right: 5px;
    9278}
    93     .wp-tab-panel label span {
    94         width: auto;
    95         text-align: left;
    96         float: left;
    97         margin-top: 3px;
    98     }
    9979    .link-search-wrapper {
    10080        padding: 5px;
    101         border-bottom: solid 1px #dfdfdf;
    10281        display: block;
    10382        overflow: hidden;
    10483    }
     84        .link-search-wrapper span {
     85            float: left;
     86            margin-top: 6px;
     87        }
     88        .link-search-wrapper input[type="text"] {
     89            float: left;
     90            width: 220px;
     91        }
    10592        .link-search-wrapper img.waiting {
    106             margin: 4px 1px 0 4px;
     93            margin: 8px 1px 0 4px;
    10794            float: left;
    10895            display: none;
     
    117104        font-size: 11px;
    118105    }
     106   
     107.query-results {
     108    border: #dfdfdf solid;
     109    border-width: 1px 0;
     110    margin: 5px 0;
     111    background: #fff;
     112    height: 220px;
     113    overflow: auto;
     114}
     115    .query-results li {
     116        margin-bottom: 0;
     117        border-bottom: 1px solid #dfdfdf;
     118        color: #555;
     119        padding: 4px 6px;
     120        cursor: pointer;
     121    }
     122    .query-results li:hover {
     123        background: #EAF2FA;
     124        color: #333;
     125    }
     126    .query-results li.selected {
     127        background: #f1f1f1;
     128        font-weight: bold;
     129        color: #333;
     130    }
     131.item-info {
     132    text-transform: uppercase;
     133    color: #aaa;
     134    font-weight: bold;
     135    font-size: 11px;
     136    float: right;
     137}
     138#search-results {
     139    display: none;
     140}
     141   
     142.wp-results-pagelinks {
     143    padding:4px 0;
     144    margin:0 auto;
     145    text-align:center;
     146}
     147    .wp-results-pagelinks-top {
     148        border-bottom: 1px solid #dfdfdf;
     149    }
    119150
    120151.submitbox {
    121     padding: 5px;
     152    padding: 5px 5px 0;
    122153    font-size: 11px;
    123154    overflow: auto;
     
    135166    display: inline-block;
    136167}
    137 .wp-tab-active,
    138 .wp-tab-panel {
    139     background: #fff;
    140 }
    141     .wp-tab-panel {
    142         height: 160px;
    143         padding: 0;
    144     }
    145 .wp-tab-panel li {
    146     margin-bottom: 0;
    147     border-bottom: 1px solid #dfdfdf;
    148     color: #555;
    149     padding: 4px 6px;
    150     cursor: pointer;
    151 }
    152     .wp-tab-panel li:hover {
    153         background: #EAF2FA;
    154         color: #333;
    155     }
    156     .wp-tab-panel li.selected {
    157         background: #f1f1f1;
    158         font-weight: bold;
    159         color: #333;
    160     }
    161 .wp-tab-panel-pagelinks {
    162     display: none;
    163     padding:4px 0;
    164     margin:0 auto;
    165     text-align:center;
    166 }
    167     .wp-tab-panel-pagelinks-top {
    168         border-bottom: 1px solid #dfdfdf;
    169     }
    170168</style>
    171169</head>
    172170<?php
    173 // @TODO: Support custom post types.
    174 // $pts = get_post_types( array( 'public' => true ), 'objects' );
    175 $pts = array( get_post_type_object( 'post' ), get_post_type_object( 'page' ) );
    176 $queries = array(
    177     array( 'preset' => 'all', 'label' => __('View All') ),
    178     array( 'preset' => 'recent', 'label' => __('Most Recent') ),
    179     array( 'preset' => 'search', 'label' => __('Search') )
    180 );
    181 
    182 $tb = new WP_Tab_Bar();
    183 $tb->id = 'link-panel-tab-bar';
    184 $tb->add( 'link-panel-id-custom', __('External Link') );
    185 foreach( $pts as $pt ) {
    186     $tb->add( "link-panel-id-pt-$pt->name", $pt->labels->singular_name );
    187 }
    188171
    189172
    190173?>
    191174<body id="post-body">
    192 <div id="link-header">
    193     <?php $tb->render(); ?>
    194 </div>
    195175<div id="link-selector">
    196     <?php
    197     wp_link_panel_custom();
    198     foreach( $pts as $pt )
    199         wp_link_panel_structure('pt', $pt->name, $queries);
    200     ?>
    201176    <div id="link-options">
     177        <label for="url-field">
     178            <span><?php _e('URL:'); ?></span><input id="url-field" type="text" />
     179        </label>
    202180        <label for="link-title-field">
    203181            <span><?php _e('Description:'); ?></span><input id="link-title-field" type="text" />
     
    206184            <input type="checkbox" id="link-target-checkbox" /><span><?php _e('Open in new tab'); ?></span>
    207185        </label>
     186    </div>
     187    <div id="search-panel">
     188        <label for="search-field" class="link-search-wrapper">
     189            <span><?php _e('Search:'); ?></span>
     190            <input type="text" id="search-field" class="link-search-field" />
     191            <img class="waiting" src="<?php echo esc_url( admin_url( 'images/wpspin_light.gif' ) ); ?>" alt="" />
     192        </label>
     193       
     194        <div id="search-results" class="query-results">
     195            <div class="wp-results-pagelinks wp-results-pagelinks-top"></div>
     196            <ul>
     197                <li class="wp-results-loading unselectable"><em><?php _e('Loading...'); ?></em></li>
     198            </ul>
     199            <div class="wp-results-pagelinks wp-results-pagelinks-bottom"></div>
     200        </div>
     201       
     202        <?php $most_recent = wp_link_query(); ?>
     203        <div id="most-recent-results" class="query-results">
     204            <div class="wp-results-pagelinks wp-results-pagelinks-top">
     205                <?php echo $most_recent['pages']['page_links']; ?>
     206            </div>
     207            <ul>
     208                <?php foreach ( $most_recent['results'] as $item ): ?>
     209                    <li>
     210                        <input type="hidden" class="item-permalink" value="<?php echo esc_url( $item['permalink'] ); ?>" />
     211                        <span class="item-title"><?php echo $item['title']; ?></span>
     212                        <span class="item-info"><?php echo esc_html( $item['info'] ); ?></span>
     213                    </li>
     214                <?php endforeach; ?>
     215            </ul>
     216            <div class="wp-results-pagelinks wp-results-pagelinks-bottom">
     217                <?php echo $most_recent['pages']['page_links']; ?>
     218            </div>
     219        </div>
    208220    </div>
    209221</div>
Note: See TracChangeset for help on using the changeset viewer.