Skip to content
This repository has been archived by the owner on Dec 16, 2022. It is now read-only.

Support type-specific Setting constructors #286

Merged
merged 1 commit into from
Sep 20, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 13 additions & 5 deletions js/customize-posts.js
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@
component.addPostSettings = function addPostSettings( settings ) {
var postIds = [];
_.each( settings, function( settingArgs, id ) {
var setting, matches, parsedSettingId = component.parseSettingId( id );
var setting, matches, parsedSettingId = component.parseSettingId( id ), SettingConstructor, settingParams;
if ( ! parsedSettingId ) {

// Special case: make sure the fetch of a nav menu item is recorded so that it is not re-fetched later.
Expand All @@ -322,10 +322,18 @@

setting = api( id );
if ( ! setting ) {
setting = api.create( id, id, settingArgs.value, {
transport: settingArgs.transport,
previewer: api.previewer
} );
SettingConstructor = api.settingConstructor[ settingArgs.type ] || api.Setting;
settingParams = _.extend(
{},
settingArgs,
{
previewer: api.previewer,
dirty: false
}
);
delete settingParams.value;
setting = new SettingConstructor( id, settingArgs.value, settingParams );
api.add( id, setting );

// Mark as dirty and trigger change if setting is pre-dirty; see code in wp.customize.Value.prototype.set().
if ( settingArgs.dirty ) {
Expand Down