WordPress.org

Make WordPress Core

Changeset 16399


Ignore:
Timestamp:
11/16/2010 05:11:41 AM (10 years ago)
Author:
nacin
Message:

Internal linking functionality updates. Scrap pagination for a river of results. props koopersmith, see #11420.

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

Legend:

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

    r16393 r16399  
    1515                    file : tinymce.baseURL + '/wp-mce-link.php',
    1616                    width : 480,
    17                     height : 400,
     17                    height : 430,
    1818                    inline : 1
    1919                }, {
  • trunk/wp-includes/js/tinymce/plugins/wplink/editor_plugin.js

    r16393 r16399  
    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)})();
     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:430,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

    r16393 r16399  
    22    var inputs = {}, results = {}, ed,
    33    wpLink = {
     4        lastSearch: '',
     5        riverDefaults: function() {
     6            return {
     7                page : 2,
     8                allLoaded: false,
     9                active: false
     10            };
     11        },
    412        init : function() {
    5             var e, etarget, eclass;
     13            var e;
    614            // Init shared vars
    715            ed = tinyMCEPopup.editor;
     
    1826            results.search = $('#search-results');
    1927            results.recent = $('#most-recent-results');
     28            results.search.data('river', wpLink.riverDefaults() );
     29            results.recent.data('river', wpLink.riverDefaults() );
    2030           
    2131            // Bind event handlers
     
    2333            $('#wp-cancel').click( function() { tinyMCEPopup.close(); } );
    2434            $('.query-results').delegate('li', 'click', wpLink.selectInternalLink );
    25             $('.wp-results-pagelinks').delegate('a', 'click', wpLink.selectPageLink );
     35            $('.query-results').scroll( wpLink.maybeLoadRiver );
    2636            inputs.search.keyup( wpLink.searchInternalLinks );
    2737
     
    3545                    inputs.openInNewTab.attr('checked','checked');
    3646            }
     47           
     48            // Focus the URL field
     49            inputs.url.focus();
    3750        },
    3851       
     
    7588                // If no selection exists, create a new link from scratch.
    7689                if ( ed.selection.isCollapsed() ) {
    77                     var el = ed.dom.create('a', { href: "#mce_temp_url#" }, defaultContent);
     90                    el = ed.dom.create('a', { href: "#mce_temp_url#" }, defaultContent);
    7891                    ed.selection.setNode(el);
    7992                // If a selection exists, wrap it in a link.
     
    114127        },
    115128       
    116         selectPageLink : function(e) {
    117             var page = e.target.href.match(/page=(\d+)/);
    118            
    119             page = page ? page[1] : 1; // If there's no match, it's the first page.
    120             e.preventDefault(); // Prevent the link from redirecting.
    121            
    122             wpLink.linkAJAX( $(this), { page : page });
     129        maybeLoadRiver : function() {
     130            var t = $(this),
     131                ul = t.children('ul'),
     132                river = t.data('river'),
     133                waiting = t.find('.river-waiting');
     134           
     135            if( t.scrollTop() + t.height() != ul.height() || river.active || river.allLoaded )
     136                return;
     137           
     138            river.active = true;
     139            waiting.show();
     140           
     141            wpLink.linkAJAX( t, { page : river.page }, function(r) {
     142                river.page++;
     143                river.active = false;
     144                river.allLoaded = !r;
     145                waiting.hide();
     146            }, true);
    123147        },
    124148       
     
    127151                title = t.val();
    128152           
    129             if ( title ) {
     153            if ( title.length > 2 ) {
    130154                results.recent.hide();
    131155                results.search.show();
     156               
     157                // Don't search if the keypress didn't change the title.
     158                if ( wpLink.lastSearch == title )
     159                    return;
     160               
     161                wpLink.lastSearch = title;
    132162                waiting = t.siblings('img.waiting').show();
     163               
     164                results.search.data('river', wpLink.riverDefaults() );
     165                results.search.scrollTop(0);
    133166                wpLink.linkAJAX( results.search, { title : title }, function(){ waiting.hide(); });
    134167            } else {
     
    138171        },
    139172       
    140         linkAJAX : function( $panel, params, callback ) {
     173        linkAJAX : function( $panel, params, callback, append ) {
    141174            if ( ! $panel.hasClass('query-results') )
    142175                $panel = $panel.parents('.query-results');
     
    147180            $.post( ajaxurl, $.extend({
    148181                action : 'wp-link-ajax'
    149             }, params ), function(r) {
    150                 var pagelinks = $panel.children('.wp-results-pagelinks');
     182            }, params ), function( results ) {
     183                var list = '';
     184               
     185                if ( !results ) {
     186                    if ( !append ) {
     187                        list += '<li class="no-matches-found unselectable"><span class="item-title"><em>'
     188                        + wpLinkL10n.noMatchesFound
     189                        + '</em></span></li>';
     190                    }
     191                } else {
     192                    $.each( results, function() {
     193                        list += '<li><input type="hidden" class="item-permalink" value="' + this['permalink'] + '" />';
     194                        list += '<span class="item-title">';
     195                        list += this['title'] ? this['title'] : '<em>'+ wpLinkL10n.untitled + '</em>';
     196                        list += '</span><span class="item-info">' + this['info'] + '</span></li>';
     197                    });
     198                }
    151199               
    152200                // 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();
     201                $panel.children('ul')[ append ? 'append' : 'html' ]( list );
    160202               
    161203                // Run callback
    162204                if ( callback )
    163                     callback( r['results'] );
     205                    callback( results );
    164206            }, "json" );
    165         },
    166        
    167         generateListMarkup : function( results ) {
    168             var s = '';
    169            
    170             if ( ! results )
    171                 return '<li class="no-matches-found unselectable"><span class="item-title"><em>' + wpLinkL10n.noMatchesFound + '</em></span></li>';
    172            
    173             $.each( results, function() {
    174                 s+= '<li><input type="hidden" class="item-permalink" value="' + this['permalink'] + '" />';
    175                 s+= '<span class="item-title">'
    176                 s+= this['title'] ? this['title'] : '<em>'+ wpLinkL10n.untitled + '</em>';
    177                 s+= '</span><span class="item-info">' + this['info'] + '</span>';
    178                 s+= '</li>';
    179             });
    180             return s;
    181207        }
    182208    }
  • trunk/wp-includes/js/tinymce/plugins/wplink/js/wplink.js

    r16397 r16399  
    1 (function(d){var a={},c={},b,e={init:function(){var h,g,f;b=tinyMCEPopup.editor;a.url=d("#url-field");a.title=d("#link-title-field");a.openInNewTab=d("#link-target-checkbox");a.search=d("#search-field");c.search=d("#search-results");c.recent=d("#most-recent-results");d("#wp-update").click(e.update);d("#wp-cancel").click(function(){tinyMCEPopup.close()});d(".query-results").delegate("li","click",e.selectInternalLink);d(".wp-results-pagelinks").delegate("a","click",e.selectPageLink);a.search.keyup(e.searchInternalLinks);if(h=b.dom.getParent(b.selection.getNode(),"A")){a.url.val(h.href);a.title.val(b.dom.getAttrib(h,"title"));if("_blank"==b.dom.getAttrib(h,"target")){a.openInNewTab.attr("checked","checked")}}},update:function(){var j,g=tinyMCEPopup.editor,h={href:a.url.val(),title:a.title.val(),target:a.openInNewTab.attr("checked")?"_blank":""},k,f,i=h.title?h.title:h.href;tinyMCEPopup.restoreSelection();k=g.dom.getParent(g.selection.getNode(),"A");if(!h.href){if(g.selection.isCollapsed()){tinyMCEPopup.close();return}else{if(k){tinyMCEPopup.execCommand("mceBeginUndoLevel");f=g.selection.getBookmark();g.dom.remove(k,1);g.selection.moveToBookmark(f);tinyMCEPopup.execCommand("mceEndUndoLevel");tinyMCEPopup.close();return}}}tinyMCEPopup.execCommand("mceBeginUndoLevel");if(k==null){g.getDoc().execCommand("unlink",false,null);if(g.selection.isCollapsed()){var j=g.dom.create("a",{href:"#mce_temp_url#"},i);g.selection.setNode(j)}else{tinyMCEPopup.execCommand("CreateLink",false,"#mce_temp_url#",{skip_undo:1})}tinymce.each(g.dom.select("a"),function(l){if(g.dom.getAttrib(l,"href")=="#mce_temp_url#"){k=l;g.dom.setAttribs(k,h)}})}else{g.dom.setAttribs(k,h)}if(k.childNodes.length!=1||k.firstChild.nodeName!="IMG"){g.focus();g.selection.select(k);g.selection.collapse(0);tinyMCEPopup.storeSelection()}tinyMCEPopup.execCommand("mceEndUndoLevel");tinyMCEPopup.close()},selectInternalLink:function(){var f=d(this);if(f.hasClass("unselectable")){return}f.siblings(".selected").removeClass("selected");f.addClass("selected");a.url.val(f.children(".item-permalink").val());a.title.val(f.children(".item-title").text())},selectPageLink:function(g){var f=g.target.href.match(/page=(\d+)/);f=f?f[1]:1;g.preventDefault();e.linkAJAX(d(this),{page:f})},searchInternalLinks:function(){var f=d(this),h,g=f.val();if(g){c.recent.hide();c.search.show();h=f.siblings("img.waiting").show();e.linkAJAX(c.search,{title:g},function(){h.hide()})}else{c.search.hide();c.recent.show()}},linkAJAX:function(g,f,h){if(!g.hasClass("query-results")){g=g.parents(".query-results")}if(!g.length){return}d.post(ajaxurl,d.extend({action:"wp-link-ajax"},f),function(j){var i=g.children(".wp-results-pagelinks");g.children("ul").html(e.generateListMarkup(j.results));if(j.page_links){i.html(j.page_links).show()}else{i.hide()}if(h){h(j.results)}},"json")},generateListMarkup:function(f){var g="";if(!f){return'<li class="no-matches-found unselectable"><span class="item-title"><em>'+wpLinkL10n.noMatchesFound+"</em></span></li>"}d.each(f,function(){g+='<li><input type="hidden" class="item-permalink" value="'+this["permalink"]+'" />';g+='<span class="item-title">';g+=this["title"]?this["title"]:"<em>"+wpLinkL10n.untitled+"</em>";g+='</span><span class="item-info">'+this["info"]+"</span>";g+="</li>"});return g}};d(document).ready(e.init)})(jQuery);
     1(function(d){var a={},c={},b,e={lastSearch:"",riverDefaults:function(){return{page:2,allLoaded:false,active:false}},init:function(){var f;b=tinyMCEPopup.editor;a.url=d("#url-field");a.title=d("#link-title-field");a.openInNewTab=d("#link-target-checkbox");a.search=d("#search-field");c.search=d("#search-results");c.recent=d("#most-recent-results");c.search.data("river",e.riverDefaults());c.recent.data("river",e.riverDefaults());d("#wp-update").click(e.update);d("#wp-cancel").click(function(){tinyMCEPopup.close()});d(".query-results").delegate("li","click",e.selectInternalLink);d(".query-results").scroll(e.maybeLoadRiver);a.search.keyup(e.searchInternalLinks);if(f=b.dom.getParent(b.selection.getNode(),"A")){a.url.val(f.href);a.title.val(b.dom.getAttrib(f,"title"));if("_blank"==b.dom.getAttrib(f,"target")){a.openInNewTab.attr("checked","checked")}}a.url.focus()},update:function(){var j,g=tinyMCEPopup.editor,h={href:a.url.val(),title:a.title.val(),target:a.openInNewTab.attr("checked")?"_blank":""},k,f,i=h.title?h.title:h.href;tinyMCEPopup.restoreSelection();k=g.dom.getParent(g.selection.getNode(),"A");if(!h.href){if(g.selection.isCollapsed()){tinyMCEPopup.close();return}else{if(k){tinyMCEPopup.execCommand("mceBeginUndoLevel");f=g.selection.getBookmark();g.dom.remove(k,1);g.selection.moveToBookmark(f);tinyMCEPopup.execCommand("mceEndUndoLevel");tinyMCEPopup.close();return}}}tinyMCEPopup.execCommand("mceBeginUndoLevel");if(k==null){g.getDoc().execCommand("unlink",false,null);if(g.selection.isCollapsed()){j=g.dom.create("a",{href:"#mce_temp_url#"},i);g.selection.setNode(j)}else{tinyMCEPopup.execCommand("CreateLink",false,"#mce_temp_url#",{skip_undo:1})}tinymce.each(g.dom.select("a"),function(l){if(g.dom.getAttrib(l,"href")=="#mce_temp_url#"){k=l;g.dom.setAttribs(k,h)}})}else{g.dom.setAttribs(k,h)}if(k.childNodes.length!=1||k.firstChild.nodeName!="IMG"){g.focus();g.selection.select(k);g.selection.collapse(0);tinyMCEPopup.storeSelection()}tinyMCEPopup.execCommand("mceEndUndoLevel");tinyMCEPopup.close()},selectInternalLink:function(){var f=d(this);if(f.hasClass("unselectable")){return}f.siblings(".selected").removeClass("selected");f.addClass("selected");a.url.val(f.children(".item-permalink").val());a.title.val(f.children(".item-title").text())},maybeLoadRiver:function(){var g=d(this),f=g.children("ul"),h=g.data("river"),i=g.find(".river-waiting");if(g.scrollTop()+g.height()!=f.height()||h.active||h.allLoaded){return}h.active=true;i.show();e.linkAJAX(g,{page:h.page},function(j){h.page++;h.active=false;h.allLoaded=!j;i.hide()},true)},searchInternalLinks:function(){var f=d(this),h,g=f.val();if(g.length>2){c.recent.hide();c.search.show();if(e.lastSearch==g){return}e.lastSearch=g;h=f.siblings("img.waiting").show();c.search.data("river",e.riverDefaults());c.search.scrollTop(0);e.linkAJAX(c.search,{title:g},function(){h.hide()})}else{c.search.hide();c.recent.show()}},linkAJAX:function(h,g,i,f){if(!h.hasClass("query-results")){h=h.parents(".query-results")}if(!h.length){return}d.post(ajaxurl,d.extend({action:"wp-link-ajax"},g),function(j){var k="";if(!j){if(!f){k+='<li class="no-matches-found unselectable"><span class="item-title"><em>'+wpLinkL10n.noMatchesFound+"</em></span></li>"}}else{d.each(j,function(){k+='<li><input type="hidden" class="item-permalink" value="'+this["permalink"]+'" />';k+='<span class="item-title">';k+=this["title"]?this["title"]:"<em>"+wpLinkL10n.untitled+"</em>";k+='</span><span class="item-info">'+this["info"]+"</span></li>"})}h.children("ul")[f?"append":"html"](k);if(i){i(j)}},"json")}};d(document).ready(e.init)})(jQuery);
  • trunk/wp-includes/js/tinymce/wp-mce-link-includes.php

    r16393 r16399  
    2121        $query['s'] = $args['s'];
    2222
    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;
     23    $query['offset'] = $args['pagenum'] > 1 ? $query['posts_per_page'] * ( $args['pagenum'] - 1 ) : 0;
    2924
    3025    // Do main query.
     
    4843            'permalink' => get_permalink( $post->ID ),
    4944            'info' => $info,
    50         );;
     45        );
    5146    }
    5247
    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 
    62     // Build response.
    63     $resp = array(
    64         'query' => $get_posts,
    65         'objects' => $posts,
    66         'results' => $results,
    67         'pages' => $pagination,
    68     );
    69 
    70     return $resp;
     48    return $results;
    7149}
    7250
     
    7755    $args['pagenum'] = ! empty( $request['page'] ) ? absint( $request['page'] ) : 1;
    7856
    79     $resp = wp_link_query( $args );
     57    $results = wp_link_query( $args );
    8058
    81     if ( ! isset( $resp ) )
     59    if ( ! isset( $results ) )
    8260        die( '0' );
    83 
    84     $json = array( 'results' => $resp['results'] );
    85     if ( isset( $resp['pages'] ) && !empty( $resp['pages']['page_links'] ) )
    86         $json['page_links'] = $resp['pages']['page_links'];
    8761   
    88     echo json_encode( $json );
     62    echo json_encode( $results );
    8963    echo "\n";
    9064}
  • trunk/wp-includes/js/tinymce/wp-mce-link.php

    r16398 r16399  
    2424wp_print_scripts( array( 'jquery', 'jquery-ui-widget' ) );
    2525$suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '.dev' : '';
    26 $src = "plugins/wplink/js/wplink$suffix.js?ver=20101115";
     26$src = "plugins/wplink/js/wplink$suffix.js?ver=20101116";
    2727?>
    2828<script type="text/javascript" src="<?php echo $src; ?>"></script>
     
    127127#search-results {
    128128    display: none;
     129}
     130.river-waiting {
     131    display: none;
     132    padding: 10px 0;
     133}
     134.river-waiting img.waiting {
     135    margin: 0 auto;
     136    display: block;
    129137}
    130138.submitbox {
     
    158166        </label>
    159167        <label for="link-target-checkbox" id="open-in-new-tab">
    160             <input type="checkbox" id="link-target-checkbox" /><span><?php _e( 'Open in new tab' ); ?></span>
     168            <input type="checkbox" id="link-target-checkbox" /><span><?php _e( 'Open link in a new window/tab' ); ?></span>
    161169        </label>
    162170    </div>
     
    182190            <ul>
    183191                <li class="unselectable"><em><?php _e( 'No search term specified. Showing recent items.' ); ?></em></li>
    184                 <?php foreach ( $most_recent['results'] as $item ) : ?>
     192                <?php foreach ( $most_recent as $item ) : ?>
    185193                    <li>
    186194                        <input type="hidden" class="item-permalink" value="<?php echo esc_url( $item['permalink'] ); ?>" />
Note: See TracChangeset for help on using the changeset viewer.