]> scripts.mit.edu Git - autoinstalls/wordpress.git/blobdiff - wp-admin/js/post.dev.js
Wordpress 3.0.5
[autoinstalls/wordpress.git] / wp-admin / js / post.dev.js
index 6621003693da347077853554560adecfcda72bb8..9a39e08f5bf55492f18b9fc89066f89d52fc89f9 100644 (file)
@@ -36,24 +36,39 @@ tagBox = {
        },
 
        quickClicks : function(el) {
-               var thetags = $('.the-tags', el), tagchecklist = $('.tagchecklist', el), current_tags;
+               var thetags = $('.the-tags', el),
+                       tagchecklist = $('.tagchecklist', el),
+                       id = $(el).attr('id'),
+                       current_tags, disabled;
 
                if ( !thetags.length )
                        return;
 
+               disabled = thetags.attr('disabled');
+
                current_tags = thetags.val().split(',');
                tagchecklist.empty();
 
                $.each( current_tags, function( key, val ) {
-                       var txt, button_id, id = $(el).attr('id');
+                       var span, xbutton;
 
-                       val = $.trim(val);
-                       if ( !val.match(/^\s+$/) && '' != val ) {
-                               button_id = id + '-check-num-' + key;
-                               txt = '<span><a id="' + button_id + '" class="ntdelbutton">X</a>&nbsp;' + val + '</span> ';
-                               tagchecklist.append(txt);
-                               $( '#' + button_id ).click( function(){ tagBox.parseTags(this); });
+                       val = $.trim( val );
+
+                       if ( ! val )
+                               return;
+
+                       // Create a new span, and ensure the text is properly escaped.
+                       span = $('<span />').text( val );
+
+                       // If tags editing isn't disabled, create the X button.
+                       if ( ! disabled ) {
+                               xbutton = $( '<a id="' + id + '-check-num-' + key + '" class="ntdelbutton">X</a>' );
+                               xbutton.click( function(){ tagBox.parseTags(this); });
+                               span.prepend('&nbsp;').prepend( xbutton );
                        }
+
+                       // Append the span to the tag list.
+                       tagchecklist.append( span );
                });
        },
 
@@ -107,14 +122,14 @@ tagBox = {
                });
 
                $('div.taghint', ajaxtag).click(function(){
-                       $(this).css('visibility', 'hidden').siblings('.newtag').focus();
+                       $(this).css('visibility', 'hidden').parent().siblings('.newtag').focus();
                });
 
                $('input.newtag', ajaxtag).blur(function() {
                        if ( this.value == '' )
-                   $(this).siblings('.taghint').css('visibility', '');
+                   $(this).parent().siblings('.taghint').css('visibility', '');
            }).focus(function(){
-                       $(this).siblings('.taghint').css('visibility', 'hidden');
+                       $(this).parent().siblings('.taghint').css('visibility', 'hidden');
                }).keyup(function(e){
                        if ( 13 == e.which ) {
                                tagBox.flushTags( $(this).closest('.tagsdiv') );
@@ -127,7 +142,7 @@ tagBox = {
                        }
                }).each(function(){
                        var tax = $(this).closest('div.tagsdiv').attr('id');
-                       $(this).suggest( ajaxurl + '?action=ajax-tag-search&tax=' + tax, { delay: 500, minchars: 2, multiple: true, multipleSep: ", " } );
+                       $(this).suggest( ajaxurl + '?action=ajax-tag-search&tax=' + tax, { delay: 500, minchars: 2, multiple: true, multipleSep: "," } );
                });
 
            // save tags on post save/publish
@@ -212,9 +227,9 @@ WPSetThumbnailID = function(id){
        }
 };
 
