Assets::register_assets()

Registers all default plugin assets.

Description

See also

Source

File: src/assets.php

	protected function register_assets() {
		$this->register_style( 'frontend', 'assets/dist/css/frontend.css', array(
			'deps' => array(),
			'ver'  => $this->plugin_version,
		) );

		$this->register_script( 'util', 'assets/dist/js/util.js', array(
			'deps'      => array( 'jquery', 'underscore', 'wp-util', 'wp-api' ),
			'ver'       => $this->plugin_version,
			'in_footer' => true,
		) );

		$this->register_style( 'admin-icons', 'assets/dist/css/admin-icons.css', array(
			'deps' => array(),
			'ver'  => $this->plugin_version,
		) );

		$this->register_script( 'admin-fixed-sidebar', 'assets/dist/js/admin-fixed-sidebar.js', array(
			'deps'      => array( 'jquery' ),
			'ver'       => $this->plugin_version,
			'in_footer' => true,
		) );

		$this->register_script( 'admin-tooltip-descriptions', 'assets/dist/js/admin-tooltip-descriptions.js', array(
			'deps'      => array( 'jquery' ),
			'ver'       => $this->plugin_version,
			'in_footer' => true,
		) );

		$this->register_style( 'admin-tooltip-descriptions', 'assets/dist/css/admin-tooltip-descriptions.css', array(
			'deps' => array( 'dashicons' ),
			'ver'  => $this->plugin_version,
		) );

		$this->register_script( 'admin-unload', 'assets/dist/js/admin-unload.js', array(
			'deps'      => array( 'jquery', 'post' ),
			'ver'       => $this->plugin_version,
			'in_footer' => true,
		) );

		$this->register_script( 'admin-form-builder', 'assets/dist/js/admin-form-builder.js', array(
			'deps'          => array( $this->prefix_handle( 'util' ), 'jquery', 'underscore', 'backbone', 'wp-backbone', 'plugin-lib-fields', 'jquery-ui-draggable', 'jquery-ui-droppable', 'jquery-ui-dialog' ),
			'ver'           => $this->plugin_version,
			'in_footer'     => true,
			'localize_name' => 'torroBuilderI18n',
			'localize_data' => array(
				'couldNotInitCanvas'         => __( 'Could not initialize form canvas as the selector points to an element that does not exist.', 'torro-forms' ),
				'couldNotLoadData'           => __( 'Could not load form builder data. Please verify that the REST API is correctly enabled on your site.', 'torro-forms' ),
				/* translators: %s: container index number */
				'defaultContainerLabel'      => __( 'Page %s', 'torro-forms' ),
				/* translators: %s: element choice index number */
				'elementChoiceLabel'         => __( 'Choice %s', 'torro-forms' ),
				'showContent'                => __( 'Show Content', 'torro-forms' ),
				'hideContent'                => __( 'Hide Content', 'torro-forms' ),
				'yes'                        => __( 'Yes', 'torro-forms' ),
				'no'                         => __( 'No', 'torro-forms' ),
				'confirmDeleteContainer'     => __( 'Do you really want to delete this page?', 'torro-forms' ),
				'confirmDeleteElement'       => __( 'Do you really want to delete this element?', 'torro-forms' ),
				'confirmDeleteElementChoice' => __( 'Do you really want to delete this choice?', 'torro-forms' ),
			),
		) );

		$this->register_style( 'admin-form-builder', 'assets/dist/css/admin-form-builder.css', array(
			'deps' => array(),
			'ver'  => $this->plugin_version,
		) );

		$this->register_script( 'admin-settings', 'assets/dist/js/admin-settings.js', array(
			'deps'      => array( 'jquery' ),
			'ver'       => $this->plugin_version,
			'in_footer' => true,
		) );

		$this->register_style( 'admin-settings', 'assets/dist/css/admin-settings.css', array(
			'deps' => array(),
			'ver'  => $this->plugin_version,
		) );

		$this->register_script( 'clipboard', 'assets/dist/js/clipboard.js', array(
			'deps'      => array(),
			'ver'       => $this->plugin_version,
			'in_footer' => true,
		) );

		$this->register_style( 'clipboard', 'assets/dist/css/clipboard.css', array(
			'deps' => array(),
			'ver'  => $this->plugin_version,
		) );

		$this->register_script( 'template-tag-fields', 'assets/dist/js/template-tag-fields.js', array(
			'deps'      => array( 'plugin-lib-fields', 'jquery' ),
			'ver'       => $this->plugin_version,
			'in_footer' => true,
		) );

		$this->register_style( 'template-tag-fields', 'assets/dist/css/template-tag-fields.css', array(
			'deps' => array( 'plugin-lib-fields' ),
			'ver'  => $this->plugin_version,
		) );

		$this->register_script( 'd3', 'node_modules/d3/d3.js', array(
			'deps'      => array(),
			'ver'       => '3.5.17',
			'in_footer' => true,
		) );

		$this->register_script( 'c3', 'node_modules/c3/c3.js', array(
			'deps'      => array( 'd3' ),
			'ver'       => '0.4.11',
			'in_footer' => true,
		) );

		$c3_script = <<<JAVASCRIPT
( function( c3 ) {
	var c3Definitions = document.getElementsByClassName( 'c3-chart-data' );
	var c3Definition, i;

	function parseFormatFunction( format ) {
		var search = [
			'%value%',
			'%percentage%',
			'%id%'
		];
		var replace, replaced, percentage, i;

		function formatter( value, id ) {
			value = Math.round( value * 100 ) / 100;

			if ( ! format.template ) {
				return '' + value;
			}

			percentage = ( ( format.aggregate && format.aggregate > 0 ) ? value / format.aggregate : 0.0 ) * 100.0;

			replace = [
				value,
				Math.round( percentage * 100 ) / 100,
				id
			];

			replaced = format.template;

			for ( i = 0; i < replace.length; i++ ) {
				replaced = replaced.replace( search[ i ], replace[ i ] );
			}

			return replaced;
		};

		return formatter;
	}

	for ( i = 0; i < c3Definitions.length; i++ ) {
		c3Definition = JSON.parse( c3Definitions[ i ].innerHTML );

		if ( 'object' === typeof c3Definition.data && 'object' === typeof c3Definition.data.labels && 'object' === typeof c3Definition.data.labels.format ) {
			c3Definition.data.labels.format = parseFormatFunction( c3Definition.data.labels.format );
		}

		c3.generate( c3Definition );
	}
}( window.c3 ) );
JAVASCRIPT;

		wp_add_inline_script( 'c3', $c3_script );

		$this->register_style( 'c3', 'node_modules/c3/c3.css', array(
			'deps' => array(),
			'ver'  => '0.4.11',
		) );

		/**
		 * Fires after all default plugin assets have been registered.
		 *
		 * Do not use this action to actually enqueue any assets, as it is only
		 * intended for registering them.
		 *
		 * @since 1.0.0
		 *
		 * @param Assets $assets The assets manager instance.
		 */
		do_action( "{$this->get_prefix()}register_assets", $this );
	}

Changelog

Changelog
Version Description
1.0.0 Introduced.