????

Your IP : 216.73.216.174


Current Path : /home2/morganrand/www/wp-content/themes/wanderfuls-2/framework/addons/
Upload File :
Current File : /home2/morganrand/www/wp-content/themes/wanderfuls-2/framework/addons/page-animations.php

<?php
/**
 * Page Animation Functions
 *
 * @package Wanderfuls WordPress Theme
 * @subpackage Framework
 */

// Exit if accessed directly
if ( ! defined( 'ABSPATH' ) ) {
	exit;
}

// Start Class
if ( ! class_exists( 'TB_Page_Animations' ) ) {

	class TB_Page_Animations {
		private $has_animations;

		/**
		 * Main constructor
		 *
		 * @since 2.1.0
		 */
		public function __construct() {

			// Add customizer settings
			add_filter( 'tb_customizer_sections', array( $this, 'customizer_settings' ) );

			// Animations disabled by default
			$this->has_animations = false;

			// Get animations
			$this->animate_in  = apply_filters( 'tb_page_animation_in', tb_get_mod( 'page_animation_in' ) );
			$this->animate_out = apply_filters( 'tb_page_animation_out', tb_get_mod( 'page_animation_out' ) );

			// Set enabled to true
			if ( $this->animate_in || $this->animate_out ) {
				$this->has_animations = true;
			}

			// If page animations is enabled lets do things
			if ( $this->has_animations ) {

				// Load scripts
				add_filter( 'wp_enqueue_scripts', array( $this, 'get_css' ) );

				// Open wrapper
				add_action( 'tb_outer_wrap_before', array( $this, 'open_wrapper' ) );

				// Close wrapper
				add_action( 'tb_outer_wrap_after', array( $this, 'close_wrapper' ) );
			   
				// Add to localize array
				add_action( 'tb_localize_array', array( $this, 'localize' ) );

				// Add custom CSS for text
				add_action( 'tb_head_css', array( $this, 'loading_text' ) );

				// Add strings to WPML
				add_filter( 'tb_register_theme_mod_strings', array( $this, 'register_strings' ) );

			}

		}

		/**
		 * Retrieves cached CSS or generates the responsive CSS
		 *
		 * @since 2.1.0
		 */
		public function get_css() {
			wp_enqueue_style( 'animsition', TB_CSS_DIR_URI .'animsition.css' );
		}

		/**
		 * Localize script
		 *
		 * @since 2.1.0
		 */
		public function localize( $array ) {

			// Set animation to true
			$array['pageAnimation'] = true;

			// Animate In
			if ( $this->animate_in && array_key_exists( $this->animate_in, $this->in_transitions() ) ) {
				$array['pageAnimationIn'] = $this->animate_in;
			}

			// Animate out
			if ( $this->animate_out && array_key_exists( $this->animate_out, $this->out_transitions() ) ) {
				$array['pageAnimationOut'] = $this->animate_out;
			}

			// Animation Speeds
			$speed = tb_get_mod( 'page_animation_speed' );
			$speed = $speed ? $speed : 400;
			$array['pageAnimationInDuration']  = $speed;
			$array['pageAnimationOutDuration'] = $speed;

			// Loading text
			$text = tb_get_mod( 'page_animation_loading' );
			$text = $text ? $text : __( 'Loading...', 'tb' );
			$array['pageAnimationLoadingText'] = $text;

	
			// Output opening div
			return $array;

		}

		/**
		 * Open wrapper
		 *
		 * @since 2.1.0
		 *
		 */
		public function open_wrapper() {
			echo '<div class="tb-page-animation-wrap animsition clr">';
		}

		/**
		 * Close Wrapper
		 *
		 * @since 2.1.0
		 *
		 */
		public function close_wrapper() {
			echo '</div><!-- .animsition -->';
		}

		/**
		 * In Transitions
		 *
		 * @return array
		 *
		 * @since 2.1.0
		 *
		 */
		public static function in_transitions() {
			return array(
				''              => __( 'None', 'tb' ),
				'fade-in'       => __( 'Fade In', 'tb' ),
				'fade-in-up'    => __( 'Fade In Up', 'tb' ),
				'fade-in-down'  => __( 'Fade In Down', 'tb' ),
				'fade-in-left'  => __( 'Fade In Left', 'tb' ),
				'fade-in-right' => __( 'Fade In Right', 'tb' ),
				'rotate-in'     => __( 'Rotate In', 'tb' ),
				'flip-in-x'     => __( 'Flip In X', 'tb' ),
				'flip-in-y'     => __( 'Flip In Y', 'tb' ),
				'zoom-in'       => __( 'Zoom In', 'tb' ),
			);
		}

		/**
		 * Out Transitions
		 *
		 * @return array
		 *
		 * @since 2.1.0
		 */
		public static function out_transitions() {
			return array(
				''               => __( 'None', 'tb' ),
				'fade-out'       => __( 'Fade Out', 'tb' ),
				'fade-out-up'    => __( 'Fade Out Up', 'tb' ),
				'fade-out-down'  => __( 'Fade Out Down', 'tb' ),
				'fade-out-left'  => __( 'Fade Out Left', 'tb' ),
				'fade-out-right' => __( 'Fade Out Right', 'tb' ),
				'rotate-out'     => __( 'Rotate Out', 'tb' ),
				'flip-out-x'     => __( 'Flip Out X', 'tb' ),
				'flip-out-y'     => __( 'Flip Out Y', 'tb' ),
				'zoom-out'       => __( 'Zoom Out', 'tb' ),
			);
		}

		/**
		 * Add strings for WPML
		 *
		 * @return array
		 *
		 * @since 2.1.0
		 */
		public function register_strings( $strings ) {
			$strings['page_animation_loading'] = __( 'Loading...', 'tb' );
			return $strings;
		}

		/**
		 * Adds customizer settings for the animations
		 *
		 * @return array
		 *
		 * @since 2.1.0
		 */
		public function customizer_settings( $sections ) {
			$sections['tb_page_animations'] = array(
				'title' => __( 'Page Animations', 'tb' ),
				'panel' => 'tb_general',
				'desc'  => __( 'You must save your options and refresh your live site to preview changes to this setting.', 'tb' ),
				'settings' => array(
					array(
						'id' => 'page_animation_in',
						'transport' => 'postMessage',
						'control' => array (
							'label' => __( 'In Animation', 'tb' ),
							'type' => 'select',
							'choices' => $this->in_transitions(),
						),
					),
					array(
						'id' => 'page_animation_out',
						'transport' => 'postMessage',
						'control' => array (
							'label' => __( 'Out Animation', 'tb' ),
							'type' => 'select',
							'choices' => $this->out_transitions(),
						),
					),
					array(
						'id' => 'page_animation_loading',
						'transport' => 'postMessage',
						'control' => array (
							'label' => __( 'Loading Text', 'tb' ),
							'type' => 'text',
						),
					),
					array(
						'id' => 'page_animation_speed',
						'transport' => 'postMessage',
						'default' => 400,
						'control' => array (
							'label' => __( 'Speed', 'tb' ),
							'type' => 'number',
						),
					),
				)
			);
			return $sections;
		}

		/**
		 * Add loading text
		 *
		 * @since 2.0.0
		 */
		public function loading_text( $css ) {
			$text = tb_get_mod( 'page_animation_loading' );
			$text = $text ? $text : __( 'Loading...', 'tb' );
			$css .= '/*PAGE ANIMATIONS*/.animsition-loading{content:"'. $text .'";}';
			return $css;
		}

	}
}
$tb_page_transitions = new TB_Page_Animations();