Skip to content

Commit 9200d3f

Browse files
author
Leo Leoncio
committed
Initial release
0 parents  commit 9200d3f

File tree

14 files changed

+439
-0
lines changed

14 files changed

+439
-0
lines changed

.editorconfig

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
; top-most EditorConfig file
2+
root = true
3+
4+
; Unix-style newlines
5+
[*]
6+
end_of_line = lf
7+
insert_final_newline = true
8+
trim_trailing_whitespace = true
9+
charset = utf-8
10+
indent_style = space
11+
indent_size = 4
12+
tab_width = 4
13+
14+
[*.{json,yml}]
15+
indent_size = 2

.gitignore

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/vendor
2+
/composer.lock
3+
/node_modules
4+
/package-lock.json
5+
6+
# thumbnails
7+
._*
8+
9+
# misc
10+
.sass-cache
11+
.cache
12+
.php_cs.cache
13+
ecs.php
14+
.DS_Store
15+
.project
16+
.settings
17+
*.esproj
18+
*.sublime-workspace
19+
*.sublime-project
20+
*.tmproj
21+
*.tmproject
22+
config.codekit3
23+
prepros-6.config
24+
25+
# ide
26+
.idea
27+
.vscode

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# Release Notes for Masked Fields
2+
3+
All notable changes to this project will be documented in this file.
4+
5+
## 1.0.0 - 2022.11.28
6+
### Initial release
7+

LICENSE.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
### The MIT License (MIT)
2+
3+
Copyright (c) 2020-2024 Leowebguy
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
Masked Fields plugin for Craft
2+
===
3+
4+
A mix of masked/validated fields for Craft
5+
6+
_Thanks to https://github.com/igorescobar/jQuery-Mask-Plugin_
7+
8+
### Installation
9+
10+
```bash
11+
composer require leowebguy/masked-fields
12+
```
13+
14+
On your Control Panel, go to Settings → Plugins → "Masked Fields" → Install
15+
16+
### Usage
17+

composer.json

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
{
2+
"name": "leowebguy/masked-fields",
3+
"description": "A mix of masked/validated fields for Craft",
4+
"keywords": [
5+
"craftcms",
6+
"masked",
7+
"fields",
8+
"mask",
9+
"validation"
10+
],
11+
"version": "1.0.0",
12+
"type": "craft-plugin",
13+
"license": "MIT",
14+
"authors": [
15+
{
16+
"name": "Leo",
17+
"homepage": "https://github.com/leowebguy"
18+
}
19+
],
20+
"minimum-stability": "dev",
21+
"prefer-stable": true,
22+
"require": {
23+
"craftcms/cms": "^4.0"
24+
},
25+
"require-dev": {
26+
"craftcms/ecs": "dev-main",
27+
"craftcms/phpstan": "dev-main",
28+
"craftcms/rector": "dev-main"
29+
},
30+
"autoload": {
31+
"psr-4": {
32+
"leowebguy\\maskedfields\\": "src/"
33+
}
34+
},
35+
"extra": {
36+
"name": "Masked Fields",
37+
"handle": "masked-fields",
38+
"hasCpSection": false,
39+
"hasCpSettings": false,
40+
"class": "leowebguy\\maskedfields\\Plugin"
41+
},
42+
"config": {
43+
"platform": {
44+
"php": "8.0.2"
45+
},
46+
"allow-plugins": {
47+
"yiisoft/yii2-composer": true,
48+
"craftcms/plugin-installer": true
49+
}
50+
},
51+
"scripts": {
52+
"check-cs": "vendor/bin/ecs check src --ansi",
53+
"fix-cs": "vendor/bin/ecs check src --ansi --fix",
54+
"phpstan": "vendor/bin/phpstan analyse src",
55+
"rector": "vendor/bin/rector process src --config vendor/craftcms/rector/sets/craft-cms-40.php"
56+
}
57+
}

