216 } |
216 } |
217 } ); |
217 } ); |
218 |
218 |
219 // Clear the search results and trigger an `input` event to fire a new search. |
219 // Clear the search results and trigger an `input` event to fire a new search. |
220 this.$clearResults.on( 'click', function() { |
220 this.$clearResults.on( 'click', function() { |
221 self.$search.val( '' ).focus().trigger( 'input' ); |
221 self.$search.val( '' ).trigger( 'focus' ).trigger( 'input' ); |
222 } ); |
222 } ); |
223 |
223 |
224 this.$el.on( 'input', '#custom-menu-item-name.invalid, #custom-menu-item-url.invalid', function() { |
224 this.$el.on( 'input', '#custom-menu-item-name.invalid, #custom-menu-item-url.invalid', function() { |
225 $( this ).removeClass( 'invalid' ); |
225 $( this ).removeClass( 'invalid' ); |
226 }); |
226 }); |
227 |
227 |
228 // Load available items if it looks like we'll need them. |
228 // Load available items if it looks like we'll need them. |
229 api.panel( 'nav_menus' ).container.bind( 'expanded', function() { |
229 api.panel( 'nav_menus' ).container.on( 'expanded', function() { |
230 if ( ! self.rendered ) { |
230 if ( ! self.rendered ) { |
231 self.initList(); |
231 self.initList(); |
232 self.rendered = true; |
232 self.rendered = true; |
233 } |
233 } |
234 }); |
234 }); |
235 |
235 |
236 // Load more items. |
236 // Load more items. |
237 this.sectionContent.scroll( function() { |
237 this.sectionContent.on( 'scroll', function() { |
238 var totalHeight = self.$el.find( '.accordion-section.open .available-menu-items-list' ).prop( 'scrollHeight' ), |
238 var totalHeight = self.$el.find( '.accordion-section.open .available-menu-items-list' ).prop( 'scrollHeight' ), |
239 visibleHeight = self.$el.find( '.accordion-section.open' ).height(); |
239 visibleHeight = self.$el.find( '.accordion-section.open' ).height(); |
240 |
240 |
241 if ( ! self.loading && $( this ).scrollTop() > 3 / 4 * totalHeight - visibleHeight ) { |
241 if ( ! self.loading && $( this ).scrollTop() > 3 / 4 * totalHeight - visibleHeight ) { |
242 var type = $( this ).data( 'type' ), |
242 var type = $( this ).data( 'type' ), |
444 .prop( 'tabIndex', -1 ); |
444 .prop( 'tabIndex', -1 ); |
445 } |
445 } |
446 self.pages[ name ] = -1; |
446 self.pages[ name ] = -1; |
447 return; |
447 return; |
448 } else if ( ( 'post_type:page' === name ) && ( ! availableMenuItemContainers[ name ].hasClass( 'open' ) ) ) { |
448 } else if ( ( 'post_type:page' === name ) && ( ! availableMenuItemContainers[ name ].hasClass( 'open' ) ) ) { |
449 availableMenuItemContainers[ name ].find( '.accordion-section-title > button' ).click(); |
449 availableMenuItemContainers[ name ].find( '.accordion-section-title > button' ).trigger( 'click' ); |
450 } |
450 } |
451 typeItems = new api.Menus.AvailableItemCollection( typeItems ); // @todo Why is this collection created and then thrown away? |
451 typeItems = new api.Menus.AvailableItemCollection( typeItems ); // @todo Why is this collection created and then thrown away? |
452 self.collection.add( typeItems.models ); |
452 self.collection.add( typeItems.models ); |
453 typeInner = availableMenuItemContainers[ name ].find( '.available-menu-items-list' ); |
453 typeInner = availableMenuItemContainers[ name ].find( '.available-menu-items-list' ); |
454 typeItems.each( function( menuItem ) { |
454 typeItems.each( function( menuItem ) { |
642 // Only posts are supported currently. |
642 // Only posts are supported currently. |
643 if ( 'post_type' !== itemType ) { |
643 if ( 'post_type' !== itemType ) { |
644 return; |
644 return; |
645 } |
645 } |
646 |
646 |
647 if ( '' === $.trim( itemName.val() ) ) { |
647 if ( '' === itemName.val().trim() ) { |
648 itemName.addClass( 'invalid' ); |
648 itemName.addClass( 'invalid' ); |
649 itemName.focus(); |
649 itemName.focus(); |
650 return; |
650 return; |
651 } else { |
651 } else { |
652 itemName.removeClass( 'invalid' ); |
652 itemName.removeClass( 'invalid' ); |
714 control.collapseForm(); |
714 control.collapseForm(); |
715 } ); |
715 } ); |
716 |
716 |
717 this.$el.find( '.selected' ).removeClass( 'selected' ); |
717 this.$el.find( '.selected' ).removeClass( 'selected' ); |
718 |
718 |
719 this.$search.focus(); |
719 this.$search.trigger( 'focus' ); |
720 }, |
720 }, |
721 |
721 |
722 // Closes the panel. |
722 // Closes the panel. |
723 close: function( options ) { |
723 close: function( options ) { |
724 options = options || {}; |
724 options = options || {}; |
825 /** |
825 /** |
826 * Update field visibility when clicking on the field toggles. |
826 * Update field visibility when clicking on the field toggles. |
827 */ |
827 */ |
828 ready: function() { |
828 ready: function() { |
829 var panel = this; |
829 var panel = this; |
830 panel.container.find( '.hide-column-tog' ).click( function() { |
830 panel.container.find( '.hide-column-tog' ).on( 'click', function() { |
831 panel.saveManageColumnsState(); |
831 panel.saveManageColumnsState(); |
832 }); |
832 }); |
833 |
833 |
834 // Inject additional heading into the menu locations section's head container. |
834 // Inject additional heading into the menu locations section's head container. |
835 api.section( 'menu_locations', function( section ) { |
835 api.section( 'menu_locations', function( section ) { |
1877 _setupTitleUI: function() { |
1877 _setupTitleUI: function() { |
1878 var control = this, titleEl; |
1878 var control = this, titleEl; |
1879 |
1879 |
1880 // Ensure that whitespace is trimmed on blur so placeholder can be shown. |
1880 // Ensure that whitespace is trimmed on blur so placeholder can be shown. |
1881 control.container.find( '.edit-menu-item-title' ).on( 'blur', function() { |
1881 control.container.find( '.edit-menu-item-title' ).on( 'blur', function() { |
1882 $( this ).val( $.trim( $( this ).val() ) ); |
1882 $( this ).val( $( this ).val().trim() ); |
1883 } ); |
1883 } ); |
1884 |
1884 |
1885 titleEl = control.container.find( '.menu-item-title' ); |
1885 titleEl = control.container.find( '.menu-item-title' ); |
1886 control.setting.bind( function( item ) { |
1886 control.setting.bind( function( item ) { |
1887 var trimmedTitle, titleText; |
1887 var trimmedTitle, titleText; |
1888 if ( ! item ) { |
1888 if ( ! item ) { |
1889 return; |
1889 return; |
1890 } |
1890 } |
1891 trimmedTitle = $.trim( item.title ); |
1891 item.title = item.title || ''; |
|
1892 trimmedTitle = item.title.trim(); |
1892 |
1893 |
1893 titleText = trimmedTitle || item.original_title || api.Menus.data.l10n.untitled; |
1894 titleText = trimmedTitle || item.original_title || api.Menus.data.l10n.untitled; |
1894 |
1895 |
1895 if ( item._invalid ) { |
1896 if ( item._invalid ) { |
1896 titleText = api.Menus.data.l10n.invalidTitleTpl.replace( '%s', titleText ); |
1897 titleText = api.Menus.data.l10n.invalidTitleTpl.replace( '%s', titleText ); |
3419 * @return {string} |
3420 * @return {string} |
3420 */ |
3421 */ |
3421 function displayNavMenuName( name ) { |
3422 function displayNavMenuName( name ) { |
3422 name = name || ''; |
3423 name = name || ''; |
3423 name = wp.sanitize.stripTagsAndEncodeText( name ); // Remove any potential tags from name. |
3424 name = wp.sanitize.stripTagsAndEncodeText( name ); // Remove any potential tags from name. |
3424 name = $.trim( name ); |
3425 name = name.toString().trim(); |
3425 return name || api.Menus.data.l10n.unnamed; |
3426 return name || api.Menus.data.l10n.unnamed; |
3426 } |
3427 } |
3427 |
3428 |
3428 })( wp.customize, wp, jQuery ); |
3429 })( wp.customize, wp, jQuery ); |