Plugin Directory

Changeset 1551976


Ignore:
Timestamp:
12/11/2016 04:05:21 PM (9 years ago)
Author:
bainternet
Message:

updated tinymce button to use native window manager

Location:
bainternet-simple-toc/trunk
Files:
7 added
2 deleted
2 edited

Legend:

Unmodified
Added
Removed
  • bainternet-simple-toc/trunk/readme.txt

    r1041024 r1551976  
    33Donate link:http://en.bainternet.info/donations
    44Tags: table of contents, toc, wiki like toc
    5 Requires at least: 2.9.2
    6 Tested up to: 4.0.1
    7 Stable tag: 0.8.1
     5Requires at least: 3.4.0
     6Tested up to: 4.7.0
     7Stable tag: 0.9.0
    88
    99create a wiki like TOC (table of contents) in your posts or pages using shortcode.
     
    6767
    6868== Changelog ==
     690.9.0 Updated Tinymce button to use the native tinymce window manager.
     70
    69710.8.1 fixed WordPress 4.0.1 replacing 3 dashes `---` with a wide dash `—`
    7072
  • bainternet-simple-toc/trunk/simple-toc.php

    r1041024 r1551976  
    44Plugin URI: http://en.bainternet.info/2011/simple-toc-table-of-contents-plugin
    55Description: Automatically create a wiki like TOC (table of contents) in your posts or pages using shortcode based on your headings.
    6 Version: 0.8.1
     6Version: 0.9.0
    77Author: Bainternet
    88Author URI: http://en.bainternet.info
     
    2929
    3030        function __construct() {
    31             add_action( 'admin_init', array( $this, 'action_admin_init' ) );
     31            $this->hooks();
     32        }
     33       
     34        function hooks(){
     35            add_action('admin_head', array( $this, 'admin_head' ) );
    3236            add_filter("the_content", array( $this, "bainternet_generate_toc" ));
    3337            add_filter("the_content", array( $this, "bainternet_generate_toc_encoded" ));
     
    3539            //plugin links row
    3640            add_filter( 'plugin_row_meta', array($this,'_my_plugin_links'), 10, 2 );
    37             if (is_admin()){
    38                 global $pagenow;
    39                 if ($pagenow=='post-new.php' || $pagenow=='post.php'){
    40                     add_action('admin_footer',array($this,'tinymce_popup'));
    41                 }
    42             }
    4341            remove_filter( 'the_content', 'wptexturize' );
    44            
     42            add_action( 'admin_enqueue_scripts', array( $this, 'admin_enqueue_scripts' ) );
     43        }
     44       
     45        function admin_head(){
     46            // check user permissions
     47            if ( !current_user_can( 'edit_posts' ) && !current_user_can( 'edit_pages' ) ) {
     48                return;
     49            }
     50            // check if WYSIWYG is enabled
     51            if ( 'true' == get_user_option( 'rich_editing' ) ) {
     52                add_filter( 'mce_external_plugins', array($this, 'mce_external_plugins' ) );
     53                add_filter( 'mce_buttons', array($this, 'mce_buttons' ) );
     54            }
     55        }
     56       
     57        function admin_enqueue_scripts() {
     58            wp_enqueue_style('simple_toc', plugins_url('/assets/css/simple_toc.css', __FILE__) );
     59        }
     60       
     61        function mce_external_plugins( $plugin_array ){
     62            $plugin_array['simple_toc'] = plugin_dir_url( __FILE__ ) . 'assets/js/simple.toc.js';
     63            return $plugin_array;
     64        }
     65       
     66        function mce_buttons( $buttons ){
     67            array_push( $buttons, 'simple_toc' );
     68            return $buttons;
    4569        }
    4670       
     
    119143        }
    120144       
    121         function action_admin_init() {
    122             // only hook up these filters if we're in the admin panel, and the current user has permission
    123             // to edit posts and pages
    124             if ( current_user_can( 'edit_posts' ) && current_user_can( 'edit_pages' ) ) {
    125                 add_filter( 'mce_buttons', array( $this, 'filter_mce_button' ) );
    126                 add_filter( 'tiny_mce_before_init', array( $this, 'filter_mce_plugin' ) );
    127             }
    128         }
    129        
    130         function filter_mce_button( $buttons ) {
    131             // add a separation before our button, here our button's id is "TOC_button"
    132             array_push( $buttons, '|', 'TOC' );
    133             return $buttons;
    134         }
    135        
    136         function filter_mce_plugin( $initArray ) {
    137             // this plugin file will work the magic of our button
    138             $initArray['setup'] = <<<JS
    139 [function(ed) {
    140     ed.addButton('TOC', {
    141         title : 'Simple TOC',
    142         image : '../wp-content/plugins/bainternet-simple-toc/toc_icon.png',
    143         onclick : function() {
    144            var width = jQuery(window).width(), H = jQuery(window).height(), W = ( 720 < width ) ? 720 : width;
    145        W = W - 80;
    146        H = H - 84;
    147        tb_show( 'Simple TOC Shortcode', '#TB_inline?width=' + W + '&height=' + H + '&inlineId=toc-form' );
    148         }
    149     });
    150 }][0]
    151 JS;
    152     return $initArray;
    153 
    154         }
    155145       
    156146        public function toc_by_h_tags($content){
     
    209199        }
    210200       
    211        public function tinymce_popup(){
    212           ?>
    213         <script type="text/javascript">
    214         jQuery(document).ready(function() {
    215           var form = jQuery('<div id="toc-form"><h2>Specify the Shortcode you want to insert.</h2><br /><ul><li><strong>Auto TOC heading</strong> -<small> insert once in the place you want your TOC to show, and specify the tag for heading (eg: h2,h3)</small></li><li><strong>TOC place holder </strong> -<small> insert once in the place you want your TOC to show</small></li><li><strong>TOC Header </strong>- <small>insert once or none at all, anywhere you want, this will show as the TOC heading</small></li><li><strong>TOC Heading </strong>- <small>insert as many headings as you want include there heading, this will be the text at the TOC link, insert where the heading is.</small></li><table id="TOC-table" class="form-table">\
    216             <tr>\
    217                 <th><label for="TOC-sc_type">What to insert?</label></th>\
    218                 <td><select name="type" id="TOC-sc_type">\
    219                     <option value="4">Auto TOC heading</option>\
    220                     <option value="1">TOC place holder</option>\
    221                     <option value="2">TOC Header</option>\
    222                     <option value="3">TOC Heading</option>\
    223                 </select><br />\
    224                 </td>\
    225             </tr>\
    226             <tr id="type_2" style="display: none;">\
    227                     <th><label for="TOC-include">Table of contents header</label></th>\
    228                     <td><input type="text" name="header" id="TOC-header" value="" /><br />\
    229                     <small>Shown on The head of the TOC, add Only Once!!</small>\
    230                     </td>\
    231             </tr>\
    232             <tr id="type_3" style="display: none;">\
    233                     <th><label for="TOC-include">TOC ITEM heading</label></th>\
    234                     <td><input type="text" name="heading" id="TOC-heading" value="" /><br />\
    235                     <small>This will be the text of the TOC link ,Usually palce one above each heading in you content</small>\
    236                     </td>\
    237             </tr>\
    238             <tr id="type_4">\
    239                     <th><label for="TOC-include">Auto generate heading by tag</label></th>\
    240                     <td><input type="text" name="tag" id="TOC-tag" value="" /><br />\
    241                     <small>This smart shortcode generates headings for you , you just need to specify the heading tag, depends on your content ( but usually h2)</small>\
    242                     </td>\
    243             </tr>\
    244         </table>\
    245         <p class="submit">\
    246             <input type="button" id="TOC-submit" class="button-primary" value="Insert" name="submit" />\
    247         </p>\
    248         </div>');
    249        
    250         var table = form.find('table');
    251         form.appendTo('body').hide();
    252         // handels the select event
    253         table.find('#TOC-sc_type').change(function(){
    254             if (table.find('#TOC-sc_type').val() == 1){
    255                 table.find('#type_2').hide('fast');
    256                 table.find('#type_3').hide('fast');
    257                 table.find('#type_4').hide('fast');
    258             }
    259             if (table.find('#TOC-sc_type').val() == 2){
    260                 table.find('#type_3').hide('fast');
    261                 table.find('#type_4').hide('fast');
    262                 table.find('#type_2').show('slow');
    263             }
    264             if (table.find('#TOC-sc_type').val() == 3){
    265                 table.find('#type_2').hide('fast');
    266                 table.find('#type_4').hide('fast');
    267                 table.find('#type_3').show('slow');
    268             }
    269             if (table.find('#TOC-sc_type').val() == 4){
    270                 table.find('#type_2').hide('fast');
    271                 table.find('#type_3').hide('fast');
    272                 table.find('#type_4').show('slow');
    273             }
    274         });
    275        
    276         // handles the click event of the submit button
    277         form.find('#TOC-submit').click(function(){
    278             // defines the options and their default values
    279             // again, this is not the most elegant way to do this
    280             // but well, this gets the job done nonetheless
    281            
    282             var shortcode = '[---TOC';
    283            
    284             if (table.find('#TOC-sc_type').val() == 2){
    285                 shortcode += ' Header:' + table.find('#TOC-header').val();
    286             }
    287             if (table.find('#TOC-sc_type').val() == 3){
    288                 shortcode += ' Heading:' + table.find('#TOC-heading').val();
    289             }           
    290             shortcode += '---]';
    291             if (table.find('#TOC-sc_type').val() == 4){
    292                 shortcode = '[---ATOC---]  <br/> [---TAG:' + table.find('#TOC-tag').val();
    293                 shortcode += '---]';
    294             }
    295             table.find('#TOC-heading').val('');
    296             table.find('#TOC-header').val('');
    297             table.find('#TOC-tag').val('');
    298             // inserts the shortcode into the active editor
    299             tinyMCE.activeEditor.execCommand('mceInsertContent', 0, shortcode);
    300            
    301             // closes Thickbox
    302             tb_remove();
    303         });
    304         });
    305            </script>
    306         <?php
    307        }
    308        
    309201        public function _my_plugin_links($links, $file) {
    310202            $plugin = plugin_basename(__FILE__); 
Note: See TracChangeset for help on using the changeset viewer.