| 1 |
(function($) { |
| 2 |
|
| 3 |
"use strict"; |
| 4 |
|
| 5 |
// color picket setup |
| 6 |
$(function () { |
| 7 |
$('.my-color-field').wpColorPicker({ |
| 8 |
defaultColor: false, |
| 9 |
palettes: ['#96D754', '#FFFA74', '#FF7150', '#9ABADC', '#FFA74C', '#158A61'] |
| 10 |
}); |
| 11 |
}); |
| 12 |
|
| 13 |
// convert rgb to hex |
| 14 |
function rgb2hex(rgb) { |
| 15 |
rgb = rgb.match(/^rgb\((\d+),\s*(\d+),\s*(\d+)\)$/); |
| 16 |
function hex(x) { |
| 17 |
return ("0" + parseInt(x).toString(16)).slice(-2); |
| 18 |
} |
| 19 |
return "#" + hex(rgb[1]) + hex(rgb[2]) + hex(rgb[3]); |
| 20 |
} |
| 21 |
|
| 22 |
// modify hex for background usage |
| 23 |
function convertHex(hex,opacity){ |
| 24 |
hex = hex.replace('#',''); |
| 25 |
var r = parseInt(hex.substring(0,2), 16); |
| 26 |
var g = parseInt(hex.substring(2,4), 16); |
| 27 |
var b = parseInt(hex.substring(4,6), 16); |
| 28 |
return 'rgba('+r+','+g+','+b+','+opacity/100+')'; |
| 29 |
} |
| 30 |
|
| 31 |
// highlight each row |
| 32 |
$('.mark-posts-marker').each(function() { |
| 33 |
var color = $(this).data('background'); |
| 34 |
$(this).parent().parent().find('th, td').css('background-color', convertHex(color,25)); |
| 35 |
$(this).parent().parent().find('.check-column').css('border-left', '4px solid '+color); |
| 36 |
$(this).parent().parent().find('.check-column input').css('margin-left', '3px'); // balance border width |
| 37 |
}); |
| 38 |
|
| 39 |
// live preview of new markers |
| 40 |
$('.new-markers').hide(); |
| 41 |
$('.js-add-markers').keyup(function(e) { // use keyup instead of keypress for latest char |
| 42 |
$('.new-markers').show(); |
| 43 |
var markers = []; |
| 44 |
var make_markers = $(this).val().split(","); // separate marker by comma |
| 45 |
$(make_markers).each(function(e) { // push each new marker to array |
| 46 |
markers.push('<span class="new-marker">'+make_markers[e]+'</span>'); |
| 47 |
}); |
| 48 |
|
| 49 |
$('.js-new-markers-intro').show(); |
| 50 |
$('.js-new-markers').html(markers.join(' ')); // preview new markers |
| 51 |
|
| 52 |
if($(this).val().length == 0) // hide container |
| 53 |
$('.new-markers').hide(); |
| 54 |
}); |
| 55 |
|
| 56 |
// change background color in edit post options |
| 57 |
if($('#mark_posts_options').length > 0) { |
| 58 |
var color = $('select#mark_posts_term_id option:selected').data('color'); |
| 59 |
if (color) |
| 60 |
$('#mark_posts_options h3.hndle').css('background-color', convertHex(color,25)); |
| 61 |
$('span.mark-posts-color').css('background-color', color); |
| 62 |
$('select#mark_posts_term_id').on('change', function() { |
| 63 |
var color = $('select#mark_posts_term_id option:selected').data('color'); |
| 64 |
$('#mark_posts_options h3.hndle').css('background-color', convertHex(color,25)); |
| 65 |
$('span.mark-posts-color').css('background-color', color); |
| 66 |
}); |
| 67 |
} |
| 68 |
|
| 69 |
$('a.mark-posts-initial').click(function() { |
| 70 |
var confirm_msg = $(this).data('confirm-msg'); |
| 71 |
if (confirm(confirm_msg)) { |
| 72 |
var term_id = $(this).data('term-id'); |
| 73 |
window.location = 'options-general.php?page=mark-posts&mark-all-posts-term-id=' + term_id; |
| 74 |
} |
| 75 |
else { |
| 76 |
return false; |
| 77 |
} |
| 78 |
return false; |
| 79 |
}); |
| 80 |
|
| 81 |
}(jQuery)); |