<?php
namespace ERROPiX\AIOW;

// don't load directly
if ( ! defined( 'ABSPATH' ) ) die( '-1' );

/**
 * JS Helper
*/
class JS {
	static $scripts;
	
	static function load() {
		self::$scripts = array();
		add_action( 'wp_footer', __class__.'::output' );
		add_action( 'wp_enqueue_scripts', __class__.'::enqueue' );
	}
	
	static function exists( $id ) {
		return isset(self::$scripts[$id]);
	}
	
	static function enqueue( $id ) {
		wp_enqueue_script( 'js_composer_front' );
	}
	
	static function add( $js, $id='default' ) {
		if( $js ) {
			if( !self::exists( $id ) ) {
				self::$scripts[$id] = '';
			}
			self::$scripts[$id] .= $js;
		}
	}
	
	static function output() {
		$js = implode( '\n', self::$scripts );
		if( $js ) {
			echo '<script type="text/javascript">'. $js .'</script>';
		}
	}
}