|
307 | 307 | * unless the notification is specifically for this control's setting property.
|
308 | 308 | *
|
309 | 309 | * @this {wp.customize.Control}
|
310 |
| - * @param {string} code Notification code. |
311 |
| - * @param {wp.customize.Notification} notification Notification object. |
| 310 | + * @param {string|wp.customize.Notification} notification - Notification object to add. Alternatively code may be supplied, and in that case the second notificationObject argument must be supplied. |
| 311 | + * @param {wp.customize.Notification} [notificationObject] - Notification to add when first argument is the code string. |
312 | 312 | * @returns {wp.customize.Notification|null} Notification if not bypassed.
|
313 | 313 | */
|
314 |
| - addPostFieldControlNotification: function addPostFieldControlNotification( code, notification ) { |
315 |
| - var isSettingNotification, isSettingPropertyNotification; |
| 314 | + addPostFieldControlNotification: function addPostFieldControlNotification( notification, notificationObject ) { |
| 315 | + var isSettingNotification, isSettingPropertyNotification, code; |
| 316 | + code = 'string' === typeof notification ? notification : notification.code; |
316 | 317 | isSettingNotification = -1 !== code.indexOf( ':' ) || notification.setting; // Note that sniffing for ':' is deprecated as of #36944 & #37890.
|
317 | 318 | isSettingPropertyNotification = notification.data && notification.data.setting_property === this.setting_property;
|
318 | 319 | if ( isSettingPropertyNotification || ! isSettingNotification ) {
|
319 |
| - return api.Values.prototype.add.call( this, code, notification ); |
| 320 | + return ( api.Notifications || api.Values ).prototype.add.call( this, notification, notificationObject ); |
320 | 321 | } else {
|
321 | 322 | return null;
|
322 | 323 | }
|
|
393 | 394 | }
|
394 | 395 | } );
|
395 | 396 |
|
396 |
| - // Override preview trying to de-activate control not present in preview context. See WP Trac #37270. |
397 |
| - control.active.validate = function() { |
398 |
| - return true; |
399 |
| - }; |
400 |
| - |
401 | 397 | // Register.
|
402 | 398 | section.postFieldControls.post_title = control;
|
403 | 399 | api.control.add( control.id, control );
|
|
451 | 447 | setting.bind( setPlaceholder );
|
452 | 448 | } );
|
453 | 449 |
|
454 |
| - // Override preview trying to de-activate control not present in preview context. See WP Trac #37270. |
455 |
| - control.active.validate = function() { |
456 |
| - return true; |
457 |
| - }; |
458 |
| - |
459 | 450 | // Register.
|
460 | 451 | section.postFieldControls.post_name = control;
|
461 | 452 | api.control.add( control.id, control );
|
|
487 | 478 | }
|
488 | 479 | } );
|
489 | 480 |
|
490 |
| - // Override preview trying to de-activate control not present in preview context. See WP Trac #37270. |
491 |
| - control.active.validate = function() { |
492 |
| - return true; |
493 |
| - }; |
494 |
| - |
495 | 481 | // Register.
|
496 | 482 | section.postFieldControls.post_status = control;
|
497 | 483 | api.control.add( control.id, control );
|
|
524 | 510 | }
|
525 | 511 | } );
|
526 | 512 |
|
527 |
| - // Override preview trying to de-activate control not present in preview context. See WP Trac #37270. |
528 |
| - control.active.validate = function() { |
529 |
| - return true; |
530 |
| - }; |
531 |
| - |
532 | 513 | // Register.
|
533 | 514 | section.postFieldControls.post_date = control;
|
534 | 515 | api.control.add( control.id, control );
|
|
617 | 598 | }
|
618 | 599 | } );
|
619 | 600 |
|
620 |
| - // Override preview trying to de-activate control not present in preview context. See WP Trac #37270. |
621 |
| - control.active.validate = function() { |
622 |
| - return true; |
623 |
| - }; |
624 |
| - |
625 | 601 | // Register.
|
626 | 602 | section.postFieldControls.post_excerpt = control;
|
627 | 603 | api.control.add( control.id, control );
|
|
686 | 662 | } );
|
687 | 663 | }
|
688 | 664 |
|
689 |
| - // Override preview trying to de-activate control not present in preview context. |
690 |
| - control.active.validate = function() { |
691 |
| - return true; |
692 |
| - }; |
693 |
| - |
694 | 665 | // Register.
|
695 | 666 | section.postFieldControls.page_parent = control;
|
696 | 667 | api.control.add( control.id, control );
|
|
724 | 695 | }
|
725 | 696 | } );
|
726 | 697 |
|
727 |
| - // Override preview trying to de-activate control not present in preview context. See WP Trac #37270. |
728 |
| - control.active.validate = function() { |
729 |
| - return true; |
730 |
| - }; |
731 |
| - |
732 | 698 | // Register.
|
733 | 699 | section.postFieldControls.menu_order = control;
|
734 | 700 | api.control.add( control.id, control );
|
|
761 | 727 | }
|
762 | 728 | } );
|
763 | 729 |
|
764 |
| - // Override preview trying to de-activate control not present in preview context. See WP Trac #37270. |
765 |
| - control.active.validate = function() { |
766 |
| - return true; |
767 |
| - }; |
768 |
| - |
769 | 730 | // Register.
|
770 | 731 | section.postFieldControls.post_discussion_fields = control;
|
771 | 732 | api.control.add( control.id, control );
|
|
809 | 770 | return data;
|
810 | 771 | };
|
811 | 772 |
|
812 |
| - // Override preview trying to de-activate control not present in preview context. See WP Trac #37270. |
813 |
| - control.active.validate = function() { |
814 |
| - return true; |
815 |
| - }; |
816 |
| - |
817 | 773 | // Register.
|
818 | 774 | section.postFieldControls.post_author = control;
|
819 | 775 | api.control.add( control.id, control );
|
|
826 | 782 | },
|
827 | 783 |
|
828 | 784 | /**
|
829 |
| - * Set up section notifications. |
| 785 | + * Polyfill notifications API onto sections if not yet on WordPress 4.9 where it is defined in core. |
830 | 786 | *
|
| 787 | + * @link <https://core.trac.wordpress.org/ticket/38794> |
831 | 788 | * @returns {void}
|
832 | 789 | */
|
833 |
| - setupSectionNotifications: function() { |
834 |
| - var section = this, setting = api( section.id ), debouncedRenderNotifications, setPageForPostsNotice; |
835 |
| - if ( ! setting.notifications ) { |
| 790 | + polyfillNotifications: function() { |
| 791 | + var section = this, debouncedRenderNotifications; |
| 792 | + if ( section.notifications ) { |
836 | 793 | return;
|
837 | 794 | }
|
838 | 795 |
|
839 |
| - // Add the notifications API. |
840 | 796 | section.notifications = new api.Values({ defaultConstructor: api.Notification });
|
841 | 797 | section.notificationsContainer = $( '<div class="customize-control-notifications-container"></div>' );
|
| 798 | + section.notifications.container = section.notificationsContainer; |
842 | 799 | section.notificationsTemplate = wp.template( 'customize-post-section-notifications' );
|
843 | 800 | section.container.find( '.customize-section-title' ).after( section.notificationsContainer );
|
844 | 801 | section.getNotificationsContainerElement = function() {
|
845 | 802 | return section.notificationsContainer;
|
846 | 803 | };
|
847 | 804 | section.renderNotifications = api.Control.prototype.renderNotifications;
|
848 | 805 |
|
849 |
| - // Sync setting notifications into the section notifications |
850 |
| - setting.notifications.bind( 'add', function( settingNotification ) { |
851 |
| - var notification = new api.Notification( setting.id + ':' + settingNotification.code, settingNotification ); |
852 |
| - if ( ! settingNotification.data || ! settingNotification.data.setting_property || ! api.control.has( section.id + '[' + settingNotification.data.setting_property + ']' ) ) { |
853 |
| - section.notifications.add( notification.code, notification ); |
854 |
| - } |
855 |
| - } ); |
856 |
| - setting.notifications.bind( 'remove', function( settingNotification ) { |
857 |
| - section.notifications.remove( setting.id + ':' + settingNotification.code ); |
858 |
| - } ); |
859 |
| - |
860 | 806 | /*
|
861 | 807 | * Render notifications when the collection is updated.
|
862 | 808 | * Note that this debounced/deferred rendering is needed for two reasons:
|
|
872 | 818 | } );
|
873 | 819 | section.notifications.bind( 'remove', debouncedRenderNotifications );
|
874 | 820 | section.renderNotifications();
|
| 821 | + }, |
| 822 | + |
| 823 | + /** |
| 824 | + * Set up section notifications. |
| 825 | + * |
| 826 | + * @returns {void} |
| 827 | + */ |
| 828 | + setupSectionNotifications: function() { |
| 829 | + var section = this, setting = api( section.id ), setPageForPostsNotice, notificationTemplate; |
| 830 | + if ( ! setting.notifications ) { |
| 831 | + return; |
| 832 | + } |
| 833 | + |
| 834 | + // Add the notifications API if not present. |
| 835 | + section.polyfillNotifications(); |
| 836 | + |
| 837 | + // Sync setting notifications into the section notifications |
| 838 | + setting.notifications.bind( 'add', function( settingNotification ) { |
| 839 | + var notification = new api.Notification( setting.id + ':' + settingNotification.code, _.extend( {}, |
| 840 | + settingNotification, |
| 841 | + { |
| 842 | + template: notificationTemplate |
| 843 | + } |
| 844 | + ) ); |
| 845 | + if ( ! settingNotification.data || ! settingNotification.data.setting_property || ! api.control.has( section.id + '[' + settingNotification.data.setting_property + ']' ) ) { |
| 846 | + section.notifications.add( notification.code, notification ); |
| 847 | + } |
| 848 | + } ); |
| 849 | + setting.notifications.bind( 'remove', function( settingNotification ) { |
| 850 | + section.notifications.remove( setting.id + ':' + settingNotification.code ); |
| 851 | + } ); |
875 | 852 |
|
876 | 853 | // Dismiss conflict block when clicking on button.
|
877 |
| - section.notificationsContainer.on( 'click', '.override-post-conflict', function( e ) { |
| 854 | + section.notifications.container.on( 'click', '.override-post-conflict', function( e ) { |
878 | 855 | var ourValue;
|
879 | 856 | e.preventDefault();
|
880 | 857 | ourValue = _.clone( setting.get() );
|
|
890 | 867 | } );
|
891 | 868 |
|
892 | 869 | // Detect conflict errors.
|
| 870 | + notificationTemplate = wp.template( 'customize-post-field-notification' ); |
893 | 871 | api.bind( 'error', function( response ) {
|
894 | 872 | var theirValue, ourValue,
|
895 | 873 | conflictedControls = [];
|
|
0 commit comments