assets.php 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  1. <?php
  2. /**
  3. * JavaScript and CSS files.
  4. *
  5. * @package Pen
  6. */
  7. if ( ! defined( 'ABSPATH' ) ) {
  8. exit;
  9. }
  10. if ( ! function_exists( 'pen_assets' ) ) {
  11. /**
  12. * Enqueue scripts and styles.
  13. */
  14. function pen_assets() {
  15. $theme_directory = "//cdn.yoqi.me/blog/wp-content/themes/pen";
  16. $css_files = array(
  17. 'normalize' => '/assets/css/normalize.css',
  18. 'animate' => '/assets/css/plugins/animate.css',
  19. 'slicknav' => '/assets/css/plugins/jquery.slicknav.css',
  20. 'base' => '/assets/css/pen-base.css',
  21. 'fonts' => '/assets/css/pen-fonts.css',
  22. 'typography' => '/assets/css/pen-typography.css',
  23. 'layout' => '/assets/css/pen-layout.css',
  24. 'buttons' => '/assets/css/pen-buttons.css',
  25. 'bottom' => '/assets/css/pen-bottom.css',
  26. 'comments' => '/assets/css/pen-comments.css',
  27. 'footer' => '/assets/css/pen-footer.css',
  28. 'header' => '/assets/css/pen-header.css',
  29. 'menus' => '/assets/css/pen-menus.css',
  30. 'navigation' => '/assets/css/pen-navigation.css',
  31. 'forms' => '/assets/css/pen-forms.css',
  32. 'content' => '/assets/css/pen-content.css',
  33. 'thumbnails' => '/assets/css/pen-thumbnails.css',
  34. 'author' => '/assets/css/pen-author.css',
  35. 'pagination' => '/assets/css/pen-pagination.css',
  36. 'share' => '/assets/css/pen-share.css',
  37. 'search-bar' => '/assets/css/pen-search-bar.css',
  38. 'top' => '/assets/css/pen-top.css',
  39. 'widgets' => '/assets/css/pen-widgets.css',
  40. );
  41. // The key has to be the same as the slug in the inline CSS of the customize.php file.
  42. $css_files['css'] = '/assets/css/pen-general.css';
  43. if ( file_exists( $theme_directory . '/assets/css/custom.css' ) ) {
  44. $css_files['custom'] = '/assets/css/custom.css';
  45. }
  46. foreach ( $css_files as $key => $value ) {
  47. wp_enqueue_style( 'pen-' . $key, $theme_directory . $value, array(), PEN_THEME_VERSION );
  48. }
  49. wp_enqueue_script( 'jquery-fittext', $theme_directory . '/assets/js/plugins/jquery.fittext.js', array( 'jquery' ), '1.2', true );
  50. wp_enqueue_script( 'autosize', $theme_directory . '/assets/js/plugins/autosize.js', array(), '4.0', true );
  51. wp_enqueue_script( 'respond', $theme_directory . '/assets/js/plugins/respond.js', array( 'jquery' ), '1.4.2', true );
  52. wp_enqueue_script( 'pen-skip', $theme_directory . '/assets/js/skip-link-focus-fix.js', array( 'jquery' ), PEN_THEME_VERSION, true );
  53. if ( is_singular() ) {
  54. wp_enqueue_script( 'comment-reply' );
  55. }
  56. ob_start( 'pen_compress_html' );
  57. get_template_part( 'partials/site', 'navigation' );
  58. $navigation_easing = array();
  59. $navigation = ob_get_clean();
  60. if ( $navigation ) {
  61. wp_enqueue_script( 'hoverIntent' );
  62. wp_enqueue_script( 'jquery-superfish', $theme_directory . '/assets/js/plugins/jquery.superfish.js', array( 'jquery' ), '1.7.9', true );
  63. wp_enqueue_script( 'jquery-slicknav', $theme_directory . '/assets/js/plugins/jquery.slicknav.js', array( 'jquery' ), '1.0.10', true );
  64. $easing = pen_option_get( 'navigation_easing' );
  65. if ( $easing ) {
  66. wp_enqueue_script( 'jquery-easing', $theme_directory . '/assets/js/plugins/jquery.easing.js', array( 'jquery' ), '1.3', true );
  67. $navigation_easing = array(
  68. 'height' => array( 'show', $easing ),
  69. );
  70. }
  71. }
  72. wp_enqueue_script( 'jquery-waypoints', $theme_directory . '/assets/js/plugins/jquery.waypoints.js', array( 'jquery' ), '4.0.1', true );
  73. $content_list_type = pen_list_type();
  74. if ( 'masonry' === $content_list_type ) {
  75. wp_enqueue_script( 'imagesloaded' );
  76. wp_enqueue_script( 'masonry' );
  77. }
  78. wp_enqueue_script( 'pen-modernizr', $theme_directory . '/assets/js/plugins/modernizr.js', array(), '3.6', true );
  79. $site_background_effect = pen_option_get( 'color_site_background_effect' );
  80. $trianglify = false;
  81. $trianglify_colors = false;
  82. if ( 'trianglify' === $site_background_effect ) {
  83. $trianglify = true;
  84. /**
  85. * Dear WP.org reviewer,
  86. * Base64 is required to generate a DataURI for a SVG background.
  87. * We can remove this feature entirely if you don't like it?
  88. */
  89. wp_enqueue_script( 'base64', $theme_directory . '/assets/js/plugins/base64.js', array( 'jquery' ), PEN_THEME_VERSION, true );
  90. $trianglify_colors = array(
  91. pen_option_get( 'color_site_background' ),
  92. pen_option_get( 'color_button_background_primary' ),
  93. pen_option_get( 'color_button_background_secondary' ),
  94. pen_option_get( 'color_header_background_primary' ),
  95. pen_option_get( 'color_header_background_secondary' ),
  96. pen_option_get( 'color_navigation_background_primary' ),
  97. pen_option_get( 'color_navigation_background_secondary' ),
  98. );
  99. wp_enqueue_script( 'trianglify', $theme_directory . '/assets/js/plugins/trianglify.js', array( 'jquery', 'base64' ), '2.0.0', true );
  100. }
  101. $shards = false;
  102. $shards_colors = false;
  103. if ( 'shards' === $site_background_effect ) {
  104. $shards = true;
  105. $site_background = new \Pen\Color( pen_option_get( 'color_site_background' ) );
  106. $site_background = array_values( $site_background->getRgb() );
  107. $site_background[] = 0.25;
  108. $header_background_primary = new \Pen\Color( pen_option_get( 'color_header_background_primary' ) );
  109. $header_background_primary = array_values( $header_background_primary->getRgb() );
  110. $header_background_primary[] = 0.25;
  111. $shards_colors = array(
  112. $site_background,
  113. $header_background_primary,
  114. );
  115. wp_enqueue_script( 'shards', $theme_directory . '/assets/js/plugins/shards.js', array( 'jquery' ), '1.1', true );
  116. }
  117. wp_enqueue_script(
  118. 'pen-js',
  119. $theme_directory . '/assets/js/pen-scripts.js',
  120. array_filter(
  121. array(
  122. 'jquery',
  123. 'jquery-masonry',
  124. $shards ? 'shards' : '',
  125. $trianglify ? 'trianglify' : '',
  126. )
  127. ),
  128. PEN_THEME_VERSION,
  129. true
  130. );
  131. wp_localize_script(
  132. 'pen-js',
  133. 'pen_js',
  134. array(
  135. 'header_sticky' => pen_option_get( 'header_sticky' ),
  136. 'list_type' => $content_list_type,
  137. 'trianglify_colors' => $trianglify_colors,
  138. 'shards_colors' => $shards_colors,
  139. 'navigation_arrows' => pen_option_get( 'navigation_arrows' ) ? true : false,
  140. 'navigation_easing' => $navigation_easing,
  141. 'navigation_mobile' => pen_option_get( 'navigation_mobile_display' ) ? true : false,
  142. 'animation_comments' => pen_option_get( 'comments_animation_reveal' ),
  143. 'animation_navigation_speed' => pen_option_get( 'navigation_animation_speed' ),
  144. 'animation_list' => pen_option_get( 'list_animation_reveal' ),
  145. 'animation_list_thumbnails' => pen_option_get( 'list_thumbnail_animation_reveal' ),
  146. 'animation_content' => pen_option_get( 'content_animation_reveal' ),
  147. 'animation_content_thumbnails' => pen_option_get( 'content_thumbnail_animation_reveal' ),
  148. /* phpcs:disable */
  149. 'font_resize' => array(
  150. 'site_title' => pen_option_get( 'font_resize_sitetitle' ),
  151. ),
  152. 'text' => array(
  153. 'pen_theme' => __( 'Pen', 'pen' ),
  154. 'loading' => __( 'Loading...', 'pen' ),
  155. 'enter_keyword' => __( 'Please enter some keywords.', 'pen' ),
  156. 'close' => __( 'Close', 'pen' ),
  157. 'menu' => __( 'Menu', 'pen' ),
  158. 'overview_options_post' => __( 'Content settings overview', 'pen' ),
  159. 'expand_collapse' => __( 'Expand\Collapse', 'pen' ),
  160. 'theme_specific' => __( "This is a part of the 'Pen' theme, so if you switch to another theme this nice little editing tool will be no longer available.", 'pen' ),
  161. ),
  162. /* phpcs:enable */
  163. )
  164. );
  165. if ( file_exists( $theme_directory . '/assets/js/custom.js' ) ) {
  166. wp_enqueue_script( 'pen-custom', $theme_directory . '/assets/js/custom.js', array( 'jquery' ), PEN_THEME_VERSION, true );
  167. }
  168. wp_enqueue_script( 'html5shiv', $theme_directory . '/assets/js/plugins/html5.js', array(), '3.7.3', false );
  169. wp_script_add_data( 'html5shiv', 'conditional', 'lt IE 9' );
  170. }
  171. add_action( 'wp_enqueue_scripts', 'pen_assets' );
  172. }