jQuery(function($) { "use strict"; var ASSET_TYPES = ['styles', 'scripts'], p = '#page-edit-'; $(p + 'dialog').on('guff.loaded', function(ev) { var r = ev.post_data; $(p + 'theme').val(r.theme_id || 'site-default'); // set assets $.each(ASSET_TYPES, function(i, key) { $(p + key).val(r[key].join("\n")); }); }); $(p + 'confirm').click(function() { var theme_id = $(p + 'theme').val(); if (theme_id == 'site-default') theme_id = null; // get assets var assets = ASSET_TYPES.reduce(function(r, key) { r[key] = listify(p + key); return r; }, {}); $(p + 'dialog').trigger({ type: 'guff.save', post_data: $.extend({ have_theme_id: 't', theme_id: theme_id, }, assets), }); // stop event return false; }); });