-WPRemoveThumbnail = function(){
+WPRemoveThumbnail = function(nonce){
        $.post(ajaxurl, {
-               action:"set-post-thumbnail", post_id: $('#post_ID').val(), thumbnail_id: -1, cookie: encodeURIComponent(document.cookie)
+               action:"set-post-thumbnail", post_id: $('#post_ID').val(), thumbnail_id: -1, _ajax_nonce: nonce, cookie: encodeURIComponent(document.cookie)
        }, function(str){
                if ( str == '0' ) {
                        alert( setPostThumbnailL10n.error );
@@ -228,13 +243,9 @@ WPRemoveThumbnail = function(){
 })(jQuery);
 
 jQuery(document).ready( function($) {
-       var catAddAfter, stamp, visibility, sticky = '', post = 'post' == pagenow || 'post-new' == pagenow, page = 'page' == pagenow || 'page-new' == pagenow;
+       var stamp, visibility, sticky = '';
 
-       // postboxes
-       if ( post )
-               postboxes.add_postbox_toggles('post');
-       else if ( page )
-               postboxes.add_postbox_toggles('page');
+       postboxes.add_postbox_toggles(pagenow);
 
        // multi-taxonomies
        if ( $('#tagsdiv-post_tag').length ) {
@@ -249,35 +260,54 @@ jQuery(document).ready( function($) {
        }
 
        // categories
-       if ( $('#categorydiv').length ) {
+       $('.categorydiv').each( function(){
+               var this_id = $(this).attr('id'), noSyncChecks = false, syncChecks, catAddAfter, taxonomyParts, taxonomy, settingName;
+
+               taxonomyParts = this_id.split('-');
+               taxonomyParts.shift();
+               taxonomy = taxonomyParts.join('-');
+               settingName = taxonomy + '_tab';
+               if ( taxonomy == 'category' )
+                       settingName = 'cats';
+
                // TODO: move to jQuery 1.3+, support for multiple hierarchical taxonomies, see wp-lists.dev.js
-               $('a', '#category-tabs').click(function(){
+               $('a', '#' + taxonomy + '-tabs').click( function(){
                        var t = $(this).attr('href');
                        $(this).parent().addClass('tabs').siblings('li').removeClass('tabs');
-                       $('#category-tabs').siblings('.tabs-panel').hide();
+                       $('#' + taxonomy + '-tabs').siblings('.tabs-panel').hide();
                        $(t).show();
-                       if ( '#categories-all' == t )
-                               deleteUserSetting('cats');
+                       if ( '#' + taxonomy + '-all' == t )
+                               deleteUserSetting(settingName);
                        else
-                               setUserSetting('cats','pop');
+                               setUserSetting(settingName, 'pop');
                        return false;
                });
-               if ( getUserSetting('cats') )
-                       $('a[href="#categories-pop"]', '#category-tabs').click();
+
+               if ( getUserSetting(settingName) )
+                       $('a[href="#' + taxonomy + '-pop"]', '#' + taxonomy + '-tabs').click();
 
                // Ajax Cat
-               $('#newcat').one( 'focus', function() { $(this).val( '' ).removeClass( 'form-input-tip' ) } );
-               $('#category-add-sumbit').click( function(){ $('#newcat').focus(); } );
+               $('#new' + taxonomy).one( 'focus', function() { $(this).val( '' ).removeClass( 'form-input-tip' ) } );
+               $('#' + taxonomy + '-add-submit').click( function(){ $('#new' + taxonomy).focus(); });
+
+               syncChecks = function() {
+                       if ( noSyncChecks )
+                               return;
+                       noSyncChecks = true;
+                       var th = jQuery(this), c = th.is(':checked'), id = th.val().toString();
+                       $('#in-' + taxonomy + '-' + id + ', #in-' + taxonomy + '-category-' + id).attr( 'checked', c );
+                       noSyncChecks = false;
+               };
 
                catAddBefore = function( s ) {
-                       if ( !$('#newcat').val() )
+                       if ( !$('#new'+taxonomy).val() )
                                return false;
-                       s.data += '&' + $( ':checked', '#categorychecklist' ).serialize();
+                       s.data += '&' + $( ':checked', '#'+taxonomy+'checklist' ).serialize();
                        return s;
                };
 
                catAddAfter = function( r, s ) {
-                       var sup, drop = $('#newcat_parent');
+                       var sup, drop = $('#new'+taxonomy+'_parent');
 
                        if ( 'undefined' != s.parsed.responses[0] && (sup = s.parsed.responses[0].supplemental.newcat_parent) ) {
                                drop.before(sup);
@@ -285,33 +315,32 @@ jQuery(document).ready( function($) {
                        }
                };
 
-               $('#categorychecklist').wpList({
+               $('#' + taxonomy + 'checklist').wpList({
                        alt: '',
-                       response: 'category-ajax-response',
+                       response: taxonomy + '-ajax-response',
                        addBefore: catAddBefore,
                        addAfter: catAddAfter
                });
 
-               $('#category-add-toggle').click( function() {
-                       $('#category-adder').toggleClass( 'wp-hidden-children' );
-                       $('a[href="#categories-all"]', '#category-tabs').click();
+               $('#' + taxonomy + '-add-toggle').click( function() {
+                       $('#' + taxonomy + '-adder').toggleClass( 'wp-hidden-children' );
+                       $('a[href="#' + taxonomy + '-all"]', '#' + taxonomy + '-tabs').click();
+                       $('#new'+taxonomy).focus();
                        return false;
                });
 
-               $('#categorychecklist').children('li.popular-category').add( $('#categorychecklist-pop').children() ).find(':checkbox').live( 'click', function(){
+               $('#' + taxonomy + 'checklist li.popular-category :checkbox, #' + taxonomy + 'checklist-pop :checkbox').live( 'click', function(){
                        var t = $(this), c = t.is(':checked'), id = t.val();
-                       $('#in-category-' + id + ', #in-popular-category-' + id).attr( 'checked', c );
+                       if ( id && t.parents('#taxonomy-'+taxonomy).length )
+                               $('#in-' + taxonomy + '-' + id + ', #in-popular-' + taxonomy + '-' + id).attr( 'checked', c );
                });
 
-       } // end cats
+       }); // end cats
 
        // Custom Fields
        if ( $('#postcustom').length ) {
                $('#the-list').wpList( { addAfter: function( xml, s ) {
                        $('table#list-table').show();
-                       if ( typeof( autosave_update_post_ID ) != 'undefined' ) {
-                               autosave_update_post_ID(s.parsed.responses[0].supplemental.postid);
-                       }
                }, addBefore: function( s ) {
                        s.data += '&post_id=' + $('#post_ID').val();
                        return s;
@@ -340,8 +369,8 @@ jQuery(document).ready( function($) {
                }
 
                function updateText() {
-                       var attemptedDate, originalDate, currentDate, publishOn, postStatus = $('#post_status'),
-                               optPublish = $('option[value=publish]', postStatus), aa = $('#aa').val(),
+                       var attemptedDate, originalDate, currentDate, publishOn, page = 'page' == pagenow || 'page-new' == pagenow,
+                               postStatus = $('#post_status'), optPublish = $('option[value=publish]', postStatus), aa = $('#aa').val(),
                                mm = $('#mm').val(), jj = $('#jj').val(), hh = $('#hh').val(), mn = $('#mn').val();
 
                        attemptedDate = new Date( aa, mm - 1, jj, hh, mn );
@@ -448,7 +477,7 @@ jQuery(document).ready( function($) {
 
                        if ( $('input:radio:checked', pvSelect).val() != 'public' ) {
                                $('#sticky').attr('checked', false);
-                       }
+                       } // WEAPON LOCKED
 
                        if ( true == $('#sticky').attr('checked') ) {
                                sticky = 'Sticky';
@@ -519,7 +548,7 @@ jQuery(document).ready( function($) {
        // permalink
        if ( $('#edit-slug-box').length ) {
                editPermalink = function(post_id) {
-                       var i, c = 0, e = $('#editable-post-name'), revert_e = e.html(), real_slug = $('#post_name'), revert_slug = real_slug.html(), b = $('#edit-slug-buttons'), revert_b = b.html(), full = $('#editable-post-name-full').html();
+                       var i, c = 0, e = $('#editable-post-name'), revert_e = e.html(), real_slug = $('#post_name'), revert_slug = real_slug.val(), b = $('#edit-slug-buttons'), revert_b = b.html(), full = $('#editable-post-name-full').html();
 
                        $('#view-post-btn').hide();
                        b.html('<a href="#" class="save button">'+postL10n.ok+'</a> <a class="cancel" href="#">'+postL10n.cancel+'</a>');
@@ -577,4 +606,19 @@ jQuery(document).ready( function($) {
                }
                makeSlugeditClickable();
        }
+
+       if ( $('#title').val() == '' )
+               $('#title').siblings('#title-prompt-text').css('visibility', '');
+       $('#title-prompt-text').click(function(){
+               $(this).css('visibility', 'hidden').siblings('#title').focus();
+       });
+       $('#title').blur(function(){
+               if (this.value == '')
+                       $(this).siblings('#title-prompt-text').css('visibility', '');
+       }).focus(function(){
+               $(this).siblings('#title-prompt-text').css('visibility', 'hidden');
+       }).keydown(function(e){
+               $(this).siblings('#title-prompt-text').css('visibility', 'hidden');
+               $(this).unbind(e);
+       });
 });