/** * File: CacheGroups_Plugin_Admin_View.js * * @since 2.1.0 * * @package W3TC */ jQuery(function() { jQuery(document).on( 'submit', '#cachegroups_form', function() { var error = []; var mobile_groups = jQuery('#mobile_groups li'); mobile_groups.each(function(index, mobile_group) { var $mobile_group = jQuery(mobile_group); if ($mobile_group.find('.mobile_group_enabled:checked').length) { var name = $mobile_group.find('.mobile_group').text(); var theme = $mobile_group.find('select').val(); var redirect = $mobile_group.find('input[type=text]').val(); var agents = $mobile_group.find('textarea').val().split("\n").filter(function(line){return line.trim()!==''}).map(function(line){return line.trim();}); mobile_groups.not($mobile_group).each(function(index, compare_mobile_group) { var $compare_mobile_group = jQuery(compare_mobile_group); if ($compare_mobile_group.find('.mobile_group_enabled:checked').length) { var compare_name = $compare_mobile_group.find('.mobile_group').text(); var compare_theme = $compare_mobile_group.find('select').val(); var compare_redirect = $compare_mobile_group.find('input[type=text]').val(); var compare_agents = $compare_mobile_group.find('textarea').val().split("\n").filter(function(line){return line.trim()!==''}).map(function(line){return line.trim();}); var groups = sort_array([name, compare_name]); if (compare_redirect === '' && redirect === '' && compare_theme !== '' && compare_theme === theme) { error.push('Duplicate theme "' + compare_theme + '" found in the user agent groups "' + groups[0] + '" and "' + groups[1] + '"'); } if (compare_redirect !== '' && compare_redirect === redirect) { error.push('Duplicate redirect "' + compare_redirect + '" found in the user agent groups "' + groups[0] + '" and "' + groups[1] + '"'); } jQuery.each(compare_agents, function(index, value) { if (jQuery.inArray(value, agents) !== -1) { error.push('Duplicate stem "' + value + '" found in the user agent groups "' + groups[0] + '" and "' + groups[1] + '"'); } }); } }); } }); var referrer_groups = jQuery('#referrer_groups li'); referrer_groups.each(function(index, referrer_group) { var $referrer_group = jQuery(referrer_group); if ($referrer_group.find('.referrer_group_enabled:checked').length) { var name = $referrer_group.find('.referrer_group').text(); var theme = $referrer_group.find('select').val(); var redirect = $referrer_group.find('input[type=text]').val(); var agents = $referrer_group.find('textarea').val().split("\n").filter(function(line){return line.trim()!==''}).map(function(line){return line.trim();}); referrer_groups.not($referrer_group).each(function(index, compare_referrer_group) { var $compare_referrer_group = jQuery(compare_referrer_group); if ($compare_referrer_group.find('.referrer_group_enabled:checked').length) { var compare_name = $compare_referrer_group.find('.referrer_group').text(); var compare_theme = $compare_referrer_group.find('select').val(); var compare_redirect = $compare_referrer_group.find('input[type=text]').val(); var compare_agents = $compare_referrer_group.find('textarea').val().split("\n").filter(function(line){return line.trim()!==''}).map(function(line){return line.trim();}); var groups = sort_array([name, compare_name]); if (compare_redirect === '' && redirect === '' && compare_theme !== '' && compare_theme === theme) { error.push('Duplicate theme "' + compare_theme + '" found in the referrer groups "' + groups[0] + '" and "' + groups[1] + '"'); } if (compare_redirect !== '' && compare_redirect === redirect) { error.push('Duplicate redirect "' + compare_redirect + '" found in the referrer groups "' + groups[0] + '" and "' + groups[1] + '"'); } jQuery.each(compare_agents, function(index, value) { if (jQuery.inArray(value, agents) !== -1) { error.push('Duplicate stem "' + value + '" found in the referrer groups "' + groups[0] + '" and "' + groups[1] + '"'); } }); } }); } }); var cookiegroups = jQuery('#cookiegroups li'); cookiegroups.each(function(index, cookiegroup) { var $cookiegroup = jQuery(cookiegroup); if ($cookiegroup.find('.cookiegroup_enabled:checked').length) { var name = $cookiegroup.find('.cookiegroup_name').text(); var agents = $cookiegroup.find('textarea').val().split("\n").filter(function(line){return line.trim()!==''}).map(function(line){return line.trim();}); console.log(agents); cookiegroups.not($cookiegroup).each(function(index, compare_cookiegroup) { var $compare_cookiegroup = jQuery(compare_cookiegroup); if ($compare_cookiegroup.find('.cookiegroup_enabled:checked').length) { var compare_name = $compare_cookiegroup.find('.cookiegroup_name').text(); var compare_agents = $compare_cookiegroup.find('textarea').val().split("\n").filter(function(line){return line.trim()!==''}).map(function(line){return line.trim();}); console.log(compare_agents); var groups = sort_array([name, compare_name]); jQuery.each(compare_agents, function(index, value) { if (jQuery.inArray(value, agents) !== -1) { error.push('Duplicate stem "' + value + '" found in the cookie groups "' + groups[0] + '" and "' + groups[1] + '"'); } }); } }); } }); if (error.length !== 0) { alert(unique_array(error).join('\n')); return false; } return true; }); jQuery(document).on( 'click', '#mobile_add', function() { var group = prompt('Enter group name (only "0-9", "a-z", "_" symbols are allowed).'); if (group !== null) { group = group.toLowerCase(); group = group.replace(/[^0-9a-z_]+/g, '_'); group = group.replace(/^_+/, ''); group = group.replace(/_+$/, ''); if (group) { var exists = false; jQuery('.mobile_group').each(function() { if (jQuery(this).html() == group) { alert('Group already exists!'); exists = true; return false; } }); if (!exists) { var li = jQuery('
Group name: | ' + '' + '' + (jQuery('#mobile_groups li').length + 1) + '. ' + '' + group + ' ' + '' + ' | ' + '
---|---|
' + ' | ' + '' + '' + ' | ' + '
' + ' | ' +
'' +
' Assign this group of user agents to a specific them. Leaving this option "Active Theme" allows any plugins you have (e.g. mobile plugins) to properly handle requests for these user agents. If the "redirect users to" field is not empty, this setting is ignored. ' + ' | ' +
'
' + ' | ' +
'' +
' A 302 redirect is used to send this group of users to another hostname (domain); recommended if a 3rd party service provides a mobile version of your site. ' + ' | ' +
'
' + ' | ' +
'' +
' Specify the user agents for this group. ' + ' | ' +
'
Group name: | ' + '' + '' + (jQuery('#referrer_groups li').length + 1) + '. ' + '' + group + ' ' + '' + ' | ' + '
---|---|
' + '' + ' | ' + '' + '' + '' + ' | ' + '
' + ' | ' +
'' +
' Assign this group of referrers to a specific them. Leaving this option "Active Theme" allows any plugins you have (e.g. referrer plugins) to properly handle requests for these referrers. If the "redirect users to" field is not empty, this setting is ignored. ' + ' | ' +
'
' + ' | ' +
'' +
' A 302 redirect is used to send this group of users to another hostname (domain); recommended if a 3rd party service provides a referrer version of your site. ' + ' | ' +
'
' + ' | ' +
'' +
' Specify the referrers for this group. ' + ' | ' +
'
Group name: | ' + '' + ' | ' + ' ' + ' ' + '' + '
---|---|
' + ' | ' + '' + ' | ' + '
' + ' | ' + ' | ' + '
' + ' | ' +
'' +
' Specify the cookies for this group. Values like \'cookie\', \'cookie=value\', and cookie[a-z]+=value[a-z]+are supported. Remember to escape special characters like spaces, dots or dashes with a backslash. Regular expressions are also supported. ' + ' | ' +
'