Making WordPress.org

Ticket #4835: 4835.diff

File 4835.diff, 4.6 KB (added by valentinbora, 5 years ago)

New plugin wporg-bbp-code-blocks adding code expand/contract functionality

  • new file wordpress.org/public_html/wp-content/plugins/wporg-bbp-code-blocks/wporg-bbp-code-blocks-expand-contract.css

    diff --git wordpress.org/public_html/wp-content/plugins/wporg-bbp-code-blocks/wporg-bbp-code-blocks-expand-contract.css wordpress.org/public_html/wp-content/plugins/wporg-bbp-code-blocks/wporg-bbp-code-blocks-expand-contract.css
    new file mode 100644
    index 000000000..b864b00b1
    - +  
     1.wporg-bbp-code-tools {
     2        margin-top: -24px;
     3        margin-bottom: 24px;
     4}
     5
     6#bbpress-forums div.bbp-reply-content a.wporg-bbp-code-expand,
     7#bbpress-forums div.bbp-topic-content a.wporg-bbp-code-expand {
     8        background: #f0f0f0;
     9        display: inline-block;
     10        border: 1px solid #ddd;
     11        border-top: none;
     12        padding: 3px 8px 3px 4px;
     13        text-decoration: none;
     14}
     15
     16.wporg-bbp-code-expand:before {
     17        font: 400 16px/1 dashicons;
     18        margin-right: 3px;
     19        float: left;
     20        padding-top: 3px;
     21        content: "\f347";
     22}
     23
     24.wporg-bbp-code-expand.wporg-bbp-code-expanded:before {
     25        content: "\f343";
     26}
  • new file wordpress.org/public_html/wp-content/plugins/wporg-bbp-code-blocks/wporg-bbp-code-blocks-expand-contract.js

    diff --git wordpress.org/public_html/wp-content/plugins/wporg-bbp-code-blocks/wporg-bbp-code-blocks-expand-contract.js wordpress.org/public_html/wp-content/plugins/wporg-bbp-code-blocks/wporg-bbp-code-blocks-expand-contract.js
    new file mode 100644
    index 000000000..e0fd7bbe6
    - +  
     1jQuery(document).ready( function($) {
     2        $( '.bbp-topic-content > pre > code, .bbp-reply-content > pre > code' ).each( function() {
     3                var $el = $( this );
     4
     5                if ( typeof this.scrollHeight !== 'undefined' && $el.height() < this.scrollHeight ) {
     6                        var btn = $( '<div class="wporg-bbp-code-tools"><a class="wporg-bbp-code-expand" href="#">Expand</a></div>' );
     7
     8                        btn.insertAfter( $el.closest( 'pre' ) )
     9                }
     10        });
     11
     12        $( '.wporg-bbp-code-expand' ).on( 'click', function(el) {
     13                var pre = $( this ).closest( 'div' ).prev( 'pre' ),
     14                        code = pre.find( 'code' ),
     15                        heightGoal,
     16                        maxHeightGoal,
     17                        scrollGoal;
     18
     19                if ( $( this ).hasClass( 'wporg-bbp-code-expanded' ) ) {
     20                        maxHeightGoal = pre.data( 'bbpInitHeight' );
     21                        scrollGoal = pre.offset().top - 45;
     22                } else {
     23                        pre.data( 'bbpInitHeight', pre.css( 'max-height' ) );
     24                        heightGoal = code.get( 0 ).scrollHeight;
     25                        maxHeightGoal = 'none';
     26                }
     27
     28                if ( typeof heightGoal !== 'undefined' ) {
     29                        pre.css( 'max-height', maxHeightGoal );
     30                        code.css( 'max-height', maxHeightGoal );
     31                        code.animate( { height: heightGoal });
     32                        $( this ).text( 'Contract' );
     33                } else {
     34                        $( [document.documentElement, document.body] ).animate({
     35                                scrollTop: scrollGoal
     36                            },
     37                            600,
     38                            'swing',
     39                            function() {
     40                                        pre.css( 'max-height', maxHeightGoal );
     41                                        code.css( 'max-height', maxHeightGoal );
     42                            }
     43                    );
     44
     45                        $( this ).text( 'Expand' );
     46                }
     47
     48                $( this ).toggleClass( 'wporg-bbp-code-expanded' );
     49
     50                return false;
     51        });
     52});
     53 No newline at end of file
  • new file wordpress.org/public_html/wp-content/plugins/wporg-bbp-code-blocks/wporg-bbp-code-blocks.php

    diff --git wordpress.org/public_html/wp-content/plugins/wporg-bbp-code-blocks/wporg-bbp-code-blocks.php wordpress.org/public_html/wp-content/plugins/wporg-bbp-code-blocks/wporg-bbp-code-blocks.php
    new file mode 100644
    index 000000000..77d344753
    - +  
     1<?php
     2/**
     3 * Plugin Name: bbPress: Code blocks formatter
     4 * Description: Convert wiki markup links into HTML WordPress Codex links.
     5 * Version:     1.0
     6 * Author:      WordPress.org
     7 * Author URI:  https://wordpress.org/
     8 * License:     GPLv2 or later
     9 *
     10 */
     11
     12/**
     13 *      This program is free software; you can redistribute it and/or modify
     14 *      it under the terms of the GNU General Public License, version 2, as
     15 *      published by the Free Software Foundation.
     16 *
     17 *      This program is distributed in the hope that it will be useful,
     18 *      but WITHOUT ANY WARRANTY; without even the implied warranty of
     19 *      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     20 *      GNU General Public License for more details.
     21 *
     22 *      You should have received a copy of the GNU General Public License
     23 *      along with this program; if not, see <http://www.gnu.org/licenses/>.
     24 */
     25
     26if ( ! defined( 'ABSPATH' ) ) exit;
     27
     28if ( ! class_exists( 'WPORG_bbPress_Code_Blocks' ) ) {
     29class WPORG_bbPress_Code_Blocks {
     30        public function __construct() {
     31                wp_enqueue_script( 'wporg-bbp-code-blocks-expand-contract', plugins_url( 'wporg-bbp-code-blocks-expand-contract.js', __FILE__ ), [ 'jquery' ], 1, true );
     32                wp_enqueue_style( 'wporg-bbp-code-blocks-expand-contract', plugins_url( 'wporg-bbp-code-blocks-expand-contract.css', __FILE__ ), [], 1 );
     33        }
     34} }
     35
     36new WPORG_bbPress_Code_Blocks;