src/Plugin.php

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
<?php
2+
/**
3+
* A mix of masked/validated fields for Craft
4+
*
5+
* @author Leo Leoncio
6+
* @see https://github.com/leowebguy
7+
* @copyright Copyright (c) 2022, leowebguy
8+
* @license MIT
9+
*/
10+
11+
namespace leowebguy\maskedfields;
12+
13+
use Craft;
14+
use craft\base\Plugin as BasePlugin;
15+
use craft\events\RegisterComponentTypesEvent;
16+
use craft\web\View;
17+
use leowebguy\maskedfields\assets\Assets;
18+
use leowebguy\maskedfields\fields\MaskedField;
19+
use yii\base\Event;
20+
use craft\services\Fields;
21+
22+
/*
23+
* Class MixManifest
24+
*/
25+
class Plugin extends BasePlugin
26+
{
27+
// Properties
28+
// =========================================================================
29+
public static $plugin;
30+
31+
// Public Methods
32+
// =========================================================================
33+
public function init()
34+
{
35+
parent::init();
36+
self::$plugin = $this;
37+
38+
if (!$this->isInstalled) {
39+
return;
40+
}
41+
42+
/**
43+
* Register assets
44+
*/
45+
Event::on(
46+
View::class,
47+
View::EVENT_BEFORE_RENDER_TEMPLATE,
48+
static function() {
49+
if (Craft::$app->getRequest()->getIsCpRequest()) {
50+
$view = Craft::$app->getView();
51+
$view->registerAssetBundle(Assets::class);
52+
}
53+
}
54+
);
55+
56+
/**
57+
* Register fields
58+
*/
59+
Event::on(
60+
Fields::class,
61+
Fields::EVENT_REGISTER_FIELD_TYPES,
62+
function(RegisterComponentTypesEvent $event) {
63+
$event->types[] = MaskedField::class;
64+
}
65+
);
66+
67+
/**
68+
* Log info
69+
*/
70+
Craft::info(
71+
'Masked Fields plugin loaded',
72+
__METHOD__
73+
);
74+
}
75+
}

src/assets/Assets.php

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<?php
2+
/**
3+
* A mix of masked/validated fields for Craft
4+
*
5+
* @author Leo Leoncio
6+
* @see https://github.com/leowebguy
7+
* @copyright Copyright (c) 2022, leowebguy
8+
* @license MIT
9+
*/
10+
11+
namespace leowebguy\maskedfields\assets;
12+
13+
use craft\web\AssetBundle;
14+
use craft\web\assets\cp\CpAsset;
15+
16+
class Assets extends AssetBundle
17+
{
18+
public function init()
19+
{
20+
$this->sourcePath = '@leowebguy/maskedfields/assets';
21+
$this->depends = [CpAsset::class];
22+
23+
//$this->css = [
24+
// 'css/cp.css'
25+
//];
26+
27+
$this->js = [
28+
'js/jquery.mask.min.js',
29+
'js/cp.js'
30+
];
31+
32+
parent::init();
33+
}
34+
}

src/assets/js/cp.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
(($) => {
2+
$('.date-mask').mask('00/00/0000', {placeholder: 'mm/dd/yyyy'})
3+
$('.time-mask').mask('00:00:00', {placeholder: 'hh:mm:ss'})
4+
$('.datetime-mask').mask('00/00/0000 00:00:00', {placeholder: 'mm/dd/yyyy hh:mm:ss'})
5+
$('.cep-mask').mask('00000-000', {placeholder: '_____-___'})
6+
$('.zip-mask').mask('00000', {placeholder: '_____'})
7+
$('.phonebr-mask').mask('(00) 0000-0000', {placeholder: '(__) ____-____'})
8+
$('.phoneus-mask').mask('(000) 000-0000', {placeholder: '(___) ___-____'})
9+
$('.ip-mask').mask('099.099.099.099', {placeholder: '___.___.___.___'})
10+
$('.cnpj-mask').mask('00.000.000/0000-00', {placeholder: '__.___.___/____-__', reverse: true})
11+
$('.cpf-mask').mask('000.000.000-00', {placeholder: '___.___.___-__', reverse: true})
12+
$('.itin-mask').mask('000-00-0000', {placeholder: '___-__-____', reverse: true})
13+
$('.money-mask').mask('#.##0,00', {reverse: true})
14+
$('.percent-mask').mask('##0,00%', {reverse: true})
15+
})(jQuery)

src/assets/js/jquery.mask.min.js

Lines changed: 19 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)