Skip to content

Commit

Permalink
new version 1.5
Browse files Browse the repository at this point in the history
  • Loading branch information
Eduardo Villão authored and Eduardo Villão committed Sep 16, 2021
1 parent ea0e6f8 commit dc38356
Show file tree
Hide file tree
Showing 7 changed files with 453 additions and 231 deletions.
40 changes: 7 additions & 33 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@

Form Masks for Elementor create a custom control in field advanced tab for your customize your fields with masks. This plugin require the Elementor Pro (Form Widget).

The masks function with filed types 'text' and 'tel'.
The masks work with filed types 'text'.

[Vídeo demo](https://www.youtube.com/watch?v=NYoykAUl4QE)
https://www.youtube.com/watch?v=NYoykAUl4QE

## Masks Available
#### Masks Available ####

* Phone - '0000-0000' or '(000) 000-0000' or '(00) 0000-0000'

Expand All @@ -24,36 +24,10 @@ The masks function with filed types 'text' and 'tel'.

* CEP - '00000-000'

## Changelog
```
= 1.4.2 =
#### Masks Available ####

* Suppor to Wp 5.8
Check the [Pro version](https://codecanyon.net/item/form-masks-for-elementor/25872641)

= 1.4.1 =
#### CREDITS ####

* Fix: active mask on popup when is called by link, button and others.
= 1.4 =
* Support for Elementor Popup.
= 1.3 =
* Add new mask - Credit card and Credit card date.
= 1.2 =
* Add new mask - Phone 9 digits.
= 1.1 =
* Update the mask control.
= 1.0 =
* Initial release.
```
#### CREDITS

This plugin use the jQuery Mask library plugin. [jQuery Mask Plugin](https://github.com/igorescobar/jQuery-Mask-Plugin)
This plugin use the jQuery Mask library plugin. [jQuery Mask Plugin](https://github.com/igorescobar/jQuery-Mask-Plugin)
33 changes: 0 additions & 33 deletions assets/elementor_mask.js

This file was deleted.

43 changes: 43 additions & 0 deletions assets/js/elementor-mask.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
(function($) {
var fmeMasks = {
'ev-tel': '0000-0000',
'ev-tel-ddd': '(00) 0000-0000',
'ev-tel-ddd9': '(00) 0.0000-0000',
'ev-tel-us': '(000) 000-0000',
'ev-cpf': '000.000.000-00',
'ev-cnpj': '00.000.000/0000-00',
'ev-money': '000.000.000.000.000,00',
'ev-ccard': '0000-0000-0000-0000',
'ev-ccard-valid': '00/00',
'ev-cep': '00000-000',
'ev-time': '00:00:00',
'ev-date': '00/00/0000',
'ev-date_time': '00/00/0000 00:00:00'
};

$(window).load( function() {
"use strict";
$('.fme-mask-input').each(function() {
if($( this ).data('fme-mask') !== undefined) {
var inputMask = $( this ).data("fme-mask");
if(inputMask == 'ev-cpf' || inputMask == 'ev-cnpj' || inputMask == 'ev-money') {
$( this ).mask( fmeMasks[inputMask], {reverse: true} );
} else {
$( this ).mask( fmeMasks[inputMask] );
}
}
});
jQuery(document).on( 'elementor/popup/show', () => {
$('.fme-mask-input').each(function() {
if($( this ).data("fme-mask") !== undefined) {
var inputMask = $( this ).data("fme-mask");
if(inputMask == 'ev-cpf' || inputMask == 'ev-cnpj' || inputMask == 'ev-money') {
$( this ).mask( fmeMasks[inputMask], {reverse: true} );
} else {
$( this ).mask( fmeMasks[inputMask] );
}
}
});
});
});
})(jQuery);
File renamed without changes.
238 changes: 225 additions & 13 deletions form-masks-for-elementor.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
* Description: Form Masks for Elementor create a custom control in field advanced tab for your customize your fields with masks. This plugin require the Elementor Pro (Form Widget).
* Author: EduardoVillao.me
* Author URI: https://eduardovillao.me/
* Version: 1.4.2
* Version: 1.5
* Domain Path: /languages
* Text Domain: form-masks-for-elementor
* License: GPL-2.0+
* License URI: http://www.gnu.org/licenses/gpl-2.0.txt
*/
Expand All @@ -14,19 +16,229 @@
exit; // Exit if accessed directly
}

/**Include Required Files**/
require dirname(__FILE__).'/includes/class-elementor-mask-control.php';
define( 'FME_PLUGIN_PATH', plugin_dir_path( __FILE__ ) );
define( 'FME_PLUGN_URL', plugin_dir_url( __FILE__ ) );
define( 'FME_VERSION' , '1.5' );

function evcode_include_js () {
wp_enqueue_script( 'plugin_jquery_mask', plugin_dir_url( __FILE__ ) . 'assets/jquery.mask.js', array( 'jquery' ) );
wp_enqueue_script( 'jquery_mask', plugin_dir_url( __FILE__ ) . 'assets/elementor_mask.js', array( 'jquery' ) );
}
add_action( 'wp_enqueue_scripts', 'evcode_include_js' );
/**
* Form Mask Elementor Class
*
* Class to initialize the plugin.
*
* @since 1.4
*/
final class FME_Init {

/**
* Minimum PHP Version
*
* @since 1.4
*
* @var string Minimum PHP version required to run the plugin.
*/
const MINIMUM_PHP_VERSION = '7.0';

/**
* Minimum WP Version
*
* @since 1.4
*
* @var string Minimum PHP version required to run the plugin.
*/
const MINIMUM_WP_VERSION = '5.3';

/**
* Instance
*
* @since 1.4
*
* @access private
* @static
*
* @var FME_Init The single instance of the class.
*/
private static $_instance = null;

/**Check Elementor Pro Plugin Installed**/
function evcode_check_elementor_active(){
if ( ! is_plugin_active( 'elementor-pro/elementor-pro.php' ) ) {
echo "<div class='error'><p><strong>Form Masks for Elementor</strong> requires <strong> Elementor Pro plugin</strong> </p></div>";
/**
* Instance
*
* Ensures only one instance of the class is loaded or can be loaded.
*
* @since 1.4
*
* @access public
* @static
*
* @return FME_Init An instance of the class.
*/
public static function instance() {

if ( is_null( self::$_instance ) ) {
self::$_instance = new self();
}
return self::$_instance;
}

/**
* Constructor
*
* Private method for prevent instance outsite the class.
*
* @since 1.4
*
* @access private
*/
private function __construct() {

if ( version_compare( PHP_VERSION, self::MINIMUM_PHP_VERSION, '<' ) ) {
add_action( 'admin_notices', [ $this, 'admin_notice_minimum_php_version' ] );
return;
}

if ( version_compare( $GLOBALS['wp_version'], self::MINIMUM_WP_VERSION, '<' ) ) {
add_action( 'admin_notices', [ $this, 'admin_notice_minimum_wp_version' ] );
return;
}

// load plugin text domain
load_plugin_textdomain( 'form-masks-for-elementor', false, dirname( plugin_basename( __FILE__ ) ) . '/languages' );

// init if element are initialized
add_action( 'plugins_loaded', [ $this, 'init' ] );
}

/**
* Initialize the plugin
*
* Load the plugin and all classes after Elementor and all plugins is loaded.
*
* @since 1.4
*
* @access public
*/
public function init() {

if( ! $this->plugin_is_active( 'elementor-pro/elementor-pro.php' ) ) {

add_action( 'admin_notices', [ $this, 'notice_elementor_pro_inactive' ] );
return;
}

// action fired when plugin is activated and dependencies checked
do_action( 'fme_init' );

// required files
require_once FME_PLUGIN_PATH . '/includes/class-elementor-mask-control.php';

// register and enqueue scripts
add_action( 'wp_enqueue_scripts', [ $this, 'enqueue_plugin_js' ] );
}

/**
* Enqueue JS
*
* Register and enqueue JS scripts.
*
* @since 1.4
*
* @access public
*/
public function enqueue_plugin_js() {

wp_register_script( 'fme-jquery-mask', FME_PLUGN_URL . 'assets/lib/jquery.mask.js', array( 'jquery' ), FME_VERSION, true );
wp_register_script( 'fme-mask', FME_PLUGN_URL . 'assets/js/elementor-mask.js', array( 'jquery' ), FME_VERSION, true );
wp_enqueue_script( 'fme-jquery-mask' );
wp_enqueue_script( 'fme-mask' );

/**
* Action for enqueue more scripts or remove current scripts
*
* @since 1.5
*/
do_action( 'fme_after_enqueue_scripts' );
}

/**
* Admin notice - Elementor PRO
*
* Warning when the site doesn't have Elementor PRO activated.
*
* @since 1.4
*
* @access public
*/
public function notice_elementor_pro_inactive() {

$message = sprintf(
esc_html__( '%1$s requires %2$s to be installed and activated.', 'form-masks-for-elementor' ),
'<strong>Form Masks for Elementor</strong>',
'<strong>Elementor Pro</strong>'
);

printf( '<div class="notice notice-error"><p>%1$s</p></div>', $message );
}

/**
* Admin notice - PHP
*
* Warning when the site doesn't have a minimum required PHP version.
*
* @since 1.4
*
* @access public
*/
public function admin_notice_minimum_php_version() {

if ( isset( $_GET['activate'] ) ) {
unset( $_GET['activate'] );
}

$message = sprintf(
esc_html__( '%1$s requires %2$s version %3$s or greater.', 'form-masks-for-elementor' ),
'<strong>Form masks for Elementor</strong>',
'<strong>PHP</strong>',
self::MINIMUM_PHP_VERSION
);

printf( '<div class="notice notice-error"><p>%1$s</p></div>', $message );
}

/**
* Admin notice - WP
*
* Warning when the site doesn't have a minimum required WP version.
*
* @since 1.4
*
* @access public
*/
public function admin_notice_minimum_wp_version() {

if ( isset( $_GET['activate'] ) ) {
unset( $_GET['activate'] );
}

$message = sprintf(
esc_html__( '%1$s requires %2$s version %3$s or greater.', 'form-masks-for-elementor' ),
'<strong>Form masks for Elementor</strong>',
'<strong>WordPress</strong>',
self::MINIMUM_WP_VERSION
);

printf( '<div class="notice notice-error"><p>%1$s</p></div>', $message );
}

/**
* Check plugin is activated
*
* @since 1.5
* @return boolean
* @param string $plugin
*/
public function plugin_is_active( $plugin ) {

return function_exists( 'is_plugin_active' ) ? is_plugin_active( $plugin ) : in_array( $plugin, (array) get_option( 'active_plugins', array() ), true );
}
}
add_action('admin_notices', 'evcode_check_elementor_active');

FME_Init::instance();
Loading

0 comments on commit dc38356

Please sign in to comment.