Advertisement
jegtheme

scriptstyle.php

Aug 5th, 2014
216
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 21.88 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.     $browserstring = strtolower($_SERVER['HTTP_USER_AGENT']);
  120.     if(strpos($browserstring,'ipad') !== false) {
  121.         $ismobile = true;
  122.     }
  123.  
  124.     // populate option array
  125.     $option = array();
  126.     $option['adminurl'] = admin_url("admin-ajax.php");
  127.     $option['themesurl'] = get_template_directory_uri();
  128.     $option['ismobile'] = $ismobile;
  129.     $option['rightclick'] = vp_option('joption.disable_rightclick');
  130.     $option['rightclickmsg'] = vp_option('joption.msg_rightclick');
  131.     $option['enablemegamenu'] = 0;
  132.     $option['menucollapsed'] = 300;
  133.     $option['smallmenuheight'] = 50;
  134.  
  135.     $option['loaderbackground'] = get_theme_mod('loader_background', '#FFF');
  136.     $option['loaderlinecolor'] = get_theme_mod('linear_color', '#000');
  137.  
  138.     if(jeg_music_bg_enabled()) {
  139.         $option['musicbg'] = true;
  140.     }
  141.  
  142.     return $option;
  143. }
  144.  
  145. function jeg_init_script ()
  146. {
  147.     jeg_register_script();
  148.  
  149.     if(!jeg_is_login_page()) {
  150.         wp_enqueue_script('jquery');
  151.         wp_enqueue_script('jkreativ_common');
  152.         wp_enqueue_script('jkreativ_main');
  153.         wp_enqueue_script('jkreativ_mediaelement');
  154.  
  155.         wp_enqueue_script('jkreativ_plugin');
  156.         wp_localize_script('jkreativ_plugin', 'joption', jeg_get_js_option());
  157.  
  158.         // smooth scroll
  159.         if(!vp_option('joption.disable_smoothscroll')) {
  160.             wp_enqueue_script('jkreativ_smoothscroll');
  161.         }
  162.  
  163.         if(jeg_is_using_loading()) {
  164.             wp_enqueue_script('jkreativ_pageload');
  165.             wp_enqueue_script('jkreativ_nprogress');
  166.         }
  167.         if ( is_singular() ) {
  168.             wp_enqueue_script( 'comment-reply' );
  169.         }
  170.  
  171.         if(jeg_music_bg_enabled()) {
  172.             wp_enqueue_script( 'jkreativ_jmusic' );
  173.         }
  174.  
  175.         jeg_load_page_spesific_script();
  176.     }
  177. }
  178.  
  179. /**
  180.  * reduce bandwidth with only load necessary script
  181.  */
  182. function jeg_load_page_spesific_script()
  183. {
  184.     global $post;
  185.  
  186.     if(is_home()) {
  187.         // default blog listing (index.php)
  188.         wp_enqueue_script('jkreativ_normalblog');
  189.     } else if(is_page()) {
  190.         if(function_exists('is_woocommerce') && is_account_page()) {
  191.             wp_enqueue_script('jkreativ_normalblog');
  192.         } else {
  193.             $template = get_post_meta($post->ID,'_wp_page_template',true);
  194.             switch ($template) {
  195.                 case 'default':
  196.                 case 'template-single-wide.php' :
  197.                 case 'template/template-page-cover.php' :
  198.                 case 'template/template-page-normal.php' :
  199.                 case 'template/template-page-wide.php' :
  200.                 case 'template/template-blog-wide.php' :
  201.                 case 'template/template-blog.php' :
  202.                 case 'template/template-blog-clean.php' :
  203.                     wp_enqueue_script('jkreativ_normalblog');
  204.                     break;
  205.                 case 'template/template-blog-masonry.php' :
  206.                     wp_enqueue_script('jkreativ_masonryblog');
  207.                     break;
  208.                 case 'template/template-contact-full-map.php' :
  209.                     wp_enqueue_script('jkreativ_fsmap');
  210.                     wp_enqueue_script('jkreativ_normalblog');
  211.                     break;
  212.                 case 'template/template-fsslider-iosslider.php' :
  213.                     wp_enqueue_script('jkreativ_fullscreen');
  214.                     break;
  215.                 case 'template/template-fsslider-kenburn.php' :
  216.                     wp_enqueue_script('jkreativ_kenburn');
  217.                     break;
  218.                 case 'template/template-fsslider-serviceslider.php' :
  219.                     wp_enqueue_script('jkreativ_slitslider');
  220.                     break;
  221.                 case 'template/template-fsslider-media.php' :
  222.                     wp_enqueue_script('jkreativ_fotorama');
  223.                     break;
  224.                 case 'template/template-media-gallery.php' :
  225.                     wp_enqueue_script('jkreativ_imggallery');
  226.                     break;
  227.                 case 'template/template-media-gallery-content.php' :
  228.                     wp_enqueue_script('jkreativ_imggallery');
  229.                     wp_enqueue_script('jkreativ_normalblog');
  230.                     break;
  231.                 case 'template/template-portfolio.php' :
  232.                     wp_enqueue_script('jkreativ_portfolio');
  233.                     wp_enqueue_script('jkreativ_normalblog');
  234.                     break;
  235.                 case 'template/template-landing-page.php' :
  236.                 case 'template/template-landing-page-vc.php' :
  237.                     wp_enqueue_script('jkreativ_normalblog');
  238.                     wp_enqueue_script('jkreativ_landing');
  239.                     break;
  240.                 case 'template/template-nowrap.php' :
  241.                     wp_enqueue_script('jkreativ_normalblog');
  242.                     break;
  243.                 default:
  244.                     break;
  245.             }
  246.         }
  247.     } else if(is_single()) {
  248.         if($post->post_type === 'portfolio') {
  249.             $layout = get_post_meta($post->ID, 'portfolio_layout', true);
  250.             switch ($layout) {
  251.                 case 'ajax':
  252.                     wp_enqueue_script('jkreativ_psingle');
  253.                     wp_enqueue_script('jkreativ_normalblog');
  254.                     break;
  255.                 case 'cover':
  256.                     wp_enqueue_script('jkreativ_psinglepage');
  257.                     wp_enqueue_script('jkreativ_normalblog');
  258.                     break;
  259.                 case 'sidecontent':
  260.                     wp_enqueue_script('jkreativ_imggallery');
  261.                     wp_enqueue_script('jkreativ_normalblog');
  262.                     break;
  263.                 case 'landingpagevc':
  264.                 case 'landingpage':
  265.                     wp_enqueue_script('jkreativ_normalblog');
  266.                     wp_enqueue_script('jkreativ_landing');
  267.                     break;
  268.                 default:
  269.                     break;
  270.             }
  271.         }
  272.         else if($post->post_type === 'post')
  273.         {
  274.             wp_enqueue_script('jkreativ_normalblog');
  275.         }
  276.         else if($post->post_type === 'product')
  277.         {
  278.             wp_enqueue_script('jkreativ_imggallery');
  279.             wp_enqueue_script('jkreativ_normalblog');
  280.         }
  281.         else {
  282.             wp_enqueue_script('jkreativ_normalblog');
  283.         }
  284.     } else if(is_archive()) {
  285.         global $wp_query;
  286.         if(function_exists('is_shop') && is_shop()) {
  287.             wp_enqueue_script('jkreativ_product');
  288.         } else if(isset($wp_query->query_vars['taxonomy']) && ( $wp_query->query_vars['taxonomy'] === 'product_cat' || $wp_query->query_vars['taxonomy'] === 'product_tag')) {
  289.             wp_enqueue_script('jkreativ_product');
  290.         } else {
  291.             $template = vp_option('joption.archive_template');
  292.             if($template === 'masonry') {
  293.                 wp_enqueue_script('jkreativ_masonryblog');
  294.             } else if($template === 'normal') {
  295.                 wp_enqueue_script('jkreativ_normalblog');
  296.             }
  297.         }
  298.     } else if(is_search()) {
  299.         $template = vp_option('joption.search_template', 'masonry');
  300.         if($template === 'masonry') {
  301.             wp_enqueue_script('jkreativ_masonryblog');
  302.         } else if($template === 'normal') {
  303.             wp_enqueue_script('jkreativ_normalblog');
  304.         }
  305.     }
  306. }
  307.  
  308. function jeg_init_style()
  309. {
  310.     if(!jeg_is_login_page()) {
  311.  
  312.         $templateurl = jeg_get_template_multisite_url();
  313.  
  314.         wp_enqueue_style ('jeg-fontawesome'     ,   $templateurl . '/public/fontawesome/font-awesome.min.css', null, JEG_VERSION);
  315.         wp_enqueue_style ('jeg-jkreativ-icon'   ,   $templateurl . '/public/jkreativ-icon/jkreativ-icon.min.css', null, JEG_VERSION);
  316.         wp_enqueue_style ('jeg-normalize'       ,   $templateurl . '/style.css', null, JEG_VERSION);
  317.         wp_enqueue_style ('jeg-plugin'          ,   $templateurl . '/public/css/plugin.css', null, JEG_VERSION);
  318.         wp_enqueue_style ('jeg-maincss'         ,   $templateurl . '/public/css/main.css', null, JEG_VERSION);
  319.         wp_enqueue_style ('jeg-boxed'           ,   $templateurl . '/public/css/boxed.css', null, JEG_VERSION);
  320.         wp_enqueue_style ('jeg-transparent'     ,   $templateurl . '/public/css/transparent.css', null, JEG_VERSION);
  321.  
  322.         if(is_mega_menu_installed()) {
  323.             wp_enqueue_style ('jeg-megamenu'    ,   $templateurl . '/public/css/jmegamenu.css', null, JEG_VERSION);
  324.         }
  325.  
  326.         wp_enqueue_style ('jeg-mediaelement'    ,   $templateurl . '/public/mediaelementjs/mediaelementplayer.min.css', null, JEG_VERSION);
  327.         wp_enqueue_style ('jeg-responsive'      ,   $templateurl . '/public/css/responsive.css', null, JEG_VERSION);
  328.  
  329.         // style schema
  330.         $style = get_theme_mod('switch_style');
  331.         switch ($style) {
  332.             case 'normal' :
  333.                 // do nothing
  334.                 break;
  335.             case 'hotel' :
  336.                 wp_enqueue_style ('switch_style' , $templateurl . '/public/css/clean-hotel.css', null, JEG_VERSION);
  337.                 break;
  338.             case 'flat':
  339.                 wp_enqueue_style ('switch_style' , $templateurl . '/public/css/flat.css', null, JEG_VERSION);
  340.                 break;
  341.             case 'dark':
  342.                 wp_enqueue_style ('switch_style' , $templateurl . '/public/css/dark.css', null, JEG_VERSION);
  343.                 break;
  344.             default:
  345.                 wp_enqueue_style ('switch_style' , $templateurl . '/public/css/normal.css', null, JEG_VERSION);
  346.                 break;
  347.         }
  348.  
  349.         $additionalcss = jeg_additional_style();
  350.         wp_add_inline_style( 'switch_style',  $additionalcss);
  351.     }
  352. }
  353.  
  354.  
  355. function jeg_build_font($fontarray) {
  356.     $fonturl = "https://fonts.googleapis.com/css?family=";
  357.  
  358.     foreach($fontarray as $idx => $font)
  359.     {
  360.         $fontname = str_replace(' ', '+', $font['fontname']);
  361.         $farray = array();
  362.  
  363.         if(!empty($font['fontstyle'])) {
  364.             foreach($font['fontstyle'] as $fontstyle) {
  365.                 // font normal
  366.                 if($fontstyle == 'normal') $fontstyle = '';
  367.  
  368.                 if(!empty($font['fontweight'])) {
  369.                     foreach($font['fontweight'] as $fontweight) {
  370.                         // font weight
  371.                         if($fontweight == 'normal') $fontweight = 400;
  372.                         $farray[] = $fontweight . $fontstyle;
  373.                     }
  374.                 }
  375.  
  376.             }
  377.         }
  378.  
  379.         if(empty($farray)) {
  380.             $fullfonturl = $fonturl . $fontname;
  381.         } else {
  382.             $fullfonturl = $fonturl . $fontname . ":" . implode(',', $farray);
  383.         }
  384.  
  385.         wp_enqueue_style ('jeg_font_' . $idx, $fullfonturl , null, null);
  386.     }
  387. }
  388.  
  389. function jeg_check_use_font_uploader($option) {
  390.     $fontname = vp_option('joption.' . $option . '_fontname');
  391.     if( !empty($fontname) ) {
  392.         return true;
  393.     }
  394.     return false;
  395. }
  396.  
  397. function jeg_font_setup () {
  398.     $fontarray = array();
  399.  
  400.     // style schema
  401.     $style = get_theme_mod('switch_style');
  402.     switch ($style) {
  403.         case 'flat':
  404.             // flat
  405.             $fontarray[0] = array(
  406.                 'fontname' => 'Open Sans',
  407.                 'fontstyle' => array('normal'),
  408.                 'fontweight' => array( '300', '400', '700')
  409.             );
  410.             $fontarray[1] = array(
  411.                 'fontname' => 'Raleway',
  412.                 'fontstyle' => array('normal', 'italic'),
  413.                 'fontweight' => array('300', '400', '700')
  414.             );
  415.             break;
  416.         case 'dark':
  417.             // dark
  418.             break;
  419.         case 'hotel' :
  420.         case 'normal' :
  421.         default:
  422.             $fontarray[0] = array(
  423.                 'fontname' => 'Open Sans',
  424.                 'fontstyle' => array('normal'),
  425.                 'fontweight' => array( '300', '400', '700')
  426.             );
  427.             $fontarray[1] = array(
  428.                 'fontname' => 'Lato',
  429.                 'fontstyle' => array('normal'),
  430.                 'fontweight' => array( '400', '700')
  431.             );
  432.             $fontarray[2] = array(
  433.                 'fontname' => 'Playfair Display',
  434.                 'fontstyle' => array('normal, italic'),
  435.                 'fontweight' => array('400')
  436.             );
  437.             break;
  438.     }
  439.  
  440.     if(!jeg_check_use_font_uploader('additional_font_1')){
  441.         $firstfont = get_theme_mod('first_font');
  442.         if(!empty($firstfont)) {
  443.             $fontarray[0] = array(
  444.                 'fontname' => $firstfont,
  445.                 'fontstyle' => jeg_extract_value(vp_get_gwf_style($firstfont)),
  446.                 'fontweight' => jeg_extract_value(vp_get_gwf_weight($firstfont))
  447.             );
  448.         }
  449.     }
  450.  
  451.     if(!jeg_check_use_font_uploader('additional_font_2')) {
  452.         $secondfont = get_theme_mod('second_font');
  453.         if (!empty($secondfont)) {
  454.             $fontarray[1] = array(
  455.                 'fontname' => $secondfont,
  456.                 'fontstyle' => jeg_extract_value(vp_get_gwf_style($secondfont)),
  457.                 'fontweight' => jeg_extract_value(vp_get_gwf_weight($secondfont))
  458.             );
  459.         }
  460.     }
  461.  
  462.     if(!jeg_check_use_font_uploader('additional_font_3')) {
  463.         $thirdfont = get_theme_mod('third_font');
  464.         if (!empty($thirdfont)) {
  465.             $fontarray[2] = array(
  466.                 'fontname' => $thirdfont,
  467.                 'fontstyle' => jeg_extract_value(vp_get_gwf_style($thirdfont)),
  468.                 'fontweight' => jeg_extract_value(vp_get_gwf_weight($thirdfont))
  469.             );
  470.         }
  471.     }
  472.  
  473.     jeg_build_font($fontarray);
  474. }
  475.  
  476. add_action('wp_enqueue_scripts', 'jeg_init_style');
  477. add_action('wp_enqueue_scripts', 'jeg_font_setup');
  478. add_action('wp_enqueue_scripts', 'jeg_init_script');
  479.  
  480. /*** additional script ****/
  481.  
  482.  
  483. function jeg_get_body_background() {
  484.     $bgobj = array();
  485.     $bgobj['color']         = get_theme_mod('website_color_background', '#ffffff');
  486.     $bgobj['imgbg']         = get_theme_mod('website_image_background', get_template_directory_uri() . '/public/img/pattern/grid_noise.png');
  487.  
  488.     if(ctype_digit($bgobj['imgbg']) || is_int($bgobj['imgbg'])) {
  489.         $bgobj['imgbg'] = wp_get_attachment_image_src($bgobj['imgbg'], "full");
  490.         $bgobj['imgbg'] = $bgobj['imgbg'][0];
  491.     }
  492.  
  493.     $bgobj['bgvertical']    = get_theme_mod('website_background_vertical_position', 'center');
  494.     $bgobj['bghorizontal']  = get_theme_mod('website_background_horizontal_position', 'center');
  495.     $bgobj['bgrepeat']      = get_theme_mod('website_background_repeat', 'repeat');
  496.     $bgobj['bgfullscreen']  = get_theme_mod('website_background_fullscreen', false);
  497.  
  498.     // alter page id
  499.     global $post;
  500.     $pageid = ($post !== null) ? jeg_alter_woo_page_id(get_the_ID()) : null;
  501.  
  502.     if(vp_metabox('jkreativ_general.override_background', null, $pageid)) {
  503.         $bgobj = array();
  504.         $bgobj['color']         = vp_metabox('jkreativ_general.override_background_group.0.color_background', null, $pageid);
  505.         $bgobj['imgbg']         = jeg_get_image_attachment(vp_metabox('jkreativ_general.override_background_group.0.image_background', null, $pageid));
  506.         $bgobj['bgvertical']    = vp_metabox('jkreativ_general.override_background_group.0.background_vertical_position', null, $pageid);
  507.         $bgobj['bghorizontal']  = vp_metabox('jkreativ_general.override_background_group.0.background_horizontal_position', null, $pageid);
  508.         $bgobj['bgrepeat']      = vp_metabox('jkreativ_general.override_background_group.0.background_repeat', null, $pageid);
  509.         $bgobj['bgfullscreen']  = vp_metabox('jkreativ_general.override_background_group.0.background_fullscreen', null, $pageid);
  510.     }
  511.  
  512.     return $bgobj;
  513. }
  514.  
  515. function jeg_generate_body_background() {
  516.     $bgobj = jeg_get_body_background();
  517.  
  518.     $css = "body { ";
  519.     if(!empty($bgobj['color'])) $css .= "\n\tbackground-color: {$bgobj['color']};";
  520.     if(!empty($bgobj['imgbg'])) {
  521.         $css .= "\n\tbackground-image: url('{$bgobj['imgbg']}');";
  522.         $css .= "\n\tbackground-position: {$bgobj['bgvertical']} {$bgobj['bghorizontal']};";
  523.         $css .= "\n\tbackground-repeat: {$bgobj['bgrepeat']};";
  524.         if($bgobj['bgfullscreen']) {
  525.             $css .= "\n\tbackground-attachment: fixed;";
  526.             $css .= "\n\tbackground-size: cover;";
  527.         }
  528.     }
  529.     $css .= "\n}";
  530.     return $css;
  531. }
  532.  
  533. function jeg_additional_style() {
  534.     $additionalcss = '';
  535.     $additionalcss .= jeg_generate_body_background();
  536.     ob_start();
  537.     get_template_part('template/additionalcss');
  538.     echo $additionalcss;
  539.     return ob_get_clean();
  540. }
  541.  
  542. /** admin style ***/
  543. function jeg_get_admin_js_option() {
  544.     $option = array();
  545.     $option['adminurl'] = admin_url("admin-ajax.php");
  546.     $option['imageurl'] = 'jeg_get_image';
  547.  
  548.     return $option;
  549. }
  550.  
  551. function jeg_init_load_script() {
  552.     wp_localize_script('jquery', 'jkreativoption', jeg_get_admin_js_option());
  553. }
  554.  
  555. function jeg_admin_theme_style() {
  556.     wp_enqueue_style ('jeg-admin-style', get_template_directory_uri() . '/public/css/admin-style.css', null, JEG_VERSION);
  557.  
  558. }
  559.  
  560. add_action('admin_enqueue_scripts', 'jeg_admin_theme_style');
  561. add_action('wp_enqueue_scripts', 'jeg_init_load_script');
  562.  
  563. /** additional javascript **/
  564. function jeg_additional_script() {
  565.     $script = "<script>\n" . vp_option('joption.jseditor') . "\n</script>\n";
  566.     echo $script;
  567. }
  568.  
  569. add_action('wp_footer', 'jeg_additional_script');
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement