Advertisement
Guest User

Selecticon.ph

a guest
Aug 6th, 2013
123
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.36 KB | None | 0 0
  1. <?php
  2. /**
  3. * Your Inspiration Themes
  4. *
  5. * @package WordPress
  6. * @subpackage Your Inspiration Themes
  7. * @author Your Inspiration Themes Team <info@yithemes.com>
  8. *
  9. * This source file is subject to the GNU GENERAL PUBLIC LICENSE (GPL 3.0)
  10. * that is bundled with this package in the file LICENSE.txt.
  11. * It is also available through the world-wide-web at this URL:
  12. * http://www.gnu.org/licenses/gpl-3.0.txt
  13. */
  14.  
  15. /**
  16. * YIT Type: SelectIcon
  17. *
  18. * @since 1.0.0
  19. */
  20. class YIT_Type_SelectIcon {
  21.  
  22. /**
  23. * Load and print the correspondent field type.
  24. *
  25. * @param @field
  26. * @return string
  27. */
  28. public static function display( $value, $dep ) {
  29. $config = YIT_Config::load();
  30.  
  31. $icon_value = maybe_unserialize( yit_get_option( $value['id'], $value['std'] ) );
  32. if ( ! is_array( $icon_value ) ) {
  33. $icon_value = array( 'icon' => $icon_value, 'custom' => '' );
  34. }
  35.  
  36. ob_start(); ?>
  37. <div id="<?php echo $value['id_container'] ?>" <?php if($dep): ?>data-field="<?php echo $dep['field'] ?>" data-dep="<?php echo $dep['dep'] ?>" data-value="<?php echo $dep['value'] ?>" <?php endif ?>class="yit_options rm_option rm_input rm_text">
  38. <div class="option">
  39. <label for="<?php echo $value['id'] ?>"><?php echo $value['name'] ?></label>
  40.  
  41. <div class="select_wrapper">
  42. <select name="<?php yit_field_name( $value['id'] ); ?>[icon]" id="<?php echo $value['id'] ?>">
  43. <?php foreach ( $config['awesome_icons'] as $val => $option ): ?>
  44. <option value="<?php echo $val ?>"<?php selected( $icon_value['icon'], $val ) ?>><?php echo $option; ?></option>
  45.  
  46. <?php endforeach; ?>
  47. </select>
  48. </div>
  49. <div class="icon-preview"><span class="<?php echo $icon_value['icon'] ?>"></span></div>
  50.  
  51. <?php if( isset( $value['upload'] ) && $value['upload'] ) : ?>
  52. <div class="clearboth"></div>
  53.  
  54. <div class="upload-button">
  55. <?php _e( 'or upload your own icon:', 'yit' ) ?>
  56. <input type="text" style="width:200px;" id="<?php echo $value['id']; ?>_custom" name="<?php yit_field_name( $value['id'] ); ?>[custom]" value="<?php if ( isset( $icon_value['custom'] ) ) echo $icon_value['custom']; ?>" />
  57. <a href="#" class="button-secondary" id="<?php echo $value['id']; ?>_upload_button"><?php _e( 'Upload', 'yit' ) ?></a>
  58. </div>
  59. <?php endif ?>
  60.  
  61. </div>
  62. <div class="description">
  63. <?php $default = $value['std']['custom'] != '' ? $value['std']['custom'] : ucfirst( end( explode( '-', $value['std'] ) ) ); ?>
  64. <?php echo $value['desc'] ?> <?php printf( __( '(Default: %s)', 'yit' ), $default ) ?>
  65. </div>
  66. <div class="clear"></div>
  67. </div>
  68.  
  69.  
  70. <script type="text/javascript">
  71. jQuery(document).ready( function( $ ) {
  72. $( '#<?php echo( $value['id'] ); ?>_icon' ).attr( 'class', $( '#<?php echo( $value['id'] ); ?>' ).val() );
  73.  
  74. $( '#<?php echo( $value['id'] ); ?>' ).change( function() {
  75. $( '#<?php echo( $value['id'] ); ?>_icon' ).removeAttr( 'class' );
  76. $( '#<?php echo( $value['id'] ); ?>_icon' ).attr( 'class', $( this ).val() );
  77.  
  78. $(this).parents('.yit_options').find('.icon-preview span').attr( 'class', $( this ).val() );
  79. });
  80.  
  81. $('#<?php echo( $value['id'] ); ?>_upload_button').live('click', function(){
  82. var yit_this_object = $(this).prev();
  83.  
  84. tb_show('', 'media-upload.php?post_id=0&type=image&TB_iframe=true');
  85.  
  86. window.send_to_editor = function(html) {
  87. imgurl = $('img', html).attr('src');
  88. yit_this_object.val(imgurl);
  89.  
  90. tb_remove();
  91. }
  92.  
  93. return false;
  94. });
  95. });
  96. </script>
  97. <?php
  98. return ob_get_clean();
  99. }
  100. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement