Changeset 1551976
- Timestamp:
- 12/11/2016 04:05:21 PM (9 years ago)
- Location:
- bainternet-simple-toc/trunk
- Files:
-
- 7 added
- 2 deleted
- 2 edited
-
assets (added)
-
assets/css (added)
-
assets/css/simple_toc.css (added)
-
assets/images (added)
-
assets/images/toc_icon.png (added)
-
assets/js (added)
-
assets/js/simple.toc.js (added)
-
readme.txt (modified) (2 diffs)
-
simple-toc.php (modified) (5 diffs)
-
toc_icon.png (deleted)
-
toc_plugin.js (deleted)
Legend:
- Unmodified
- Added
- Removed
-
bainternet-simple-toc/trunk/readme.txt
r1041024 r1551976 3 3 Donate link:http://en.bainternet.info/donations 4 4 Tags: table of contents, toc, wiki like toc 5 Requires at least: 2.9.26 Tested up to: 4. 0.17 Stable tag: 0. 8.15 Requires at least: 3.4.0 6 Tested up to: 4.7.0 7 Stable tag: 0.9.0 8 8 9 9 create a wiki like TOC (table of contents) in your posts or pages using shortcode. … … 67 67 68 68 == Changelog == 69 0.9.0 Updated Tinymce button to use the native tinymce window manager. 70 69 71 0.8.1 fixed WordPress 4.0.1 replacing 3 dashes `---` with a wide dash `—` 70 72 -
bainternet-simple-toc/trunk/simple-toc.php
r1041024 r1551976 4 4 Plugin URI: http://en.bainternet.info/2011/simple-toc-table-of-contents-plugin 5 5 Description: Automatically create a wiki like TOC (table of contents) in your posts or pages using shortcode based on your headings. 6 Version: 0. 8.16 Version: 0.9.0 7 7 Author: Bainternet 8 8 Author URI: http://en.bainternet.info … … 29 29 30 30 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' ) ); 32 36 add_filter("the_content", array( $this, "bainternet_generate_toc" )); 33 37 add_filter("the_content", array( $this, "bainternet_generate_toc_encoded" )); … … 35 39 //plugin links row 36 40 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 }43 41 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; 45 69 } 46 70 … … 119 143 } 120 144 121 function action_admin_init() {122 // only hook up these filters if we're in the admin panel, and the current user has permission123 // to edit posts and pages124 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 button138 $initArray['setup'] = <<<JS139 [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 }155 145 156 146 public function toc_by_h_tags($content){ … … 209 199 } 210 200 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 event253 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 button277 form.find('#TOC-submit').click(function(){278 // defines the options and their default values279 // again, this is not the most elegant way to do this280 // but well, this gets the job done nonetheless281 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 editor299 tinyMCE.activeEditor.execCommand('mceInsertContent', 0, shortcode);300 301 // closes Thickbox302 tb_remove();303 });304 });305 </script>306 <?php307 }308 309 201 public function _my_plugin_links($links, $file) { 310 202 $plugin = plugin_basename(__FILE__);
Note: See TracChangeset
for help on using the changeset viewer.