Plugin Directory

Changeset 3009226


Ignore:
Timestamp:
12/13/2023 07:44:37 AM (2 years ago)
Author:
web83info
Message:

Add: Animation timeout
Tested up to WordPress 6.4.2.

Location:
show-current-width
Files:
21 added
7 edited

Legend:

Unmodified
Added
Removed
  • show-current-width/trunk/assets/show-current-width.js

    r2973725 r3009226  
    66        this.timeoutWidth = undefined;
    77        this.timeoutCountUp = undefined;
    8         this.delay = 500;
     8        this.delay = ShowCurrentWidthVariables.animation_timeout;
    99        this.widthFrom = 0;
    1010        this.widthTo = window.innerWidth;
  • show-current-width/trunk/assets/show-current-width.min.js

    r2973725 r3009226  
    1 "use strict";class ShowCurrentWidth{constructor(){this.timeoutWidth=void 0,this.timeoutCountUp=void 0,this.delay=500,this.widthFrom=0,this.widthTo=window.innerWidth,this.widthNow=0,this.countUpProceeding=!1,window.addEventListener("load",this.showWidth()),window.addEventListener("load",this.showWidthDelay())}showWidth(){this.widthTo=window.innerWidth,1==ShowCurrentWidthVariables.animation_show?(this.countUpProceeding=!0,this.showWidthWithAnimation()):this.showWidthWithoutAnimation()}showWidthWithAnimation(){let t=Math.abs(this.widthTo-this.widthFrom)/30;if(this.showWidthCore(this.widthNow),!this.countUpProceeding)return clearTimeout(this.timeoutCountUp),void(this.widthFrom=this.widthTo);this.widthNow>this.widthTo?this.widthNow-=t:this.widthNow<this.widthTo&&(this.widthNow+=t),Math.abs(this.widthNow-this.widthTo)<=t&&(this.widthNow=this.widthTo,this.countUpProceeding=!1),this.timeoutCountUp=setTimeout(()=>{this.showWidthWithAnimation()},7)}showWidthWithoutAnimation(){this.showWidthCore(this.widthTo)}showWidthCore(t){let i=void 0,h=void 0,o=new Array,e="»",d=void 0;ShowCurrentWidthVariables.breakpoints_definition.split("\n").forEach((t,e)=>{let d=t.trim().split(/\s*,\s*/);d[0]<=this.widthNow&&this.widthNow<d[1]?(i=d[2],h=d[3],o[e]=!0):o[e]=!1}),document.querySelector("#wp-admin-bar-show-current-width .ab-icon .width").textContent=Math.round(t),document.querySelector("#wp-admin-bar-show-current-width .ab-label .width").textContent=Math.round(t),1==ShowCurrentWidthVariables.breakpoints_show&&(document.querySelector("#wp-admin-bar-show-current-width .breakpoint").textContent=i,document.querySelector("#wp-admin-bar-show-current-width-breakpoint .breakpoint").textContent=h,o.forEach((t,i)=>{d=t?e:"",document.querySelector("#wp-admin-bar-show-current-width-breakpoint-"+i+" .icon").textContent=d}))}showWidthDelay(){window.addEventListener("resize",()=>{clearTimeout(this.timeoutWidth),this.timeoutWidth=setTimeout(()=>{this.showWidth()},this.delay)},!1)}}new ShowCurrentWidth;
     1"use strict";class ShowCurrentWidth{constructor(){this.timeoutWidth=void 0,this.timeoutCountUp=void 0,this.delay=ShowCurrentWidthVariables.animation_timeout,this.widthFrom=0,this.widthTo=window.innerWidth,this.widthNow=0,this.countUpProceeding=!1,window.addEventListener("load",this.showWidth()),window.addEventListener("load",this.showWidthDelay())}showWidth(){this.widthTo=window.innerWidth,1==ShowCurrentWidthVariables.animation_show?(this.countUpProceeding=!0,this.showWidthWithAnimation()):this.showWidthWithoutAnimation()}showWidthWithAnimation(){let t=Math.abs(this.widthTo-this.widthFrom)/30;if(this.showWidthCore(this.widthNow),!this.countUpProceeding)return clearTimeout(this.timeoutCountUp),void(this.widthFrom=this.widthTo);this.widthNow>this.widthTo?this.widthNow-=t:this.widthNow<this.widthTo&&(this.widthNow+=t),Math.abs(this.widthNow-this.widthTo)<=t&&(this.widthNow=this.widthTo,this.countUpProceeding=!1),this.timeoutCountUp=setTimeout(()=>{this.showWidthWithAnimation()},7)}showWidthWithoutAnimation(){this.showWidthCore(this.widthTo)}showWidthCore(t){let i=void 0,h=void 0,o=new Array,e="»",d=void 0;ShowCurrentWidthVariables.breakpoints_definition.split("\n").forEach((t,e)=>{let d=t.trim().split(/\s*,\s*/);d[0]<=this.widthNow&&this.widthNow<d[1]?(i=d[2],h=d[3],o[e]=!0):o[e]=!1}),document.querySelector("#wp-admin-bar-show-current-width .ab-icon .width").textContent=Math.round(t),document.querySelector("#wp-admin-bar-show-current-width .ab-label .width").textContent=Math.round(t),1==ShowCurrentWidthVariables.breakpoints_show&&(document.querySelector("#wp-admin-bar-show-current-width .breakpoint").textContent=i,document.querySelector("#wp-admin-bar-show-current-width-breakpoint .breakpoint").textContent=h,o.forEach((t,i)=>{d=t?e:"",document.querySelector("#wp-admin-bar-show-current-width-breakpoint-"+i+" .icon").textContent=d}))}showWidthDelay(){window.addEventListener("resize",()=>{clearTimeout(this.timeoutWidth),this.timeoutWidth=setTimeout(()=>{this.showWidth()},this.delay)},!1)}}new ShowCurrentWidth;
  • show-current-width/trunk/class/class-showcurrentwidth-admin.php

    r2979825 r3009226  
    2121
    2222    /**
    23      * Plugin constant.
     23     * Constructor.
    2424     *
    2525     * @return void
     
    124124            ),
    125125        );
    126         // Add field 1-4 (Animation on/off).
     126
     127        // Add section 2.
     128        add_settings_section(
     129            ShowCurrentWidth_Core::PLUGIN_PREFIX . '-section2',
     130            __( 'Display settings', 'show-current-width' ),
     131            array( $this, 'register_section2_html' ),
     132            ShowCurrentWidth_Core::PLUGIN_PREFIX
     133        );
     134        // Add field 2-1 (Admin page display).
     135        add_settings_field(
     136            ShowCurrentWidth_Core::PLUGIN_PREFIX . '_admin_show',
     137            __( 'Admin page display', 'show-current-width' ),
     138            array( $this, 'register_field_admin_show_html' ),
     139            ShowCurrentWidth_Core::PLUGIN_PREFIX,
     140            ShowCurrentWidth_Core::PLUGIN_PREFIX . '-section2',
     141            array(
     142                'label_for' => ShowCurrentWidth_Core::PLUGIN_PREFIX . '_admin_show',
     143            ),
     144        );
     145        // Add field 2-2 (Role condition).
     146        add_settings_field(
     147            ShowCurrentWidth_Core::PLUGIN_PREFIX . '_condition_role',
     148            __( 'Role condition', 'show-current-width' ),
     149            array( $this, 'register_field_condition_role_html' ),
     150            ShowCurrentWidth_Core::PLUGIN_PREFIX,
     151            ShowCurrentWidth_Core::PLUGIN_PREFIX . '-section2',
     152            array(
     153                'label_for' => ShowCurrentWidth_Core::PLUGIN_PREFIX . '_condition_role',
     154            ),
     155        );
     156        // Add field 2-3 (Animation on/off).
    127157        add_settings_field(
    128158            ShowCurrentWidth_Core::PLUGIN_PREFIX . '_animation_show',
     
    130160            array( $this, 'register_field_animation_show_html' ),
    131161            ShowCurrentWidth_Core::PLUGIN_PREFIX,
    132             ShowCurrentWidth_Core::PLUGIN_PREFIX . '-section1',
     162            ShowCurrentWidth_Core::PLUGIN_PREFIX . '-section2',
    133163            array(
    134164                'label_for' => ShowCurrentWidth_Core::PLUGIN_PREFIX . '_animation_show',
    135165            ),
    136166        );
    137 
    138         // Add section 2.
    139         add_settings_section(
     167        // Add field 2-4 (Animation timeout).
     168        add_settings_field(
     169            ShowCurrentWidth_Core::PLUGIN_PREFIX . '_animation_timeout',
     170            __( 'Animation timeout', 'show-current-width' ),
     171            array( $this, 'register_field_animation_timeout_html' ),
     172            ShowCurrentWidth_Core::PLUGIN_PREFIX,
    140173            ShowCurrentWidth_Core::PLUGIN_PREFIX . '-section2',
    141             __( 'Display condition settings', 'show-current-width' ),
    142             array( $this, 'register_section2_html' ),
    143             ShowCurrentWidth_Core::PLUGIN_PREFIX
    144         );
    145         // Add field 2-1 (Admin page display).
    146         add_settings_field(
    147             ShowCurrentWidth_Core::PLUGIN_PREFIX . '_admin_show',
    148             __( 'Admin page display', 'show-current-width' ),
    149             array( $this, 'register_field_admin_show_html' ),
    150             ShowCurrentWidth_Core::PLUGIN_PREFIX,
    151             ShowCurrentWidth_Core::PLUGIN_PREFIX . '-section2',
    152             array(
    153                 'label_for' => ShowCurrentWidth_Core::PLUGIN_PREFIX . '_admin_show',
    154             ),
    155         );
    156         // Add field 2-2 (Role condition).
    157         add_settings_field(
    158             ShowCurrentWidth_Core::PLUGIN_PREFIX . '_condition_role',
    159             __( 'Role condition', 'show-current-width' ),
    160             array( $this, 'register_field_condition_role_html' ),
    161             ShowCurrentWidth_Core::PLUGIN_PREFIX,
    162             ShowCurrentWidth_Core::PLUGIN_PREFIX . '-section2',
    163             array(
    164                 'label_for' => ShowCurrentWidth_Core::PLUGIN_PREFIX . '_condition_role',
     174            array(
     175                'label_for' => ShowCurrentWidth_Core::PLUGIN_PREFIX . '_animation_timeout',
    165176            ),
    166177        );
     
    287298
    288299    /**
    289      * Field 1-4 HTML.
    290      *
    291      * @return void
    292      */
    293     public function register_field_animation_show_html() {
    294         printf(
    295             '<input type="hidden" name="%s_animation_show" value="0" />',
    296             esc_attr( ShowCurrentWidth_Core::PLUGIN_PREFIX )
    297         );
    298         printf(
    299             '<input type="checkbox" name="%s_animation_show" id="%s_animation_show" value="1" %s />',
    300             esc_attr( ShowCurrentWidth_Core::PLUGIN_PREFIX ),
    301             esc_attr( ShowCurrentWidth_Core::PLUGIN_PREFIX ),
    302             checked( get_option( ShowCurrentWidth_Core::PLUGIN_PREFIX . '_animation_show' ), '1', false )
    303         );
    304         printf(
    305             '<label for="%s_animation_show">%s</label>',
    306             esc_attr( ShowCurrentWidth_Core::PLUGIN_PREFIX ),
    307             esc_html__( 'Enable count up animation', 'show-current-width' )
    308         );
    309     }
    310 
    311     /**
    312300     * Section 2 HTML.
    313301     *
     
    315303     */
    316304    public function register_section2_html() {
    317         echo esc_html__( 'Setting about display condition', 'show-current-width' );
     305        echo esc_html__( 'Setting about display', 'show-current-width' );
    318306    }
    319307
     
    372360
    373361    /**
     362     * Field 2-3 HTML.
     363     *
     364     * @return void
     365     */
     366    public function register_field_animation_show_html() {
     367        printf(
     368            '<input type="hidden" name="%s_animation_show" value="0" />',
     369            esc_attr( ShowCurrentWidth_Core::PLUGIN_PREFIX )
     370        );
     371        printf(
     372            '<input type="checkbox" name="%s_animation_show" id="%s_animation_show" value="1" %s />',
     373            esc_attr( ShowCurrentWidth_Core::PLUGIN_PREFIX ),
     374            esc_attr( ShowCurrentWidth_Core::PLUGIN_PREFIX ),
     375            checked( get_option( ShowCurrentWidth_Core::PLUGIN_PREFIX . '_animation_show' ), '1', false )
     376        );
     377        printf(
     378            '<label for="%s_animation_show">%s</label>',
     379            esc_attr( ShowCurrentWidth_Core::PLUGIN_PREFIX ),
     380            esc_html__( 'Enable count up animation', 'show-current-width' )
     381        );
     382    }
     383
     384    /**
     385     * Field 2-4 HTML.
     386     *
     387     * @return void
     388     */
     389    public function register_field_animation_timeout_html() {
     390        printf(
     391            '<label for="%s_animation_timeout">%s</label> ',
     392            esc_attr( ShowCurrentWidth_Core::PLUGIN_PREFIX ),
     393            esc_html__( 'Time to display the screen width after it is changed. (millisecond)', 'show-current-width' )
     394        );
     395        printf(
     396            '<input type="text" name="%s_animation_timeout" id="%s_animation_timeout" class="small-text" value="%s" /> ms',
     397            esc_attr( ShowCurrentWidth_Core::PLUGIN_PREFIX ),
     398            esc_attr( ShowCurrentWidth_Core::PLUGIN_PREFIX ),
     399            esc_attr( get_option( ShowCurrentWidth_Core::PLUGIN_PREFIX . '_animation_timeout' ) )
     400        );
     401    }
     402
     403    /**
    374404     * Section 3 HTML.
    375405     *
     
    460490        register_setting(
    461491            ShowCurrentWidth_Core::PLUGIN_PREFIX . '-field1',
    462             ShowCurrentWidth_Core::PLUGIN_PREFIX . '_animation_show',
    463             'esc_attr',
    464         );
    465         register_setting(
    466             ShowCurrentWidth_Core::PLUGIN_PREFIX . '-field1',
    467492            ShowCurrentWidth_Core::PLUGIN_PREFIX . '_admin_show',
    468493            'esc_attr',
     
    475500                'sanitize_callback' => array( $this, 'sanitize_array' ),
    476501            ),
     502        );
     503        register_setting(
     504            ShowCurrentWidth_Core::PLUGIN_PREFIX . '-field1',
     505            ShowCurrentWidth_Core::PLUGIN_PREFIX . '_animation_show',
     506            'esc_attr',
     507        );
     508        register_setting(
     509            ShowCurrentWidth_Core::PLUGIN_PREFIX . '-field1',
     510            ShowCurrentWidth_Core::PLUGIN_PREFIX . '_animation_timeout',
     511            'esc_attr',
    477512        );
    478513        register_setting(
  • show-current-width/trunk/class/class-showcurrentwidth-core.php

    r2994893 r3009226  
    2323     * Plugin constant.
    2424     */
    25     const PLUGIN_VERSION           = '1.2.3';
     25    const PLUGIN_VERSION           = '1.2.4';
    2626    const PLUGIN_PREFIX            = 'show-current-width';
    2727    const PLUGIN_PREFIX_DEPRECATED = 'w83-show-current-width';
     
    4141    const OPTION_DEFAULT_BREAKPOINTS_LIMITWIDTH_MAX = 9999;
    4242    const OPTION_DEFAULT_ANIMATION_SHOW             = 1;
     43    const OPTION_DEFAULT_ANIMATION_TIMEOUT          = 500;
    4344    const OPTION_DEFAULT_ADMIN_SHOW                 = 0;
    4445    const OPTION_DEFAULT_CONDITION_ROLE             = array( 'administrator' );
     
    5960        'breakpoints_limitwidth_max' => self::OPTION_DEFAULT_BREAKPOINTS_LIMITWIDTH_MAX,
    6061        'animation_show'             => self::OPTION_DEFAULT_ANIMATION_SHOW,
     62        'animation_timeout'          => self::OPTION_DEFAULT_ANIMATION_TIMEOUT,
    6163        'admin_show'                 => self::OPTION_DEFAULT_ADMIN_SHOW,
    6264        'condition_role'             => self::OPTION_DEFAULT_CONDITION_ROLE,
     
    173175            'breakpoints_show'       => get_option( self::PLUGIN_PREFIX . '_breakpoints_show' ),
    174176            'animation_show'         => get_option( self::PLUGIN_PREFIX . '_animation_show' ),
     177            'animation_timeout'      => get_option( self::PLUGIN_PREFIX . '_animation_timeout' ),
    175178        );
    176179        wp_localize_script( self::PLUGIN_PREFIX . '-js', 'ShowCurrentWidthVariables', $pass_to_js );
     
    205208            foreach ( $breakpoints as $breakpoint_key => $breakpoint_value ) {
    206209                $breakpoints[ $breakpoint_key ] = explode( ',', $breakpoint_value );
     210                if ( count( $breakpoints[ $breakpoint_key ] ) < 4 ) {
     211                    unset( $breakpoints[ $breakpoint_key ] );
     212                }
    207213            }
    208214
  • show-current-width/trunk/readme.txt

    r2994893 r3009226  
    44Tags: admin,width,developement,design
    55Requires at least: 6.2
    6 Tested up to: 6.4.1
     6Tested up to: 6.4.2
    77Requires PHP: 7.4
    8 Stable tag: 1.2.3
     8Stable tag: 1.2.4
    99License: GPLv2 or later
    1010License URI: http://www.gnu.org/licenses/gpl-2.0.html
     
    2121== Changelog ==
    2222
     23= 1.2.4 - 2023-12-13 =
     24* Add: Animation timeout
     25* Tested up to WordPress 6.4.2.
     26
    2327= 1.2.3 - 2023-11-13 =
    24 * Add: Setting link  in adminbar.
     28* Add: Setting link in adminbar.
    2529* Tested up to WordPress 6.4.1.
    2630
  • show-current-width/trunk/uninstall.php

    r2973725 r3009226  
    1212// Delete all options if option 'show-current-width_other_uninstall' is checked.
    1313if ( is_multisite() ) {
    14     global $wpdb;
    15     $blogid_current = get_current_blog_id();
    16     $blogids        = $wpdb->get_col( "SELECT blog_id FROM $wpdb->blogs" );
    17     foreach ( $blogids as $blogid ) {
    18         switch_to_blog( $blogid );
    19         if ( '1' === get_option( 'show-current-width_other_uninstall' ) ) {
    20             // Delete all options whose key begins with 'show-current-width_'.
    21             delete_all_options( wp_load_alloptions( true ) );
    22         }
     14    $sites = get_sites();
     15    foreach ( $sites as $site ) {
     16        switch_to_blog( $site->blog_id );
     17        delete_all_related_options();
     18        restore_current_blog();
    2319    }
    24     switch_to_blog( $blogid_current );
    2520} else {
    26     if ( '1' === get_option( 'show-current-width_other_uninstall' ) ) {
    27         // Delete all options whose key begins with 'show-current-width_'.
    28         delete_all_options( wp_load_alloptions( true ) );
    29     }
     21    delete_all_related_options();
    3022}
    3123
    3224/**
    3325 * Delete all options core.
    34  *
    35  * @param array $alloptions Load all options.
    3626 */
    37 function delete_all_options( $alloptions ) {
    38     foreach ( $alloptions as $option_key => $option_value ) {
    39         if ( false !== strpos( $option_key, 'show-current-width_' ) ) {
    40             delete_option( $option_key );
     27function delete_all_related_options() {
     28    $alloptions = wp_load_alloptions( true );
     29    if ( '1' === get_option( 'show-current-width_other_uninstall' ) ) {
     30        foreach ( $alloptions as $option_key => $option_value ) {
     31            if ( false !== strpos( $option_key, 'show-current-width_' ) ) {
     32                delete_option( $option_key );
     33            }
    4134        }
    4235    }
  • show-current-width/trunk/w83-show-current-width.php

    r2994893 r3009226  
    44 * Plugin URI:
    55 * Description:         This plugin shows a current screen width on WP adminbar.
    6  * Version:             1.2.3
     6 * Version:             1.2.4
    77 * Requires at least:   6.0
    8  * Tested up to:        6.4.1
     8 * Tested up to:        6.4.2
    99 * Requires PHP:        7.4
    1010 * Author:              web83info <[email protected]>
Note: See TracChangeset for help on using the changeset viewer.