Ticket #12186: move_custom-background_js_to_separate_file.diff

File move_custom-background_js_to_separate_file.diff, 4.6 KB (added by eddieringle, 2 years ago)

Move inline JavaScript to separate file.

  • wp-admin/js/custom-background.dev.js

     
     1var buttons = ['#pickcolor'], 
     2        farbtastic; 
     3 
     4function pickColor(color) { 
     5        jQuery('#background-color').val(color); 
     6        farbtastic.setColor(color); 
     7        jQuery('#custom-background-image').css('background-color', color); 
     8} 
     9 
     10jQuery(document).ready(function() { 
     11        jQuery('#pickcolor').click(function() { 
     12                jQuery('#colorPickerDiv').show(); 
     13        }); 
     14        jQuery('#background-color').keyup(function() { 
     15                var _hex = jQuery('#background-color').val(); 
     16                var hex = _hex; 
     17                if ( hex[0] != '#' ) 
     18                        hex = '#' + hex; 
     19                hex = hex.replace(/[^#a-fA-F0-9]+/, ''); 
     20                if ( hex != _hex ) 
     21                        jQuery('#background-color').val(hex); 
     22                if ( hex.length == 4 || hex.length == 7 ) 
     23                        pickColor( hex ); 
     24        }); 
     25 
     26        farbtastic = jQuery.farbtastic('#colorPickerDiv', function(color) { pickColor(color); }); 
     27        pickColor('#<?php background_color(); ?>'); 
     28}); 
     29 
     30jQuery(document).mousedown(function(){ 
     31        hide_picker(); // Make the picker disappear if you click outside its div element 
     32}); 
     33 
     34function hide_picker(what) { 
     35        var update = false; 
     36        jQuery('#colorPickerDiv').each(function(){ 
     37                var id = jQuery(this).attr('id'); 
     38                if (id == what) { 
     39                        return; 
     40                } 
     41                var display = jQuery(this).css('display'); 
     42                if (display == 'block') { 
     43                        jQuery(this).fadeOut(2); 
     44                } 
     45        }); 
     46} 
     47 No newline at end of file 
  • wp-admin/js/custom-background.js

     
     1var buttons=['#pickcolor'],farbtastic;function pickColor(color){jQuery('#background-color').val(color);farbtastic.setColor(color);jQuery('#custom-background-image').css('background-color',color);}jQuery(document).ready(function(){jQuery('#pickcolor').click(function(){jQuery('#colorPickerDiv').show();});jQuery('#background-color').keyup(function(){var _hex=jQuery('#background-color').val();var hex=_hex;if(hex[0]!='#')hex='#'+hex;hex=hex.replace(/[^#a-fA-F0-9]+/,'');if(hex!=_hex)jQuery('#background-color').val(hex);if(hex.length==4||hex.length==7)pickColor(hex);});farbtastic=jQuery.farbtastic('#colorPickerDiv',function(color){pickColor(color);});pickColor('#<?php background_color(); ?>');});jQuery(document).mousedown(function(){hide_picker();});function hide_picker(what){var update=false;jQuery('#colorPickerDiv').each(function(){var id=jQuery(this).attr('id');if(id==what){return;}var display=jQuery(this).css('display');if(display=='block'){jQuery(this).fadeOut(2);}});} 
     2 No newline at end of file 
  • wp-admin/custom-background.php

     
    166166         * @since unknown 
    167167         */ 
    168168        function js_1() { ?> 
    169 <script type="text/javascript"> 
    170         var buttons = ['#pickcolor'], 
    171                 farbtastic; 
    172  
    173         function pickColor(color) { 
    174                 jQuery('#background-color').val(color); 
    175                 farbtastic.setColor(color); 
    176                 jQuery('#custom-background-image').css('background-color', color); 
    177         } 
    178  
    179         jQuery(document).ready(function() { 
    180                 jQuery('#pickcolor').click(function() { 
    181                         jQuery('#colorPickerDiv').show(); 
     169        <script type="text/javascript" src="<?php echo get_option('siteurl'), '/wp-admin/js/custom-background.js'; ?>"></script> 
     170        <script type="text/javascript"> 
     171                jQuery(document).ready(function() { 
     172                        pickColor('#<?php background_color(); ?>'); 
    182173                }); 
    183                 jQuery('#background-color').keyup(function() { 
    184                         var _hex = jQuery('#background-color').val(); 
    185                         var hex = _hex; 
    186                         if ( hex[0] != '#' ) 
    187                                 hex = '#' + hex; 
    188                         hex = hex.replace(/[^#a-fA-F0-9]+/, ''); 
    189                         if ( hex != _hex ) 
    190                                 jQuery('#background-color').val(hex); 
    191                         if ( hex.length == 4 || hex.length == 7 ) 
    192                                 pickColor( hex ); 
    193                 }); 
    194  
    195                 farbtastic = jQuery.farbtastic('#colorPickerDiv', function(color) { pickColor(color); }); 
    196                 pickColor('#<?php background_color(); ?>'); 
    197         }); 
    198  
    199         jQuery(document).mousedown(function(){ 
    200                 hide_picker(); // Make the picker disappear if you click outside its div element 
    201         }); 
    202  
    203         function hide_picker(what) { 
    204                 var update = false; 
    205                 jQuery('#colorPickerDiv').each(function(){ 
    206                         var id = jQuery(this).attr('id'); 
    207                         if (id == what) { 
    208                                 return; 
    209                         } 
    210                         var display = jQuery(this).css('display'); 
    211                         if (display == 'block') { 
    212                                 jQuery(this).fadeOut(2); 
    213                         } 
    214                 }); 
     174        </script> 
     175        <?php 
    215176        } 
    216177 
    217 </script> 
    218 <?php 
    219         } 
    220  
    221178        /** 
    222179         * Display first step of custom background image page. 
    223180         *