/**
 * Enqueue JS and CSS for Themify settings page and meta boxes
 * @param String $page
 * @since 1.1.1
 *******************************************************/
function themify_enqueue_scripts($page)
{
    global $typenow;
    $pagenow = isset($_GET['page']) ? $_GET['page'] : '';
    $types = themify_post_types();
    $pages = apply_filters('themify_top_pages', array('post.php', 'post-new.php', 'toplevel_page_themify', 'nav-menus.php'));
    $pagenows = apply_filters('themify_pagenow', array('themify'));
    // Custom Write Panel
    if (($page == 'post.php' || $page == 'post-new.php') && in_array($typenow, $types)) {
        wp_enqueue_script('meta-box-tabs', get_template_directory_uri() . '/themify/js/meta-box-tabs.js', array('jquery'), '1.0', true);
        wp_enqueue_script('media-library-browse', get_template_directory_uri() . '/themify/js/media-lib-browse.js', array('jquery'), '1.0', true);
    }
    // Settings Panel
    if ($page == 'toplevel_page_themify') {
        wp_enqueue_script('jquery-ui-sortable');
    }
    if (in_array($page, $pages)) {
        //Enqueue styles
        wp_enqueue_style('themify-ui', THEMIFY_URI . '/css/themify-ui.css', array(), THEMIFY_VERSION);
        if (is_rtl()) {
            wp_enqueue_style('themify-ui-rtl', THEMIFY_URI . '/css/themify-ui-rtl.css', array(), THEMIFY_VERSION);
        }
        wp_enqueue_style('colorpicker', THEMIFY_URI . '/css/jquery.minicolors.css', array(), THEMIFY_VERSION);
        //Enqueue scripts
        wp_enqueue_script('jquery');
        wp_enqueue_script('jquery-ui-core');
        wp_enqueue_script('jquery-ui-tabs');
        wp_enqueue_script('json2');
        wp_enqueue_script('plupload-all');
        wp_enqueue_script('validate', THEMIFY_URI . '/js/jquery.validate.pack.js', array('jquery'), THEMIFY_VERSION);
        wp_enqueue_script('colorpicker-js', THEMIFY_URI . '/js/jquery.minicolors.js', array('jquery'), THEMIFY_VERSION);
        if (in_array($typenow, $types) || in_array($pagenow, $pagenows)) {
            //Don't include Themify JavaScript if we're not in one of the Themify-managed pages
            wp_enqueue_script('themify-scripts', THEMIFY_URI . '/js/scripts.js', array('jquery'), THEMIFY_VERSION);
            wp_enqueue_script('themify-plupload', THEMIFY_URI . '/js/plupload.js', array('jquery', 'themify-scripts'), THEMIFY_VERSION);
            wp_register_script('gallery-shortcode', THEMIFY_URI . '/js/gallery-shortcode.js', array('jquery', 'themify-scripts'), THEMIFY_VERSION, true);
        }
        themify_font_icons_admin_assets();
        wp_enqueue_style('magnific', THEMIFY_URI . '/css/lightbox.css', array(), THEMIFY_VERSION);
        wp_enqueue_script('magnific', THEMIFY_URI . '/js/lightbox.js', array('jquery'), THEMIFY_VERSION, true);
    }
    //Inject variable values to scripts.js previously enqueued
    wp_localize_script('themify-scripts', 'themify_js_vars', array('themify' => THEMIFY_URI, 'nonce' => wp_create_nonce('ajax-nonce'), 'admin_url' => admin_url('admin.php?page=themify'), 'ajax_url' => admin_url('admin-ajax.php'), 'app_url' => get_template_directory_uri() . '/themify/', 'theme_url' => get_template_directory_uri() . '/', 'blog_url' => site_url() . '/'));
    // Inject variable for Plupload
    $global_plupload_init = array('runtimes' => 'html5,flash,silverlight,html4', 'browse_button' => 'plupload-browse-button', 'container' => 'plupload-upload-ui', 'drop_element' => 'drag-drop-area', 'file_data_name' => 'async-upload', 'multiple_queues' => true, 'max_file_size' => wp_max_upload_size() . 'b', 'url' => admin_url('admin-ajax.php'), 'flash_swf_url' => includes_url('js/plupload/plupload.flash.swf'), 'silverlight_xap_url' => includes_url('js/plupload/plupload.silverlight.xap'), 'filters' => array(array('title' => __('Allowed Files', 'themify'), 'extensions' => 'jpg,jpeg,gif,png,ico,zip,txt,svg')), 'multipart' => true, 'urlstream_upload' => true, 'multi_selection' => false, 'multipart_params' => array('_ajax_nonce' => '', 'action' => 'themify_plupload', 'imgid' => 0));
    wp_localize_script('themify-scripts', 'global_plupload_init', $global_plupload_init);
    wp_localize_script('themify-scripts', 'themify_lang', array('confirm_reset_styling' => __('Are you sure you want to reset your theme style?', 'themify'), 'confirm_reset_settings' => __('Are you sure you want to reset your theme settings?', 'themify'), 'confirm_refresh_webfonts' => __('Are you sure you want to reset the Google WebFonts list? This will also save the current settings.', 'themify'), 'check_backup' => __('Make sure to backup before upgrading. Files and settings may get lost or changed.', 'themify'), 'confirm_delete_image' => __('Do you want to delete this image permanently?', 'themify'), 'invalid_login' => __('Invalid username or password.<br/>Contact <a href="http://themify.me/contact">Themify</a> for login issues.', 'themify'), 'enable_zip_upload' => sprintf(__('Go to your <a href="%s">Network Settings</a> to enable <strong>zip</strong>, <strong>txt</strong> and <strong>svg</strong> extensions in <strong>Upload file types</strong> field.', 'themify'), esc_url(network_admin_url('settings.php') . '#upload_filetypes')), 'filesize_error' => __('The file you are trying to upload exceeds the maximum file size allowed.', 'themify'), 'filesize_error_fix' => sprintf(__('Go to your <a href="%s">Network Settings</a> and increase the value of the <strong>Max upload file size</strong>.', 'themify'), esc_url(network_admin_url('settings.php') . '#fileupload_maxk'))));
    // Add strings to TinyMCE menu button
    themify_wpeditor_button_send_vars();
}
 /**
  * Load frontend js and css
  */
 function load_front_js_css()
 {
     wp_enqueue_style('themify-builder-style', THEMIFY_BUILDER_URI . '/css/themify-builder-style.css', array(), THEMIFY_VERSION);
     wp_enqueue_style('themify-animate', THEMIFY_BUILDER_URI . '/css/animate.min.css', array(), THEMIFY_VERSION);
     wp_register_script('themify-easy-pie-chart', THEMIFY_BUILDER_URI . '/js/jquery.easy-pie-chart.js', array('jquery'), THEMIFY_VERSION, true);
     // Themify waypoints
     wp_register_script('theme-waypoints', THEMIFY_URI . '/js/waypoints.min.js', array('jquery'), false, true);
     // load only when editing and login
     if (Themify_Builder_Model::is_frontend_editor_page()) {
         wp_enqueue_style('themify-builder-admin-ui', THEMIFY_BUILDER_URI . '/css/themify-builder-admin-ui.css', array(), THEMIFY_VERSION);
         wp_enqueue_style('themify-icons', THEMIFY_URI . '/themify-icons/themify-icons.css', array(), THEMIFY_VERSION);
         wp_enqueue_style('google-fonts-builder', themify_https_esc('http://fonts.googleapis.com/css') . '?family=Open+Sans:400,300,600|Montserrat');
         wp_enqueue_style('colorpicker', THEMIFY_URI . '/css/jquery.minicolors.css');
         // from themify framework
         wp_enqueue_script('themify-easy-pie-chart');
         // Icon picker
         wp_enqueue_script('themify-font-icons-js', THEMIFY_URI . '/js/themify.font-icons-select.js', array('jquery'), THEMIFY_VERSION, true);
         add_action('wp_footer', 'themify_font_icons_dialog', 10);
         do_action('themify_builder_admin_enqueue', $this);
     }
     // lib scripts
     if (!wp_script_is('themify-carousel-js')) {
         wp_enqueue_script('themify-carousel-js', THEMIFY_URI . '/js/carousel.js', array('jquery'));
         // grab from themify framework
     }
     // Check if BigVideo.js is loaded, if it's not, load it after loading Video.js
     if (!wp_script_is('themify-bigvideo-js')) {
         wp_enqueue_script('themify-videojs-js', THEMIFY_URI . '/js/video.js', array('jquery'));
         wp_enqueue_script('themify-bigvideo-js', THEMIFY_URI . '/js/bigvideo.js', array('themify-videojs-js'));
     }
     // Check if scroll highlight is loaded. If it's not, load it.
     if (!wp_script_is('themify-scroll-highlight')) {
         wp_enqueue_script('themify-scroll-highlight', THEMIFY_BUILDER_URI . '/js/themify.scroll-highlight.js', array('jquery'));
     }
     // module scripts
     wp_register_script('themify-builder-module-plugins-js', THEMIFY_BUILDER_URI . "/js/themify.builder.module.plugins.js", array('jquery'), THEMIFY_VERSION, true);
     wp_enqueue_script('themify-builder-module-plugins-js');
     wp_register_script('themify-builder-script-js', THEMIFY_BUILDER_URI . "/js/themify.builder.script.js", array('jquery', 'theme-waypoints'), THEMIFY_VERSION, true);
     wp_enqueue_script('themify-builder-script-js');
     wp_localize_script('themify-builder-script-js', 'tbLocalScript', array('isTouch' => themify_is_touch() ? true : false, 'animationInviewSelectors' => apply_filters('themify_builder_animation_inview_selectors', array('.fly-in > .post', '.fly-in .row_inner > .tb-column', '.fade-in > .post', '.fade-in .row_inner > .tb-column', '.slide-up > .post', '.slide-up .row_inner > .tb-column', '.col4-1.fly-in', '.col4-2.fly-in, .col4-3.fly-in', '.col3-1.fly-in', '.col3-2.fly-in', '.col2-1.fly-in', '.col-full.fly-in', '.col4-1.fade-in', '.col4-2.fade-in', '.col4-3.fade-in', '.col3-1.fade-in', '.col3-2.fade-in', '.col2-1.fade-in', '.col-full.fade-in', '.col4-1.slide-up', '.col4-2.slide-up', '.col4-3.slide-up', '.col3-1.slide-up', '.col3-2.slide-up', '.col2-1.slide-up', '.col-full.slide-up'))));
     if (Themify_Builder_Model::is_frontend_editor_page()) {
         // load module panel frontend
         add_action('wp_footer', array(&$this, 'builder_module_panel_frontedit'), 10);
         if (function_exists('wp_enqueue_media')) {
             wp_enqueue_media();
         }
         if (class_exists('Jetpack_VideoPress')) {
             // Load this so submit_button() is available in VideoPress' print_media_templates().
             require_once ABSPATH . 'wp-admin/includes/template.php';
         }
         $enqueue_scripts = array('jquery-ui-core', 'jquery-ui-accordion', 'jquery-ui-droppable', 'jquery-ui-sortable', 'jquery-ui-resizable', 'jquery-effects-core', 'media-upload', 'jquery-ui-dialog', 'wpdialogs', 'wpdialogs-popup', 'wplink', 'editor', 'quicktags', 'admin-widgets', 'colorpicker-js', 'themify-builder-google-webfont', 'themify-builder-front-ui-js');
         // is mobile version
         if ($this->isMobile()) {
             wp_register_script('themify-builder-mobile-ui-js', THEMIFY_BUILDER_URI . "/js/jquery.ui.touch-punch.js", array('jquery'), THEMIFY_VERSION, true);
             wp_enqueue_script('jquery-ui-mouse');
             wp_enqueue_script('themify-builder-mobile-ui-js');
         }
         foreach ($enqueue_scripts as $script) {
             switch ($script) {
                 case 'admin-widgets':
                     wp_enqueue_script($script, admin_url('/js/widgets.min.js'), array('jquery-ui-sortable', 'jquery-ui-draggable', 'jquery-ui-droppable'));
                     break;
                 case 'colorpicker-js':
                     wp_enqueue_script($script, THEMIFY_URI . '/js/jquery.minicolors.js', array('jquery'));
                     // grab from themify framework
                     break;
                 case 'themify-builder-google-webfont':
                     wp_enqueue_script($script, themify_https_esc('http://ajax.googleapis.com/ajax/libs/webfont/1/webfont.js'));
                     break;
                 case 'themify-builder-front-ui-js':
                     // front ui js
                     wp_register_script($script, THEMIFY_BUILDER_URI . "/js/themify.builder.front.ui.js", array('jquery', 'jquery-ui-tabs'), THEMIFY_VERSION, true);
                     wp_enqueue_script($script);
                     wp_localize_script($script, 'themifyBuilder', apply_filters('themify_builder_ajax_front_vars', array('ajaxurl' => admin_url('admin-ajax.php'), 'isTouch' => themify_is_touch() ? 'true' : 'false', 'tfb_load_nonce' => wp_create_nonce('tfb_load_nonce'), 'tfb_url' => THEMIFY_BUILDER_URI, 'post_ID' => get_the_ID(), 'dropPlaceHolder' => __('drop module here', 'themify'), 'newRowTemplate' => $this->template_vars['rows']['content'], 'draggerTitleMiddle' => __('Drag left/right to change columns', 'themify'), 'draggerTitleLast' => __('Drag left to add columns', 'themify'), 'moduleDeleteConfirm' => __('Press OK to remove this module', 'themify'), 'toggleOn' => __('Turn On Builder', 'themify'), 'toggleOff' => __('Turn Off Builder', 'themify'), 'confirm_on_turn_off' => __('Do you want to save the changes made to this page?', 'themify'), 'confirm_on_duplicate_page' => __('Save the Builder before duplicating this page?', 'themify'), 'confirm_on_unload' => __('You have unsaved data.', 'themify'), 'textImportBuilder' => __('Import From', 'themify'), 'textRowStyling' => __('Row Styling', 'themify'), 'importFileConfirm' => __('This import will override all current Builder data. Press OK to continue', 'themify'), 'confirm_template_selected' => __('This will replace your current Builder layout with the Template', 'themify'), 'load_layout_title' => __('Layouts', 'themify'), 'save_as_layout_title' => __('Save as Layout', 'themify'), 'confirm_delete_layout' => __('Are you sure want to delete this layout ?', 'themify'), 'isThemifyTheme' => $this->is_themify_theme() ? 'true' : 'false')));
                     // Themify Shortcodes Editor Button: generate and send strings for JavaScript.
                     themify_wpeditor_button_send_vars('themify-builder-front-ui-js');
                     break;
                 default:
                     wp_enqueue_script($script);
                     break;
             }
         }
     }
 }