Skip to content

Commit 42ed21e

Browse files
add tinymce button that loads add media frame
1 parent 40ae0a6 commit 42ed21e

File tree

4 files changed

+153
-0
lines changed

4 files changed

+153
-0
lines changed

classes/Visualizer/Module/Admin.php

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,59 @@ public function __construct( Visualizer_Plugin $plugin ) {
6161
$this->_addFilter( 'visualizer_logger_data', 'getLoggerData' );
6262
$this->_addFilter( 'visualizer_get_chart_counts', 'getChartCountsByTypeAndMeta' );
6363
$this->_addFilter( 'visualizer_feedback_review_trigger', 'feedbackReviewTrigger' );
64+
65+
$this->_addAction( 'admin_init', 'init' );
66+
}
67+
68+
/**
69+
* Admin init.
70+
*
71+
* @access public
72+
*/
73+
public function init() {
74+
if ( current_user_can( 'edit_posts' ) && current_user_can( 'edit_pages' ) && 'true' == get_user_option( 'rich_editing' ) ) {
75+
$this->_addFilter( 'mce_external_languages', 'add_tinymce_lang', 10, 1 );
76+
$this->_addFilter( 'mce_external_plugins', 'tinymce_plugin', 10, 1 );
77+
$this->_addFilter( 'mce_buttons', 'register_mce_button', 10, 1 );
78+
}
79+
}
80+
81+
/**
82+
* Load plugin translation for - TinyMCE API
83+
*
84+
* @access public
85+
* @param array $arr The tinymce_lang array.
86+
* @return array
87+
*/
88+
public function add_tinymce_lang( $arr ) {
89+
$ui_lang = VISUALIZER_ABSPATH . '/classes/Visualizer/Module/Language.php';
90+
$ui_lang = apply_filters( 'visualizer_ui_lang_filter', $ui_lang );
91+
$arr[] = $ui_lang;
92+
return $arr;
93+
}
94+
95+
/**
96+
* Load custom js options - TinyMCE API
97+
*
98+
* @access public
99+
* @param array $plugin_array The tinymce plugin array.
100+
* @return array
101+
*/
102+
public function tinymce_plugin( $plugin_array ) {
103+
$plugin_array['visualizer_mce_button'] = VISUALIZER_ABSURL . 'js/mce.js';
104+
return $plugin_array;
105+
}
106+
107+
/**
108+
* Register new button in the editor
109+
*
110+
* @access public
111+
* @param array $buttons The tinymce buttons array.
112+
* @return array
113+
*/
114+
public function register_mce_button( $buttons ) {
115+
array_push( $buttons, 'visualizer_mce_button' );
116+
return $buttons;
64117
}
65118

66119
/**
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
<?php
2+
/**
3+
* The Language function file for tinymce.
4+
*
5+
* @link http://themeisle.com
6+
* @since 3.0.0
7+
*
8+
*/
9+
/**
10+
*
11+
* SECURITY : Exit if accessed directly
12+
*/
13+
if ( ! defined( 'ABSPATH' ) ) {
14+
die( 'Direct access not allowed!' );
15+
}
16+
17+
/**
18+
*
19+
* Translation for TinyMCE
20+
*/
21+
22+
if ( ! class_exists( '_WP_Editors' ) ) {
23+
require( ABSPATH . WPINC . '/class-wp-editor.php' );
24+
}
25+
26+
/**
27+
* The module for all languages stuff.
28+
*
29+
* @category Visualizer
30+
* @package Module
31+
*
32+
* @since 1.0.0
33+
*/
34+
class Visualizer_Module_Language extends Visualizer_Module {
35+
36+
/**
37+
* The strings for translation.
38+
*
39+
* @access protected
40+
* @var array $strings The ID of this plugin.
41+
*/
42+
protected $strings;
43+
44+
/**
45+
* Initialize the class and set its properties.
46+
*
47+
* @since 3.0.0
48+
* @access public
49+
*/
50+
public function __construct() {
51+
$this->strings = array(
52+
'plugin_label' => __( 'Insert Chart', 'visualizer' ),
53+
'plugin_title' => __( 'Insert Chart', 'visualizer' ),
54+
);
55+
}
56+
57+
/**
58+
*
59+
* The method that returns the translation array
60+
*
61+
* @access public
62+
* @return string
63+
*/
64+
public function tinymce_translation() {
65+
66+
$locale = _WP_Editors::$mce_locale;
67+
$translated = 'tinyMCE.addI18n("' . $locale . '.visualizer_tinymce_plugin", ' . json_encode( $this->strings ) . ");\n";
68+
69+
return $translated;
70+
}
71+
72+
}
73+
74+
$visualizerLangClass = new Visualizer_Module_Language();
75+
$strings = $visualizerLangClass->tinymce_translation();

css/media.css

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,3 +162,13 @@ a.visualizer-library-pagination-page:hover {
162162
z-index: 1001;
163163
background: url(../images/ajax-loader.gif) no-repeat center center;
164164
}
165+
166+
167+
/* TinyMCE button */
168+
i.mce-i-visualizer-icon:before {
169+
content: "\f184";
170+
display: inline-block;
171+
-webkit-font-smoothing: antialiased;
172+
font: 400 20px/1 dashicons;
173+
vertical-align: top;
174+
}

js/mce.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
/* global tinymce */
2+
/* jshint unused:false */
3+
(function($) {
4+
tinymce.PluginManager.add('visualizer_mce_button', function( editor, url ) {
5+
editor.addButton( 'visualizer_mce_button', {
6+
title: editor.getLang( 'visualizer_tinymce_plugin.plugin_label' ),
7+
label: editor.getLang( 'visualizer_tinymce_plugin.plugin_label' ),
8+
icon: 'visualizer-icon',
9+
onclick: function() {
10+
$('#insert-media-button').trigger('click');
11+
}
12+
});
13+
});
14+
15+
})(jQuery);

0 commit comments

Comments
 (0)