jQuery(function($) { var CF = CF || {}; $('#cf-kuler-menu a').click(function(e) { $('#cf-kuler-menu a').removeClass('current'); $(this).addClass('current'); $swatches = $('#cf-kuler-swatch-selector'); $swatches.html('
' + cf_kuler_settings.loading + '
'); $.post( ajaxurl, { 'action': 'cf_kuler', 'request': $(this).attr('data-request'), 'listType': $(this).attr('data-listtype'), 'startIndex': $(this).attr('data-start'), 'itemsPerPage': $(this).attr('data-items') }, function(response) { $swatches.html(response); // set height to avoid the window jerk var wrapHeight = $swatches.height(); $swatches.css('height', wrapHeight); }, 'html' ); e.preventDefault(); }); $('.cf-kuler-wrap .scheme-item a').click(function() { var swatches = $(this).attr('data').split(','); var idx = 0; $('#cf-kuler-swatch-selected .cf-kuler-theme li').each(function(){ $(this).attr('style', 'background:'+ swatches[idx++]); }); }); $('#cf-kuler-search-form').submit(function(e) { $swatches = $('#cf-kuler-swatch-selector'); $swatches.html('
' + cf_kuler_settings.loading + '
'); $.post( ajaxurl, { 'action': 'cf_kuler', 'request': 'search', 'searchQuery': $(this).find('#cf_kuler_search').val(), 'startIndex': $(this).attr('data-start'), 'itemsPerPage': $(this).attr('data-items') }, function(response) { $swatches.html(response); }, 'html' ); e.preventDefault(); }); $('a.cf-kuler-paging').live('click', function(e) { $swatches = $('#cf-kuler-swatch-selector'); $swatches.html('
' + cf_kuler_settings.loading + '
'); $.post( ajaxurl, { 'action': 'cf_kuler', 'request': $(this).attr('data-request'), 'listType': $(this).attr('data-listtype'), 'searchQuery': $(this).attr('data-search'), 'startIndex': $(this).attr('data-start'), 'itemsPerPage': $(this).attr('data-items') }, function(response) { $swatches.html(response); $.scrollTo($('#preview-selected'), 'slow'); }, 'html' ); e.preventDefault(); }); $('#cf-kuler-swatch-selector .cf-kuler-theme .cf-kuler-apply').live('click', function(e) { // select swatch var $selected = $('#cf-kuler-swatch-selected'); $selected.find('.cf-kuler-theme').html(''); var $theme = $(this).closest('.cf-kuler-theme'); $selected.find('.cf-kuler-theme').append($theme.find('ul').clone()).append($theme.find('p.cf-kuler-theme-description').clone()); // populate hidden field // show save button $('#cf_kuler_settings_form') .find('#cf-kuler-theme-info').html($theme.find('.cf-kuler-theme-data').clone()).end() .find('#cf_kuler_colors').val($theme.attr('data-swatches')).end() .find('input[type=submit]').show().end(); $('html, body').animate({scrollTop:0}, 'slow'); // scroll to top CF.utils.initSelectedSortable(); e.preventDefault(); }); $('#cf_kuler_settings_form').live('submit', function() { // pull selected theme's swatch state $(this).find('#cf_kuler_colors').val(CF.utils.getThemeColors($('#cf-kuler-swatch-selected .cf-kuler-theme'))); }); // Utils CF.utils = function($) { return { getThemeColors: function(theme) { var $list = $(theme).find('ul'); var colors = []; $list.find('li').each(function(i) { colors[i] = CF.utils.rgbToHex($(this).css('backgroundColor')); }); return colors; }, decodeEntities: function(encoded) { return $('