Advertisement
jegtheme

scriptstyle.php

Jul 21st, 2015
256
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 22.22 KB | None | 0 0
  1. <?php
  2.  
  3. /**
  4. * @author jegbagus
  5. */
  6.  
  7. function jeg_is_login_page()
  8. {
  9.     return in_array($GLOBALS['pagenow'], array('wp-login.php', 'wp-register.php'));
  10. }
  11.  
  12. function is_mega_menu_installed () {
  13.     if(defined('MMPM_PLUGIN_VERSION')) {
  14.         return true;
  15.     }
  16.     return false;
  17. }
  18.  
  19. function jeg_music_bg_enabled () {
  20.     if(vp_metabox('jkreativ_music_player.enable_music') && !wp_is_mobile()) {
  21.         return true;
  22.     } else {
  23.         return false;
  24.     }
  25. }
  26.  
  27. function jeg_get_template_multisite_url() {
  28.     return apply_filters('jeg_template_multisite_url', get_template_directory_uri());
  29. }
  30.  
  31. function jeg_register_script()
  32. {
  33.     $templateurl = jeg_get_template_multisite_url();
  34.  
  35.     wp_register_script('jkreativ_maps'              , 'http://maps.google.com/maps/api/js?sensor=false', null, null, true);
  36.     wp_register_script('jkreativ_sharrre'           , $templateurl . '/public/js/external/jquery.sharrre.min.js', null, JEG_VERSION, true);
  37.     wp_register_script('jkreativ_plugin'            , $templateurl . '/public/js/external/essencialplugin.js', null, JEG_VERSION, true);
  38.     wp_register_script('jkreativ_slitslider'        , $templateurl . '/public/js/external/jquery.slitslider.js', null, JEG_VERSION, true);
  39.     wp_register_script('jkreativ_klass'             , $templateurl . '/public/js/external/klass.min.js', null, JEG_VERSION, true);
  40.     wp_register_script('jkreativ_photoswipe'        , $templateurl . '/public/js/external/code.photoswipe.jquery-3.0.5.1.min.js', array('jkreativ_klass'), JEG_VERSION, true);
  41.     wp_register_script('jkreativ_magnificpopup'     , $templateurl . '/public/js/external/jquery.magnific-popup.min.js', null, JEG_VERSION, true);
  42.     wp_register_script('jkreativ_infobubble'        , $templateurl . '/public/js/external/infobubble.js', null, JEG_VERSION, true);
  43.     wp_register_script('jkreativ_bootstrap'         , $templateurl . '/public/js/external/bootstrap.js', null, JEG_VERSION, true);
  44.     wp_register_script('jkreativ_fotorama'          , $templateurl . '/public/js/external/fotorama.js', null, JEG_VERSION, true);
  45.     wp_register_script('jkreativ_waypoint'          , $templateurl . '/public/js/external/waypoints.js', null, JEG_VERSION, true);
  46.     wp_register_script('jkreativ_isotope'           , $templateurl . '/public/js/external/jquery.isotope.min.js', null, JEG_VERSION, true);
  47.     wp_register_script('jkreativ_iosslider'         , $templateurl . '/public/js/external/jquery.iosslider.min.js', null, JEG_VERSION, true);
  48.     wp_register_script('jkreativ_typer'             , $templateurl . '/public/js/external/jquery.typer.js', null, JEG_VERSION, true);
  49.     wp_register_script('jkreativ_odometer'          , $templateurl . '/public/js/external/odometer.min.js', null, JEG_VERSION, true);
  50.     wp_register_script('jkreativ_nprogress'         , $templateurl . '/public/js/external/nprogress.js', null, JEG_VERSION, true);
  51.     wp_register_script('jkreativ_owlslider'         , $templateurl . '/public/js/external/owl.carousel.min.js', null, JEG_VERSION, true);
  52.     wp_register_script('jkreativ_kenburn'           , $templateurl . '/public/js/external/kenburns.js', null, JEG_VERSION, true);
  53.     wp_register_script('jkreativ_swipebox'          , $templateurl . '/public/js/external/jquery.swipebox.js', null, JEG_VERSION, true);
  54.     wp_register_script('jkreativ_tubular'           , $templateurl . '/public/js/external/jquery.tubular.1.0.js', null, JEG_VERSION, true);
  55.     wp_register_script('jkreativ_smoothscroll'      , $templateurl . '/public/js/external/smoothscroll.js', null, JEG_VERSION, true);
  56.     wp_register_script('jkreativ_mediaelement'      , $templateurl . '/public/mediaelementjs/mediaelement-and-player.min.js', null, JEG_VERSION, true);
  57.  
  58.     // check if development mode enabled
  59.     $folder = WP_DEBUG ? 'internal' : 'internalmin';
  60.    
  61.     wp_register_script('jkreativ_main'          , $templateurl . '/public/js/' . $folder . '/main.js', null, JEG_VERSION, true);
  62.     wp_register_script('jkreativ_common'        , $templateurl . '/public/js/' . $folder . '/jquery.jcommon.js', null, JEG_VERSION, true);
  63.     wp_register_script('jkreativ_kenburn'       , $templateurl . '/public/js/' . $folder . '/kenburns.js', null, JEG_VERSION, true);
  64.     wp_register_script('jkreativ_pageload'      , $templateurl . '/public/js/' . $folder . '/jquery.jpageload.js', null, JEG_VERSION, true);
  65.     wp_register_script('jkreativ_tooltip'       , $templateurl . '/public/js/' . $folder . '/jquery.jtooltip.js', null, JEG_VERSION, true);
  66.     wp_register_script('jkreativ_360'           , $templateurl . '/public/js/' . $folder . '/jquery.jresponsive360.js', null, JEG_VERSION, true);
  67.     wp_register_script('jkreativ_npslider'      , $templateurl . '/public/js/' . $folder . '/jquery.jnpslider.js', null, JEG_VERSION, true);
  68.     wp_register_script('jkreativ_jmusic'        , $templateurl . '/public/js/' . $folder . '/jquery.jmusic.js', null, JEG_VERSION, true);
  69.  
  70.     wp_register_script('jkreativ_product'       , $templateurl . '/public/js/' . $folder . '/jquery.jproduct.js', array(
  71.         'jkreativ_isotope', 'jkreativ_photoswipe'
  72.     ), JEG_VERSION, true);
  73.  
  74.     wp_register_script('jkreativ_psinglepage'   , $templateurl . '/public/js/' . $folder . '/jquery.jportfoliosinglepage.js', array(
  75.         'jkreativ_isotope', 'jkreativ_iosslider'
  76.     ), JEG_VERSION, true);
  77.  
  78.     wp_register_script('jkreativ_psingle'       , $templateurl . '/public/js/' . $folder . '/jquery.jportfoliosingle.js', array(
  79.         'jkreativ_isotope', 'jkreativ_iosslider'
  80.     ), JEG_VERSION, true);
  81.  
  82.     wp_register_script('jkreativ_landing'       , $templateurl . '/public/js/' . $folder . '/jquery.jlanding.js', array(
  83.         'jkreativ_tooltip', 'jkreativ_slitslider', 'jkreativ_infobubble',
  84.         'jkreativ_owlslider', 'jkreativ_waypoint', 'jkreativ_isotope',
  85.         'jkreativ_npslider', 'jkreativ_magnificpopup', 'jkreativ_typer', 'jkreativ_odometer',
  86.         'jkreativ_tubular'
  87.     ), JEG_VERSION, true);
  88.  
  89.     wp_register_script('jkreativ_portfolio'     , $templateurl . '/public/js/' . $folder . '/jquery.jportfolio.js', array(
  90.         'jkreativ_iosslider', 'jkreativ_isotope'
  91.     ), JEG_VERSION, true);
  92.  
  93.     wp_register_script('jkreativ_imggallery'    , $templateurl . '/public/js/' . $folder . '/jquery.jimggallery.js', array(
  94.         'jkreativ_fotorama', 'jkreativ_isotope', 'jkreativ_photoswipe', 'jkreativ_magnificpopup', 'jkreativ_swipebox'
  95.     ), JEG_VERSION, true);
  96.  
  97.     wp_register_script('jkreativ_fullscreen'    , $templateurl . '/public/js/' . $folder . '/jquery.jfullscreenios.js', array(
  98.         'jkreativ_iosslider'
  99.     ), JEG_VERSION, true);
  100.  
  101.     wp_register_script('jkreativ_fsmap'         , $templateurl . '/public/js/' . $folder . '/jquery.jfsmap.js', array(
  102.         'jkreativ_maps', 'jkreativ_infobubble'
  103.     ), JEG_VERSION, true);
  104.  
  105.     wp_register_script('jkreativ_masonryblog'   , $templateurl . '/public/js/' . $folder . '/jquery.jmasonryblog.js', array(
  106.         'jkreativ_fotorama', 'jkreativ_isotope'
  107.     ), JEG_VERSION, true);
  108.  
  109.     wp_register_script('jkreativ_normalblog'    , $templateurl . '/public/js/' . $folder . '/jquery.jnormalblog.js', array(
  110.         'jkreativ_sharrre', 'jkreativ_fotorama',  'jkreativ_bootstrap',
  111.         'jkreativ_photoswipe' , 'jkreativ_360'
  112.     ), JEG_VERSION, true);
  113. }
  114.  
  115. function jeg_get_js_option()
  116. {
  117.     $ismobile = wp_is_mobile();
  118.  
  119.     // populate option array
  120.     $option = array();
  121.     $option['currenturl'] = get_permalink(JEG_PAGE_ID);
  122.     $option['adminurl'] = admin_url("admin-ajax.php");
  123.     $option['themesurl'] = get_template_directory_uri();
  124.     $option['ismobile'] = $ismobile;
  125.     $option['rightclick'] = vp_option('joption.disable_rightclick');
  126.     $option['rightclickmsg'] = vp_option('joption.msg_rightclick');
  127.     $option['enablemegamenu'] = 0;
  128.     $option['menucollapsed'] = 300;
  129.     $option['smallmenuheight'] = 50;
  130.  
  131.     $option['loaderbackground'] = get_theme_mod('loader_background', '#FFF');
  132.     $option['loaderlinecolor'] = get_theme_mod('linear_color', '#000');
  133.  
  134.     if(jeg_music_bg_enabled()) {
  135.         $option['musicbg'] = true;
  136.     }
  137.  
  138.     return $option;
  139. }
  140.  
  141. function jeg_init_script ()
  142. {
  143.     jeg_register_script();
  144.  
  145.     if(!jeg_is_login_page()) {
  146.         wp_enqueue_script('jquery');
  147.         wp_enqueue_script('jkreativ_common');
  148.         wp_enqueue_script('jkreativ_main');
  149.         wp_enqueue_script('jkreativ_mediaelement');
  150.  
  151.         wp_enqueue_script('jkreativ_plugin');
  152.         wp_localize_script('jkreativ_plugin', 'joption', jeg_get_js_option());
  153.  
  154.         // smooth scroll
  155.         if(!vp_option('joption.disable_smoothscroll')) {
  156.             wp_enqueue_script('jkreativ_smoothscroll');
  157.         }
  158.  
  159.         if(jeg_is_using_loading()) {
  160.             wp_enqueue_script('jkreativ_pageload');
  161.             wp_enqueue_script('jkreativ_nprogress');
  162.         }
  163.         if ( is_singular() ) {
  164.             wp_enqueue_script( 'comment-reply' );
  165.         }
  166.  
  167.         if(jeg_music_bg_enabled()) {
  168.             wp_enqueue_script( 'jkreativ_jmusic' );
  169.         }
  170.  
  171.         jeg_load_page_spesific_script();
  172.     }
  173. }
  174.  
  175. /**
  176.  * reduce bandwidth with only load necessary script
  177.  */
  178. function jeg_load_page_spesific_script()
  179. {
  180.     global $post;
  181.  
  182.     wp_enqueue_script('jkreativ_normalblog');
  183.     if(is_home()) {
  184.         // default blog listing (index.php)
  185.         wp_enqueue_script('jkreativ_normalblog');
  186.     } else if(is_page()) {
  187.         if(function_exists('is_woocommerce') && is_account_page()) {
  188.             wp_enqueue_script('jkreativ_normalblog');
  189.         } else if(function_exists('is_shop') && is_shop()) {
  190.             wp_enqueue_script('jkreativ_product');
  191.         } else {
  192.             $template = get_post_meta($post->ID,'_wp_page_template',true);
  193.             switch ($template) {
  194.                 case 'default':
  195.                 case 'template-single-wide.php' :
  196.                 case 'template/template-page-cover.php' :
  197.                 case 'template/template-page-normal.php' :
  198.                 case 'template/template-page-wide.php' :
  199.                 case 'template/template-blog-wide.php' :
  200.                 case 'template/template-blog.php' :
  201.                 case 'template/template-blog-clean.php' :
  202.                     wp_enqueue_script('jkreativ_normalblog');
  203.                     break;
  204.                 case 'template/template-blog-masonry.php' :
  205.                     wp_enqueue_script('jkreativ_masonryblog');
  206.                     break;
  207.                 case 'template/template-contact-full-map.php' :
  208.                     wp_enqueue_script('jkreativ_fsmap');
  209.                     wp_enqueue_script('jkreativ_normalblog');
  210.                     break;
  211.                 case 'template/template-fsslider-iosslider.php' :
  212.                     wp_enqueue_script('jkreativ_fullscreen');
  213.                     break;
  214.                 case 'template/template-fsslider-kenburn.php' :
  215.                     wp_enqueue_script('jkreativ_kenburn');
  216.                     break;
  217.                 case 'template/template-fsslider-serviceslider.php' :
  218.                     wp_enqueue_script('jkreativ_slitslider');
  219.                     break;
  220.                 case 'template/template-fsslider-media.php' :
  221.                     wp_enqueue_script('jkreativ_fotorama');
  222.                     break;
  223.                 case 'template/template-media-gallery.php' :
  224.                     wp_enqueue_script('jkreativ_imggallery');
  225.                     break;
  226.                 case 'template/template-media-gallery-content.php' :
  227.                     wp_enqueue_script('jkreativ_imggallery');
  228.                     wp_enqueue_script('jkreativ_normalblog');
  229.                     break;
  230.                 case 'template/template-portfolio.php' :
  231.                     wp_enqueue_script('jkreativ_portfolio');
  232.                     wp_enqueue_script('jkreativ_normalblog');
  233.                     break;
  234.                 case 'template/template-landing-page.php' :
  235.                 case 'template/template-landing-page-vc.php' :
  236.                     wp_enqueue_script('jkreativ_normalblog');
  237.                     wp_enqueue_script('jkreativ_landing');
  238.                     break;
  239.                 case 'template/template-nowrap.php' :
  240.                     wp_enqueue_script('jkreativ_normalblog');
  241.                     break;
  242.                 default:
  243.                     break;
  244.             }
  245.         }
  246.     } else if(is_single()) {
  247.         if($post->post_type === 'portfolio') {
  248.             $layout = get_post_meta($post->ID, 'portfolio_layout', true);
  249.             switch ($layout) {
  250.                 case 'ajax':
  251.                     wp_enqueue_script('jkreativ_psingle');
  252.                     wp_enqueue_script('jkreativ_normalblog');
  253.                     break;
  254.                 case 'cover':
  255.                     wp_enqueue_script('jkreativ_psinglepage');
  256.                     wp_enqueue_script('jkreativ_normalblog');
  257.                     break;
  258.                 case 'sidecontent':
  259.                     wp_enqueue_script('jkreativ_imggallery');
  260.                     wp_enqueue_script('jkreativ_normalblog');
  261.                     break;
  262.                 case 'landingpagevc':
  263.                 case 'landingpage':
  264.                     wp_enqueue_script('jkreativ_normalblog');
  265.                     wp_enqueue_script('jkreativ_landing');
  266.                     break;
  267.                 default:
  268.                     break;
  269.             }
  270.         }
  271.         else if($post->post_type === 'post')
  272.         {
  273.             wp_enqueue_script('jkreativ_normalblog');
  274.         }
  275.         else if($post->post_type === 'product')
  276.         {
  277.             wp_enqueue_script('jkreativ_imggallery');
  278.             wp_enqueue_script('jkreativ_normalblog');
  279.         }
  280.         else {
  281.             wp_enqueue_script('jkreativ_normalblog');
  282.         }
  283.     } else if(is_archive()) {
  284.         global $wp_query;
  285.         if(function_exists('is_shop') && is_shop()) {
  286.             wp_enqueue_script('jkreativ_product');
  287.         } else if(isset($wp_query->query_vars['taxonomy']) && ( $wp_query->query_vars['taxonomy'] === 'product_cat' || $wp_query->query_vars['taxonomy'] === 'product_tag')) {
  288.             wp_enqueue_script('jkreativ_product');
  289.         } else {
  290.             $template = vp_option('joption.archive_template');
  291.             if($template === 'masonry') {
  292.                 wp_enqueue_script('jkreativ_masonryblog');
  293.             } else if($template === 'normal') {
  294.                 wp_enqueue_script('jkreativ_normalblog');
  295.             }
  296.         }
  297.     } else if(is_search()) {
  298.         $template = vp_option('joption.search_template', 'masonry');
  299.         if($template === 'masonry') {
  300.             wp_enqueue_script('jkreativ_masonryblog');
  301.         } else if($template === 'normal') {
  302.             wp_enqueue_script('jkreativ_normalblog');
  303.         }
  304.     }
  305. }
  306.  
  307. function jeg_init_style()
  308. {
  309.     if(!jeg_is_login_page()) {
  310.  
  311.         $templateurl = jeg_get_template_multisite_url();
  312.  
  313.         wp_enqueue_style ('jeg-fontawesome'     ,   $templateurl . '/public/fontawesome/font-awesome.min.css', null, JEG_VERSION);
  314.         wp_enqueue_style ('jeg-jkreativ-icon'   ,   $templateurl . '/public/jkreativ-icon/jkreativ-icon.min.css', null, JEG_VERSION);
  315.         wp_enqueue_style ('jeg-normalize'       ,   get_stylesheet_uri() , null, JEG_VERSION);
  316.         wp_enqueue_style ('jeg-plugin'          ,   $templateurl . '/public/css/plugin.css', null, JEG_VERSION);
  317.         wp_enqueue_style ('jeg-maincss'         ,   $templateurl . '/public/css/main.css', null, JEG_VERSION);
  318.         wp_enqueue_style ('jeg-boxed'           ,   $templateurl . '/public/css/boxed.css', null, JEG_VERSION);
  319.         wp_enqueue_style ('jeg-transparent'     ,   $templateurl . '/public/css/transparent.css', null, JEG_VERSION);
  320.  
  321.         if(is_mega_menu_installed()) {
  322.             wp_enqueue_style ('jeg-megamenu'    ,   $templateurl . '/public/css/jmegamenu.css', null, JEG_VERSION);
  323.         }
  324.  
  325.         wp_enqueue_style ('jeg-mediaelement'    ,   $templateurl . '/public/mediaelementjs/mediaelementplayer.min.css', null, JEG_VERSION);
  326.         wp_enqueue_style ('jeg-responsive'      ,   $templateurl . '/public/css/responsive.css', null, JEG_VERSION);
  327.  
  328.         // style schema
  329.         $style = get_theme_mod('switch_style');
  330.         switch ($style) {
  331.             case 'normal' :
  332.                 // do nothing
  333.                 break;
  334.             case 'hotel' :
  335.                 wp_enqueue_style ('switch_style' , $templateurl . '/public/css/clean-hotel.css', null, JEG_VERSION);
  336.                 break;
  337.             case 'flat':
  338.                 wp_enqueue_style ('switch_style' , $templateurl . '/public/css/flat.css', null, JEG_VERSION);
  339.                 break;
  340.             case 'dark':
  341.                 wp_enqueue_style ('switch_style' , $templateurl . '/public/css/dark.css', null, JEG_VERSION);
  342.                 break;
  343.             default:
  344.                 wp_enqueue_style ('switch_style' , $templateurl . '/public/css/normal.css', null, JEG_VERSION);
  345.                 break;
  346.         }
  347.  
  348.         $additionalcss = jeg_additional_style();
  349.         wp_add_inline_style( 'switch_style',  $additionalcss);
  350.     }
  351. }
  352.  
  353.  
  354. function jeg_build_font($fontarray) {
  355.     $fonturl = "https://fonts.googleapis.com/css?family=";
  356.  
  357.     foreach($fontarray as $idx => $font)
  358.     {
  359.         $fontname = str_replace(' ', '+', $font['fontname']);
  360.         $farray = array();
  361.  
  362.         if(!empty($font['fontstyle'])) {
  363.             foreach($font['fontstyle'] as $fontstyle) {
  364.                 // font normal
  365.                 if($fontstyle == 'normal') $fontstyle = '';
  366.  
  367.                 if(!empty($font['fontweight'])) {
  368.                     foreach($font['fontweight'] as $fontweight) {
  369.                         // font weight
  370.                         if($fontweight == 'normal') $fontweight = 400;
  371.                         $farray[] = $fontweight . $fontstyle;
  372.                     }
  373.                 }
  374.  
  375.             }
  376.         }
  377.  
  378.         if(empty($farray)) {
  379.             $fullfonturl = $fonturl . $fontname;
  380.         } else {
  381.             $fullfonturl = $fonturl . $fontname . ":" . implode(',', $farray);
  382.         }
  383.  
  384.         wp_enqueue_style ('jeg_font_' . $idx, $fullfonturl , null, null);
  385.     }
  386. }
  387.  
  388. function jeg_check_use_font_uploader($option) {
  389.     $fontname = vp_option('joption.' . $option . '_fontname');
  390.     if( !empty($fontname) ) {
  391.         return true;
  392.     }
  393.     return false;
  394. }
  395.  
  396. function jeg_font_setup () {
  397.     $fontarray = array();
  398.  
  399.     // style schema
  400.     $style = get_theme_mod('switch_style');
  401.     switch ($style) {
  402.         case 'flat':
  403.             // flat
  404.             $fontarray[0] = array(
  405.                 'fontname' => 'Open Sans',
  406.                 'fontstyle' => array('normal'),
  407.                 'fontweight' => array( '300', '400', '700')
  408.             );
  409.             $fontarray[1] = array(
  410.                 'fontname' => 'Raleway',
  411.                 'fontstyle' => array('normal', 'italic'),
  412.                 'fontweight' => array('300', '400', '700')
  413.             );
  414.             break;
  415.         case 'dark':
  416.             // dark
  417.             break;
  418.         case 'hotel' :
  419.         case 'normal' :
  420.         default:
  421.             $fontarray[0] = array(
  422.                 'fontname' => 'Open Sans',
  423.                 'fontstyle' => array('normal'),
  424.                 'fontweight' => array( '300', '400', '700')
  425.             );
  426.             $fontarray[1] = array(
  427.                 'fontname' => 'Lato',
  428.                 'fontstyle' => array('normal'),
  429.                 'fontweight' => array( '400', '700')
  430.             );
  431.             $fontarray[2] = array(
  432.                 'fontname' => 'Playfair Display',
  433.                 'fontstyle' => array('normal, italic'),
  434.                 'fontweight' => array('400')
  435.             );
  436.             break;
  437.     }
  438.  
  439.     if(!jeg_check_use_font_uploader('additional_font_1')){
  440.         $firstfont = get_theme_mod('first_font');
  441.         if(!empty($firstfont)) {
  442.             $fontarray[0] = array(
  443.                 'fontname' => $firstfont,
  444.                 'fontstyle' => jeg_extract_value(vp_get_gwf_style($firstfont)),
  445.                 'fontweight' => jeg_extract_value(vp_get_gwf_weight($firstfont))
  446.             );
  447.         }
  448.     }
  449.  
  450.     if(!jeg_check_use_font_uploader('additional_font_2')) {
  451.         $secondfont = get_theme_mod('second_font');
  452.         if (!empty($secondfont)) {
  453.             $fontarray[1] = array(
  454.                 'fontname' => $secondfont,
  455.                 'fontstyle' => jeg_extract_value(vp_get_gwf_style($secondfont)),
  456.                 'fontweight' => jeg_extract_value(vp_get_gwf_weight($secondfont))
  457.             );
  458.         }
  459.     }
  460.  
  461.     if(!jeg_check_use_font_uploader('additional_font_3')) {
  462.         $thirdfont = get_theme_mod('third_font');
  463.         if (!empty($thirdfont)) {
  464.             $fontarray[2] = array(
  465.                 'fontname' => $thirdfont,
  466.                 'fontstyle' => jeg_extract_value(vp_get_gwf_style($thirdfont)),
  467.                 'fontweight' => jeg_extract_value(vp_get_gwf_weight($thirdfont))
  468.             );
  469.         }
  470.     }
  471.  
  472.     jeg_build_font($fontarray);
  473. }
  474.  
  475. add_action('wp_enqueue_scripts', 'jeg_init_style');
  476. add_action('wp_enqueue_scripts', 'jeg_font_setup');
  477. add_action('wp_enqueue_scripts', 'jeg_init_script');
  478.  
  479. /*** additional script ****/
  480.  
  481.  
  482. function jeg_get_body_background() {
  483.     $bgobj = array();
  484.     $bgobj['color']         = get_theme_mod('website_color_background', '#ffffff');
  485.     $bgobj['imgbg']         = get_theme_mod('website_image_background', get_template_directory_uri() . '/public/img/pattern/grid_noise.png');
  486.  
  487.     if(ctype_digit($bgobj['imgbg']) || is_int($bgobj['imgbg'])) {
  488.         $bgobj['imgbg'] = wp_get_attachment_image_src($bgobj['imgbg'], "full");
  489.         $bgobj['imgbg'] = $bgobj['imgbg'][0];
  490.     }
  491.  
  492.     $bgobj['bgvertical']    = get_theme_mod('website_background_vertical_position', 'center');
  493.     $bgobj['bghorizontal']  = get_theme_mod('website_background_horizontal_position', 'center');
  494.     $bgobj['bgrepeat']      = get_theme_mod('website_background_repeat', 'repeat');
  495.     $bgobj['bgfullscreen']  = get_theme_mod('website_background_fullscreen', false);
  496.  
  497.     // alter page id
  498.     global $post;
  499.     $pageid = ($post !== null) ? jeg_alter_woo_page_id(get_the_ID()) : null;
  500.  
  501.     if(vp_metabox('jkreativ_general.override_background', null, $pageid)) {
  502.         $bgobj = array();
  503.         $bgobj['color']         = vp_metabox('jkreativ_general.override_background_group.0.color_background', null, $pageid);
  504.         $bgobj['imgbg']         = jeg_get_image_attachment(vp_metabox('jkreativ_general.override_background_group.0.image_background', null, $pageid));
  505.         $bgobj['bgvertical']    = vp_metabox('jkreativ_general.override_background_group.0.background_vertical_position', null, $pageid);
  506.         $bgobj['bghorizontal']  = vp_metabox('jkreativ_general.override_background_group.0.background_horizontal_position', null, $pageid);
  507.         $bgobj['bgrepeat']      = vp_metabox('jkreativ_general.override_background_group.0.background_repeat', null, $pageid);
  508.         $bgobj['bgfullscreen']  = vp_metabox('jkreativ_general.override_background_group.0.background_fullscreen', null, $pageid);
  509.     }
  510.  
  511.     return $bgobj;
  512. }
  513.  
  514. function jeg_generate_body_background() {
  515.     $bgobj = jeg_get_body_background();
  516.  
  517.     $css = "body { ";
  518.     if(!empty($bgobj['color'])) $css .= "\n\tbackground-color: {$bgobj['color']};";
  519.     if(!empty($bgobj['imgbg'])) {
  520.         $css .= "\n\tbackground-image: url('{$bgobj['imgbg']}');";
  521.         $css .= "\n\tbackground-position: {$bgobj['bgvertical']} {$bgobj['bghorizontal']};";
  522.         $css .= "\n\tbackground-repeat: {$bgobj['bgrepeat']};";
  523.         if($bgobj['bgfullscreen']) {
  524.             $css .= "\n\tbackground-attachment: fixed;";
  525.             $css .= "\n\tbackground-size: cover;";
  526.         }
  527.     }
  528.     $css .= "\n}";
  529.     return $css;
  530. }
  531.  
  532. function jeg_additional_style() {
  533.     $additionalcss = '';
  534.     $additionalcss .= jeg_generate_body_background();
  535.     ob_start();
  536.     get_template_part('template/additionalcss');
  537.     echo $additionalcss;
  538.     return ob_get_clean();
  539. }
  540.  
  541. /** admin style ***/
  542. function jeg_get_admin_js_option() {
  543.     $option = array();
  544.     $option['adminurl'] = admin_url("admin-ajax.php");
  545.     $option['imageurl'] = 'jeg_get_image';
  546.  
  547.     return $option;
  548. }
  549.  
  550. function jeg_init_load_script() {
  551.     wp_localize_script('jquery', 'jkreativoption', jeg_get_admin_js_option());
  552. }
  553.  
  554. function jeg_admin_theme_style() {
  555.     wp_enqueue_style ('jeg-admin-style', get_template_directory_uri() . '/public/css/admin-style.css', null, JEG_VERSION);
  556.  
  557. }
  558.  
  559. add_action('admin_enqueue_scripts', 'jeg_admin_theme_style');
  560. add_action('wp_enqueue_scripts', 'jeg_init_load_script');
  561.  
  562. /** additional javascript **/
  563. function jeg_additional_script() {
  564.     $script = "<script>\n" . vp_option('joption.jseditor') . "\n</script>\n";
  565.     echo $script;
  566. }
  567.  
  568. add_action('wp_footer', 'jeg_additional_script');
  569.  
  570.  
  571. /** favico header **/
  572. function jeg_favico_header() {
  573.     $favico = vp_option('joption.website_favico');
  574.     if($favico) {
  575.         echo '<link rel="shortcut icon" type="image/x-icon" href="' . $favico . '" />';
  576.     }
  577. }
  578.  
  579. add_action('wp_enqueue_scripts', 'jeg_favico_header');
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement