0f76960d1a0be76bbf07af1e6e41ac38ff8fd741.svn-base 5.0 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163
<?php if ( ! defined( 'ABSPATH' ) ) {
	die;
} // Cannot access pages directly.
/**
 *
 * Field: Editor
 *
 */
if ( ! class_exists( 'Exopite_Simple_Options_Framework_Field_editor' ) ) {

	class Exopite_Simple_Options_Framework_Field_editor extends Exopite_Simple_Options_Framework_Fields {

		public function __construct( $field, $value = '', $unique = '', $config = array() ) {
			parent::__construct( $field, $value, $unique, $config );
		}

		public function output() {

			$classes = ( isset( $this->field['class'] ) ) ? explode( ' ', $this->field['class'] ) : array();//$this->element_class()
			$editor  = ( isset( $this->field['editor'] ) ) ? $this->field['editor'] : 'tinymce';

			echo $this->element_before();

			if ( $editor == 'tinymce' && isset( $this->field['sub'] ) && $this->field['sub'] ) {

				$classes[] = 'tinymce-js';
				$classes   = implode( ' ', $classes );

				echo '<textarea id="' . $this->field['id'] . '" name="' . $this->element_name() . '" class="' . $classes . '"' . $this->element_attributes() . '>' . $this->element_value() . '</textarea>';

			} elseif ( $editor == 'trumbowyg' ) {

				$classes[] = 'trumbowyg-js';
				$classes   = implode( ' ', $classes );

				echo '<textarea id="' . $this->field['id'] . '" name="' . $this->element_name() . '" data-icon-path="' . plugin_dir_url( __DIR__ ) . 'assets/editors/trumbowyg/icons.svg" class="' . $classes . '"' . $this->element_attributes() . '>' . $this->element_value() . '</textarea>';

			} else {

				$args = array(
					'textarea_rows' => 15,
					'editor_class'  => implode( ' ', $classes ),
					'textarea_name' => $this->element_name(),
					'teeny'         => false,
					// output the minimal editor config used in Press This
					'dfw'           => false,
					// replace the default fullscreen with DFW (supported on the front-end in WordPress 3.4)
					'tinymce'       => true,
					// load TinyMCE, can be used to pass settings directly to TinyMCE using an array()
					'quicktags'     => true
					// load Quicktags, can be used to pass settings directly to Quicktags using an array()
				);

				wp_editor( $this->element_value(), $this->field['id'], $args );

			}

			echo $this->element_after();

		}

		public static function enqueue( $args ) {

			if ( isset( $args['field'] ) && isset( $args['field']['editor'] ) && is_array( $args['field']['editor'] ) ) {

				foreach ( $args['field']['editor'] as $editor ) {

					switch ( $editor ) {

						case 'trumbowyg':

							$resources = array(
								array(
									'name'       => 'trumbowyg',
									'fn'         => 'editors/trumbowyg/trumbowyg.min.css',
									'type'       => 'style',
									'dependency' => array(),
									'version'    => '2.10.0',
									'attr'       => 'all',
								),
								array(
									'name'       => 'trumbowyg-colors',
									'fn'         => 'editors/trumbowyg/trumbowyg.colors.min.css',
									'type'       => 'style',
									'dependency' => array(),
									'version'    => '2.10.0',
									'attr'       => 'all',
								),
								array(
									'name'       => 'trumbowyg-user',
									'fn'         => 'editors/trumbowyg/trumbowyg.user.min.css',
									'type'       => 'style',
									'dependency' => array(),
									'version'    => '2.10.0',
									'attr'       => 'all',
								),
								array(
									'name'       => 'trumbowyg',
									'fn'         => 'editors/trumbowyg/trumbowyg.min.js',
									'type'       => 'script',
									'dependency' => array( 'jquery' ),
									'version'    => '1.8.2',
									'attr'       => true,
								),
								array(
									'name'       => 'trumbowyg-base64',
									'fn'         => 'editors/trumbowyg/trumbowyg.base64.min.js',
									'type'       => 'script',
									'dependency' => array( 'trumbowyg' ),
									'version'    => '1.8.2',
									'attr'       => true,
								),
								array(
									'name'       => 'trumbowyg-colors',
									'fn'         => 'editors/trumbowyg/trumbowyg.colors.min.js',
									'type'       => 'script',
									'dependency' => array( 'trumbowyg' ),
									'version'    => '1.8.2',
									'attr'       => true,
								),
								array(
									'name'       => 'trumbowyg-fontfamily',
									'fn'         => 'editors/trumbowyg/trumbowyg.fontfamily.min.js',
									'type'       => 'script',
									'dependency' => array( 'trumbowyg' ),
									'version'    => '1.8.2',
									'attr'       => true,
								),
								array(
									'name'       => 'trumbowyg-fontsize',
									'fn'         => 'editors/trumbowyg/trumbowyg.fontsize.min.js',
									'type'       => 'script',
									'dependency' => array( 'trumbowyg' ),
									'version'    => '1.8.2',
									'attr'       => true,
								),
								array(
									'name'       => 'exopite-sof-trumbowyg-loader',
									'fn'         => 'loader-jquery-trumbowyg.min.js',
									'type'       => 'script',
									'dependency' => array( 'trumbowyg' ),
									'version'    => '',
									'attr'       => true,
								),

							);

							parent::do_enqueue( $resources, $args );

							break;

					}

				}

			}


		}

	}

}