(function($){ $(document).ready(function(){ $('body').on('click', '.media-input', function(e) { media_input_btn = $(this); e.preventDefault(); var image = wp.media({ //title: 'Dodaj obrazek', // mutiple: true if you want to upload multiple files at once multiple: false }).open() .on('select', function(e){ // This will return the selected image from the Media Uploader, the result is an object var uploaded_image = image.state().get('selection').first(); // We convert uploaded_image to a JSON object to make accessing it easier // Output to the console uploaded_image console.log(uploaded_image); //console.log(uploaded_image.toJSON()); var image_url = uploaded_image.toJSON().url; // Let's assign the url value to the input field media_input_btn.prev().val(image_url); media_input_btn.next().empty().append(''); }); }); $('.color-picker').colorPicker(); var i=1; $( "#sortable [class*='_position']").each(function(){ $(this).val(i); i++; }); $( "#sortable" ).sortable({ update: function(event, ui) { ui.item.find(" [class*='_position']").val(ui.item.index()); i=1; social_positions = ''; $( "#sortable [class*='_position']").each(function(){ $(this).val(i); social_positions = social_positions + $(this).attr('class').replace('_position','') +":" + i + ","; i++; }); $("#social_positions").val(social_positions); } }); //$( "#sortable" ).disableSelection(); $('#custom_colors_lum').on('change', function(){ setColors(); }); $('#kolor_1, #kolor_2').on('blur',function(){ setColors(); }); function setColors() { if($('#custom_colors_lum').val()=='1') { sign = 1; $('#kolor_11').val(ColorLuminance($('#kolor_1').val(), 0.08 * sign)).css('background',ColorLuminance($('#kolor_1').val(), 0.25 * sign)); $('#kolor_12').val(ColorLuminance($('#kolor_1').val(), 0.16 * sign)).css('background',ColorLuminance($('#kolor_1').val(), 0.4 * sign)); $('#kolor_21').val(ColorLuminance($('#kolor_2').val(), 0.08 * sign)).css('background',ColorLuminance($('#kolor_2').val(), 0.25 * sign)); $('#kolor_22').val(ColorLuminance($('#kolor_2').val(), 0.16 * sign)).css('background',ColorLuminance($('#kolor_2').val(), 0.4 * sign)); } else { sign = -1; $('#kolor_11').val(ColorLuminance($('#kolor_1').val(), 0.16 * sign)).css('background',ColorLuminance($('#kolor_1').val(), 0.4 * sign)); $('#kolor_12').val(ColorLuminance($('#kolor_1').val(), 0.08 * sign)).css('background',ColorLuminance($('#kolor_1').val(), 0.25 * sign)); $('#kolor_21').val(ColorLuminance($('#kolor_2').val(), 0.16 * sign)).css('background',ColorLuminance($('#kolor_2').val(), 0.4 * sign)); $('#kolor_22').val(ColorLuminance($('#kolor_2').val(), 0.08 * sign)).css('background',ColorLuminance($('#kolor_2').val(), 0.25 * sign)); } } facebook_social_link = /^https?:\/\/.*facebook\.?.*\//; twitter_social_link = /^https?:\/\/.*twitter\.?.*\//; youtube_social_link = /^https?:\/\/.*youtube\.?.*\//; instagram_social_link = /^https?:\/\/.*instagram\.?.*\//; pinterest_social_link = /^https?:\/\/.*pinterest\.?.*\//; google_plus_social_link = /^https?:\/\/.*google\.?.*\//; $('#socials .check-valid').blur(function(){ checkValid(); }); $('#theme-options-form').submit(function(){ checkValid(); return !$('#theme-options-form *').hasClass('input-validation-error'); }); function checkValid() { $('#socials .check-valid').each(function(){ pattern = $(this).attr('id'); if(!eval(pattern).test($(this).val()) && $(this).val() != '' && $(this).val() != '#') { $(this).addClass('input-validation-error'); } else { $(this).removeClass('input-validation-error'); } }); } setInterval(function(){ if($('#enable_custom_colors').is(':checked')) { $('#colors-container').slideDown( "slow" ); }else{ $('#colors-container').slideUp( "slow" ); } }, 500); }); })(jQuery); function ColorLuminance(rgb, lum) { rgb = rgb.match(/^rgba?[\s+]?\([\s+]?(\d+)[\s+]?,[\s+]?(\d+)[\s+]?,[\s+]?(\d+)[\s+]?/i); hex = (rgb && rgb.length === 4) ? "#" + ("0" + parseInt(rgb[1],10).toString(16)).slice(-2) + ("0" + parseInt(rgb[2],10).toString(16)).slice(-2) + ("0" + parseInt(rgb[3],10).toString(16)).slice(-2) : ''; // validate hex string hex = String(hex).replace(/[^0-9a-f]/gi, ''); if (hex.length < 6) { hex = hex[0]+hex[0]+hex[1]+hex[1]+hex[2]+hex[2]; } lum = lum || 0; // convert to decimal and change luminosity var rgb = "#", c, i; for (i = 0; i < 3; i++) { c = parseInt(hex.substr(i*2,2), 16); c = Math.round(Math.min(Math.max(0, c + (c * lum)), 255)).toString(16); rgb += ("00"+c).substr(c.length); } return rgb; }