From 30e6b3cbc49aa6a49ab7c17324398d7c0c818950 Mon Sep 17 00:00:00 2001 From: Aricura Date: Sat, 24 May 2014 14:11:30 +0000 Subject: [PATCH] - Add: New button in the WYSIWYG editor and in the plain text editor to easily implement the footnotes tag (icon for WYSIWYG-button missing!!!) git-svn-id: https://plugins.svn.wordpress.org/footnotes/trunk@920366 b8457f37-d9ea-0310-8a92-e5e31aec5664 --- includes/wysiwyg-editor.php | 110 ++++++++++++++++++++++++++++++++++++ index.php | 32 +++++++---- js/wysiwyg-editor.js | 76 +++++++++++++++++++++++++ readme.txt | 1 + 4 files changed, 208 insertions(+), 11 deletions(-) create mode 100644 includes/wysiwyg-editor.php create mode 100644 js/wysiwyg-editor.js diff --git a/includes/wysiwyg-editor.php b/includes/wysiwyg-editor.php new file mode 100644 index 0000000..7f1db6e --- /dev/null +++ b/includes/wysiwyg-editor.php @@ -0,0 +1,110 @@ + + + $l_str_StartingTag, "end" => $l_str_EndingTag)); + exit; +} \ No newline at end of file diff --git a/index.php b/index.php index 237774a..5d4de93 100755 --- a/index.php +++ b/index.php @@ -47,6 +47,8 @@ require_once(dirname(__FILE__) . "/includes/scripts.php"); /* include script and stylesheet functions */ require_once(dirname(__FILE__) . "/includes/convert.php"); /* include script and stylesheet functions */ +require_once(dirname(__FILE__) . "/includes/wysiwyg-editor.php"); +/* include script and stylesheet functions */ require_once(dirname(__FILE__) . "/includes/replacer.php"); /* require plugin class */ @@ -62,6 +64,25 @@ footnotes_RegisterReplacementFunctions(); /* adds javascript and stylesheets to the public page */ add_action('wp_enqueue_scripts', 'footnotes_add_public_stylesheet'); +/* defines the callback function for the editor buttons */ +add_action('wp_ajax_nopriv_footnotes_getTags', 'footnotes_wysiwyg_ajax_callback' ); +add_action('wp_ajax_footnotes_getTags', 'footnotes_wysiwyg_ajax_callback' ); +/* add new button to the WYSIWYG - editor */ +add_filter('mce_buttons', 'footnotes_wysiwyg_editor_functions'); +add_filter( "mce_external_plugins", "footnotes_wysiwyg_editor_buttons" ); +/* add new button to the plain text editor */ +add_action( 'admin_print_footer_scripts', 'footnotes_text_editor_buttons' ); + +/* action to locate language and load the wordpress-specific language file */ +add_action('plugins_loaded', 'footnotes_load_language'); + +/* add link to the settings page in plugin main page */ +$l_str_plugin_file = FOOTNOTES_PLUGIN_DIR_NAME . '/index.php'; +add_filter("plugin_action_links_{$l_str_plugin_file}", 'footnotes_plugin_settings_link', 10, 2); + +/* register footnotes widget */ +add_action('widgets_init', create_function('', 'return register_widget("Class_FootnotesWidget");')); + /* only admin is allowed to execute the plugin settings */ if (!function_exists('is_admin')) { header('Status: 403 Forbidden'); @@ -76,17 +97,6 @@ register_deactivation_hook(__FILE__, array('Class_Footnotes', 'deactivate')); /* register hook for uninstalling the plugin */ register_uninstall_hook(__FILE__, array('Class_Footnotes', 'uninstall')); - -/* action to locate language and load the wordpress-specific language file */ -add_action('plugins_loaded', 'footnotes_load_language'); - -/* add link to the settings page in plugin main page */ -$l_str_plugin_file = FOOTNOTES_PLUGIN_DIR_NAME . '/index.php'; -add_filter("plugin_action_links_{$l_str_plugin_file}", 'footnotes_plugin_settings_link', 10, 2); - -/* register footnotes widget */ -add_action('widgets_init', create_function('', 'return register_widget("Class_FootnotesWidget");')); - /* initialize an object of the plugin class */ global $g_obj_FootnotesPlugin; diff --git a/js/wysiwyg-editor.js b/js/wysiwyg-editor.js new file mode 100644 index 0000000..9e06f4c --- /dev/null +++ b/js/wysiwyg-editor.js @@ -0,0 +1,76 @@ +/** + * Created by Stefan on 24.05.14. + */ + +(function() { + tinymce.create('tinymce.plugins.Footnotes', { + /** + * Initializes the plugin, this will be executed after the plugin has been created. + * This call is done before the editor instance has finished it's initialization so use the onInit event + * of the editor instance to intercept that event. + * + * @param {tinymce.Editor} ed Editor instance that the plugin is initialized in. + * @param {string} url Absolute URL to where the plugin is located. + */ + init : function(ed, url) { + ed.addButton('footnotes', { + title : 'Footnotes', + cmd : 'footnotes' + //image : url + '/dropcap.jpg' TODO: add icon here + }); + + ed.addCommand('footnotes', function() { + jQuery.ajax({ + type: 'POST', + url: '/wp-admin/admin-ajax.php', + data: { + action: 'footnotes_getTags', + data: '' + }, + success: function(data, textStatus, XMLHttpRequest){ + var l_arr_Tags = JSON.parse(data); + var return_text = l_arr_Tags['start'] + ed.selection.getContent() + l_arr_Tags['end']; + console.log(return_text); + ed.execCommand('mceInsertContent', 0, return_text); + }, + error: function(MLHttpRequest, textStatus, errorThrown){ + console.log("Error: " + errorThrown); + } + }); + }); + }, + + /** + * Creates control instances based in the incomming name. This method is normally not + * needed since the addButton method of the tinymce.Editor class is a more easy way of adding buttons + * but you sometimes need to create more complex controls like listboxes, split buttons etc then this + * method can be used to create those. + * + * @param {String} n Name of the control to create. + * @param {tinymce.ControlManager} cm Control manager to use inorder to create new control. + * @return {tinymce.ui.Control} New control instance or null if no control was created. + */ + createControl : function(n, cm) { + return null; + }, + + /** + * Returns information about the plugin as a name/value array. + * The current keys are longname, author, authorurl, infourl and version. + * + * @return {Object} Name/value array containing information about the plugin. + */ + getInfo : function() { + return { + longname : 'Insert Footnotes tag', + author : 'media competence institute', + authorurl : 'http://cheret.co.uk/mci', + infourl : 'http://wordpress.org/plugins/footnotes/', + version : "1.1.2" + }; + } + }); + + // Register plugin + tinymce.PluginManager.add( 'footnotes', tinymce.plugins.Footnotes ); +})(); \ No newline at end of file diff --git a/readme.txt b/readme.txt index b154bf2..54cb093 100755 --- a/readme.txt +++ b/readme.txt @@ -46,6 +46,7 @@ No, this Plugin has been written from scratch. Of course some inspirations on ho - Add: Pre defined footnote short codes and possibility for a user defined short code - Add: Plugin Widget to define where the reference container shall appear when set to "widget area" - Update: Translation for new settings and for the Widget description +- Add: New button in the WYSIWYG editor and in the plain text editor to easily implement the footnotes tag (icon for WYSIWYG-button missing!!!) = 1.1.1 = - Feature: Short code to not display the 'love me' slug on specific pages ( short code = [[no footnotes: love]] )